/* KaribuNet Network Monitor - one stylesheet, design tokens on :root.
   Status colours are reserved for state and always paired with an icon + word.
   Series colours (RX blue, TX orange) are only used for chart data. */

:root {
  color-scheme: light;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f7;
  --border: #e3e8ef;
  --border-strong: #cfd7e3;
  --text: #0f1b2d;
  --text-2: #4a5872;
  --text-3: #7a879c;
  --brand: #102b4e;          /* KaribuNet navy, kept from V1-V5 */
  --brand-2: #17406f;
  --accent: #1f6fd1;
  --accent-ink: #ffffff;
  --accent-soft: #e7f0fc;
  --focus: #1f6fd1;

  --good: #0ca30c;  --good-ink: #0b6b0b;  --good-soft: #e5f6e5;
  --warn: #fab219;  --warn-ink: #8a5a00;  --warn-soft: #fff4dc;
  --serious: #ec835a;
  --bad: #d03b3b;   --bad-ink: #a42727;   --bad-soft: #fde9e9;
  --info: #1f6fd1;  --info-ink: #1c5cab;  --info-soft: #e7f0fc;

  --series-1: #2a78d6;  /* RX */
  --series-2: #eb6834;  /* TX */
  --grid: #e8edf3;

  --side-bg: #0d2342;
  --side-text: #c4d3e8;
  --side-muted: #7f95b5;
  --side-active: #ffffff;
  --side-hover: #16335c;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 43, 78, .05), 0 4px 16px rgba(16, 43, 78, .05);
  --shadow-lg: 0 12px 48px rgba(10, 25, 50, .22);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1220; --surface: #111a2b; --surface-2: #0f1727; --surface-3: #1a2539;
    --border: #1f2b40; --border-strong: #2c3a53;
    --text: #e8eef8; --text-2: #a9b6cb; --text-3: #75839b;
    --accent: #4b93f0; --accent-ink: #06101f; --accent-soft: #15284a; --focus: #6aa8f5;
    --good-ink: #4fd34f; --good-soft: #0f2a17;
    --warn-ink: #fbc24d; --warn-soft: #2e2410;
    --bad-ink: #f07a7a; --bad-soft: #351619;
    --info-ink: #7fb1f3; --info-soft: #15284a;
    --series-1: #3987e5; --series-2: #d95926; --grid: #1c273a;
    --side-bg: #070d18; --side-hover: #121d31;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220; --surface: #111a2b; --surface-2: #0f1727; --surface-3: #1a2539;
  --border: #1f2b40; --border-strong: #2c3a53;
  --text: #e8eef8; --text-2: #a9b6cb; --text-3: #75839b;
  --accent: #4b93f0; --accent-ink: #06101f; --accent-soft: #15284a; --focus: #6aa8f5;
  --good-ink: #4fd34f; --good-soft: #0f2a17;
  --warn-ink: #fbc24d; --warn-soft: #2e2410;
  --bad-ink: #f07a7a; --bad-soft: #351619;
  --info-ink: #7fb1f3; --info-soft: #15284a;
  --series-1: #3987e5; --series-2: #d95926; --grid: #1c273a;
  --side-bg: #070d18; --side-hover: #121d31;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.block { display: block; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.sprite { position: absolute; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }
/* theme.js always stamps the effective theme, so the toggle shows the other one. */
:root[data-theme="dark"] .only-light, :root[data-theme="light"] .only-dark, :root:not([data-theme]) .only-dark { display: none; }

/* ------------------------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; padding: 20px 14px; z-index: 30; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; padding: 4px 8px 22px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #2a78d6, #19b28a); display: grid; place-items: end center; grid-auto-flow: column; gap: 3px; padding: 8px 8px 9px; box-shadow: 0 6px 18px rgba(42, 120, 214, .35); }
.brand-mark span { width: 4px; background: #fff; border-radius: 2px; }
.brand-mark span:nth-child(1) { height: 7px; } .brand-mark span:nth-child(2) { height: 12px; } .brand-mark span:nth-child(3) { height: 17px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: -.01em; }
.brand-text small { color: var(--side-muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--side-text); text-decoration: none; font-weight: 500; position: relative; }
.nav a span { flex: 1; }
.nav a:hover { background: var(--side-hover); color: #fff; }
.nav a.active { background: rgba(75, 147, 240, .16); color: var(--side-active); }
.nav a.active::before { content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: #4b93f0; }
.badge { min-width: 22px; height: 20px; padding: 0 7px; border-radius: 10px; background: rgba(255, 255, 255, .12); color: #fff; font-size: 11.5px; display: inline-grid; place-items: center; font-weight: 600; }
.badge.bad { background: var(--bad); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 14px; }
.live { font-size: 12px; color: var(--side-muted); display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.whoami { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, .05); }
.whoami .who { flex: 1; display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.whoami .who strong { color: #fff; overflow: hidden; text-overflow: ellipsis; }
.whoami .who small { color: var(--side-muted); font-size: 11.5px; }
.whoami .icon-btn { color: var(--side-text); }
.whoami .icon-btn:hover { background: var(--side-hover); color: #fff; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, #4b93f0, #19b28a); color: #fff; display: grid; place-items: center; font-weight: 700; }
.scrim { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 18px 32px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid transparent; }
.topbar-title { flex: 1; min-width: 0; }
.topbar h1 { font-size: 22px; font-weight: 700; }
.topbar p { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar .menu-btn { display: none; }
.content { padding: 8px 32px 32px; display: flex; flex-direction: column; gap: 20px; max-width: 1480px; width: 100%; }
.foot { padding: 0 32px 28px; color: var(--text-3); font-size: 12px; }

/* ------------------------------------------------------------------ controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 15px; border-radius: var(--radius-sm); border: 1px solid transparent; font: 600 13.5px var(--font); cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 2px rgba(31, 111, 209, .25); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-block { width: 100%; }
.btn[disabled], .is-busy .btn-primary { opacity: .7; pointer-events: none; }
.is-busy .btn-primary .icon { animation: spin 0.9s linear infinite; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: 0; background: transparent; color: var(--text-2); display: inline-grid; place-items: center; cursor: pointer; font-size: 20px; line-height: 1; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad-ink); }
.topbar .icon-btn { border: 1px solid var(--border-strong); background: var(--surface); }

input, select, textarea { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: 14px var(--font); transition: border-color .15s, box-shadow .15s; }
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; color: var(--text); }
label small { font-weight: 400; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid.inner { gap: 14px; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.form-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
fieldset { border: 0; padding: 0; margin: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; }
.segmented input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------ cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head.pad { padding: 18px 20px 0; }
.card-head h2 { font-size: 15.5px; font-weight: 650; display: flex; align-items: center; gap: 10px; }
.card-head h2 .icon { color: var(--text-3); }
.link { font-weight: 600; font-size: 13px; text-decoration: none; }
.link:hover { text-decoration: underline; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.grid-2.even { grid-template-columns: 1fr 1fr; }
.grid-discovery { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* hero: health ring + KPIs */
.hero { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 20px; }
.health { display: flex; align-items: center; gap: 22px; background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%); color: #fff; border: 0; position: relative; overflow: hidden; }
.health::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(circle, rgba(75, 147, 240, .35), transparent 70%); }
.ring { width: 112px; height: 112px; flex: none; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; }
.ring-bg { stroke: rgba(255, 255, 255, .12); }
.ring-fg { stroke-linecap: round; transition: stroke-dasharray .8s cubic-bezier(.2, .8, .2, 1); animation: ring-in 1.1s cubic-bezier(.2, .8, .2, 1); }
.ring.good .ring-fg { stroke: #3ddc84; } .ring.warn .ring-fg { stroke: var(--warn); } .ring.bad .ring-fg { stroke: #ff6b6b; } .ring.idle .ring-fg { stroke: transparent; }
.health-text { position: relative; z-index: 1; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: 11.5px; font-weight: 700; opacity: .75; }
.health-text strong { display: block; font-size: 46px; font-weight: 750; line-height: 1.05; letter-spacing: -.03em; }
.health-text strong small { font-size: 22px; opacity: .7; margin-left: 2px; }
.health-text p { margin: 6px 0 0; color: #d4e3f5; display: flex; gap: 6px; align-items: center; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.kpis-4 { grid-template-columns: repeat(2, 1fr); }
.kpi { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--text); transition: transform .15s, box-shadow .15s, border-color .15s; padding: 16px 18px; }
a.kpi:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.kpi-label { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.kpi-label .icon { width: 16px; height: 16px; color: var(--text-3); }
.kpi strong { font-size: 30px; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; }
.kpi strong small { font-size: 15px; color: var(--text-2); font-weight: 600; }
.kpi > small { color: var(--text-3); font-size: 12px; }
.kpi .up { color: var(--good-ink); }
.kpi-alert { border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); background: linear-gradient(180deg, var(--bad-soft), var(--surface) 80%); }
.kpi-alert .kpi-label, .kpi-alert .kpi-label .icon { color: var(--bad-ink); }
.kpi-warn { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); background: linear-gradient(180deg, var(--warn-soft), var(--surface) 80%); }
.kpi-warn .kpi-label, .kpi-warn .kpi-label .icon { color: var(--warn-ink); }

/* ------------------------------------------------------------------ status */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px 0 8px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.chip .icon { width: 14px; height: 14px; stroke-width: 2.2; }
.chip-good { background: var(--good-soft); color: var(--good-ink); }
.chip-warn { background: var(--warn-soft); color: var(--warn-ink); }
.chip-bad { background: var(--bad-soft); color: var(--bad-ink); }
.chip-info { background: var(--info-soft); color: var(--info-ink); }
.chip-muted, .chip-paused { background: var(--surface-3); color: var(--text-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; flex: none; position: relative; }
.dot.good { background: var(--good); }
.pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; animation: pulse 2.2s ease-out infinite; }

/* device cards */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.device { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 12px; position: relative; transition: border-color .2s; }
.device:hover { border-color: var(--border-strong); }
.device.is-offline { border-color: color-mix(in srgb, var(--bad) 55%, var(--border)); background: linear-gradient(180deg, var(--bad-soft), var(--surface-2) 70%); }
.device.is-offline::before { content: ""; position: absolute; inset: -1px; border-radius: 12px; border: 2px solid var(--bad); opacity: 0; animation: alarm 2s ease-in-out infinite; pointer-events: none; }
.device.is-degraded { border-color: color-mix(in srgb, var(--warn) 60%, var(--border)); }
.device.is-paused { opacity: .6; }
.device header { display: flex; align-items: flex-start; gap: 10px; }
.device-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.device-icon.sm { width: 30px; height: 30px; }
.is-offline .device-icon { background: var(--bad-soft); color: var(--bad-ink); }
.device-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.device-name strong, .device-name small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-name small { color: var(--text-3); font-size: 12px; }
.device-metric { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: end; }
.device-metric .big { font-size: 26px; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.device-metric small { color: var(--text-3); margin-left: 3px; font-weight: 600; }
.device footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.since { color: var(--text-3); font-size: 12px; white-space: nowrap; }
.device-extra { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); border-top: 1px dashed var(--border); padding-top: 10px; }

/* availability */
.avail { display: flex; align-items: center; gap: 8px; min-width: 120px; flex: 1; max-width: 190px; }
.avail-track { flex: 1; height: 6px; }
.avail-bg { fill: var(--surface-3); }
.avail-fill.good { fill: var(--good); } .avail-fill.warn { fill: var(--warn); } .avail-fill.bad { fill: var(--bad); }
.avail .num { font-size: 12px; font-weight: 650; color: var(--text-2); min-width: 40px; text-align: right; }

/* sparklines */
.spark { width: 100%; height: 36px; display: block; overflow: visible; cursor: crosshair; }
.spark-wide { height: 34px; }
.spark-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-line.s1 { stroke: var(--series-1); } .spark-line.s2 { stroke: var(--series-2); }
.spark-area.s1 { fill: color-mix(in srgb, var(--series-1) 14%, transparent); }
.spark-area.s2 { fill: color-mix(in srgb, var(--series-2) 9%, transparent); }
.spark-gap { fill: var(--bad); }
.spark-cursor { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }
.spark-empty { font-size: 12px; color: var(--text-3); height: 36px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--border); border-radius: 8px; }
.chart-cell { width: 180px; min-width: 140px; }
.chart-cell.wide { width: 280px; }
.legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.s1 { background: var(--series-1); } .sw.s2 { background: var(--series-2); }
.tooltip { position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--surface); padding: 7px 10px; border-radius: 8px; font-size: 12px; box-shadow: var(--shadow-lg); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); font-variant-numeric: tabular-nums; }
.tooltip b { font-weight: 700; }
.tooltip .tt-time { opacity: .7; display: block; font-size: 11px; }
.tooltip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 5px; }

/* interface list (overview) */
.iface-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; }
.iface-list li { display: grid; grid-template-columns: minmax(80px, 1fr) minmax(80px, 1.2fr) auto; gap: 14px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.iface-name { display: flex; flex-direction: column; min-width: 0; }
.iface-name strong { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iface-name small { color: var(--text-3); font-size: 11.5px; }
.iface-rates { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; font-weight: 600; color: var(--text-2); }
.iface-rates .icon { width: 13px; height: 13px; stroke-width: 2.4; margin-right: 3px; vertical-align: -2px; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { padding: 0 0 14px 20px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 8px; bottom: -6px; width: 1px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: ""; position: absolute; left: 0; top: 4px; width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); box-shadow: 0 0 0 3px var(--surface); }
.timeline .tl-error::after { background: var(--bad); } .timeline .tl-warning::after { background: var(--warn); } .timeline .tl-alert::after { background: var(--info); }
.tl-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tl-row time { font-size: 12px; }
.timeline p { margin: 5px 0 2px; font-size: 13px; overflow-wrap: anywhere; }
.timeline small { font-size: 12px; }

/* tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table .r { text-align: right; }
.row-muted { opacity: .6; }
.cell-main { display: flex; align-items: center; gap: 12px; }
.cell-main small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-main > div { min-width: 0; }
.cell-main strong { white-space: nowrap; }
.col-device { min-width: 210px; max-width: 280px; }
.col-note { max-width: 220px; }
.col-note .clamp { max-width: 220px; }
.clamp { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: inline-flex; gap: 2px; }
.row-actions .icon { width: 17px; height: 17px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag-dhcp-lease { background: var(--info-soft); color: var(--info-ink); }
.tag-arp { background: color-mix(in srgb, #19b28a 14%, var(--surface)); color: color-mix(in srgb, #0d7a5f 80%, var(--text)); }
.inline-edit { display: flex; gap: 4px; align-items: center; min-width: 190px; }
.inline-edit input { height: 34px; border-color: transparent; background: transparent; padding: 0 8px; font-weight: 600; }
.inline-edit input:hover { border-color: var(--border-strong); }
.inline-edit input:focus { background: var(--surface); }
.inline-edit .icon-btn { width: 30px; height: 30px; opacity: 0; transition: opacity .15s; }
.inline-edit:focus-within .icon-btn, .inline-edit:hover .icon-btn { opacity: 1; }

/* filters & tabs */
.filters { display: flex; gap: 10px; padding: 12px; flex-wrap: wrap; }
.filters select { width: auto; min-width: 150px; }
.search { position: relative; flex: 1; min-width: 220px; }
.search .icon { position: absolute; left: 12px; top: 11px; color: var(--text-3); }
.search input { padding-left: 38px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--text-2); font-weight: 600; font-size: 13px; border: 1px solid var(--border); background: var(--surface); }
.tabs a b { margin-left: 4px; color: var(--text-3); font-weight: 600; }
.tabs a.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.tabs a.active b { color: inherit; opacity: .7; }

/* empty states, prose, facts */
.empty { text-align: center; padding: 34px 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-icon { width: 54px; height: 54px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 6px; }
.empty-icon .icon { width: 26px; height: 26px; }
.empty h3 { font-size: 15.5px; }
.empty p { margin: 0 0 8px; color: var(--text-2); max-width: 440px; }
.prose p, .prose ol { margin: 0 0 12px; color: var(--text-2); }
.prose ol { padding-left: 20px; } .prose li { margin-bottom: 4px; }
.facts { margin: 0 0 14px; display: grid; gap: 0; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.facts dt { color: var(--text-2); } .facts dd { margin: 0; font-weight: 600; text-align: right; }

/* toasts */
.toasts { position: fixed; top: 18px; right: 18px; z-index: 90; display: flex; flex-direction: column; gap: 10px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px 12px 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: toast-in .35s cubic-bezier(.2, .9, .3, 1.2) both; font-weight: 500; }
.toast > span { flex: 1; padding-top: 1px; }
.toast-success > .icon { color: var(--good); } .toast-error > .icon { color: var(--bad); } .toast-info > .icon { color: var(--info); }
.toast-error { border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.toast-x { border: 0; background: none; color: var(--text-3); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; }
.toast.out { animation: toast-out .25s ease-in both; }

/* dialogs */
.dialog { border: 0; padding: 0; border-radius: 18px; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: rgba(8, 18, 36, .55); backdrop-filter: blur(3px); }
.dialog[open] { animation: pop .22s cubic-bezier(.2, .9, .3, 1.1); }
.dialog header, .dialog footer { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; gap: 10px; }
.dialog header { border-bottom: 1px solid var(--border); }
.dialog header h2 { font-size: 17px; }
.dialog footer { border-top: 1px solid var(--border); justify-content: flex-end; background: var(--surface-2); }
.dialog .form-grid { padding: 20px 22px; }
.dialog .form-grid.inner { padding: 0; }
.is-ping .mikrotik-only { display: none; }

/* ------------------------------------------------------------------ login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 20% -10%, #1d4c86 0%, transparent 60%), radial-gradient(800px 500px at 110% 110%, #0f5d55 0%, transparent 55%), #0a1a33; position: relative; overflow: hidden; }
.login-art { position: absolute; inset: 0; display: grid; place-items: center; opacity: .55; }
.mesh { width: min(900px, 140vw); }
.mesh .links path { fill: none; stroke: rgba(126, 178, 240, .35); stroke-width: 1.4; stroke-dasharray: 6 8; animation: flow 6s linear infinite; }
.mesh .nodes circle { fill: #4b93f0; filter: drop-shadow(0 0 8px #4b93f0); }
.mesh .sweep { fill: none; stroke: #3ddc84; stroke-width: 2; animation: sweep 3.2s ease-out infinite; transform-origin: 300px 260px; }
.login-card { position: relative; z-index: 1; width: min(400px, 100%); background: var(--surface); border-radius: 20px; padding: 32px; box-shadow: 0 30px 80px rgba(0, 0, 0, .45); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 22px; margin-top: 10px; }
.login-card p { margin: 0; }
.brand.big { padding: 0; color: var(--text); }
.brand.big small { color: var(--text-3); }
.alert { padding: 10px 12px; border-radius: 10px; font-size: 13px; font-weight: 500; background: var(--info-soft); color: var(--info-ink); }
.alert-error { background: var(--bad-soft); color: var(--bad-ink); }

/* ------------------------------------------------------------------ wall display (NOC screen) */
.wall .sidebar, .wall .foot, .wall .topbar-actions form, .wall .topbar .menu-btn { display: none; }
.wall .shell { grid-template-columns: 1fr; }
.wall .content { max-width: none; }
body.wall { font-size: 15px; }
body.wall .device-grid { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
body.wall .health-text strong { font-size: 60px; }

/* ------------------------------------------------------------------ motion */
.flash { animation: fade .5s ease-out; }
@keyframes pulse { 0% { transform: scale(1); opacity: .7; } 80%, 100% { transform: scale(3); opacity: 0; } }
@keyframes alarm { 0%, 100% { opacity: 0; } 50% { opacity: .55; } }
@keyframes ring-in { from { stroke-dasharray: 0 100; } }
@keyframes fade { from { opacity: .55; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }
@keyframes flow { to { stroke-dashoffset: -140; } }
@keyframes sweep { 0% { r: 10; opacity: .9; } 100% { r: 260; opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1500px) { .hide-lg { display: none; } }
@media (max-width: 1100px) {
  .hero, .grid-2, .grid-2.even, .grid-discovery { grid-template-columns: 1fr; }
  .hide-md { display: none; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 264px; transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(8, 18, 36, .5); z-index: 25; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 12px 16px; gap: 10px; }
  .topbar h1 { font-size: 18px; }
  .topbar p { display: none; }
  .content { padding: 4px 16px 24px; gap: 16px; }
  .foot { padding: 0 16px 20px; }
  .btn span { display: none; }
  .btn { padding: 0 11px; }
  .hide-sm { display: none; }
  [data-wall] { display: none; }
}
@media (max-width: 560px) {
  .form-grid, .segmented { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .health { gap: 16px; }
  .ring { width: 88px; height: 88px; }
  .health-text strong { font-size: 38px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi strong { font-size: 24px; }
  .device-grid { grid-template-columns: 1fr; }
  .table th, .table td { padding: 10px 12px; }
  .iface-list li { grid-template-columns: 1fr auto; }
  .iface-list .spark { display: none; }
}
[data-live="traffic"] { display: flex; flex-direction: column; gap: 20px; }
