/* =====================================================================
   Hyper Optic — design system
   Navy navigation · white / light-grey surfaces · electric-blue accent ·
   emerald for positive money & network states · Inter · Lucide icons
   ===================================================================== */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/inter-latin-wght-normal.woff2") format("woff2-variations"),
       url("/static/fonts/inter-latin-wght-normal.woff2") format("woff2");
}

:root {
  color-scheme: light;
  /* surfaces */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --border: #e5e9f0;
  --border-strong: #d4dae4;
  /* ink */
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  /* brand */
  --navy: #0b1730;
  --navy-2: #12223f;
  --navy-3: #1b2e52;
  --navy-ink: #c9d4e6;
  --navy-muted: #7f8fab;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --primary-50: #eff4ff;
  --primary-100: #dbe6fe;
  /* states (always paired with icon + label) */
  --good: #059669; --good-bg: #ecfdf5; --good-border: #a7f3d0;
  --warn: #b45309; --warn-bg: #fffbeb; --warn-border: #fde68a;
  --bad: #dc2626;  --bad-bg: #fef2f2;  --bad-border: #fecaca;
  --info-bg: #eff6ff;
  /* site / series colours (validated categorical order) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s-muted: #94a3b8;
  /* chart chrome */
  --grid: #eef1f5; --axis: #cbd5e1;
  /* shape */
  --r-sm: 8px; --r: 12px; --r-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 2px 8px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .14), 0 2px 6px rgba(15, 23, 42, .06);
  --sidebar-w: 252px;
  --sidebar-w-collapsed: 76px;
  --header-h: 64px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font);
  font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }
h1, h2, h3, h4 { margin: 0; color: var(--ink); letter-spacing: -0.015em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 620; }
h3 { font-size: 13.5px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.small { font-size: 12.5px; } .xs { font-size: 11.5px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.strong { font-weight: 600; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.hide { display: none !important; }
.hide-lg { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ic { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: -4px; }
.ic.sm { width: 15px; height: 15px; vertical-align: -3px; }
.ic.lg { width: 22px; height: 22px; }

/* ------------------------------------------------------------- app shell */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.app.collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

.sidebar {
  background: var(--navy); color: var(--navy-ink); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; border-right: 1px solid #0a1428; z-index: 40;
}
.sb-brand { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 16px 16px 10px; min-height: var(--header-h); }
.sb-logo { display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 12px; padding: 4px 12px;
  box-shadow: 0 1px 0 rgba(255,255,255,.06), 0 4px 14px rgba(0,0,0,.25); }
.sb-logo .brand-logo { height: 58px; width: auto; display: block; }
.sb-logo .brand-mark { display: none; width: 30px; height: 30px; }
.sb-slogan { color: var(--navy-muted); font-size: 11px; letter-spacing: .04em; text-align: center; white-space: nowrap; }
.brand-logo, .brand-mark { display: block; height: auto; max-width: 100%; }
.sb-scroll { flex: 1; overflow-y: auto; padding: 6px 12px 12px; scrollbar-width: thin; scrollbar-color: var(--navy-3) transparent; }
.sb-group { margin-top: 14px; }
.sb-group-title { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--navy-muted);
  padding: 0 10px 6px; white-space: nowrap; }
.sb-link { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px; color: var(--navy-ink);
  font-weight: 500; font-size: 13.5px; white-space: nowrap; position: relative; }
.sb-link .ic { color: var(--navy-muted); }
.sb-link:hover { background: var(--navy-2); color: #fff; }
.sb-link:hover .ic { color: #fff; }
.sb-link.active { background: var(--navy-3); color: #fff; }
.sb-link.active .ic { color: #60a5fa; }
.sb-link.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #3b82f6; }
.sb-badge { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: #7f1d1d; color: #fecaca; }
.sb-foot { border-top: 1px solid var(--navy-2); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; min-width: 0; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; font-size: 13px;
  background: #1e3a6b; color: #dbeafe; flex: none; text-transform: uppercase; }
.sb-user-text { min-width: 0; line-height: 1.2; }
.sb-user-text b { display: block; color: #fff; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.sb-user-text span { color: var(--navy-muted); font-size: 11.5px; }
.sb-collapse { background: transparent; border: 0; color: var(--navy-muted); cursor: pointer; display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: 8px; font: inherit; font-size: 13px; }
.sb-collapse:hover { background: var(--navy-2); color: #fff; }
.app.collapsed .sb-slogan, .app.collapsed .sb-group-title, .app.collapsed .sb-link span, .app.collapsed .sb-user-text,
.app.collapsed .sb-collapse span, .app.collapsed .sb-badge { display: none; }
.app.collapsed .sb-brand { align-items: center; padding-left: 0; padding-right: 0; }
.app.collapsed .sb-logo { background: transparent; box-shadow: none; padding: 0; }
.app.collapsed .sb-logo .brand-logo { display: none; }
.app.collapsed .sb-logo .brand-mark { display: block; }
.app.collapsed .sb-link, .app.collapsed .sb-collapse { justify-content: center; }
.app.collapsed .sb-user { justify-content: center; }
.app.collapsed .sb-group { margin-top: 10px; border-top: 1px solid var(--navy-2); padding-top: 10px; }
.app.collapsed .sb-group:first-child { border-top: 0; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--header-h); background: rgba(255,255,255,.92); backdrop-filter: saturate(1.6) blur(8px);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 14px; padding: 0 28px;
}
.topbar .btn.tb-menu { display: none; }
.tb-title { min-width: 0; flex: 1; }
.tb-title h1 { font-size: 17px; font-weight: 640; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-title .crumbs { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.sync-pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 99px; background: var(--surface); white-space: nowrap; }
.sync-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px var(--good-bg); }
.sync-pill.warn .dot { background: #f59e0b; box-shadow: 0 0 0 3px var(--warn-bg); }
.sync-pill.bad .dot { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }

.content { padding: 24px 28px 48px; max-width: 1480px; width: 100%; margin: 0 auto; }

/* ------------------------------------------------------------- page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 24px; font-weight: 680; letter-spacing: -0.02em; }
.page-head .sub { color: var(--muted); margin-top: 3px; font-size: 13.5px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-size: 13.5px; font-weight: 550;
  height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--ink-2); cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm); transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); border-color: #c3cad6; color: var(--ink); }
.btn:focus-visible, .input:focus-visible, select:focus-visible, .sb-link:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad-border); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm.icon { width: 30px; }
.btn.block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

/* ------------------------------------------------------------- forms */
.input, select, textarea {
  font: inherit; font-size: 13.5px; color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); height: 36px; padding: 0 11px; min-width: 0; box-shadow: var(--shadow-sm);
}
textarea { height: auto; padding: 9px 11px; }
select { padding-right: 30px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 15px; }
.input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .field > label { font-size: 12.5px; font-weight: 550; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.field .input, .field select { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; align-items: end; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.check { display: flex; gap: 11px; align-items: flex-start; cursor: pointer; }
.check input { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--primary); flex: none; }
.input.inline { height: 30px; width: auto; padding: 0 8px; display: inline-block; }
.input.w-xs { width: 76px; }
input[type=time].input.w-xs { width: 112px; }
.search { position: relative; flex: 1; min-width: 200px; }
.search .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search .input { width: 100%; padding-left: 36px; }

/* ------------------------------------------------------------- filters bar */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 20px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 3px; gap: 2px;
  box-shadow: var(--shadow-sm); overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg a, .seg button { border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 550; color: var(--muted); padding: 5px 11px;
  border-radius: 6px; cursor: pointer; white-space: nowrap; }
.seg a:hover, .seg button:hover { color: var(--ink); background: var(--surface-3); }
.seg .on { background: var(--primary-50); color: var(--primary-600); box-shadow: inset 0 0 0 1px var(--primary-100); }
.filter-pop { position: relative; }
.filter-pop > summary { list-style: none; }
.filter-pop > summary::-webkit-details-marker { display: none; }
.pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 25; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-lg); padding: 14px; min-width: 280px; }
.pop .form-grid { grid-template-columns: 1fr 1fr; }
.filters .spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 99px; border: 1px solid var(--border-strong);
  background: var(--surface); font-size: 12.5px; color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.chip.on { border-color: var(--primary); color: var(--primary-600); background: var(--primary-50); }
a.chip:hover { border-color: var(--primary); }

/* ------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; flex-wrap: wrap; }
.card-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.card-body { padding: 16px 20px 20px; }
.card-body.flush { padding: 8px 0 4px; }
.card-foot { border-top: 1px solid var(--border); padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid, .kpis + .card, .kpis + .grid, .notice + .card { margin-top: 18px; }
.grid { display: grid; gap: 18px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-12 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 26px 0 12px; }
.section-title h2 { font-size: 16px; }

/* ------------------------------------------------------------- KPI cards */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpis.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis.k5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 16px 18px;
  min-width: 0; display: flex; flex-direction: column; gap: 6px; position: relative; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 12.5px; font-weight: 550; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-50); color: var(--primary); flex: none; }
.kpi-icon.good { background: var(--good-bg); color: var(--good); }
.kpi-icon.warn { background: var(--warn-bg); color: var(--warn); }
.kpi-icon.bad { background: var(--bad-bg); color: var(--bad); }
.kpi-icon.navy { background: #eef2fb; color: var(--navy-3); }
.kpi-icon .ic { width: 17px; height: 17px; }
.kpi-value { font-size: 26px; font-weight: 680; letter-spacing: -0.025em; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value .unit { font-size: 14px; font-weight: 550; color: var(--muted); margin-right: 3px; letter-spacing: 0; }
.kpi-sub { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; font-size: 12px; padding: 1px 6px; border-radius: 6px; }
.delta.up { color: var(--good); background: var(--good-bg); }
.delta.down { color: var(--bad); background: var(--bad-bg); }
.delta .ic { width: 13px; height: 13px; vertical-align: -2px; }
.kpi.hero { background: linear-gradient(180deg, #0f2449 0%, var(--navy) 100%); border-color: var(--navy); color: #fff; }
.kpi.hero .kpi-label { color: #9fb2d3; }
.kpi.hero .kpi-value { color: #fff; font-size: 30px; }
.kpi.hero .kpi-value .unit { color: #9fb2d3; }
.kpi.hero .kpi-sub { color: #9fb2d3; }
.kpi.hero .kpi-icon { background: rgba(96,165,250,.16); color: #93c5fd; }
.kpi.hero .delta.up { background: rgba(16,185,129,.18); color: #6ee7b7; }
.kpi.hero .delta.down { background: rgba(248,113,113,.18); color: #fca5a5; }

/* ------------------------------------------------------------- badges & status */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px;
  border: 1px solid transparent; white-space: nowrap; line-height: 18px; }
.badge .ic { width: 13px; height: 13px; vertical-align: -2px; }
.badge.good { color: #047857; background: var(--good-bg); border-color: var(--good-border); }
.badge.warning, .badge.serious { color: #92400e; background: var(--warn-bg); border-color: var(--warn-border); }
.badge.critical, .badge.bad { color: #b91c1c; background: var(--bad-bg); border-color: var(--bad-border); }
.badge.neutral { color: var(--ink-2); background: var(--surface-3); border-color: var(--border); }
.badge.info { color: var(--primary-600); background: var(--primary-50); border-color: var(--primary-100); }
.sdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.sdot.good { background: #10b981; box-shadow: 0 0 0 3px var(--good-bg); }
.sdot.warning { background: #f59e0b; box-shadow: 0 0 0 3px var(--warn-bg); }
.sdot.critical { background: #ef4444; box-shadow: 0 0 0 3px var(--bad-bg); }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; vertical-align: 0; }
.k-1 { background: var(--s1); } .k-2 { background: var(--s2); } .k-3 { background: var(--s3); } .k-4 { background: var(--s4); } .k-5 { background: var(--s5); } .k-muted { background: var(--s-muted); }
.site-name { display: inline-flex; align-items: center; gap: 8px; font-weight: 550; color: var(--ink); white-space: nowrap; }

/* ------------------------------------------------------------- tables (become cards on phones) */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted);
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { padding-left: 20px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 20px; }
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: #fafbfd; }
.tbl tr.dim td { opacity: .5; }
.tbl .n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 650; border-top: 1px solid var(--border-strong); background: var(--surface-2); }
.tbl td.wrap { white-space: normal; }
.tbl a.row-link { color: var(--ink); font-weight: 550; }
.tbl a.row-link:hover { color: var(--primary); }
.tbl .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.tbl.compact td { padding-top: 8px; padding-bottom: 8px; }

/* ------------------------------------------------------------- charts */
.chart { position: relative; height: 280px; }
.chart.sm { height: 200px; }
.chart.lg { height: 320px; }
.chart canvas { position: absolute; inset: 0; }
.chart.loading::after { content: ""; position: absolute; inset: 8px 0; border-radius: 10px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%); background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 3px; width: 14px; border-radius: 2px; }
.as-table { margin-top: 10px; }
.as-table > summary { cursor: pointer; font-size: 12.5px; color: var(--primary); list-style: none; display: inline-flex; gap: 4px; align-items: center; }
.as-table > summary::-webkit-details-marker { display: none; }
.spark { height: 46px; position: relative; }
.chart.spark { height: 46px; }

/* meters / bars */
.meter { height: 8px; border-radius: 99px; background: var(--surface-3); position: relative; overflow: hidden; }
.meter > span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
.meter > .proj { opacity: .28; }
.meter .good { background: #10b981; } .meter .warning { background: #f59e0b; } .meter .serious { background: #f97316; }
.meter .critical { background: #ef4444; } .meter .primary { background: var(--primary); } .meter .neutral { background: var(--s-muted); }
.meter.thin { height: 6px; }
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 140px) 1fr auto; gap: 12px; align-items: center; font-size: 13px; }
.hbar .lab { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .val { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; min-width: 60px; }
.hbar .meter { height: 10px; }

/* ------------------------------------------------------------- site cards */
.site-card { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.site-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.site-card-head h3 { font-size: 16px; display: flex; align-items: center; gap: 9px; }
.site-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; }
.site-stats div span { display: block; font-size: 11.5px; color: var(--muted); font-weight: 550; }
.site-stats div b { font-size: 15.5px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
a.card.site-card { color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.card.site-card:hover { border-color: #c7d2fe; box-shadow: var(--shadow-lg); }

/* stat list */
.stat-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; }
.stat-list > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 14px; min-width: 0; }
.stat-list span { display: block; font-size: 12px; color: var(--muted); font-weight: 550; }
.stat-list b { display: block; font-size: 19px; font-weight: 680; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-list small { font-size: 12px; color: var(--muted); }

dl.facts { display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; margin: 0; font-size: 13.5px; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 550; text-align: right; font-variant-numeric: tabular-nums; }

/* list rows (alerts, activity) */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 20px; border-top: 1px solid var(--border); min-width: 0; }
.list-row:first-child { border-top: 0; }
.list-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-2); flex: none; }
.list-icon.good { background: var(--good-bg); color: var(--good); } .list-icon.warning { background: var(--warn-bg); color: var(--warn); }
.list-icon.critical { background: var(--bad-bg); color: var(--bad); } .list-icon.info { background: var(--primary-50); color: var(--primary); }
.list-main { min-width: 0; flex: 1; }
.list-main b { display: block; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-main span { display: block; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-side { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.list-side b { display: block; font-weight: 650; }
.list-side span { font-size: 12px; color: var(--muted); }

/* pagination */
.pager { display: flex; align-items: center; gap: 6px; }
.pager .info { font-size: 12.5px; color: var(--muted); margin-right: 6px; }

/* empty & loading states */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .empty-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--surface-3); color: var(--faint); display: grid; place-items: center; margin: 0 auto 12px; }
.empty b { display: block; color: var(--ink); font-size: 14.5px; margin-bottom: 4px; }
.empty p { max-width: 380px; margin: 0 auto 14px; font-size: 13px; }
.topline { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 100; pointer-events: none; overflow: hidden; }
body.is-loading .topline::before { content: ""; position: absolute; top: 0; bottom: 0; width: 40%; background: var(--primary); animation: topline 1s ease-in-out infinite; }
@keyframes topline { 0% { left: -40%; } 100% { left: 100%; } }

/* notices & toasts */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface); font-size: 13.5px; }
.notice + .notice { margin-top: 10px; }
.notice.warning { background: var(--warn-bg); border-color: var(--warn-border); color: #78350f; }
.notice.critical { background: var(--bad-bg); border-color: var(--bad-border); color: #7f1d1d; }
.notice.info { background: var(--info-bg); border-color: var(--primary-100); color: #1e3a8a; }
.notice.good { background: var(--good-bg); border-color: var(--good-border); color: #064e3b; }
.notice .ic { margin-top: 1px; }
.notices { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.toasts { position: fixed; top: 76px; right: 20px; z-index: 90; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; background: var(--navy); color: #e2e8f0; padding: 12px 14px; border-radius: var(--r);
  box-shadow: var(--shadow-lg); font-size: 13.5px; animation: toast-in .2s ease-out; }
.toast .ic { color: #6ee7b7; }
.toast.error .ic { color: #fca5a5; }
.toast button { background: none; border: 0; color: #94a3b8; cursor: pointer; padding: 0; margin-left: auto; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* modal */
dialog.modal { border: 0; border-radius: var(--r-lg); padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); color: var(--ink); }
dialog.modal::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-2); }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 10px 14px; font-weight: 550; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--primary-600); border-bottom-color: var(--primary); }

/* login */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-brand { background: radial-gradient(1200px 600px at 10% 0%, #15315f 0%, var(--navy) 55%); color: #dbe4f3; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-logo { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.auth-logo-card { background: #fff; border-radius: 14px; padding: 12px 20px; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.auth-logo-card .brand-logo { height: 72px; width: auto; }
.auth-slogan { color: #9fb2d3; font-size: 13px; letter-spacing: .05em; padding-left: 4px; }
.auth-logo-m { flex-direction: column; align-items: flex-start; gap: 6px; margin-bottom: 28px; }
.auth-logo-m .brand-logo { height: 48px; width: auto; }
.auth-brand h2 { color: #fff; font-size: 30px; letter-spacing: -0.03em; line-height: 1.2; max-width: 420px; }
.auth-brand p { color: #9fb2d3; max-width: 420px; margin-top: 12px; font-size: 15px; }
.auth-points { display: flex; flex-direction: column; gap: 12px; margin-top: 28px; }
.auth-points div { display: flex; gap: 10px; align-items: center; color: #c9d4e6; }
.auth-points .ic { color: #60a5fa; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; background: var(--surface); }
.auth-card { width: min(380px, 100%); }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }

/* bottom nav + more sheet (phones) */
.bottom-nav { display: none; }
.sheet { position: fixed; inset: 0; z-index: 60; display: none; }
.sheet.open { display: block; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; background: var(--surface); border-radius: 18px 18px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: sheet-in .2s ease-out; }
@keyframes sheet-in { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 2px 10px; }
.sheet-brand .brand-logo { height: 40px; width: auto; }
.sheet-brand span { color: var(--muted); font-size: 12px; }
.sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: 4px auto 12px; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sheet-grid a { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 14px 6px; border-radius: var(--r); background: var(--surface-2);
  border: 1px solid var(--border); color: var(--ink-2); font-size: 12.5px; font-weight: 550; text-align: center; }
.sheet-grid a.active { border-color: var(--primary); color: var(--primary-600); background: var(--primary-50); }
.sheet-grid .ic { width: 22px; height: 22px; }
.drawer-backdrop { display: none; }

/* utilities */
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.mt-0 { margin-top: 0 !important; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.gap-6 { gap: 6px; }
.w-full { width: 100%; }
.right { text-align: right; }

/* ===================================================== responsive */
@media (max-width: 1280px) {
  .kpis.k5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-21, .g-12 { grid-template-columns: minmax(0, 1fr); }
}
/* tablet: sidebar becomes a drawer */
@media (max-width: 1023px) {
  .app, .app.collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 272px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .app.drawer-open .sidebar { transform: none; }
  .app.drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 35; }
  .app.collapsed .sb-slogan, .app.collapsed .sb-group-title, .app.collapsed .sb-link span, .app.collapsed .sb-user-text { display: block; }
  .app.collapsed .sb-brand { align-items: stretch; padding-left: 16px; padding-right: 16px; }
  .app.collapsed .sb-logo { background: #fff; padding: 7px 12px; }
  .app.collapsed .sb-logo .brand-logo { display: block; }
  .app.collapsed .sb-logo .brand-mark { display: none; }
  .app.collapsed .sb-link, .app.collapsed .sb-collapse { justify-content: flex-start; }
  .sb-collapse { display: none; }
  .topbar .btn.tb-menu { display: inline-flex; }
  .topbar { padding: 0 20px; }
  .content { padding: 20px 20px 40px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .hide-lg { display: flex !important; }
}
/* phones */
@media (max-width: 767px) {
  body { font-size: 14px; }
  .topbar { padding: 0 16px; height: 56px; gap: 10px; }
  .topbar .btn.tb-menu { display: none; }
  .tb-title h1 { font-size: 16px; }
  .sync-pill .txt { display: none; }
  .sync-pill { padding: 6px; border: 0; background: transparent; }
  .tb-actions .hide-sm { display: none; }
  .content { padding: 16px 16px calc(92px + env(safe-area-inset-bottom)); }
  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 20px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .kpis, .kpis.k3, .kpis.k5 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 13px 14px; }
  .kpi-value { font-size: 20px; }
  .kpi.hero { grid-column: 1 / -1; }
  .kpi.hero .kpi-value { font-size: 26px; }
  .kpi-icon { width: 28px; height: 28px; }
  .g-2, .g-3 { grid-template-columns: minmax(0, 1fr); }
  .grid { gap: 14px; }
  .card + .card, .grid + .card, .card + .grid, .grid + .grid, .kpis + .card, .kpis + .grid { margin-top: 14px; }
  .card-head { padding: 14px 16px 0; }
  .card-body { padding: 14px 16px 16px; }
  .card-foot { padding: 12px 16px; }
  .chart { height: 230px; }
  .chart.lg { height: 250px; }
  .filters { gap: 8px; }
  .filters > * { max-width: 100%; }
  .filters select, .filters .search { flex: 1 1 100%; }
  .btn { height: 40px; }
  .btn.sm { height: 34px; }
  .input, select { height: 40px; font-size: 16px; }   /* 16px stops iOS zooming */
  .site-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hbar { grid-template-columns: 90px 1fr auto; }
  .list-row { padding: 11px 16px; }
  .toasts { top: 64px; right: 16px; left: 16px; max-width: none; }
  .pop { position: fixed; left: 16px; right: 16px; top: auto; bottom: calc(80px + env(safe-area-inset-bottom)); min-width: 0; }

  /* tables -> cards */
  .tbl.cards thead { display: none; }
  .tbl.cards, .tbl.cards tbody, .tbl.cards tr, .tbl.cards td, .tbl.cards tfoot { display: block; width: 100%; }
  .tbl.cards tr { border-bottom: 1px solid var(--border); padding: 10px 16px; }
  .tbl.cards tbody tr:last-child { border-bottom: 0; }
  .tbl.cards td { border: 0; padding: 3px 0 !important; display: flex; justify-content: space-between; gap: 12px; white-space: normal; text-align: right; }
  .tbl.cards td::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; font-weight: 500; text-align: left; flex: none; }
  .tbl.cards td.lead { font-size: 15px; padding-bottom: 6px !important; }
  .tbl.cards td.lead::before { display: none; }
  .tbl.cards td.lead > * { text-align: left; }
  .tbl.cards td:empty { display: none; }
  .tbl.cards tbody tr:hover td { background: transparent; }
  .tbl.cards tfoot tr { padding: 10px 16px; background: var(--surface-2); }
  .tbl.cards tfoot td { background: transparent; border: 0; }
  .tbl.cards .n { text-align: right; }

  /* bottom navigation */
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: rgba(255,255,255,.97); backdrop-filter: blur(10px); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; color: var(--muted);
    font: inherit; font-size: 11px; font-weight: 550; background: none; border: 0; cursor: pointer; border-radius: 10px; min-height: 52px; justify-content: center; }
  .bottom-nav .ic { width: 22px; height: 22px; }
  .bottom-nav .active { color: var(--primary); }
  .bottom-nav .active .ic { stroke-width: 2.3; }
}
@media (max-width: 380px) {
  .kpi-value { font-size: 18px; }
  .site-stats div b { font-size: 14px; }
  .seg a, .seg button { padding: 5px 9px; }
}

@media print {
  .sidebar, .topbar, .bottom-nav, .filters, .page-actions, .toasts { display: none !important; }
  .app { display: block; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
