/* ===== Theme tokens. Change look here; components only read these variables. ===== */
:root, [data-theme="terminal"][data-mode="dark"] {
  --bg: #050505; --panel: #0d0d0d; --panel2: #141414; --raise: #1b1b1b; --line: #262626; --line2: #3a3a3a;
  --text: #e8e2d0; --muted: #8a8478; --faint: #5c574e;
  --accent: #f2a516; --accent-ink: #1a1203; --accent2: #ffcf6b; --link: #f2a516;
  --good: #3fd07a; --warn: #f2a516; --bad: #ff5a4e; --info: #6fb7ff;
  --good-bg: rgba(63,208,122,.12); --warn-bg: rgba(242,165,22,.12); --bad-bg: rgba(255,90,78,.12); --info-bg: rgba(111,183,255,.12);
  --font: 'JetBrains Mono', ui-monospace, Menlo, monospace; --font-ui: 'Inter', system-ui, sans-serif; --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --radius: 2px; --radius-lg: 3px; --upper: uppercase; --track: .06em;
  --map-land: #141414; --map-border: #333; --map-dot: #f2a516; --map-dot2: #6b6457;
}
[data-theme="terminal"][data-mode="light"] {
  --bg: #f4f1e8; --panel: #fbf9f3; --panel2: #efeadd; --raise: #e6e0d0; --line: #d6cfbd; --line2: #bfb7a2;
  --text: #1d1a14; --muted: #6a6355; --faint: #9a927f;
  --accent: #b36b00; --accent-ink: #fff8ea; --accent2: #8a5200; --link: #8a5200;
  --good: #1f8a4c; --warn: #b36b00; --bad: #c0362c; --info: #1f5fa8;
  --good-bg: rgba(31,138,76,.1); --warn-bg: rgba(179,107,0,.1); --bad-bg: rgba(192,54,44,.1); --info-bg: rgba(31,95,168,.1);
  --map-land: #e9e3d3; --map-border: #c9c0a9; --map-dot: #b36b00; --map-dot2: #9a927f;
}
[data-theme="ops"][data-mode="dark"] {
  --bg: #0b121a; --panel: #0f1720; --panel2: #16212d; --raise: #1c2a38; --line: #22303e; --line2: #31445a;
  --text: #dbe4ee; --muted: #7d8fa3; --faint: #50627a;
  --accent: #5fd4e6; --accent-ink: #062027; --accent2: #8fb3ff; --link: #5fd4e6;
  --good: #4fd18b; --warn: #f0b44c; --bad: #ff6b6b; --info: #8fb3ff;
  --font: 'Inter', system-ui, sans-serif; --radius: 6px; --radius-lg: 10px; --upper: none; --track: 0;
  --map-land: #16212d; --map-border: #2c3e52; --map-dot: #5fd4e6; --map-dot2: #50627a;
}
[data-theme="ops"][data-mode="light"] {
  --bg: #eef2f6; --panel: #ffffff; --panel2: #f3f6f9; --raise: #e7edf3; --line: #d9e1ea; --line2: #c3cfdc;
  --text: #13202d; --muted: #5a6b7e; --faint: #8b9aab;
  --accent: #0b8aa0; --accent-ink: #ffffff; --accent2: #3a63c9; --link: #0b7387;
  --good: #188152; --warn: #a96a00; --bad: #c43c3c; --info: #3a63c9;
  --font: 'Inter', system-ui, sans-serif; --radius: 6px; --radius-lg: 10px; --upper: none; --track: 0;
  --map-land: #e3eaf1; --map-border: #c3cfdc; --map-dot: #0b8aa0; --map-dot2: #8b9aab;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 13px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 500; letter-spacing: var(--track); }
h1 { font-size: 20px; } h2 { font-size: 15px; text-transform: var(--upper); } h3 { font-size: 13px; text-transform: var(--upper); color: var(--muted); } h4 { font-size: 13px; }
p { margin: 0 0 .6rem; }
.mono { font-family: var(--font-mono); } .muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 11.5px; }
.good { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); } .acc { color: var(--accent); }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ===== Layout ===== */
#app { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
#nav { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 16px 14px; border-bottom: 1px solid var(--line); }
.brand-mark { color: var(--accent); font-size: 20px; }
.brand-name { font-weight: 600; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); white-space: nowrap; }
.brand-tag { font-size: 10.5px; color: var(--muted); }
#navlinks { padding: 8px 0; overflow-y: auto; flex: 1; }
#navlinks .grp { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .12em; padding: 12px 16px 4px; }
#navlinks a { display: flex; gap: 10px; padding: 6px 16px; color: var(--muted); border-left: 2px solid transparent; }
#navlinks a .n { color: var(--faint); width: 18px; font-family: var(--font-mono); font-size: 11px; }
#navlinks a:hover { color: var(--text); background: var(--panel2); text-decoration: none; }
#navlinks a.on { color: var(--text); border-left-color: var(--accent); background: var(--panel2); }
#navlinks a.on .n { color: var(--accent); }
.nav-foot { padding: 10px 16px; border-top: 1px solid var(--line); font-size: 10.5px; color: var(--faint); }
#main { min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 16px; padding: 8px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; min-height: 46px; }
#crumb { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
#topstats { display: flex; gap: 18px; margin-left: auto; font-size: 11.5px; }
#topstats .ts b { color: var(--accent); font-weight: 500; }
.top-actions { display: flex; gap: 8px; align-items: center; }
#view { padding: 18px 20px 60px; outline: none; max-width: 1500px; width: 100%; }
.loading { color: var(--muted); padding: 40px; }

/* ===== Panels & grids ===== */
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) 360px; } .g-side-l { grid-template-columns: 300px minmax(0, 1fr); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .spanall { grid-column: 1 / -1; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px 14px; min-width: 0; }
.panel > .ph { display: flex; align-items: center; gap: 10px; margin: -12px -14px 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.panel > .ph h2, .panel > .ph h3 { margin: 0; font-size: 11.5px; color: var(--accent); text-transform: uppercase; letter-spacing: .1em; }
.panel > .ph .r { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.kpi { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.kpi .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.kpi .v { font-size: 20px; font-family: var(--font-mono); margin-top: 2px; }
.kpi .s { font-size: 11px; color: var(--muted); }
.page-h { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.page-h .sub { color: var(--muted); max-width: 820px; }
.page-h .r { margin-left: auto; display: flex; gap: 8px; }

/* ===== Controls ===== */
button, .btn { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--radius); padding: 6px 12px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; }
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.pri, .btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); } button.ghost:hover { color: var(--text); border-color: var(--line2); }
button.sm, .btn.sm { padding: 3px 8px; font-size: 11.5px; }
button:disabled { opacity: .5; cursor: default; }
.icon-btn { padding: 4px 9px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line2); border-radius: var(--radius); padding: 6px 8px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 1px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; line-height: 1.5; }
label.f { display: block; margin-bottom: 10px; } label.f > span { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 3px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border: 1px solid var(--line2); border-radius: 999px; font-size: 11.5px; color: var(--muted); background: transparent; cursor: pointer; }
.chip:empty { display: none; }
.chip.on, .chip:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.tag { display: inline-block; padding: 0 6px; border-radius: var(--radius); font-size: 10.5px; border: 1px solid var(--line2); color: var(--muted); white-space: nowrap; }
.tag.good { color: var(--good); border-color: var(--good); background: var(--good-bg); }
.tag.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-bg); }
.tag.bad { color: var(--bad); border-color: var(--bad); background: var(--bad-bg); }
.tag.info { color: var(--info); border-color: var(--info); background: var(--info-bg); }
.conf { display: inline-block; font-size: 9.5px; padding: 0 4px; border-radius: var(--radius); margin-left: 4px; vertical-align: 1px; text-transform: uppercase; letter-spacing: .05em; }
.conf.hi { color: var(--good); border: 1px solid var(--good); } .conf.md { color: var(--warn); border: 1px solid var(--warn); } .conf.lo { color: var(--bad); border: 1px solid var(--bad); }
.srcs a { font-size: 10px; margin-left: 2px; color: var(--faint); } .srcs a:hover { color: var(--accent); }
.note { padding: 8px 10px; border-left: 2px solid var(--accent); background: var(--panel2); color: var(--muted); font-size: 12px; margin: 8px 0; }
.note.bad { border-left-color: var(--bad); } .note.good { border-left-color: var(--good); } .note.info { border-left-color: var(--info); }
.err { color: var(--bad); font-size: 11.5px; margin-top: 4px; }

/* ===== Tables ===== */
.tbl-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); }
table.t { width: 100%; border-collapse: collapse; font-size: 12px; }
table.t th { position: sticky; top: 0; background: var(--panel2); color: var(--muted); font-weight: 500; text-align: left; padding: 6px 8px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--line2); cursor: pointer; white-space: nowrap; z-index: 1; }
table.t th.sorted { color: var(--accent); }
table.t td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr:hover td { background: var(--panel2); }
table.t tr.click { cursor: pointer; }
table.t td.n, table.t th.n { text-align: right; font-family: var(--font-mono); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 12px; font-size: 12px; }
.kv > div:nth-child(odd) { color: var(--muted); }

/* ===== Bars ===== */
.bar { height: 6px; background: var(--raise); border-radius: 1px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.hbar { display: grid; grid-template-columns: 120px 1fr 48px; gap: 8px; align-items: center; font-size: 11.5px; margin: 3px 0; }

/* ===== Timeline ===== */
.tl { position: relative; }
.tl-item { display: grid; grid-template-columns: 22px 92px 1fr auto; gap: 10px; align-items: start; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.tl-item.done .t-title { text-decoration: line-through; color: var(--faint); }
.tl-item.past:not(.done) .t-date { color: var(--bad); }
.tl-item .t-date { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }
.tl-item .t-cat { font-size: 10px; }
.tl-month { font-size: 10.5px; color: var(--accent); text-transform: uppercase; letter-spacing: .12em; padding: 12px 0 2px; border-bottom: 1px solid var(--line2); }

/* ===== Drawer / modal ===== */
.drawer { position: fixed; inset: 0 0 0 auto; width: min(720px, 92vw); background: var(--panel); border-left: 1px solid var(--line2); transform: translateX(105%); transition: transform .18s ease; z-index: 30; overflow-y: auto; }
.drawer.open { transform: none; box-shadow: -20px 0 60px rgba(0,0,0,.35); }
.drawer-inner { padding: 18px 20px 60px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; z-index: 40; }
.modal.open { display: flex; }
.modal-inner { background: var(--panel); border: 1px solid var(--line2); border-radius: var(--radius-lg); padding: 18px 20px; width: min(640px, 92vw); max-height: 88vh; overflow-y: auto; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 50; }
.toast { background: var(--raise); border: 1px solid var(--line2); border-left: 2px solid var(--accent); padding: 8px 12px; font-size: 12px; max-width: 360px; }
.toast.bad { border-left-color: var(--bad); }

/* ===== Onboarding ===== */
.onb { max-width: 860px; margin: 20px auto; }
.onb .steps { display: flex; gap: 6px; margin-bottom: 16px; }
.onb .steps i { flex: 1; height: 3px; background: var(--line2); } .onb .steps i.on { background: var(--accent); }
.choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-bottom: 14px; }
.choice button { flex-direction: column; align-items: flex-start; text-align: left; padding: 10px 12px; background: var(--panel); min-height: 64px; }
.choice button b { font-weight: 500; } .choice button span { font-size: 11px; color: var(--muted); }
.choice button.on { border-color: var(--accent); background: var(--panel2); box-shadow: inset 2px 0 0 var(--accent); }

/* ===== Map ===== */
.map-wrap { position: relative; background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius); }
.map-svg { width: 100%; height: auto; display: block; }
.map-svg .st { fill: var(--map-land); stroke: var(--map-border); stroke-width: .7; cursor: pointer; }
.map-svg .st:hover { fill: var(--raise); } .map-svg .st.sel { fill: var(--warn-bg); stroke: var(--accent); }
.map-svg .d25 { fill: var(--map-dot); stroke: var(--bg); stroke-width: 1; cursor: pointer; }
.map-svg .d100 { fill: var(--map-dot2); opacity: .8; cursor: pointer; }
.map-svg .d25.dim { opacity: .2; } .map-svg .d100.dim { opacity: .1; }
.map-svg text.lbl { font: 9px var(--font-mono); fill: var(--text); pointer-events: none; paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.map-tip { position: absolute; pointer-events: none; background: var(--raise); border: 1px solid var(--line2); padding: 6px 8px; font-size: 11.5px; max-width: 240px; display: none; z-index: 3; }
.legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); padding: 6px 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

/* ===== Interview ===== */
.iv-stage { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; }
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 58vh; overflow-y: auto; padding: 4px 2px; }
.msg { padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); max-width: 88%; white-space: pre-wrap; }
.msg.iv { background: var(--panel2); align-self: flex-start; }
.msg.me { background: var(--bg); align-self: flex-end; border-color: var(--line2); }
.msg .meta { font-size: 10.5px; color: var(--faint); margin-bottom: 3px; text-transform: uppercase; letter-spacing: .06em; }
.timer { font-family: var(--font-mono); font-size: 28px; }
.timer.warn { color: var(--warn); } .timer.bad { color: var(--bad); }
.fb { border: 1px solid var(--line); border-left: 2px solid var(--accent); padding: 8px 10px; margin: 6px 0 12px; background: var(--panel2); font-size: 12px; }
.score { display: inline-block; min-width: 26px; text-align: center; font-family: var(--font-mono); border: 1px solid var(--line2); border-radius: var(--radius); }

/* ===== Boards ===== */
.post { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px; background: var(--panel2); }
.post .ph2 { display: flex; gap: 8px; font-size: 11px; color: var(--muted); margin-bottom: 4px; align-items: center; }
.post .ph2 .handle { color: var(--accent); }
.post .body { white-space: pre-wrap; }
.board-item { padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.board-item:hover, .board-item.on { background: var(--panel2); }

/* ===== Misc ===== */
.empty { color: var(--muted); padding: 18px; text-align: center; border: 1px dashed var(--line2); border-radius: var(--radius); }
.list-plain { margin: 0; padding-left: 18px; } .list-plain li { margin: 3px 0; }
.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }
.spark { width: 100%; height: 120px; }
.spark path.l { fill: none; stroke: var(--accent); stroke-width: 1.5; } .spark circle { fill: var(--accent); }
.spark line.g { stroke: var(--line); } .spark text { font: 9px var(--font-mono); fill: var(--muted); }
details.x { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; margin: 6px 0; background: var(--panel); }
details.x summary { cursor: pointer; color: var(--text); }
details.x[open] summary { color: var(--accent); margin-bottom: 6px; }
.typing::after { content: '▍'; animation: blink 1s steps(1) infinite; color: var(--accent); } @keyframes blink { 50% { opacity: 0; } }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g-side, .iv-stage { grid-template-columns: 1fr; } }

/* ===== Shared layout helpers (used by views instead of inline grid styles) ===== */
.hbar.wide { grid-template-columns: 130px 1fr 80px; }
.g-glance { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; }
.kv.narrow { grid-template-columns: 120px 1fr; }
#menuBtn, #tabbar, #navScrim { display: none; }

/* ===== Phone: slide-in menu, bottom tab bar, touch-sized controls =====
   Narrow screens (≤760px), plus short touch screens so a phone turned sideways keeps the phone layout.
   Keep in sync with phone() in js/core.js. */
@media (max-width: 760px), (pointer: coarse) and (max-height: 500px) {
  :root { --tabbar-h: 58px; --safe-b: env(safe-area-inset-bottom, 0px); }
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 14px; overscroll-behavior-y: none; }
  h1 { font-size: 19px; } h2 { font-size: 14px; }
  .small { font-size: 12.5px; }

  /* Shell */
  #app { display: block; }
  #main { min-height: 100vh; min-height: 100dvh; }
  #nav { position: fixed; inset: 0 auto 0 0; width: min(310px, 86vw); height: 100%; z-index: 36;
    transform: translateX(-102%); transition: transform .2s ease; padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: var(--safe-b); box-shadow: none; }
  body.nav-open #nav { transform: none; box-shadow: 20px 0 60px rgba(0,0,0,.45); }
  body.nav-open { overflow: hidden; }
  #navScrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.nav-open #navScrim { opacity: 1; pointer-events: auto; }
  #navlinks a { padding: 11px 18px; font-size: 14px; }
  #navlinks .grp { padding: 14px 18px 4px; }
  /* The claude.ai wrapper pads :root by the safe-area insets, so the sticky header sits just below the
     status bar instead of padding for it, and a fixed band paints the area above it. */
  #topbar { gap: 8px; padding: 6px 10px; min-height: 52px; top: env(safe-area-inset-top, 0px); }
  body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--panel); }
  #menuBtn { display: inline-flex; }
  #crumb { flex: 1; min-width: 0; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
  #topstats { display: none; }
  .top-actions .chip { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; line-height: 30px; }
  .top-actions .chip:empty { display: none; }
  #view { padding: 14px 12px 28px; }
  body.has-tabs #view { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px); }

  #tabbar { display: none; }
  body.has-tabs #tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--panel); border-top: 1px solid var(--line2); padding-bottom: var(--safe-b); height: calc(var(--tabbar-h) + var(--safe-b)); }
  #tabbar a, #tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: var(--tabbar-h);
    color: var(--muted); font: 10.5px var(--font-ui); letter-spacing: .02em; background: none; border: 0; border-radius: 0; padding: 0; text-decoration: none; -webkit-tap-highlight-color: transparent; }
  #tabbar .on { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }

  /* Touch targets (44px for primary controls) and 16px inputs so iOS doesn't zoom on focus */
  button, .btn { min-height: 42px; padding: 8px 14px; }
  button.sm, .btn.sm { min-height: 34px; padding: 5px 10px; font-size: 12.5px; }
  .icon-btn { min-height: 40px; min-width: 40px; justify-content: center; padding: 6px; }
  .seg button { min-height: 40px; }
  .chip { min-height: 32px; padding: 4px 12px; font-size: 12.5px; }
  input, select, textarea { font-size: 16px; padding: 9px 10px; min-height: 42px; }
  input[type=checkbox], input[type=radio] { min-height: 0; width: 20px; height: 20px; }
  textarea { min-height: 120px; }
  label.f > span { font-size: 11.5px; }
  .seg { display: flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: 1 1 auto; min-width: min-content; justify-content: center; text-align: center; white-space: normal; line-height: 1.25; }
  label.row { flex-wrap: nowrap; align-items: flex-start; } label.row > input[type=checkbox], label.row > input[type=radio] { flex: none; margin-top: 1px; }

  /* Grids: KPI rows go 2-up, everything else stacks */
  .grid { gap: 10px; }
  .g2, .g3, .g-side, .g-side-l, .g-glance, .iv-stage { grid-template-columns: minmax(0, 1fr) !important; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2, .span3 { grid-column: auto; }
  .panel { padding: 12px; }
  .panel > .ph { margin: -12px -12px 10px; padding: 9px 12px; flex-wrap: wrap; row-gap: 6px; }
  .panel > .ph .r { flex-wrap: wrap; }
  .kpi .v { font-size: 18px; overflow-wrap: anywhere; }
  .page-h { flex-wrap: wrap; align-items: flex-start; }
  .page-h .r { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .row { row-gap: 8px; }

  /* Key/value and bar rows */
  .kv, .kv.narrow { grid-template-columns: minmax(0, 42%) minmax(0, 1fr); font-size: 13px; }
  .kv > div { overflow-wrap: anywhere; }
  .hbar, .hbar.wide { grid-template-columns: minmax(0, 96px) 1fr auto; font-size: 12.5px; gap: 6px; margin: 6px 0; }
  .hbar > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Tables: page scrolls vertically, table scrolls sideways with a fade hint */
  .tbl-wrap { max-height: none; -webkit-overflow-scrolling: touch;
    background: linear-gradient(to right, var(--panel), var(--panel)) left / 20px 100% no-repeat local,
                linear-gradient(to left, var(--panel), var(--panel)) right / 20px 100% no-repeat local,
                linear-gradient(to right, rgba(0,0,0,.35), transparent) left / 10px 100% no-repeat scroll,
                linear-gradient(to left, rgba(0,0,0,.35), transparent) right / 10px 100% no-repeat scroll; }
  table.t { font-size: 13px; }
  table.t th, table.t td { padding: 8px 8px; }
  table.t th { position: static; }
  .tbl-wrap table.t th { position: sticky; }
  :not(.tbl-wrap) > table.t { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

  /* Card tables (4+ columns, labeled by cardify() in app.js) */
  .tbl-wrap.has-cards { border: 0; overflow: visible; max-height: none !important; background: none; }
  table.t.cards, .cards > tbody, .cards > tbody > tr, .cards > tbody > tr > td { display: block; width: auto; }
  table.t.cards { overflow: visible; }
  .cards > thead { display: none; }
  .cards.sortable > thead { display: block; margin-bottom: 8px; }
  .cards.sortable > thead > tr { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .cards.sortable > thead th { position: static; flex: none; border: 1px solid var(--line2); border-radius: 999px; padding: 6px 12px; background: transparent; text-align: left; }
  .cards.sortable > thead th.sorted { border-color: var(--accent); }
  .cards > tbody > tr { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel2); padding: 8px 12px; margin-bottom: 8px; }
  .cards > tbody > tr > td { display: grid; grid-template-columns: minmax(0, 38%) minmax(0, 1fr); gap: 10px; padding: 4px 0; border: 0; text-align: left !important; overflow-wrap: anywhere; }
  .cards > tbody > tr > td::before { content: attr(data-label); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-family: var(--font); padding-top: 2px; }
  .cards > tbody > tr > td[data-label=""], .cards > tbody > tr > td.wide { display: block; }
  .cards > tbody > tr > td[data-label=""]::before, .cards > tbody > tr > td.wide::before { content: none; }
  .cards > tbody > tr > td:first-child { font-weight: 500; }
  .cards > tbody > tr > td:empty { display: none; }
  .cards > tbody > tr > td { min-width: 0; }
  .cards > tbody > tr > td select, .cards > tbody > tr > td input:not([type=checkbox]):not([type=radio]) { max-width: 100% !important; min-width: 0; width: 100% !important; }
  table.t.cards tr:hover td { background: none; }
  .cards > tbody > tr > td { justify-items: start; }
  .cards.dense > tbody > tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px 14px; }
  .cards.dense > tbody > tr > td { display: block; padding: 3px 0; }
  .cards.dense > tbody > tr > td::before { display: block; padding: 0 0 1px; font-size: 10px; }
  .cards.dense > tbody > tr > td.wide, .cards > tbody > tr > td.act { grid-column: 1 / -1; }
  .cards > tbody > tr > td.act { display: flex; justify-content: flex-end; gap: 6px; padding-top: 6px; border-top: 1px dashed var(--line); margin-top: 4px; }
  .cards > tbody > tr > td.act::before { content: none; }
  .cards > tbody > tr > td.act button { min-height: 38px; min-width: 44px; justify-content: center; font-size: 14px; }

  /* Timeline: checkbox | date+title stacked | tag */
  .tl-item { grid-template-columns: 24px minmax(0, 1fr) auto; grid-template-areas: "c d t" "c b t"; gap: 2px 10px; padding: 10px 0; }
  .tl-item > input { grid-area: c; margin-top: 2px; }
  .tl-item > .t-date { grid-area: d; font-size: 12px; }
  .tl-item > .t-date .small { display: inline; margin-left: 6px; }
  .tl-item > div:nth-of-type(2) { grid-area: b; min-width: 0; }
  .tl-item > div:last-child { grid-area: t; }

  /* Sheets: modal slides up from the bottom; drawer is full screen */
  .modal { align-items: flex-end; }
  .modal-inner { width: 100%; max-height: 90vh; max-height: 90dvh; border-radius: 12px 12px 0 0; border-bottom: 0;
    padding: 18px 16px calc(18px + var(--safe-b)); }
  .modal-inner .row:last-child button { flex: 1 1 auto; justify-content: center; }
  .drawer { width: 100vw; }
  .drawer-inner { padding: calc(14px + env(safe-area-inset-top, 0px)) 14px calc(40px + var(--safe-b)); }
  #toasts { left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); align-items: stretch; }
  body.has-tabs #toasts { bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px); }
  .toast { max-width: none; font-size: 13px; }

  /* Onboarding */
  .onb { margin: 4px auto; }
  .onb .panel { padding: 16px 14px !important; }
  .choice { grid-template-columns: minmax(0, 1fr); }
  .choice button { min-height: 56px; }

  /* Interview: timers become a compact strip pinned under the header; reference panels go below the chat */
  .iv-stage { display: flex; flex-wrap: wrap; gap: 8px; }
  .iv-stage > * { flex: 1 1 100%; min-width: 0; }
  .iv-stage > .grid { display: contents; }
  .iv-stage > .grid > .panel, .iv-stage > .panel + .panel { order: -1; flex: 1 1 40%; position: sticky; top: calc(52px + env(safe-area-inset-top, 0px)); z-index: 4;
    padding: 6px 10px; box-shadow: -8px 0 0 var(--bg), 0 -8px 0 var(--bg), -8px -8px 0 var(--bg), 0 8px 0 var(--bg), -8px 8px 0 var(--bg); }
  .iv-stage > .grid > .panel > .ph, .iv-stage > .panel + .panel > .ph { margin: -6px -10px 2px; padding: 5px 10px; border: 0; }
  .iv-stage > .grid > .panel > .small.muted, .iv-stage > .panel + .panel > .small.muted { display: none; }
  .iv-stage > .grid > .panel .timer, .iv-stage > .panel + .panel .timer { font-size: 20px !important; line-height: 1.2; }
  .iv-stage > .grid > .panel.iv-aside { order: 1; position: static; flex-basis: 100%; padding: 12px; box-shadow: none; }
  .iv-stage > .grid > .panel.iv-aside > .ph { margin: -12px -12px 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
  .chat .msg { scroll-margin-top: 140px; }
  .chat { max-height: none; }
  .msg { max-width: 94%; }
  .timer { font-size: 24px; }

  /* Map */
  .map-tip { display: none !important; }
  .legend { flex-wrap: wrap; gap: 8px 14px; }

  details.x summary { padding: 6px 0; }
  .empty { padding: 14px; }
}
/* Phone held sideways: slimmer bars, and keep content clear of the notch at the left/right edge */
@media (pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  :root { --tabbar-h: 44px; }
  #topbar { min-height: 44px; padding-top: 4px; padding-bottom: 4px; top: env(safe-area-inset-top, 0px); }
  #topbar, #view, body.has-tabs #tabbar { padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
  #tabbar a, #tabbar button { flex-direction: row; gap: 6px; font-size: 12px; }
  #tabbar svg { width: 18px; height: 18px; }
  #nav { padding-left: env(safe-area-inset-left, 0px); }
  .iv-stage > .grid > .panel, .iv-stage > .panel + .panel { top: calc(44px + env(safe-area-inset-top, 0px)); }
  .modal-inner { max-height: 96dvh; }
}
@media (hover: none) {
  table.t tr:hover td, #navlinks a:hover, .board-item:hover { background: inherit; }
  #navlinks a.on { background: var(--panel2); }
}


/* ---------- Beta: AI Interview Coach teaser ---------- */
.coach { border-color: var(--accent); }
.coach-ex { border: 1px dashed var(--line2); padding: 10px; }
.coach-ex .msg { max-width: 100%; margin-bottom: 6px; }
label.chip input[type="checkbox"] { width: auto; margin: 0; }
#acct:empty { display: none; }
#acct button { white-space: nowrap; }
@media (max-width: 760px), (pointer: coarse) and (max-height: 500px) {
  /* Guests on a phone: the sign-in button replaces the handle chip to save room. */
  .top-actions:has(#signInBtn) #who { display: none; }
}
