:root {
  --bg: #f8f9fa;
  --panel: #ffffff;
  --panel-border: #dadce0;
  --text: #202124;
  --muted: #5f6368;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --user-bg: #e8f0fe;
  --assistant-bg: #ffffff;
  --ok: #188038;
  --warn: #b06000;
  --error: #d93025;
  --link: #1a73e8;
  --code-bg: #202124;
  --code-text: #e8eaed;
  font-family: "Google Sans", Roboto, Arial, sans-serif;
}

/* Tutor and the proposed study notices share the existing Hub design. */
.topbar-links { display: flex; align-items: flex-end; flex-direction: column; gap: .35rem; font-size: .8rem; text-align: right; }
.privacy-banner { flex-shrink: 0; padding: .7rem 1.25rem; background: #fff5dc; border-bottom: 1px solid #dfc78d; color: #503d17; font-size: .9rem; line-height: 1.45; }
.input-privacy-warning { flex-basis: 100%; margin: 0; color: #725016; font-size: .77rem; line-height: 1.4; }
.responsible-use { flex-shrink: 0; padding: .7rem 1.25rem; border-top: 1px solid var(--panel-border); background: #f8fafc; font-size: .79rem; line-height: 1.45; color: var(--muted); }
.responsible-use p { margin: 0 0 .55rem; }
.responsible-use details { margin-bottom: .6rem; }
.responsible-use summary { cursor: pointer; color: var(--accent); }
.global-feedback { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.global-feedback button { font-size: .75rem; padding: .35rem .6rem; }
.global-feedback a { margin-left: .2rem; }
#tutor-view { flex: 1; min-height: 300px; display: flex; flex-direction: column; }
.tutor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem .3rem; }
.tutor-toolbar h2 { margin: 0 0 .25rem; font-size: 1.25rem; }
.tutor-toolbar p { margin: 0; color: var(--muted); font-size: .9rem; }
.tutor-controls { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; font-size: .8rem; }
.tutor-controls select, #flag-type { padding: .5rem; border: 1px solid var(--panel-border); background: white; border-radius: 7px; color: var(--text); font: inherit; }
.tutor-context { margin: .5rem 1.25rem; color: var(--muted); font-size: .85rem; }
.tutor-starters { display: flex; flex-wrap: wrap; gap: .65rem; padding: .75rem 1.25rem; }
.tutor-starters button { text-align: left; background: #edf4fe; color: #174ea6; border: 1px solid #c8daf6; border-radius: 10px; padding: .8rem 1rem; }
.tutor-choices { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.tutor-status { min-height: 1.2em; margin: .6rem 1.25rem 1rem; }
#tutor-messages { min-height: 80px; }
#tutor-messages .message { max-width: min(95%, 960px); }
.tutor-progress { margin: .1rem 0; padding-left: 1.35rem; color: var(--muted); font-size: .9rem; }
.tutor-progress li { padding: .12rem 0; }
.tutor-progress li:last-child { color: var(--text); font-weight: 600; }
.tutor-progress li.done { color: var(--muted); font-weight: 400; }
#tutor-view[aria-busy="true"] .tutor-status::before { content: ""; display: inline-block; width: .65rem; height: .65rem; margin-right: .5rem; border-radius: 50%; background: var(--accent); animation: tutor-pulse 1.1s ease-in-out infinite alternate; }
@keyframes tutor-pulse { to { opacity: .35; } }
button:disabled { cursor: not-allowed; opacity: .6; }
#flag-modal .flag-modal-panel { width: min(94vw, 700px); max-height: 90vh; overflow-y: auto; font-size: .87rem; line-height: 1.5; }
#flag-modal details { border: 1px solid var(--panel-border); border-radius: 8px; padding: .6rem .8rem; margin-bottom: .8rem; }
#flag-modal details summary { cursor: pointer; font-weight: 600; }
.study-choice { display: flex; align-items: flex-start; gap: .65rem; margin: .75rem 0; font-size: .9rem; }
.study-choice input { margin: .25rem 0 0; flex: 0 0 auto; }
.study-inactive { padding: .85rem 1rem; border: 1px solid #c6d6e7; border-radius: 9px; background: #eef5fc; color: #244565; line-height: 1.5; }
.study-content { width: min(900px, calc(100% - 2.5rem)); margin: 2rem auto 3rem; line-height: 1.6; }
.study-content > h2 { font-size: clamp(1.8rem, 5vw, 2.6rem); margin: .25rem 0 .65rem; letter-spacing: -.04em; }
.study-lead { font-size: 1.08rem; color: #405163; }
.study-eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-size: .75rem; }
.study-card { background: white; border: 1px solid var(--panel-border); border-radius: 12px; padding: 1.4rem 1.6rem; margin: 1rem 0; }
.study-card h3 { margin: 0 0 .8rem; font-size: 1.15rem; }
.study-card p:last-child { margin-bottom: 0; }
.study-disabled-controls { border: 1px solid var(--panel-border); border-radius: 8px; padding: 1rem; margin: 1rem 0; }
.study-disabled-controls legend { padding: 0 .3rem; font-size: .8rem; color: var(--muted); }
.study-disabled-controls button { margin: .25rem .5rem .25rem 0; }
.study-return { display: inline-block; margin-top: .8rem; }
@media (prefers-reduced-motion: reduce) { #tutor-view[aria-busy="true"] .tutor-status::before { animation: none; } }
@media (max-width: 720px) {
  .topbar { align-items: flex-start; gap: .75rem; }
  .topbar-links { max-width: 40%; font-size: .75rem; }
  .privacy-banner { padding: .65rem .85rem; font-size: .82rem; }
  .query-overlay { padding: .55rem .7rem; }
  .query-overlay .query-input-wrap { flex-basis: calc(100% - 90px); }
  .query-overlay .query-overlay-home { order: 1; }
  .query-overlay #send-btn { order: 1; }
  .query-overlay .query-overlay-model, .query-overlay .query-overlay-debug { order: 1; }
  .query-overlay .input-privacy-warning { order: 2; }
  .tutor-toolbar { flex-direction: column; align-items: flex-start; padding: .9rem; }
  .tutor-context { margin: .5rem .9rem; }
  .tutor-starters { padding: .65rem .9rem; }
  .tutor-starters button { width: 100%; }
  .responsible-use { padding: .7rem .85rem; }
  .study-content { width: calc(100% - 1.5rem); margin-top: 1.2rem; }
  .study-card { padding: 1.1rem; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

code {
  background: #f1f3f4;
  color: var(--text);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.topbar {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel);
}

/** Semi-transparent overlay bar — dual function: press Enter to ask a
 * question (routes exactly like the old bottom composer), or just type to
 * live-filter the Browse tree/tiles while on the Browse tab. Sticky so it
 * stays reachable at the top of the screen even if content scrolls. */
.query-overlay {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1.25rem;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  border-bottom: 1px solid var(--panel-border);
  box-shadow: 0 2px 6px rgba(60, 64, 67, 0.08);
}

/** The real <input> sits on top with transparent text/background (only its
 * caret is visible) — a separate .query-highlight-overlay div behind it
 * (same font/padding/border-radius, so a single line of text lines up
 * pixel-for-pixel) actually paints the visible text, so "@Label; " mention
 * segments can be colored differently from free text (2026-08-04: "may be
 * useful to highlight dx text in the search bar with blue, and other text
 * black") — a plain <input> can't have mixed inline text colors on its own.
 * Kept in sync on every keystroke by updateQueryHighlightOverlay(). */
.query-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.query-overlay #query-input {
  position: relative;
  z-index: 2;
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font: inherit;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
}

.query-overlay #query-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* The input's own text color is transparent (see .query-highlight-overlay
 * above) — give the placeholder an explicit visible color so it doesn't
 * inherit that transparency. */
.query-overlay #query-input::placeholder {
  color: #6b7280;
}

.query-highlight-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: pre;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  pointer-events: none;
}

.query-input-wrap:focus-within .query-highlight-overlay {
  background: #ffffff;
}

.query-highlight-overlay .mention-highlight {
  color: var(--accent);
  font-weight: 600;
}

.query-overlay #send-btn {
  flex-shrink: 0;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
}

.query-overlay-debug {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.query-overlay-model {
  flex-shrink: 0;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.query-overlay-home {
  flex-shrink: 0;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.query-overlay-home:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/** "+" completely and unconditionally replaces "VS" as the OncoTree's only
 * leaf action button (renderMentionAddButton in app.js) — same size/shape
 * as .vs-btn, just a different glyph/color so it's visually clear this
 * button means "add to the search bar", not "compare". No separate
 * dropdown/overlay widget: typing "@" just takes over browse-content with
 * the live OncoTree itself (see selectMentionLeaf in app.js). */
.mention-add-btn {
  border-color: var(--accent);
  color: var(--accent);
}

.mention-add-btn:hover {
  background: var(--accent);
  color: #ffffff;
}

.info-modal-list {
  margin: 0.5rem 0 0.9rem;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.status {
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
}

.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.error { color: var(--error); }

/** Full-screen emphasis: the app fills the viewport edge-to-edge instead of
 * sitting in a narrow centered "sandbox" card. .chat-panel (which holds
 * Browse/Ask) takes all remaining height after the topbar + query overlay. */
.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  gap: 0;
}

.chat-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: none;
  border-radius: 0;
}

/** Advanced settings / export — collapsed by default so they never compete
 * with the Browse tree for screen space; expand only on demand. */
.bottom-stack-toggle {
  flex-shrink: 0;
  border-top: 1px solid var(--panel-border);
  background: var(--panel);
  padding: 0.5rem 1.25rem;
}

.bottom-stack-toggle summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}

.bottom-stack-toggle[open] {
  padding-bottom: 1rem;
}

.bottom-stack-toggle[open] .bottom-stack {
  margin-top: 0.75rem;
}

.view-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem 1rem 0;
  border-bottom: 1px solid var(--panel-border);
}

.view-tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.5rem 0.25rem 0.6rem;
  margin-right: 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.view-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.view-panel.hidden {
  /* !important: #browse-view/#ask-view each also carry their own
     `display: flex` rule (higher specificity via ID), which would
     otherwise always win over this class rule and leave the "hidden"
     panel visually stacked underneath the active one. */
  display: none !important;
}

.view-panel#browse-view {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.view-panel#ask-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.browse-breadcrumbs {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
}

.breadcrumb-link {
  background: transparent;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.breadcrumb-current {
  color: var(--text);
  font-weight: 600;
}

.browse-heading {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.browse-search-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.55rem 0 0.35rem;
}

.browse-search-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
}

.browse-search-clear {
  flex-shrink: 0;
  padding: 0.45rem 0.7rem;
  font-size: 0.8rem;
}

.browse-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.85rem;
}

.browse-tile {
  position: relative;
  height: 130px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.6rem 2.4rem;
  container-type: inline-size;
}

.browse-tile-glyph {
  font-size: clamp(0.95rem, 5.5cqw, 1.35rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
  text-align: center;
  line-height: 1.15;
  word-break: break-word;
}

.browse-tile-banner {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.45rem 0.6rem;
  background: rgba(6, 10, 16, 0.62);
}

.browse-tile-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  text-align: left;
  line-height: 1.2;
}

.browse-tile-count {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.75);
}

.chevron-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.oncotree-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.oncotree-title {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
}

.oncotree-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.4rem 0;
  flex-wrap: wrap;
}

.oncotree-info-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: #f8f9fa;
  color: var(--muted-text, #6b7280);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.oncotree-info-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.oncotree-toolbar .btn-secondary {
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
}

.oncotree-zoom-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: 0.25rem;
}

.oncotree-zoom-label {
  font-size: 0.78rem;
  color: var(--muted-text, #6b7280);
  min-width: 2.6rem;
  text-align: center;
}

.oncotree-container {
  overflow-x: auto;
  overflow-y: visible;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #fbfbfc;
  margin-top: 0.5rem;
}

.oncotree-canvas {
  position: relative;
}

.oncotree-links {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.oncotree-node {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  height: 28px;
  max-width: 300px;
  padding: 0 0.4rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
}

/* Leaves render as a sibling label-button + VS-button pair (a button can't
 * validly nest inside another button) — this wrapper positions both as one
 * unit at the node's computed {top,left}, matching plain .oncotree-node. */
.oncotree-node-wrap {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  height: 28px;
  max-width: 340px;
}

.oncotree-node-wrap .oncotree-node {
  position: static;
  max-width: 260px;
}

/* Long WHO subtype names wrap onto a 2nd line instead of truncating to an
 * identical-looking prefix (2026-08-02: "instead of 300 max gets 300x2
 * max") — same column width, double the row height. align-items:
 * flex-start keeps the dot/VS button pinned to the first line (where the
 * connecting curve from the parent arrives), not re-centered in the taller
 * box, so the line still visually meets the dot. */
.oncotree-node-wrap-tall {
  align-items: flex-start;
  height: auto;
}

.oncotree-node-wrap-tall .oncotree-node {
  height: auto;
  min-height: 28px;
  align-items: flex-start;
  white-space: normal;
  overflow: visible;
  word-break: break-word;
  line-height: 1.2;
  padding-top: 0.2rem;
  padding-bottom: 0.2rem;
}

.oncotree-node-wrap-tall .oncotree-node .oncotree-dot {
  margin-top: 0.15rem;
}

.oncotree-node-wrap-tall .oncotree-vs-btn {
  margin-top: 0.2rem;
}

.oncotree-vs-btn {
  flex-shrink: 0;
  padding: 0.08rem 0.35rem;
  font-size: 0.65rem;
}

.oncotree-node:hover {
  background: rgba(0, 0, 0, 0.05);
}

.oncotree-node.oncotree-leaf {
  font-weight: 500;
}

.oncotree-node.oncotree-group .oncotree-label {
  font-style: italic;
  color: var(--muted-text, #6b7280);
}

/* A root-level disease-process bucket (Neoplastic, Infectious, ...) inserted
 * purely to cut down an unmanageable root fan-out (Peds/Neuro/Skin/Heme/
 * Forensic) — heuristic prose-matching over section headers, not WHO
 * taxonomy, so it reads visually distinct from a real subcategory. */
.oncotree-node.oncotree-supergroup .oncotree-label {
  font-weight: 700;
  color: var(--accent);
}

/* A hand-curated "trunk" (e.g. Melanocytic) grouping several genuinely
 * distinct-but-related subcategories that used to fan out as confusing
 * near-duplicate siblings (2026-08-02) — see SUBCATEGORY_TRUNK_MAP.
 * Distinct styling from a supergroup (bold, not accent-colored) since it
 * sits one level deeper and groups real subcategories, not a synthesized
 * disease-process bucket. */
.oncotree-node.oncotree-trunk .oncotree-label {
  font-weight: 700;
  font-style: italic;
}

.oncotree-node.oncotree-match {
  background: rgba(255, 214, 0, 0.28);
  font-weight: 700;
  border-radius: 4px;
}

.oncotree-node.oncotree-match:hover {
  background: rgba(255, 214, 0, 0.42);
}

.oncotree-node.oncotree-super {
  cursor: default;
  font-weight: 700;
}

.oncotree-node.oncotree-super:hover {
  background: transparent;
}

.oncotree-more {
  position: absolute;
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 0.4rem;
  font-size: 0.78rem;
  color: var(--muted-text, #6b7280);
  font-style: italic;
}

.oncotree-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid;
}

.oncotree-dot-branch {
  background: #fff !important;
}

.oncotree-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.oncotree-count {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--muted-text, #6b7280);
  background: rgba(0, 0, 0, 0.06);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
}

.oncotree-caret {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--muted-text, #6b7280);
}

.chevron-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  text-align: left;
  background: #f8f9fa;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.chevron-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.chevron-item .chevron {
  color: var(--accent);
  font-size: 1.1rem;
}

.chevron-count {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: normal;
}

.topic-prebuilt-hint {
  color: var(--accent);
  font-weight: 500;
}

.topic-page {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.topic-page-top {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 1rem;
}

.topic-page-top-facts-only {
  grid-template-columns: 1fr;
}

.topic-key-facts,
.topic-gallery,
.section-gallery {
  background: #f8f9fa;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.85rem;
}

.section-gallery {
  margin-top: 0.85rem;
}

.section-gallery-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.topic-panel-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.topic-key-facts .answer-md .answer-list {
  margin-left: 0.9rem;
}

.evidence-source-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 0.65rem 0 0.85rem;
}

.evidence-source-bar .source-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.55rem;
  border-radius: 6px;
  font-size: 0.78rem;
  border: 1px solid var(--panel-border);
  background: #f8f9fa;
  color: #3c4043;
}

.evidence-source-bar .source-chip.ok {
  border-color: #c8e6c9;
  background: #e8f5e9;
}

.evidence-source-bar .source-chip.missing {
  border-color: #ffcdd2;
  background: #ffebee;
  color: #b71c1c;
}

.evidence-source-bar .source-chip-note {
  flex: 1 1 100%;
  margin: 0.15rem 0 0;
}

.literature-strip {
  margin: 1rem 0 1.25rem;
  padding: 0.85rem 1rem;
  background: #f8f9fa;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}

.literature-list {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.literature-title {
  font-weight: 600;
  line-height: 1.35;
}

.literature-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

.literature-snip {
  font-size: 0.85rem;
  color: #3c4043;
  margin-top: 0.15rem;
  line-height: 1.4;
}

.literature-status {
  margin: 0.35rem 0 0.5rem;
}

.literature-warning {
  color: var(--warn);
}

.topic-gallery-grid {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
}

.topic-gallery-thumb {
  flex: 0 0 auto;
  width: 108px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: transparent;
}

.topic-gallery-thumb img {
  width: 100%;
  height: 72px;
  object-fit: cover;
  display: block;
}

.topic-lecture-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.65rem;
}

.topic-lecture-thumb {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.35rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.topic-lecture-thumb img {
  width: 100%;
  height: 78px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

.topic-lecture-thumb-caption {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

.topic-lecture-thumb-ts {
  font-size: 0.72rem;
  color: var(--muted);
}

.topic-section-body .answer-md ul.answer-list {
  margin: 0 0 0.65rem 1.15rem;
  padding: 0;
}

.topic-section-body .answer-md ul.answer-list ul.answer-list {
  margin: 0.15rem 0 0.35rem 1rem;
  list-style-type: circle;
}

.topic-section-body .answer-md li {
  margin-bottom: 0.3rem;
}

.topic-videos {
  background: #f8f9fa;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.85rem;
}

.topic-video-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.topic-video-item {
  font-size: 0.92rem;
  line-height: 1.35;
}

.topic-video-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.topic-video-link:hover {
  text-decoration: underline;
}

.topic-video-unavailable {
  color: var(--muted);
  font-size: 0.85rem;
}

.topic-video-ts {
  color: var(--muted);
  font-size: 0.82rem;
  margin-left: 0.35rem;
}

.topic-sections {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.topic-section {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  overflow: hidden;
}

.topic-section-header {
  background: #202124;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.5rem 0.85rem;
}

.topic-section-body {
  padding: 0.75rem 0.85rem;
}

.ddx-link-btn {
  background: transparent;
  border: none;
  border-bottom: 1px dotted var(--accent);
  color: var(--accent);
  font-weight: 700;
  padding: 0;
  cursor: pointer;
  font-size: inherit;
}

.ddx-list li {
  margin-bottom: 0.4rem;
}

.topic-who-mentions {
  margin: 0.75rem 0 1rem;
}

.who-mention-meta {
  color: var(--muted);
  font-size: 0.92em;
  font-weight: 400;
}

@media (max-width: 720px) {
  .topic-page-top {
    grid-template-columns: 1fr;
  }
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message {
  border-radius: 10px;
  padding: 0.85rem 1rem;
  max-width: 95%;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
}

.message.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border: 1px solid var(--panel-border);
}

.message .role {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.message .body {
  line-height: 1.5;
}

.message .body .answer-md {
  white-space: normal;
}

.message .body .answer-md p {
  margin: 0 0 0.65rem;
}

.message .body .answer-md ul.answer-list {
  margin: 0 0 0.75rem 1.1rem;
  padding: 0;
}

.message .body .answer-md li {
  margin-bottom: 0.35rem;
}

.message .body .answer-line {
  margin: 0 0 0.35rem;
}

.message .body .answer-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 0.85rem;
  font-size: 0.88rem;
}

.message .body .answer-table th,
.message .body .answer-table td {
  border: 1px solid var(--panel-border);
  padding: 0.4rem 0.55rem;
  text-align: left;
  vertical-align: top;
}

.message .body .answer-table th {
  background: #f1f3f4;
  color: var(--text);
}

.figures-strip {
  margin-bottom: 0.75rem;
}

.figures-strip-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.figures-grid-prominent img {
  max-width: 220px;
  max-height: 170px;
}

.figures-grid-prominent {
  margin-top: 0;
}

.message .body a {
  color: var(--link);
}

.inline-cite-link {
  border-bottom: 1px dotted var(--link);
  text-decoration: none;
}

/* Any inline citation with a rich hover card available (DOI/literature,
 * textbook page image, video timestamped frame, WHO/Pathoutlines excerpt)
 * gets a slightly heavier underline hinting that hovering shows more than
 * a bare link — see #cite-hover-card / showCiteHoverCard(). */
.inline-cite-link-hover {
  border-bottom: 1px dotted var(--accent);
  cursor: help;
}

.cite-hover-card {
  position: fixed;
  z-index: 200;
  max-width: 320px;
  background: #1a1a1d;
  color: #f1f1f3;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  padding: 0;
  overflow: hidden;
  pointer-events: none;
  font-size: 0.8rem;
  line-height: 1.35;
}

.cite-hover-card.hidden {
  display: none;
}

.cite-hover-img {
  display: block;
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  background: #0e0e10;
}

.cite-hover-body {
  padding: 0.55rem 0.7rem;
}

.cite-hover-title {
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.15rem;
}

.cite-hover-meta {
  color: #b6bcc6;
  font-size: 0.74rem;
  margin-bottom: 0.3rem;
}

.cite-hover-meta:empty,
.cite-hover-excerpt:empty {
  display: none;
}

.cite-hover-excerpt {
  color: #d7dae0;
  font-size: 0.76rem;
  font-style: italic;
}

.inline-figure-row {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.5rem 0;
  width: 100%;
}

.inline-figure-row .inline-figure-btn {
  margin: 0;
  flex: 0 0 auto;
}

/* Belt-and-suspenders: even if JS misses a coalescing pass, figure-only
   paragraphs / list items sit side-by-side instead of stacking full-width. */
.topic-section-body .answer-line:has(> .inline-figure-btn:only-child) {
  display: inline-block;
  vertical-align: top;
  width: auto;
  max-width: 260px;
  margin: 0.25rem 0.5rem 0.25rem 0;
}

.topic-section-body ul.answer-list > li:has(> .inline-figure-btn:only-child) {
  display: inline-block;
  vertical-align: top;
  list-style: none;
  margin: 0.25rem 0.5rem 0.25rem 0;
  max-width: 260px;
}

.inline-figure-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  margin: 0.35rem 0;
  padding: 0.4rem;
  background: #f8f9fa;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
  max-width: 260px;
  vertical-align: top;
}

.inline-figure-img {
  max-width: 240px;
  max-height: 170px;
  border-radius: 6px;
  display: block;
}

.inline-figure-caption {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: left;
  line-height: 1.3;
}

.message .body .answer-md ul.answer-list ul.answer-list {
  margin-top: 0.35rem;
}

.citations {
  margin-top: 0.75rem;
  border-top: 1px solid var(--panel-border);
  padding-top: 0.75rem;
}

.citations summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
}

/** Collapses literature/citations/source-summary/debug/export behind one
 * toggle at the bottom of a topic page, instead of always taking up scroll
 * space past the synthesized answer's own Key Literature section. */
.topic-more-section {
  margin: 1rem 0 0;
  border-top: 1px solid var(--panel-border);
  padding-top: 0.75rem;
}

.topic-more-section summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  list-style: none;
}

.topic-more-section[open] {
  padding-bottom: 0.5rem;
}

.citation-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.citation-item {
  font-size: 0.85rem;
  background: #f8f9fa;
  border: 1px solid var(--panel-border);
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
}

.citation-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.25rem;
}

.source-badge {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.tag-chip {
  display: inline-block;
  font-size: 0.68rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: #f1f3f4;
  color: var(--muted);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-tags-header,
.curriculum-tagline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid #c5d8f5;
  border-radius: 8px;
  background: linear-gradient(180deg, #f3f8ff 0%, #ffffff 100%);
  font-size: 0.82rem;
}

.curriculum-tag-path {
  font-size: 0.78rem;
  background: #eef3fb;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  word-break: break-all;
}

.topic-tags-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.topic-entry-tag {
  max-width: none;
  white-space: normal;
  background: #e8f0fe;
  color: #174ea6;
  font-weight: 600;
}

.tag-breadcrumb-sep {
  color: var(--muted);
  opacity: 0.7;
  padding: 0 0.05rem;
}

.provenance-badge {
  text-transform: none;
  font-weight: 600;
}

.citation-excerpt {
  margin-bottom: 0.35rem;
}

.citation-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  margin-top: 0.35rem;
}

.citation-links a {
  font-size: 0.78rem;
}

.citation-thumb-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0;
  padding: 0;
  background: transparent;
  color: var(--link);
  border: none;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
}

.citation-thumb {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
}

/* Applied by the global `error` listener in app.js when a figure/page/
   citation-thumbnail/modal image URL 404s or otherwise fails to load —
   dashed border distinguishes "known broken, showing placeholder" from a
   normal thumbnail so it never looks like an ordinary content image. */
.img-broken {
  object-fit: contain !important;
  border: 1px dashed var(--panel-border) !important;
  background: #f1f3f4;
}

/* Gallery/figure chrome hidden after client-side tiny/near-black detection
   (HTTP 200 extraction stubs that never fire img error). */
.img-defect-hidden {
  display: none !important;
}

.figure-preview-btn {
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
}

.relevance-warn {
  display: none;
}

.message .body .answer-heading {
  margin: 0.75rem 0 0.35rem;
  font-size: 1rem;
  color: var(--text);
}

.teaching-banner {
  margin-bottom: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(61, 214, 140, 0.45);
  background: rgba(61, 214, 140, 0.08);
}

.teaching-link {
  display: inline-block;
  margin-top: 0.35rem;
  color: var(--ok);
  font-weight: 600;
}

.mode-hint,
.curriculum-hint {
  margin-top: -0.35rem;
  margin-bottom: 0.75rem;
}

.curriculum-hint {
  margin-top: 0.5rem;
  margin-bottom: 0;
}

.media-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-modal.hidden {
  display: none;
}

.media-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.media-modal-panel {
  position: relative;
  z-index: 1;
  max-width: min(92vw, 960px);
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1rem;
}

.media-modal-close {
  position: absolute;
  top: 0.35rem;
  right: 0.5rem;
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

.media-modal-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-modal-nav:hover {
  background: rgba(0, 0, 0, 0.65);
}

.media-modal-nav[hidden] {
  display: none;
}

.media-modal-prev {
  left: 0.5rem;
}

.media-modal-next {
  right: 0.5rem;
}

.media-modal-img {
  display: block;
  max-width: 100%;
  max-height: 75vh;
  margin: 0 auto;
  border-radius: 8px;
}

.media-modal-caption {
  margin: 0.65rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.media-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.media-modal-action {
  display: inline-block;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  color: var(--link);
  font-size: 0.82rem;
  text-decoration: none;
}

.media-modal-action:hover {
  background: var(--accent-soft);
}

.media-modal-action[hidden] {
  display: none;
}

body.modal-open {
  overflow: hidden;
}

.citation-item .meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.figures-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.figures-grid img {
  max-width: 180px;
  max-height: 140px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
}

.debug-block {
  margin-top: 0.75rem;
  font-size: 0.75rem;
}

.debug-block pre {
  overflow: auto;
  max-height: 240px;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 0.5rem;
  border-radius: 6px;
}

.controls select:focus,
.controls input[type="number"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.bottom-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.controls,
.notes-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1rem;
}

.export-panel-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

#export-page-btn {
  width: 100%;
}

.export-btn-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.export-btn-row #export-page-btn {
  flex: 1;
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--panel-border);
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.btn-secondary:hover {
  background: var(--accent-soft);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.browse-leaf-row {
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
}

.browse-leaf-row .chevron-item {
  flex: 1;
}

.vs-btn {
  flex: 0 0 auto;
  min-width: 2.5rem;
  border: 1px solid var(--panel-border);
  background: #fff;
  color: var(--accent);
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.vs-btn:hover,
.vs-btn.in-compare {
  background: var(--accent-soft);
}

.vs-btn-inline {
  margin-left: 0.35rem;
  padding: 0.1rem 0.45rem;
  vertical-align: middle;
}

.topic-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.topic-source-summary {
  margin-top: 1.25rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--panel-border);
  margin-bottom: 0.35rem;
}

.topic-source-summary .hint {
  margin: 0.15rem 0;
}

.compare-tray {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--accent-soft);
}

.compare-tray.hidden {
  display: none;
}

.compare-tray-count {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
}

.compare-view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.compare-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.compare-column {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.65rem;
  background: #fff;
}

.compare-column-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

/* When resolvable to a leaf, the title is a <button> that opens that
 * entity's own topic page (bindCompareColumnNav) — reset button chrome and
 * make it visually obvious it's clickable. */
button.compare-column-title {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
}

button.compare-column-title:hover {
  text-decoration: underline;
}

.compare-column-title-arrow {
  font-weight: 400;
  opacity: 0.7;
}

.compare-tab-bar {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.compare-tab-btn {
  border: 1px solid var(--panel-border);
  background: #fff;
  border-radius: 6px;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
}

.compare-tab-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.compare-col-panel.hidden {
  display: none;
}

.compare-analysis {
  border-top: 1px solid var(--panel-border);
  padding-top: 0.75rem;
}

.compare-analysis h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.flag-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.flag-modal.hidden {
  display: none;
}

.flag-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.flag-modal-panel {
  position: relative;
  z-index: 1;
  width: min(92vw, 480px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 1rem;
}

.flag-modal-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.flag-modal-panel textarea {
  width: 100%;
  resize: vertical;
  margin: 0.35rem 0 0.75rem;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.6rem;
  font: inherit;
}

.flag-modal-actions {
  display: flex;
  gap: 0.5rem;
}

.flag-modal-close {
  position: absolute;
  top: 0.35rem;
  right: 0.5rem;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
}

.flag-status {
  margin-top: 0.5rem;
}

.export-status {
  margin: 0.5rem 0 0;
  min-height: 1.1rem;
}

.controls h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.controls-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  list-style: none;
}

.controls-details[open] summary {
  margin-bottom: 0.75rem;
}

.controls-summary-hint {
  display: block;
  font-weight: 400;
  color: var(--muted);
  margin-top: 0.2rem;
  text-transform: none;
  letter-spacing: normal;
}

.controls label,
.controls legend {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.controls select,
.controls input[type="number"] {
  width: 100%;
  margin-bottom: 0.75rem;
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
}

fieldset {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem 0.75rem;
  margin: 0 0 0.75rem;
}

.source-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 0.5rem;
}

.source-grid label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text);
  font-size: 0.82rem;
  margin: 0;
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.error-text {
  color: var(--error);
}

/* Live iterative-retrieval “thinking” panel (SSE progress events). */
.thinking-panel {
  border: 1px solid #c5d8f5;
  border-radius: 10px;
  background: linear-gradient(180deg, #eef4ff 0%, #f8fafc 100%);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  box-shadow: inset 0 0 0 1px rgba(26, 115, 232, 0.08);
}

.thinking-panel.thinking-live {
  position: sticky;
  top: 0;
  z-index: 8;
  box-shadow: 0 4px 16px rgba(26, 115, 232, 0.12);
}

.thinking-panel-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.55rem;
}

.thinking-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.thinking-step {
  display: grid;
  grid-template-columns: 1.1rem 1fr;
  gap: 0.45rem;
  align-items: start;
  font-size: 0.88rem;
  line-height: 1.35;
}

.thinking-step .thinking-mark {
  width: 0.7rem;
  height: 0.7rem;
  margin-top: 0.3rem;
  border-radius: 50%;
  border: 2px solid var(--panel-border);
  background: #fff;
}

.thinking-step.running .thinking-mark {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.15);
  animation: thinking-pulse 1.1s ease-in-out infinite;
}

.thinking-step.done .thinking-mark {
  border-color: var(--ok);
  background: var(--ok);
}

.thinking-step.error .thinking-mark {
  border-color: var(--error);
  background: var(--error);
}

.thinking-step .thinking-label {
  font-weight: 600;
}

.thinking-step .thinking-detail {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.1rem;
}

.thinking-step .thinking-queries {
  margin: 0.25rem 0 0;
  padding-left: 1rem;
  color: var(--muted);
  font-size: 0.78rem;
}

@keyframes thinking-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.75; }
}

.topic-export-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--panel-border);
}

.topic-export-bar .hint {
  margin: 0;
}

@media (max-width: 900px) {
  .query-overlay {
    padding: 0.5rem 0.75rem;
    flex-wrap: wrap;
  }
  .query-overlay-debug {
    order: 3;
  }
}

.tutor-citation-ref { display: inline; border: none; padding: 0 .1rem; background: none; color: var(--accent); font: inherit; cursor: pointer; vertical-align: baseline; }
.tutor-citation-ref:hover, .tutor-citation-ref:focus-visible { text-decoration: underline; }
/* Notices must not consume the tutor's usable area on short viewports. Let the
   document scroll instead of allowing its footer to cover the conversation. */
body[data-active-view="tutor"] .chat-panel { min-height: 520px; }
.tutor-toolbar, .tutor-context, .tutor-starters, .tutor-status { flex-shrink: 0; }
@media (max-width: 720px) {
  .topbar { align-items: flex-start; gap: .75rem; }
  .query-overlay { padding: .55rem .7rem; }
  .query-overlay .query-overlay-debug { order: 1; }
  body[data-active-view="tutor"] .layout { flex: 0 0 auto; }
  body[data-active-view="tutor"] .chat-panel { flex: none; min-height: 0; }
  #tutor-view { flex: none; min-height: 440px; }
  #tutor-messages { flex: 0 0 auto; min-height: 160px; max-height: 60vh; }
}

/* Daily-reference landing experience. The established Tutor IDs remain in
   place because the same RAM-only conversation and evidence renderer power it. */
body[data-active-view="tutor"] {
  background: #f3f6f8;
}

body[data-active-view="tutor"] .query-overlay {
  background: rgba(248, 251, 252, .94);
  border-bottom-color: #cfdde1;
}

body[data-active-view="tutor"] .query-highlight-overlay {
  background: #fff;
}

.view-tab-primary {
  color: #165b66;
}

.view-tab-primary.active {
  color: #0c5561;
  border-bottom-color: #138195;
}

#tutor-view {
  background: linear-gradient(180deg, #f2f8f8 0, #fff 330px);
}

.tutor-toolbar {
  align-items: flex-start;
  padding: 1.55rem 1.5rem .55rem;
}

.tutor-heading {
  max-width: 720px;
}

.tutor-eyebrow {
  display: block;
  margin-bottom: .38rem;
  color: #0b6876;
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.tutor-toolbar h2 {
  margin-bottom: .42rem;
  font-size: clamp(1.45rem, 2.6vw, 2rem);
  letter-spacing: -.025em;
  color: #173a41;
}

.tutor-toolbar p {
  max-width: 680px;
  line-height: 1.55;
  color: #48636a;
}

.tutor-controls {
  justify-content: flex-end;
  padding: .72rem;
  border: 1px solid #cadcdf;
  border-radius: 12px;
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 5px 18px rgba(29, 65, 73, .06);
}

.tutor-controls label {
  color: #48636a;
  font-weight: 650;
}

#tutor-view.has-conversation .tutor-heading {
  display: none;
}

#tutor-view.has-conversation .tutor-toolbar {
  justify-content: flex-end;
  padding: .65rem 1.25rem .2rem;
}

.tutor-controls select {
  min-width: 180px;
  border-color: #b9d0d5;
}

.tutor-context {
  margin: .25rem 1.5rem .6rem;
  color: #5a7176;
}

.tutor-starters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .8rem;
  padding: .8rem 1.5rem .95rem;
}

.tutor-starters button {
  display: flex;
  min-height: 106px;
  flex-direction: column;
  justify-content: center;
  gap: .35rem;
  padding: 1rem 1.05rem;
  border-color: #bed5d9;
  border-radius: 12px;
  background: rgba(255, 255, 255, .92);
  color: #174f59;
  box-shadow: 0 4px 14px rgba(29, 65, 73, .05);
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.tutor-starters button:hover,
.tutor-starters button:focus-visible,
.tutor-starters button.selected {
  border-color: #168094;
  box-shadow: 0 7px 20px rgba(22, 128, 148, .12);
  transform: translateY(-1px);
}

.tutor-starters button.selected {
  background: #eaf6f7;
}

.starter-title {
  font-size: 1rem;
  font-weight: 730;
}

.starter-description {
  color: #5a7176;
  font-size: .82rem;
  line-height: 1.4;
}

.learning-tools {
  margin: 0 1.5rem .95rem;
  padding: .65rem .85rem;
  border: 1px solid #dce5e7;
  border-radius: 10px;
  background: rgba(255, 255, 255, .7);
  color: #52666a;
  font-size: .82rem;
}

.learning-tools summary {
  cursor: pointer;
  color: #345c64;
  font-weight: 650;
}

.learning-tools p {
  margin: .65rem 0;
}

.learning-starters {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.learning-starters button.selected {
  border-color: #168094;
  background: #eaf6f7;
  color: #174f59;
}

#tutor-messages:not(:empty) {
  border-top: 1px solid #dce5e7;
  background: rgba(255, 255, 255, .72);
}

#tutor-messages .message.user {
  background: #e5f0f3;
}

#tutor-messages .message.assistant {
  border-color: #d6e2e4;
  box-shadow: 0 3px 12px rgba(29, 65, 73, .05);
}

.tutor-followups {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
  margin-top: 1rem;
  padding-top: .8rem;
  border-top: 1px solid #e2e8ea;
}

.tutor-evidence-status {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  margin: .65rem 0 .15rem;
  padding: .28rem .55rem;
  border: 1px solid #cbdde0;
  border-radius: 999px;
  background: #f6fafb;
  color: #536b70;
  font-size: .73rem;
  font-weight: 650;
}

.tutor-evidence-status::before {
  content: "";
  width: .42rem;
  height: .42rem;
  border-radius: 50%;
  background: #2b8291;
}

.tutor-evidence-status.reused::before {
  background: #70858a;
}

.tutor-followups-label {
  margin-right: .1rem;
  color: #60757a;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.tutor-followups button {
  padding: .4rem .65rem;
  border-color: #c7d9dc;
  border-radius: 999px;
  background: #f7fbfb;
  color: #245d67;
  font-size: .78rem;
}

@media (max-width: 900px) {
  .tutor-toolbar {
    flex-direction: column;
  }

  .tutor-controls {
    width: 100%;
    justify-content: flex-start;
  }

  .tutor-starters {
    grid-template-columns: 1fr;
  }

  .tutor-starters button {
    min-height: 0;
  }
}

@media (max-width: 720px) {
  .tutor-toolbar {
    padding: 1.1rem .9rem .45rem;
  }

  .tutor-controls select {
    min-width: 0;
    flex: 1;
  }

  .tutor-context {
    margin: .2rem .9rem .45rem;
  }

  .tutor-starters {
    padding: .65rem .9rem .8rem;
  }

  .learning-tools {
    margin: 0 .9rem .8rem;
  }

  .tutor-followups-label {
    width: 100%;
  }
}
