/* Palette: dataviz reference palette (validated for CVD; see README). */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);

  --s-temp: #2a78d6;      /* slot 1 blue   */
  --s-heat: #eb6834;      /* slot 2 orange */
  --s-refill: #1baf7a;    /* slot 3 aqua   */
  --s-sun: #eda100;       /* slot 4 yellow */
  --s-air: #898781;       /* context series: neutral */
  --s-set: #52514e;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;

  --seq-0: #cde2fb; --seq-1: #86b6ef; --seq-2: #3987e5; --seq-3: #1c5cab; --seq-4: #0d366b;

  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);
    --s-temp: #3987e5; --s-heat: #d95926; --s-refill: #199e70; --s-sun: #c98500; --s-set: #c3c2b7;
    --good-ink: #0ca30c;
    --seq-0: #184f95; --seq-1: #1c5cab; --seq-2: #2a78d6; --seq-3: #6da7ec; --seq-4: #b7d3f6;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.05);
  --s-temp: #3987e5; --s-heat: #d95926; --s-refill: #199e70; --s-sun: #c98500; --s-set: #c3c2b7;
  --good-ink: #0ca30c;
  --seq-0: #184f95; --seq-1: #1c5cab; --seq-2: #2a78d6; --seq-3: #6da7ec; --seq-4: #b7d3f6;
}

* { box-sizing: border-box; }
html, body { background: var(--page); }
body { margin: 0; color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
.page { max-width: 1180px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 32px; }

h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0; }
h3.chart-title { font-size: 13px; font-weight: 600; margin: 18px 0 4px; color: var(--ink-2); }
.sub, .muted { color: var(--muted); }
.small { font-size: 12px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.top-right { display: flex; gap: 8px; align-items: center; }

.badge { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 12.5px; color: var(--ink-2); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.ok .dot { background: var(--good); }
.badge.stale .dot { background: var(--critical); }
.badge.warn .dot { background: var(--warning); }

.icon-btn, .ghost, .seg button {
  font: inherit; color: var(--ink-2); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.icon-btn { width: 34px; height: 30px; padding: 0; }
.icon-btn:hover, .ghost:hover, .seg button:hover { background: var(--wash); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; border-radius: 0; padding: 5px 11px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--ink); color: var(--surface); font-weight: 600; }
a.ghost { display: inline-flex; align-items: center; text-decoration: none; font-size: 12.5px; }
button:focus-visible, a.ghost:focus-visible { outline: 2px solid var(--s-temp); outline-offset: 2px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.tile .label { color: var(--ink-2); font-size: 12.5px; }
.tile .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; }
.tile.hero .value { font-size: 40px; line-height: 1.1; }
.tile .unit { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 3px; letter-spacing: 0; }
.tile .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.meter { position: relative; height: 6px; border-radius: 3px; background: var(--wash); margin-top: 10px; overflow: visible; }
.meter > div:first-child { height: 100%; border-radius: 3px; background: var(--s-temp); width: 0; transition: width .4s; }
.meter .mark { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--ink-2); border-radius: 1px; }
.state { display: inline-flex; align-items: center; gap: 8px; }
.state .ico { font-size: 18px; }
.state.on { color: var(--s-heat); }
.state.off { color: var(--ink-2); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px 18px; margin-top: 14px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--ink-2); font-size: 12.5px; margin: 6px 0 4px; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 16px; }
.sw.line { height: 2px; border-radius: 1px; }
.sw.line.dashed { height: 0; border-top: 2px dashed; background: none !important; }
.sw.band { height: 10px; border-radius: 3px; opacity: .35; }
.s-temp { background: var(--s-temp); } .s-air { background: var(--s-air); }
.s-set { border-color: var(--s-set); color: var(--s-set); }
.s-heat { background: var(--s-heat); } .s-refill { background: var(--s-refill); }
.s-rec { background: var(--s-heat); }
.stats { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: 260px; position: relative; }
.chart.short { height: 150px; }
.chart .u-over { touch-action: pan-y; }
.nav { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.nav-track { position: relative; flex: 1; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--page); overflow: hidden; cursor: pointer; touch-action: none; }
.nav-track canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.nav-thumb { position: absolute; top: 0; bottom: 0; border: 2px solid var(--s-temp); border-radius: 7px; background: color-mix(in srgb, var(--s-temp) 14%, transparent); cursor: grab; min-width: 8px; }
.nav-thumb:active { cursor: grabbing; }
.nav-span { min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 11.5px; margin: 8px 0 0; }

/* uPlot tweaks */
.uplot { font-family: var(--font); }
.u-select { background: var(--wash); border-left: 1px solid var(--axis); border-right: 1px solid var(--axis); }
.u-cursor-x { border-right: 1px solid var(--axis) !important; }
.u-cursor-y { display: none; }

/* Tooltip */
.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 12px; min-width: 150px;
  box-shadow: 0 6px 24px rgba(0,0,0,.14); font-variant-numeric: tabular-nums; }
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip .r span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tip .r b { font-weight: 600; }
.tip i { width: 10px; height: 2px; border-radius: 1px; display: inline-block; }

/* Control */
.ctl-row, .ctl-plan { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.btn { border: 1px solid var(--ink); background: var(--ink); color: var(--surface); border-radius: 9px; padding: 8px 14px; font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.btn.quiet { background: var(--surface); color: var(--ink); border-color: var(--border); font-weight: 500; }
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .45; cursor: progress; }
.ctl-temp, .ctl-plan label { color: var(--ink-2); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.ctl-row select, .ctl-plan select, .ctl-plan input { font: inherit; font-size: 13px; padding: 5px 6px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--ink); }
.plan-now { margin-top: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--page); font-size: 13.5px; }
.plan-now .mode { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-right: 8px; }
#ctlMsg.err { color: var(--critical); }
#ctlMsg.warn, td.warn, #linkLine .weak { color: var(--warning); }
.activity { margin-bottom: 10px; display: grid; gap: 6px; }
.act { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 9px 12px; border-radius: 10px; font-size: 13.5px; border: 1px solid var(--border); background: var(--page); }
.act.fill { border-color: var(--s-refill); background: color-mix(in srgb, var(--s-refill) 12%, var(--surface)); }
.act.heat { border-color: var(--s-heat); background: color-mix(in srgb, var(--s-heat) 12%, var(--surface)); }
.act.idle { color: var(--muted); }
.act .pulse { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; animation: pulse 1.4s ease-in-out infinite; }
.act.fill .pulse { background: var(--s-refill); } .act.heat .pulse { background: var(--s-heat); } .act.wait .pulse { background: var(--muted); }
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }
.btn.running { animation: pulse-btn 1.6s ease-in-out infinite; }
@keyframes pulse-btn { 50% { opacity: .6; } }
.tile.active { border-color: var(--s-refill); }
#heaterTile.active { border-color: var(--s-heat); }
#levelTile.active .meter > div { background-image: repeating-linear-gradient(-45deg, rgba(255,255,255,.35) 0 6px, transparent 6px 12px); background-size: 17px 17px; animation: stripes 1s linear infinite; }
@keyframes stripes { to { background-position: 17px 0; } }
@media (prefers-reduced-motion: reduce) { .act .pulse, .btn.running, #levelTile.active .meter > div { animation: none; } }
td.bad, #linkLine .bad { color: var(--critical); }

/* Recommendations */
.recs { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
.rec { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--page); min-width: 0; }
.rec .kind { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.rec h4 { margin: 4px 0 6px; font-size: 14.5px; line-height: 1.35; }
.rec p { margin: 0 0 6px; color: var(--ink-2); }
.rec .impact { font-weight: 650; color: var(--good-ink); }
.rec .impact.neg { color: var(--ink-2); }
.rec ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.rec ul.changes { margin: 2px 0 8px; color: var(--ink); font-size: 13.5px; font-weight: 600; }
.rec ul.changes li { margin: 2px 0; }
.rec.warning { border-color: var(--critical); }
.conf { font-weight: 600; }
.conf::before { content: "●"; margin-right: 4px; }
.conf.high::before { color: var(--good); } .conf.medium::before { color: var(--warning); } .conf.low::before { color: var(--muted); }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-top: 14px; }
.fact { background: var(--page); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; }
.fact .k { color: var(--muted); font-size: 11.5px; }
.fact .v { font-size: 16px; font-weight: 600; }
.fact .n { color: var(--muted); font-size: 11px; }

/* Heatmap */
.heat-wrap { overflow-x: auto; }
.heatmap { display: grid; grid-template-columns: 120px repeat(24, minmax(22px, 1fr)); gap: 2px; min-width: 640px; font-size: 11px; }
.heatmap .rl { color: var(--ink-2); display: flex; align-items: center; padding-right: 6px; }
.heatmap .hl { color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.heatmap .cell { height: 26px; border-radius: 4px; background: var(--wash); position: relative; cursor: default; }
.heatmap .cell.cfg { box-shadow: inset 0 0 0 2px var(--ink); }
.heat-legend { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11.5px; margin-top: 8px; }
.heat-legend .ramp { width: 120px; height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, var(--seq-0), var(--seq-1), var(--seq-2), var(--seq-3), var(--seq-4)); }
.sched-compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; margin-top: 12px; }
.sched-compare .box { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--page); }
.sched-compare .box h4 { margin: 0 0 6px; font-size: 13px; }
.sched-compare dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 12.5px; }
.sched-compare dt { color: var(--muted); }
.sched-compare dd { margin: 0; }

/* Daily */
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 4px 18px; }
.totals { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 12px; color: var(--ink-2); font-size: 13px; }
.totals b { color: var(--ink); }
.table-view { margin-top: 12px; }
.table-view summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }
.table-scroll { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; }

.foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 20px; padding-bottom: env(safe-area-inset-bottom); }
.foot .err { color: var(--critical); }

@media (max-width: 640px) {
  .top-right { flex-wrap: wrap; justify-content: flex-start; }
  .page { padding-left: 12px; padding-right: 12px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 11px 12px; }
  .tile.hero { grid-column: span 2; }
  .tile .value { font-size: 24px; }
  .tile.hero .value { font-size: 36px; }
  .card { padding: 14px 12px; }
  .chart { height: 220px; }
  .chart.short { height: 130px; }
  .seg button { padding: 6px 9px; }
  /* heat map fits the width: each row's name sits above its 24 hours */
  .heat-wrap { overflow: visible; }
  .heatmap { grid-template-columns: repeat(24, minmax(0, 1fr)); min-width: 0; gap: 2px 1px; }
  .heatmap > div:first-child { display: none; }
  .heatmap .hl { font-size: 9px; }
  .heatmap .rl { grid-column: 1 / -1; padding: 6px 0 0; }
  .heatmap .cell { height: 24px; border-radius: 2px; }
  /* daily table: main columns only, a tapped day shows the rest */
  #dTable .x { display: none; }
  #dTable th, #dTable td { padding: 6px 4px; }
  #dTable tr.drow { cursor: pointer; }
  #dTable tr.drow.open td { background: var(--wash); border-bottom: 0; }
  #dTable tr.dmore td { background: var(--wash); text-align: left; white-space: normal; }
  #dTable dl { display: grid; grid-template-columns: auto auto; gap: 2px 12px; margin: 0; font-size: 12px; }
  #dTable dt { color: var(--muted); }
  #dTable dd { margin: 0; text-align: right; }
  #ctlLog td { white-space: normal; }
}
#dTable tr.dmore { display: none; }
@media (max-width: 640px) { #dTable tr.dmore:not([hidden]) { display: table-row; } }

@media (forced-colors: active) {
  .sw.band { opacity: 1; background-image: repeating-linear-gradient(45deg, CanvasText 0 1px, transparent 1px 4px); }
}

/* ---- shared menu: account drop-down + view-only badge (core/templates/_nav.html) */
.user-menu { position: relative; }
.user-menu > summary { list-style: none; display: inline-block; font-weight: 600; }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary::after { content: " ▾"; color: var(--muted); font-weight: 400; }
.user-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 170px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12); display: grid; gap: 2px; }
.user-pop a, .user-pop button { display: block; width: 100%; text-align: left; font: inherit; font-size: 13.5px;
  color: var(--ink); background: none; border: 0; border-radius: 7px; padding: 7px 10px; cursor: pointer; text-decoration: none; }
.user-pop a:hover, .user-pop button:hover { background: var(--wash); }
.user-pop form { margin: 0; }
.badge.view-only { font-size: 12px; color: var(--ink-2); border: 1px solid var(--border); }
.badge.view-only .dot { background: var(--warning); }
