/* WireGuard UI styles. No build step, no external fonts. */

:root {
  color-scheme: light;
  --bg: #f3f3f0;
  --surface: #fcfcfb;
  --surface-2: #f3f3f0;
  --surface-3: #ebebe6;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.18);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #66645e; /* 4.7:1 on the grey page, 5.3:1 on cards */
  --axis-text: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;

  --accent: #256abf;
  --accent-hover: #1c5cab;
  --accent-soft: rgba(42, 120, 214, 0.1);
  --accent-text: #1c5cab;
  --on-accent: #ffffff;

  /* Data series (validated categorical slots 1-2) */
  --down: #2a78d6;
  --up: #eb6834;

  /* Status (fixed, always paired with icon/label) */
  --good: #0ca30c;
  --good-text: #006300;
  --good-soft: rgba(12, 163, 12, 0.1);
  --warning: #fab219;
  --warning-text: #8a5a00;
  --warning-soft: rgba(250, 178, 25, 0.14);
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-text: #b42f2f;
  --critical-soft: rgba(208, 59, 59, 0.09);
  --neutral-dot: #a8a69e;

  /* Sequential blue ramp (heatmap): low -> high */
  --seq-lo: #e4effc;
  --seq-hi: #0d366b;
  --meter-track: #cde2fb;

  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.04);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 4px 16px rgba(11, 11, 11, 0.05);
  --shadow-lg: 0 12px 48px rgba(11, 11, 11, 0.18);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 232px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --surface-3: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a988f;
    --axis-text: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #256abf;
    --accent-hover: #2a78d6;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --accent-text: #86b6ef;
    --down: #3987e5;
    --up: #d95926;
    --good-text: #4cc94c; /* readable on the green badge tint (dark) */
    --good-soft: rgba(12, 163, 12, 0.16);
    --warning-text: #fab219;
    --warning-soft: rgba(250, 178, 25, 0.14);
    --critical-text: #e66767;
    --critical-soft: rgba(208, 59, 59, 0.16);
    --neutral-dot: #6b6a64;
    --seq-lo: #16263a;
    --seq-hi: #9ec5f4;
    --meter-track: #184f95;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #9a988f;
  --axis-text: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #256abf;
  --accent-hover: #2a78d6;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --accent-text: #86b6ef;
  --down: #3987e5;
  --up: #d95926;
  --good-text: #4cc94c; /* readable on the green badge tint (dark) */
  --good-soft: rgba(12, 163, 12, 0.16);
  --warning-text: #fab219;
  --warning-soft: rgba(250, 178, 25, 0.14);
  --critical-text: #e66767;
  --critical-soft: rgba(208, 59, 59, 0.16);
  --neutral-dot: #6b6a64;
  --seq-lo: #16263a;
  --seq-hi: #9ec5f4;
  --meter-track: #184f95;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ----------------------------------------------------------------- shell */
.app { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--border);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2a78d6, #104281); color: #fff; flex: none;
}
.brand-name { font-weight: 650; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-text); }
.nav a .icon { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.server-pill {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px;
  background: var(--surface-2); font-size: 12.5px; color: var(--text-2);
}
.server-pill strong { color: var(--text); font-weight: 600; }
.version { font-size: 11.5px; color: var(--muted); padding: 0 2px; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--border); }
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.crumbs { font-size: 12.5px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.content { padding: 8px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1440px; width: 100%; }
.banners { display: flex; flex-direction: column; gap: 10px; padding: 0 28px; max-width: 1440px; }
.banners:empty { display: none; }

/* ------------------------------------------------------------- components */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); min-width: 0;
}
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 18px 0;
}
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px 18px 18px; }
.card-body.flush { padding: 8px 0 4px; }

.grid { display: grid; gap: 20px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.main-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* Stat tiles */
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.stat-label { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat-value small { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; margin-left: 4px; }
.stat-sub { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.stat-trend { height: 32px; margin-top: 2px; }
.delta { font-weight: 600; font-size: 12.5px; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical-text); }
.delta.flat { color: var(--muted); }

.key { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.swatch.line { width: 14px; height: 3px; border-radius: 2px; }
.sw-down { background: var(--down); }
.sw-up { background: var(--up); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-weight: 550; cursor: pointer;
  white-space: nowrap; transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  text-decoration: none !important; box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--critical-text); }
.btn.danger:hover { background: var(--critical-soft); }
.btn.danger.solid { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon-only { width: 36px; padding: 0; }
.btn.sm.icon-only { width: 30px; }
.btn.block { width: 100%; }

/* Segmented control */
.seg {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.seg button {
  border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; cursor: pointer;
  color: var(--text-2); font-weight: 550; font-size: 13px; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { font-weight: 550; font-size: 13px; color: var(--text); }
.field .hint { font-size: 12.5px; color: var(--muted); }
.field .error-text { font-size: 12.5px; color: var(--critical-text); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); transition: border-color 0.12s, box-shadow 0.12s;
}
.textarea { height: auto; min-height: 72px; padding: 9px 12px; resize: vertical; line-height: 1.45; }
.textarea.mono { font-family: var(--mono); font-size: 12.5px; }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 0.85; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.invalid .input, .field.invalid .textarea { border-color: var(--critical); }
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .select, .input-group .addon {
  width: auto; border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px;
}
.addon {
  display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text-2); border-radius: 0 9px 9px 0; font-size: 13px;
}
.search { position: relative; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search .input { padding-left: 34px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px;
  padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: var(--text-2);
}
.chip:hover { color: var(--text); background: var(--surface-2); }
.chip.active { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
details.advanced > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px;
  font-weight: 550; color: var(--text-2); font-size: 13px; user-select: none;
}
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary .icon { width: 16px; height: 16px; transition: transform 0.15s; }
details.advanced[open] > summary .icon { transform: rotate(90deg); }
details.advanced > .form-grid { margin-top: 14px; }

/* Toggle switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 36px; height: 20px; border-radius: 999px; background: var(--surface-3);
  border: 1px solid var(--border-strong); position: relative; transition: background 0.15s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Status */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 550; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--neutral-dot); flex: none; }
.dot.online { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.warning { background: var(--warning); }
.dot.critical { background: var(--critical); }
.status.online { color: var(--good-text); }
.status.offline { color: var(--muted); }
.status.disabled { color: var(--muted); }
.status.warning { color: var(--warning-text); }
.status.critical { color: var(--critical-text); }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap;
}
.badge.good { background: var(--good-soft); color: var(--good-text); }
.badge.warning { background: var(--warning-soft); color: var(--warning-text); }
.badge.critical { background: var(--critical-soft); color: var(--critical-text); }
.badge.accent { background: var(--accent-soft); color: var(--accent-text); }
.badge .icon { width: 12px; height: 12px; }

/* Banners */
.banner {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13.5px;
}
.banner .icon { width: 18px; height: 18px; flex: none; }
.banner.info { background: var(--accent-soft); border-color: transparent; }
.banner.info .icon { color: var(--accent-text); }
.banner.warning { background: var(--warning-soft); border-color: transparent; }
.banner.warning .icon { color: var(--warning-text); }
.banner.critical { background: var(--critical-soft); border-color: transparent; }
.banner.critical .icon { color: var(--critical-text); }
.banner .grow { min-width: 0; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 550; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: var(--surface-2); }
.table th:first-child, .table td:first-child { padding-left: 18px; }
.table th:last-child, .table td:last-child { padding-right: 18px; }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.empty .icon { width: 28px; height: 28px; margin: 0 auto 10px; color: var(--axis); }
.empty h3 { color: var(--text); margin-bottom: 4px; }

/* Lists */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--border); min-width: 0; }
.list-item:last-child { border-bottom: 0; }
.list-item .meta { font-size: 12.5px; color: var(--muted); }
.ev-icon {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--text-2);
}
.ev-icon .icon { width: 15px; height: 15px; }
.ev-icon.good { background: var(--good-soft); color: var(--good-text); }
.ev-icon.warning { background: var(--warning-soft); color: var(--warning-text); }
.ev-icon.critical { background: var(--critical-soft); color: var(--critical-text); }
.ev-icon.accent { background: var(--accent-soft); color: var(--accent-text); }

/* Key/value details */
.kv { display: grid; grid-template-columns: minmax(110px, auto) minmax(0, 1fr); gap: 10px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; display: flex; align-items: center; gap: 6px; }
.copyable { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; }
.copyable code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.copy-btn { border: 0; background: transparent; padding: 3px; border-radius: 6px; cursor: pointer; color: var(--muted); flex: none; }
.copy-btn:hover { background: var(--surface-2); color: var(--text); }
.copy-btn .icon { width: 14px; height: 14px; }

/* Charts */
.chart { position: relative; width: 100%; user-select: none; }
.chart svg { width: 100%; overflow: visible; }
.chart .axis-label { fill: var(--axis-text); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .end-label { fill: var(--text-2); font-size: 11.5px; font-weight: 550; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .hover-dot { stroke: var(--surface); stroke-width: 2; }
.chart-empty { display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.spark { width: 100%; height: 100%; overflow: visible; }

.tooltip {
  position: fixed; z-index: 100; pointer-events: none; min-width: 140px; max-width: 280px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 10px; box-shadow: var(--shadow); padding: 9px 11px; font-size: 12.5px;
  opacity: 0; transition: opacity 0.08s;
}
.tooltip.show { opacity: 1; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 6px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row + .tt-row { margin-top: 3px; }
.tooltip .tt-row .v { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; padding-left: 12px; }
.tooltip .tt-row.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; color: var(--text-2); }

/* Bar list (top clients) */
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: flex; flex-direction: column; gap: 6px; cursor: default; }
.bar-row .bar-head { display: flex; align-items: baseline; gap: 10px; font-size: 13px; }
.bar-row .bar-head .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.bar-row .bar-head .val { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-row .bar-head .pct { color: var(--muted); font-size: 12px; min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.bar-track { display: flex; gap: 2px; height: 10px; }
.bar-seg { height: 100%; min-width: 0; }
.bar-seg:last-child { border-radius: 0 4px 4px 0; }
.bar-seg.down { background: var(--down); }
.bar-seg.up { background: var(--up); }
a.bar-row { color: inherit; text-decoration: none; }
a.bar-row:hover .name { text-decoration: underline; }

/* Meter */
.meter { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.meter-track { height: 6px; border-radius: 999px; background: var(--meter-track); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; background: var(--down); }
.meter.warning .meter-track { background: var(--warning-soft); }
.meter.warning .meter-fill { background: var(--warning); }
.meter.critical .meter-track { background: var(--critical-soft); }
.meter.critical .meter-fill { background: var(--critical); }
.meter-label { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Heatmap */
.heatmap { display: grid; grid-template-columns: 34px repeat(24, minmax(0, 1fr)); gap: 3px; align-items: center; }
.heatmap .hm-day { font-size: 11px; color: var(--axis-text); }
.heatmap .hm-cell { aspect-ratio: 1 / 1; border-radius: 2px; background: var(--surface-2); min-height: 10px; }
.heatmap .hm-cell:hover { outline: 2px solid var(--text); outline-offset: 1px; }
.heatmap .hm-hour { font-size: 10.5px; color: var(--axis-text); text-align: left; }
.hm-legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 12px; justify-content: flex-end; }
.hm-legend .ramp { width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--seq-lo), var(--seq-hi)); }

/* Client list */
.client-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.client-name .names { min-width: 0; }
.client-name .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-name .note { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.avatar {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--text-2); font-weight: 650; font-size: 13px; position: relative;
}
.avatar .dot { position: absolute; right: -2px; bottom: -2px; border: 2px solid var(--surface); width: 12px; height: 12px; box-shadow: none; }
.live-cell { display: flex; align-items: center; gap: 10px; }
.live-cell .spark-box { width: 84px; height: 26px; flex: none; }
.rates { display: flex; flex-direction: column; font-size: 12px; font-variant-numeric: tabular-nums; line-height: 1.35; white-space: nowrap; }
.rates .r { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); }
.rates .r .swatch { width: 6px; height: 6px; border-radius: 50%; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.client-cards { display: none; }
.seen-detail { max-width: 190px; }
.card-meta { flex-basis: 100%; display: flex; gap: 12px; align-items: center; padding-left: 46px; min-width: 0; }
.client-cards .dl-btn { display: none; }
@media (max-width: 420px) { .card-meta { padding-left: 0; } }

/* Dropdown menu */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 200px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px; display: flex; flex-direction: column;
}
.menu.up { top: auto; bottom: calc(100% + 6px); }
.menu button {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; border: 0; background: transparent;
  border-radius: 7px; cursor: pointer; text-align: left; color: var(--text); font-size: 13.5px; white-space: nowrap;
}
.menu button:hover { background: var(--surface-2); }
.menu button .icon { width: 16px; height: 16px; color: var(--text-2); }
.menu button.danger, .menu button.danger .icon { color: var(--critical-text); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 80; background: rgba(8, 8, 8, 0.45);
  display: grid; place-items: center; padding: 20px; animation: fade 0.12s ease-out;
}
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 40px); overflow: auto;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); animation: pop 0.14s ease-out;
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 22px 4px; }
.modal-head h2 { font-size: 17px; }
.modal-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.modal-body { padding: 16px 22px; display: flex; flex-direction: column; gap: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 6px 22px 20px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }

.qr-box {
  background: #fff; border-radius: 14px; padding: 10px; width: 100%; max-width: 300px; margin: 0 auto;
  border: 1px solid var(--border); aspect-ratio: 1 / 1;
}
.qr-box img { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
.connect-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 22px; align-items: start; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 12px; }
.steps li { counter-increment: step; display: flex; gap: 10px; font-size: 13.5px; color: var(--text-2); }
.steps li::before {
  content: counter(step); width: 22px; height: 22px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); font-weight: 650; font-size: 12px;
}
.share-box { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: 10px; background: var(--surface-2); }
pre.config {
  margin: 0; padding: 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
  font: 12.5px/1.55 var(--mono); overflow: auto; max-height: 420px; white-space: pre;
}

/* Toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; max-width: 420px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 13.5px; animation: pop 0.15s ease-out;
}
.toast .icon { width: 16px; height: 16px; flex: none; }
.toast.error { background: var(--critical); color: #fff; }
.toast.warning { background: var(--warning); color: #0b0b0b; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; padding: 30px; display: flex; flex-direction: column; gap: 18px; }
.login-card .brand { padding: 0; justify-content: center; flex-direction: column; text-align: center; gap: 12px; }
.login-card .brand-mark { width: 48px; height: 48px; border-radius: 14px; }
.login-card .brand-mark .icon { width: 26px; height: 26px; }
.form-error { color: var(--critical-text); font-size: 13px; background: var(--critical-soft); padding: 8px 12px; border-radius: 8px; }

/* Page header actions row (filters) */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; max-width: 360px; }

.section-title { display: flex; align-items: center; gap: 10px; }
.section-title h2 { font-size: 15px; }
.settings-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.settings-nav { position: sticky; top: 80px; }
.save-bar {
  position: sticky; bottom: 16px; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
}

.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.main-side { grid-template-columns: minmax(0, 1fr); }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { position: static; }
}
@media (max-width: 860px) {
  .sidebar {
    inset: auto 0 0 0; width: auto; height: 64px; flex-direction: row; padding: 6px 8px;
    border-right: 0; border-top: 1px solid var(--border); padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .sidebar .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; flex: 1; text-align: center; }
  .nav .badge { display: none; }
  .main { margin-left: 0; padding-bottom: 72px; }
  .topbar { padding: 12px 16px; }
  .content { padding: 4px 16px 32px; gap: 16px; }
  .banners { padding: 0 16px; }
  .grid { gap: 16px; }
  .grid.cols-3, .grid.cols-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .connect-layout { grid-template-columns: minmax(0, 1fr); }
  .client-table { display: none; }
  .client-cards { display: flex; flex-direction: column; }
  .client-cards .seen-detail { max-width: none; }
  .hide-sm { display: none !important; }
  h1 { font-size: 19px; }
  .stat-value { font-size: 24px; }
  .toolbar .search { max-width: none; min-width: 100%; }
}
@media (max-width: 520px) {
  .grid.cols-4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 20px; }
  .topbar-actions .btn .btn-text { display: none; }
  .topbar-actions .btn { padding: 0 10px; }
  .modal-backdrop { padding: 8px; align-items: end; }
  .modal { border-radius: 16px 16px 12px 12px; }
  .heatmap { gap: 2px; grid-template-columns: 28px repeat(24, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.meter-label .icon { width: 12px; height: 12px; vertical-align: -2px; margin-right: 4px; }
.stat-sub .icon { width: 14px; height: 14px; }

/* Interface rows (dashboard server card, settings tabs) */
.iface-list { display: flex; flex-direction: column; gap: 6px; }
.iface-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px;
  background: var(--surface-2); color: var(--text); text-decoration: none !important; min-width: 0;
}
.iface-row:hover { background: var(--surface-3); }
.iface-tabs { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.iface-tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-weight: 550;
}
.iface-tab:hover { color: var(--text); background: var(--surface-2); }
.iface-tab.active { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.iface-tab .muted { font-weight: 400; font-size: 12px; }
.import-result { font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.kv dd { flex-wrap: wrap; }
.kv dd > .small { white-space: nowrap; }
