/* Docs-specific styles extending the main design system */

/* Skip to content link for accessibility */
.skip-to-content {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--primary);
  color: #0A1600;
  padding: 8px 16px;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  z-index: 1000;
  transition: top 0.2s ease;
}

.skip-to-content:focus {
  top: 6px;
}

/* Docs Layout Grid */
.docs-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: auto 1fr;
  gap: var(--space-lg);
  min-height: 100vh;
}

.docs-sidebar {
  grid-column: 1;
  grid-row: 1 / -1;
  position: sticky;
  top: 80px;
  height: fit-content;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.docs-content {
  grid-column: 2;
  grid-row: 2;
  max-width: 840px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  overflow-x: auto; /* Handle wide code/math content gracefully */
}

.docs-toc {
  grid-column: 3;
  grid-row: 1 / -1;
  position: sticky;
  top: 80px;
  height: fit-content;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  display: none;
}

/* Responsive breakpoints */
@media (max-width: 1023px) {
  .docs-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }

  .docs-sidebar {
    grid-column: 1;
    grid-row: 2;
    position: static;
    max-height: none;
  }

  .docs-content {
    grid-column: 1;
    grid-row: 3;
  }

  /* Desktop-TOC aus; mobil per Toc-Drawer (rechts) */
  .docs-toc { display: none !important; }
}

/* === DOCS MOBILE TOC FLYOUT (RIGHT) ===================================== */
@media (max-width: 1023px){
  .toc-handle{
    position: fixed;
    right: 10px; top: 45%;
    transform: translateY(-50%);
    width: 42px; height: 42px;
    display: grid; place-items:center;
    border-radius: 10px;
    background: rgba(0,0,0,.55);
    color: #fff; backdrop-filter: blur(6px);
    z-index: 980;
    cursor: pointer;
  }

  .toc-flyout{
    position: fixed; top:0; right:0; height:100dvh; width: min(82vw, 320px);
    background:#fff; border-left:1px solid var(--line);
    box-shadow: -2px 0 22px rgba(0,0,0,.12);
    transform: translateX(100%); transition: transform .25s ease;
    z-index: 996; display:grid; grid-template-rows: auto 1fr;
  }
  .toc-flyout.is-active{ transform: translateX(0); }

  .toc-flyout-head{
    display:flex; align-items:center; justify-content:space-between; gap:10px;
    padding:12px 14px; border-bottom:1px solid var(--line);
  }
  .toc-flyout-body{ overflow:auto; padding: 12px; }

  .toc-list{ list-style:none; margin:0; padding:0; }
  .toc-link{
    display:block; padding:10px 12px; border-radius:10px;
    color: var(--muted); border-left: 2px solid transparent;
  }
  .toc-link:hover{ background: rgba(11,67,101,.06); color: var(--secondary); border-left-color: var(--secondary); }
  .toc-link.active{ background: rgba(88,199,218,.08); color: var(--primary); border-left-color: var(--primary); font-weight:600; }

  /* Overlay wiederverwenden */
  .menu-overlay.toc { z-index: 992; } /* optional separater Layer */
}

/* Docs-Menü-Icon (oben rechts mobil) – nur zeigen, wenn Header schmal */
@media (max-width: 900px){
  .docs-menu-toggle{ display:inline-flex; }
}

@media (max-width: 767px) {
  .docs-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .docs-sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--neutral);
    z-index: 1000;
    padding: var(--space-lg);
    box-shadow: 2px 0 16px rgba(0,0,0,0.1);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

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

  .docs-content {
    grid-column: 1;
    grid-row: 2;
    padding: 0 var(--space-md);
  }
}

/* Sidebar Navigation */
.sidebar-nav { padding: var(--space-lg); }

.sidebar-nav h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: var(--space-lg);
  color: var(--fg);
}

/* Desktop: klassisch */
@media (min-width: 1024px) {
  .nav-group { margin-bottom: var(--space-xl); }
  .nav-group-title {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: var(--space-sm);
  }
}

/* Mobile: Accordion */
@media (max-width: 1023px) {
  .nav-group {
    margin-bottom: var(--space-md);
    border: 1px solid rgba(11,67,101,.15);
    border-radius: 10px;
    overflow: hidden;
  }
  .nav-group-title {
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--fg);
    text-transform: none;
    letter-spacing: 0;
    margin: 0;
    padding: var(--space-md) var(--space-lg);
    background: var(--card);
    border-bottom: 1px solid rgba(11,67,101,.15);
    cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    transition: background .2s ease;
  }
  .nav-group-title::after {
    content: '▸';
    font-size: 16px; line-height: 1;
    transition: transform .2s ease;
    color: var(--muted);
  }
  .nav-group.is-open .nav-group-title::after { transform: rotate(90deg); }
}

.nav-list { list-style: none; padding: 0; margin: 0; background: var(--neutral); }

@media (max-width: 1023px) {
  .nav-list { display: none; }
  .nav-group.is-open .nav-list {
    display: block;
    border-top: 1px solid rgba(11,67,101,.08);
  }
  .nav-item { margin: 0; border-bottom: 1px solid rgba(11,67,101,.06); }
  .nav-item:last-child { border-bottom: 0; }
}

.nav-item { margin-bottom: 2px; }

.nav-link {
  display: block;
  padding: var(--space-sm) var(--space-lg);
  text-decoration: none;
  color: var(--muted);
  font-size: var(--fs-sm);
  transition: background .15s ease, color .15s ease, border-color .15s ease;
  border: 1px solid transparent;
  position: relative;
}

.nav-link:hover { background: rgba(11,67,101,.06); color: var(--secondary); }

.nav-link.active {
  background: rgba(88,199,218,.1);
  color: var(--primary);
  border-color: rgba(88,199,218,.3);
  font-weight: 500;
}

.nav-link.active:hover {
  background: rgba(155, 199, 35, 0.15);
}

/* Table of Contents */
.toc-container {
  padding: var(--space-lg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toc-title {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-md);
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin-bottom: 4px;
}

.toc-link {
  display: block;
  padding: 4px 8px;
  border-radius: 4px;
  text-decoration: none;
  color: var(--muted);
  font-size: var(--fs-sm);
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
}

.toc-link:hover {
  background: rgba(11, 67, 101, 0.04);
  color: var(--secondary);
  border-left-color: var(--secondary);
}

.toc-link.active {
  background: rgba(155, 199, 35, 0.08);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 500;
}

.toc-h2 {
  padding-left: 8px;
}

.toc-h3 {
  padding-left: 16px;
  font-size: 13px;
}

/* Content Styles */
.docs-content h1 {
  font-size: var(--fs-3xl);
  font-weight: 700;
  margin-bottom: var(--space-md);
  line-height: 1.2;
  color: var(--fg);
}

.docs-content h2 {
  font-size: var(--fs-2xl);
  font-weight: 600;
  margin-top: var(--space-2xl);
  margin-bottom: var(--space-md);
  line-height: 1.3;
  color: var(--fg);
  scroll-margin-top: 100px;
}

.docs-content h3 {
  font-size: var(--fs-xl);
  font-weight: 600;
  margin-top: var(--space-xl);
  margin-bottom: var(--space-sm);
  line-height: 1.4;
  color: var(--fg);
  scroll-margin-top: 100px;
}

.docs-content p {
  margin-bottom: var(--space-lg);
  line-height: 1.6;
  color: var(--muted);
}

.docs-content ul,
.docs-content ol {
  margin-bottom: var(--space-lg);
  padding-left: var(--space-xl);
}

.docs-content li {
  margin-bottom: var(--space-xs);
  line-height: 1.6;
  color: var(--muted);
}

/* Hero section for docs home */
.docs-hero {
  text-align: center;
  padding: var(--space-2xl) 0;
  margin-bottom: var(--space-2xl);
}

.docs-hero h1 {
  font-size: 3.5rem;
  font-weight: 700;
  margin-bottom: var(--space-md);
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.docs-hero p {
  font-size: var(--fs-lg);
  color: var(--muted);
  max-width: 600px;
  margin: 0 auto var(--space-xl);
}

/* Cards for docs sections */
.docs-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-2xl);
}

.docs-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-lg);
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
}

.docs-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  border-color: rgba(155, 199, 35, 0.2);
}

.docs-card h3 {
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: var(--space-sm);
  color: var(--fg);
}

.docs-card p {
  color: var(--muted);
  margin-bottom: var(--space-md);
}

.docs-card-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.15s ease;
}

.docs-card-link:hover {
  color: var(--secondary);
}

/* External links */
.external-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--secondary);
  text-decoration: none;
  transition: all 0.15s ease;
}

.external-link:hover {
  color: var(--primary);
}

.external-link::after {
  content: '';
  width: 12px;
  height: 12px;
  background: currentColor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3Cpolyline points='15,3 21,3 21,9'/%3E%3Cline x1='10' y1='14' x2='21' y2='3'/%3E%3C/svg%3E") no-repeat center;
  mask-size: contain;
  display: inline-block;
}

/* Callouts */
.callout {
  border-left: 4px solid var(--primary);
  background: rgba(155, 199, 35, 0.05);
  padding: var(--space-md);
  margin: var(--space-lg) 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.callout.warn {
  border-left-color: #f4a261;
  background: rgba(244, 162, 97, 0.05);
}

.callout.success {
  border-left-color: #2a9d8f;
  background: rgba(42, 157, 143, 0.05);
}

.callout.error {
  border-left-color: #e63946;
  background: rgba(230, 57, 70, 0.05);
}

/* Code blocks */
.code-block {
  background: rgba(11, 67, 101, 0.05);
  border: 1px solid rgba(11, 67, 101, 0.1);
  border-radius: var(--radius);
  padding: var(--space-md);
  margin: var(--space-lg) 0;
  font-family: ui-monospace, 'Monaco', monospace;
  font-size: var(--fs-sm);
  overflow-x: auto;
  white-space: pre-wrap;
}

/* Breadcrumbs */
.breadcrumbs {
  margin-bottom: var(--space-lg);
  font-size: var(--fs-sm);
}

.breadcrumbs ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}

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

.breadcrumbs li:not(:last-child)::after {
  content: '/';
  margin-left: var(--space-xs);
  color: var(--line);
}

.breadcrumbs a {
  color: var(--secondary);
  text-decoration: none;
}

.breadcrumbs a:hover {
  text-decoration: underline;
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 1001;
  background: var(--neutral);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-sm);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-toggle:hover {
  background: rgba(11, 67, 101, 0.06);
}

@media (max-width: 767px) {
  .sidebar-toggle {
    display: block;
  }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

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

/* Placeholder content styling */
.placeholder-content {
  background: rgba(155, 199, 35, 0.05);
  border: 1px solid rgba(155, 199, 35, 0.2);
  border-radius: var(--radius);
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
  text-align: center;
}

.placeholder-content p {
  color: var(--primary);
  font-weight: 500;
  margin: 0;
}

/* ==== mobile-only, docs-only ==== */
@media (max-width: 900px), (hover: none) and (pointer: coarse) {
  body.page-docs .menu-overlay,
  body.page-docs .toc-flyout {
    position: fixed; inset: 0 auto 0 0; /* wird per JS geöffnet/geschlossen */
  }

  /* Dubletten weg: blauer schwebender Burger etc. */
  body.page-docs .fab-menu,
  body.page-docs .docs-fab,
  body.page-docs .floating-burger,
  body.page-docs .blue-burger,
  body.page-docs .toc-handle-legacy { display: none !important; }

  /* Ein einheitlicher TOC-Button rechts (Listensymbol) */
  body.page-docs .toc-toggle {
    position: fixed; right: 12px; bottom: 24px; z-index: 980;
    width: 44px; height: 44px; display: grid; place-items: center;
    border: 0; border-radius: 10px; cursor: pointer;
    background: rgba(0,0,0,.55); color: #fff; backdrop-filter: blur(3px);
    font: inherit;
  }
  body.page-docs .toc-toggle::before { content: "≡"; font-size: 20px; }

  /* TOC-Flyout rechts */
  body.page-docs .toc-flyout {
    right: 0; width: min(82vw, 320px); height: 100dvh;
    background: #fff; border-left: 1px solid var(--line);
    box-shadow: -2px 0 22px rgba(0,0,0,.12);
    transform: translateX(100%); transition: transform .25s ease; z-index: 996;
    display: grid; grid-template-rows: auto 1fr auto; /* unten: socials */
  }
  body.page-docs .toc-flyout.is-active { transform: translateX(0); }

  body.page-docs .menu-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    z-index: 990; opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.page-docs .menu-overlay.is-active { opacity: 1; pointer-events: auto; }

  /* TOC-List + Active-State (Kapitel einfärben) */
  body.page-docs .toc-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; }
  body.page-docs .toc-link {
    display: block; padding: 10px 12px; border-radius: 10px;
    color: var(--muted); border-left: 2px solid transparent; text-decoration: none;
  }
  body.page-docs .toc-link:hover {
    background: rgba(11,67,101,.06); color: var(--secondary);
    border-left-color: var(--secondary);
  }
  body.page-docs .toc-link.active {
    background: rgba(88,199,218,.08); color: var(--primary);
    border-left-color: var(--primary);
  }

  /* Social-Logos zentriert – IN der Docs-Navigation/Flyout, NICHT im Site-Footer */
  body.page-docs .toc-socials {
    display: flex; justify-content: center; gap: 12px;
    padding: 10px; border-top: 1px solid var(--line);
  }
  body.page-docs .toc-socials a {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border: 1px solid var(--line);
    border-radius: 10px; text-decoration: none; color: var(--fg);
  }
  /* evtl. vorhandene Textlabels verbergen */
  body.page-docs .toc-socials .label { display: none !important; }
}

/* Focus styles for accessibility */
.nav-link:focus-visible,
.docs-card-link:focus-visible,
.external-link:focus-visible,
.toc-link:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Print styles */
@media print {
  .docs-sidebar,
  .docs-toc,
  .sidebar-toggle,
  .skip-to-content {
    display: none !important;
  }

  .docs-layout {
    display: block !important;
  }

  .docs-content {
    max-width: none !important;
    padding: 0 !important;
  }
}

/* === DOCS: MOBILE & DESKTOP RESTORE (append-only) ========================= */

/* 0) Gemeinsame Sticky-Top-Variable (falls Headerhöhe variiert) */
:root { --docs-sticky-top: 80px; }

/* 1) Verhindere horizontales Scrollen & Nested-Scroll-Fallen */
html, body { overflow-x: hidden; }
.docs-layout, .docs-content { overflow: visible; } /* Seite scrollt als Ganzes */

/* 2) Desktop-TOC wieder einschalten (rechts) auf großen Screens */
@media (min-width: 1280px) {
  .docs-layout {
    grid-template-columns: 280px 1fr 260px; /* Sidebar | Content | TOC */
  }
  .docs-toc {
    display: block;
    position: sticky;
    top: var(--docs-sticky-top);
    max-height: calc(100vh - (var(--docs-sticky-top) + 20px));
    overflow-y: auto;
  }
}

/* 3) Sticky-Sidebar/TOC: Safe-Area berücksichtigen */
@supports (padding-top: env(safe-area-inset-top)) {
  .docs-sidebar,
  .docs-toc {
    top: calc(var(--docs-sticky-top) + env(safe-area-inset-top));
  }
}

/* 4) Anker-Heading Offsets für Sticky-Header (mobil enger) */
@media (max-width: 767px) {
  .docs-content h2,
  .docs-content h3 {
    scroll-margin-top: 72px; /* war 100px */
  }
}

/* 5) MOBILE: Off-Canvas Sidebar + Overlay + Scroll-Lock */
@media (max-width: 767px) {
  /* Toggle-Button ist bereits definiert; nur Cosmetik */
  .sidebar-toggle { top: 16px; left: 16px; }

  /* Sidebar-Basis bereits vorhanden; wir ergänzen nur Details */
  .docs-sidebar {
    will-change: transform;
    -webkit-overflow-scrolling: touch;
  }

  /* Wenn offen: Body nicht scrollen */
  body.docs-sidebar-open {
    overflow: hidden;
    touch-action: none;
  }

  /* Overlay sicht-/unsichtbar: Klassenzustand ergänzt */
  .sidebar-overlay { transition: opacity .25s ease; }
  .sidebar-overlay.active { display:block; opacity:1; }

  /* Content innen etwas enger, damit nichts klebt */
  .docs-content { padding: 0 var(--space-md); }
}

/* 6) Karten/Grid in Docs robust halten */
@media (max-width: 767px) {
  .docs-cards { grid-template-columns: 1fr; }
}

/* 7) Codeblöcke & Tabellen: horizontales Scrolling statt Layoutsprung */
.code-block { overflow-x: auto; }
.docs-content table { display: block; width: 100%; overflow-x: auto; }

/* 8) Kleine Typo-/Spacing-Optimierungen mobil */
@media (max-width: 767px) {
  .docs-hero { padding: var(--space-xl) 0; margin-bottom: var(--space-xl); }
  .docs-hero h1 { font-size: 2rem; }
  .docs-hero p { font-size: var(--fs-base); }
}

/* ==== DOCS: MOBILE OFF-CANVAS + ICON FIX (append-only) ================== */

/* A) Header-Menü: Icons auf Mobil NICHT verstecken */
@media (max-width: 1023px) {
  header nav .btn .icon,
  header nav .btn img.icon,
  header nav .btn svg.icon {
    display: inline-block !important;
    width: 18px; height: 18px;
    margin-right: 8px;
    vertical-align: -2px;
  }
}

/* B) Docs-Sidebar (links) – Off-Canvas mobil fixen */
@media (max-width: 767px) {
  .docs-sidebar {
    display: block;               /* sicherstellen, dass vorhanden */
    position: fixed;
    top: 0; left: 0;
    width: min(86vw, 320px);
    height: 100vh;
    background: var(--neutral);
    z-index: 1002;
    padding: var(--space-lg);
    box-shadow: 2px 0 16px rgba(0,0,0,0.18);
    transform: translateX(-100%);
    transition: transform 0.28s ease;
  }
  .docs-sidebar.open { transform: translateX(0); }

  /* Toggle-Button sichtbarer + über allem */
  .sidebar-toggle {
    display: inline-flex;
    align-items: center; justify-content: center;
    position: fixed;
    top: 14px; left: 14px;
    width: 42px; height: 42px;
    z-index: 1003;
    background: rgba(255,255,255,0.95);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  }

  /* Overlay */
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.48);
    z-index: 1001;
    opacity: 0;
    transition: opacity .25s ease;
  }
  .sidebar-overlay.active { display: block; opacity: 1; }

  /* Body scroll lock, wenn Sidebar offen */
  body.docs-sidebar-open { overflow: hidden; touch-action: none; }
}

/* C) TOC – Off-Canvas von rechts + Toggle-Button (mobil) + Socials */
@media (max-width: 1023px) {
  /* Verstecke die Desktop-TOC-Spalte vollständig */
  .docs-toc { display: none !important; }

  /* Toggle-Button (rechts, halbtransparent) */
  .toc-toggle {
    position: fixed;
    right: 10px; top: 50%;
    transform: translateY(-50%);
    z-index: 1003;
    width: 44px; height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.45);
    color: #fff;
    border: 0; border-radius: 22px;
    backdrop-filter: blur(3px);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
    -webkit-tap-highlight-color: transparent;
    font: inherit;
  }
  .toc-toggle::before { content: "≡"; font-size: 20px; }

  /* Drawer selbst (mit Socials unten) */
  .toc-drawer {
    position: fixed;
    top: 0; right: 0;
    width: min(86vw, 320px);
    height: 100vh;
    z-index: 1002;
    background: var(--neutral);
    box-shadow: -2px 0 16px rgba(0,0,0,0.18);
    transform: translateX(100%);
    transition: transform .28s ease;
    display: grid;
    grid-template-rows: auto 1fr auto; /* header, toc-body, socials */
  }
  .toc-drawer.open { transform: translateX(0); }

  .toc-drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
  }
  .toc-drawer-title { font-weight: 600; font-size: var(--fs-base); color: var(--fg); }
  .toc-drawer-close {
    width: 36px; height: 36px;
    display: inline-flex; align-items:center; justify-content:center;
    border-radius: 18px; border: 1px solid var(--line);
    background: rgba(255,255,255,0.96);
    font-size: 18px; cursor: pointer;
  }

  .toc-drawer-body {
    overflow-y: auto;
    padding: 8px 6px 14px 6px;
  }
  .toc-drawer-body .toc-list { padding: 0 8px; }

  /* Social-Icons unten, zentriert */
  .toc-drawer .toc-socials {
    display: flex; justify-content: center; gap: 12px;
    padding: 10px; border-top: 1px solid var(--line);
  }
  .toc-drawer .toc-socials a {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 10px;
    text-decoration: none; color: var(--fg);
  }
  .toc-drawer .toc-socials .label { display: none !important; }

  /* Overlay */
  .toc-overlay {
    position: fixed; inset: 0;
    z-index: 1001;
    background: rgba(0,0,0,0.48);
    opacity: 0; display: none;
    transition: opacity .25s ease;
  }
  .toc-overlay.active { display: block; opacity: 1; }

  /* Body scroll lock, wenn Drawer offen */
  body.toc-open { overflow: hidden; touch-action: none; }
}

/* D) TOC-Links mobile – ein bisschen kompakter */
@media (max-width: 1023px) {
  .toc-link { padding: 6px 8px; border-left-width: 3px; }
  .toc-h2 { padding-left: 6px; }
  .toc-h3 { padding-left: 14px; font-size: 13px; }
}

/* E) Sicherheit: keine horizontale Scroll-Hölle */
html, body { overflow-x: hidden; }

/* Docs: linke Sidebar mobil über TOC/Overlays legen */
@media (max-width: 1023px){
  .docs-sidebar { z-index: 1202 !important; position: fixed; }      /* über .toc-overlay (1200) & .toc-drawer (1201) */
  .sidebar-overlay { z-index: 1201 !important; }   /* knapp darunter, damit Klick zum Schließen geht */
  /* Schutz: Overlay klickbar nur zum Schließen, Sidebar bleibt klickbar */
  .sidebar-overlay.active { pointer-events: auto; }
  .sidebar-overlay { pointer-events: none; } /* nur aktiv klickt */
}

/* DOCS: Overlays/Drawer sicher über dem Header */
@media (max-width: 1023px){
  .toc-drawer, .toc-flyout { z-index: 1200; }
  .toc-overlay, .menu-overlay { z-index: 1199; }
}
@media (max-width: 767px){
  .docs-sidebar { z-index: 1200; }
  .sidebar-overlay { z-index: 1199; }
}

/* Falls oben noch ein altes 'display:none' für .docs-sidebar@<=767px steht,
   hier hart überstimmen um FOUC zu vermeiden */
@media (max-width: 767px){
  .docs-sidebar { display: block !important; }
}

/* TOC-Liste klar scope'n, damit Desktop-TOC nicht Mobile-TOC überschreibt */
.docs-toc > .toc-list { display: block; }
/* === PATCH: DOCS TOC/GRID/OVERLAYS – APPEND ONLY ========================= */

/* 1) Grid-Überlauf verhindern: Content-Spalte darf schrumpfen */
.docs-layout { grid-template-columns: 280px minmax(0,1fr); }
@media (min-width: 1280px) {
  .docs-layout { grid-template-columns: 280px minmax(0,1fr) 260px; }
}

/* 2) Desktop-TOC nur zeigen, wenn befüllt (modern) */
@supports selector(.docs-toc:has(.toc-list)) {
  .docs-toc:has(.toc-list:empty),
  .docs-toc:has(.toc-list:not(:has(li))) { display: none !important; }
}
/* 2b) Fallback: per [hidden] oder .is-empty vom JS setzbar */
.docs-toc[hidden],
.docs-toc.is-empty { display: none !important; }

/* 3) Safety: TOC/Sidebar kleben sauber, überlappen Header nicht */
.docs-toc { position: sticky; top: var(--docs-sticky-top); }
.docs-sidebar { position: sticky; top: var(--docs-sticky-top); }

/* 4) Layer-Ordnung für Mobile-Drawer/Overlays deutlich über Header */
/* Layer-Ordnung FINAL (damit die Sidebar oben bleibt) */
@media (max-width:1023px){
  .toc-drawer, .toc-flyout { z-index: 1200; }
  .toc-overlay, .menu-overlay { z-index: 1199; }
  .docs-sidebar { z-index: 1202 !important; }
  .sidebar-overlay { z-index: 1201 !important; }
}

/* Final overlay safety */
.toc-overlay:not(.active),
.menu-overlay:not(.is-active) {
  pointer-events: none !important;
}

/* 5) Mobile: Desktop-TOC wirklich komplett weg (kein Deckkraft-Schatten etc.) */
@media (max-width: 1023px){
  .docs-toc { display: none !important; visibility: hidden !important; }
}

/* 6) Legacy/Floating Burger endgültig killen (alle Varianten) */
.fab-menu,
.docs-fab,
.floating-burger,
.blue-burger,
.toc-handle-legacy { display: none !important; }

/* 7) Kleinere Robustheits-Fixes */
.docs-toc { min-width: 0; }
.docs-content { overflow: visible; }
.code-block { overflow-x: auto; }

/* 8) Mobile TOC-Links: kompakter + bessere Hit-Area (bleibt konsistent) */
@media (max-width: 1023px){
  .toc-link { padding: 8px 10px; border-left-width: 3px; }
  .toc-h2 { padding-left: 6px; }
  .toc-h3 { padding-left: 14px; font-size: 13px; }
}

/* 9) Optional: TOC-Box ausblenden, wenn keine Liste gerendert wurde */
.docs-toc > .toc-list { display: block; }
.docs-toc > .toc-list:empty { display: none; }

/* 10) Fix content overflow - ensure code blocks and math expressions break properly */
.code-block, .docs-content pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre;
  word-break: break-all;
  word-wrap: break-word;
  hyphens: auto;
}

/* Handle long math expressions and subscripts */
.docs-content sub,
.docs-content sup,
.docs-content .math {
  word-break: break-word;
  white-space: normal;
}

/* Prevent horizontal overflow in content area */
.docs-content {
  overflow-x: hidden;
  word-wrap: break-word;
}

/* Ensure grid columns respect content constraints */
@media (min-width: 1280px) {
  .docs-layout {
    grid-template-columns: 280px minmax(0, 1fr) 260px;
    max-width: 100vw;
    overflow-x: hidden;
  }
  .docs-content {
    max-width: 100%;
    overflow-x: hidden;
  }
  .docs-toc {
    min-width: 260px;
    max-width: 260px;
  }
}
/* === DOCS HOTFIX: unify mobile TOC to .toc-drawer only =================== */
@media (max-width:1023px){
  /* 1) Legacy komplett kappen */
  .toc-flyout,
  .menu-overlay.toc { display:none !important; }

  /* 2) Toggle: genau EIN Button zulassen */
  .toc-toggle ~ .toc-toggle { display:none !important; }

  /* 3) Toggle-Position konsistent (rechts, Mitte); aber nicht über HUD */
  .toc-toggle{
    position:fixed; right:10px; top:50%; transform:translateY(-50%);
    z-index:1200; width:44px; height:44px; border:0; border-radius:12px;
    background:rgba(0,0,0,.55); color:#fff; backdrop-filter:blur(6px);
  }
  .toc-toggle::before{ content:"≡"; font-size:20px; }

  /* 4) Drawer + Overlay: nur die .toc-drawer Variante aktiv */
  .toc-drawer{
    position:fixed; top:0; right:0; height:100dvh; width:min(82vw,320px);
    background:#fff; border-left:1px solid var(--line);
    box-shadow:-2px 0 22px rgba(0,0,0,.12);
    transform:translateX(100%); transition:transform .25s ease;
    z-index:1201; display:grid; grid-template-rows:auto 1fr auto;
  }
  .toc-drawer.open{ transform:translateX(0); }

  .toc-overlay{
    position:fixed; inset:0; z-index:1200; background:rgba(0,0,0,.45);
    opacity:0; pointer-events:none; transition:opacity .2s ease;
  }
  .toc-overlay.active{ opacity:1; pointer-events:auto; }

  /* 5) Docs-Sidebar mobil: kein FOUC zwischen hide/show */
  .docs-sidebar{ transform:translateX(-100%); }
  .docs-sidebar.open{ transform:translateX(0); }
}

/* === DOCS HOTFIX: kill legacy sidebar toggles completely on mobile ======= */
@media (max-width:1023px){
  .sidebar-toggle{ display:none !important; } /* wir nutzen das zentrale mobile Menü */
}
