/* Vivere Colorado — Dashboard and Engines.
   An app shell, not a document. The page itself never scrolls; each region owns its
   own overflow, so the thing you are working on stays put while you work on it.

   The scroll rule: any list that can grow without bound is either capped with a
   "see all" that changes view, or put on a horizontal snap rail. Vertical scroll is
   for reading, not for navigating. */

@layer tokens, base, shell, parts, viz, print, motion;

@layer tokens {
  :root {
    --forest: #16281f;  --forest-2: #1d3529;  --forest-3: #24402f;
    --gold: #caa03d;    --gold-2: #e6c877;    --gold-dim: #8a6a1f;
    --cream: #f3ead9;   --ink: #0c1410;

    --bg: #0f1713;      --panel: #14201a;     --panel-2: #1a2a21;
    --line: #24382c;    --line-2: #2f4a3a;
    --txt: #e4e9e3;     --mut: #8fa294;       --dim: #6b7d71;

    --stop: #d9563a;    --warn: #d9a13c;      --ok: #4aa06a;   --info: #5b93c4;

    --rail: 62px;       --hdr: 56px;   --sub: 44px;
    --r: 10px;          --r-lg: 14px;
    --ease: cubic-bezier(.2, .7, .3, 1);
    --shadow: 0 1px 2px rgb(0 0 0 / .28), 0 8px 24px -12px rgb(0 0 0 / .5);
  }
  @media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
      --bg: #f4f1e9; --panel: #fff; --panel-2: #faf7f0;
      --line: #e0d8c8; --line-2: #cfc4ae;
      --txt: #1b2620; --mut: #5f6f66; --dim: #8a9890;
      --shadow: 0 1px 2px rgb(60 50 30 / .07), 0 8px 24px -14px rgb(60 50 30 / .22);
    }
  }
}

@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0; background: var(--bg); color: var(--txt);
    font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-text-size-adjust: 100%; overscroll-behavior: none;
  }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; }
  h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.012em; }
  ::-webkit-scrollbar { width: 9px; height: 9px; }
  ::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

@layer shell {
  #app {
    display: grid; height: 100dvh;
    grid-template-columns: var(--rail) 1fr;
    grid-template-rows: var(--hdr) 1fr;
    grid-template-areas: "rail head" "rail main";
  }

  /* ── icon rail ── */
  #rail {
    grid-area: rail; background: var(--forest); display: flex; flex-direction: column;
    align-items: center; gap: 2px; padding: 8px 0; overflow-y: auto; overflow-x: hidden;
    scrollbar-width: none;
  }
  #rail::-webkit-scrollbar { display: none; }
  #rail .mk { width: 30px; height: 30px; margin-bottom: 10px; flex: 0 0 auto; }
  #rail button {
    width: 46px; height: 44px; border: 0; background: none; border-radius: 9px;
    display: grid; place-items: center; color: #93a89a; position: relative;
    transition: background .16s var(--ease), color .16s var(--ease); flex: 0 0 auto;
  }
  #rail button:hover { background: var(--forest-3); color: var(--cream); }
  #rail button[aria-selected="true"] { background: var(--forest-3); color: var(--gold); }
  #rail button[aria-selected="true"]::before {
    content: ""; position: absolute; left: -8px; top: 10px; bottom: 10px;
    width: 3px; border-radius: 0 3px 3px 0; background: var(--gold);
  }
  #rail svg { width: 20px; height: 20px; }
  #rail .tip {
    position: absolute; left: calc(100% + 8px); white-space: nowrap; background: var(--ink);
    color: var(--cream); font-size: .74rem; padding: .25em .5em; border-radius: 6px;
    opacity: 0; pointer-events: none; transition: opacity .14s; z-index: 60;
    box-shadow: var(--shadow);
  }
  #rail button:hover .tip { opacity: 1; }

  /* ── header ── */
  #head {
    grid-area: head; display: flex; align-items: center; gap: 12px;
    padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
    overflow: hidden; min-width: 0;
  }
  #head .now { display: flex; flex-direction: column; line-height: 1.15; flex: 0 0 auto; }
  #head .now b { font-size: .94rem; letter-spacing: -.01em; }
  #head .now span { font-size: .68rem; color: var(--mut); }
  #head .chips { display: flex; gap: 5px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
  #head .chips::-webkit-scrollbar { display: none; }

  /* ── covers dial: the one control that moves the whole engine ── */
  .covers {
    display: flex; align-items: center; gap: 0; flex: 0 0 auto;
    background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 999px;
    padding: 2px; box-shadow: var(--shadow);
  }
  .covers button {
    width: 30px; height: 30px; border: 0; background: none; border-radius: 999px;
    color: var(--mut); font-size: 1.1rem; line-height: 1; display: grid; place-items: center;
  }
  .covers button:hover { background: var(--forest-3); color: var(--gold); }
  .covers .val {
    min-width: 74px; text-align: center; padding: 0 .3rem; line-height: 1.05;
    display: flex; flex-direction: column; align-items: center; cursor: pointer;
  }
  .covers .val b { font-size: 1rem; font-variant-numeric: tabular-nums; }
  .covers .val i {
    font-style: normal; font-size: .54rem; letter-spacing: .1em;
    text-transform: uppercase; color: var(--dim); white-space: nowrap;
  }
  .covers input[type=range] { width: 92px; accent-color: var(--gold); margin: 0 .5rem 0 .2rem; }

  /* ── main + views ── */
  #main { grid-area: main; position: relative; overflow: hidden; min-width: 0; min-height: 0; }
  .view { position: absolute; inset: 0; display: none; min-width: 0; min-height: 0; }
  .view[data-on] { display: grid; }
  .view.split { grid-template-columns: minmax(290px, 380px) 1fr; }
  .view.stack { grid-template-rows: var(--sub) 1fr; }
  .view.split.stack { grid-template-columns: minmax(290px, 380px) 1fr; grid-template-rows: var(--sub) 1fr; }
  .pane { overflow: auto; overscroll-behavior: contain; min-width: 0; min-height: 0; }
  /* Named, not ordered. A view with a sub-toolbar has a non-pane div first, and
     :first-of-type would match that instead of the list pane. */
  .view.split > .pane-list { border-right: 1px solid var(--line); }

  /* segmented sub-toolbar — one switch instead of a stack of sections */
  .subbar {
    grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; padding: 0 12px;
    background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto;
    scrollbar-width: none; min-width: 0;
  }
  .subbar::-webkit-scrollbar { display: none; }
  .subbar .sp { flex: 1 1 auto; }
  .seg { display: inline-flex; background: var(--panel-2); border-radius: 999px; padding: 2px; flex: 0 0 auto; }
  .seg button {
    border: 0; background: none; color: var(--mut); border-radius: 999px;
    padding: .3rem .78rem; font-size: .8rem; white-space: nowrap;
    transition: background .16s var(--ease), color .16s var(--ease);
  }
  .seg button[aria-selected="true"] { background: var(--forest-3); color: var(--gold); font-weight: 560; }
  :root:not([data-theme="dark"]) .seg button[aria-selected="true"] { background: var(--forest); color: var(--gold-2); }
}

@layer parts {
  .secthead {
    position: sticky; top: 0; z-index: 4; display: flex; align-items: center; gap: 8px;
    padding: .5rem .75rem; background: var(--panel); border-bottom: 1px solid var(--line);
    font-size: .65rem; letter-spacing: .12em; text-transform: uppercase; color: var(--mut);
  }
  .secthead .sp { flex: 1 1 auto; }
  .secthead .lnk {
    border: 0; background: none; color: var(--gold); font-size: .68rem;
    letter-spacing: .05em; text-transform: none; padding: 0;
  }
  .secthead .lnk:hover { text-decoration: underline; }

  .chip {
    display: inline-flex; align-items: center; gap: .3em; flex: 0 0 auto;
    padding: .2em .55em; border-radius: 999px; border: 1px solid var(--line-2);
    background: var(--panel-2); font-size: .68rem; color: var(--mut); white-space: nowrap;
  }
  .chip.good { color: var(--ok); border-color: color-mix(in oklch, var(--ok) 42%, transparent); }
  .chip.warm { color: var(--warn); border-color: color-mix(in oklch, var(--warn) 42%, transparent); }
  .chip.hot  { color: var(--stop); border-color: color-mix(in oklch, var(--stop) 46%, transparent); }
  .chip.info { color: var(--info); border-color: color-mix(in oklch, var(--info) 42%, transparent); }
  .chip .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }

  .btn {
    border: 1px solid var(--line-2); background: var(--panel-2); color: var(--txt);
    border-radius: 8px; padding: .4rem .7rem; font-size: .82rem; min-height: 36px;
    transition: border-color .16s var(--ease), background .16s var(--ease);
  }
  .btn:hover { border-color: var(--gold-dim); }
  .btn.pri { background: var(--gold); color: var(--ink); border-color: var(--gold); font-weight: 600; }
  .btn.pri:hover { background: var(--gold-2); }
  .btn.sm { padding: .22rem .55rem; font-size: .74rem; min-height: 30px; }

  /* ── dense list rows. One line of subtext, clamped — this is where the scroll went. ── */
  .rowitem {
    display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
    padding: .5rem .75rem; border-bottom: 1px solid var(--line); cursor: pointer;
    transition: background .13s var(--ease);
  }
  .rowitem:hover { background: var(--panel-2); }
  .rowitem[aria-current="true"] { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--gold); }
  .rowitem > span:nth-child(2) { min-width: 0; }
  .rowitem .ttl {
    display: block; font-size: .87rem; line-height: 1.3; font-weight: 520;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .rowitem .sub {
    display: block; font-size: .72rem; color: var(--mut); line-height: 1.3;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .rowitem .when { font-size: .7rem; color: var(--mut); text-align: right; white-space: nowrap; }
  .rowitem .when.late { color: var(--stop); font-weight: 600; }

  .tick {
    width: 20px; height: 20px; border-radius: 6px; border: 1.6px solid var(--line-2);
    background: none; display: grid; place-items: center; padding: 0; flex: 0 0 auto;
  }
  .tick svg { width: 12px; height: 12px; opacity: 0; }
  .tick[data-s="done"] { background: var(--ok); border-color: var(--ok); }
  .tick[data-s="done"] svg { opacity: 1; }
  .tick[data-s="blocked"] { border-color: var(--stop); }
  .tick[data-s="doing"] { border-color: var(--gold); border-style: dashed; }

  .empty { padding: 1.5rem 1rem; text-align: center; color: var(--dim); font-size: .84rem; line-height: 1.55; }

  /* ── metric tiles on a horizontal snap rail ── */
  .tiles {
    display: flex; gap: 10px; padding: 10px 12px; overflow-x: auto;
    scroll-snap-type: x proximity; scrollbar-width: none;
  }
  .tiles::-webkit-scrollbar { display: none; }
  .tile {
    flex: 0 0 auto; min-width: 156px; max-width: 230px; scroll-snap-align: start;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: .58rem .7rem; display: flex; flex-direction: column; gap: .08rem;
    box-shadow: var(--shadow);
  }
  .tile .k { font-size: .59rem; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); white-space: nowrap; }
  .tile .v { font-size: 1.42rem; font-weight: 640; letter-spacing: -.025em; font-variant-numeric: tabular-nums; line-height: 1.18; }
  .tile .v.sm { font-size: 1.06rem; }
  .tile .n { font-size: .69rem; color: var(--mut); line-height: 1.3; }
  .tile.accent { border-color: var(--gold-dim); }
  .tile.accent .v { color: var(--gold); }
  .tile.warnb { border-color: color-mix(in oklch, var(--stop) 45%, transparent); }

  .grid-cards {
    display: grid; gap: 10px; padding: 10px 12px;
    grid-template-columns: repeat(auto-fill, minmax(166px, 1fr));
  }
  .card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: .7rem .75rem; box-shadow: var(--shadow); min-width: 0;
  }
  .card > h3 {
    font-size: .64rem; letter-spacing: .11em; text-transform: uppercase;
    color: var(--mut); margin-bottom: .55rem; display: flex; align-items: center; gap: .5rem;
  }
  .card > h3 .sp { flex: 1 1 auto; }
  .stat { display: flex; flex-direction: column; gap: .1rem; }
  .stat b { font-size: 1.32rem; font-weight: 640; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
  .stat span { font-size: .73rem; color: var(--mut); }
  .trend { display: flex; align-items: center; gap: .45rem; margin-top: .35rem; }

  /* zone layout that collapses cleanly to one column */
  .zones { display: grid; gap: 10px; padding: 0 12px 16px; grid-template-columns: 1fr; align-content: start; }
  @media (min-width: 1000px) { .zones.two { grid-template-columns: 1fr 1fr; } }

  /* ── tables ── */
  .tbl-wrap { overflow-x: auto; }
  table.grid { width: 100%; border-collapse: collapse; font-size: .82rem; }
  table.grid th {
    position: sticky; top: 0; background: var(--panel-2); text-align: left; z-index: 3;
    font-size: .6rem; letter-spacing: .1em; text-transform: uppercase; color: var(--mut);
    padding: .45rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap;
  }
  table.grid td { padding: .32rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
  table.grid td.n, table.grid th.n { text-align: right; font-variant-numeric: tabular-nums; }
  table.grid tr.tot td { font-weight: 660; border-top: 2px solid var(--line-2); background: var(--panel-2); }
  table.grid tbody tr:hover { background: var(--panel-2); }
  .mut { color: var(--mut); }
  .dimtxt { color: var(--dim); font-size: .72rem; }
  .nowrap { white-space: nowrap; }

  input.mini, select.mini {
    width: 5.2rem; background: var(--panel-2); border: 1px solid var(--line);
    border-radius: 6px; padding: .25rem .42rem; font-size: .78rem; text-align: right;
    min-height: 32px; font-variant-numeric: tabular-nums;
  }
  select.mini { text-align: left; width: auto; }
  input.mini.wide { width: 9rem; text-align: left; }
  input.mini.full { width: 100%; text-align: left; }
  input.mini:focus, select.mini:focus { outline: none; border-color: var(--gold); }
  input.mini.dirty { border-color: var(--gold); background: color-mix(in oklch, var(--gold) 10%, var(--panel-2)); }

  /* ── detail pane ── */
  .detail { padding: 14px 16px 44px; max-width: 900px; }
  .detail h2 { font-size: 1.28rem; margin-bottom: .12rem; letter-spacing: -.02em; }
  .detail .why { color: var(--mut); font-size: .85rem; margin: 0 0 .7rem; line-height: 1.5; }
  .detail .actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .9rem; align-items: center; }
  .detail h3.sec {
    font-size: .63rem; letter-spacing: .12em; text-transform: uppercase; color: var(--mut);
    margin: 1.25rem 0 .5rem; padding-bottom: .3rem; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: .5rem;
  }
  .detail h3.sec .sp { flex: 1 1 auto; }
  .detail h3.sec:first-of-type { margin-top: .8rem; }
  .detail ol.steps { padding-left: 1.15rem; font-size: .88rem; margin: 0; }
  .detail ol.steps li { margin-bottom: .55rem; line-height: 1.5; }

  .composer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: .6rem; margin-bottom: 1rem; }
  .composer textarea {
    width: 100%; min-height: 64px; resize: vertical; background: var(--panel-2);
    border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; font-size: .86rem;
  }
  .composer textarea:focus { outline: none; border-color: var(--gold); }
  .composer .bar { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .5rem; align-items: center; }
  .composer input[type=date] { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: .3rem .5rem; font-size: .8rem; min-height: 36px; }

  .thread { border-left: 2px solid var(--line); padding-left: .85rem; margin-left: .2rem; }
  .ev { position: relative; padding: .42rem 0; }
  .ev::before { content: ""; position: absolute; left: -1.2rem; top: .8rem; width: 8px; height: 8px; border-radius: 999px; background: var(--line-2); }
  .ev.done::before { background: var(--ok); }
  .ev.sys::before { background: var(--info); }
  .ev .meta { font-size: .67rem; color: var(--dim); }
  .ev .body { font-size: .86rem; line-height: 1.5; white-space: pre-wrap; }
  .ev .tags { margin-top: .2rem; display: flex; gap: .3rem; flex-wrap: wrap; }
  .ev .tags i { font-style: normal; font-size: .63rem; color: var(--mut); background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: .1em .45em; }

  /* ── calendar: month grid ── */
  .month { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line); padding: 1px; }
  .month .dow { background: var(--panel-2); padding: .32rem; text-align: center; font-size: .59rem; letter-spacing: .1em; text-transform: uppercase; color: var(--mut); }
  .month .cell {
    background: var(--panel); min-height: 82px; padding: .28rem .32rem; display: flex;
    flex-direction: column; gap: .12rem; cursor: pointer; overflow: hidden;
    transition: background .13s var(--ease); border: 0; text-align: left; align-items: stretch;
  }
  .month .cell:hover { background: var(--panel-2); }
  .month .cell.off { opacity: .36; }
  .month .cell.trades { background: color-mix(in oklch, var(--forest-2) 34%, var(--panel)); }
  .month .cell.today { box-shadow: inset 0 0 0 2px var(--gold); }
  .month .cell[aria-current="true"] { box-shadow: inset 0 0 0 2px var(--info); }
  .month .cell .d { font-size: .73rem; font-variant-numeric: tabular-nums; color: var(--mut); }
  .month .cell.today .d { color: var(--gold); font-weight: 700; }
  .month .cell .pip {
    font-size: .61rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; padding: .04rem .25rem; border-radius: 4px;
  }
  .pip.roadhouse { background: color-mix(in oklch, var(--info) 25%, transparent); color: var(--info); }
  .pip.holiday   { background: color-mix(in oklch, var(--stop) 23%, transparent); color: var(--stop); }
  .pip.milestone { background: color-mix(in oklch, var(--gold) 25%, transparent); color: var(--gold); }
  .pip.festival  { background: color-mix(in oklch, var(--ok)   23%, transparent); color: var(--ok); }
  .pip.task      { background: var(--panel-2); color: var(--mut); }

  /* ── calendar: week strip ── */
  .weekstrip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; padding: 12px; }
  .weekcol {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
    padding: .45rem .4rem; min-height: 128px; display: flex; flex-direction: column; gap: .25rem;
    min-width: 0;
  }
  .weekcol.trades { border-color: var(--gold-dim); }
  .weekcol.today { box-shadow: inset 0 0 0 2px var(--gold); }
  .weekcol .hd { font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; color: var(--mut); text-align: center; }
  .weekcol .hd b { display: block; font-size: 1rem; color: var(--txt); letter-spacing: -.02em; }
  .weekcol .fc { text-align: center; font-size: .71rem; color: var(--gold); font-variant-numeric: tabular-nums; }

  .kv { display: grid; grid-template-columns: auto 1fr; gap: .22rem .7rem; font-size: .8rem; margin: 0; }
  .kv dt { color: var(--mut); white-space: nowrap; }
  .kv dd { margin: 0; font-variant-numeric: tabular-nums; }

  .note {
    display: block; margin: 10px 12px; padding: .55rem .7rem; border-radius: var(--r);
    font-size: .78rem; line-height: 1.5; color: var(--txt);
    background: color-mix(in oklch, var(--warn) 9%, var(--panel));
    border: 1px solid color-mix(in oklch, var(--warn) 34%, transparent);
  }
  .note.info { background: color-mix(in oklch, var(--info) 9%, var(--panel)); border-color: color-mix(in oklch, var(--info) 32%, transparent); }
  .note b { color: var(--txt); }
  .detail .note { margin: .5rem 0 0; }
}

@layer viz {
  .ring .bg { fill: none; stroke: var(--line); }
  .ring .fg { fill: none; stroke: var(--gold); stroke-linecap: round; transition: stroke-dashoffset .6s var(--ease); }
  .ring text { fill: var(--txt); font-weight: 640; font-variant-numeric: tabular-nums; }

  .spark { width: 100%; height: 34px; overflow: visible; }
  .spark path { fill: none; stroke: var(--gold); stroke-width: 1.6; stroke-linejoin: round; }
  .spark path.area { fill: color-mix(in oklch, var(--gold) 15%, transparent); stroke: none; }
  .spark .pt { fill: var(--gold); }

  .gauge { display: block; flex: 1 1 auto; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; min-width: 44px; }
  .gauge i { display: block; height: 100%; border-radius: 999px; background: var(--ok); transition: width .5s var(--ease); }
  .gauge.warm i { background: var(--warn); }
  .gauge.hot i { background: var(--stop); }

  /* cost band drawn to scale: low ── typical ── high */
  .band { position: relative; height: 24px; margin: .35rem 0 .1rem; }
  .band .track { position: absolute; left: 0; right: 0; top: 9px; height: 6px; border-radius: 999px; background: var(--line); }
  .band .fill { position: absolute; top: 9px; height: 6px; border-radius: 999px; background: color-mix(in oklch, var(--gold) 42%, transparent); }
  .band .pin { position: absolute; top: 5px; width: 2px; height: 14px; border-radius: 2px; background: var(--gold); }
  .band .lbl { position: absolute; bottom: 0; font-size: .59rem; color: var(--dim); transform: translateX(-50%); white-space: nowrap; }

  /* stacked money bar: sales split into COGS / labour / overhead / net */
  .pbar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
  .pbar i { display: block; height: 100%; transition: width .5s var(--ease); }
  .pbar i.cogs { background: color-mix(in oklch, var(--stop) 62%, transparent); }
  .pbar i.lab  { background: color-mix(in oklch, var(--warn) 62%, transparent); }
  .pbar i.oh   { background: color-mix(in oklch, var(--info) 55%, transparent); }
  .pbar i.net  { background: color-mix(in oklch, var(--ok) 70%, transparent); }
  .pbar i.unk  { background: repeating-linear-gradient(45deg, var(--line) 0 5px, var(--panel-2) 5px 10px); }
  .pkey { display: flex; gap: .7rem; flex-wrap: wrap; margin-top: .45rem; font-size: .69rem; color: var(--mut); }
  .pkey span { display: inline-flex; align-items: center; gap: .3rem; }
  .pkey em { width: 9px; height: 9px; border-radius: 3px; font-style: normal; flex: 0 0 auto; }
  .pkey em.cogs { background: color-mix(in oklch, var(--stop) 62%, transparent); }
  .pkey em.lab  { background: color-mix(in oklch, var(--warn) 62%, transparent); }
  .pkey em.oh   { background: color-mix(in oklch, var(--info) 55%, transparent); }
  .pkey em.net  { background: color-mix(in oklch, var(--ok) 70%, transparent); }
  .pkey em.unk  { background: repeating-linear-gradient(45deg, var(--line) 0 4px, var(--panel-2) 4px 8px); }

  /* hour strip */
  .strip { position: relative; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
  .strip .hr { position: absolute; top: 0; bottom: 12px; width: 1px; background: var(--line); }
  .strip .lb { position: absolute; bottom: 1px; font-size: .55rem; color: var(--dim); transform: translateX(-50%); }
  .strip .win { position: absolute; top: 4px; height: 15px; border-radius: 4px; background: color-mix(in oklch, var(--gold) 26%, transparent); border: 1px solid var(--gold-dim); }
  .strip .now { position: absolute; top: 0; bottom: 12px; width: 2px; background: var(--stop); }

  /* forecast column chart */
  .cols { display: flex; align-items: flex-end; gap: 6px; height: 94px; padding: 0 2px; }
  .cols .col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .18rem; min-width: 0; }
  .cols .col i { display: block; width: 100%; border-radius: 4px 4px 0 0; background: color-mix(in oklch, var(--gold) 55%, transparent); transition: height .5s var(--ease); }
  .cols .col.dark i { background: var(--line-2); }
  .cols .col b { font-size: .63rem; font-variant-numeric: tabular-nums; }
  .cols .col span { font-size: .57rem; color: var(--dim); }
}

@layer parts {
  /* ── suggestion cards ── */
  .card.sug { border-left: 3px solid var(--line-2); }
  .card.sug.act { border-left-color: var(--stop); }
  .card.sug.watch { border-left-color: var(--warn); }
  .card.sug.ok { border-left-color: var(--ok); }
  .sugttl { font-size: 1.02rem; font-weight: 600; letter-spacing: -.015em; line-height: 1.3; margin-bottom: .35rem; }
  .sugdet { font-size: .84rem; line-height: 1.55; color: var(--txt); margin: 0 0 .6rem; }
  .sugnum {
    background: var(--panel-2); border-radius: 8px; padding: .5rem .65rem; font-size: .78rem;
    grid-template-columns: auto 1fr; gap: .18rem .8rem; margin-bottom: .6rem;
  }
  .sugnum dt { color: var(--mut); }
  .sugnum dd { text-align: right; }
  .sugact { font-size: .84rem; line-height: 1.5; margin-bottom: .55rem; }
  .sugact b { color: var(--gold); margin-right: .3rem; }
  .sugfoot { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

  /* ── form bits ── */
  textarea.notebox {
    width: 100%; min-height: 74px; resize: vertical; background: var(--panel-2);
    border: 1px solid var(--line); border-radius: 9px; padding: .55rem .65rem; font-size: .86rem;
    font-family: inherit; color: inherit;
  }
  textarea.notebox:focus { outline: none; border-color: var(--gold); }
  label.ck {
    display: flex; align-items: center; gap: .45rem; font-size: .8rem; padding: .22rem 0; cursor: pointer;
  }
  label.ck input { width: 17px; height: 17px; accent-color: var(--gold); flex: 0 0 auto; }
  input[type=file] {
    width: 100%; font-size: .8rem; background: var(--panel-2); border: 1px dashed var(--line-2);
    border-radius: 9px; padding: .6rem; color: var(--mut);
  }
  input[type=file]::file-selector-button {
    background: var(--panel); border: 1px solid var(--line-2); border-radius: 7px; color: var(--txt);
    padding: .3rem .6rem; margin-right: .6rem; font: inherit; font-size: .78rem; cursor: pointer;
  }
  table.grid input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--ok); }
  .card > h3 + select.mini, .card > h3 + input.mini { margin-top: 0; }
  .secthead select.mini { min-height: 28px; padding: .12rem .35rem; font-size: .72rem; }

  /* Focus is a safety feature on a form this size, not a decoration. */
  :focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }
}

@layer overlay {
  /* ── search: a destination you reach from anywhere and leave without losing your place ── */
  #search, #sheet, .modal {
    position: fixed; inset: 0; z-index: 200; background: rgb(6 12 9 / .62);
    backdrop-filter: blur(3px); display: grid; padding: 14px;
    animation: ovIn .16s var(--ease) both;
  }
  #search { align-content: start; justify-items: center; padding-top: max(8vh, 40px); }
  #sheet, .modal { place-items: center; }
  #search[hidden], #sheet[hidden] { display: none; }
  .modal .sheetcard { max-height: 86dvh; }
  @keyframes ovIn { from { opacity: 0 } to { opacity: 1 } }

  .searchcard, .sheetcard {
    width: 100%; max-width: 640px; background: var(--panel); border: 1px solid var(--line-2);
    border-radius: var(--r-lg); box-shadow: 0 24px 70px -20px rgb(0 0 0 / .7);
    overflow: hidden; display: flex; flex-direction: column; max-height: 78dvh;
    animation: cardIn .2s var(--ease) both;
  }
  @keyframes cardIn { from { opacity: 0; transform: translateY(-8px) scale(.99) } to { opacity: 1; transform: none } }

  .searchtop { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .searchtop svg { width: 18px; height: 18px; color: var(--mut); flex: 0 0 auto; }
  .searchtop input {
    flex: 1 1 auto; min-width: 0; background: none; border: 0; font-size: .96rem;
    padding: .3rem 0; min-height: 32px;
  }
  .searchtop input:focus { outline: none; }
  .searchtop input::-webkit-search-cancel-button { display: none; }

  #searchOut { overflow: auto; overscroll-behavior: contain; }
  .sres {
    display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
    padding: .5rem .8rem; cursor: pointer; border-bottom: 1px solid var(--line); width: 100%;
    background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; color: inherit;
  }
  .sres:hover, .sres[aria-selected="true"] { background: var(--panel-2); }
  .sres[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--gold); }
  .sres .ttl { font-size: .87rem; font-weight: 520; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sres .sub { font-size: .72rem; color: var(--mut); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sres mark { background: color-mix(in oklch, var(--gold) 32%, transparent); color: inherit; border-radius: 3px; padding: 0 .1em; }
  .sgrouphd {
    position: sticky; top: 0; z-index: 2; padding: .35rem .8rem; background: var(--panel-2);
    font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--dim);
    border-bottom: 1px solid var(--line);
  }
  .searchfoot { padding: .5rem .8rem; font-size: .68rem; color: var(--dim); border-top: 1px solid var(--line); }
  .searchfoot kbd {
    background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 4px;
    padding: 0 .3em; font: inherit; font-size: .9em;
  }

  /* ── the More sheet: ten sections do not fit a phone's bottom bar ── */
  .sheetgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); }
  .sheetgrid button {
    background: var(--panel); border: 0; color: var(--txt); padding: 1rem .4rem;
    display: flex; flex-direction: column; align-items: center; gap: .4rem; font-size: .72rem;
  }
  .sheetgrid button:hover { background: var(--panel-2); }
  .sheetgrid button[aria-selected="true"] { color: var(--gold); }
  .sheetgrid svg { width: 21px; height: 21px; }

  /* ── the unprotected banner ── */
  #banner {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 150; padding: .5rem .9rem;
    background: color-mix(in oklch, var(--stop) 22%, var(--ink)); color: var(--cream);
    font-size: .74rem; line-height: 1.4; display: flex; gap: .6rem; align-items: center;
    border-top: 1px solid color-mix(in oklch, var(--stop) 50%, transparent);
  }
  #banner[hidden] { display: none; }
  #banner b { color: #fff; }
  #banner button { margin-left: auto; flex: 0 0 auto; }
  @media (max-width: 860px) { #banner { bottom: 52px; } }

  .iconbtn { padding: .3rem .45rem; min-height: 34px; display: grid; place-items: center; flex: 0 0 auto; }
  .iconbtn svg { width: 17px; height: 17px; display: block; }
}

@layer motion {
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  }
  .view[data-on] > .pane { animation: fade .2s var(--ease) both; }
  @keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}

/* ── mobile: rail becomes a bottom bar, split panes become a drill-down ── */
@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr; grid-template-rows: var(--hdr) 1fr auto;
    grid-template-areas: "head" "main" "rail";
  }
  #rail {
    flex-direction: row; justify-content: space-around; align-items: stretch;
    padding: 0; border-top: 1px solid var(--forest-3); overflow: visible;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  #rail .mk { display: none; }
  #rail button {
    width: auto; flex: 1 1 0; height: 52px; border-radius: 0;
    flex-direction: column; gap: 1px; justify-content: center;
  }
  #rail button[aria-selected="true"]::before {
    left: 18%; right: 18%; top: 0; bottom: auto; width: auto; height: 3px; border-radius: 0 0 3px 3px;
  }
  /* Ten destinations will not fit across 375px at a touchable size. Four plus a
     door to the rest will. */
  #rail button:not([data-primary]) { display: none; }
  #rail button[data-more] { display: flex; }
  #rail svg { width: 18px; height: 18px; }
  #rail .tip {
    position: static; opacity: 1; background: none; color: inherit; padding: 0;
    font-size: .55rem; letter-spacing: .01em; box-shadow: none; line-height: 1;
  }

  #head { padding: 0 10px; gap: 8px; }
  #head .chips { display: none; }
  .covers .val { min-width: 58px; }
  .covers input[type=range] { display: none; }

  .view.split { grid-template-columns: 1fr; }
  .view.split > .pane-list { border-right: 0; }
  .view.split > .pane-detail { display: none; }
  .view.split[data-detail] > .pane-list { display: none; }
  .view.split[data-detail] > .pane-detail { display: block; }
  .view.split.stack { grid-template-columns: 1fr; }

  .detail { padding: 12px 12px 46px; }
  .grid-cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .weekstrip { grid-template-columns: 1fr; gap: 6px; }
  .weekcol { min-height: 0; flex-direction: row; align-items: center; gap: .6rem; flex-wrap: wrap; }
  .weekcol .hd { text-align: left; display: flex; align-items: baseline; gap: .4rem; flex: 0 0 auto; }
  .weekcol .hd b { display: inline; }
  .weekcol .fc { flex: 0 0 auto; }
  .month .cell { min-height: 56px; }
  .month .cell .pip { font-size: .5rem; }
  table.grid { font-size: .78rem; }
  .tile { min-width: 142px; }
}

@media (max-width: 420px) {
  .covers button { width: 26px; }
  .covers .val { min-width: 50px; }
  #head .now b { font-size: .84rem; }
  .tile .v { font-size: 1.24rem; }
}

@layer print {
  @media print {
    #rail, #head, .subbar, .btn, .composer, .tiles { display: none !important; }
    #app { display: block; height: auto; }
    .view { position: static; display: none; }
    .view[data-on] { display: block; }
    .pane { overflow: visible; }
    .view.split > .pane-list { display: none; }
    body { background: #fff; color: #000; font-size: 11pt; }
    .detail { max-width: none; padding: 0; }
    table.grid th { background: #eee; color: #000; }
    .secthead { position: static; background: none; color: #000; }
    .card, .tile { break-inside: avoid; border-color: #999; }
  }
}
