/* ==========================================================================
   snap-lens design tokens
   ========================================================================== */

@font-face {
  font-family: "Inter Variable";
  src:
    url("/vendor/fonts/inter-variable.woff2") format("woff2-variations"),
    url("/vendor/fonts/inter-variable.woff2") format("woff2");
  font-weight: 380 780;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/vendor/fonts/jetbrains-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/vendor/fonts/jetbrains-mono-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-sans:
    "Inter Variable", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica,
    Arial, sans-serif;
  --font-mono:
    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Surfaces */
  --bg: #ffffff;
  --bg-canvas: #fbfbfc;
  --bg-sidebar: #f7f8fa;
  --bg-elevated: #ffffff;
  --bg-muted: #f1f2f5;
  --bg-hover: #eef0f3;

  /* Borders */
  --border: #e5e7eb;
  --border-strong: #d7dae0;

  /* Text */
  --text: #15171b;
  --text-muted: #63676f;
  --text-faint: #979ba5;

  /* Accent */
  --accent: #2f6feb;
  --accent-hover: #2557bd;
  --accent-soft: #eaf1ff;
  --accent-contrast: #ffffff;

  /* Semantic */
  --danger: #c0392b;
  --danger-soft: #fdecec;
  --warn: #a6650a;
  --warn-bg: #fff7e6;
  --warn-border: #f0c36d;
  --success: #1a7a3c;
  --success-soft: #e7f8ec;

  --code-bg: #f5f6f8;

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(21, 23, 27, 0.06);
  --shadow-md: 0 8px 24px rgba(21, 23, 27, 0.1);
  --shadow-lg: 0 20px 48px rgba(21, 23, 27, 0.18);

  /* Shell metrics */
  --topbar-h: 60px;
  --sidebar-w: 268px;
  --toc-w: 232px;

  color-scheme: light;
  font-size: 15px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13;
    --bg-canvas: #0a0b0e;
    --bg-sidebar: #111318;
    --bg-elevated: #15171d;
    --bg-muted: #1c1f26;
    --bg-hover: #1f232b;

    --border: #262a33;
    --border-strong: #343a45;

    --text: #edf0f2;
    --text-muted: #9aa2ad;
    --text-faint: #676e79;

    --accent: #6ea3ff;
    --accent-hover: #8fb8ff;
    --accent-soft: #1b2b47;
    --accent-contrast: #0b1830;

    --danger: #f87171;
    --danger-soft: #3a1f1f;
    --warn: #e0b45f;
    --warn-bg: #3a2f14;
    --warn-border: #8a6a1f;
    --success: #7be09b;
    --success-soft: #163d23;

    --code-bg: #191c22;

    color-scheme: dark;
  }
}

/* Explicit toggle always wins over the OS preference, in both directions. */
:root[data-theme="dark"] {
  --bg: #0d0f13;
  --bg-canvas: #0a0b0e;
  --bg-sidebar: #111318;
  --bg-elevated: #15171d;
  --bg-muted: #1c1f26;
  --bg-hover: #1f232b;
  --border: #262a33;
  --border-strong: #343a45;
  --text: #edf0f2;
  --text-muted: #9aa2ad;
  --text-faint: #676e79;
  --accent: #6ea3ff;
  --accent-hover: #8fb8ff;
  --accent-soft: #1b2b47;
  --accent-contrast: #0b1830;
  --danger: #f87171;
  --danger-soft: #3a1f1f;
  --warn: #e0b45f;
  --warn-bg: #3a2f14;
  --warn-border: #8a6a1f;
  --success: #7be09b;
  --success-soft: #163d23;
  --code-bg: #191c22;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-canvas: #fbfbfc;
  --bg-sidebar: #f7f8fa;
  --bg-elevated: #ffffff;
  --bg-muted: #f1f2f5;
  --bg-hover: #eef0f3;
  --border: #e5e7eb;
  --border-strong: #d7dae0;
  --text: #15171b;
  --text-muted: #63676f;
  --text-faint: #979ba5;
  --accent: #2f6feb;
  --accent-hover: #2557bd;
  --accent-soft: #eaf1ff;
  --accent-contrast: #ffffff;
  --danger: #c0392b;
  --danger-soft: #fdecec;
  --warn: #a6650a;
  --warn-bg: #fff7e6;
  --warn-border: #f0c36d;
  --success: #1a7a3c;
  --success-soft: #e7f8ec;
  --code-bg: #f5f6f8;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-feature-settings: "cv11", "ss01";
  color: var(--text);
  background: var(--bg-canvas);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.25;
  color: var(--text);
  text-transform: capitalize;
}

/* Capitalizing runs on rendered text regardless of markup, so code-ish
 * heading content (paths, identifiers) would get mangled - opt back out
 * wherever a heading contains code/inline-code. */
h1 code,
h2 code,
h3 code,
h4 code,
h5 code,
h6 code {
  text-transform: none;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.loading {
  padding: 3rem;
  color: var(--text-muted);
  text-align: center;
}

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

/* ==========================================================================
   Shell: topbar + sidebar + content + table of contents
   ========================================================================== */

.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */

.topbar {
  flex: 0 0 var(--topbar-h);
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--sidebar-w);
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 30;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  text-decoration: none;
  color: var(--text);
}

.topbar-brand-mark {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: block;
  color: var(--accent);
}

.topbar-brand-word {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.topbar-search {
  position: relative;
  justify-self: center;
  width: 100%;
  max-width: 480px;
}

.topbar-search-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-muted);
  transition:
    border-color 0.12s ease-out,
    background 0.12s ease-out;
}

.topbar-search-input-wrap:focus-within {
  border-color: var(--accent);
  background: var(--bg);
}

.topbar-search-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.topbar-search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.topbar-search-input:focus {
  outline: none;
}

.topbar-search-kbd {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  background: var(--bg-elevated);
}

.topbar-search-popup {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  max-height: min(60vh, 480px);
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.4rem;
}

.topbar-search-popup[hidden] {
  display: none;
}

.topbar-search-hint,
.topbar-search-empty {
  padding: 0.9rem 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.topbar-search-results {
  list-style: none;
  margin: 0;
  padding: 0;
}

.topbar-search-results li + li {
  margin-top: 0.1rem;
}

.topbar-search-result {
  display: block;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
}

.topbar-search-result:hover,
.topbar-search-result.is-active {
  background: var(--accent-soft);
}

.topbar-search-result-title {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
}

.topbar-search-result-path {
  display: block;
  margin-top: 0.1rem;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-family: var(--font-mono);
}

.topbar-controls {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.28rem 0.6rem;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.mode-badge.mode-none {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ---------- Layout grid (sidebar / content / toc) ---------- */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

/* ---------- Sidebar ---------- */

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-sidebar);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 0.9rem 0.7rem 1.25rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  margin-bottom: 0.4rem;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: 550;
  font-size: 0.9rem;
  position: relative;
}

/* Main nav labels only - the file tree below keeps real filename casing. */
.sidebar-nav-item span {
  text-transform: capitalize;
}

.sidebar-nav-item svg {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  color: var(--text-muted);
}

.sidebar-nav-item:hover {
  background: var(--bg-hover);
}

.sidebar-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-nav-item.active svg {
  color: var(--accent);
}

.sidebar-nav-item.active::before {
  content: "";
  position: absolute;
  left: -0.7rem;
  top: 0.35rem;
  bottom: 0.35rem;
  width: 3px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

.sidebar-nav-item.nav-disabled {
  color: var(--text-faint);
  cursor: not-allowed;
  opacity: 0.65;
}

.sidebar-nav-item.nav-disabled:hover {
  background: none;
}

.sidebar-divider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.7rem 0.5rem 0.4rem;
  margin-top: 0.35rem;
  border-top: 1px solid var(--border);
}

.sidebar-divider-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.sidebar-tree-actions {
  display: flex;
  gap: 0.15rem;
}

.sidebar-tree-actions button {
  width: 1.6rem;
  height: 1.6rem;
}

.sidebar-tree-actions button svg {
  width: 14px;
  height: 14px;
}

.sidebar-filter {
  margin: 0.3rem 0.15rem 0.5rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.83rem;
}

.tree-container {
  overflow-y: auto;
  flex: 1;
  padding: 0.1rem;
}

.tree,
.tree ul {
  list-style: none;
  margin: 0;
  padding-left: 0.85rem;
}

.tree {
  padding-left: 0;
}

.tree summary {
  cursor: pointer;
  padding: 0.3rem 0.4rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--text-muted);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.tree summary::-webkit-details-marker {
  display: none;
}

.tree summary:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.tree-empty {
  color: var(--text-faint);
  font-size: 0.78rem;
  padding: 0.1rem 0.6rem;
}

.tree-file {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.32rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  word-break: break-word;
}

.tree-file:hover {
  background: var(--bg-hover);
}

.tree-file.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.tree-icon {
  opacity: 0.65;
  font-size: 0.78rem;
}

.tree-icon-folder {
  display: inline-flex;
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
}

.tree-icon-folder svg {
  width: 100%;
  height: 100%;
}

/* ---------- Content column ----------
 * .content-scroll is the *only* vertical scroll container for the main
 * pane - it holds both the doc content and the TOC rail as flex siblings,
 * so there's one scrollbar for the two of them together, flush against the
 * outer edge of the window rather than sandwiched between the columns. The
 * TOC pins itself in place via position: sticky as that shared scrollbar
 * moves. */

.content-scroll {
  min-width: 0;
  overflow-y: auto;
  background: var(--bg);
}

.content-row {
  display: flex;
  align-items: flex-start;
  min-height: 100%;
  gap: 2.5rem;
}

/* Fills whatever room content-row has left after the TOC's fixed width and
 * the row's gap - no arbitrary cap, so wide panes (a table-heavy report, the
 * dashboard, the graph) actually use the available width. Long-form prose
 * still reads at a comfortable line length via .doc-body's own max-width
 * below, independent of how wide this box gets. */
.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 2.25rem 3rem 6rem;
}

.screen h1 {
  margin-top: 0;
  font-size: 1.65rem;
}

/* ---------- Table of contents (right rail) ---------- */

.toc {
  flex: 0 0 var(--toc-w);
  position: sticky;
  top: 0;
  align-self: flex-start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
}

.toc[hidden] {
  display: none;
}

.toc-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 0.7rem;
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  border-left: 1px solid var(--border);
}

.toc-link {
  display: block;
  padding: 0.32rem 0 0.32rem 0.85rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.83rem;
  line-height: 1.35;
}

/* Clamping lives on an inner span, not .toc-link itself - clamping a padded
 * box directly leaves a sliver of the clipped line's descenders visible
 * past the padding in Chromium. */
.toc-link-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.toc-link:hover {
  color: var(--text);
}

.toc-link.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.toc-depth-3 {
  padding-left: 1.6rem;
  font-size: 0.79rem;
}

.toc-depth-4 {
  padding-left: 2.35rem;
  font-size: 0.79rem;
}

/* ==========================================================================
   Shared content components
   ========================================================================== */

.badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.badge {
  display: inline-block;
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-pill);
  background: var(--bg-muted);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  font-weight: 500;
}

.badge-mode {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
  font-weight: 600;
}

/* Frontmatter tag chips (doc view) */
.tag-chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin: 0.6rem 0 1.1rem;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.22rem 0.65rem 0.22rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tag-chip::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.doc-type-chip {
  background: var(--bg-muted);
  color: var(--text-muted);
}

.doc-type-chip::before {
  display: none;
}

.counts-row {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

.count-tile {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.3rem;
  min-width: 118px;
  box-shadow: var(--shadow-sm);
}

.count-value {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.count-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 0.1rem;
}

.freshness-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.freshness-row:last-child {
  border-bottom: none;
}

.freshness-key {
  flex: 0 0 220px;
  font-weight: 600;
  color: var(--text-muted);
}

.freshness-warn {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn-border);
  padding-left: 0.6rem;
  border-radius: 4px;
}

.problems {
  margin-top: 2rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
  border-radius: var(--radius);
}

.problems h2 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.problems ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.85rem;
}

/* ---------- How to guides (tabbed doc view) ---------- */

.guide-tabs {
  display: flex;
  gap: 0.1rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.75rem;
  scrollbar-width: thin;
}

.guide-tab {
  flex: 0 0 auto;
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 550;
  font-size: 0.88rem;
  padding: 0.7rem 0.9rem;
  white-space: nowrap;
  cursor: pointer;
}

.guide-tab:hover {
  color: var(--text);
}

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

.guide-doc .doc-header {
  padding-top: 0;
}

/* ---------- Document view ---------- */

.doc-header {
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
  padding-bottom: 0.9rem;
}

.doc-header h1 {
  margin-bottom: 0.2rem;
}

.doc-path {
  color: var(--text-faint);
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.doc-description {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 68ch;
}

.doc-body {
  max-width: 860px;
  overflow-wrap: anywhere;
}

.doc-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

.doc-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  overflow-x: auto;
}

.doc-body code {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.doc-body :not(pre) > code {
  background: var(--code-bg);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

/* A table wider than the middle pane must scroll *inside its own box*
 * rather than overflow into the TOC rail. `display: block` turns the
 * <table> itself into a scrollable box while its row/cell children keep
 * their normal table layout (the browser fixes this up with an anonymous
 * table wrapper) - the standard trick for a horizontally-scrollable table
 * with no markup changes. */
.doc-body table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.doc-body th,
.doc-body td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  text-align: left;
}

.doc-body th {
  background: var(--bg-muted);
  font-weight: 650;
}

.doc-body blockquote {
  margin: 0;
  padding-left: 1rem;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.mermaid-rendered {
  overflow-x: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.mermaid-error {
  color: var(--danger);
  background: var(--warn-bg);
}

.code-block {
  white-space: pre-wrap;
  word-break: break-word;
}

.tok-key {
  color: #8250df;
  font-weight: 600;
}

.tok-string {
  color: #116329;
}

.tok-number {
  color: #0550ae;
}

.tok-bool {
  color: #cf222e;
}

.tok-comment {
  color: var(--text-muted);
  font-style: italic;
}

.doc-provenance {
  margin-top: 2rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 0.82rem;
}

/* ---------- Search (full-page fallback, kept for deep links) ---------- */

.search-input {
  width: 100%;
  max-width: 520px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
  background: var(--bg);
  color: var(--text);
}

.search-results {
  list-style: none;
  padding: 0;
  margin: 0;
  max-width: 720px;
}

.search-results li {
  border-bottom: 1px solid var(--border);
}

.search-results a {
  display: block;
  padding: 0.6rem 0.2rem;
  text-decoration: none;
  color: var(--text);
}

.search-results a:hover {
  background: var(--accent-soft);
}

.search-path {
  display: block;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--font-mono);
}

/* ---------- Banners (shared: dashboard, graph) ---------- */

.banner {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.banner-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
}

.banner-info {
  background: var(--accent-soft);
  border: 1px solid transparent;
}

/* ---------- Delivery dashboard ---------- */

.dashboard-view section {
  margin-bottom: 2rem;
}

.dashboard-view h2 {
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
}

.rollup-cards {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.rollup-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 1.1rem;
  min-width: 110px;
  box-shadow: var(--shadow-sm);
}

.rollup-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.rollup-label {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.dashboard-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.dashboard-toolbar label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.dashboard-toolbar select {
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.epic-group {
  margin-bottom: 1.4rem;
}

.epic-group h3 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
}

.story-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 760px;
}

.story-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.2rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.story-id {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  min-width: 2.4rem;
}

.story-row a {
  flex: 1;
  color: var(--text);
  text-decoration: none;
}

.story-row a:hover {
  text-decoration: underline;
}

.status-badge {
  text-transform: capitalize;
  font-size: 0.72rem;
}

.status-badge.status-done {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}

.status-badge.status-in-progress {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.status-badge.status-review {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}

.status-badge.status-ready-for-dev {
  background: #f0e9fd;
  color: #6c3fc5;
  border-color: transparent;
}

.status-badge.status-unknown,
.status-badge.status-open {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.task-badge {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.unknown-bucket {
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
}

.action-items-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 760px;
}

.action-items-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.2rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.count-tile-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.delivery-headline {
  margin-bottom: 2rem;
}

/* ---------- Module graph ---------- */

.graph-view {
  display: flex;
  flex-direction: column;
  height: calc(100% - 1px);
  max-width: none;
}

.graph-banner {
  margin-bottom: 0.75rem;
}

.graph-banner-meta {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.graph-degraded-banner {
  margin-bottom: 0.4rem;
}

.graph-banner-coverage {
  font-size: 0.82rem;
}

.graph-toolbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.75rem;
}

.graph-toolbar input {
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 260px;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
}

.graph-breadcrumb {
  font-size: 0.88rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.graph-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.graph-breadcrumb a:hover {
  text-decoration: underline;
}

.graph-notfound-banner {
  position: relative;
  padding-right: 2.4rem;
}

.graph-notice-dismiss {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  border: none;
  background: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-muted);
}

.graph-focus-note {
  margin: -0.25rem 0 0.75rem;
}

.graph-legend {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.legend-line {
  display: inline-block;
  width: 18px;
  border-top: 2px solid var(--accent);
}

.legend-line-solid {
  border-top-style: solid;
}

.legend-line-dashed {
  border-top-style: dashed;
}

.legend-line-dotted {
  border-top-style: dotted;
}

.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.legend-dot-unmapped {
  background: #9aa2ad;
}

.graph-container {
  position: relative;
  flex: 1;
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.graph-zoom-controls {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  display: flex;
  gap: 0.3rem;
}

.graph-zoom-btn {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

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

.cy-canvas {
  width: 100%;
  height: 100%;
  min-height: 480px;
  background: var(--bg);
}

.graph-side-panel {
  position: absolute;
  top: 3.25rem;
  right: 0.75rem;
  bottom: 0.75rem;
  width: 300px;
  max-width: calc(100% - 1.5rem);
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-md);
}

.graph-side-panel h3 {
  margin: 0 0 0.3rem;
}

.graph-panel-doc-link {
  display: block;
  margin-bottom: 0.6rem;
  padding: 0.4rem 0.7rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.graph-panel-doc-link:hover {
  background: var(--accent-hover);
}

.graph-panel-focus-btn {
  display: block;
  margin-bottom: 0.6rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.graph-panel-focus-btn:hover {
  background: var(--accent-soft);
}

.graph-side-panel h4 {
  margin: 1rem 0 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.graph-side-panel ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
}

.graph-panel-glob {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.graph-panel-close {
  position: absolute;
  top: 0.5rem;
  right: 0.6rem;
  border: none;
  background: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* ---------- Annotations ---------- */

.status-chip {
  text-transform: none;
}

.status-chip-open {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}

.status-chip-resolved {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}

.status-chip-orphaned {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.annotation-badge {
  text-decoration: none;
  color: var(--warn);
  background: var(--warn-bg);
  border-color: transparent;
}

.annotate-doc-btn {
  margin-top: 0.7rem;
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text);
  cursor: pointer;
}

.annotate-doc-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.doc-annotations-wholefile:empty {
  display: none;
}

.annotations-block {
  margin: 0.4rem 0 1.2rem;
}

.annotations-cards {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
}

.annotation-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn-border);
  background: var(--bg-muted);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  max-width: 720px;
  font-size: 0.88rem;
}

.annotation-card.annotation-resolved {
  border-left-color: var(--success);
}

.annotation-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
}

.annotation-author {
  font-weight: 600;
}

.annotation-date {
  color: var(--text-muted);
}

.annotation-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.annotation-resolved-note,
.annotation-resolved-by {
  margin-top: 0.4rem;
  font-size: 0.82rem;
}

.annotation-resolved-note {
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border);
}

.annotation-add-btn {
  opacity: 0.35;
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: opacity 0.12s ease-out;
}

.doc-body
  :is(h1, h2, h3, h4, h5, h6):hover
  + .annotations-block
  .annotation-add-btn,
.annotations-block:hover .annotation-add-btn,
.annotation-add-btn:focus {
  opacity: 1;
}

.annotation-form {
  margin-top: 0.5rem;
  max-width: 720px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem;
  background: var(--bg);
}

.annotation-form textarea {
  width: 100%;
  font: inherit;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

.annotation-form-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.annotation-form-author {
  flex: 1;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.annotation-form-submit,
.annotation-form-cancel {
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 550;
}

.annotation-form-submit {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
}

.annotation-form-submit:hover {
  background: var(--accent-hover);
}

.annotation-form-cancel {
  background: transparent;
  color: var(--text);
}

.annotation-form-error {
  margin-top: 0.4rem;
  color: var(--danger);
  font-size: 0.82rem;
}

/* ---------- Annotations index page ---------- */

.annotations-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.annotations-toolbar label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.annotations-toolbar select {
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.annotation-file-group {
  margin-bottom: 1.6rem;
}

.annotation-file-group h3 {
  font-size: 0.9rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.annotation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: 780px;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.annotation-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  font-size: 0.88rem;
}

.annotation-row-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}

.annotation-row-header a {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.annotation-row-header a:hover {
  text-decoration: underline;
}

.annotations-tray {
  border: 1px solid var(--warn-border);
  background: var(--warn-bg);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin-top: 2rem;
}

.annotations-tray .annotation-row {
  background: var(--bg);
}

.annotations-headline {
  margin-bottom: 2rem;
}

/* ==========================================================================
   Chat: floating action button + popover panel
   ========================================================================== */

.chat-fab {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 40;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.12s ease-out,
    background 0.12s ease-out;
}

.chat-fab:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.chat-fab svg {
  width: 24px;
  height: 24px;
}

.chat-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--bg);
}

.chat-panel {
  position: fixed;
  right: 1.5rem;
  bottom: 5.25rem;
  z-index: 40;
  width: 400px;
  max-width: calc(100vw - 2rem);
  height: 600px;
  max-height: calc(100vh - 7.5rem);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel[hidden] {
  display: none;
}

.chat-panel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.chat-panel-title {
  font-weight: 650;
  font-size: 0.95rem;
}

.chat-panel-header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.chat-usage-chip {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.chat-usage-chip[hidden] {
  display: none;
}

.chat-usage-chip-limit {
  color: var(--danger);
  font-weight: 600;
}

.chat-panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-width: none;
  height: auto;
  padding: 0 1rem 1rem;
}

.chat-notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  margin: 0.75rem 0;
}

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

.chat-message {
  display: flex;
}

.chat-message-user {
  justify-content: flex-end;
}

.chat-message-assistant {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 0.88rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.chat-message-user .chat-bubble {
  background: var(--accent-soft);
  border-color: transparent;
  white-space: pre-wrap;
}

.chat-message-assistant .chat-bubble {
  background: var(--bg-muted);
}

.chat-message-assistant .chat-bubble :is(p, ul, ol) {
  margin: 0 0 0.6rem;
}

.chat-message-assistant .chat-bubble :last-child {
  margin-bottom: 0;
}

/* Document references inside a chat reply route back into the app the same
 * way sidebar/tree links do - style them so they read as navigable, not as
 * plain body text. */
.chat-bubble a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.chat-bubble a:hover {
  text-decoration: underline;
}

.chat-activity {
  padding: 0.3rem 0;
  font-size: 0.85rem;
}

.chat-error {
  color: var(--danger);
  font-size: 0.85rem;
  padding: 0.3rem 0;
}

.chat-input-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  flex: 0 0 auto;
}

.chat-input-row textarea {
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  font-size: 0.88rem;
}

.chat-input-row textarea:disabled {
  opacity: 0.6;
}

.chat-input-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.chat-input-actions button {
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.83rem;
  background: transparent;
  color: var(--text);
}

.chat-input-actions button:disabled {
  cursor: default;
  opacity: 0.5;
}

.chat-input-actions #chat-send {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
  font-weight: 600;
}

.chat-input-actions #chat-send:hover:not(:disabled) {
  background: var(--accent-hover);
}

.chat-disabled code {
  background: var(--code-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

/* ---------- Not-a-workspace / landing screen ---------- */

.none-mode code {
  background: var(--code-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.landing-screen {
  max-width: 640px;
  padding-top: 2rem;
}

.landing-mark {
  /* `.landing-mark` is a plain <span> - width/height are no-ops on an
   * inline non-replaced box, so without this the bare inline <svg> inside
   * (no width/height of its own) auto-sizes to fill the available space
   * instead of respecting the 52px meant here. */
  display: inline-block;
  width: 52px;
  height: 52px;
  color: var(--accent);
  margin-bottom: 1.25rem;
}

.landing-mark svg {
  display: block;
  width: 100%;
  height: 100%;
}

.landing-screen h1 {
  font-size: 1.9rem;
  margin-bottom: 0.5rem;
}

.landing-screen pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  overflow-x: auto;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

.sidebar-toggle {
  display: none;
}

@media (max-width: 1180px) {
  .toc {
    display: none;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }
}

@media (max-width: 860px) {
  .sidebar-toggle {
    display: inline-flex;
  }

  .layout {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: var(--topbar-h) auto 0 0;
    z-index: 25;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.15s ease-out;
    box-shadow: var(--shadow-lg);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 0 0.75rem;
    gap: 0.6rem;
  }

  .topbar-brand-word {
    display: none;
  }

  .content {
    padding: 1.5rem 1.25rem 5rem;
  }

  .chat-panel {
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    bottom: 5rem;
  }

  .chat-fab {
    right: 1rem;
    bottom: 1rem;
  }

  .freshness-row {
    flex-direction: column;
    gap: 0.15rem;
  }

  .freshness-key {
    flex: none;
  }
}
