/* JS Meter Hub - design tokens, layout and components. Light + dark (OS setting or toggle). */
:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --sunken: #ecebe6;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #7a7873;
  --hairline: rgba(11, 11, 11, .10);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --brand: #1b2240;          /* twilight navy */
  --brand-ink: #f4f3ee;
  --brand-2: #2b3563;
  --sun: #f2a33a;            /* solar amber, chrome accent only */
  --accent: #2459b8;         /* links / primary buttons */
  --accent-ink: #ffffff;
  --focus: #2a78d6;
  /* chart series (reference palette, validated) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  /* status (reserved for state; always with icon + label) */
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-ink: #7a5200;
  --serious: #ec835a;
  --serious-ink: #8a3a12;
  --critical: #d03b3b;
  --critical-ink: #a32121;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --sunken: #121211;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8f8d86; --hairline: rgba(255,255,255,.10);
    --grid: #2c2c2a; --axis: #45453f; --brand: #121628; --brand-2: #1f2747; --accent: #5b8fe8; --accent-ink: #0b0b0b;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --good-ink: #3fcf3f; --warning-ink: #fab219; --serious-ink: #f29a76; --critical-ink: #f07a7a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --sunken: #121211;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #8f8d86; --hairline: rgba(255,255,255,.10);
  --grid: #2c2c2a; --axis: #45453f; --brand: #121628; --brand-2: #1f2747; --accent: #5b8fe8; --accent-ink: #0b0b0b;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --good-ink: #3fcf3f; --warning-ink: #fab219; --serious-ink: #f29a76; --critical-ink: #f07a7a;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
.icon { fill: currentColor; flex: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- shell */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--brand); color: var(--brand-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand-mark { width: 34px; height: 34px; }
.brand-name { font-weight: 650; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 11.5px; opacity: .7; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; padding: 9px 10px; border-radius: 8px; opacity: .82; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.07); opacity: 1; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.12); opacity: 1; box-shadow: inset 3px 0 0 var(--sun); }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.whoami { padding: 4px 10px; font-size: 12.5px; opacity: .85; }
.whoami strong { display: block; font-size: 13.5px; opacity: 1; }
.side-btn { display: flex; align-items: center; gap: 10px; background: none; border: 0; color: inherit; padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit; opacity: .82; text-align: left; }
.side-btn:hover { background: rgba(255,255,255,.07); opacity: 1; }
.main { min-width: 0; display: flex; flex-direction: column; }
/* Settings › Statement: a small likeness of the PDF's top (white like paper in both themes) */
.stmt-preview { background: #ffffff; color: #1a1d26; border: 1px solid var(--hairline); border-radius: 8px; padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.stmt-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-height: 34px; }
.stmt-logo { max-height: 34px; max-width: 45%; object-fit: contain; }
.stmt-company { font-weight: 700; font-size: 13px; text-align: right; margin-left: auto; }
.stmt-rule { height: 3px; margin: 8px 0 10px; border-radius: 2px; }
.stmt-title { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.stmt-tile { display: inline-flex; flex-direction: column; gap: 2px; padding: 8px 12px; background: #f3f4f7; border-top: 3px solid; font-size: 11px; color: #5e6473; }
.stmt-tile strong { font-size: 17px; color: #1a1d26; }
.stmt-tile small { font-size: 11px; font-weight: 400; color: #5e6473; }
.check-list { border: 0; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.check-list legend { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; padding: 0; }
.check-list label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.demo-banner { padding: 8px 28px; font-size: 13px; color: var(--warning-ink); background: color-mix(in srgb, var(--warning) 18%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--warning) 45%, transparent); }
.topbar { display: flex; align-items: center; gap: 12px; padding: 18px 28px 14px; flex-wrap: wrap; }
.topbar h1 { font-size: 21px; }
.topbar .crumb { color: var(--muted); font-size: 13px; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.topbar .menu-btn { display: none; }
.view { padding: 4px 28px 40px; display: flex; flex-direction: column; gap: 18px; }
.view.loading { opacity: .55; transition: opacity .2s; }

/* --------------------------------------------------------------- pieces */
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card-title { font-size: 14.5px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title .sub { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { color: var(--ink-2); font-size: 12.5px; }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 4px; letter-spacing: -.02em; }
.stat-value small { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.hero .stat-value { font-size: 48px; line-height: 1.05; }

.btn { text-decoration: none; display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--hairline); background: var(--surface); color: var(--ink); font: inherit; font-weight: 550; padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: var(--critical); color: #fff; border-color: transparent; }
.btn-danger:hover { background: var(--critical); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-icon { background: none; border: 0; padding: 6px; border-radius: 6px; color: var(--ink-2); cursor: pointer; display: inline-flex; }
.btn-icon:hover { background: var(--surface-2); }
.btn .spin, .spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px 2px 7px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.badge-good { color: var(--good-ink); background: color-mix(in srgb, var(--good) 12%, transparent); }
.badge-good .icon { fill: var(--good); }
.badge-warning { color: var(--warning-ink); background: color-mix(in srgb, var(--warning) 18%, transparent); }
.badge-warning .icon { fill: var(--warning); }
.badge-serious { color: var(--serious-ink); background: color-mix(in srgb, var(--serious) 16%, transparent); }
.badge-serious .icon { fill: var(--serious); }
.badge-critical { color: var(--critical-ink); background: color-mix(in srgb, var(--critical) 12%, transparent); }
.badge-critical .icon { fill: var(--critical); }
.badge-neutral { color: var(--ink-2); background: var(--surface-2); border-color: var(--hairline); }
.badge-brand { color: var(--brand-ink); background: var(--brand-2); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; text-transform: none; padding: 8px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; white-space: nowrap; }
.table td.wrap, .table td .wrap { white-space: normal; min-width: 220px; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table-compact td, .table-compact th { padding: 5px 8px; font-size: 12.5px; }
.table .sub { color: var(--muted); font-size: 12px; display: block; }
.table tr.row-alert td:first-child { box-shadow: inset 3px 0 0 var(--critical); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 22px 4px; text-align: center; }
.error-text { color: var(--critical-ink); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 13.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--hairline); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; font: inherit; padding: 6px 12px; cursor: pointer; color: var(--ink-2); border-right: 1px solid var(--hairline); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.search { width: min(340px, 100%); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--grid); overflow-x: auto; }
.tabs a { padding: 9px 12px; text-decoration: none; color: var(--ink-2); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 16px; }
.form-section { border: 0; padding: 0; margin: 0 0 18px; }
.form-section legend { font-weight: 650; font-size: 13.5px; margin-bottom: 10px; padding: 0; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, .field .field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; }
.radio-card { border: 1px solid var(--hairline); border-radius: 8px; padding: 10px 12px; cursor: pointer; display: flex; gap: 9px; align-items: flex-start; background: var(--surface); }
.radio-card:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.radio-card strong { display: block; font-size: 13.5px; }
.radio-card span { font-size: 12px; color: var(--muted); }
.notes { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 12.5px; }
.callout { border-radius: 8px; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--hairline); display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; }
.callout.warn { background: color-mix(in srgb, var(--warning) 12%, var(--surface)); }
.callout.warn .icon { fill: var(--warning); }
.callout.info .icon { fill: var(--accent); }
.callout.ok .icon { fill: var(--good); }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--sunken); border: 1px solid var(--hairline); border-radius: 8px; padding: 10px 12px; overflow-x: auto; white-space: pre; }

/* live values */
.phase-table td.num strong { font-weight: 600; }
.reg-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.reg { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.reg .k { font-size: 12px; color: var(--ink-2); }
.reg .v { font-size: 18px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.reg .v small { font-size: 12px; color: var(--ink-2); font-weight: 500; margin-left: 3px; }
.reg .t { font-size: 11.5px; color: var(--muted); }

/* charts */
.chart { display: flex; flex-direction: column; gap: 8px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.key-line { width: 16px; height: 2px; border-radius: 2px; display: inline-block; }
.key-rect { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-plot { position: relative; width: 100%; min-height: 60px; }
.chart-svg { display: block; overflow: visible; }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart-svg .axis { stroke: var(--axis); stroke-width: 1; }
.chart-svg .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .unit { font-weight: 600; }
.chart-svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .area { opacity: .10; stroke: none; }
.chart-svg .dot { stroke: var(--surface); stroke-width: 2; }
.chart-svg .end-label { fill: var(--ink-2); font-size: 12px; font-weight: 600; }
.chart-svg .value-label { fill: var(--ink-2); font-size: 11.5px; font-weight: 600; }
.chart-svg .crosshair { stroke: var(--ink-2); stroke-width: 1; opacity: .5; }
.chart-svg .hit { fill: transparent; cursor: crosshair; }
.chart-svg .bar-group .hit { cursor: default; }
.chart-svg .bar-group:hover .bar, .chart-svg .bar-group:focus .bar { filter: brightness(1.15) saturate(1.1); }
.chart-svg .bar-group:focus { outline: none; }
.chart-svg .bar-group:focus .hit { fill: color-mix(in srgb, var(--ink) 5%, transparent); }
.chart-tip { position: absolute; display: none; pointer-events: none; background: var(--surface); border: 1px solid var(--hairline); box-shadow: 0 6px 24px rgba(0,0,0,.14); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; z-index: 5; min-width: 150px; }
.tip-head { color: var(--ink-2); margin-bottom: 4px; font-size: 12px; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-row strong { font-variant-numeric: tabular-nums; }
.tip-label { color: var(--ink-2); }
.chart-foot { display: flex; justify-content: flex-end; }

/* dialog & toasts */
.dialog { border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dialog-wide { width: min(980px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 12, 24, .45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--grid); }
.dialog-head h2 { font-size: 17px; }
.dialog-body { padding: 18px 20px; max-height: calc(100vh - 190px); overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--grid); }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { display: flex; align-items: center; gap: 9px; background: var(--brand); color: var(--brand-ink); padding: 10px 14px; border-radius: 9px; box-shadow: 0 8px 26px rgba(0,0,0,.25); max-width: 420px; transition: opacity .3s, transform .3s; }
.toast-success .icon { fill: #5fd35f; }
.toast-error { background: #6e1b1b; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background:
  radial-gradient(1200px 600px at 85% -10%, rgba(242,163,58,.18), transparent 60%),
  linear-gradient(160deg, #1b2240, #0f1427 70%); }
.login-card { width: min(380px, 100%); background: var(--surface); border-radius: 14px; padding: 28px; box-shadow: 0 24px 80px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { font-size: 20px; }
.login-card .brand { padding: 0 0 6px; color: var(--ink); }

.period-list { display: flex; flex-direction: column; gap: 2px; }
.period-list a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.period-list a:hover { background: var(--surface-2); }
.period-list a[aria-current="page"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); font-weight: 600; }
.billing-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 18px; align-items: start; }
.detail-row td { background: var(--surface-2); }

@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar .menu-btn { display: inline-flex; }
  .grid-2, .grid-3, .billing-layout { grid-template-columns: 1fr; }
  .topbar { padding: 14px 16px 10px; }
  .view { padding: 4px 16px 32px; }
  .hero .stat-value { font-size: 40px; }
}
@media print { .sidebar, .topbar .actions, .chart-foot, .menu-btn { display: none !important; } .app { display: block; } }
