/* Aquasense dashboard — "ocean instrument panel".
 *
 * Tokens first, then layout, then components. Everything that carries colour
 * reads a custom property, so light and dark are one block each and charts
 * (SVG, drawn by lib/charts.js) restyle with no JavaScript.
 *
 * Status colours are always paired with an icon and a word in the markup; the
 * colour is the third channel, never the only one. */

:root {
  color-scheme: light;
  --font: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #e9f2f5;
  --bg-glow: radial-gradient(1100px 520px at 12% -8%, rgba(20, 160, 150, .14), transparent 62%),
             radial-gradient(900px 480px at 100% 0%, rgba(56, 130, 200, .10), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f3f8fa;
  --surface-3: #e5eff3;
  --line: #d5e3e9;
  --line-strong: #b6cbd5;
  --text: #0a2230;
  --text-2: #3d5a69;
  --muted: #647e8b;

  --accent: #0e8f8a;
  --accent-ink: #0a6c68;
  --accent-soft: rgba(14, 143, 138, .12);
  --accent-line: rgba(14, 143, 138, .45);
  --on-accent: #ffffff;
  --focus: #1a73e8;

  --shadow-1: 0 1px 2px rgba(7, 34, 48, .06);
  --shadow-2: 0 1px 2px rgba(7, 34, 48, .05), 0 10px 28px -14px rgba(7, 34, 48, .22);
  --shadow-3: 0 18px 48px -12px rgba(7, 34, 48, .35);

  /* verdict bands */
  --st-excellent: #0a8f6b; --st-excellent-ink: #076f53; --st-excellent-soft: rgba(10, 143, 107, .13);
  --st-good: #4f9a1c;      --st-good-ink: #3b7612;      --st-good-soft: rgba(79, 154, 28, .14);
  --st-fair: #d39a00;      --st-fair-ink: #8a6200;      --st-fair-soft: rgba(211, 154, 0, .16);
  --st-poor: #dc6425;      --st-poor-ink: #a8470f;      --st-poor-soft: rgba(220, 100, 37, .14);
  --st-critical: #cf3a3a;  --st-critical-ink: #a82727;  --st-critical-soft: rgba(207, 58, 58, .13);
  --st-unknown: #7d929d;   --st-unknown-ink: #51666f;   --st-unknown-soft: rgba(125, 146, 157, .16);

  /* chart zones sit behind a line, so they are washes */
  --zone-ideal: rgba(10, 143, 107, .10);
  --zone-watch: rgba(211, 154, 0, .13);
  --zone-crit: rgba(207, 58, 58, .12);
  --chart-grid: rgba(10, 34, 48, .09);
  --chart-axis: #6b8491;
  --chart-line: #0e8f8a;
  --chart-band: rgba(14, 143, 138, .16);

  --radius: 14px;
  --radius-sm: 9px;
  --sidebar: 244px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}


/* dark values are declared under both scopes: the media query follows the OS,
   the attribute follows the viewer's toggle, and the toggle wins both ways. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #050f17;
    --bg-glow: radial-gradient(1100px 560px at 10% -10%, rgba(30, 200, 185, .10), transparent 62%),
               radial-gradient(900px 520px at 100% 0%, rgba(60, 120, 220, .10), transparent 60%);
    --surface: #0b1a25;
    --surface-2: #0f2230;
    --surface-3: #143043;
    --line: #1a3345;
    --line-strong: #29495d;
    --text: #e7f3f7;
    --text-2: #a6bfcb;
    --muted: #7391a0;
    --accent: #36d1c4;
    --accent-ink: #5fe3d8;
    --accent-soft: rgba(54, 209, 196, .13);
    --accent-line: rgba(54, 209, 196, .5);
    --on-accent: #04211f;
    --focus: #6aa8ff;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, .35), 0 14px 32px -16px rgba(0, 0, 0, .7);
    --shadow-3: 0 22px 56px -12px rgba(0, 0, 0, .8);
    --st-excellent: #2fd4a0; --st-excellent-ink: #5fe6bc; --st-excellent-soft: rgba(47, 212, 160, .15);
    --st-good: #93d65a;      --st-good-ink: #b0e67f;      --st-good-soft: rgba(147, 214, 90, .15);
    --st-fair: #f3b81b;      --st-fair-ink: #f6cb55;      --st-fair-soft: rgba(243, 184, 27, .16);
    --st-poor: #f28b4c;      --st-poor-ink: #f6a574;      --st-poor-soft: rgba(242, 139, 76, .16);
    --st-critical: #ff6b6b;  --st-critical-ink: #ff9090;  --st-critical-soft: rgba(255, 107, 107, .16);
    --st-unknown: #8ba3ae;   --st-unknown-ink: #a9bdc6;   --st-unknown-soft: rgba(139, 163, 174, .16);
    --zone-ideal: rgba(47, 212, 160, .09);
    --zone-watch: rgba(243, 184, 27, .11);
    --zone-crit: rgba(255, 107, 107, .12);
    --chart-grid: rgba(167, 205, 224, .10);
    --chart-axis: #7f9cab;
    --chart-line: #36d1c4;
    --chart-band: rgba(54, 209, 196, .17);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050f17;
  --bg-glow: radial-gradient(1100px 560px at 10% -10%, rgba(30, 200, 185, .10), transparent 62%),
             radial-gradient(900px 520px at 100% 0%, rgba(60, 120, 220, .10), transparent 60%);
  --surface: #0b1a25;
  --surface-2: #0f2230;
  --surface-3: #143043;
  --line: #1a3345;
  --line-strong: #29495d;
  --text: #e7f3f7;
  --text-2: #a6bfcb;
  --muted: #7391a0;
  --accent: #36d1c4;
  --accent-ink: #5fe3d8;
  --accent-soft: rgba(54, 209, 196, .13);
  --accent-line: rgba(54, 209, 196, .5);
  --on-accent: #04211f;
  --focus: #6aa8ff;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, .35), 0 14px 32px -16px rgba(0, 0, 0, .7);
  --shadow-3: 0 22px 56px -12px rgba(0, 0, 0, .8);
  --st-excellent: #2fd4a0; --st-excellent-ink: #5fe6bc; --st-excellent-soft: rgba(47, 212, 160, .15);
  --st-good: #93d65a;      --st-good-ink: #b0e67f;      --st-good-soft: rgba(147, 214, 90, .15);
  --st-fair: #f3b81b;      --st-fair-ink: #f6cb55;      --st-fair-soft: rgba(243, 184, 27, .16);
  --st-poor: #f28b4c;      --st-poor-ink: #f6a574;      --st-poor-soft: rgba(242, 139, 76, .16);
  --st-critical: #ff6b6b;  --st-critical-ink: #ff9090;  --st-critical-soft: rgba(255, 107, 107, .16);
  --st-unknown: #8ba3ae;   --st-unknown-ink: #a9bdc6;   --st-unknown-soft: rgba(139, 163, 174, .16);
  --zone-ideal: rgba(47, 212, 160, .09);
  --zone-watch: rgba(243, 184, 27, .11);
  --zone-crit: rgba(255, 107, 107, .12);
  --chart-grid: rgba(167, 205, 224, .10);
  --chart-axis: #7f9cab;
  --chart-line: #36d1c4;
  --chart-band: rgba(54, 209, 196, .17);
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  font: 400 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg) var(--bg-glow) no-repeat fixed;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.01em; font-weight: 700; }
h1 { font-size: 1.6rem; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0; }
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
code, kbd, pre { font-family: var(--mono); font-size: .86em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 100; background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow-2); }
.skip-link:focus { top: 12px; }

/* ----------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  padding: 22px 14px 16px; border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; text-decoration: none; color: var(--text); }
.brand-mark { color: var(--accent); display: grid; place-items: center; }
.brand-name { font-weight: 800; font-size: 1.12rem; letter-spacing: -.02em; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px;
  color: var(--text-2); text-decoration: none; font-weight: 600; font-size: .93rem;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); box-shadow: inset 0 0 0 1px var(--accent-line); }
.sidebar-foot { margin-top: auto; padding: 12px 12px 0; display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .78rem; }
.live-dot-row { display: flex; align-items: center; gap: 8px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--st-excellent); box-shadow: 0 0 0 0 var(--st-excellent); animation: pulse 2.4s infinite; }
.live-dot[data-state="paused"], .live-dot[data-state="error"] { animation: none; background: var(--st-unknown); }
.live-dot[data-state="error"] { background: var(--st-critical); }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
}
.topbar-title { font-weight: 700; color: var(--text-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.main { padding: 8px 28px 56px; max-width: 1480px; width: 100%; margin: 0 auto; outline: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2); transition: all .15s var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }
.wallet-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px; border-radius: 999px; font-weight: 700; font-size: .85rem;
  text-decoration: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.wallet-chip svg { width: 16px; height: 16px; }
.wallet-chip[data-low="true"] { background: var(--st-fair-soft); border-color: var(--st-fair); color: var(--st-fair-ink); }
.user-menu { position: relative; }
.avatar.has-img { padding: 0; overflow: hidden; }
.avatar.has-img img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: linear-gradient(135deg, var(--accent-soft), var(--surface-2)); color: var(--accent-ink); font-weight: 800; cursor: pointer; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; padding: 6px; z-index: 40;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-3);
}
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-head b { display: block; }
.menu a, .menu button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 9px 12px; border: 0; background: none; text-align: left; border-radius: 8px; color: var(--text); text-decoration: none; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--surface-2); }

/* ------------------------------------------------------------ page chrome */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap; padding: 14px 0 22px; }
.page-head .eyebrow { color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
.page-head .sub { color: var(--text-2); margin-top: 6px; max-width: 70ch; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.breadcrumb { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .85rem; text-decoration: none; margin-bottom: 8px; }
.breadcrumb:hover { color: var(--text); }

.grid { display: grid; gap: 18px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1);
  padding: 20px; min-width: 0; position: relative;
}
.card.flat { box-shadow: none; }
.card.pad-0 { 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 h2 { display: flex; align-items: center; gap: 8px; }
.card-head .hint { color: var(--muted); font-size: .82rem; }
.card-pad { padding: 20px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border-radius: 11px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font-weight: 700; font-size: .9rem; cursor: pointer;
  text-decoration: none; transition: all .15s var(--ease); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--accent-line); }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: 0 6px 18px -8px var(--accent); }
.btn.primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn.danger { color: var(--st-critical-ink); border-color: color-mix(in srgb, var(--st-critical) 45%, var(--line)); }
.btn.danger:hover { background: var(--st-critical-soft); }
.btn.danger.solid { background: var(--st-critical); color: #fff; border-color: var(--st-critical); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 32px; padding: 0 11px; font-size: .82rem; border-radius: 9px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; filter: none; }
.spin { animation: spin .8s linear infinite; }

/* ----------------------------------------------------------------- inputs */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > .label { font-size: .8rem; font-weight: 700; color: var(--text-2); }
.field .help { font-size: .78rem; color: var(--muted); }
.field .err { font-size: .8rem; color: var(--st-critical-ink); font-weight: 600; }
.input, select.input, textarea.input {
  height: 40px; width: 100%; padding: 0 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); transition: border-color .15s, box-shadow .15s; appearance: none;
}
/* The compact control that sits in a row with .btn.sm: same 32px, so a select and its buttons line up. */
.input.sm, select.input.sm { height: 32px; min-height: 32px; padding-top: 0; padding-bottom: 0; padding-left: 10px; font-size: .82rem; border-radius: 9px; }
select.input.sm { padding-right: 28px; background-position: right 10px center; }
textarea.input { height: auto; padding: 10px 12px; min-height: 76px; resize: vertical; }
select.input { padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238aa4b1' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--st-critical); }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.input-icon .input { padding-left: 36px; }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.switch { position: relative; display: inline-flex; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line-strong); transition: background .2s; pointer-events: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--text-2); transition: transform .2s var(--ease), background .2s; }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--on-accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

.segmented { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line); gap: 2px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; padding: 6px 13px; border-radius: 8px; font-weight: 700; font-size: .83rem; color: var(--text-2); cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--surface); color: var(--accent-ink); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--accent-line); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 12px 16px; font-weight: 700; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px; border-radius: 999px; font-size: .82rem; font-weight: 700; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2);
}
.chip:hover { border-color: var(--accent-line); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
.tag { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 7px; font-size: .75rem; font-weight: 700; background: var(--surface-3); color: var(--text-2); }

/* -------------------------------------------------- status & presence UI */
.status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px; font-weight: 700; font-size: .78rem; white-space: nowrap; }
.status svg { width: 14px; height: 14px; flex: none; }
.status[data-status="excellent"] { background: var(--st-excellent-soft); color: var(--st-excellent-ink); }
.status[data-status="good"] { background: var(--st-good-soft); color: var(--st-good-ink); }
.status[data-status="fair"] { background: var(--st-fair-soft); color: var(--st-fair-ink); }
.status[data-status="poor"] { background: var(--st-poor-soft); color: var(--st-poor-ink); }
.status[data-status="critical"] { background: var(--st-critical-soft); color: var(--st-critical-ink); }
.status[data-status="unknown"] { background: var(--st-unknown-soft); color: var(--st-unknown-ink); }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--st-unknown); }
.pill[data-presence="online"] { color: var(--st-excellent-ink); background: var(--st-excellent-soft); border-color: transparent; }
.pill[data-presence="online"] .dot { background: var(--st-excellent); box-shadow: 0 0 0 0 var(--st-excellent); animation: pulse 2.4s infinite; }
.pill[data-presence="offline"] .dot { background: transparent; border: 2px solid var(--st-unknown); }
.pill[data-presence="never"] .dot { background: transparent; border: 2px dashed var(--st-unknown); }
.pill[data-presence="queued"] .dot, .pill[data-presence="running"] .dot { background: var(--accent); animation: pulse 1.4s infinite; }
.pill[data-presence="failed"] { color: var(--st-critical-ink); background: var(--st-critical-soft); border-color: transparent; }
.pill[data-presence="failed"] .dot { background: var(--st-critical); }
.pill[data-presence="succeeded"] .dot { background: var(--st-excellent); }

.score-chip { display: inline-flex; align-items: baseline; justify-content: center; min-width: 46px; padding: 3px 8px; border-radius: 9px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-chip[data-status="excellent"] { background: var(--st-excellent-soft); color: var(--st-excellent-ink); }
.score-chip[data-status="good"] { background: var(--st-good-soft); color: var(--st-good-ink); }
.score-chip[data-status="fair"] { background: var(--st-fair-soft); color: var(--st-fair-ink); }
.score-chip[data-status="poor"] { background: var(--st-poor-soft); color: var(--st-poor-ink); }
.score-chip[data-status="critical"] { background: var(--st-critical-soft); color: var(--st-critical-ink); }
.score-chip[data-status="unknown"] { background: var(--st-unknown-soft); color: var(--st-unknown-ink); }

/* ------------------------------------------------------------------ cards */
.hero { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 28px; align-items: center; }
.hero .ring-wrap { width: 190px; }
.hero h1 { font-size: 1.9rem; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.kpi { text-align: left; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.kpi .k { font-size: .76rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .v { font-size: 1.55rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.kpi .v small { font-size: .8rem; font-weight: 600; color: var(--muted); letter-spacing: 0; }

.stackbar { display: flex; height: 14px; gap: 2px; border-radius: 7px; overflow: hidden; }
.stackbar span { display: block; min-width: 4px; }
.stackbar span:first-child { border-radius: 7px 3px 3px 7px; } .stackbar span:last-child { border-radius: 3px 7px 7px 3px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; font-size: .82rem; color: var(--text-2); }
.legend .item { display: inline-flex; align-items: center; gap: 7px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.sw[data-status="excellent"], .bg-excellent { background: var(--st-excellent); }
.sw[data-status="good"], .bg-good { background: var(--st-good); }
.sw[data-status="fair"], .bg-fair { background: var(--st-fair); }
.sw[data-status="poor"], .bg-poor { background: var(--st-poor); }
.sw[data-status="critical"], .bg-critical { background: var(--st-critical); }
.sw[data-status="unknown"], .bg-unknown { background: var(--st-unknown); }

.param-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.ptile {
  display: flex; flex-direction: column; gap: 8px; text-align: left; padding: 14px; border-radius: 13px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2); color: inherit; transition: all .15s var(--ease);
}
.ptile:hover { border-color: var(--accent-line); transform: translateY(-1px); box-shadow: var(--shadow-2); }
.ptile .name { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; font-size: .88rem; }
.ptile .val { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.ptile .val small { font-size: .78rem; font-weight: 600; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.ptile .meta { font-size: .76rem; color: var(--muted); }
.meter { height: 6px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 4px; transition: width .5s var(--ease); }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .73rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th button { all: unset; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }
.table th button:hover { color: var(--text); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); 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 .num, .table td.right, .table th.right, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td:first-child { min-width: 190px; }
.table a.cell-link { color: var(--text); font-weight: 700; text-decoration: none; }
.table a.cell-link:hover { color: var(--accent-ink); }
.table .sub { color: var(--muted); font-size: .78rem; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar .input-icon { flex: 1; min-width: 190px; max-width: 340px; }
.toolbar select.input { width: auto; min-width: 140px; }

/* ----------------------------------------------------------- heatmap grid */
.heat { overflow: auto; position: relative; }
.heat-grid { display: grid; gap: 3px; min-width: min-content; font-size: .78rem; }
.heat-head { font-size: .68rem; font-weight: 700; color: var(--text-2); text-align: center; padding: 0 2px 6px; white-space: nowrap; align-self: end; line-height: 1.15; }
.heat-head span { display: block; font-weight: 600; font-size: .68rem; color: var(--muted); }
.heat-row-label { display: flex; align-items: center; gap: 8px; padding-right: 10px; font-weight: 700; white-space: nowrap; min-width: 0; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.heat-row-label a { color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.heat-row-label a:hover { color: var(--accent-ink); }
.heat-cell {
  height: 32px; min-width: 46px; border-radius: 7px; display: grid; place-items: center; font-weight: 800; font-variant-numeric: tabular-nums; font-size: .78rem;
  border: 0; cursor: default; padding: 0; color: #fff;
}
.heat-cell[data-status="excellent"] { background: var(--st-excellent); color: #02261b; }
.heat-cell[data-status="good"] { background: var(--st-good); color: #112a02; }
.heat-cell[data-status="fair"] { background: var(--st-fair); color: #2c1f00; }
.heat-cell[data-status="poor"] { background: var(--st-poor); color: #2e1203; }
.heat-cell[data-status="critical"] { background: var(--st-critical); color: #fff; }
:root[data-theme="dark"] .heat-cell[data-status="critical"] { color: #2a0606; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .heat-cell[data-status="critical"] { color: #2a0606; } }
.heat-cell[data-status="empty"] { background: repeating-linear-gradient(45deg, transparent 0 5px, var(--chart-grid) 5px 6px); color: var(--muted); font-weight: 600; }
.heat-cell:focus-visible, .heat-cell:hover { outline: 2px solid var(--text); outline-offset: 1px; z-index: 2; }
.heat-cell.off { opacity: .55; }

/* --------------------------------------------------------------------- map */
.map { height: 420px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); position: relative; z-index: 0; }
.map.tall { height: 100%; min-height: 420px; }
.map.mini { height: 220px; }
:root[data-theme="dark"] .leaflet-tile-pane { filter: brightness(.62) contrast(1.05) saturate(.7) hue-rotate(180deg) invert(1) hue-rotate(180deg) brightness(.95); }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .leaflet-tile-pane { filter: brightness(.62) contrast(1.05) saturate(.7) hue-rotate(180deg) invert(1) hue-rotate(180deg) brightness(.95); } }
.leaflet-container { font-family: var(--font); background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--shadow-3); }
.leaflet-popup-content { margin: 14px 16px; min-width: 190px; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--line); }
.leaflet-bar a:hover { background: var(--surface-2); }
.map-marker { position: relative; }
.map-marker .core { position: absolute; inset: 6px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 2px 6px rgba(0, 0, 0, .35); }
.map-marker .halo { position: absolute; inset: 0; border-radius: 50%; opacity: .45; }
.map-marker.online .halo { animation: ring-pulse 2.4s infinite; }
.map-marker.offline .core { background: var(--surface-3) !important; border: 3px dashed var(--st-unknown); }
.map-marker.offline .halo { display: none; }
.map-pop h4 { margin-bottom: 6px; }
.map-pop .line { display: flex; gap: 8px; align-items: center; margin: 4px 0; font-size: .85rem; }
.map-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; z-index: 500; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(3px); }

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart svg text { font-family: var(--font); fill: var(--chart-axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--line-strong); stroke-width: 1; }
.chart .zone-ideal { fill: var(--zone-ideal); } .chart .zone-watch { fill: var(--zone-watch); } .chart .zone-crit { fill: var(--zone-crit); }
.chart .band { fill: var(--chart-band); }
.chart .line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--chart-band); opacity: .55; }
.chart .dot { fill: var(--chart-line); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; }
.chart .zone-label { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; opacity: .85; }
.chart .endlabel { font-weight: 700; fill: var(--text); font-size: 12px; }
.chart:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.chart-empty { display: grid; place-items: center; min-height: 140px; text-align: center; color: var(--muted); padding: 20px; border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--surface-2); }
.tooltip {
  position: fixed; z-index: 300; pointer-events: none; padding: 10px 12px; border-radius: 10px; font-size: .8rem; line-height: 1.4; min-width: 150px; max-width: 280px;
  background: color-mix(in srgb, var(--surface) 96%, transparent); border: 1px solid var(--line-strong); box-shadow: var(--shadow-3); color: var(--text);
}
.tooltip .t-title { font-weight: 800; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; color: var(--text-2); }
.tooltip .t-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.tooltip .t-status { margin-top: 6px; }

.ring { display: block; width: 100%; height: auto; }
.ring .track { fill: none; stroke: var(--surface-3); }
.ring .arc { fill: none; stroke-linecap: round; transition: stroke-dashoffset .8s var(--ease); }
.ring text { font-family: var(--font); fill: var(--text); }
.ring .big { font-weight: 800; letter-spacing: -.03em; font-variant-numeric: proportional-nums; }
.ring .small { fill: var(--muted); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.ring .tick { stroke: var(--text); stroke-width: 2; stroke-linecap: round; }

.rangebar { position: relative; height: 30px; margin: 4px 0 2px; }
.rangebar .zones { position: absolute; left: 0; right: 0; top: 11px; height: 8px; display: flex; border-radius: 5px; overflow: hidden; gap: 2px; }
.rangebar .zones i { display: block; height: 100%; }
.rangebar .z-crit { background: var(--st-critical); opacity: .55; }
.rangebar .z-watch { background: var(--st-fair); opacity: .6; }
.rangebar .z-ideal { background: var(--st-excellent); opacity: .7; }
.rangebar .marker { position: absolute; top: 3px; width: 4px; height: 24px; margin-left: -2px; border-radius: 3px; background: var(--text); box-shadow: 0 0 0 2px var(--surface); transition: left .5s var(--ease); }
.rangebar .tickline { position: absolute; top: 0; width: 1px; height: 30px; background: var(--muted); opacity: .6; }
.rangeaxis { position: relative; height: 16px; font-size: .68rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.rangeaxis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }

.spark { display: block; }
.spark path.line { fill: none; stroke: var(--chart-line); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.spark path.area { fill: var(--chart-band); opacity: .6; stroke: none; }

/* ---------------------------------------------------------------- devices */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.dcard { display: flex; flex-direction: column; gap: 14px; text-decoration: none; color: inherit; transition: all .18s var(--ease); }
.dcard:hover { border-color: var(--accent-line); transform: translateY(-2px); box-shadow: var(--shadow-2); }
.dcard.offline { background: color-mix(in srgb, var(--surface) 70%, var(--surface-2)); }
.dcard-top { display: flex; align-items: center; gap: 14px; }
.dcard-top .ring-wrap { width: 68px; flex: none; }
.dcard .name { font-weight: 800; font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dcard .id { color: var(--muted); font-size: .78rem; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.weak { display: flex; flex-direction: column; gap: 7px; }
.weak-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; font-size: .84rem; }
.weak-row .l { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--text-2); font-weight: 600; }
.weak-row .l svg { width: 14px; height: 14px; flex: none; }
.weak-row b { font-variant-numeric: tabular-nums; }
.dcard-foot { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .78rem; border-top: 1px solid var(--line); padding-top: 12px; }

.gauge-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.gauge { padding: 14px 16px; border-radius: 13px; border: 1px solid var(--line); background: var(--surface-2); }
.gauge-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.gauge-top .nm { font-weight: 700; font-size: .88rem; }
.gauge-top .vl { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.gauge-top .vl small { font-size: .75rem; color: var(--muted); font-weight: 600; margin-left: 3px; letter-spacing: 0; }
.gauge .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: .76rem; color: var(--muted); }

.chart-card h3 { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.chart-card .stat { display: flex; gap: 18px; color: var(--muted); font-size: .78rem; margin-bottom: 10px; flex-wrap: wrap; }
.chart-card .stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.small-multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }

/* ---------------------------------------------------------------- reports */
.report-hero { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px; align-items: center; }
.risk-list, .action-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.risk-list li { display: flex; gap: 10px; align-items: flex-start; }
.risk-list svg { width: 18px; height: 18px; color: var(--st-poor); flex: none; margin-top: 2px; }
.action { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.action .why { color: var(--text-2); font-size: .86rem; margin-top: 2px; }
.prio { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 6px; font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; align-self: start; margin-top: 2px; }
.prio[data-p="urgent"] { background: var(--st-critical); color: #fff; }
.prio[data-p="high"] { background: var(--st-poor-soft); color: var(--st-poor-ink); box-shadow: inset 0 0 0 1px var(--st-poor); }
.prio[data-p="medium"] { background: var(--st-fair-soft); color: var(--st-fair-ink); }
.prio[data-p="low"] { background: var(--surface-3); color: var(--text-2); }
:root[data-theme="dark"] .prio[data-p="urgent"] { color: #2a0606; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .prio[data-p="urgent"] { color: #2a0606; } }
.pcard { display: flex; flex-direction: column; gap: 14px; }
.pcard-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pcard-head h3 { font-size: 1.02rem; }
.scorebar { position: relative; height: 10px; border-radius: 6px; background: var(--surface-3); }
.scorebar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; transition: width .6s var(--ease); }
.scorebar .base { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); border-radius: 2px; opacity: .8; }
.scorebar-meta { display: flex; justify-content: space-between; font-size: .76rem; color: var(--muted); margin-top: 6px; }
.trend { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; font-weight: 700; color: var(--text-2); }
.trend svg { width: 16px; height: 16px; }
.trend[data-t="worsening"] { color: var(--st-poor-ink); } .trend[data-t="improving"] { color: var(--st-excellent-ink); } .trend[data-t="volatile"] { color: var(--st-fair-ink); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 18px; }
.kv div { font-size: .8rem; color: var(--muted); }
.kv b { display: block; color: var(--text); font-size: .95rem; font-variant-numeric: tabular-nums; }
details.disclose { border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
details.disclose > summary { cursor: pointer; padding: 11px 14px; font-weight: 700; font-size: .86rem; list-style: none; display: flex; align-items: center; gap: 8px; color: var(--text-2); }
details.disclose > summary::-webkit-details-marker { display: none; }
details.disclose > summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
details.disclose[open] > summary::before { transform: rotate(45deg); }
details.disclose .body { padding: 4px 14px 14px; }
ul.plain { margin: 0; padding-left: 18px; color: var(--text-2); }
ul.plain li { margin: 3px 0; }
.progress-card { text-align: center; padding: 56px 20px; }
.droplet-loader { width: 74px; height: 74px; margin: 0 auto 18px; color: var(--accent); }
.droplet-loader .wave { animation: wave 1.8s ease-in-out infinite; }
.steps { display: flex; justify-content: center; gap: 28px; margin-top: 22px; color: var(--muted); font-size: .85rem; font-weight: 600; flex-wrap: wrap; }
.steps span { display: inline-flex; align-items: center; gap: 8px; }
.steps span[data-on="true"] { color: var(--accent-ink); }
.steps i { width: 9px; height: 9px; border-radius: 50%; background: var(--surface-3); border: 2px solid var(--line-strong); }
.steps span[data-on="true"] i { background: var(--accent); border-color: var(--accent); }

/* --------------------------------------------------------------- schedule */
.sched { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.sched:last-child { border-bottom: 0; }
.sched h3 { font-size: 1rem; }
.sched .desc { color: var(--text-2); font-size: .86rem; }
.sched .meta { display: flex; gap: 8px 16px; flex-wrap: wrap; margin-top: 8px; font-size: .78rem; color: var(--muted); }
.sched .meta span { display: inline-flex; gap: 6px; align-items: center; }
.sched.paused { opacity: .7; }
.sched .actions { display: flex; gap: 6px; }

/* ----------------------------------------------------------- misc blocks */
.empty { text-align: center; padding: 44px 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty .art { width: 84px; height: 84px; color: var(--accent); opacity: .9; }
.empty h3 { font-size: 1.1rem; }
.empty p { color: var(--text-2); max-width: 46ch; }
.alert { display: flex; gap: 12px; padding: 12px 14px; border-radius: 12px; font-size: .88rem; border: 1px solid; align-items: flex-start; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.alert.warn { background: var(--st-fair-soft); border-color: var(--st-fair); color: var(--text); }
.alert.err { background: var(--st-critical-soft); border-color: var(--st-critical); color: var(--text); }
.alert.info { background: var(--accent-soft); border-color: var(--accent-line); color: var(--text); }
.codeblock { position: relative; background: #07161f; color: #d7ecf3; border-radius: 12px; padding: 14px 16px; overflow: auto; font-size: .8rem; line-height: 1.6; border: 1px solid var(--line); }
:root[data-theme="light"] .codeblock { background: #0c2230; }
.codeblock pre { margin: 0; white-space: pre; }
.codeblock .copy { position: absolute; right: 8px; top: 8px; }
.quickstart { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; counter-reset: step; }
.qs { position: relative; padding: 18px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.qs::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; background: var(--accent); color: var(--on-accent); font-weight: 800; margin-bottom: 12px; }
.qs h3 { margin-bottom: 6px; } .qs p { color: var(--text-2); font-size: .87rem; }
.secret-box { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px dashed var(--accent-line); font-family: var(--mono); font-size: .86rem; word-break: break-all; }
.kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 6px; font-size: .75rem; }

/* range bars on the reference page */
.ref-row { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.ref-row:last-child { border-bottom: 0; }
.ref-row .why { color: var(--text-2); font-size: .84rem; margin-top: 6px; }
.ref-row .basis { color: var(--muted); font-size: .78rem; margin-top: 10px; }
.ref-row .judgement { color: var(--st-fair-ink); }

/* ------------------------------------------------------------ dialog/toast */
dialog.dlg {
  border: 1px solid var(--line-strong); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-3);
  width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); overflow: hidden;
}
dialog.dlg[open] { display: flex; flex-direction: column; animation: dlg-in .22s var(--ease); }
dialog.dlg.wide { width: min(820px, calc(100vw - 24px)); }
dialog.dlg::backdrop { background: rgba(2, 10, 16, .6); backdrop-filter: blur(4px); animation: fade .2s; }
.dlg-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 24px 8px; }
.dlg-head p { color: var(--text-2); font-size: .88rem; margin-top: 4px; }
.dlg-body { padding: 14px 24px 8px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }
.dlg-foot { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding: 16px 24px 20px; border-top: 1px solid var(--line); margin-top: 8px; flex-wrap: wrap; }
.dlg-foot .spacer { flex: 1; }
.preview { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 14px; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--line); }
.preview div { font-size: .74rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.preview b { display: block; font-size: 1.2rem; color: var(--text); text-transform: none; letter-spacing: -.01em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 400; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 36px)); }
.toast { display: flex; gap: 12px; align-items: flex-start; padding: 13px 15px; border-radius: 13px; background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow-3); animation: toast-in .3s var(--ease); font-size: .88rem; }
.toast svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.toast[data-kind="success"] svg { color: var(--st-excellent); } .toast[data-kind="error"] svg { color: var(--st-critical); } .toast[data-kind="info"] svg { color: var(--accent); }
.toast b { display: block; }

/* ---------------------------------------------------------------- skeleton */
.skel { position: relative; overflow: hidden; background: var(--surface-3); border-radius: 8px; min-height: 14px; }
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent); animation: shimmer 1.4s infinite; }
.skel.block { height: 120px; border-radius: var(--radius); }
.skel.line { height: 14px; margin: 8px 0; }

/* -------------------------------------------------------------- animations */
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--st-excellent) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 8px transparent; } }
@keyframes ring-pulse { 0% { transform: scale(.7); opacity: .55; } 100% { transform: scale(1.5); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes fade { from { opacity: 0; } }
@keyframes dlg-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes wave { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.rise { animation: rise .45s var(--ease) both; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quickstart { grid-template-columns: 1fr; }
}
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 60; flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; gap: 2px; }
  .nav-link { flex-direction: column; gap: 3px; padding: 7px 6px; font-size: .68rem; flex: 1; text-align: center; border-radius: 10px; }
  .nav-link[aria-current="page"] { box-shadow: none; }
  .main { padding: 4px 16px 96px; }
  .topbar { padding: 10px 16px; }
  .cols-2, .cols-3, .report-hero, .hero { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .hero .ring-wrap, .report-hero .ring-wrap { width: 170px; margin: 0 auto; }
  .hero { text-align: center; } .hero .row { justify-content: center; }
  .ref-row { grid-template-columns: 1fr; gap: 8px; }
  .toasts { bottom: 88px; right: 12px; left: 12px; max-width: none; }
}
@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .cols-4 { grid-template-columns: 1fr 1fr; }
  .kpis { gap: 8px; }
  .kpi { padding: 10px 11px; }
  .kpi .v { font-size: 1.3rem; }
  .kpi .k { font-size: .66rem; letter-spacing: .03em; }
  .form-grid { grid-template-columns: 1fr; }
  .preview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sched { grid-template-columns: 1fr; }
  .small-multiples { grid-template-columns: 1fr; }
  .device-grid { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .wallet-chip span.long { display: none; }
  .page-head { padding-bottom: 16px; }
  .map { height: 320px; }
  .dlg-head, .dlg-body, .dlg-foot { padding-left: 18px; padding-right: 18px; }
}

/* ---- device picker, usage, live chart, alerts added with the dashboard rework ---- */
.alert.ok { background: var(--st-excellent-soft, var(--accent-soft)); border-color: var(--st-excellent, var(--accent)); color: var(--text); }
.linklike { background: none; border: 0; padding: 0; color: var(--accent-ink); cursor: pointer; font: inherit; text-decoration: underline; }
.device-picker { display: flex; flex-direction: column; gap: 10px; }
.dp-list { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.dp-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.dp-row:last-child { border-bottom: 0; }
.dp-row:hover { background: var(--accent-soft); }
.dp-name { display: flex; flex-direction: column; min-width: 0; }
.dp-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-name code { font-size: .74rem; color: var(--muted); }
.dp-summary { font-size: .82rem; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.barchart { width: 100%; }
.bar-holder { width: 100%; }
.bar-holder svg { display: block; }
.bar-holder .bar { fill: var(--accent); }
.bar-holder .bar:hover, .bar-holder .bar:focus { fill: var(--accent-ink); outline: none; }
.bar-holder .bar.zero { fill: var(--line); }
.bar-holder .grid-line { stroke: var(--line); stroke-width: 1; }
.bar-holder .axis-text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.bar-readout { min-height: 1.4em; margin-top: 6px; font-size: .84rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.share { flex: 1; height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; display: block; min-width: 50px; }
.share i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover { background: var(--accent-soft); }
.usage-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.usage-row:hover { background: var(--accent-soft); }
.live-dot-inline { display: inline-block; width: 8px; height: 8px; margin-left: 10px; border-radius: 50%; background: var(--st-excellent); box-shadow: 0 0 0 0 var(--st-excellent); animation: pulse 2s infinite; vertical-align: middle; }
@media (prefers-reduced-motion: reduce) { .live-dot-inline { animation: none; } }
.tab-panel[hidden] { display: none; }
.chip-row.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.chip-row.scroll .chip { flex: none; }

/* ---- small phones -------------------------------------------------------
   The 600px rules above reflow the layout; these make it comfortable to use
   with a thumb: inputs at 16px (iOS zooms the page on anything smaller),
   44px touch targets, dialogs as bottom sheets, nothing wider than the screen. */
@media (max-width: 600px) {
  .input, select.input, textarea.input { font-size: 16px; min-height: 44px; }
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; min-width: 40px; }
  .input.sm, select.input.sm { min-height: 40px; height: 40px; font-size: 16px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  .chip { min-height: 38px; }
  .tabs button { padding: 12px 14px; }
  .nav-link { min-height: 48px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-actions { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  .page-actions > .btn, .page-actions > .segmented, .page-actions > select { flex: 1 1 auto; }
  .page-actions .segmented { overflow-x: auto; }
  .sched .actions { flex-wrap: wrap; justify-content: flex-start; }
  .sched .meta { gap: 6px 12px; }
  .toolbar { gap: 8px; }
  .toolbar .input-icon { max-width: none; min-width: 0; flex: 1 1 100%; }
  .table td:first-child { min-width: 150px; }
  .table th, .table td { padding-left: 12px; padding-right: 12px; }
  .secret-box { flex-wrap: wrap; word-break: break-all; }
  .codeblock pre { font-size: .76rem; }
  dialog.dlg, dialog.dlg.wide { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .dlg-foot { position: sticky; bottom: 0; background: var(--surface); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .dlg-foot .btn { flex: 1 1 auto; }
  .map { height: 280px; }
  .menu { right: -8px; max-width: calc(100vw - 24px); }
  .leaflet-popup-content { min-width: 0; }
}
@media (max-width: 380px) {
  .main { padding-left: 12px; padding-right: 12px; }
  .topbar { padding-left: 12px; padding-right: 12px; }
  .wallet-chip { padding-left: 10px; padding-right: 10px; }
  .nav-link { font-size: .62rem; padding-left: 2px; padding-right: 2px; }
  .cols-4, .preview { grid-template-columns: 1fr 1fr; }
  .hero .ring-wrap, .report-hero .ring-wrap { width: 150px; }
}

/* Round icon tile at the start of a list row (channels, templates). */
.ch-ico { width: 42px; height: 42px; flex: none; display: inline-grid; place-items: center; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-ink); border: 1px solid var(--accent-line); }
.ch-ico svg { width: 20px; height: 20px; display: block; }
.sched h3 .status, .sched h3 .tag { vertical-align: middle; margin-left: 4px; font-weight: 700; }

.site-card { display: flex; flex-direction: column; gap: 8px; }
.site-attn { display: flex; align-items: center; gap: 6px; font-size: .84rem; color: var(--st-poor, #c2410c); font-weight: 600; flex-wrap: wrap; }
.site-attn a { color: inherit; }

/* ---- arrangeable widgets ------------------------------------------------ */
.arrange .widget { position: relative; border-radius: 16px; }
.arrange.editing .widget { outline: 2px dashed var(--accent-line); outline-offset: 6px; margin-top: 6px; }
.arrange.editing .widget.is-hidden > :not(.wbar) { opacity: .35; pointer-events: none; filter: grayscale(1); }
.arrange .widget.dragging { opacity: .45; }
.wbar { display: flex; align-items: center; gap: 6px; padding: 6px 8px; margin-bottom: 8px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); font-size: .85rem; }
.wbar[hidden] { display: none; }
.wbar .grip { cursor: grab; display: inline-flex; padding: 6px; border-radius: 8px; touch-action: none; }
.wbar .grip:active { cursor: grabbing; background: var(--surface); }
.wbar .btn.sm { min-height: 32px; }
.arrange-hint { font-size: .85rem; color: var(--muted); }

/* First-run onboarding: two ways in, side by side (a sensor, or a file). */
.onboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr); gap: 0; align-items: stretch; margin-top: 6px; }
.ob-side { display: flex; flex-direction: column; gap: 12px; padding: 20px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line); min-width: 0; }
.ob-side h3 { margin: 0; font-size: 1.15rem; }
.ob-lead { margin: 0; color: var(--text-2); font-size: .9rem; line-height: 1.5; }
.ob-tag { display: inline-flex; align-items: center; gap: 8px; font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ob-num { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-size: .8rem; letter-spacing: 0; }
.ob-tabs { display: flex; }
.ob-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.ob-notes { margin: 0; padding-left: 18px; color: var(--text-2); font-size: .84rem; line-height: 1.6; }
.ob-or { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.ob-or::before, .ob-or::after { content: ""; flex: 1; width: 1px; background: var(--line); }
.ob-or span { padding: 10px 0; }
.onboard-code { margin: 0; max-height: 210px; overflow: auto; font-size: .76rem; }
@media (max-width: 900px) {
  .onboard-grid { grid-template-columns: 1fr; }
  .ob-or { flex-direction: row; padding: 10px 0; }
  .ob-or::before, .ob-or::after { width: auto; height: 1px; }
  .ob-or span { padding: 0 12px; }
}

/* Navigation clock: 2026/03/10 - 22:43:01, seconds rolling in. */
.nav-clock { display: inline-flex; align-items: baseline; gap: 0; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); font-size: .82rem; font-variant-numeric: tabular-nums; letter-spacing: .01em; text-decoration: none; white-space: nowrap; }
.nav-clock:hover { border-color: var(--muted); color: var(--ink); }
.nav-clock-sep { color: var(--muted); padding: 0 .45em; }
.nav-clock-s { display: inline-flex; color: var(--ink); font-weight: 700; }
.nav-clock-zone { margin-left: 8px; font-size: .7rem; color: var(--muted); font-weight: 600; }
.cd { display: inline-block; min-width: .62em; text-align: center; }
.cd.roll { animation: cd-roll .28s cubic-bezier(.2, .8, .2, 1); }
@keyframes cd-roll { from { transform: translateY(-65%); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-width: 900px) { .nav-clock-zone { display: none; } .nav-clock { padding: 6px 8px; font-size: .76rem; } }
@media (max-width: 640px) { .nav-clock { display: none; } }

/* Overview: hint to subscribe when the account has no (active) subscription. */
.sub-hint { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; border-color: var(--accent); background: linear-gradient(135deg, var(--surface-2), transparent); }
.sub-hint-icon { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: var(--accent); color: var(--on-accent); flex: none; }
.sub-hint-body { flex: 1 1 320px; min-width: 0; }
.sub-hint-body h2 { margin: 0 0 4px; font-size: 1.15rem; }
.sub-hint-body p { margin: 0; }
.sub-hint-note { margin-top: 6px !important; font-size: .82rem; color: var(--muted); }

/* Top-bar live badge: green and pulsing only while a device is really reporting. */
.live-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); font-size: .82rem; font-weight: 600; white-space: nowrap; }
.live-badge[data-state="live"] { color: var(--st-excellent-ink, var(--ink)); border-color: color-mix(in srgb, var(--st-excellent) 45%, var(--line)); }
.live-badge .live-dot { flex: none; }
.live-dot[data-state="idle"], .live-dot[data-state="connecting"] { animation: none; background: var(--muted); }
@media (max-width: 640px) { #live-label { display: none; } .live-badge { padding: 8px; } }

/* Role-based UI: controls marked for a higher role disappear for lower ones. The server
   still enforces every rule; this only stops showing buttons that can only fail. */
html[data-role="viewer"] .needs-operator, html[data-role="viewer"] .needs-admin,
html[data-role="operator"] .needs-admin { display: none !important; }
html[data-role="viewer"] .switch { pointer-events: none; opacity: .55; }
.noaccess { display: flex; gap: 16px; align-items: flex-start; padding: 6px; }
.noaccess-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); color: var(--muted); flex: none; }
.noaccess p { margin: 4px 0 12px; }
.role-note { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); font-size: .86rem; }

/* Device > Raw events */
.ev-table td, .ev-table th { text-align: left; vertical-align: middle; }
.ev-table td.right { text-align: right; }
.ev-table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ev-vals { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.ev-chip { display: inline-flex; align-items: baseline; gap: 5px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: .8rem; font-variant-numeric: tabular-nums; }
.ev-chip b { color: var(--text-2); font-weight: 700; }
.ev-chip i { color: var(--muted); font-style: normal; font-size: .72rem; }
.ev-lag { font-size: .8rem; color: var(--text-2); }
.ev-lag[data-tone="warn"] { color: var(--st-fair-ink); font-weight: 700; }
.ev-lag[data-tone="bad"] { color: var(--st-critical-ink); font-weight: 700; }
.ev-new { animation: ev-flash 1.6s ease-out; }
@keyframes ev-flash { from { background: var(--accent-soft); } to { background: transparent; } }
.ev-raw td { padding-top: 0; background: var(--surface-2); }
.ev-empty { padding: 8px 4px 4px; }
@media (prefers-reduced-motion: reduce) { .ev-new { animation: none; } }

/* The model's short note on where a sensor is (a river, the coast), in a report. */
.loc-note { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0 0; max-width: 72ch; color: var(--text-2); font-size: .86rem; line-height: 1.45; }
.loc-note svg { flex: none; margin-top: 2px; color: var(--accent); }

/* Interface language button: the globe and the two-letter code. */
.lang-btn { display: inline-flex; align-items: center; width: auto; gap: 6px; padding: 0 10px; font-weight: 700; font-size: .78rem; letter-spacing: .04em; }
.lang-list button[aria-checked="true"] { font-weight: 700; color: var(--accent-ink); }
