/* ================================================================
   Hermes Atlas — Unified Style System
   ----------------------------------------------------------------
   Shared by: index.html, diataxis.html, sequence-diagrams.html,
              data-model.html

   Theme: Blueprint aesthetic (cool blue, DM Sans + Fira Code) with
   Diátaxis-quadrant extensions and data-model schema components.
   ================================================================ */

/* ============ THEME — Blueprint aesthetic ============ */
:root {
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'Fira Code', 'SF Mono', Consolas, monospace;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --surface-elevated: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --border-bright: rgba(15, 23, 42, 0.16);
  --text: #0f172a;
  --text-dim: #64748b;
  --text-bright: #0f172a;

  --accent: #0284c7;
  --accent-dim: rgba(2, 132, 199, 0.08);
  --teal: #0d9488;
  --teal-dim: rgba(13, 148, 136, 0.08);
  --sky: #0284c7;
  --sky-dim: rgba(2, 132, 199, 0.08);
  --amber: #d97706;
  --amber-dim: rgba(217, 119, 6, 0.08);
  --rose: #e11d48;
  --rose-dim: rgba(225, 29, 72, 0.06);
  --emerald: #059669;
  --emerald-dim: rgba(5, 150, 105, 0.08);
  --indigo: #4f46e5;
  --indigo-dim: rgba(79, 70, 229, 0.08);
  --slate: #475569;
  --slate-dim: rgba(71, 85, 105, 0.08);

  --green: #059669;
  --green-dim: rgba(5, 150, 105, 0.1);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.1);
  --orange: #d97706;
  --orange-dim: rgba(217, 119, 6, 0.1);

  /* Diátaxis quadrant colors (used by diataxis.html) */
  --tutorial: #0d9488;
  --tutorial-dim: rgba(13, 148, 136, 0.08);
  --howto: #0284c7;
  --howto-dim: rgba(2, 132, 199, 0.08);
  --reference: #b45309;
  --reference-dim: rgba(180, 83, 9, 0.08);
  --explanation: #4f46e5;
  --explanation-dim: rgba(79, 70, 229, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1222;
    --surface: #151d2e;
    --surface2: #1a2538;
    --surface-elevated: #1e2a40;
    --border: rgba(148, 163, 184, 0.08);
    --border-bright: rgba(148, 163, 184, 0.16);
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-bright: #f1f5f9;

    --accent: #38bdf8;
    --accent-dim: rgba(56, 189, 248, 0.12);
    --teal: #2dd4bf;
    --teal-dim: rgba(45, 212, 191, 0.12);
    --sky: #38bdf8;
    --sky-dim: rgba(56, 189, 248, 0.12);
    --amber: #fbbf24;
    --amber-dim: rgba(251, 191, 36, 0.1);
    --rose: #fb7185;
    --rose-dim: rgba(251, 113, 133, 0.1);
    --emerald: #34d399;
    --emerald-dim: rgba(52, 211, 153, 0.1);
    --indigo: #818cf8;
    --indigo-dim: rgba(129, 140, 248, 0.1);
    --slate: #94a3b8;
    --slate-dim: rgba(148, 163, 184, 0.1);

    --green: #34d399;
    --green-dim: rgba(52, 211, 153, 0.12);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.12);
    --orange: #fbbf24;
    --orange-dim: rgba(251, 191, 36, 0.12);

    --tutorial: #2dd4bf;
    --tutorial-dim: rgba(45, 212, 191, 0.12);
    --howto: #38bdf8;
    --howto-dim: rgba(56, 189, 248, 0.12);
    --reference: #fbbf24;
    --reference-dim: rgba(251, 191, 36, 0.1);
    --explanation: #818cf8;
    --explanation-dim: rgba(129, 140, 248, 0.1);
  }
}

/* Manual dark override */
:root[data-theme="dark"] {
    --bg: #0c1222;
    --surface: #151d2e;
    --surface2: #1a2538;
    --surface-elevated: #1e2a40;
    --border: rgba(148, 163, 184, 0.08);
    --border-bright: rgba(148, 163, 184, 0.16);
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-bright: #f1f5f9;
    --accent: #38bdf8;
    --accent-dim: rgba(56, 189, 248, 0.12);
    --teal: #2dd4bf; --teal-dim: rgba(45, 212, 191, 0.12);
    --sky: #38bdf8; --sky-dim: rgba(56, 189, 248, 0.12);
    --amber: #fbbf24; --amber-dim: rgba(251, 191, 36, 0.1);
    --rose: #fb7185; --rose-dim: rgba(251, 113, 133, 0.1);
    --emerald: #34d399; --emerald-dim: rgba(52, 211, 153, 0.1);
    --indigo: #818cf8; --indigo-dim: rgba(129, 140, 248, 0.1);
    --slate: #94a3b8; --slate-dim: rgba(148, 163, 184, 0.1);
    --green: #34d399; --green-dim: rgba(52, 211, 153, 0.12);
    --red: #f87171; --red-dim: rgba(248, 113, 113, 0.12);
    --orange: #fbbf24; --orange-dim: rgba(251, 191, 36, 0.12);
    --tutorial: #2dd4bf; --tutorial-dim: rgba(45, 212, 191, 0.12);
    --howto: #38bdf8; --howto-dim: rgba(56, 189, 248, 0.12);
    --reference: #fbbf24; --reference-dim: rgba(251, 191, 36, 0.1);
    --explanation: #818cf8; --explanation-dim: rgba(129, 140, 248, 0.1);
}

/* ============ RESET + BASE ============ */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 999;
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: 8px;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s;
}
.theme-toggle:hover { opacity: 1; }

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  background-image:
    repeating-linear-gradient(
      0deg, transparent, transparent 23px,
      var(--border) 23px, var(--border) 24px
    ),
    repeating-linear-gradient(
      90deg, transparent, transparent 23px,
      var(--border) 23px, var(--border) 24px
    );
  background-size: 24px 24px;
  color: var(--text);
  font-family: var(--font-body);
  padding: 40px;
  min-height: 100vh;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}

/* ============ ANIMATION ============ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.anim {
  animation: fadeUp 0.4s ease-out both;
  animation-delay: calc(var(--i, 0) * 0.05s);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ LAYOUT ============ */
.wrap {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 0 40px;
}
.main { min-width: 0; grid-column: 2; padding-bottom: 40px; }
.main p + p, .main p + ul, .main ul + p,
.main p + .diagram-shell, .main .diagram-shell + p { margin-top: 16px; }

/* ============ TOC ============ */
.toc {
  position: sticky;
  top: 24px;
  align-self: start;
  padding: 14px 0;
  grid-row: 1 / -1;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}
.toc::-webkit-scrollbar { width: 3px; }
.toc::-webkit-scrollbar-thumb { background: var(--surface-elevated); border-radius: 2px; }
.toc-title {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  padding: 0 0 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.toc a {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 5px;
  border-left: 2px solid transparent;
  transition: all 0.15s;
  line-height: 1.4;
  margin-bottom: 1px;
}
.toc a:hover { color: var(--text); background: var(--surface2); }
.toc a.active { color: var(--text); border-left-color: var(--accent); }

/* ============ MULTI-PAGE TOC (page-nav.js) ============ */
.toc-page { margin-bottom: 4px; }
.toc-page__title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 6px;
  border-left: 2px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
}
.toc-page__title::before {
  content: '\25B8';
  font-size: 9px;
  color: var(--text-dim);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.toc-page__title:hover { background: var(--surface2); }
.toc-page.is-active .toc-page__title {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-dim);
}
.toc-page.is-active .toc-page__title::before {
  transform: rotate(90deg);
}
.toc-page__sections {
  overflow: hidden;
  max-height: 1000px;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  opacity: 1;
  padding-left: 4px;
}
.toc-page.is-collapsed .toc-page__sections {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}
.toc-page.is-collapsed .toc-page__title::before {
  transform: rotate(0deg);
}

/* ============ TYPOGRAPHY ============ */
h1 {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1.1;
  margin-bottom: 8px;
  text-wrap: balance;
}
h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.5px;
  margin: 8px 0 16px;
}
h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 20px 0 8px;
  letter-spacing: -0.2px;
  color: var(--text-bright);
}
.subtitle {
  color: var(--text-dim);
  font-size: 14px;
  font-family: var(--font-mono);
  margin-bottom: 12px;
}
.lead {
  font-size: 17px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 40px;
  max-width: 72ch;
}
.sec-head {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 20px 0 16px;
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  scroll-margin-top: 24px;
}
.sec-head .dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.section-desc {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 20px;
  max-width: 72ch;
}

/* ============ PROSE BLOCK (diataxis) ============ */
.prose {
  font-size: 14px;
  line-height: 1.7;
  max-width: 65ch;
  color: var(--text);
}
.prose p { margin-bottom: 14px; }
.prose strong { color: var(--text-bright); font-weight: 600; }
.prose code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ============ KPI ROW ============ */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}
.kpi-card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.kpi-card__value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-card__label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* ============ SECTION CARD ============ */
.ve-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.ve-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.ve-card--hero {
  background: color-mix(in srgb, var(--surface) 92%, var(--accent) 8%);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  border-color: color-mix(in srgb, var(--border) 50%, var(--accent) 50%);
  margin-bottom: 20px;
}
.ve-card--recessed {
  background: var(--surface2);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.04);
}
.ve-card__label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ve-card__label::before {
  content: '';
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
}

/* Color accents */
.c-accent { border-left: 3px solid var(--accent); }
.c-accent .ve-card__label { color: var(--accent); }
.c-teal { border-left: 3px solid var(--teal); }
.c-teal .ve-card__label { color: var(--teal); }
.c-sky { border-left: 3px solid var(--sky); }
.c-sky .ve-card__label { color: var(--sky); }
.c-amber { border-left: 3px solid var(--amber); }
.c-amber .ve-card__label { color: var(--amber); }
.c-rose { border-left: 3px solid var(--rose); }
.c-rose .ve-card__label { color: var(--rose); }
.c-emerald { border-left: 3px solid var(--emerald); }
.c-emerald .ve-card__label { color: var(--emerald); }
.c-indigo { border-left: 3px solid var(--indigo); }
.c-indigo .ve-card__label { color: var(--indigo); }
.c-slate { border-left: 3px solid var(--slate); }
.c-slate .ve-card__label { color: var(--slate); }
/* Diátaxis quadrant variants */
.c-tutorial { border-left: 3px solid var(--tutorial); }
.c-tutorial .ve-card__label { color: var(--tutorial); }
.c-howto { border-left: 3px solid var(--howto); }
.c-howto .ve-card__label { color: var(--howto); }
.c-reference { border-left: 3px solid var(--reference); }
.c-reference .ve-card__label { color: var(--reference); }
.c-explanation { border-left: 3px solid var(--explanation); }
.c-explanation .ve-card__label { color: var(--explanation); }

/* ============ GRIDS ============ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.gap-24 { gap: 24px; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.card-grid .ve-card { margin-bottom: 0; }

/* ============ QUADRANT GRID (diataxis) ============ */
.quadrant-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 2px;
  margin-bottom: 28px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.quadrant {
  padding: 28px 24px;
  position: relative;
}
.quadrant__corner {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 6px;
  opacity: 0.6;
}
.quadrant__title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
  margin-bottom: 8px;
}
.quadrant__desc {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.quadrant__question {
  font-size: 14px;
  font-style: italic;
  color: var(--text);
  opacity: 0.8;
}
.q-tutorial { background: var(--tutorial-dim); }
.q-tutorial .quadrant__title { color: var(--tutorial); }
.q-howto { background: var(--howto-dim); }
.q-howto .quadrant__title { color: var(--howto); }
.q-reference { background: var(--reference-dim); }
.q-reference .quadrant__title { color: var(--reference); }
.q-explanation { background: var(--explanation-dim); }
.q-explanation .quadrant__title { color: var(--explanation); }
.axis-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  text-align: center;
  padding: 10px;
}

/* ============ NODE / STEP LIST ============ */
.node-list, .step-list {
  list-style: none;
  font-size: 12px;
  line-height: 1.8;
}
.node-list li, .step-list li {
  padding-left: 14px;
  position: relative;
}
.node-list li::before, .step-list li::before {
  content: '\203A';
  color: var(--text-dim);
  font-weight: 600;
  position: absolute;
  left: 0;
}
.node-list code, .step-list code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ============ FLOW ARROW ============ */
.flow-arrow {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 0;
}
.flow-arrow svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: var(--border-bright);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ============ TAG ============ */
.tag {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  display: inline-block;
  margin: 1px 2px;
}
.tag--accent { background: var(--accent-dim); color: var(--accent); }
.tag--teal { background: var(--teal-dim); color: var(--teal); }
.tag--sky { background: var(--sky-dim); color: var(--sky); }
.tag--amber { background: var(--amber-dim); color: var(--amber); }
.tag--rose { background: var(--rose-dim); color: var(--rose); }
.tag--emerald { background: var(--emerald-dim); color: var(--emerald); }
.tag--indigo { background: var(--indigo-dim); color: var(--indigo); }
.tag--slate { background: var(--slate-dim); color: var(--slate); }
.tag--tutorial { background: var(--tutorial-dim); color: var(--tutorial); }
.tag--howto { background: var(--howto-dim); color: var(--howto); }
.tag--reference { background: var(--reference-dim); color: var(--reference); }
.tag--explanation { background: var(--explanation-dim); color: var(--explanation); }

/* ============ CALLOUT ============ */
.callout {
  padding: 16px 20px;
  border-radius: 8px;
  border-left: 4px solid var(--accent);
  background: var(--accent-dim);
  margin: 20px 0;
  font-size: 13px;
  line-height: 1.6;
}
.callout strong { color: var(--text-bright); }
.callout code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface);
  padding: 1px 5px;
  border-radius: 3px;
}
.callout--tutorial { border-color: var(--tutorial); background: var(--tutorial-dim); }
.callout--howto { border-color: var(--howto); background: var(--howto-dim); }
.callout--reference { border-color: var(--reference); background: var(--reference-dim); }
.callout--explanation { border-color: var(--explanation); background: var(--explanation-dim); }

/* ============ PRINCIPLE CARD (diataxis) ============ */
.principle {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.principle__num {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -1px;
  opacity: 0.4;
  flex-shrink: 0;
  line-height: 1;
  padding-top: 4px;
  min-width: 28px;
}
.principle__body { flex: 1; min-width: 0; }
.principle__title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.principle__desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
}
.principle__desc code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ============ PULLQUOTE (diataxis) ============ */
.pullquote {
  margin: 32px 0;
  padding-left: 24px;
  border-left: 3px solid var(--explanation);
}
.pullquote p {
  font-size: 19px;
  font-style: italic;
  line-height: 1.45;
  color: var(--text-bright);
  margin: 0;
}
.pullquote cite {
  display: block;
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 8px;
}

/* ============ PIPELINE ============ */
.pipeline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: stretch;
  padding-bottom: 4px;
  margin-bottom: 20px;
}
.pipeline-step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-dim);
  border-radius: 8px;
  padding: 14px 18px;
  min-width: 160px;
  flex: 1 1 180px;
  text-align: center;
}
/* Gradient progression: step 1 quietest → step 4 most emphatic.
   Uses color-mix to interpolate between --accent-dim and --accent. */
.pipeline--gradient .pipeline-step:nth-child(1) {
  border-left-color: color-mix(in srgb, var(--accent) 25%, var(--border-bright));
}
.pipeline--gradient .pipeline-step:nth-child(3) {
  border-left-color: color-mix(in srgb, var(--accent) 55%, var(--border-bright));
}
.pipeline--gradient .pipeline-step:nth-child(5) {
  border-left-color: color-mix(in srgb, var(--accent) 80%, var(--border-bright));
  background: color-mix(in srgb, var(--accent) 4%, var(--surface));
}
.pipeline--gradient .pipeline-step:nth-child(7) {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
}
.pipeline-step .step-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}
.pipeline-step .step-detail {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
}
.pipeline-arrow {
  display: flex;
  align-items: center;
  padding: 0 3px;
  color: var(--border-bright);
  font-size: 16px;
  flex-shrink: 0;
}
/* Hide arrows once the pipeline wraps onto multiple rows — simplest heuristic:
   hide whenever the container isn't wide enough to keep all 4 steps in one row.
   Combined min-width × 4 + arrows ≈ 760px; hide below that. */
@media (max-width: 820px) {
  .pipeline-arrow { display: none; }
}

/* ============ INNER GRID (nested cards) ============ */
.inner-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inner-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.inner-card .title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.inner-card .desc { color: var(--text-dim); font-size: 12px; line-height: 1.5; }
.inner-card code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ============ LEGEND ============ */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.legend-swatch {
  width: 12px; height: 12px; border-radius: 3px;
}

/* ============ SCHEMA TABLE (data-model) ============ */
.schema-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 12px;
}
.schema-table th {
  text-align: left;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  border-bottom: 2px solid var(--border-bright);
}
.schema-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.schema-table tr:last-child td { border-bottom: none; }
.col-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
}
.col-type {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}
.col-pk, .col-fk, .col-idx, .col-version {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 3px;
  display: inline-block;
}
.col-pk { background: var(--amber-dim); color: var(--amber); }
.col-fk { background: var(--sky-dim); color: var(--sky); }
.col-idx { background: var(--teal-dim); color: var(--teal); }
.col-version { background: var(--slate-dim); color: var(--slate); }

/* ============ TREE DIAGRAM (data-model) ============ */
.tree { margin: 12px 0; }
.tree ul {
  list-style: none;
  padding-left: 1.5rem;
  position: relative;
}
.tree > ul { padding-left: 0; }
.tree li {
  position: relative;
  padding: 3px 0 3px 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
}
.tree li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--border-bright);
}
.tree li::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0.85em;
  width: 14px;
  height: 1px;
  background: var(--border-bright);
}
.tree li:last-child::before { height: 0.85em; }
.tree .dir { color: var(--accent); font-weight: 600; }
.tree .file { color: var(--text-dim); }
.tree .required { color: var(--emerald); font-weight: 600; }
.tree .optional { color: var(--slate); }

/* ============ CONFIG LAYER DIAGRAM (data-model) ============ */
.config-layers {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 16px 0;
}
.config-layer {
  padding: 14px 18px;
  border: 1px solid var(--border);
  font-size: 13px;
  position: relative;
}
.config-layer:first-child { border-radius: 10px 10px 0 0; }
.config-layer:last-child { border-radius: 0 0 10px 10px; }
.config-layer + .config-layer { border-top: none; }
.config-layer .layer-label {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 4px;
}
.config-layer .layer-desc {
  font-size: 12px;
  color: var(--text-dim);
}
.layer-runtime { background: var(--amber-dim); }
.layer-runtime .layer-label { color: var(--amber); }
.layer-env { background: var(--teal-dim); }
.layer-env .layer-label { color: var(--teal); }
.layer-user { background: var(--sky-dim); }
.layer-user .layer-label { color: var(--sky); }
.layer-default { background: var(--slate-dim); }
.layer-default .layer-label { color: var(--slate); }
.layer-arrow {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 0;
  font-family: var(--font-mono);
}

/* ============ CODE BLOCKS (data-model) ============ */
pre {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.55;
}
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
}
pre code { background: none; padding: 0; font-size: inherit; }

/* ============ FLEX UTILITY ============ */
.flex-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ============ MERMAID ============ */
.mermaid-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: grab;
}
.mermaid-wrap.is-panning { cursor: grabbing; user-select: none; }
.mermaid .nodeLabel { color: var(--text) !important; }
.mermaid .edgeLabel { color: var(--text-dim) !important; background-color: var(--bg) !important; }
.mermaid .edgeLabel rect { fill: var(--bg) !important; }
.mermaid .node rect, .mermaid .node circle, .mermaid .node polygon { stroke-width: 1.5px; }
.mermaid .edge-pattern-solid { stroke-width: 1.5px; }
.mermaid .edgeLabel { font-family: var(--font-mono) !important; font-size: 12px !important; }
.mermaid .nodeLabel { font-family: var(--font-body) !important; font-size: 15px !important; }
/* Sequence-diagram specific Mermaid overrides (harmless on other diagram types) */
.mermaid .messageText { font-family: var(--font-mono) !important; font-size: 12px !important; }
.mermaid .labelText { font-family: var(--font-mono) !important; }
.mermaid .loopText { font-family: var(--font-mono) !important; font-size: 11px !important; }
.mermaid .actor { stroke-width: 1.5px; }
.mermaid text.actor { font-family: var(--font-body) !important; }
.mermaid .activation0,
.mermaid .activation1,
.mermaid .activation2 { stroke-width: 1px; }

.zoom-controls {
  position: absolute;
  top: 8px; right: 8px;
  display: flex; gap: 2px;
  z-index: 10;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}
.zoom-controls button,
.zoom-controls .zoom-btn {
  width: 28px; height: 28px;
  border: none; background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 14px; cursor: pointer;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.zoom-controls button:hover,
.zoom-controls .zoom-btn:hover { background: var(--border); color: var(--text); }
.zoom-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  padding: 0 6px;
  white-space: nowrap;
  display: flex; align-items: center;
}
.mermaid-viewport {
  position: relative;
  overflow: hidden;
  width: 100%; height: 100%;
}
.mermaid-canvas {
  position: absolute;
  top: 0; left: 0;
}
.diagram-shell { margin-bottom: 24px; }
.diagram-shell__hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 8px;
  opacity: 0.7;
}
.diagram-source { display: none; }

/* ============ COLLAPSIBLE ============ */
details.collapsible {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 16px;
}
details.collapsible summary {
  padding: 14px 20px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  transition: background 0.15s ease;
}
details.collapsible summary:hover { background: var(--surface-elevated); }
details.collapsible summary::-webkit-details-marker { display: none; }
details.collapsible summary::before {
  content: '\25B8';
  font-size: 11px;
  color: var(--text-dim);
  transition: transform 0.15s ease;
}
details.collapsible[open] summary::before { transform: rotate(90deg); }
details.collapsible .collapsible__body {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.6;
}

/* ============ COMPANION FOOTER LINKS ============ */
.companion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.companion-link {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.companion-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: var(--accent);
}
.companion-link__title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.companion-link__desc {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* ============ DIVIDER ============ */
hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 40px 0;
}

/* ============ RESPONSIVE ============ */
/* ============ MOBILE NAV TOGGLE ============ */
.nav-toggle {
  display: none; /* hidden on desktop */
}

@media (max-width: 1000px) {
  .wrap { grid-template-columns: 1fr; padding-top: 0; }
  body { padding-top: 0; padding: 20px; }
  h1 { font-size: 32px; }

  /* Hamburger button */
  .nav-toggle {
    display: flex; align-items: center; justify-content: center;
    position: fixed; top: 12px; left: 12px; z-index: 301;
    width: 36px; height: 36px;
    background: var(--surface); border: 1px solid var(--border-bright);
    border-radius: 8px; cursor: pointer;
    font-size: 18px; opacity: 0.7; transition: opacity 0.2s;
  }
  .nav-toggle:hover { opacity: 1; }
  .nav-toggle .bar {
    display: block; width: 16px; height: 2px;
    background: var(--text); border-radius: 1px;
    position: relative; transition: transform 0.2s, opacity 0.2s;
  }
  .nav-toggle .bar::before,
  .nav-toggle .bar::after {
    content: ''; display: block; width: 16px; height: 2px;
    background: var(--text); border-radius: 1px;
    position: absolute; left: 0;
    transition: transform 0.2s, opacity 0.2s;
  }
  .nav-toggle .bar::before { top: -5px; }
  .nav-toggle .bar::after { top: 5px; }

  /* Animate to X when open */
  .nav-toggle.open .bar { background: transparent; }
  .nav-toggle.open .bar::before { top: 0; transform: rotate(45deg); }
  .nav-toggle.open .bar::after { top: 0; transform: rotate(-45deg); }

  /* TOC as a slide-down overlay */
  .toc {
    position: fixed; top: 0; left: 0; right: 0; z-index: 300;
    max-height: 0; overflow: hidden;
    display: flex; flex-direction: column; gap: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    transition: max-height 0.3s ease, padding 0.3s ease;
    grid-row: auto;
  }
  .toc.open {
    max-height: 100dvh; overflow-y: auto;
    padding: 56px 20px 20px;
  }
  .toc::-webkit-scrollbar { display: none; }
  .toc-title { display: none; }
  .toc ul {
    display: flex; flex-direction: column; gap: 2px;
    list-style: none; padding: 0; margin: 0;
  }
  .toc a {
    display: block;
    white-space: nowrap;
    border-left: 2px solid transparent; border-bottom: none;
    border-radius: 0;
    padding: 10px 12px; font-size: 14px;
  }
  .toc a.active { border-left-color: var(--accent); border-bottom: none; background: var(--surface); }
  .toc .toc-home {
    margin-top: 8px; padding-top: 12px;
    border-top: 1px solid var(--border);
  }

  /* Multi-page TOC mobile */
  .toc-page__title {
    padding: 10px 12px;
    font-size: 14px;
  }
  .toc-page.is-active .toc-page__title {
    border-left-width: 2px;
  }

  /* Backdrop overlay */
  .nav-backdrop {
    display: none; position: fixed; inset: 0; z-index: 299;
    background: rgba(0,0,0,0.4);
    -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  }
  .nav-backdrop.open { display: block; }

  /* Push theme toggle away from hamburger */
  .theme-toggle { top: 12px; right: 12px; }

  .main { padding-top: 20px; padding-bottom: 20px; grid-column: 1; }
  .sec-head { scroll-margin-top: 16px; }
  section[id] { scroll-margin-top: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .quadrant-grid { grid-template-columns: 1fr; }
  .inner-grid { grid-template-columns: 1fr; }
}

/* ============ REPO REFERENCE LINKS (enhancer.js) ============ */

/* ============ DIAGRAM FULLSCREEN OVERLAY ============ */
.diagram-overlay {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  padding: 20px;
}
.diagram-overlay svg {
  max-width: 95vw; max-height: 85vh;
  height: auto; width: auto;
}
.diagram-overlay__close {
  position: absolute; top: 16px; right: 16px;
  background: var(--surface); border: 1px solid var(--border-bright);
  border-radius: 8px; color: var(--text);
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; cursor: pointer; opacity: 0.8;
  transition: opacity 0.2s;
}
.diagram-overlay__close:hover { opacity: 1; }

/* Native fullscreen styling for diagram-shell */
.diagram-shell:fullscreen,
.diagram-shell:-webkit-full-screen {
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.diagram-shell:fullscreen .mermaid-wrap,
.diagram-shell:-webkit-full-screen .mermaid-wrap {
  width: 100% !important;
  height: 100% !important;
  max-width: none;
  max-height: none;
}
.diagram-shell:fullscreen .diagram-shell__hint,
.diagram-shell:-webkit-full-screen .diagram-shell__hint {
  display: none;
}

.ref-link {
  color: inherit;
  text-decoration: none;
  /* Keep wrapped <code> chips visually intact — anchor is transparent by default. */
  background: transparent;
  border: 0;
  padding: 0;
}
.ref-link:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.ref-link code {
  /* Don't alter code-chip styling; the link wraps it transparently. */
  color: inherit;
}
.ref-link:hover code {
  color: inherit;
}
.ref-link__icon {
  display: inline-block;
  width: 0.75em;
  height: 0.75em;
  margin-left: 2px;
  vertical-align: middle;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}
.ref-link:hover .ref-link__icon {
  opacity: 1;
}
