:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e6e8ec;
  --border-strong: #d6d9df;
  --text: #14181f;
  --text-2: #5b6573;
  --muted: #8b95a4;
  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --green: #16a34a;
  --green-soft: #e7f6ec;
  --amber: #d97706;
  --amber-soft: #fdf1e1;
  --red: #dc2626;
  --red-soft: #fdeaea;
  --teal: #0d9488;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  z-index: 10;
}
.logo { display: flex; align-items: center; gap: 11px; padding: 0 8px; margin-bottom: 28px; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.logo span { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  text-decoration: none; color: var(--text-2);
  padding: 9px 12px; border-radius: 8px; font-weight: 500; font-size: 14px;
  transition: all 0.12s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); }
.host { font-weight: 600; font-size: 13px; }
.host-sub { color: var(--muted); font-size: 12px; margin-top: 2px; font-family: "IBM Plex Mono", monospace; }

/* Main */
.main {
  margin-left: var(--sidebar-w);
  padding: 26px 30px 50px;
  max-width: 1280px;
}

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.crumb { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.head-actions { display: flex; align-items: center; gap: 12px; }
.live {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--text-2); font-size: 13px; font-weight: 500;
  font-family: "IBM Plex Mono", monospace;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4); animation: pulse 1.9s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0.4); }
  70% { box-shadow: 0 0 0 7px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

/* Buttons */
.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all 0.12s ease; font-family: inherit;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.small { padding: 6px 11px; font-size: 12px; }
.btn.danger { color: var(--red); border-color: #f0c4c4; }
.btn.danger:hover { background: var(--red-soft); }
.btn.link { border: none; box-shadow: none; background: transparent; color: var(--accent); padding: 6px 8px; }
.btn.link:hover { background: var(--accent-soft); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 27px; font-weight: 700; margin: 8px 0; letter-spacing: -0.02em; }
.kpi-sub { color: var(--text-2); font-size: 12.5px; font-family: "IBM Plex Mono", monospace; }
.kpi-meter { height: 6px; background: #eef0f3; border-radius: 999px; overflow: hidden; margin: 4px 0 9px; }
.kpi-meter span {
  display: block; height: 100%; width: 0%; border-radius: 999px;
  background: var(--accent); transition: width 0.5s ease;
}
.kpi-meter span.teal { background: var(--teal); }
.kpi-meter span.warn { background: var(--amber); }
.kpi-meter span.crit { background: var(--red); }

/* Charts */
.charts { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; margin-bottom: 16px; }
.chart-panel { padding: 16px 18px; }
.chart-wrap { position: relative; height: 240px; margin-top: 8px; }

/* Panels */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 16px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; gap: 16px; flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.panel-sub { color: var(--muted); font-size: 12.5px; font-family: "IBM Plex Mono", monospace; }
.panel-note { margin: -6px 18px 6px; color: var(--muted); font-size: 12.5px; }

/* Table */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table thead th {
  text-align: left; padding: 10px 16px; font-size: 11.5px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap;
}
.table th.num, .table td.num { text-align: right; font-family: "IBM Plex Mono", monospace; }
.table th.right, .table td.right { text-align: right; }
.table tbody td {
  padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .loading { text-align: center; color: var(--muted); padding: 28px; }

.svc { display: flex; flex-direction: column; }
.svc .name { font-weight: 600; }
.svc .meta { color: var(--muted); font-size: 11.5px; font-family: "IBM Plex Mono", monospace; }

.status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.online { color: var(--green); background: var(--green-soft); }
.status.offline { color: var(--red); background: var(--red-soft); }
.status.warn { color: var(--amber); background: var(--amber-soft); }

.site { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.site .pip { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.site.ok .pip { background: var(--green); }
.site.bad .pip { background: var(--red); }
.site a { color: var(--accent); text-decoration: none; font-weight: 500; }
.site a:hover { text-decoration: underline; }
.site .nolink { color: var(--muted); }

/* Snapshots accordion */
.accordion { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.acc-loading { color: var(--muted); padding: 20px; text-align: center; }

.acc-item {
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.acc-item.open { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }

.acc-head {
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  cursor: pointer;
  user-select: none;
}
.acc-head:hover { background: var(--surface-2); }
.acc-chev {
  width: 22px; height: 22px; display: grid; place-items: center;
  color: var(--muted); transition: transform 0.2s ease; font-size: 12px;
}
.acc-item.open .acc-chev { transform: rotate(90deg); color: var(--accent); }

.acc-id { min-width: 0; }
.acc-id .nm { font-weight: 600; font-size: 14.5px; }
.acc-id .inc {
  color: var(--text-2); font-size: 12px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.dbtag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.dbtag::before { content: ""; width: 6px; height: 6px; border-radius: 2px; background: currentColor; }
.dbtag.postgres { color: #1d4ed8; background: #eaf0ff; }
.dbtag.sqlite { color: var(--teal); background: #e6f6f3; }
.dbtag.none { color: var(--muted); background: var(--surface-2); }

.acc-summary { display: flex; align-items: center; gap: 12px; }
.acc-count {
  font-size: 12.5px; color: var(--text-2); white-space: nowrap;
}
.acc-count b { color: var(--text); font-weight: 600; }

.acc-body {
  display: none;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.acc-item.open .acc-body { display: block; }

.snaprow {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px 12px 52px;
  border-bottom: 1px solid var(--border);
}
.snaprow:last-child { border-bottom: none; }
.snaprow .si { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.snaprow .si .date { font-weight: 600; font-size: 13.5px; }
.snaprow .si .size {
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 6px;
}
.snaprow .si .ago { color: var(--muted); font-size: 12.5px; }
.snaprow .si .latest {
  font-size: 10.5px; font-weight: 700; color: var(--green);
  background: var(--green-soft); padding: 2px 7px; border-radius: 5px;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.snaprow .sa { display: inline-flex; gap: 7px; }
.acc-empty { padding: 16px 16px 16px 52px; color: var(--muted); font-style: italic; font-size: 13px; }

/* Icon buttons */
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); padding: 6px 11px; border-radius: 7px;
  font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: all 0.12s ease;
}
.icon-btn svg { width: 13px; height: 13px; }
.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.icon-btn.danger:hover { background: var(--red-soft); border-color: #f0a5a5; color: var(--red); }

/* Switch */
.snap-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.slider {
  width: 40px; height: 23px; border-radius: 999px; background: #d6d9df;
  position: relative; transition: all 0.18s ease;
}
.slider::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: all 0.18s ease;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { left: 18px; }
.switch-label { font-size: 13px; font-weight: 600; }

/* Footer */
.foot {
  display: flex; justify-content: space-between; color: var(--muted);
  font-size: 12px; padding: 12px 4px; margin-top: 6px;
}

/* Toasts */
.toast-wrap { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 50; }
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); padding: 12px 16px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 13px; min-width: 240px; animation: slidein 0.2s ease;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes slidein { from { transform: translateX(16px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.spin { animation: rot 0.8s linear infinite; display: inline-block; }
@keyframes rot { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* Login */
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, #eef0fe, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 28px 28px 22px;
  text-align: center;
}
.login-brand { display: inline-flex; align-items: center; gap: 11px; margin-bottom: 18px; }
.login-brand span { font-weight: 700; font-size: 18px; }
.login-title { margin: 6px 0 6px; font-size: 19px; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 18px; color: var(--text-2); font-size: 13.5px; line-height: 1.5; }
.login-loading { color: var(--muted); padding: 26px; }
.qr-box {
  display: grid; place-items: center; padding: 14px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  margin: 0 auto 14px; width: fit-content;
}
.qr-box img { display: block; width: 220px; height: 220px; image-rendering: pixelated; }
.secret-details { text-align: center; margin-bottom: 6px; }
.secret-details summary { cursor: pointer; color: var(--accent); font-size: 12.5px; font-weight: 600; }
.secret-code {
  display: block; margin-top: 10px; padding: 9px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  font-family: "IBM Plex Mono", monospace; font-size: 12.5px; word-break: break-all; color: var(--text);
}
.code-form { margin-top: 14px; }
.code-input {
  width: 100%; text-align: center; font-family: "IBM Plex Mono", monospace;
  font-size: 30px; font-weight: 600; letter-spacing: 0.4em;
  padding: 13px 10px; border: 1px solid var(--border-strong); border-radius: 11px;
  color: var(--text); background: var(--surface-2); outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.code-input::placeholder { color: #c4c9d2; letter-spacing: 0.4em; }
.code-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fff; }
.login-btn { width: 100%; margin-top: 12px; padding: 11px; font-size: 14px; justify-content: center; }
.login-err { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 10px; font-weight: 500; }
.login-foot { color: var(--muted); font-size: 12px; margin: 18px 0 0; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45);
  display: grid; place-items: center; z-index: 60; padding: 24px;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 360px; background: var(--surface);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 24px; text-align: center;
}
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { color: var(--text-2); font-size: 13px; margin: 0 0 16px; line-height: 1.5; }
.modal .qr-box { margin-bottom: 14px; }
.modal-close { margin-top: 8px; }

/* Header auth controls */
.icon-only {
  width: 36px; height: 36px; padding: 0; display: inline-grid; place-items: center;
}
.icon-only svg { width: 16px; height: 16px; }

@media (max-width: 1040px) {
  .charts { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 20px 16px 40px; }
  .kpis { grid-template-columns: 1fr 1fr; }
}
