/* ==========================================================================
   Design tokens

   The visual language of a clinical reading app: text-first, dense, one
   accent colour used sparingly so it always means "actionable". Type is the
   UI here -- papers are long-form, so the reading column and line-height get
   more care than any decorative element.
   ========================================================================== */
:root {
  --teal-50:  #eef7f7;
  --teal-100: #d3ebeb;
  --teal-500: #0d7c7c;
  --teal-600: #0a6666;
  --teal-700: #085252;

  --ink-900: #10161c;
  --ink-800: #1c252e;
  --ink-700: #33414f;
  --ink-500: #5d6b7a;
  --ink-400: #8593a1;
  --ink-300: #b9c3cc;
  --ink-200: #dde3e9;
  --ink-100: #eef1f4;
  --ink-50:  #f7f9fa;

  --amber:  #b7791f;
  --rose:   #c0392b;
  --green:  #1e7d5a;

  --bg:        #ffffff;
  --surface:   #ffffff;
  --surface-2: #f4f6f8;
  --border:    #e3e8ec;
  --text:      #000000;
  --text-dim:  #414d59;
  --text-mute: #6b7885;
  --accent:    var(--teal-500);
  --accent-dim:var(--teal-50);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16,22,28,.06), 0 1px 3px rgba(16,22,28,.04);
  --shadow-md: 0 4px 12px rgba(16,22,28,.08);
  --shadow-lg: 0 12px 32px rgba(16,22,28,.14);

  --header-h: 56px;
  --tabbar-h: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="dark"] {
    --bg:        #0d1216;
    --surface:   #151d24;
    --surface-2: #1e2831;
    --border:    #2a3641;
    --text:      #e8edf1;
    --text-dim:  #9aa8b5;
    --text-mute: #6e7d8a;
    --accent:    #2fa8a8;
    --accent-dim:#12292c;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,.45);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.55);
  }
}
:root[data-theme="dark"] {
  --bg:        #0d1216;
  --surface:   #151d24;
  --surface-2: #1e2831;
  --border:    #2a3641;
  --text:      #e8edf1;
  --text-dim:  #9aa8b5;
  --text-mute: #6e7d8a;
  --accent:    #2fa8a8;
  --accent-dim:#12292c;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,.45);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }

/* ---------- app shell ---------- */
#app { min-height: 100dvh; }

.screen {
  display: none;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  min-height: 100dvh;
}
.screen.active { display: block; }

.appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; gap: 4px;
  padding-inline: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}
.appbar h1 {
  font-size: 18px; font-weight: 680; letter-spacing: -.02em;
  margin: 0; padding-inline: 8px; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.appbar .icon-btn { flex: none; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; color: var(--text-dim);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.on { color: var(--accent); }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-mute); font-size: 10.5px; font-weight: 550;
  position: relative; transition: color .15s;
}
.tab.active { color: var(--accent); }
.tab svg { width: 22px; height: 22px; }
.tab .badge {
  position: absolute; top: 4px; left: 50%; margin-left: 4px;
  background: var(--rose); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1;
  padding: 2.5px 5px; border-radius: 999px; min-width: 17px; text-align: center;
}

/* ---------- paper card ---------- */
.list { padding: 10px 12px 24px; max-width: 720px; margin: 0 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 15px 11px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: box-shadow .18s, transform .18s, border-color .18s;
  cursor: pointer;
}
.card:active { transform: scale(.988); }
@media (hover: hover) {
  .card:hover { box-shadow: var(--shadow-md); border-color: var(--ink-300); }
}
/* Unread marker: a quiet rail, not a loud dot. */
.card.unread::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.card.read .card-title { color: var(--text-dim); font-weight: 560; }

.card-src {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 640; letter-spacing: .02em;
  color: var(--accent); text-transform: uppercase;
  margin-bottom: 5px;
}
.card-src .dot { color: var(--ink-300); font-weight: 400; }
.card-src .date { color: var(--text-mute); text-transform: none; letter-spacing: 0; font-weight: 500; }

.card-title {
  font-size: 16px; font-weight: 640; line-height: 1.32;
  letter-spacing: -.011em; margin: 0 0 6px;
  color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-authors {
  font-size: 13px; color: var(--text-dim); margin-bottom: 9px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-foot {
  display: flex; align-items: center; gap: 4px;
  border-top: 1px solid var(--border); padding-top: 7px; margin-top: 2px;
}
.card-foot .spacer { flex: 1; }
.card-act {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 9px; border-radius: 8px;
  font-size: 12.5px; font-weight: 560; color: var(--text-mute);
  transition: background .15s, color .15s;
}
.card-act svg { width: 16px; height: 16px; }
.card-act:hover { background: var(--surface-2); color: var(--text); }
.card-act.on { color: var(--accent); }
.card-act.on svg { fill: currentColor; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 5px;
  background: var(--surface-2); color: var(--text-dim);
}
.pill.trial { background: var(--accent-dim); color: var(--accent); }
.pill.review { background: color-mix(in srgb, var(--amber) 13%, transparent); color: var(--amber); }
.pill.free  { background: color-mix(in srgb, var(--green) 13%, transparent); color: var(--green); }

/* ---------- reader ---------- */
.reader { max-width: 700px; margin: 0 auto; padding: 18px 20px 40px; }
.reader .r-journal {
  font-size: 12px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 10px;
}
.reader h2 {
  font-family: var(--serif);
  font-size: 26px; line-height: 1.24; letter-spacing: -.015em;
  font-weight: 700; margin: 0 0 14px;
}
.reader .r-authors { font-size: 14.5px; color: var(--text-dim); line-height: 1.5; margin-bottom: 6px; }
.reader .r-cite { font-size: 13px; color: var(--text-mute); margin-bottom: 16px; }
.reader .r-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.reader .r-actions {
  display: flex; gap: 8px; padding: 12px 0; margin-bottom: 8px;
  border-block: 1px solid var(--border);
}
.reader .r-abstract {
  font-family: var(--serif);
  font-size: 17.5px; line-height: 1.66; color: var(--text);
}
.reader .r-abstract p { margin: 0 0 16px; }
/* Structured abstracts arrive as "METHODS: ..." -- style the label run-in. */
.reader .r-abstract b { font-weight: 700; letter-spacing: .02em; font-size: 13px;
  text-transform: uppercase; font-family: var(--font); color: var(--text-dim);
  display: block; margin-bottom: 3px; }
.reader h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-mute); margin: 26px 0 10px; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 16px; border-radius: 10px; font-size: 15px; font-weight: 600;
  background: var(--accent); color: #fff;
  transition: filter .15s, transform .12s;
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .55; pointer-events: none; }

/* ---------- rows (topics / journals) ---------- */
.row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px;
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.row-sub { font-size: 12.5px; color: var(--text-mute); margin-top: 2px; }
.follow-btn {
  flex: none; padding: 7px 14px; border-radius: 999px;
  font-size: 13px; font-weight: 640;
  border: 1.5px solid var(--accent); color: var(--accent); background: transparent;
  transition: all .15s;
}
.follow-btn.on { background: var(--accent); color: #fff; }
.follow-btn:active { transform: scale(.95); }

.section-head {
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-mute); margin: 22px 4px 10px;
}
.section-head:first-child { margin-top: 6px; }

/* ---------- search ---------- */
.searchbar { padding: 10px 12px; max-width: 720px; margin: 0 auto; }
.searchbar input {
  width: 100%; padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 16px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.searchbar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 12px 12px;
  max-width: 720px; margin: 0 auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 560;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  white-space: nowrap; transition: all .15s;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- states ---------- */
.empty { text-align: center; padding: 64px 32px; color: var(--text-mute); }
.empty svg { width: 46px; height: 46px; opacity: .4; margin-bottom: 14px; }
.empty h3 { font-size: 17px; font-weight: 620; color: var(--text-dim); margin: 0 0 6px; }
.empty p { font-size: 14px; margin: 0 0 18px; line-height: 1.5; }

.skel { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px; margin-bottom: 10px; }
.skel div { height: 11px; border-radius: 4px; margin-bottom: 9px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skel div { animation: none; } }

.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--ink-900); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 550; z-index: 200; box-shadow: var(--shadow-lg);
  opacity: 0; transition: all .26s cubic-bezier(.2,.8,.3,1); pointer-events: none;
  max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.offline-bar {
  position: fixed; top: calc(var(--header-h) + env(safe-area-inset-top));
  left: 0; right: 0; z-index: 45;
  background: var(--amber); color: #fff; text-align: center;
  font-size: 12.5px; font-weight: 600; padding: 5px;
  transform: translateY(-100%); transition: transform .25s;
}
.offline-bar.show { transform: translateY(0); }

/* ---------- auth / onboarding ---------- */
.auth-wrap { max-width: 420px; margin: 0 auto; padding: 40px 24px; }
.brand { text-align: center; margin-bottom: 30px; }
.brand .mark {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 14px;
  background: linear-gradient(145deg, var(--teal-500), var(--teal-700));
  display: grid; place-items: center; box-shadow: var(--shadow-md);
}
.brand .mark svg { width: 32px; height: 32px; color: #fff; }
.brand h1 { font-size: 25px; font-weight: 700; letter-spacing: -.025em; margin: 0; }
.brand p { color: var(--text-mute); font-size: 14.5px; margin: 5px 0 0; }

.field { margin-bottom: 13px; }
.field label {
  display: block; font-size: 12.5px; font-weight: 620; color: var(--text-dim);
  margin-bottom: 5px; letter-spacing: .01em;
}
.field input, .field select {
  width: 100%; padding: 11px 13px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.err { color: var(--rose); font-size: 13.5px; margin: 8px 0 0; min-height: 18px; }
.switch-auth { text-align: center; margin-top: 18px; font-size: 14px; color: var(--text-dim); }

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(10,15,20,.45); z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity .22s;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 101;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.3,1);
  max-height: 78dvh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.sheet.show { transform: translateY(0); }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--border);
  margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 12px; font-size: 17px; font-weight: 650; }
.sheet-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 13px 6px; font-size: 15.5px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.sheet-item:last-child { border-bottom: none; }
.sheet-item svg { width: 20px; height: 20px; color: var(--text-mute); flex: none; }

@media (min-width: 760px) {
  .list, .reader { padding-inline: 0; }
  .card { border-radius: 14px; }
}

/* ---------- evidence tier badges ----------
   Colour carries meaning here: a clinician scanning a feed should be able to
   spot a guideline without reading. Only the top tiers get colour; everything
   else stays neutral so the signal is not diluted. */
.pill.tier-7 { background: color-mix(in srgb, var(--teal-500) 16%, transparent); color: var(--teal-600); }
.pill.tier-6 { background: color-mix(in srgb, var(--teal-500) 12%, transparent); color: var(--teal-600); }
.pill.tier-5 { background: color-mix(in srgb, var(--green) 14%, transparent);    color: var(--green); }
.pill.tier-4 { background: var(--surface-2); color: var(--text-dim); }
.pill.tier-3 { background: var(--surface-2); color: var(--text-mute); }
.pill.tier-1 { background: var(--surface-2); color: var(--text-mute); }

/* The AI bottom line replaces the author list as the scan target on a card:
   a clinician skimming wants the finding, not the byline. */
.card-bottomline {
  font-size: 14px; line-height: 1.42; color: var(--text-dim);
  margin-bottom: 9px; padding-left: 9px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
}

/* ---------- reader: the clinical read ---------- */
.ai-read {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px 11px;
  margin: 4px 0 20px;
}
.ai-head {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 11.5px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 9px;
}
.ai-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
/* Provenance sits in the header, not a settings page: the reader must always
   be able to see this came from a model reading an abstract. */
.ai-prov {
  font-size: 10.5px; font-weight: 550; letter-spacing: 0;
  text-transform: none; color: var(--text-mute);
}
.ai-bottom {
  font-size: 16.5px; line-height: 1.44; font-weight: 560;
  color: var(--text); margin: 0 0 10px;
}
.ai-row { font-size: 14px; line-height: 1.5; color: var(--text-dim); margin-bottom: 5px; }
.ai-row b {
  display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-mute); margin-bottom: 1px;
}
.ai-foot {
  font-size: 11px; color: var(--text-mute);
  margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--border);
}

/* Inline "+N more" for long author lists — a 40-author byline otherwise
   pushes the clinical read below the fold. */
.link-btn {
  color: var(--accent); font-size: inherit; font-weight: 560;
  padding: 0; background: none; border: none;
}

/* Marks the feed card's scan line as model-generated. Without it an AI
   sentence sat in the same visual slot as the author list with nothing
   distinguishing it from the paper's own text. Low-confidence summaries are
   withheld from the card entirely (see cardBottomLine in views.js). */
.card-ai-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 5px;
  border-radius: 3px;
  background: var(--accent-soft, #e8effb);
  color: var(--accent, #2d5bd7);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  vertical-align: 1px;
}

/* ==========================================================================
   ASK -- evidence-grounded clinical Q&A, as a first-class tab.
   Uses the same tokens as the rest of the app so it reads as one product
   rather than a bolted-on chatbot.
   ========================================================================== */

/* Ask is the one screen that must NOT grow with its content: the composer
   has to stay reachable while a long answer scrolls. Every other screen uses
   page-level scrolling with min-height:100dvh, which pushed the input below
   the tab bar and off-screen on a phone. Pin the height instead and let the
   thread scroll inside it. `.screen.active` sets display:block, so the flex
   layout has to be re-declared at equal specificity. */
#screen-ask.active {
  display: flex;
  flex-direction: column;
  /* max-height as well as height: `.screen` sets min-height:100dvh, which
     beat a bare `height` and let the box grow to 3600px so the composer fell
     off-screen. Capping the max is what actually constrains it. */
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  padding-bottom: 0;
  overflow: hidden;
}
/* min-height:0 lets a flex child shrink below its content size -- without it
   the thread refuses to scroll and pushes the composer out instead. */
.ask-thread { min-height: 0; flex: 1 1 auto; overflow-y: auto; }
.ask-composer {
  /* Sits directly above the tab bar rather than after it in flow. */
  margin-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: 10px;
}

.ask-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 8px;
  -webkit-overflow-scrolling: touch;
}

.ask-empty {
  padding: 34px 8px;
  text-align: center;
  color: var(--muted);
}
.ask-empty h2 { font-size: 17px; font-weight: 650; color: var(--text); margin: 0 0 6px; }
.ask-empty p  { font-size: 13.5px; line-height: 1.55; margin: 0 auto 18px; max-width: 30em; }

.ask-suggest {
  display: flex; flex-direction: column; gap: 8px;
  max-width: 34em; margin: 0 auto;
}
.ask-suggest button {
  width: 100%; text-align: left;
  padding: 11px 13px; font-size: 13.5px; line-height: 1.45;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 11px;
  cursor: pointer;
}
.ask-suggest button:hover { border-color: var(--accent); }

.ask-msg { margin-bottom: 18px; }
.ask-q {
  background: var(--accent-dim);
  border: 1px solid var(--border);
  border-radius: 13px 13px 13px 4px;
  padding: 10px 13px;
  font-size: 14.5px; font-weight: 550; color: var(--text);
  margin-left: auto; max-width: 88%;
  border-radius: 13px 13px 4px 13px;
}
.ask-a { font-size: 14.5px; line-height: 1.62; color: var(--text); }
.ask-a h2 {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
  margin: 16px 0 6px;
}
.ask-a p  { margin: 0 0 10px; }
.ask-a ul { margin: 0 0 10px; padding-left: 20px; }
.ask-a li { margin-bottom: 4px; }
.ask-a a.cite {
  display: inline-block; vertical-align: 1px;
  min-width: 17px; padding: 0 4px; margin: 0 1px;
  font-size: 10.5px; font-weight: 700; line-height: 16px; text-align: center;
  color: var(--accent); background: var(--accent-dim);
  border-radius: 4px; text-decoration: none;
}
.ask-a a.cite:hover { background: var(--accent); color: #fff; }

.ask-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); padding: 6px 0;
}
.ask-status .spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: ask-spin .7s linear infinite;
}
@keyframes ask-spin { to { transform: rotate(360deg); } }

/* ---- Evidence trail ---- */
.ask-trail {
  margin-top: 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); overflow: hidden;
}
.ask-trail-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 9px 11px;
}
.ask-grade {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700;
  padding: 3px 7px; border-radius: 6px; border: 1px solid;
}
.ask-grade .dot { width: 6px; height: 6px; border-radius: 50%; }
.grade-high        { color:#0b7a5a; border-color:#0b7a5a44; background:#0b7a5a12; }
.grade-high .dot   { background:#0b7a5a; }
.grade-moderate    { color:#1668b8; border-color:#1668b844; background:#1668b812; }
.grade-moderate .dot{ background:#1668b8; }
.grade-low         { color:#a06a00; border-color:#a06a0044; background:#a06a0012; }
.grade-low .dot    { background:#a06a00; }
.grade-verylow     { color:#b4531d; border-color:#b4531d44; background:#b4531d12; }
.grade-verylow .dot{ background:#b4531d; }
.grade-insufficient{ color:var(--muted); border-color:var(--border); background:transparent; }
.grade-insufficient .dot { background: var(--muted); }

.ask-screened { font-size: 11.5px; color: var(--muted); }
.ask-screened b { color: var(--text); font-weight: 650; }
.ask-dropped { font-size: 11.5px; color: #a06a00; }
.ask-trail-toggle {
  margin-left: auto; font-size: 11.5px; color: var(--muted);
  background: none; border: 0; cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px; padding: 2px;
}
.ask-trail-toggle:hover { color: var(--text); }
.ask-trail-body {
  padding: 4px 11px 11px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 12px;
}
.ask-trail-body h4 {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; margin: 0 0 5px;
}
.ask-trail-body p, .ask-trail-body li { font-size: 12.5px; line-height: 1.5; color: var(--text); margin: 0; }
.ask-pico { display: flex; flex-wrap: wrap; gap: 5px; }
.ask-pico span {
  font-size: 11px; background: var(--accent-dim); color: var(--text);
  padding: 3px 7px; border-radius: 6px;
}
.ask-pico span b { color: var(--muted); margin-right: 4px; }
.ask-query {
  display: block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10.5px; line-height: 1.5; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; margin-bottom: 4px;
  word-break: break-word;
}
.ask-note {
  font-size: 10.5px; color: var(--muted); line-height: 1.5;
  padding-top: 8px; border-top: 1px solid var(--border);
}

/* ---- Sources ---- */
.ask-sources { margin-top: 12px; }
.ask-sources > h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; margin: 0 0 7px;
}
.ask-src {
  display: block; text-decoration: none;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface); padding: 10px 12px; margin-bottom: 7px;
}
.ask-src:hover { border-color: var(--accent); }
.ask-src-n {
  display: inline-block; min-width: 17px; padding: 0 4px; margin-right: 6px;
  font-size: 10.5px; font-weight: 700; line-height: 16px; text-align: center;
  color: var(--accent); background: var(--accent-dim); border-radius: 4px;
}
.ask-src-title { font-size: 13.5px; font-weight: 600; color: var(--text); line-height: 1.4; }
.ask-src-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.ask-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.ask-badge {
  font-size: 10px; font-weight: 650; padding: 2px 6px;
  border-radius: 5px; border: 1px solid;
}
.tier-1 { color:#0b7a5a; border-color:#0b7a5a44; background:#0b7a5a12; }
.tier-2 { color:#1668b8; border-color:#1668b844; background:#1668b812; }
.tier-3 { color:var(--ink-500); border-color:var(--border); background:transparent; }
.tier-4, .tier-5, .tier-6 { color:var(--muted); border-color:var(--border); background:transparent; }
.badge-guideline { color:#6d4bb8; border-color:#6d4bb844; background:#6d4bb812; }

/* ---- Composer ---- */
.ask-composer {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--surface);
}
#ask-input {
  flex: 1; font-size: 15px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 22px; padding: 11px 15px; outline: none;
}
#ask-input:focus { border-color: var(--accent); }
.ask-send {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  color: #fff; background: var(--accent); border: 0;
}
.ask-send:disabled { opacity: .45; cursor: default; }

/* ==========================================================================
   LEGAL pages -- disclaimer, terms, privacy.
   Set for reading, not scanning: longer measure, generous leading. These are
   documents a clinician may actually need to read carefully.
   ========================================================================== */
.legal-body { padding: 4px 18px 40px; }
.legal-doc { max-width: 62ch; margin: 0 auto; }
.legal-doc .lg-lead {
  font-size: 16px; line-height: 1.6; color: var(--text);
  padding-bottom: 14px; margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.legal-doc h2 {
  font-size: 15px; font-weight: 650; color: var(--text);
  margin: 26px 0 8px; line-height: 1.35;
}
.legal-doc p { font-size: 14.5px; line-height: 1.68; color: var(--text); margin: 0 0 12px; }
.legal-doc ul { margin: 0 0 14px; padding-left: 20px; }
.legal-doc li { font-size: 14.5px; line-height: 1.6; margin-bottom: 7px; color: var(--text); }
.legal-doc b { font-weight: 650; }
.lg-updated {
  font-size: 12.5px; color: var(--text-mute); margin-top: 26px;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.lg-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.lg-nav button {
  font-size: 13.5px; color: var(--accent); background: var(--accent-dim);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 13px; cursor: pointer;
}
.lg-nav button:hover { border-color: var(--accent); }
