/* OPDA Knowledge Base — design-system.css
 * Layout, prose, components. Imports tokens.
 */

@import url("./design-tokens.css");
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

/* ─────────────────────────────────────────────────────────────
   BASE
   ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
/* Bumped root font-size up one notch (16 → 17.5 effective px on default browsers).
   Everything sized in rem scales proportionally — typography, spacing, layout. */
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; font-size: 109%; }
body {
  margin: 0;
  font-family: 'Inter', var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-surface-alt);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a {
  color: var(--color-link);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease);
}
a:hover { color: var(--color-link-hover); text-decoration: underline; text-underline-offset: 3px; }

/* ─────────────────────────────────────────────────────────────
   SHELL — Header / Body / Sidebar / Main
   ───────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center;
  height: var(--header-height);
  padding: 0 var(--space-6);
  /* Always dark navy, in both light + dark modes */
  background: #0b2545;
  color: white;
  border-bottom: 1px solid #13315c;
  box-shadow: var(--shadow-md);
  /* Background is pinned, so pin the brand tints the header text depends on:
     otherwise dark mode inverts them to dark-on-dark and the nav disappears. */
  --color-brand-100: #eef4f8;
  --color-brand-200: #d8e6ed;
  --color-brand-300: #b8d4e3;
}
.app-header .brand-link {
  display: flex; align-items: baseline; gap: var(--space-3);
  color: white; text-decoration: none;
}
.app-header .brand-link:hover { text-decoration: none; }
.app-header .brand-mark {
  font-weight: 800; font-size: var(--text-xl); letter-spacing: -0.02em;
}
.app-header .brand-sub {
  font-weight: 400; font-size: var(--text-sm); color: var(--color-brand-300);
  letter-spacing: 0.01em;
}
/* Horizontal global menu — seven top-level sections */
.app-header .global-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: var(--space-5);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.app-header .global-nav::-webkit-scrollbar { display: none; }
.app-header .global-nav a {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-brand-100);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: -0.005em;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease);
}
.app-header .global-nav a:hover {
  background: rgba(255,255,255,0.10);
  color: white;
  text-decoration: none;
}
.app-header .global-nav a.active {
  background: rgba(255,255,255,0.15);
  color: white;
  box-shadow: inset 0 -2px 0 var(--color-brand-300);
}

.app-header .header-nav { margin-left: auto; display: flex; gap: var(--space-5); }
.app-header .header-nav a {
  color: var(--color-brand-200); font-size: var(--text-sm); font-weight: 500;
}
.app-header .header-nav a:hover { color: white; text-decoration: none; }
.menu-toggle {
  display: none;
  background: transparent; border: 0; color: white; cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-md);
}
.menu-toggle:hover { background: rgba(255,255,255,0.1); }

/* Light/dark theme toggle in the header */
.theme-toggle {
  display: inline-flex;
  align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: white;
  padding: 0;
  width: 2.2rem; height: 2.2rem;
  margin-left: var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
}
.theme-toggle:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.35);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--color-brand-300);
  outline-offset: 2px;
}
.theme-icon { display: none; }
/* In light mode, show the moon (click = go dark);
   in dark mode, show the sun (click = go light). */
:root[data-theme="light"] .theme-icon--moon,
:root:not([data-theme="dark"]) .theme-icon--moon { display: block; }
:root[data-theme="dark"]  .theme-icon--sun  { display: block; }
:root[data-theme="dark"]  .theme-icon--moon { display: none;  }

/* Sidebar section title */
.sidebar-section-title {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  color: var(--color-brand-700);
  padding: 0 var(--space-3) var(--space-3);
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

/* When there's no sidebar (home page), give main full width */
.app-body.no-sidebar {
  grid-template-columns: 1fr;
}

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  align-items: start;
  min-height: calc(100vh - var(--header-height));
}

.app-sidebar {
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: var(--space-6) 0 var(--space-7);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
}
.sidebar-nav { padding: 0 var(--space-5); }
.nav-group + .nav-group { margin-top: var(--space-5); }
.app-sidebar h3 {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--color-ink-500);
  font-weight: 700;
  margin: 0 var(--space-3) var(--space-2);
  padding-top: var(--space-1);
}
.app-sidebar ul { list-style: none; padding: 0; margin: 0; }
.app-sidebar li + li { margin-top: 2px; }
.app-sidebar a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--color-ink-700);
  line-height: 1.35;
}
.app-sidebar a:hover {
  background: var(--color-brand-100);
  color: var(--color-brand-900);
  text-decoration: none;
}
.app-sidebar a.active {
  /* Pinned mid-blue so white text contrasts in both modes */
  background: #1a4d80;
  color: white;
  box-shadow: 0 1px 2px rgba(11,37,69,0.18);
}

.app-main {
  padding: var(--space-8) var(--space-10);
  max-width: 100%;
  background: var(--color-surface-alt);
}

/* Mobile / narrow */
@media (max-width: 960px) {
  .menu-toggle { display: inline-flex; margin-left: auto; }
  .app-header .header-nav { display: none; }
  .app-header .global-nav { margin-left: var(--space-3); gap: 0; }
  .app-header .global-nav a { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }
  .app-body { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0; right: 0;
    height: calc(100vh - var(--header-height));
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease);
    z-index: 40;
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { padding: var(--space-5) var(--space-5); }
}

/* ─────────────────────────────────────────────────────────────
   PROSE — typography for body content
   ───────────────────────────────────────────────────────────── */
.prose {
  max-width: 56rem;
  margin: 0 auto;
  background: var(--color-surface);
  padding: var(--space-8) var(--space-8);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
}
.prose.wide { max-width: 112.5rem; } /* 1800px */
.prose > * + * { margin-top: var(--space-4); }
.prose > h2 + *, .prose > h3 + *, .prose > h1 + * { margin-top: var(--space-3); }

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-ink-900);
  line-height: var(--leading-tight);
  margin-top: var(--space-7);
  margin-bottom: var(--space-3);
}
.prose h1 {
  font-size: clamp(1.875rem, 1.5rem + 1.5vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-top: 0;
}
.prose h1 + .lead {
  font-size: var(--text-xl);
  color: var(--color-ink-600);
  line-height: var(--leading-snug);
  font-weight: 400;
  margin: var(--space-4) 0 var(--space-6);
  max-width: 56ch;
}
.prose h2 {
  font-size: var(--text-2xl);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-8);
}
.prose h1 + h2, .prose .page-meta + h1 + h2, .prose .lead + h2 { border-top: 0; padding-top: 0; }
.prose h3 { font-size: var(--text-xl); }
.prose h4 { font-size: var(--text-lg); color: var(--color-ink-700); font-weight: 600; }

.prose p, .prose ul, .prose ol { margin: 0; }
.prose ul, .prose ol { padding-left: 1.25em; }
.prose li + li { margin-top: var(--space-2); }
.prose ul li::marker { color: var(--color-brand-500); }
.prose strong { color: var(--color-ink-900); font-weight: 600; }
.prose blockquote {
  border-left: 4px solid var(--color-brand-500);
  padding: var(--space-3) var(--space-5);
  margin: var(--space-5) 0;
  background: var(--color-brand-50);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-style: italic;
  color: var(--color-ink-700);
}
.prose blockquote > * + * { margin-top: var(--space-2); }

.heading-anchor {
  display: inline-block;
  margin-left: var(--space-2);
  opacity: 0;
  font-weight: 400;
  color: var(--color-brand-500);
  font-size: 0.7em;
  transition: opacity var(--duration-fast) var(--ease);
  text-decoration: none;
}
.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor { opacity: 1; }
.heading-anchor:hover { color: var(--color-brand-700); text-decoration: none; }

/* ─────────────────────────────────────────────────────────────
   CODE
   ───────────────────────────────────────────────────────────── */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--color-brand-100);
  padding: 0.1em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--color-brand-900);
  word-break: break-word;
}
/* File-path resource link — <a class="resource-link"><code>source/…</code></a> */
.resource-link {
  text-decoration: none;
  color: inherit;
  border-bottom: 1px dashed var(--color-brand-500);
  transition: background var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
}
.resource-link:hover { text-decoration: none; border-bottom-color: var(--color-brand-700); }
.resource-link:hover code {
  background: var(--color-brand-200);
  color: var(--color-brand-900);
}
.resource-link:focus-visible {
  outline: 2px solid var(--color-brand-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Tables already use .pill / .enum-pill which override these — only inline path codes need the visual cue. */
.prose pre {
  /* Always dark — works for both light and dark page modes */
  background: #0b1220;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: 1.55;
  margin: var(--space-4) 0;
  box-shadow: var(--shadow-sm);
}
.prose pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* ─────────────────────────────────────────────────────────────
   TABLES
   ───────────────────────────────────────────────────────────── */
.prose table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: var(--space-5) 0;
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}
.prose th, .prose td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}
.prose tbody tr:last-child td { border-bottom: 0; }
.prose th {
  background: var(--color-brand-100);
  color: var(--color-brand-900);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.prose tbody tr:hover { background: var(--color-brand-50); }
.prose tbody tr:nth-child(2n) { background: var(--color-ink-50); }
.prose tbody tr:nth-child(2n):hover { background: var(--color-brand-50); }

/* ─────────────────────────────────────────────────────────────
   CALLOUTS
   ───────────────────────────────────────────────────────────── */
.callout {
  border-left: 4px solid var(--color-info-500);
  background: var(--color-info-100);
  padding: var(--space-4) var(--space-5);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: var(--space-5) 0;
  box-shadow: var(--shadow-sm);
}
.callout > * + * { margin-top: var(--space-2); }
.callout--note    { border-color: var(--color-info-500);    background: var(--color-info-100); }
.callout--key     { border-color: var(--color-brand-700);   background: linear-gradient(135deg, var(--color-brand-100), var(--color-brand-50)); }
.callout--warn    { border-color: var(--color-warning-500); background: var(--color-warning-100); }
.callout--success { border-color: var(--color-success-500); background: var(--color-success-100); }
.callout--danger  { border-color: var(--color-danger-500);  background: var(--color-danger-100); }
.callout__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  margin: 0;
}
.callout--note .callout__label    { color: var(--color-info-700); }
.callout--key .callout__label     { color: var(--color-brand-700); }
.callout--warn .callout__label    { color: var(--color-warning-700); }
.callout--success .callout__label { color: var(--color-success-700); }
.callout--danger .callout__label  { color: var(--color-danger-700); }

/* ─────────────────────────────────────────────────────────────
   PILLS
   ───────────────────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.2em 0.65em;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--color-ink-100);
  color: var(--color-ink-700);
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1;
}
.pill--brand   { background: var(--color-brand-100);   color: var(--color-brand-900); }
.pill--success { background: var(--color-success-100); color: var(--color-success-700); }
.pill--warn    { background: var(--color-warning-100); color: var(--color-warning-700); }
.pill--info    { background: var(--color-info-100);    color: var(--color-info-700); }
.pill--accent  { background: var(--color-accent-100);  color: var(--color-accent-700); }

/* ─────────────────────────────────────────────────────────────
   CARDS
   ───────────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
  gap: var(--space-4);
  margin: var(--space-5) 0;
  list-style: none;
  padding: 0;
}
.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  background: var(--color-surface);
  transition: transform var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
  text-decoration: none;
  color: inherit;
}
a.card { color: inherit; }
a.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-brand-500);
  text-decoration: none;
}
.card h3 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-ink-900);
}
.card a h3, .card h3 a { color: inherit; text-decoration: none; }
.card p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-ink-600);
  line-height: var(--leading-normal);
}
.card .pill { align-self: flex-start; margin-bottom: var(--space-1); }
.card .card-meta {
  margin-top: auto;
  font-size: var(--text-xs);
  color: var(--color-ink-500);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.card-arrow {
  margin-left: auto;
  color: var(--color-brand-500);
  font-weight: 600;
  transition: transform var(--duration-fast) var(--ease);
}
a.card:hover .card-arrow { transform: translateX(3px); }

/* ─────────────────────────────────────────────────────────────
   HERO / Section header
   ───────────────────────────────────────────────────────────── */
.hero {
  /* Pinned dark navy gradient in both modes */
  background: linear-gradient(135deg, #0b2545, #1a4d80);
  color: white;
  padding: var(--space-10) var(--space-8);
  border-radius: var(--radius-xl);
  margin-bottom: var(--space-6);
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  top: -100px; right: -100px;
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(74,144,194,0.4), transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}
.hero h1 {
  font-size: clamp(2rem, 1.5rem + 2vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin: 0 0 var(--space-3);
  color: white;
  position: relative;
}
.hero p {
  font-size: var(--text-xl);
  color: var(--color-brand-200);
  max-width: 60ch;
  margin: 0;
  line-height: var(--leading-snug);
  position: relative;
}
.hero .pill { background: rgba(255,255,255,0.15); color: white; margin-bottom: var(--space-3); }

/* ─────────────────────────────────────────────────────────────
   DIAGRAMS (mermaid)
   ───────────────────────────────────────────────────────────── */
.diagram {
  margin: var(--space-6) 0;
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow-x: auto;
}
.diagram .mermaid {
  display: flex;
  justify-content: center;
  font-family: 'Inter', var(--font-sans);
}
.diagram-caption {
  font-size: var(--text-sm);
  color: var(--color-ink-500);
  text-align: center;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--color-border);
  font-style: italic;
}

/* Click a rendered diagram to open a fullscreen pan/zoom viewer. Wired in site.js.
   Ported from the diagramming-skill markdown-export HTML viewer, adapted for
   inline SVG. */
.diagram .mermaid svg { cursor: zoom-in; }
.diagram-lightbox {
  display: none;
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
.diagram-lightbox.open { display: block; }
.diagram-lightbox .viewer-canvas {
  width: 100%; height: 100%;
  cursor: grab;
  overflow: hidden;
  position: relative;
}
.diagram-lightbox .viewer-canvas.dragging { cursor: grabbing; }
.diagram-lightbox .viewer-canvas .mermaid {
  position: absolute;
  transform-origin: 0 0;
  top: 0; left: 0;
}
.diagram-lightbox .viewer-canvas .mermaid > svg {
  display: block;
  width: 100%;
  height: 100%;
}
.diagram-lightbox .viewer-controls {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px;
  background: rgba(0,0,0,0.7);
  border-radius: 8px;
  padding: 8px 12px;
  z-index: 10000;
}
.diagram-lightbox .viewer-controls button {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  min-width: 36px; height: 36px;
  border-radius: 6px;
  font-size: 14px; font-weight: 500;
  font-family: inherit;
  padding: 0 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.diagram-lightbox .viewer-controls button:hover { background: rgba(255,255,255,0.3); }
.diagram-lightbox .viewer-zoom-label {
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  line-height: 36px;
  min-width: 52px;
  text-align: center;
  font-family: var(--font-mono, ui-monospace, monospace);
}
.diagram-lightbox .viewer-close {
  position: fixed; top: 16px; right: 16px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
  transition: background 0.15s;
}
.diagram-lightbox .viewer-close:hover { background: rgba(255,255,255,0.2); }

/* ─────────────────────────────────────────────────────────────
   PAGE META + FOOTER
   ───────────────────────────────────────────────────────────── */
.page-meta {
  font-size: var(--text-xs);
  color: var(--color-ink-500);
  margin-bottom: var(--space-5);
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  align-items: center;
}
.page-footer {
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
}
.page-footer a {
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-brand-100);
  color: var(--color-brand-900);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease);
}
.page-footer a:hover { background: var(--color-brand-200); text-decoration: none; }

/* ─────────────────────────────────────────────────────────────
   UTILITIES
   ───────────────────────────────────────────────────────────── */
.muted { color: var(--color-ink-500); }
.tiny  { font-size: var(--text-xs); }
.source-note {
  font-size: var(--text-xs);
  color: var(--color-ink-500);
  margin-top: var(--space-3);
}
.source-note code { font-size: 0.85em; }

/* ─────────────────────────────────────────────────────────────
   DATA BROWSER (vanilla-JS table component)
   Used by the properties + entities browser pages.
   ───────────────────────────────────────────────────────────── */
.data-browser {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin: var(--space-5) 0;
}
.db-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--color-ink-50);
  border-bottom: 1px solid var(--color-border);
}
.db-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 9rem;
}
.db-field--grow { flex: 1 1 18rem; }
.db-field label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-ink-500);
}
.db-input,
.db-select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--duration-fast) var(--ease),
              box-shadow var(--duration-fast) var(--ease);
}
.db-input:focus,
.db-select:focus {
  outline: 0;
  border-color: var(--color-brand-500);
  box-shadow: 0 0 0 3px rgba(74,144,194,0.25);
}
.db-input { min-width: 14rem; }
.db-reset {
  align-self: end;
  padding: 0.55rem 0.95rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-ink-700);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease);
}
.db-reset:hover { background: var(--color-ink-100); }
.db-summary {
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.db-summary strong { color: var(--color-text); font-weight: 600; }
.db-table-wrap {
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
}
.db-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
}
/* Fixed layout — column widths come from <colgroup> */
.db-table.db-table--fixed { table-layout: fixed; }
.db-table.db-table--fixed td,
.db-table.db-table--fixed th {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.db-table.db-table--fixed td code {
  display: inline-block;
  max-width: 100%;
  word-break: break-all;
  white-space: normal;
}
/* Per-column alignment */
.db-table th.align-right,  .db-table td.align-right  { text-align: right; }
.db-table th.align-center, .db-table td.align-center { text-align: center; }
.db-table th.align-left,   .db-table td.align-left   { text-align: left;  }
/* Optional truncate-with-ellipsis cell */
.db-table .db-cell--truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.db-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-brand-100);
  color: var(--color-brand-900);
  font-weight: 600;
  text-align: left;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--color-border-strong);
  white-space: nowrap;
}
.db-table thead th.sortable { cursor: pointer; user-select: none; }
.db-table thead th.sortable:hover { background: var(--color-brand-200); }
.db-table thead th .sort-indicator {
  display: inline-block;
  margin-left: 0.35em;
  color: var(--color-ink-400);
  font-weight: 500;
}
.db-table thead th.sort-asc  .sort-indicator,
.db-table thead th.sort-desc .sort-indicator {
  color: var(--color-brand-700);
}
.db-table tbody td {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--color-ink-100);
  vertical-align: top;
  color: var(--color-text);
}
.db-table tbody tr:hover td { background: var(--color-brand-50); }
.db-table tbody tr:nth-child(2n) td { background: var(--color-ink-50); }
.db-table tbody tr:nth-child(2n):hover td { background: var(--color-brand-100); }
.db-table code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--color-ink-100);
  color: var(--color-brand-900);
}
.db-table .pill { font-size: 0.72rem; padding: 1px 8px; }
.db-table .enum-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 1px 6px;
  margin: 1px 2px 1px 0;
  border-radius: 3px;
  background: var(--color-brand-100);
  color: var(--color-brand-900);
  border: 1px solid var(--color-brand-200);
}
.db-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--color-ink-50);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-sm);
}
.db-pagination .db-page-info { color: var(--color-text-muted); }
.db-pagination .db-page-controls {
  display: flex;
  gap: var(--space-1);
}
.db-pagination button {
  min-width: 2rem;
  padding: 0.25rem 0.6rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-ink-700);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease);
}
.db-pagination button:hover:not(:disabled) {
  background: var(--color-brand-100);
  color: var(--color-brand-900);
}
.db-pagination button.current {
  /* Pinned mid-blue in both modes */
  background: #1a4d80;
  color: white;
  border-color: #1a4d80;
}
.db-pagination button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.db-empty {
  padding: var(--space-7) var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.db-status-loading {
  padding: var(--space-7) var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
@media (max-width: 760px) {
  .db-toolbar { flex-direction: column; align-items: stretch; }
  .db-field, .db-field--grow { min-width: 0; }
  .db-input { min-width: 0; width: 100%; }
  .db-pagination { flex-direction: column; align-items: stretch; }
  .db-pagination .db-page-controls { justify-content: center; }
}

/* ─────────────────────────────────────────────────────────────
   RIGHT-RAIL TOC (third grid column)
   Auto-built from h2/h3/h4 headings in the .prose article.
   Mounted as a sibling of .app-main; .app-body adds the third
   column when it sees a .toc child. Sticky on scroll, highlights
   the heading currently in view. Hidden under ~1280px viewports.
   ───────────────────────────────────────────────────────────── */
.app-body.with-toc {
  grid-template-columns: var(--sidebar-width) 1fr 16rem;
}
.toc {
  position: sticky;
  top: var(--header-height);
  align-self: start;            /* don't stretch to full grid row height */
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: var(--space-6) var(--space-4) var(--space-7) var(--space-3);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  font-size: var(--text-sm);
  scrollbar-width: thin;
}
.toc-title {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--color-ink-500);
  margin-bottom: var(--space-3);
  padding-left: var(--space-2);
}
.toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc li { margin: 0; }
.toc li + li { margin-top: 1px; }
.toc a {
  display: block;
  padding: 4px 8px 4px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  border-left: 2px solid transparent;
  margin-left: -2px;             /* align with .toc border-left */
  color: var(--color-ink-700);
  line-height: 1.35;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease),
              color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
}
.toc a:hover {
  background: var(--color-brand-100);
  color: var(--color-brand-900);
  text-decoration: none;
}
.toc a.active {
  background: var(--color-brand-100);
  color: var(--color-brand-900);
  font-weight: 600;
  border-left-color: var(--color-brand-700);
}
/* Indent levels */
.toc .toc-level-h2 a { font-size: 0.875rem; }
.toc .toc-level-h3 a { padding-left: 26px; font-size: 0.825rem; color: var(--color-ink-600); }
.toc .toc-level-h4 a { padding-left: 40px; font-size: 0.78rem;  color: var(--color-ink-500); }

/* Hide the TOC on narrower viewports — the prose already fits a single column */
@media (max-width: 1280px) {
  .toc { display: none; }
}

/* ─────────────────────────────────────────────────────────────
   Theme-independent overrides
   The token palette flip in design-tokens.css handles most components
   automatically (every "100 bg / 900 text" pair reads correctly because
   both values flip together when the data-theme attribute changes).
   The few rules below cover elements that should look the SAME in both
   modes — they're pinned to fixed colours rather than tokens.
   ───────────────────────────────────────────────────────────── */
/* Inline code is driven by --color-brand-100 / --color-brand-900 (see .prose code
   above). Both tokens flip via design-tokens.css when data-theme="dark" is set,
   so light mode → light bg + dark text, dark mode → dark bg + light text. No
   pinning needed. */
/* Mermaid: surface frame uses the live tokens so it adapts to mode */
.diagram { background: var(--color-surface); border: 1px solid var(--color-border); }
.mermaid svg { background: transparent; }
/* Pin Mermaid label font-size so the 109% root font-size doesn't scale the
   foreignObject text past the box bounds and clip labels. */
.mermaid foreignObject div { font-size: 14px !important; line-height: 1.3 !important; }
.mermaid .nodeLabel       { font-size: 14px !important; }
.mermaid .edgeLabel       { font-size: 13px !important; }
.mermaid .cluster-label   { font-size: 13px !important; }

/* Dark-mode classDef remapping.
   Per-page classDef rules in the Mermaid source hardcode light pastel fills
   (#dbeafe, #dcfce7, #fef3c7 …). In dark mode those become bright spots
   against the dark page. Mermaid emits each classDef name as a CSS class on
   the rendered <g class="node X"> wrapper, so we can override the fill via
   CSS — same names across pages. */
:root[data-theme="dark"] .mermaid g.node rect,
:root[data-theme="dark"] .mermaid g.node polygon,
:root[data-theme="dark"] .mermaid g.node circle,
:root[data-theme="dark"] .mermaid g.node ellipse,
:root[data-theme="dark"] .mermaid g.node path {
  stroke: var(--color-brand-400) !important;
}
/* "Government / policy / forum" group — deep navy-blue */
:root[data-theme="dark"] .mermaid g.node.gov     rect,
:root[data-theme="dark"] .mermaid g.node.act     rect,
:root[data-theme="dark"] .mermaid g.node.policy  rect,
:root[data-theme="dark"] .mermaid g.node.forum   rect,
:root[data-theme="dark"] .mermaid g.node.body    rect,
:root[data-theme="dark"] .mermaid g.node.regulator rect {
  fill: #172554 !important;
}
/* "Outputs / delivery / ops" group — deep forest green */
:root[data-theme="dark"] .mermaid g.node.out     rect,
:root[data-theme="dark"] .mermaid g.node.del     rect,
:root[data-theme="dark"] .mermaid g.node.ops     rect,
:root[data-theme="dark"] .mermaid g.node.tech    rect {
  fill: #052e16 !important;
}
/* "Form / process / phase" group — very deep amber */
:root[data-theme="dark"] .mermaid g.node.form    rect,
:root[data-theme="dark"] .mermaid g.node.proc    rect,
:root[data-theme="dark"] .mermaid g.node.step    rect,
:root[data-theme="dark"] .mermaid g.node.phase   rect {
  fill: #431407 !important;
}
/* "Source / std / primary / proptech" — very deep navy */
:root[data-theme="dark"] .mermaid g.node.src     rect,
:root[data-theme="dark"] .mermaid g.node.std     rect,
:root[data-theme="dark"] .mermaid g.node.ext     rect,
:root[data-theme="dark"] .mermaid g.node.primary rect,
:root[data-theme="dark"] .mermaid g.node.proptech rect,
:root[data-theme="dark"] .mermaid g.node.conv    rect,
:root[data-theme="dark"] .mermaid g.node.portal  rect,
:root[data-theme="dark"] .mermaid g.node.search  rect,
:root[data-theme="dark"] .mermaid g.node.root    rect,
:root[data-theme="dark"] .mermaid g.node.strat   rect,
:root[data-theme="dark"] .mermaid g.node.tier    rect,
:root[data-theme="dark"] .mermaid g.node.sg      rect,
:root[data-theme="dark"] .mermaid g.node.wg      rect,
:root[data-theme="dark"] .mermaid g.node.lender  rect {
  fill: #0b2545 !important;
}
/* OPDA / "pl" highlighted node — slightly lighter than other dark fills + bright border */
:root[data-theme="dark"] .mermaid g.node.opda    rect,
:root[data-theme="dark"] .mermaid g.node.pl      rect,
:root[data-theme="dark"] .mermaid g.node.l4      rect {
  fill: #13315c !important;
  stroke: #7aaecf !important;
}
/* Mid-tier (l1/l2/l3 layered diagrams) — each level slightly darker than before */
:root[data-theme="dark"] .mermaid g.node.l1 rect { fill: #0b2545 !important; }
:root[data-theme="dark"] .mermaid g.node.l2 rect { fill: #13315c !important; }
:root[data-theme="dark"] .mermaid g.node.l3 rect { fill: #1a4d80 !important; }
/* Text inside any dark-mode node — force light so the new dark fills are legible */
:root[data-theme="dark"] .mermaid g.node .nodeLabel,
:root[data-theme="dark"] .mermaid g.node foreignObject div,
:root[data-theme="dark"] .mermaid g.node text {
  color: #eef4f8 !important;
  fill:  #eef4f8 !important;
}
/* ER attribute rows — Mermaid 11 derives the odd/even stripe from primaryColor
   by lightening one row roughly 75% (near-white in dark mode). The row group
   is a <g class="row-rect-odd"> wrapping two <path>s; the *first* path is the
   filled rectangle whose fill attribute we need to override. */
:root[data-theme="dark"] .mermaid .row-rect-odd  > path:first-child { fill: #0f1729 !important; }
:root[data-theme="dark"] .mermaid .row-rect-even > path:first-child { fill: #0b1220 !important; }
/* Schema physical-architecture classDef groups */
:root[data-theme="dark"] .mermaid g.node.base    rect { fill: #0b2545 !important; }
:root[data-theme="dark"] .mermaid g.node.overlay rect { fill: #431407 !important; }
:root[data-theme="dark"] .mermaid g.node.engine  rect { fill: #134e4a !important; }
:root[data-theme="dark"] .mermaid g.node.api     rect { fill: #1e1b4b !important; }
:root[data-theme="dark"] .mermaid g.node.trust   rect { fill: #3b0764 !important; }
/* Resource viewer iframes — file content is almost always light-on-light, so keep iframe surface white */
.res-frame, .res-jsoncrack-wrap iframe { background: #ffffff; }
/* Index home cards: pin gradient bars to original colours in both modes */
.home-section-card::before {
  background: linear-gradient(90deg, #1a4d80, #4a90c2);
}
.home-section-card.modelling::before {
  background: linear-gradient(90deg, #b45309, #f59e0b);
}
/* Resource viewer error <pre> uses inline style — pin dark in both modes */
.res-binary pre,
.res-error pre,
.redoc-status pre,
.res-jsoncrack-status pre {
  background: #0b1220 !important;
  color: #f1f5f9 !important;
}

/* ─────────────────────────────────────────────────────────────
   PRINT
   ───────────────────────────────────────────────────────────── */
@media print {
  body { background: white; }
  .app-header, .app-sidebar, .page-footer, .menu-toggle { display: none; }
  .app-body { display: block; }
  .app-main { padding: 0; }
  .prose { box-shadow: none; border: 0; padding: 0; max-width: none; }
  .prose h1, .prose h2, .prose h3 { page-break-after: avoid; }
  .diagram, .callout, .card { page-break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; color: #666; }
}
