:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #121826;
  --muted: #5b6475;
  --navy: #0b2a5b;
  --red: #b31942;
  --accent: var(--navy);
  --border: #dde2ea;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 12px 40px rgba(11, 42, 91, 0.10);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --surface: #161b24; --surface-2: #1f2633; --text: #eef2f7; --muted: #9aa5b8;
    --navy: #8fb3ff; --red: #ff6b8a; --accent: #8fb3ff; --border: #2a3444; --shadow: 0 12px 40px rgba(0,0,0,.45);
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b24; --surface-2: #1f2633; --text: #eef2f7; --muted: #9aa5b8;
  --navy: #8fb3ff; --red: #ff6b8a; --accent: #8fb3ff; --border: #2a3444; --shadow: 0 12px 40px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }
/* The hidden attribute must win over component display rules (flex, grid…). */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; max-width: 1040px; width: 100%; margin: 0 auto;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, var(--navy), #1f4b99); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 7px; top: 7px; width: 12px; height: 12px; border-radius: 3px; background: var(--red); }
.brand-dot { color: var(--muted); font-weight: 500; font-size: .8em; }
.topnav { display: flex; align-items: center; gap: 18px; font-size: 15px; }
.topnav a { color: var(--muted); text-decoration: none; }
.link-btn { background: none; border: 1px solid var(--border); color: var(--text); font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 999px; cursor: pointer; }

main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px 48px; }

/* Hero */
.hero { text-align: center; padding: 10vh 0 28px; }
.hero-title { font-size: clamp(40px, 8vw, 64px); margin: 0 0 8px; letter-spacing: -0.03em; font-weight: 800; }
.hero-sub { font-size: clamp(18px, 2.6vw, 22px); color: var(--muted); margin: 0; }

/* Composer */
.composer { position: sticky; bottom: 0; padding: 12px 0 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); z-index: 5; }
.composer-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 12px 10px;
}
.composer-box:focus-within { border-color: var(--accent); }
textarea#prompt {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; font-size: 18px; line-height: 1.4; padding: 6px 6px 4px; max-height: 40vh;
}
textarea#prompt::placeholder { color: var(--muted); opacity: .8; transition: opacity .25s; }
textarea#prompt.placeholder-fade::placeholder { opacity: 0; }
.composer-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.recording { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--red) 18%, transparent); } }
.send-btn {
  margin-left: auto; width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--navy); color: #fff; display: grid; place-items: center; cursor: pointer; transition: transform .15s, opacity .15s;
}
:root[data-theme="dark"] .send-btn { color: #0d1117; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .send-btn { color: #0d1117; } }
.send-btn svg { width: 22px; height: 22px; }
.send-btn:disabled { opacity: .45; cursor: default; }
.send-btn:not(:disabled):hover { transform: translateY(-1px); }
.send-btn.stop svg { display: none; }
.send-btn.stop::before { content: ""; width: 14px; height: 14px; background: currentColor; border-radius: 3px; }
.composer-note { font-size: 13px; color: var(--muted); text-align: center; margin: 12px 8px 0; }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 6px 8px; }
.attachment { display: inline-flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 6px 8px 6px 10px; font-size: 14px; }
.attachment img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }
.attachment button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 10px 0 48px; }
.chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--text); border-radius: 999px;
  padding: 10px 16px; font: inherit; font-size: 15px; cursor: pointer; transition: background .15s, transform .15s;
}
.chip:hover { background: var(--surface-2); transform: translateY(-1px); }

/* Cards (Apple-product-page style rounded squares) */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px 24px 22px; }
.card-wide { grid-column: 1 / -1; }
.card h2 { font-size: 22px; margin: 14px 0 6px; letter-spacing: -0.015em; }
.card p { margin: 0; color: var(--muted); font-size: 16px; }
.card-glyph { width: 56px; height: 56px; border-radius: 16px; background: var(--surface-2); display: grid; place-items: center; color: var(--navy); cursor: default; }
.card-glyph svg { width: 34px; height: 34px; }
#flag-glyph { cursor: pointer; position: relative; }
#flag-glyph .glyph-flag { display: none; }
#flag-glyph.flag .glyph-arrow { display: none; }
#flag-glyph.flag .glyph-flag { display: block; animation: pop .3s ease; }
@keyframes pop { from { transform: scale(.6); } to { transform: scale(1); } }
.seals { width: auto; padding: 0 10px; gap: 6px; display: flex; cursor: pointer; }
.seal { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 800; color: #fff; background: var(--navy); border: 2px solid var(--surface); letter-spacing: .02em; }
.seal:nth-child(2) { background: var(--red); }
.seal:nth-child(3) { background: #1f6f43; }
.seal.flip { animation: flip .35s ease; }
@keyframes flip { 50% { transform: rotateY(90deg); } }
@media (max-width: 560px) { .cards { grid-template-columns: 1fr; } }

/* Thread */
.thread { display: flex; flex-direction: column; gap: 22px; padding: 12px 0 8px; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble { background: var(--navy); color: #fff; border-radius: 20px 20px 6px 20px; padding: 12px 16px; max-width: 85%; white-space: pre-wrap; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .msg-user .bubble { color: #0d1117; } }
:root[data-theme="dark"] .msg-user .bubble { color: #0d1117; }
.bubble .thumbs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.bubble .thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.bubble .thumbs .doc { background: rgba(255,255,255,.2); border-radius: 10px; padding: 6px 10px; font-size: 13px; }
.msg-assistant { display: flex; flex-direction: column; }
.msg-assistant > * { order: 2; }
.msg-assistant > .status { order: 0; }
.msg-assistant > .answer { order: 1; }
/* Once text is streaming, later status lines ("Searching…") show under the text, not above it. */
.msg-assistant.has-text > .status { order: 1; margin: 10px 0 0; }
.msg-assistant.has-text > .answer { order: 0; }
.msg-assistant { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.status { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; margin-bottom: 8px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p, .answer li { line-height: 1.55; }
.answer h1, .answer h2, .answer h3 { font-size: 1.05em; margin: 1em 0 .4em; }
.answer ol, .answer ul { padding-left: 1.4em; }
.answer li { margin: .3em 0; }
.answer a { word-break: break-word; }
.answer code { background: var(--surface-2); padding: .1em .35em; border-radius: 6px; font-size: .92em; }
.cite { display: inline-block; vertical-align: super; font-size: 11px; font-weight: 700; line-height: 1; margin-left: 2px; text-decoration: none; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 6px; padding: 2px 5px; }
.answer .cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.answer.refusal, .answer.error { color: var(--muted); }
.sources { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; font-size: 14px; }
.sources summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.sources .count { font-weight: 400; }
.source-list { margin: 8px 0 0; padding-left: 1.4em; }
.source-list li { margin: 4px 0; }
.source-list a { text-decoration: none; }
.source-list a:hover { text-decoration: underline; }
.source-list .domain { color: var(--muted); margin-left: 6px; font-size: 13px; }
.source-list li.cited { font-weight: 600; }
.meta { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* In-house layers: badges that say an answer drew on program notes or nearby resources */
.layers { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.layer {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px 4px 8px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, transparent), color-mix(in srgb, var(--red) 8%, transparent));
}
.layer .spark { color: var(--accent); font-size: 12px; }
.layer-expertise .spark { font-size: 14px; line-height: 1; }

/* Callouts: blockquotes in answers hold the one thing not to miss */
.answer blockquote {
  position: relative; margin: 14px 0; padding: 12px 44px 12px 14px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, #f2b33d 14%, var(--surface)); border: 1px solid color-mix(in srgb, #f2b33d 45%, var(--border));
  border-left: 4px solid #f2b33d;
}
.answer blockquote p { margin: 0; }
.answer blockquote p + p { margin-top: .5em; }
.answer blockquote strong:first-child { color: color-mix(in srgb, #9a5b00 85%, var(--text)); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .answer blockquote strong:first-child { color: #f7c66b; } }
:root[data-theme="dark"] .answer blockquote strong:first-child { color: #f7c66b; }
.clip-btn { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; font-size: 15px; opacity: .75; }
.clip-btn:hover { opacity: 1; background: color-mix(in srgb, #f2b33d 20%, transparent); }
.clip-btn.done { opacity: 1; }

/* Answer actions: save card, call script, send (not wired yet: shows Coming soon!) */
.answer-actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.action-btn { display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: 14px; font-weight: 600; color: var(--accent); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; cursor: pointer; }
.action-btn:hover { border-color: var(--accent); }
.action-btn[disabled] { opacity: .6; cursor: progress; }
.action-btn.done { color: var(--muted); }

/* Proposed update to "Your situation" when the chat contradicts it */
.profile-update { margin-top: 14px; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); font-size: 14px; }
.profile-update .pu-title { font-weight: 600; margin: 0 0 6px; }
.profile-update ul { margin: 0 0 10px; padding-left: 1.2em; }
.profile-update li { margin: 3px 0; }
.profile-update .from { color: var(--muted); text-decoration: line-through; }
.profile-update .pu-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.profile-update .pu-done { color: var(--muted); margin: 0; }

/* Suggested follow-ups */
.followups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.followup { font: inherit; font-size: 14px; text-align: left; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px 12px; cursor: pointer; transition: background .15s, border-color .15s; }
.followup::before { content: "↳ "; color: var(--muted); }
.followup:hover { background: var(--surface-2); border-color: var(--accent); }

/* "Your situation" entry line */
.situation-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 8px; margin: 6px 8px 0; font-size: 13px; color: var(--muted); }
.situation-bar.known #situation-status { color: var(--text); font-weight: 500; }

/* "Your situation" check-in panel */
.intake { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow: hidden; animation: toast-in .2s ease; }
.intake-inner { max-width: 720px; height: 100%; margin: 0 auto; display: flex; flex-direction: column; padding: 0 16px; }
.intake-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 0 10px; border-bottom: 1px solid var(--border); }
.intake-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.015em; }
.intake-head p { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.intake-thread { flex: 1; overflow-y: auto; padding: 16px 0; display: flex; flex-direction: column; gap: 12px; }
.ib { max-width: 88%; padding: 11px 14px; border-radius: 18px; line-height: 1.45; font-size: 16px; }
.ib-bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.ib-bot .q { font-weight: 600; margin-top: 4px; }
.ib-bot .q:first-child { margin-top: 0; }
.ib-bot .help { font-size: 13px; color: var(--muted); margin-top: 4px; }
.ib-user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 6px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ib-user { color: #0d1117; } }
:root[data-theme="dark"] .ib-user { color: #0d1117; }
.ib-user.skipped { background: var(--surface-2); color: var(--muted); font-style: italic; }
.ib-typing { color: var(--muted); display: inline-flex; gap: 8px; align-items: center; }
.intake-input { padding: 10px 0 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.intake-input:empty { display: none; }
.opt-row { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { font: inherit; font-size: 15px; padding: 9px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.opt:hover { border-color: var(--accent); }
.opt[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .opt[aria-pressed="true"] { color: #0d1117; } }
:root[data-theme="dark"] .opt[aria-pressed="true"] { color: #0d1117; }
.opt.primary { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .opt.primary { color: #0d1117; } }
:root[data-theme="dark"] .opt.primary { color: #0d1117; }
.opt.ghost { background: transparent; color: var(--muted); }
.field { font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); min-width: 0; }
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper .field { width: 80px; text-align: center; }
.money { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.money .amount { position: relative; }
.money .amount span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money .amount .field { padding-left: 24px; width: 160px; }
.hh-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hh-row .age { width: 90px; }
.hh-row button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; }
.type-row { display: flex; gap: 8px; }
.type-row .field { flex: 1; }
.intake-foot { padding: 8px 0 16px; display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); font-size: 14px; }
.intake-known summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.intake-known p { margin: 6px 0; }
.intake-known ul { margin: 4px 0 6px; padding-left: 1.2em; }
.intake-privacy { margin: 0; font-size: 12px; color: var(--muted); }
#intake-call { align-self: flex-start; }
body.intake-open { overflow: hidden; }

/* Saved drawer */
.saved-btn { display: inline-flex; align-items: center; gap: 6px; }
.saved-count { background: var(--navy); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; line-height: 18px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .saved-count { color: #0d1117; } }
:root[data-theme="dark"] .saved-count { color: #0d1117; }
.saved-btn.bump { animation: pop .3s ease; }
.drawer-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--bg); border-left: 1px solid var(--border); box-shadow: var(--shadow); z-index: 31; display: flex; flex-direction: column; animation: slide-in .2s ease; }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 4px; }
.drawer-head h2 { margin: 0; font-size: 20px; }
.drawer-note { margin: 0 16px 10px; font-size: 13px; color: var(--muted); }
.saved-list { overflow-y: auto; padding: 0 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.saved-empty { color: var(--muted); font-size: 15px; padding: 20px 0; text-align: center; }
.ref-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; font-size: 15px; }
.ref-card .kind { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ref-card h3 { margin: 4px 0 6px; font-size: 17px; letter-spacing: -0.01em; }
.ref-card h4 { margin: 12px 0 4px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ref-card p { margin: 4px 0; line-height: 1.5; }
.ref-card ul, .ref-card ol { margin: 4px 0; padding-left: 1.3em; }
.ref-card li { margin: 3px 0; line-height: 1.45; }
.ref-card .tip { margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, #f2b33d 14%, var(--surface)); border-left: 3px solid #f2b33d; }
.ref-card .say { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.ref-card .exchange { margin: 6px 0; }
.ref-card .exchange .they { color: var(--muted); }
.ref-card .card-actions { display: flex; gap: 12px; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }
.ref-card .card-actions button { background: none; border: 0; padding: 0; font: inherit; font-size: 13px; color: var(--accent); cursor: pointer; }
.ref-card .from { font-size: 12px; color: var(--muted); margin-top: 6px; }
.toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 15px; font-weight: 600; box-shadow: var(--shadow); z-index: 20; animation: toast-in .2s ease; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* Location bar under the composer */
.location-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 10px; margin: 8px 8px 0; font-size: 13px; color: var(--muted); }
.location-bar .loc-text { font-weight: 500; }
.location-bar .loc-text.known { color: var(--text); }
.loc-sep { color: var(--border); }
.loc-btn { background: none; border: 0; padding: 2px 4px; font: inherit; font-size: 13px; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; border-radius: 4px; }
.loc-btn:hover { background: var(--surface-2); }
.loc-btn[disabled] { opacity: .5; cursor: progress; }

.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px; }
body.chat-mode .hero, body.chat-mode .chips, body.chat-mode .cards, body.chat-mode .footer { display: none; }
body.chat-mode main { display: flex; flex-direction: column; min-height: calc(100dvh - 60px); }
body.chat-mode .thread { flex: 1; }
