/* Social Security Expert: "Reporter" look (David's pick, 2026-11-12).
   White page, royal blue, answers set in a serif with square corners, like a bound reporter.
   EVERY color is a token. Contrast for each text/background pair is computed by
   scripts/check.mjs from the values below, in both themes, and the build fails under 4.5:1. */
:root, :root[data-theme="light"] {
  --bg: #ffffff; --card: #ffffff; --bar: #f5f7fb; --line: #d5dbe7; --ink: #111a2e; --muted: #4f5b73;
  --accent: #1e4fd0; --on: #ffffff; --link: #1a44b4; --soft: #e6edfc; --softink: #173c9e;
  --quote: #f3f6fc; --warn: #a3341c; --warnbg: #fbece8; --ok: #17603f; --okbg: #e6f4ec; --userbg: #1e4fd0; --userink: #ffffff;
  --shadow: 0 8px 28px rgba(17, 26, 46, .14); color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1624; --card: #151e30; --bar: #151e30; --line: #27344d; --ink: #e6ecf8; --muted: #9aa7c0;
  --accent: #7fb2ff; --on: #0c1424; --link: #9cc4ff; --soft: #1c2c4c; --softink: #b9d4ff;
  --quote: #1a2740; --warn: #ff9a8a; --warnbg: #3a1d1a; --ok: #7fe0b0; --okbg: #12301f; --userbg: #7fb2ff; --userink: #0c1424;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
}
:root {
  --sans: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --r: 6px; --gut: max(14px, env(safe-area-inset-left, 0px)); --gutr: max(14px, env(safe-area-inset-right, 0px));
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); overflow: hidden; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell: fixed chrome, only the middle scrolls ---------- */
#app { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; grid-template-areas: "top" "main" "tabs"; }
.topbar { grid-area: top; position: relative; display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top, 0px)) var(--gutr) 10px var(--gut); background: var(--bar); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.brand-name { font: 600 17px/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lda { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: none; }
.lda button { border: 0; background: transparent; color: var(--muted); font: 600 12px/1 var(--sans); padding: 6px 9px; }
.lda button.on { background: var(--accent); color: var(--on); }
.appver.fail { color: var(--warn) !important; font-weight: 700 !important; }
#main { grid-area: main; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: none; }
.view.on { display: flex; }
.tabs { grid-area: tabs; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--bar); border-top: 1px solid var(--line); padding: 0 var(--gutr) env(safe-area-inset-bottom, 0px) var(--gut); position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; }
#app { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }
.tabs button { position: relative; border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font: 600 11px/1.1 var(--sans); min-height: 56px; }
.tabs button.on { color: var(--link); box-shadow: inset 0 2px 0 var(--link); }
.badge { position: absolute; top: 5px; left: calc(50% + 6px); min-width: 18px; padding: 2px 5px; border-radius: 999px; background: var(--warn); color: var(--bg); font: 700 10.5px/1.2 var(--sans); }

/* ---------- buttons, inputs ---------- */
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--r); padding: 9px 14px; font: 600 15px/1.2 var(--sans); min-height: 40px; }
.btn.primary { background: var(--accent); color: var(--on); border-color: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; min-height: 32px; }
.btn.danger { color: var(--warn); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.iconbtn { border: 0; background: transparent; color: var(--muted); width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--r); flex: none; }
.iconbtn.on { color: var(--link); }
.iconbtn.on svg { fill: currentColor; }
input[type=search], input[type=text], input[type=number], input[type=time], select, textarea { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--r); padding: 9px 11px; font-size: 16px; width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; flex: none; }
.seg button { border: 0; background: var(--card); color: var(--muted); padding: 7px 11px; font: 600 13px/1.2 var(--sans); min-height: 36px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--on); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 4px 10px; font: 600 12.5px/1.3 var(--sans); }
button.chip.on { background: var(--accent); color: var(--on); border-color: transparent; }
.tier { display: inline-block; border-radius: 999px; padding: 2px 8px; font: 700 11px/1.4 var(--sans); border: 1px solid var(--line); color: var(--ink); white-space: nowrap; }
.tier.primary { background: var(--soft); color: var(--softink); border-color: transparent; }
.tier.other_view { border-style: dashed; color: var(--muted); }
.tier.unrated, .tier.excluded, .tier.flag { background: var(--warnbg); color: var(--warn); border-color: transparent; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- chat ---------- */
#view-chat { flex-direction: row; }
.side { display: none; }
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head { display: flex; align-items: center; gap: 4px; padding: 2px var(--gutr) 2px var(--gut); border-bottom: 1px solid var(--line); }
.chat-title { flex: 1; min-width: 0; font: 600 15px/1.3 var(--sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.thread { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 14px var(--gutr) 18px var(--gut); display: flex; flex-direction: column; gap: 14px; }
.thread > * { width: 100%; max-width: 780px; margin-inline: auto; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.bubble { max-width: 88%; background: var(--userbg); color: var(--userink); padding: 9px 13px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.long { max-height: 9.5em; overflow: hidden; position: relative; }
.bubble-more { border: 0; background: transparent; color: var(--link); font: 600 13px/1 var(--sans); padding: 4px; }
.attached { font: 600 12.5px/1.3 var(--sans); color: var(--muted); }
.answer { font: 17px/1.62 var(--serif); overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; }
.answer p { margin: 0 0 .85em; }
.answer h2, .answer h3, .answer h4 { font: 700 17px/1.3 var(--sans); margin: 1.2em 0 .45em; }
.answer h2 { font-size: 18.5px; }
.answer ul, .answer ol { margin: 0 0 .85em; padding-left: 1.35em; }
.answer li { margin: .25em 0; }
.answer blockquote { margin: 0 0 .95em; padding: 10px 12px 8px; background: var(--quote); border-left: 3px solid var(--accent); }
.answer blockquote p:last-of-type { margin-bottom: 0; }
.answer code { font: 14px/1.4 ui-monospace, Menlo, Consolas, monospace; background: var(--bar); padding: 1px 4px; border-radius: 4px; }
.answer pre { background: var(--bar); border: 1px solid var(--line); padding: 10px; overflow-x: auto; border-radius: var(--r); }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.answer .tablewrap { overflow-x: auto; margin-bottom: .9em; }
.answer table { border-collapse: collapse; font: 14.5px/1.4 var(--sans); }
.answer th, .answer td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.qbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 6px; font: 600 12px/1.3 var(--sans); }
.qmark { margin-right: auto; }
.qmark.ok { color: var(--ok); }
.qmark.bad { color: var(--warn); }
button.stag { border: 0; background: var(--soft); color: var(--softink); border-radius: 4px; padding: 0 5px; font: 700 11.5px/1.6 var(--sans); vertical-align: 1px; margin-left: 2px; }
button.stag.other_view { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.working { display: flex; align-items: center; gap: 10px; font: 600 14px/1.35 var(--sans); color: var(--muted); padding: 8px 0; }
.working .what { flex: 1; min-width: 0; }
.working .detail { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot3 { display: inline-flex; gap: 4px; }
.dot3 i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: sse-pulse 1.1s ease-in-out infinite; }
.dot3 i:nth-child(2) { animation-delay: .18s; } .dot3 i:nth-child(3) { animation-delay: .36s; }
@keyframes sse-pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dot3 i { animation: none; opacity: .7; } }
.foot { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; display: flex; flex-direction: column; gap: 8px; font-family: var(--sans); }
.foot .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.foot .meta { font-size: 12px; color: var(--muted); }
.note { border-radius: var(--r); padding: 8px 10px; font: 500 13.5px/1.4 var(--sans); }
.note.ok { background: var(--okbg); color: var(--ok); }
.note.warn { background: var(--warnbg); color: var(--warn); }
.srcs { display: flex; flex-direction: column; gap: 4px; }
.src { display: flex; align-items: baseline; gap: 6px; text-align: left; border: 0; background: transparent; padding: 3px 0; font: 500 13.5px/1.35 var(--sans); color: var(--ink); width: 100%; }
.src .t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
a.src { text-decoration: none; }
a.src .t { color: var(--link); text-decoration: underline; }
details.trail summary { font: 600 13px/1.3 var(--sans); color: var(--muted); cursor: pointer; }
details.trail ol { margin: 6px 0 0; padding-left: 1.3em; font: 13px/1.45 var(--sans); color: var(--muted); max-height: 190px; overflow-y: auto; }
.empty { margin: auto; text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; padding: 10px 0; }
.empty h2 { font: 600 22px/1.25 var(--serif); margin: 0; text-wrap: balance; }
.empty p { margin: 0; color: var(--muted); max-width: 46ch; }
.starters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr)); gap: 8px; width: 100%; }
.starters button { text-align: left; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--r); padding: 10px 12px; font: 15px/1.4 var(--serif); }
.composer { border-top: 1px solid var(--line); background: var(--bar); padding: 8px var(--gutr) 8px var(--gut); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; max-width: 780px; margin-inline: auto; }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 34dvh; line-height: 1.4; border-radius: 18px; padding: 9px 13px; }
.composer .send { border-radius: 18px; min-width: 68px; }
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; max-width: 780px; margin: 0 auto 6px; }
.thread.drop { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* ---------- panes (History, Library, Settings): header fixed, body scrolls ---------- */
.pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pane-head { padding: 10px var(--gutr) 10px var(--gut); border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pane-head h1 { font: 600 20px/1.2 var(--serif); margin: 0; flex: none; }
.pane-head input[type=search] { flex: 1 1 200px; min-width: 0; }
.pane-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px var(--gutr) 22px var(--gut); display: flex; flex-direction: column; gap: 12px; }
.pane-body > * { width: 100%; max-width: 980px; margin-inline: auto; }
.rows { display: flex; flex-direction: column; }
.rowitem { display: flex; gap: 8px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rowitem .main { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 0; color: var(--ink); }
.rowitem .title { font: 600 15.5px/1.35 var(--sans); overflow-wrap: anywhere; }
.rowitem .sub { font: 13px/1.4 var(--sans); color: var(--muted); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: var(--soft); color: var(--softink); padding: 0 2px; }
details.group { border: 1px solid var(--line); border-radius: var(--r); background: var(--card); }
details.group > summary { padding: 12px 14px; font: 600 16px/1.3 var(--sans); cursor: pointer; }
.group-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 8px; }
.stat { border: 1px solid var(--line); border-radius: var(--r); padding: 9px 11px; }
.stat b { display: block; font: 700 21px/1.2 var(--sans); font-variant-numeric: tabular-nums; }
.stat span { font: 12.5px/1.3 var(--sans); color: var(--muted); }
.meter { height: 10px; border-radius: 999px; background: var(--bar); border: 1px solid var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter.over i { background: var(--warn); }
.tablebox { overflow-x: auto; }
table.plain { border-collapse: collapse; width: 100%; font: 13.5px/1.4 var(--sans); font-variant-numeric: tabular-nums; }
table.plain th, table.plain td { text-align: left; padding: 5px 10px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.plain th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.field { display: flex; flex-direction: column; gap: 4px; font: 600 13.5px/1.3 var(--sans); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 10px; }
.srcrow { padding: 11px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.srcrow .head { display: flex; gap: 8px; align-items: baseline; }
.srcrow .head button { flex: 1; min-width: 0; border: 0; background: transparent; padding: 0; text-align: left; color: var(--ink); font: 600 15.5px/1.35 var(--sans); overflow-wrap: anywhere; }
.rate { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rate .seg button { padding: 6px 9px; font-size: 12.5px; }
.passage { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.passage .text { font: 15.5px/1.55 var(--serif); max-height: 11em; overflow: hidden; overflow-wrap: anywhere; white-space: pre-wrap; }
.passage.open .text { max-height: none; }
.progress { font: 600 13.5px/1.4 var(--sans); color: var(--muted); }

/* ---------- source sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(8, 12, 22, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { position: relative; background: var(--card); color: var(--ink); width: min(760px, 100%); max-height: 86dvh; overflow-y: auto; border-radius: 14px 14px 0 0; border: 1px solid var(--line); box-shadow: var(--shadow); padding: 18px var(--gutr) calc(18px + env(safe-area-inset-bottom, 0px)) var(--gut); }
.sheet-x { position: sticky; top: 0; float: right; background: var(--card); }
.sheet h2 { font: 600 19px/1.3 var(--serif); margin: 0 44px 8px 0; overflow-wrap: anywhere; }
.sheet .kv { font: 14px/1.5 var(--sans); display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0; }
.sheet .kv dt { color: var(--muted); } .sheet .kv dd { margin: 0; overflow-wrap: anywhere; }
.sheet .preview { font: 15px/1.55 var(--serif); background: var(--quote); padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 30dvh; overflow-y: auto; }

/* ---------- PIN gate (team-manager/docs/pin-keypad-standard.md) ---------- */
#pin-gate { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(8px, 2vh, 18px); padding: env(safe-area-inset-top, 0px) 16px env(safe-area-inset-bottom, 0px); }
#pin-gate h1 { font: 600 clamp(20px, 3.4vh, 26px)/1.2 var(--serif); margin: 0 0 4px; }
.pin-gate { display: flex; flex-direction: column; align-items: center; gap: clamp(12px, 2.5vh, 22px); touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pin-dots { display: flex; gap: 10px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.pin-dots span.on { background: var(--ink); }
.pin-gate.busy .pin-dots span.on { animation: pinpulse .9s ease-in-out infinite; }
@keyframes pinpulse { 50% { opacity: .35; } }
.pin-gate.bad .pin-dots { animation: pinshake .35s; }
@keyframes pinshake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pin-msg { min-height: 1.3em; font-size: 16px; color: var(--muted); text-align: center; }
.pin-pad { display: grid; grid-template-columns: repeat(3, clamp(64px, 22vw, 84px)); gap: clamp(10px, 2vh, 16px); }
.pin-pad button { height: clamp(64px, 10vh, 84px); border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-family: inherit; font-weight: 600; font-size: clamp(26px, 4vh, 32px); line-height: 1; touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; }
.pin-pad button:active { background: var(--accent); color: var(--on); }
.pin-pad button:disabled { opacity: .5; }
.pin-pad .pin-del { border: none; background: transparent; font-size: 24px; }
body.gated .topbar .appver { z-index: 101; }

#toast { position: fixed; left: 50%; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 120; background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 999px; font: 600 14px/1.3 var(--sans); max-width: min(92vw, 520px); text-align: center; opacity: 0; pointer-events: none; transition: opacity .18s; }
#toast.show { opacity: 1; }

/* ---------- desktop: tabs move into the header, history sits beside the chat ---------- */
@media (min-width: 900px) {
  #app { grid-template-rows: auto 1fr; grid-template-areas: "top" "main"; padding-bottom: 0; }
  .tabs { position: static; grid-area: auto; display: flex; gap: 2px; border: 0; padding: 0; background: transparent; flex: none; }
  .tabs button { flex-direction: row; gap: 6px; min-height: 40px; padding: 6px 12px; font-size: 14px; border-radius: var(--r); }
  .tabs button.on { box-shadow: none; background: var(--soft); color: var(--softink); }
  .badge { position: static; }
  .topbar { padding-bottom: 12px; }
  .brand { flex: 1; }
  .side { display: flex; flex-direction: column; gap: 10px; width: 290px; flex: none; border-right: 1px solid var(--line); padding: 12px; min-height: 0; background: var(--bar); }
  .side-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
  .side-list button { border: 0; background: transparent; color: var(--ink); text-align: left; padding: 8px 9px; border-radius: var(--r); font: 500 14px/1.35 var(--sans); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
  .side-list button.on { background: var(--soft); color: var(--softink); font-weight: 600; }
  #chat-new { display: none; }
  .chat-title { text-align: left; padding-left: 8px; }
  #toast { bottom: 26px; }
  .sheet-wrap { align-items: center; } .sheet { border-radius: 12px; }
}
/* A phone on its side is short, not wide: keep the phone layout and tighten the chrome. */
@media (max-height: 480px) and (max-width: 899px) {
  .tabs button { min-height: 44px; padding: 4px 2px; } .tabs button span { display: none; }
  #app { padding-bottom: calc(44px + env(safe-area-inset-bottom, 0px)); }
  .chat-head { display: none; }
}
