/* Hearth. Light and dark are both chosen palettes: the dark values are stepped for the dark surface, not inverted.
   Series colours (--s1…--s6, --t-*) were checked with the dataviz palette validator against both surfaces. */
:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --raised: #ffffff;
  --ink: #0b0b0b; --ink2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11, 11, 11, .10); --wash: rgba(11, 11, 11, .045); --wash2: rgba(11, 11, 11, .08);
  --s0: #898781; --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
  --t-out: #6250d6; --t-flow: #eda100; --t-dhw: #1baf7a;
  --good: #006300; --critical: #d03b3b; --focus: #2a78d6;
  --shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 8px 24px rgba(11, 11, 11, .05);
  --r: 14px; --gap: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --raised: #222220;
    --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, .10); --wash: rgba(255, 255, 255, .05); --wash2: rgba(255, 255, 255, .09);
    --s0: #898781; --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
    --t-out: #9085e9; --t-flow: #c98500; --t-dhw: #199e70;
    --good: #0ca30c; --critical: #e66767; --focus: #6da7ec;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --raised: #222220;
  --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, .10); --wash: rgba(255, 255, 255, .05); --wash2: rgba(255, 255, 255, .09);
  --s0: #898781; --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
  --t-out: #9085e9; --t-flow: #c98500; --t-dhw: #199e70;
  --good: #0ca30c; --critical: #e66767; --focus: #6da7ec;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--raised); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--border); }
.top-in { max-width: 1240px; margin: 0 auto; padding: 0 24px; height: 60px; display: flex; align-items: center; gap: 28px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.brand svg { display: block; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a { text-decoration: none; padding: 7px 12px; border-radius: 9px; color: var(--ink2); font-weight: 500; }
.tabs a:hover { background: var(--wash); color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--wash2); color: var(--ink); }
.top-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.live { display: inline-flex; align-items: center; gap: 8px; color: var(--ink2); font-size: 13px; font-variant-numeric: tabular-nums; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 50%, transparent); animation: pulse 2.4s ease-out infinite; }
.live.stale .live-dot { background: var(--muted); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 45%, transparent); } 70%, 100% { box-shadow: 0 0 0 7px transparent; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--ink2); }
.icon-btn:hover { background: var(--wash); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; display: block; }

.tabbar { display: none; }
.notice { max-width: 1240px; margin: 16px auto 0; padding: 0 24px; }
.notice-in { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--wash); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; color: var(--ink2); font-size: 14px; }
.notice-in strong { color: var(--ink); font-weight: 600; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border); color: var(--ink2); background: var(--surface); }

/* ---------- layout ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 24px 24px 64px; outline: none; }
.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: 26px; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; }
.page-head p { color: var(--ink2); margin-top: 2px; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; } .span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
.stack { display: grid; gap: var(--gap); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { font-size: 16px; font-weight: 620; letter-spacing: -.005em; }
.card-head p { color: var(--ink2); font-size: 13.5px; margin-top: 2px; max-width: 70ch; }
.card-head .aside { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.link { color: var(--ink2); text-decoration: none; font-size: 13.5px; font-weight: 500; white-space: nowrap; }
.link:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.sub { color: var(--ink2); font-size: 13.5px; }
.muted { color: var(--muted); }
.panel-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 14px 0 2px; }
.panel-title:first-child { margin-top: 0; }
.panel-title h3 { font-size: 13.5px; font-weight: 600; color: var(--ink2); }
.insight { font-size: 15px; line-height: 1.5; max-width: 62ch; }
.insight strong { font-weight: 650; }
.insight + .insight { margin-top: 6px; color: var(--ink2); font-size: 13.5px; }

/* ---------- hero and tiles ---------- */
.hero { display: flex; flex-direction: column; justify-content: space-between; gap: 22px; min-height: 100%; }
.hero-label { color: var(--ink2); font-weight: 500; }
.hero-value { font-size: 64px; font-weight: 650; letter-spacing: -.035em; line-height: 1; margin-top: 8px; display: flex; align-items: baseline; gap: 10px; }
.hero-value small { font-size: 26px; font-weight: 550; color: var(--ink2); letter-spacing: -.01em; }
.hero-legend { display: grid; gap: 8px; margin-top: 12px; }
.hero-legend .legend-item { justify-content: flex-start; font-size: 14px; }
.hero-legend .legend-item strong { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.tiles { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tiles.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.tiles.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.tile-label { color: var(--ink2); font-size: 13.5px; font-weight: 500; }
.tile-value { font-size: 30px; font-weight: 640; letter-spacing: -.025em; line-height: 1.15; margin-top: 6px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.tile-value small { font-size: 15px; font-weight: 550; color: var(--ink2); letter-spacing: 0; }
.tile-sub { color: var(--ink2); font-size: 13px; margin-top: 4px; }
.delta { font-weight: 600; white-space: nowrap; }
.delta.down { color: var(--good); }

/* ---------- keys, legends, tooltips ---------- */
.key { display: inline-block; flex: none; }
.key-line { width: 14px; height: 3px; border-radius: 2px; }
.key-box { width: 10px; height: 10px; border-radius: 3px; }
.legend { display: flex; gap: 6px 16px; flex-wrap: wrap; align-items: center; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink2); white-space: nowrap; }
.tip { position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; opacity: 0; transition: opacity .08s; background: var(--raised); color: var(--ink); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); font-size: 13px; min-width: 150px; max-width: 300px; will-change: transform; }
.tip.on { opacity: 1; }
.tip-title { color: var(--ink2); font-size: 12px; margin-bottom: 6px; font-variant-numeric: tabular-nums; }
.tip-row { display: flex; align-items: center; gap: 8px; padding: 1.5px 0; }
.tip-name { color: var(--ink2); }
.tip-val { margin-left: auto; padding-left: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip-note { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ---------- uPlot ---------- */
.chart { width: 100%; min-width: 0; }
.uplot { font-family: inherit; }
.u-cursor-x { border-right: 1px solid var(--axis) !important; }
.u-select { background: var(--wash2) !important; }
.u-cursor-pt { box-shadow: none !important; }
.rate-strip { position: relative; height: 6px; margin-top: -2px; }
.rate-seg { position: absolute; top: 0; height: 6px; border-radius: 2px; background: color-mix(in oklab, var(--ink) calc(14% + 56% * var(--level)), var(--surface)); }
.rate-key { width: 12px; height: 6px; border-radius: 2px; background: color-mix(in oklab, var(--ink) calc(14% + 56% * var(--level)), var(--surface)); }

/* ---------- filters ---------- */
.filters { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; margin-bottom: 16px; }
.seg-ctl { display: inline-flex; background: var(--wash); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 2px; }
.seg-ctl button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--ink2); font-weight: 500; font-size: 14px; white-space: nowrap; }
.seg-ctl button:hover { color: var(--ink); }
.seg-ctl button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 1px var(--border); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper input[type="date"] { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; height: 36px; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 7px 13px; cursor: pointer; font-weight: 550; font-size: 14px; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }
.btn:hover { background: var(--wash); }
.btn.primary { background: var(--ink); color: var(--page); border-color: var(--ink); }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--critical); }
.btn:disabled { opacity: .5; cursor: default; }
.filters .spacer { flex: 1; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th { color: var(--ink2); font-weight: 500; font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
td.name { display: flex; align-items: center; gap: 10px; font-weight: 550; }
.toggle { display: inline-flex; align-items: center; gap: 10px; background: none; border: 0; padding: 2px 4px 2px 0; cursor: pointer; font-weight: 550; text-align: left; }
.toggle .key { transition: opacity .1s; }
.toggle[aria-pressed="false"] { color: var(--muted); }
.toggle[aria-pressed="false"] .key { opacity: .25; }
tr.off td { color: var(--muted); }
details.more { margin-top: 12px; }
details.more summary { cursor: pointer; color: var(--ink2); font-size: 13.5px; font-weight: 500; width: fit-content; }
details.more[open] summary { margin-bottom: 8px; }

/* ---------- bars ---------- */
.bars { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; }
.bars-y { position: relative; min-width: 24px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bars-y .sizer { visibility: hidden; font-style: normal; white-space: nowrap; display: block; height: 0; }
.bars-y span { position: absolute; right: 0; transform: translateY(50%); white-space: nowrap; line-height: 1; }
.bars-y.line-y, .bars-plot.line-plot { margin-top: 22px; }
.bars-plot { position: relative; }
.bars-grid span { position: absolute; left: 0; right: 0; height: 1px; background: var(--grid); }
.bars-cols { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); }
.bar-col { position: relative; display: flex; align-items: flex-end; justify-content: center; background: none; border: 0; padding: 0; min-width: 0; border-radius: 6px; cursor: default; }
button.bar-col { cursor: pointer; }
.bar-col:hover, .bar-col:focus-visible { background: var(--wash); }
.bar-col.ghost:hover { background: var(--wash); }
.bar-stack { display: flex; flex-direction: column-reverse; gap: 2px; width: min(24px, 68%); min-height: 0; }
.seg { display: block; min-height: 1px; flex-basis: 0; }
.seg.top { border-radius: 4px 4px 0 0; }
.bar-col.faint .seg { opacity: .55; }
.bars-x { display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); margin-top: 8px; font-size: 12px; color: var(--muted); }
.bars-x span { text-align: center; white-space: nowrap; display: flex; justify-content: center; overflow: visible; }
.line-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.line-dots span { position: absolute; width: 8px; height: 8px; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 0 2px var(--surface); }

/* ---------- parts of a whole ---------- */
.segbar { display: flex; gap: 2px; height: 8px; border-radius: 99px; overflow: hidden; }
.segbar-part { min-width: 2px; flex-basis: 0; }
.segbar.tall { height: 28px; border-radius: 0; overflow: visible; }
.segbar.tall .segbar-part { border-radius: 4px; display: flex; align-items: center; padding: 0 8px; font-size: 12.5px; font-weight: 600; }

/* ---------- hour-by-day grid ---------- */
.hg { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; align-items: center; }
.hg-label { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; line-height: 1; }
.hg-row, .hg-hours { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 2px; }
.hg-cell { height: 13px; border-radius: 2.5px; background: color-mix(in oklab, var(--hg) calc(8% + 92% * var(--f)), var(--surface)); }
.hg-cell.none { background: var(--wash); }
.hg-cell:hover, .hg-cell:focus-visible { outline: 2px solid var(--ink); outline-offset: 0; }
.hg-hours { margin-top: 6px; font-size: 12px; color: var(--muted); }
.hg-scale { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink2); }
.hg-ramp { display: inline-grid; grid-auto-flow: column; gap: 2px; }
.hg-ramp span { width: 16px; height: 10px; border-radius: 2px; background: color-mix(in oklab, var(--hg) calc(8% + 92% * var(--f)), var(--surface)); }

/* ---------- runs strip ---------- */
.runs { margin-left: 54px; margin-right: 24px; }
.runs-track { position: relative; height: 22px; background: var(--wash); border-radius: 5px; }
.run { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.run:hover, .run:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.runs-axis { position: relative; height: 18px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.runs-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.runs-axis span:first-child { transform: none; }
.runs-axis span:last-child { transform: translateX(-100%); }

/* ---------- forms ---------- */
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); align-items: start; }
label.field { display: grid; gap: 6px; font-size: 13.5px; color: var(--ink2); font-weight: 500; }
.field input, .field select, td input, td select { background: var(--raised); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; min-width: 0; width: 100%; color: var(--ink); height: 38px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
td input, td select { width: auto; max-width: 100%; }
td.edit { text-align: left; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.status { font-size: 13.5px; color: var(--ink2); }
.status.err { color: var(--critical); }
.status.ok { color: var(--good); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; font-size: 14px; }
.kv dt { color: var(--ink2); } .kv dd { margin: 0; }
code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--wash); padding: 2px 6px; border-radius: 6px; }

.empty { text-align: center; padding: 64px 20px; color: var(--ink2); }
.empty h2 { color: var(--ink); font-size: 20px; margin-bottom: 8px; }
.signin { max-width: 360px; margin: 12vh auto 0; }
.signin h1 { font-size: 22px; margin-bottom: 6px; }
.signin form { display: grid; gap: 12px; margin-top: 18px; }
.loading { opacity: .55; transition: opacity .15s; pointer-events: none; }

/* ---------- smaller screens ---------- */
@media (max-width: 1020px) {
  .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
  .tiles.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  :root { --gap: 12px; }
  .top-in { padding: 0 16px; height: 54px; }
  .tabs { display: none; }
  main { padding: 16px 16px 96px; }
  .notice { padding: 0 16px; margin-top: 12px; }
  .card { padding: 16px; }
  .page-head h1 { font-size: 22px; }
  .hero-value { font-size: 52px; }
  .tiles, .tiles.six, .tiles.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile { padding: 14px; }
  .tile-value { font-size: 24px; }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--border); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { display: grid; justify-items: center; gap: 3px; padding: 6px 2px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 550; border-radius: 10px; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--ink); }
  .seg-ctl { max-width: 100%; overflow-x: auto; }
  .filters .spacer { display: none; }
  .runs { margin-left: 0; margin-right: 0; }
  .hg-cell { height: 11px; }
  .hg-hours span:nth-child(even) { display: none; }
}
