/* ============================================================
   XALGORIX DOCS — Geist-Inspired Design System
   Clean, professional, Vercel/Stripe-quality documentation
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@100;200;300;400;500;600;700;800;900&display=swap');

/* ============================================================
   1. CSS CUSTOM PROPERTIES (DESIGN TOKENS)
   ============================================================ */
:root {
  /* Background */
  --bg: #000000;
  --bg-elevated: #0a0a0a;
  --bg-subtle: #111111;
  --bg-muted: #191919;
  --bg-overlay: rgba(0, 0, 0, 0.7);

  /* Foreground / Text */
  --fg: #eaeaea;
  --fg-muted: #a1a1aa;
  --fg-subtle: #71717a;
  --fg-faint: #52525b;
  --fg-inverse: #09090b;

  /* Accent — Xalgorix Brand Crimson (matches xalgorix.com) */
  --accent: #d70e3a;
  --accent-hover: #c9002e;
  --accent-light: #ff5c73;
  --accent-bg: rgba(215, 14, 58, 0.08);
  --accent-bg-hover: rgba(215, 14, 58, 0.14);
  --accent-border: rgba(215, 14, 58, 0.35);

  /* Success / Emerald */
  --success: #10b981;
  --success-light: #34d399;
  --success-bg: rgba(16, 185, 129, 0.1);
  --success-border: rgba(16, 185, 129, 0.4);

  /* Warning / Amber */
  --warning: #f59e0b;
  --warning-light: #fbbf24;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --warning-border: rgba(245, 158, 11, 0.4);

  /* Danger / Red */
  --danger: #ef4444;
  --danger-light: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --danger-border: rgba(239, 68, 68, 0.4);

  /* Borders */
  --border: #222222;
  --border-hover: #444444;
  --border-active: #666666;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Spacing */
  --sidebar-w: 280px;
  --topbar-h: 56px;
  --content-max-w: 860px;
  --content-padding: 3rem;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

/* ============================================================
   2. RESET & BASE TYPOGRAPHY
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

a {
  color: var(--accent-light);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: #ff8598;
}

::selection {
  background: rgba(215, 14, 58, 0.35);
  color: var(--fg);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--fg-subtle);
}

img {
  max-width: 100%;
  height: auto;
}

/* ============================================================
   3. TOP BAR
   ============================================================ */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--fg);
  transition: opacity var(--transition-fast);
}

.topbar-logo:hover {
  opacity: 0.8;
  color: var(--fg);
}

.topbar-logo img {
  height: 24px;
  width: auto;
}

.topbar-logo span {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--fg);
}

.topbar-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--accent-border);
  color: var(--accent-light);
  border-radius: var(--radius-sm);
  background: var(--accent-bg);
  letter-spacing: 0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.topbar-link {
  font-size: 0.85rem;
  color: var(--fg-muted);
  transition: color var(--transition-fast);
  font-weight: 400;
}

.topbar-link:hover {
  color: var(--accent-light);
}

/* Search */
.search-wrapper {
  position: relative;
  width: 260px;
}

.search-input {
  width: 100%;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  padding: 0.5rem 0.8rem 0.5rem 2.25rem;
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-input::placeholder {
  color: var(--fg-faint);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.search-prefix {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-faint);
  font-size: 0.85rem;
  pointer-events: none;
  display: flex;
  align-items: center;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 200;
  box-shadow: var(--shadow-lg);
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--bg-muted);
}

.search-result-item .result-title {
  color: var(--fg);
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.search-result-item .result-section {
  color: var(--fg-faint);
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 6px;
  color: var(--fg);
  transition: border-color var(--transition-fast);
}

.sidebar-toggle:hover {
  border-color: var(--border-hover);
}

.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 1.5px;
  background: currentColor;
  margin: 3.5px 0;
  transition: transform var(--transition-base), opacity var(--transition-base);
}

/* ============================================================
   4. SIDEBAR
   ============================================================ */
.docs-layout {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg);
  border-right: 1px solid var(--border);
  height: calc(100vh - var(--topbar-h));
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.25rem 0;
  transition: transform var(--transition-slow);
  z-index: 50;
}

.sidebar-section {
  margin-bottom: 1.75rem;
}

.sidebar-heading {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-subtle);
  padding: 0 1.25rem;
  margin-bottom: 0.4rem;
}

.sidebar-nav {
  list-style: none;
}

.sidebar-nav li a {
  display: block;
  padding: 0.4rem 1.25rem 0.4rem 1.5rem;
  font-size: 0.85rem;
  color: var(--fg-muted);
  border-left: 2px solid transparent;
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}

.sidebar-nav li a:hover {
  color: var(--fg);
  background: var(--bg-subtle);
}

.sidebar-nav li a.active {
  color: var(--fg);
  border-left-color: var(--accent);
  background: var(--accent-bg);
  font-weight: 500;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 40;
  transition: opacity var(--transition-slow);
}

.sidebar-overlay.active {
  display: block;
}

/* ============================================================
   5. MAIN CONTENT AREA
   ============================================================ */
.docs-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 2.5rem var(--content-padding) 4rem;
  max-width: calc(var(--content-max-w) + var(--content-padding) * 2);
  min-height: calc(100vh - var(--topbar-h));
}

/* ============================================================
   6. TYPOGRAPHY
   ============================================================ */
.doc-page h1 {
  font-family: var(--font-sans);
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.2;
  margin-bottom: 0.5rem;
  color: var(--fg);
}

.doc-page .page-description {
  font-size: 1rem;
  color: var(--fg-muted);
  margin-bottom: 2.5rem;
  max-width: 640px;
  line-height: 1.7;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.doc-page h2 {
  font-family: var(--font-sans);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  margin: 3rem 0 1rem;
  color: var(--fg);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  line-height: 1.3;
}

.doc-page h3 {
  font-family: var(--font-sans);
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 2rem 0 0.75rem;
  color: var(--fg);
  line-height: 1.4;
}

.doc-page h4 {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 1.5rem 0 0.5rem;
  color: var(--fg);
}

.doc-page p {
  margin-bottom: 1rem;
  font-size: 0.9375rem;
  line-height: 1.7;
  color: var(--fg-muted);
}

.doc-page ul,
.doc-page ol {
  margin: 0.5rem 0 1.5rem 1.5rem;
  font-size: 0.9375rem;
}

.doc-page li {
  margin-bottom: 0.4rem;
  line-height: 1.7;
  color: var(--fg-muted);
}

.doc-page li::marker {
  color: var(--fg-faint);
}

.doc-page strong {
  color: var(--fg);
  font-weight: 600;
}

.doc-page em {
  font-style: italic;
  color: var(--fg-muted);
}

.doc-page a {
  color: var(--accent-light);
  text-decoration: underline;
  text-decoration-color: rgba(215, 14, 58, 0.35);
  text-underline-offset: 2px;
  transition: text-decoration-color var(--transition-fast), color var(--transition-fast);
}

.doc-page a:hover {
  text-decoration-color: var(--accent);
  color: #ff8598;
}

.doc-page hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* ============================================================
   7. CODE BLOCKS
   ============================================================ */
.doc-page code {
  font-family: var(--font-mono);
  font-size: 0.8125em;
  background: var(--bg-muted);
  padding: 0.15rem 0.375rem;
  border-radius: var(--radius-sm);
  color: var(--fg);
  border: 1px solid var(--border);
}

.code-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin: 1rem 0 1.5rem;
  overflow-x: auto;
  position: relative;
  font-size: 0.8125rem;
  line-height: 1.7;
}

.code-block code {
  background: none;
  padding: 0;
  border: none;
  font-size: inherit;
  white-space: pre;
  color: var(--fg);
}

.code-block .comment {
  color: var(--fg-faint);
  font-style: italic;
}

.code-block .string {
  color: var(--success-light);
}

.code-block .keyword {
  color: var(--accent-light);
}

.code-block .flag {
  color: var(--warning-light);
}

.code-copy {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), border-color var(--transition-fast), background var(--transition-fast);
  opacity: 0;
}

.code-block:hover .code-copy {
  opacity: 1;
}

.code-copy:hover {
  color: var(--fg);
  border-color: var(--border-hover);
  background: var(--bg-subtle);
}

.code-copy.copied {
  color: var(--success);
  border-color: var(--success-border);
}

/* ============================================================
   8. TABLES
   ============================================================ */
.doc-table-wrapper {
  overflow-x: auto;
  margin: 1rem 0 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  -webkit-overflow-scrolling: touch;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.doc-table th {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.8125rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  color: var(--fg);
  background: var(--bg-subtle);
  white-space: nowrap;
}

.doc-table td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg-muted);
  vertical-align: top;
}

.doc-table tr:last-child td {
  border-bottom: none;
}

.doc-table tr:hover td {
  background: var(--bg-subtle);
}

.doc-table code {
  font-size: 0.8em;
}

/* ============================================================
   9. CALLOUT BOXES
   ============================================================ */
.callout {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin: 1rem 0 1.5rem;
  font-size: 0.875rem;
  line-height: 1.6;
}

.callout .callout-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 0.4rem;
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout-note {
  border-color: var(--accent-border);
  background: var(--accent-bg);
}

.callout-note .callout-title {
  color: var(--accent-light);
}

.callout-note::before {
  content: "Note";
  display: block;
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 0.4rem;
  color: var(--accent-light);
}

.callout-warning {
  border-color: var(--warning-border);
  background: var(--warning-bg);
}

.callout-warning .callout-title {
  color: var(--warning-light);
}

.callout-warning::before {
  content: "Warning";
  display: block;
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 0.4rem;
  color: var(--warning-light);
}

.callout-danger {
  border-color: var(--danger-border);
  background: var(--danger-bg);
}

.callout-danger .callout-title {
  color: var(--danger-light);
}

.callout-danger::before {
  content: "Danger";
  display: block;
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 0.4rem;
  color: var(--danger-light);
}

.callout-tip {
  border-color: var(--success-border);
  background: var(--success-bg);
}

.callout-tip .callout-title {
  color: var(--success-light);
}

.callout-tip::before {
  content: "Tip";
  display: block;
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 0.4rem;
  color: var(--success-light);
}

/* ============================================================
   10. PAGE NAVIGATION (PREV / NEXT)
   ============================================================ */
.page-nav {
  display: flex;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.page-nav-btn {
  flex: 1;
  display: block;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  text-decoration: none;
}

.page-nav-btn:hover {
  border-color: var(--accent-border);
  background: var(--bg-subtle);
}

.page-nav-btn:hover .page-nav-title {
  color: var(--accent-light);
}

.page-nav-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--fg-faint);
  margin-bottom: 0.25rem;
  letter-spacing: 0.02em;
}

.page-nav-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--fg);
}

.page-nav-next {
  text-align: right;
}

/* ============================================================
   11. FOOTER
   ============================================================ */
.docs-footer {
  margin-left: var(--sidebar-w);
  border-top: 1px solid var(--border);
  padding: 2rem var(--content-padding);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.docs-footer-copy {
  font-size: 0.8125rem;
  color: var(--fg-faint);
}

.docs-footer-links {
  display: flex;
  gap: 1.5rem;
}

.docs-footer-links a {
  font-size: 0.8125rem;
  color: var(--fg-faint);
  transition: color var(--transition-fast);
}

.docs-footer-links a:hover {
  color: var(--fg);
}

/* ============================================================
   12. BREADCRUMBS
   ============================================================ */
.breadcrumbs {
  font-size: 0.8125rem;
  color: var(--fg-faint);
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
}

.breadcrumbs a {
  color: var(--fg-faint);
  transition: color var(--transition-fast);
}

.breadcrumbs a:hover {
  color: var(--fg);
}

.breadcrumbs .sep {
  color: var(--fg-faint);
  opacity: 0.4;
}

.breadcrumbs .current {
  color: var(--fg-muted);
}

/* ============================================================
   13. ARCHITECTURE DIAGRAM (PREFORMATTED TEXT)
   ============================================================ */
.arch-pre {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--fg-muted);
  white-space: pre;
  margin: 1rem 0 1.5rem;
}

/* ============================================================
   14. MINI TABLE OF CONTENTS
   ============================================================ */
.mini-toc {
  position: fixed;
  top: calc(var(--topbar-h) + 2rem);
  right: 2rem;
  width: 200px;
  max-height: calc(100vh - var(--topbar-h) - 4rem);
  overflow-y: auto;
  padding: 0;
  z-index: 10;
}

.mini-toc-title {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-subtle);
  margin-bottom: 0.75rem;
}

.mini-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--border);
}

.mini-toc li a {
  display: block;
  padding: 0.25rem 0 0.25rem 1rem;
  font-size: 0.75rem;
  color: var(--fg-subtle);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -1px;
  transition: color 150ms, border-color 150ms;
}

.mini-toc li a:hover {
  color: var(--accent-light);
  border-left-color: var(--accent);
}

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

/* ============================================================
   15. PAGE VISIBILITY
   ============================================================ */
.doc-page {
  display: none;
}

.doc-page.active {
  display: block;
  animation: fadeIn var(--transition-base) ease;
}

/* ============================================================
   15. ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   16. RESPONSIVE BREAKPOINTS
   ============================================================ */

/* ─── Large desktop: >= 1440px ─────────────────────────────── */
@media (min-width: 1440px) {
  :root {
    --content-max-w: 900px;
  }
}

/* ─── Tablet landscape / small desktop: <= 1024px ──────────── */
@media (max-width: 1024px) {
  :root {
    --content-padding: 2rem;
    --sidebar-w: 260px;
  }

  .docs-content {
    max-width: 100%;
  }

  .topbar-link {
    display: none;
  }

  .sidebar-nav li a {
    padding: 0.35rem 1rem 0.35rem 1.25rem;
    font-size: 0.825rem;
  }

  .doc-page h2 {
    font-size: 1.375rem;
  }

  .doc-page h3 {
    font-size: 1.1rem;
  }
}

/* ─── Tablet portrait: <= 900px ────────────────────────────── */
@media (max-width: 900px) {
  :root {
    --content-padding: 1.5rem;
  }

  .sidebar-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    min-width: 280px;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .docs-content {
    margin-left: 0;
    padding: 2rem var(--content-padding) 3rem;
  }

  .docs-footer {
    margin-left: 0;
    padding: 1.5rem var(--content-padding);
  }

  .search-wrapper {
    width: 200px;
  }

  .topbar-badge {
    display: none;
  }
}

/* ─── Mobile landscape / large phone: <= 768px ─────────────── */
@media (max-width: 768px) {
  :root {
    --content-padding: 1.25rem;
    --topbar-h: 52px;
  }

  .topbar {
    padding: 0 1rem;
  }

  .topbar-inner {
    gap: 0.75rem;
  }

  .topbar-logo img {
    height: 22px;
  }

  .topbar-logo span {
    font-size: 0.875rem;
  }

  .search-wrapper {
    width: 160px;
  }

  .search-input {
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem 0.4rem 2rem;
  }

  .docs-content {
    padding: 1.5rem var(--content-padding) 2.5rem;
  }

  .doc-page h1 {
    font-size: 1.5rem;
    letter-spacing: -0.025em;
  }

  .doc-page .page-description {
    font-size: 0.9rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
  }

  .doc-page h2 {
    font-size: 1.2rem;
    margin: 2rem 0 0.75rem;
  }

  .doc-page h3 {
    font-size: 1.05rem;
    margin: 1.5rem 0 0.5rem;
  }

  .doc-page p,
  .doc-page li {
    font-size: 0.875rem;
    line-height: 1.75;
  }

  .doc-page ul,
  .doc-page ol {
    margin: 0.5rem 0 1.25rem 1.25rem;
  }

  /* Tables */
  .doc-table {
    font-size: 0.75rem;
  }

  .doc-table th {
    font-size: 0.7rem;
    padding: 0.6rem 0.75rem;
  }

  .doc-table td {
    padding: 0.5rem 0.75rem;
  }

  /* Code blocks */
  .code-block {
    padding: 1rem;
    font-size: 0.75rem;
    border-radius: var(--radius-md);
    margin: 0.75rem 0 1.25rem;
  }

  .code-block code {
    font-size: 0.75rem;
    word-break: break-all;
    white-space: pre-wrap;
  }

  .code-copy {
    opacity: 1;
    font-size: 0.65rem;
    padding: 0.2rem 0.5rem;
  }

  /* Callouts */
  .callout {
    padding: 0.85rem 1rem;
    font-size: 0.8125rem;
    margin: 0.75rem 0 1.25rem;
  }

  /* Architecture diagram */
  .arch-pre {
    font-size: 0.55rem;
    padding: 1rem 0.75rem;
    line-height: 1.4;
    border-radius: var(--radius-md);
  }

  /* Page navigation */
  .page-nav {
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 2.5rem;
    padding-top: 1.5rem;
  }

  .page-nav-btn {
    padding: 0.85rem 1rem;
  }

  .page-nav-next {
    text-align: left;
  }

  .page-nav-title {
    font-size: 0.875rem;
  }

  /* Footer */
  .docs-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1.25rem var(--content-padding);
  }

  .docs-footer-links {
    gap: 1rem;
  }

  /* Breadcrumbs */
  .breadcrumbs {
    font-size: 0.75rem;
    margin-bottom: 1.5rem;
  }
}

/* ─── Mobile portrait: <= 640px ────────────────────────────── */
@media (max-width: 640px) {
  :root {
    --content-padding: 1rem;
  }

  .topbar {
    padding: 0 0.75rem;
  }

  .topbar-inner {
    gap: 0.5rem;
  }

  .search-wrapper {
    width: 140px;
  }

  .search-input {
    font-size: 0.75rem;
    padding: 0.35rem 0.5rem 0.35rem 1.75rem;
  }

  .search-results {
    position: fixed;
    top: var(--topbar-h);
    left: 0.75rem;
    right: 0.75rem;
    max-height: 60vh;
    width: auto;
  }

  .doc-page h1 {
    font-size: 1.375rem;
  }

  .doc-page h2 {
    font-size: 1.1rem;
  }

  .doc-page h3 {
    font-size: 1rem;
  }

  .doc-page ul,
  .doc-page ol {
    margin-left: 1rem;
  }

  /* Tables get even tighter */
  .doc-table th,
  .doc-table td {
    padding: 0.45rem 0.6rem;
    font-size: 0.7rem;
  }

  /* Code blocks */
  .code-block {
    padding: 0.85rem;
    font-size: 0.7rem;
  }

  .code-block code {
    font-size: 0.7rem;
  }
}

/* ─── Small phones: <= 480px ───────────────────────────────── */
@media (max-width: 480px) {
  :root {
    --content-padding: 0.75rem;
    --topbar-h: 48px;
  }

  .topbar {
    padding: 0 0.5rem;
  }

  .topbar-inner {
    gap: 0.375rem;
  }

  .topbar-logo img {
    height: 20px;
  }

  .topbar-logo span {
    display: none;
  }

  .search-wrapper {
    flex: 1;
    min-width: 0;
    width: auto;
  }

  .search-input {
    font-size: 0.75rem;
    padding: 0.3rem 0.5rem 0.3rem 1.6rem;
  }

  .search-results {
    left: 0.5rem;
    right: 0.5rem;
  }

  .docs-content {
    padding: 1rem var(--content-padding) 2rem;
  }

  .doc-page h1 {
    font-size: 1.25rem;
  }

  .doc-page .page-description {
    font-size: 0.8125rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
  }

  .doc-page h2 {
    font-size: 1rem;
    margin: 1.5rem 0 0.5rem;
    padding-bottom: 0.35rem;
  }

  .doc-page h3 {
    font-size: 0.9375rem;
  }

  .doc-page p {
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
  }

  .doc-page li {
    font-size: 0.8125rem;
    margin-bottom: 0.3rem;
  }

  .doc-page ul,
  .doc-page ol {
    margin: 0.35rem 0 1rem 0.85rem;
  }

  /* Tables: smallest padding */
  .doc-table-wrapper {
    margin: 0.75rem 0 1rem;
    border-radius: var(--radius-md);
  }

  .doc-table th,
  .doc-table td {
    padding: 0.4rem 0.5rem;
    font-size: 0.6875rem;
  }

  /* Code blocks */
  .code-block {
    padding: 0.75rem;
    margin: 0.5rem 0 1rem;
    font-size: 0.6875rem;
  }

  .code-block code {
    font-size: 0.6875rem;
    word-break: break-all;
  }

  .doc-page code {
    font-size: 0.75em;
    padding: 0.1rem 0.25rem;
  }

  /* Callouts */
  .callout {
    padding: 0.75rem;
    font-size: 0.75rem;
    margin: 0.5rem 0 1rem;
  }

  /* Architecture */
  .arch-pre {
    font-size: 0.45rem;
    padding: 0.75rem 0.5rem;
    line-height: 1.3;
  }

  /* Page nav */
  .page-nav {
    margin-top: 2rem;
    padding-top: 1rem;
  }

  .page-nav-btn {
    padding: 0.75rem;
  }

  .page-nav-label {
    font-size: 0.65rem;
  }

  .page-nav-title {
    font-size: 0.8125rem;
  }

  /* Footer */
  .docs-footer {
    padding: 1rem var(--content-padding);
  }

  .docs-footer-copy {
    font-size: 0.75rem;
  }

  .docs-footer-links a {
    font-size: 0.75rem;
  }

  /* Breadcrumbs */
  .breadcrumbs {
    font-size: 0.6875rem;
    margin-bottom: 1rem;
  }

  /* Sidebar - full height on small screens */
  .sidebar {
    width: 260px;
    min-width: 260px;
    padding: 1rem 0;
  }

  .sidebar-heading {
    font-size: 0.65rem;
    padding: 0 1rem;
  }

  .sidebar-nav li a {
    padding: 0.35rem 1rem 0.35rem 1.25rem;
    font-size: 0.8rem;
  }

  .sidebar-section {
    margin-bottom: 1.25rem;
  }
}

/* ─── Very small phones: <= 360px ──────────────────────────── */
@media (max-width: 360px) {
  :root {
    --content-padding: 0.5rem;
  }

  .topbar {
    padding: 0 0.375rem;
  }

  .topbar-badge,
  .topbar-logo span {
    display: none;
  }

  .search-wrapper {
    width: 100%;
  }

  .search-input {
    font-size: 0.7rem;
    padding: 0.25rem 0.4rem 0.25rem 1.5rem;
  }

  .docs-content {
    padding: 0.75rem var(--content-padding) 1.5rem;
  }

  .doc-page h1 {
    font-size: 1.125rem;
  }

  .doc-page h2 {
    font-size: 0.9375rem;
  }

  .doc-page h3 {
    font-size: 0.875rem;
  }

  .doc-page p,
  .doc-page li {
    font-size: 0.75rem;
  }

  .doc-table th,
  .doc-table td {
    padding: 0.35rem 0.4rem;
    font-size: 0.625rem;
  }

  .code-block {
    padding: 0.6rem;
  }

  .code-block code {
    font-size: 0.625rem;
  }

  .callout {
    padding: 0.6rem;
    font-size: 0.7rem;
  }

  .arch-pre {
    font-size: 0.375rem;
    padding: 0.5rem;
  }

  .page-nav-btn {
    padding: 0.6rem;
  }

  .sidebar {
    width: 240px;
    min-width: 240px;
  }

  .sidebar-nav li a {
    font-size: 0.75rem;
  }
}

/* ─── Landscape phones (height-constrained) ────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --topbar-h: 44px;
  }

  .topbar {
    padding: 0 0.75rem;
  }

  .topbar-logo img {
    height: 18px;
  }

  .topbar-logo span {
    display: none;
  }

  .sidebar {
    width: 240px;
    min-width: 240px;
    padding: 0.75rem 0;
  }

  .sidebar-section {
    margin-bottom: 0.75rem;
  }

  .sidebar-nav li a {
    padding: 0.2rem 1rem 0.2rem 1.25rem;
    font-size: 0.75rem;
  }

  .doc-page h1 {
    font-size: 1.25rem;
  }

  .doc-page h2 {
    font-size: 1rem;
    margin: 1.25rem 0 0.5rem;
  }
}

/* ─── Touch device optimizations ───────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  .code-copy {
    opacity: 1;
  }

  .sidebar-nav li a {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .page-nav-btn {
    padding: 1rem;
  }

  .search-result-item {
    padding: 0.85rem 1rem;
  }

  .topbar-link {
    padding: 0.25rem 0;
  }
}

/* ─── Print styles ─────────────────────────────────────────── */
@media print {
  .topbar,
  .sidebar,
  .sidebar-overlay,
  .mini-toc,
  .page-nav,
  .docs-footer,
  .breadcrumbs,
  .search-wrapper,
  .code-copy {
    display: none !important;
  }

  .docs-layout {
    display: block;
  }

  .docs-content {
    margin-left: 0;
    padding: 0;
    max-width: 100%;
  }

  .doc-page {
    display: block !important;
    page-break-inside: avoid;
  }

  body {
    background: white;
    color: black;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  .code-block {
    border: 1px solid #ccc;
    background: #f5f5f5;
  }

  .doc-table {
    border: 1px solid #ccc;
  }

  .doc-table th,
  .doc-table td {
    border: 1px solid #ccc;
  }
}
