: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;
}

* { box-sizing: border-box; }

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;
  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-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;
}

.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;
  }
}
