:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #1d2327;
  --muted: #5d6870;
  --border: #dedbd2;
  --accent: #245c73;
  --accent-soft: #e2eef2;
  --accent-text: #ffffff;
  --ok: #2f7a4f;
  --ok-soft: #e3f1e8;
  --warn: #9a5b12;
  --warn-soft: #fbf0df;
  --danger: #a33a3a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181b; --surface: #1c2226; --surface-2: #232a2f; --text: #e8ecee; --muted: #9aa6ad;
    --border: #2f383e; --accent: #6fb3cc; --accent-soft: #1f3a45; --accent-text: #0e1a1f;
    --ok: #6cc596; --ok-soft: #1c3528; --warn: #e6b16a; --warn-soft: #3a2d1a; --danger: #e08585;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.7rem; margin: 0 0 .25rem; }
h2 { font-size: 1.25rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .4rem; }
small { color: var(--muted); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand small { display: block; font-size: .75rem; }
.logo { font-size: 1.6rem; color: var(--accent); }
.progress-wrap { display: flex; align-items: center; gap: 8px; margin-left: auto; font-size: .85rem; color: var(--muted); }
.progress { width: 140px; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--ok); transition: width .3s; }
.top-actions { display: flex; gap: 6px; }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }

/* Layout */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr) 400px; height: calc(100vh - 61px); }
.sidebar { border-right: 1px solid var(--border); overflow-y: auto; padding: 14px 10px; background: var(--surface); }
.main { overflow-y: auto; padding: 28px clamp(16px, 4vw, 48px) 80px; }
.coach { border-left: 1px solid var(--border); display: flex; flex-direction: column; background: var(--surface); min-height: 0; }

.stage-list { list-style: none; margin: 0; padding: 0; }
.stage-list button { width: 100%; text-align: left; display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; }
.stage-list button:hover { background: var(--surface-2); }
.stage-list button[aria-current="step"] { background: var(--accent-soft); font-weight: 600; }
.stage-num { flex: 0 0 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; border: 1.5px solid var(--border); background: var(--surface); }
.stage-num.done { background: var(--ok); color: #fff; border-color: var(--ok); }
.stage-num.part { border-color: var(--ok); color: var(--ok); }
.stage-label { flex: 1; font-size: .9rem; line-height: 1.3; }
.side-extra { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--border); display: grid; gap: 2px; }
.side-link { text-align: left; border: 0; background: transparent; padding: 7px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: .9rem; }
.side-link:hover, .side-link.active { background: var(--surface-2); color: var(--text); }

/* Stage page */
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; color: var(--accent); font-weight: 600; }
.goal { font-size: 1.05rem; color: var(--muted); max-width: 70ch; margin: .3rem 0 1rem; }
.expert { display: inline-flex; gap: 6px; align-items: center; background: var(--warn-soft); color: var(--warn); padding: 4px 10px; border-radius: 99px; font-size: .82rem; font-weight: 600; }
.questions { margin: .5rem 0 0; padding-left: 1.2rem; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.field { margin-bottom: 18px; }
.field > label, .field > .flabel { display: block; font-weight: 600; margin-bottom: 6px; }
.field textarea, .field input[type=text], .field select, dialog input, dialog textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; background: var(--bg); }
.field textarea { min-height: 84px; resize: vertical; }
.field textarea:focus, .field input:focus, .field select:focus, dialog input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.rating { display: inline-flex; gap: 4px; align-items: center; font-size: .82rem; color: var(--muted); margin-right: 8px; }
.rating button { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .8rem; }
.rating button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 14px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--accent); }

.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.checklist li:last-child { border-bottom: 0; }
.checklist input { margin-top: 5px; width: 17px; height: 17px; accent-color: var(--ok); }
.checklist .txt { flex: 1; }
.resources { padding-left: 1.2rem; margin: 0; }
.nav-row { display: flex; justify-content: space-between; gap: 10px; margin-top: 24px; }

/* Citation chips */
.cite { display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .74em; padding: 1px 6px; margin: 0 1px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); border: 0; cursor: pointer; vertical-align: 1px; white-space: nowrap; }
.cite.bad { background: var(--warn-soft); color: var(--warn); text-decoration: line-through; cursor: help; }
.cite.demo { cursor: default; }

/* Coach */
.coach-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.coach-head small { display: block; font-size: .78rem; }
.modes { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.modes button { border: 1px solid var(--border); background: var(--bg); border-radius: 99px; padding: 4px 10px; font-size: .8rem; cursor: pointer; }
.modes button:hover { border-color: var(--accent); color: var(--accent); }
.chat { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.msg { max-width: 100%; padding: 10px 13px; border-radius: 12px; font-size: .92rem; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); max-width: 88%; white-space: pre-wrap; }
.msg.assistant { background: var(--surface-2); }
.msg.assistant p { margin: .3rem 0; }
.msg.assistant ul, .msg.assistant ol { margin: .3rem 0; padding-left: 1.2rem; }
.msg.error { background: var(--warn-soft); color: var(--warn); }
.msg-tools { display: flex; gap: 6px; margin-top: 6px; font-size: .78rem; color: var(--muted); align-items: center; flex-wrap: wrap; }
.msg-tools button { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; padding: 1px 7px; cursor: pointer; font-size: .78rem; }
.msg-tools button.on { background: var(--accent); color: var(--accent-text); }
.typing { color: var(--muted); font-style: italic; font-size: .88rem; }
.composer { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.disclaimer { margin: 0; padding: 0 14px 12px; font-size: .74rem; color: var(--muted); }
.empty-chat { color: var(--muted); font-size: .9rem; }

/* Evidence library */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters input, .filters select { border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; background: var(--surface); }
.filters input { flex: 1; min-width: 200px; }
.ecard { border-left: 3px solid var(--accent); }
.ecard .meta { font-size: .78rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px; }
.tag { display: inline-block; padding: 0 7px; border-radius: 99px; background: var(--surface-2); font-size: .75rem; }
.tag.pitfall { background: var(--warn-soft); color: var(--warn); }
blockquote { margin: .6rem 0; padding: .4rem .9rem; border-left: 3px solid var(--border); color: var(--muted); font-family: var(--serif); font-style: italic; }

/* Dialogs */
.dialog { border: 0; border-radius: 14px; padding: 0; width: min(620px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(10,20,25,.45); }
.dialog-inner { padding: 22px 24px; display: grid; gap: 12px; max-height: 85vh; overflow-y: auto; }
.dialog-inner h2 { margin: 0; }
.dialog-inner label { display: grid; gap: 4px; font-weight: 600; }
.dialog-inner label.check { display: flex; font-weight: 400; }
dialog input[type=radio], dialog input[type=checkbox] { width: auto; flex: 0 0 auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.consent { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.consent p { margin: 0 0 8px; font-size: .88rem; color: var(--muted); }
.error { color: var(--danger); margin: 0; min-height: 1em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
hr { border: 0; border-top: 1px solid var(--border); width: 100%; }

/* Survey */
.likert { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 6px; max-width: 360px; }
.likert label { display: grid; justify-items: center; font-size: .75rem; color: var(--muted); font-weight: 400; cursor: pointer; }
.likert-ends { display: flex; justify-content: space-between; max-width: 360px; font-size: .75rem; color: var(--muted); }

.fab { position: fixed; right: 16px; bottom: 16px; z-index: 20; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 99px; padding: 12px 18px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.only-mobile { display: none; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 220px minmax(0, 1fr) 340px; }
  .progress { width: 80px; }
}
@media (max-width: 900px) {
  .only-mobile { display: inline-block; }
  .brand small, .progress-wrap { display: none; }
  .top-actions .btn { padding: 6px 8px; font-size: .82rem; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .main { padding: 20px 16px 90px; overflow: visible; }
  .sidebar { position: fixed; inset: 57px auto 0 0; width: 260px; z-index: 15; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .coach { position: fixed; inset: 0; z-index: 30; display: none; }
  .coach.open { display: flex; }
}
@media (max-width: 520px) {
  .top-actions #evidenceBtn { display: none; }
}
@media (max-width: 640px) {
  .top-actions #preregBtn { display: none; }
}

/* v0.2: plain-language layer, screener, finish page, toast */
.time-total { margin: 0 10px 10px; font-size: .8rem; color: var(--muted); }
.stage-meta { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; }
.stage-list button.opt .stage-label { opacity: .6; }
.finish-link { color: var(--ok) !important; font-weight: 600; }
.label-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.label-row label, .label-row .flabel { margin-bottom: 0 !important; }
.field > .label-row { margin-bottom: 6px; font-weight: 600; }
.help-btn { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--accent); font-size: .72rem; font-weight: 700; cursor: pointer; padding: 0; line-height: 1; }
.help-btn[aria-expanded="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.help { background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; margin: 0 0 8px; font-size: .88rem; }
.field.adv .label-row .tag { font-size: .7rem; }
.term { border: 0; background: none; padding: 0; font: inherit; color: inherit; text-decoration: underline dotted var(--accent); text-underline-offset: 3px; cursor: help; }
.term:hover { color: var(--accent); }
.checklist .tech { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.checklist .cites { flex-shrink: 0; max-width: 40%; text-align: right; }
.intro p { margin-top: 0; }
.intro details { margin-top: 8px; }
.intro summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.note { background: var(--warn-soft); color: var(--text); border-left: 3px solid var(--warn); border-radius: 8px; padding: 10px 14px; margin: 12px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn.small { padding: 4px 10px; font-size: .82rem; }
.upload .file-btn { display: inline-block; }
.upload .file-btn.disabled { opacity: .5; pointer-events: none; }
.upload .status { margin-left: 10px; color: var(--muted); font-size: .88rem; }
table.kv { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.kv th, table.kv td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.kv th { width: 28%; color: var(--muted); font-weight: 600; }
.progress-table th { width: auto; }
.prefill { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; font-size: .88rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.action-card h3 { margin-top: 0; }
.next-steps li { margin-bottom: 6px; }
.empty-chat p { margin: 0 0 8px; }
.starter { display: block; width: 100%; text-align: left; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 8px 10px; margin: 6px 0; cursor: pointer; font-size: .86rem; }
.starter:hover { border-color: var(--accent); color: var(--accent); }
.msg [data-continue] { margin-top: 6px; }
.time-hint { background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; font-size: .9rem; }
.small-dialog { width: min(440px, calc(100vw - 32px)); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: min(560px, calc(100vw - 32px)); box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: .9rem; }

/* v0.2.1: one-screen onboarding */
#welcome { width: min(560px, calc(100vw - 32px)); }
.ob-h { margin: 8px 0 0; font-family: var(--font); font-size: 1rem; }
.ob-h small { font-weight: 400; }
.seg-q { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .92rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.dialog-inner .seg label { display: block; font-weight: 400; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 5px 12px; cursor: pointer; font-size: .86rem; }
.seg label + label span { border-left: 1px solid var(--border); }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.consent-line { font-size: .9rem; align-items: flex-start; }
.consent-more { font-size: .85rem; color: var(--muted); margin: 0; }
.team-badge { margin: 0; font-size: .9rem; color: var(--ok); font-weight: 600; }
.btn.big { padding: 10px 22px; font-size: 1rem; }

a.side-link { text-decoration: none; display: block; }
