:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --ink: #1d1f22;
  --muted: #6b6f76;
  --line: #e4e2dc;
  --track: #ebe9e3;
  --ok: #2f7d6d;
  --ok-soft: rgba(47, 125, 109, 0.22);
  --warn: #b97c0c;
  --warn-soft: rgba(185, 124, 12, 0.22);
  --crit: #c93c3c;
  --crit-soft: rgba(201, 60, 60, 0.2);
  --tip: #5b5fc7;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  /* chart series: Used wears --ok (or the warn/crit level), Likely + Range blue, pace guides magenta */
  --c-likely: #2a78d6;
  --c-pace: #b8489a;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  --s-rest: #b9b6ad; --s-outside: #8a8f98;
  --heat0: #eeece6; --heat-none: transparent;
  color-scheme: light;
}
/* Dark tokens: used when the page picks dark (at sunset, or "Always dark"),
   or when it follows the computer and the computer is dark. mode.js sets data-theme. */
:root[data-theme="dark"] {
  --bg: #141517;
  --card: #1d1f22;
  --ink: #ececea;
  --muted: #9a9ea6;
  --line: #2c2f33;
  --track: #2a2d31;
  --ok: #4fbf9f;
  --ok-soft: rgba(79, 191, 159, 0.22);
  --warn: #e2a93b;
  --warn-soft: rgba(226, 169, 59, 0.22);
  --crit: #ef6a6a;
  --crit-soft: rgba(239, 106, 106, 0.22);
  --tip: #9a9df0;
  --shadow: none;
  --c-likely: #3f86dc;
  --c-pace: #c95aa3;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  --s-rest: #55585e; --s-outside: #7d828a;
  --heat0: #26292d;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517;
    --card: #1d1f22;
    --ink: #ececea;
    --muted: #9a9ea6;
    --line: #2c2f33;
    --track: #2a2d31;
    --ok: #4fbf9f;
    --ok-soft: rgba(79, 191, 159, 0.22);
    --warn: #e2a93b;
    --warn-soft: rgba(226, 169, 59, 0.22);
    --crit: #ef6a6a;
    --crit-soft: rgba(239, 106, 106, 0.22);
    --tip: #9a9df0;
    --shadow: none;
    --c-likely: #3f86dc;
    --c-pace: #c95aa3;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --s-rest: #55585e; --s-outside: #7d828a;
    --heat0: #26292d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }

/* Toolbar preview: Chrome sizes popups from the page, so give it a fixed size. */
html.popup, html.popup body { width: 340px; height: 560px; }
html:not(.popup) .popup-only { display: none; }

#app { display: flex; flex-direction: column; height: 100%; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 4px 14px;
  flex: none;
}
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; min-width: 0; }
#statusText { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.stale { background: var(--warn); }
.dot.err { background: var(--crit); }
.actions { display: flex; gap: 2px; }
.icon-btn {
  width: 30px; height: 30px; border: 0; background: transparent; border-radius: 8px;
  display: grid; place-items: center; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--track); color: var(--ink); }
.icon-btn:focus-visible, .seg button:focus-visible, .btn:focus-visible { outline: 2px solid var(--ok); outline-offset: 1px; }
.icon-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.scroll { flex: 1; overflow-y: auto; padding: 0 10px 8px; display: flex; flex-direction: column; gap: 7px; }
.scroll[hidden] { display: none; }

.limit, .where, .error {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 11px 9px; box-shadow: var(--shadow);
}
.limit-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.limit-name { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.limit-pct { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1; }
.limit.lvl-warn .limit-pct { color: var(--warn); }
.limit.lvl-crit .limit-pct { color: var(--crit); }

.bar { position: relative; height: 10px; border-radius: 6px; background: var(--track); overflow: hidden; }
.bar-fill, .bar-proj {
  position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 6px;
  transition: width 0.6s ease;
}
.bar-fill { background: var(--ok); }
.bar-proj { background: var(--ok-soft); }
.lvl-warn .bar-fill { background: var(--warn); }
.lvl-warn .bar-proj { background: var(--warn-soft); }
.lvl-crit .bar-fill { background: var(--crit); }
.lvl-crit .bar-proj { background: var(--crit-soft); }

.limit-sub { margin-top: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pace { margin-top: 6px; font-size: 12px; padding: 4px 8px; border-radius: 7px; background: var(--track); }
.pace.warn { background: var(--warn-soft); color: var(--ink); }
.pace.crit { background: var(--crit-soft); color: var(--ink); }

/* tabs */
.tabs { display: flex; gap: 2px; margin: 0 10px 6px; padding: 2px; background: var(--track); border-radius: 9px; flex: none; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 5px 0; border-radius: 7px; font-size: 12px; color: var(--muted); cursor: pointer; min-height: 28px; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.tabs button:focus-visible { outline: 2px solid var(--ok); outline-offset: 1px; }
.tab-panel { display: flex; flex-direction: column; gap: 7px; }
.tab-panel[hidden] { display: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; box-shadow: var(--shadow); }
#meterView { position: relative; }

/* charts */
.chart-wrap { margin-top: 8px; }
.chart-wrap[hidden] { display: none; }
.chart-svg { display: block; width: 100%; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.chart-svg .tick { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .grid.faint { stroke-dasharray: 2 3; }
.chart-svg .axis { stroke: var(--line); stroke-width: 1; }
.chart .area { fill: var(--ok-soft); }
.chart .area-pre { fill: var(--ok-soft); opacity: 0.45; }
.chart .line { fill: none; stroke: var(--ok); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pre { stroke: var(--ok); stroke-width: 1.6; stroke-dasharray: 1.5 3.5; stroke-linecap: round; opacity: 0.75; }
.chart .band { fill: var(--c-likely); opacity: 0.16; }
.chart .likely { fill: none; stroke: var(--c-likely); stroke-width: 2; stroke-dasharray: 5 3; stroke-linecap: round; stroke-linejoin: round; }
.chart .safe { stroke: var(--c-pace); stroke-width: 1.6; stroke-dasharray: 1.5 3.5; stroke-linecap: round; }
.chart .even { stroke: var(--c-pace); stroke-width: 1.4; stroke-dasharray: 6 4; opacity: 0.85; }
.chart .reset { stroke: var(--ink); stroke-width: 1; opacity: 0.35; }
.chart .now { fill: var(--ok); }
.chart .now-ring { fill: var(--card); }
.chart .out { fill: var(--card); stroke: var(--crit); stroke-width: 2; }
.chart .cross { stroke: var(--ink); stroke-width: 1; opacity: 0.35; }
.chart.lvl-warn .line, .chart.lvl-warn .pre { stroke: var(--warn); }
.chart.lvl-warn .area, .chart.lvl-warn .area-pre { fill: var(--warn-soft); }
.chart.lvl-warn .now { fill: var(--warn); }
.chart.lvl-crit .line, .chart.lvl-crit .pre { stroke: var(--crit); }
.chart.lvl-crit .area, .chart.lvl-crit .area-pre { fill: var(--crit-soft); }
.chart.lvl-crit .now { fill: var(--crit); }

.heat .cell.snone { fill: none; stroke: var(--line); stroke-width: 1; stroke-dasharray: 1.5 1.5; }
.heat .cell.s0 { fill: var(--heat0); }
.heat .cell.s1 { fill: var(--ok); opacity: 0.2; }
.heat .cell.s2 { fill: var(--ok); opacity: 0.38; }
.heat .cell.s3 { fill: var(--ok); opacity: 0.56; }
.heat .cell.s4 { fill: var(--ok); opacity: 0.76; }
.heat .cell.s5 { fill: var(--ok); opacity: 1; }
.heat .cell-sel { fill: none; stroke: var(--ink); stroke-width: 1.5; }

.bars .seg.s1, .k-seg.s1 { fill: var(--s1); background: var(--s1); }
.bars .seg.s2, .k-seg.s2 { fill: var(--s2); background: var(--s2); }
.bars .seg.s3, .k-seg.s3 { fill: var(--s3); background: var(--s3); }
.bars .seg.s4, .k-seg.s4 { fill: var(--s4); background: var(--s4); }
.bars .seg.s5, .k-seg.s5 { fill: var(--s5); background: var(--s5); }
.bars .seg.s-rest, .k-seg.s-rest { fill: var(--s-rest); background: var(--s-rest); }
.bars .seg.s-outside, .k-seg.s-outside { fill: var(--s-outside); background: var(--s-outside); }
.bars .col-sel { fill: var(--track); }

.legend { display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 6px; font-size: 11px; color: var(--muted); }
.legend[hidden] { display: none; }
.legend span { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend span[hidden] { display: none; }
.legend i { display: inline-block; flex: none; }
/* Each swatch matches its line on the chart: same color, same dash. */
.legend .k-line { width: 14px; height: 0; border-top: 2px solid var(--ok); }
.legend .k-pre { width: 14px; height: 0; border-top: 2px dotted var(--ok); opacity: 0.75; }
.legend .k-likely { width: 14px; height: 0; border-top: 2px dashed var(--c-likely); }
.legend .k-band { width: 12px; height: 9px; border-radius: 2px; background: var(--c-likely); opacity: 0.3; }
.legend .k-safe { width: 14px; height: 0; border-top: 2px dotted var(--c-pace); }
.legend .k-even { width: 14px; height: 0; border-top: 2px dashed var(--c-pace); }
.legend .k-out { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--crit); background: var(--card); }
.lvl-warn .legend .k-line, .lvl-warn .legend .k-pre { border-color: var(--warn); }
.lvl-crit .legend .k-line, .lvl-crit .legend .k-pre { border-color: var(--crit); }
.legend .k-seg { width: 10px; height: 10px; border-radius: 3px; }
.legend.scale { gap: 3px; align-items: center; }
.legend.scale i { width: 11px; height: 11px; border-radius: 2px; background: var(--ok); }
.legend.scale i.s1 { opacity: 0.2; } .legend.scale i.s2 { opacity: 0.38; } .legend.scale i.s3 { opacity: 0.56; } .legend.scale i.s4 { opacity: 0.76; }
.legend.scale i.snone { background: none; border: 1px dashed var(--line); }
.legend.scale .gap { width: 8px; }

.stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 0; font-size: 12px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.ctip {
  position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none;
  background: var(--ink); color: var(--bg); border-radius: 8px; padding: 6px 9px;
  font-size: 11.5px; line-height: 1.35; max-width: 230px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.ctip[hidden] { display: none; }
.ctip strong { display: block; font-weight: 600; margin-bottom: 1px; }

.spark { display: block; width: 100%; height: 34px; margin-top: 6px; }
.spark.empty { display: none; }
.spark .area { fill: var(--ok-soft); }
.spark .line { fill: none; stroke: var(--ok); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.spark .proj { fill: none; stroke: var(--muted); stroke-width: 1.2; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.spark .cap { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark .now { fill: var(--ok); }
.lvl-warn .spark .line { stroke: var(--warn); }
.lvl-warn .spark .area { fill: var(--warn-soft); }
.lvl-crit .spark .line { stroke: var(--crit); }
.lvl-crit .spark .area { fill: var(--crit-soft); }

.extra { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 12px; color: var(--muted); }
.extra .xbar { flex: 1; height: 5px; border-radius: 3px; background: var(--track); overflow: hidden; }
.extra .xbar i { display: block; height: 100%; background: var(--muted); }
.extra b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }

.where-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.section-title { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.seg { display: flex; background: var(--track); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 3px 8px; border-radius: 6px; font-size: 11.5px; color: var(--muted); cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: baseline; }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .name small { color: var(--muted); margin-left: 4px; }
.row .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.row .rbar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.row .rbar i { display: block; height: 100%; background: var(--ok); border-radius: 2px; }
.row.other .rbar i { background: var(--muted); }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 11.5px; }
.hint:empty { display: none; }

.error { border-color: var(--crit-soft); font-size: 12.5px; }
.error strong { display: block; margin-bottom: 3px; }
.error p { margin: 0; color: var(--muted); }
.error[hidden] { display: none; }

#verLabel { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }
#settingsView h2 { font-size: 14px; margin: 4px 2px 2px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.field select { background: var(--track); border: 0; border-radius: 6px; padding: 4px 6px; }
.field input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--ok); flex: none; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.btn:hover { background: var(--track); }
.btn.primary { background: var(--ok); color: #fff; border-color: transparent; margin-left: auto; }
.diag { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 11px; }
.diag summary { cursor: pointer; color: var(--muted); }
.diag pre { white-space: pre-wrap; word-break: break-word; font-size: 11px; margin: 8px 0 0; color: var(--muted); }

.ticker {
  flex: none; height: 34px; border-top: 1px solid var(--line); background: var(--card);
  overflow: hidden; position: relative; display: flex; align-items: center;
  mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
}
.ticker-track {
  display: flex; white-space: nowrap; will-change: transform;
  animation: scroll var(--dur, 40s) linear infinite;
}
.ticker:hover .ticker-track, .ticker.paused .ticker-track { animation-play-state: paused; }
.ticker-item { display: inline-flex; align-items: center; gap: 6px; padding: 0 22px 0 0; font-size: 12.5px; }
.ticker-item::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); flex: none; }
.ticker-item.warn::before { background: var(--crit); }
.ticker-item.warn { color: var(--crit); font-weight: 600; }
.ticker-item.tip::before { background: var(--tip); }
@keyframes scroll { from { transform: translateX(0); } to { transform: translateX(-50%); } }

@media (prefers-reduced-motion: reduce) {
  .ticker-track { animation: none; }
  .bar-fill, .bar-proj { transition: none; }
}
.field[hidden] { display: none; }
.quiet { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }

/* Quick View / Detailed View */
.viewseg { display: flex; flex: none; background: var(--track); border-radius: 8px; padding: 2px; margin-left: 6px; }
.viewseg button { border: 0; background: transparent; padding: 3px 8px; min-height: 26px; border-radius: 6px; font-size: 11.5px; color: var(--muted); cursor: pointer; }
.viewseg button[aria-checked="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.viewseg button:focus-visible { outline: 2px solid var(--ok); outline-offset: 1px; }
.top { gap: 4px; }
.status { flex: 1; }
body.quick .tabs,
body.quick .chart-wrap,
body.quick .legend,
body.quick .where,
body.quick #extraLimits { display: none; }
body.quick .limit { padding: 11px 12px; }
body.quick .limit-pct { font-size: 30px; }
body.quick .bar { height: 12px; }
.extra .xname { flex: none; max-width: 52%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.extra .xname small { margin-left: 5px; font-size: 10px; padding: 0 4px; border-radius: 4px; background: var(--track); }
#extraLimits .hint { margin-top: 6px; }
.pace .pace-head { display: block; }
.pace .pace-detail { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }
.field .field-hint { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }
