/* Oakton Preserve Document Assistant — black & gold, matched to the community seal. */
:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #fbfaf7;
  --ink: #1c1917;
  --ink-2: #44403c;
  --muted: #57534e;
  --line: #e7e2d8;
  --line-strong: #d6d0c4;
  --gold: #a16207;          /* text/icons on light: 5.0:1 on white */
  --gold-strong: #854d0e;   /* links: 7:1 on white */
  --gold-soft: #fbf3df;
  --gold-line: #e9cf8f;
  --primary: #1c1917;       /* buttons */
  --on-primary: #ffffff;
  --user-bubble: #1c1917;
  --on-user-bubble: #f7f5f0;
  --warn-bg: #fff7e6; --warn-line: #f0c36d; --warn-ink: #5c3d00;
  --alert-bg: #fdecea; --alert-line: #f5b5ad; --alert-ink: #8a1c13;
  --ok: #166534;
  --radius: 16px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(28,25,23,.06), 0 4px 16px rgba(28,25,23,.06);
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --topbar-h: 60px;
  --wash: rgba(247,245,240,.90);
}
/* Dark is the default theme; light is opt-in via the toggle (data-theme on <html>). */
:root[data-theme="dark"] {
    --bg: #0f0e0c; --surface: #1a1815; --surface-2: #211e1a; --ink: #f5f1e8; --ink-2: #d6d3d1; --muted: #a8a29e;
    --line: #2e2a24; --line-strong: #3d372f;
    --gold: #e3b341; --gold-strong: #f0c75e; --gold-soft: #2a2213; --gold-line: #5c4a1f;
    --primary: #e3b341; --on-primary: #1c1917;
    --user-bubble: #2b2620; --on-user-bubble: #f5f1e8;
    --warn-bg: #2a2412; --warn-line: #8a6d1f; --warn-ink: #f1dc9e;
    --alert-bg: #3a1d1a; --alert-line: #7a3129; --alert-ink: #ffb4a9;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
    --wash: rgba(15,14,12,.90);
  }
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html { overflow-x: clip; -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 12px); }
body { margin: 0; overflow-x: clip; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--sans); min-height: 100dvh; }
img { max-width: 100%; display: block; }
a { color: var(--gold-strong); text-underline-offset: 2px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 4.5vw, 2.2rem); margin: 0 0 .5rem; }
h2 { font-size: 1.3rem; margin: 2rem 0 .75rem; }
.icon { width: 20px; height: 20px; flex: none; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--primary); color: var(--on-primary); padding: .5rem 1rem; border-radius: 8px; z-index: 100; }
.skip:focus { left: 12px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- top bar ---------- */
.brand { display: flex; align-items: center; gap: .6rem; color: var(--ink); text-decoration: none; min-width: 0; }
.brand img { width: 36px; height: 36px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text strong { font-family: var(--serif); font-size: 1.02rem; font-weight: 700; }
.brand-text span { font-size: .75rem; color: var(--muted); letter-spacing: .02em; }
.inline { display: inline; margin: 0; }

/* ---------- generic content pages ---------- */
main { padding: 2rem 16px 1rem; margin: 0 auto; }
.narrow { max-width: 560px; }
.wide { max-width: 1100px; }
.lede { color: var(--muted); font-size: 1.05rem; margin-top: 0; }
.muted, .hint { color: var(--muted); font-size: .92rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; margin: 1rem 0; box-shadow: var(--shadow); }
.card.row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 48px; padding: 0 1.4rem; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 600; transition: transform .1s, background .2s, opacity .2s; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.15); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn .spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.linkbtn { background: none; border: 0; color: var(--gold-strong); padding: 0; text-decoration: underline; min-height: 44px; }
.alert { background: var(--alert-bg); color: var(--alert-ink); border: 1px solid var(--alert-line); padding: .8rem 1rem; border-radius: var(--radius-sm); }
.success { background: var(--gold-soft); border: 1px solid var(--gold-line); padding: 1rem; border-radius: var(--radius-sm); }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 1.1rem; }
.field > span, .field > label { display: flex; justify-content: space-between; font-weight: 600; font-size: .95rem; margin-bottom: .4rem; }
.field input { width: 100%; min-height: 50px; padding: .75rem .9rem; border: 1.5px solid var(--line-strong); border-radius: 12px; background: var(--surface-2); font-size: 16px; transition: border-color .2s, box-shadow .2s; }
.field input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 22%, transparent); }
.field .hint { font-weight: 400; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 3.25rem; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: 10px; }
.pw-toggle:hover { color: var(--ink); }
.check { display: flex; gap: .7rem; align-items: flex-start; margin: 1.25rem 0; font-weight: 500; }
.check input { width: 22px; height: 22px; margin-top: .15rem; accent-color: var(--gold); flex: none; }

/* ---------- sign-in / register ---------- */
body.auth { background: var(--bg); }
.auth-shell { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(380px, .9fr); min-height: 100dvh; padding: 0; max-width: none; }
.auth-photo { position: relative; color: #fff; display: flex; flex-direction: column; justify-content: flex-end; padding: clamp(24px, 5vw, 56px);
  background: #1c1917 url("img/entrance-1400.jpg") center 60% / cover no-repeat; overflow: hidden; }
.auth-photo::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(12,10,8,.15) 0%, rgba(12,10,8,.35) 45%, rgba(12,10,8,.88) 100%); }
.auth-photo-inner { position: relative; max-width: 520px; }
.auth-seal { width: 96px; height: auto; margin-bottom: 1rem; filter: drop-shadow(0 6px 18px rgba(0,0,0,.45)); }
.auth-kicker { margin: 0 0 .4rem; text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; font-weight: 600; color: #f0d58a; }
.auth-tagline { color: #fff; font-size: clamp(1.6rem, 3.2vw, 2.4rem); margin: 0 0 1rem; text-shadow: 0 2px 12px rgba(0,0,0,.4); }
.auth-points { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; font-size: .98rem; color: #f5f1e8; }
.auth-points li { display: flex; align-items: center; gap: .55rem; }
.auth-points .icon { color: #f0d58a; }
.auth-panel { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 40px clamp(16px, 4vw, 48px) 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { font-size: clamp(1.7rem, 3vw, 2.1rem); }
.auth-card .lede { margin-bottom: 1.6rem; }
.auth-alt { margin-top: 1.4rem; text-align: center; color: var(--muted); }
.auth-alt a { font-weight: 600; }
.auth-foot { margin-top: 2rem; font-size: .8rem; color: var(--muted); text-align: center; max-width: 420px; }
.privacy { font-size: .85rem; color: var(--muted); margin-top: 1rem; }
@media (max-width: 860px) {
  /* Phones/tablets: no entrance photo — just the seal, centered above the sign-in card. */
  .auth-shell { grid-template-columns: 1fr; min-height: auto; }
  .auth-photo { min-height: 0; padding: max(32px, env(safe-area-inset-top)) 16px 0; background: var(--bg); align-items: center; text-align: center; }
  .auth-photo::before { display: none; }
  .auth-seal { width: 112px; margin: 0 auto; filter: drop-shadow(0 6px 16px rgba(0,0,0,.35)); }
  .auth-kicker, .auth-tagline, .auth-points { display: none; }
  .auth-panel { justify-content: flex-start; padding-top: 20px; }
  .auth-card h1 { text-align: center; }
  .auth-card .lede { text-align: center; }
}

/* ---------- chat page ---------- */
body.chat-page { background: var(--bg); }
body.chat-page::before { content: ""; position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(var(--wash), var(--wash)), url("img/entrance-blur.jpg") center / cover no-repeat; }
.chat { max-width: 820px; padding: 0 16px; display: flex; flex-direction: column; min-height: calc(100dvh - var(--topbar-h)); }
.intro { padding: clamp(24px, 6vh, 64px) 0 1rem; text-align: center; }
.intro-seal { width: 88px; height: auto; margin: 0 auto 1rem; filter: drop-shadow(0 6px 16px rgba(0,0,0,.18)); }
.intro h1 { margin-bottom: .4rem; }
.intro .lede { max-width: 34rem; margin: 0 auto; }
.suggest { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; margin: 1.6rem 0 1rem; text-align: left; }
.suggest button { display: flex; align-items: flex-start; gap: .6rem; min-height: 56px; padding: .8rem 1rem; border-radius: 14px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--ink); text-align: left; font-size: .95rem; line-height: 1.35; box-shadow: var(--shadow); transition: border-color .2s, transform .15s; }
.suggest button:hover { border-color: var(--gold-line); transform: translateY(-1px); }
.suggest .icon { color: var(--gold); margin-top: .1rem; width: 18px; height: 18px; }
@media (max-width: 600px) { .suggest { grid-template-columns: 1fr; } .suggest button:nth-child(n+5) { display: none; } }

.thread { flex: 1; padding: 1rem 0 .5rem; }
.msg { display: flex; gap: .7rem; margin: 1.1rem 0; animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--user-bubble); color: var(--on-user-bubble); border-radius: 18px 18px 6px 18px; padding: .7rem 1rem; max-width: min(85%, 560px); white-space: pre-wrap; overflow-wrap: anywhere; }
.avatar { width: 36px; height: 36px; flex: none; margin-top: 2px; }
.avatar img { width: 36px; height: 36px; filter: drop-shadow(0 1px 3px rgba(0,0,0,.25)); }
.msg.bot.working .avatar img { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.9); opacity: .75; } }
.msg.bot .bubble { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 6px 18px 18px 18px; padding: 1rem 1.15rem; box-shadow: var(--shadow); }
.who { font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: .35rem; letter-spacing: .02em; }
.status { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .95rem; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* answer typography */
.answer { font-size: 1rem; line-height: 1.65; overflow-wrap: anywhere; }
.answer > :first-child { margin-top: 0; } .answer > :last-child { margin-bottom: 0; }
.answer p { margin: .6rem 0; }
.answer p.lead { font-size: 1.05rem; padding: .7rem .9rem; margin: 0 0 .9rem; background: var(--gold-soft); border-left: 4px solid var(--gold); border-radius: 0 10px 10px 0; }
.answer p.lead strong { font-weight: 600; }
.answer h3, .answer h4 { font-family: var(--serif); font-size: 1.08rem; margin: 1.1rem 0 .35rem; }
.answer ul, .answer ol { margin: .5rem 0; padding-left: 1.35rem; }
.answer li { margin: .35rem 0; padding-left: .15rem; }
.answer li::marker { color: var(--gold); }
.answer strong { font-weight: 650; }
.answer code { font-size: .9em; background: var(--surface-2); border: 1px solid var(--line); padding: .05rem .3rem; border-radius: 5px; }
.answer blockquote { margin: .7rem 0; padding: .55rem .9rem; border-left: 3px solid var(--line-strong); color: var(--ink-2); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.answer .table-wrap { overflow-x: auto; margin: .7rem 0; border: 1px solid var(--line); border-radius: 10px; }
.answer table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.answer th, .answer td { padding: .5rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.answer th { background: var(--surface-2); font-weight: 600; }
.answer tr:last-child td { border-bottom: 0; }
.cite { display: inline-flex; align-items: center; justify-content: center; min-width: 1.45em; height: 1.45em; padding: 0 .3em; margin: 0 .08em; vertical-align: .12em;
  font: 600 .7rem/1 var(--sans); color: var(--gold-strong); background: var(--gold-soft); border: 1px solid var(--gold-line); border-radius: 999px; text-decoration: none; }
.cite:hover, .cite:focus-visible { background: var(--gold); color: var(--on-primary); border-color: var(--gold); }
.cursor::after { content: ""; display: inline-block; width: .5em; height: 1em; margin-left: 2px; vertical-align: -.12em; background: var(--gold); animation: blink 1s steps(2) infinite; }

/* sources */
.sources { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.sources summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; font-weight: 600; font-size: .92rem; color: var(--ink-2); }
.sources summary::-webkit-details-marker { display: none; }
.sources summary::before { content: "›"; display: inline-block; transition: transform .2s; color: var(--gold); font-size: 1.2rem; line-height: 1; }
.sources[open] summary::before { transform: rotate(90deg); }
.source-list { list-style: none; margin: .25rem 0 0; padding: 0; display: grid; gap: .5rem; }
.source { border: 1px solid var(--line); border-radius: 12px; padding: .65rem .8rem; background: var(--surface-2); scroll-margin: 90px; transition: border-color .3s, box-shadow .3s; }
.source.flash { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 25%, transparent); }
.source-head { display: flex; gap: .5rem; align-items: baseline; }
.source-n { flex: none; font: 600 .72rem/1.45 var(--sans); color: var(--gold-strong); background: var(--gold-soft); border: 1px solid var(--gold-line); border-radius: 999px; padding: 0 .45rem; }
.source-title { font-weight: 600; font-size: .9rem; line-height: 1.35; }
.source-page { display: block; color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.source blockquote { margin: .5rem 0 0; padding: .4rem .7rem; border-left: 3px solid var(--gold-line); color: var(--ink-2); font-size: .88rem; white-space: pre-wrap; max-height: 9.5rem; overflow: auto; }

/* notices, disclaimer, actions */
.notice { display: flex; gap: .6rem; margin-top: .9rem; padding: .75rem .9rem; border-radius: 12px; font-size: .9rem; background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); }
.notice .icon { margin-top: .1rem; }
.disclaimer { margin: .8rem 0 0; font-size: .78rem; line-height: 1.5; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; margin-top: .5rem; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-width: 44px; min-height: 40px; padding: 0 .6rem; border-radius: 10px;
  border: 1px solid transparent; background: none; color: var(--muted); font-size: .85rem; }
.iconbtn:hover { background: var(--surface-2); border-color: var(--line); color: var(--ink); }
.iconbtn[aria-pressed="true"] { color: var(--gold-strong); background: var(--gold-soft); border-color: var(--gold-line); }
.iconbtn .icon { width: 18px; height: 18px; }
.actions .thanks { font-size: .85rem; color: var(--muted); margin-left: .25rem; }

/* follow-ups */
.followups { margin-top: .9rem; display: grid; gap: .6rem; }
.fu-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .3rem; }
.fu-row { display: flex; gap: .45rem; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; min-height: 40px; padding: .4rem .85rem; border-radius: 999px; border: 1px solid var(--gold-line); background: var(--gold-soft);
  color: var(--ink); font-size: .88rem; line-height: 1.3; text-align: left; transition: background .2s, border-color .2s; }
.chip:hover { border-color: var(--gold); }
.chip.alt { background: var(--surface); border-color: var(--line-strong); }
.chip.alt:hover { border-color: var(--gold); }
@media (max-width: 600px) {
  .fu-row { flex-direction: column; align-items: stretch; }
  .chip { width: 100%; min-height: 44px; border-radius: 12px; justify-content: flex-start; white-space: normal; }
}
.topic-break { display: flex; align-items: center; gap: .75rem; margin: 1.75rem 0 1rem; color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.topic-break::before, .topic-break::after { content: ""; flex: 1; border-top: 1px solid var(--line-strong); }
.msg-error { margin-top: .6rem; }

/* composer */
.composer { position: sticky; bottom: 0; z-index: 10; padding: .6rem 0 calc(.6rem + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 28%); }
.composer-box { display: flex; align-items: flex-end; gap: .5rem; padding: .45rem .45rem .45rem 1rem; border-radius: 22px; border: 1.5px solid var(--line-strong);
  background: var(--surface); box-shadow: var(--shadow); transition: border-color .2s, box-shadow .2s; }
.composer-box:focus-within { border-color: var(--gold); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 18%, transparent), var(--shadow); }
.composer textarea { flex: 1; min-height: 44px; max-height: 40dvh; padding: .6rem 0; border: 0; outline: none; resize: none; background: transparent; font-size: 16px; line-height: 1.5; }
.sendbtn { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); transition: opacity .2s, transform .1s; }
.sendbtn:active { transform: scale(.94); }
.sendbtn:disabled { opacity: .35; cursor: not-allowed; }
.sendbtn.stop { background: var(--surface-2); color: var(--ink); border: 1.5px solid var(--line-strong); }
.fineprint { font-size: .75rem; color: var(--muted); text-align: center; margin: .45rem 0 0; }
.jump { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(110px + env(safe-area-inset-bottom)); z-index: 15; display: none; align-items: center; gap: .35rem;
  min-height: 40px; padding: 0 .9rem; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-size: .85rem; }
.jump.show { display: inline-flex; }
.jump .icon { width: 16px; height: 16px; }

/* ---------- admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; color: var(--muted); font-size: .9rem; box-shadow: var(--shadow); }
.stat span { display: block; font: 600 1.6rem var(--serif); color: var(--ink); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.wide table { display: block; overflow-x: auto; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.answer-raw { white-space: pre-wrap; font: .85rem/1.5 var(--sans); }

.sitefoot { max-width: 820px; margin: 2rem auto 0; padding: 1rem 16px calc(2rem + env(safe-area-inset-bottom)); font-size: .8rem; color: var(--muted); border-top: 1px solid var(--line); }
.sitefoot.compact { display: none; }

/* ---------- layout additions ---------- */
[hidden] { display: none !important; }
.intro-kicker { margin: 0 0 .15rem; text-transform: uppercase; letter-spacing: .16em; font-size: .78rem; font-weight: 700; color: var(--gold); }

/* ---------- user management ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1rem 0; }
.toolbar .search { position: relative; flex: 1 1 240px; }
.toolbar .search .icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.toolbar input[type="search"] { width: 100%; min-height: 46px; padding: .6rem .9rem .6rem 2.4rem; border: 1.5px solid var(--line-strong); border-radius: 999px; background: var(--surface); font-size: 16px; }
.tabs { display: flex; gap: .35rem; flex-wrap: wrap; }
.tab { display: inline-flex; align-items: center; gap: .35rem; min-height: 40px; padding: 0 .9rem; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); text-decoration: none; font-size: .9rem; font-weight: 500; }
.tab[aria-current="page"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.tab .count { font-size: .75rem; opacity: .8; }
.user-list { display: grid; gap: .6rem; }
.user-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem 1rem; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: .85rem 1rem; box-shadow: var(--shadow); }
.user-row .who-line { font-weight: 600; }
.user-row .meta { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.user-row .row-actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 640px) { .user-row { grid-template-columns: 1fr; } .user-row .row-actions { justify-content: flex-start; } }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--ink-2); margin-left: .35rem; vertical-align: .1em; }
.badge.pending { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.badge.approved { background: color-mix(in srgb, var(--ok) 12%, transparent); border-color: color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.badge.disabled { background: var(--alert-bg); border-color: var(--alert-line); color: var(--alert-ink); }
.badge.admin { background: var(--gold-soft); border-color: var(--gold-line); color: var(--gold-strong); }
.btn.sm { min-height: 40px; padding: 0 .9rem; font-size: .88rem; }
.btn.danger { border-color: var(--alert-line); color: var(--alert-ink); background: var(--alert-bg); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }
.field select, .field textarea { width: 100%; min-height: 50px; padding: .7rem .9rem; border: 1.5px solid var(--line-strong); border-radius: 12px; background: var(--surface-2); font-size: 16px; }
.field textarea { min-height: 90px; resize: vertical; }
.section-title { font-family: var(--serif); font-size: 1.15rem; margin: 0 0 .75rem; display: flex; align-items: center; gap: .5rem; }
.section-title .icon { color: var(--gold); }
.flash-msg { margin: 1rem 0; }
.temp-pw { font: 600 1.1rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; background: var(--surface-2); border: 1px dashed var(--gold-line); padding: .5rem .8rem; border-radius: 10px; display: inline-block; user-select: all; }
.radio-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.radio-row label { display: inline-flex; gap: .45rem; align-items: center; min-height: 44px; }
.radio-row input { width: 20px; height: 20px; accent-color: var(--gold); }
.danger-zone { border-color: var(--alert-line); }
.log { font-size: .85rem; color: var(--muted); }
.log li { margin: .25rem 0; }

.mt-sm { margin-top: .6rem; }
.mt { margin-top: 1rem; }

/* phones: tighter chat spacing so answers use the full width */
@media (max-width: 600px) {
  .chat { padding: 0 12px; }
  .msg { gap: .5rem; }
  .avatar, .avatar img { width: 30px; height: 30px; }
  .msg.bot .bubble { padding: .85rem .9rem; }
  .msg.user .bubble { max-width: 88%; }
}

/* theme toggle */
.themebtn .when-dark, .themebtn .when-light { display: inline-flex; align-items: center; gap: .4rem; }
:root[data-theme="dark"] .themebtn .when-light { display: none; }
:root[data-theme="light"] .themebtn .when-dark { display: none; }

/* ---------- chat history drawer ---------- */
.drawer-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); }
.drawer { position: fixed; z-index: 41; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -10px 0 40px rgba(0,0,0,.35);
  padding: max(12px, env(safe-area-inset-top)) 0 env(safe-area-inset-bottom); animation: slidein .2s ease-out; }
@keyframes slidein { from { transform: translateX(24px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 0 12px 0 18px; }
.drawer-head h2 { margin: .4rem 0; font-size: 1.2rem; }
.drawer-note { margin: 0 18px .5rem; color: var(--muted); font-size: .85rem; }
.conv-list { list-style: none; margin: 0; padding: 0 10px 16px; overflow-y: auto; flex: 1; }
.conv { display: flex; align-items: stretch; gap: .25rem; border-radius: 12px; }
.conv + .conv { margin-top: 2px; }
.conv-open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: .7rem .75rem; border-radius: 12px; min-height: 56px; }
.conv-open:hover, .conv.active .conv-open { background: var(--gold-soft); }
.conv-title { display: block; font-weight: 600; font-size: .93rem; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.conv-meta { display: block; font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.conv .iconbtn { align-self: center; }
.conv-empty { color: var(--muted); padding: 1rem 8px; }
@media (max-width: 600px) { .drawer { width: 100vw; border-left: 0; } }

.wide-ish { max-width: 820px; }


/* ---------- security UI ---------- */
.notice-inline { background: var(--gold-soft); border: 1px solid var(--gold-line); color: var(--ink); padding: .75rem 1rem; border-radius: var(--radius-sm); }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; margin: .75rem 0; padding: 0; list-style: none; }
.codes li { font: 600 1rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); border: 1px dashed var(--gold-line); border-radius: 8px; padding: .4rem .6rem; text-align: center; user-select: all; }
.secret { font: 600 1rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; word-break: break-all; background: var(--surface-2); border: 1px dashed var(--gold-line); border-radius: 10px; padding: .6rem .8rem; user-select: all; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-warn { color: var(--warn-ink); font-weight: 600; }
.hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.log td, .log th { font-size: .82rem; }

/* ---------- two-step setup ---------- */
.setup-steps { margin: 0 0 1rem; padding-left: 1.3rem; display: grid; gap: 1.1rem; }
.setup-steps li::marker { color: var(--gold); font-weight: 700; }
.setup-steps .btn { margin-top: .6rem; }
.qr-wrap { width: 220px; height: 220px; margin: .8rem 0 .4rem; padding: 10px; background: #fff; border-radius: 14px; border: 1px solid var(--line-strong); }
.qr-wrap svg { width: 100%; height: 100%; display: block; }
.manual-key { margin-top: .6rem; }
.manual-key summary { cursor: pointer; color: var(--gold-strong); font-size: .92rem; min-height: 44px; display: inline-flex; align-items: center; }
.code-input { font: 600 1.4rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace !important; letter-spacing: .3em; text-align: center; margin-top: .6rem; }
.only-mobile { display: none; }
@media (pointer: coarse) and (max-width: 1024px) { .only-mobile { display: inline-flex; } span.only-mobile { display: inline; } .only-desktop { display: none; } }
@media print { body * { visibility: hidden; } #codes, #codes * { visibility: visible; } #codes { position: absolute; top: 0; left: 0; } }

/* ---------- top bar & navigation (fixed; aligned on phones) ---------- */
.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 30; height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  display: flex; align-items: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line); }
.topbar-space { height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
html { scroll-padding-top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px); }
.topnav { display: flex; align-items: center; justify-content: space-between; gap: .5rem; width: 100%; max-width: 1100px; margin: 0 auto; }
.nav-primary, .nav-inline { display: flex; align-items: center; gap: .25rem; }
.navbtn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; padding: 0 .8rem; border-radius: 999px;
  border: 1px solid transparent; background: none; color: var(--ink-2); text-decoration: none; font: 500 .92rem var(--sans); cursor: pointer; white-space: nowrap;
  transition: background .2s, border-color .2s, color .2s; }
.navbtn:hover, .nav-menu[open] > summary { background: var(--gold-soft); border-color: var(--gold-line); color: var(--ink); }
.navbtn .icon { width: 20px; height: 20px; }
.nav-menu { position: relative; display: none; }
.nav-menu > summary { list-style: none; }
.nav-menu > summary::-webkit-details-marker { display: none; }
.menu-sheet { position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; padding: .4rem; border-radius: 16px; z-index: 31;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: 0 12px 40px rgba(0,0,0,.35); animation: rise .15s ease-out; }
.menu-sheet form { margin: 0; }
.menu-item { display: flex; align-items: center; gap: .75rem; width: 100%; min-height: 48px; padding: 0 .85rem; border: 0; border-radius: 10px;
  background: none; color: var(--ink); text-decoration: none; font: 500 1rem var(--sans); text-align: left; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--gold-soft); }
.menu-item .icon { color: var(--gold); width: 20px; height: 20px; }
.menu-item.themebtn .when-dark, .menu-item.themebtn .when-light { display: inline-flex; align-items: center; gap: .75rem; }
:root[data-theme="dark"] .menu-item.themebtn .when-light, :root[data-theme="light"] .menu-item.themebtn .when-dark { display: none; }
.menu-sheet form:last-child { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .3rem; }

/* Phones & small tablets: three equal, aligned items — [New chat] [History] [Menu] */
@media (max-width: 760px) {
  .nav-inline { display: none; }
  .nav-menu { display: block; }
  .topnav { display: grid; grid-template-columns: 1fr auto; }
  .nav-primary { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: .25rem; }
  .navbtn { padding: 0 .65rem; font-size: .88rem; gap: .35rem; }
  .chat-page .topnav { grid-template-columns: 2fr 1fr; }
  .chat-page .nav-menu > summary { width: 100%; }
}
@media (max-width: 360px) { .navbtn span { font-size: .8rem; } .navbtn { padding: 0 .4rem; } }

/* Installed app: respect the notch / home indicator */
.is-app .composer { padding-bottom: calc(.6rem + env(safe-area-inset-bottom)); }

/* ---------- install banner ---------- */
.install-banner { position: fixed; z-index: 35; left: 50%; top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px); transform: translate(-50%, -10px); opacity: 0;
  width: min(560px, calc(100vw - 20px)); display: grid; grid-template-columns: auto 1fr; gap: .4rem .8rem; align-items: center;
  padding: .85rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--gold-line); box-shadow: 0 14px 44px rgba(0,0,0,.4);
  transition: opacity .25s, transform .25s; }
.install-banner.show { opacity: 1; transform: translate(-50%, 0); }
.install-banner img { width: 44px; height: 44px; border-radius: 10px; }
.install-text { display: grid; gap: .15rem; font-size: .9rem; line-height: 1.4; }
.install-text span { color: var(--muted); }
.install-text .icon { width: 16px; height: 16px; vertical-align: -3px; color: var(--gold); }
.install-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: .5rem; }
.offline { text-align: center; padding-top: 18vh; }
.offline .intro-seal { margin: 0 auto 1rem; }
