:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-muted: #6b7280;
  --text-subtle: #9ca3af;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --success: #047857;
  --success-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */

.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  padding: 0.25rem 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brand-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.side-nav a, .side-nav button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
  width: 100%;
}
.side-nav a:hover, .side-nav button:hover {
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}
.side-nav a.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.side-nav .spacer { flex: 1; }

.main {
  padding: 2rem 2.5rem;
  max-width: 1200px;
  width: 100%;
}

/* ---------- Header ---------- */

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 1.25rem 1.5rem; }
.card-form { padding: 1.5rem; max-width: 600px; }

/* ---------- Forms ---------- */

.field { margin-bottom: 1rem; }
.field label,
.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}
.field input[type=text],
.field input[type=password],
.field input[type=number],
.field input:not([type]),
.field select,
input.input, select.input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, input.input:focus, select.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field .hint {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-subtle);
}
.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}
.checkbox input[type=checkbox] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
}

/* ---------- Buttons ---------- */

.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
  font-family: inherit;
}
.btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--bg); }
.btn-danger {
  background: var(--danger);
}
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 0.35rem 0.55rem;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.78rem; font-weight: 500; }
.btn-icon {
  padding: 0.3rem 0.55rem;
  background: #fff;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

[hx-indicator].htmx-request { opacity: 0.55; }

/* Dropdown menu (CSS-only via :focus-within) */
.menu { position: relative; display: inline-block; }
.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 170px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 4px;
  display: none;
  z-index: 100;
}
.menu.up .menu-items { top: auto; bottom: calc(100% + 4px); }
.menu:focus-within .menu-items,
.menu.open .menu-items { display: block; }
.menu-items a,
.menu-items button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.7rem;
  background: none;
  border: 0;
  color: var(--text);
  font-size: 0.85rem;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
}
.menu-items a:hover,
.menu-items button:hover { background: var(--bg); text-decoration: none; }
.menu-items .danger { color: var(--danger); }
.menu-items form { margin: 0; }

/* Name cell with inline connection dot */
.name-cell { display: flex; align-items: center; gap: 0.55rem; }
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
  background: #d1d5db;
}
.dot.ok { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18); }
.dot.failed { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18); }
.dot.running { background: #f59e0b; }
.dot[title] { cursor: help; }

/* Compact cells */
.nowrap { white-space: nowrap; }
.cell-mono { font-size: 0.78rem; }
.pill { font-size: 0.68rem; padding: 0.1rem 0.5rem; }

/* Pill tweaks for the new compact style */
.pill.kind-pg { background: #e0e7ff; color: #3730a3; }
.pill.kind-mysql { background: #ffedd5; color: #9a3412; }
.btn-link {
  background: none;
  border: 0;
  color: var(--primary);
  padding: 0;
  font: inherit;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

.btn-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* ---------- Table ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  /* No overflow clipping — dropdown menus must escape the card. */
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th, table.data td {
  padding: 0.7rem 1rem;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: #f9fafb; }
table.data th {
  background: #fafbfc;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td.actions {
  text-align: right;
  white-space: nowrap;
}
table.data td.actions .btn-row { justify-content: flex-end; flex-wrap: nowrap; gap: 0.35rem; }
table.data td.actions form { display: inline-flex; }

.cell-primary {
  font-weight: 600;
  color: var(--text);
}
.cell-sub {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}
.cell-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  background: #f3f4f6;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  white-space: nowrap;
}

.empty {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 0.25rem; }

/* ---------- Pills / badges ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.6;
}
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.failed { background: var(--danger-soft); color: var(--danger); }
.pill.running { background: var(--warn-soft); color: var(--warn); }
.pill.muted { background: #e5e7eb; color: #4b5563; }
.pill.kind-pg { background: #dbeafe; color: #1e40af; }
.pill.kind-mysql { background: #fef3c7; color: #92400e; }
.pill.on { background: var(--success-soft); color: var(--success); }
.pill.off { background: #e5e7eb; color: #4b5563; }

/* ---------- Flash ---------- */

.flash {
  background: var(--warn-soft);
  border: 1px solid #fde68a;
  color: var(--warn);
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f4f5f7 100%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}
.login-card h1 {
  margin: 0 0 1.5rem;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

/* ---------- Misc ---------- */

.muted { color: var(--text-muted); }
.small { font-size: 0.8rem; }
.spacer-y { height: 1.25rem; }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 0.75rem 1rem; }
  .sidebar .side-nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 1.25rem; }
}
