/*
 * Panda-Network Docs - Design-System.
 *
 * Farben, Schatten und Schriften sind 1:1 aus Homepage (src/app/globals.css) und Statusseite
 * (src/web/index.css) uebernommen, damit die drei Seiten wie eine wirken. Dark-only, genau wie
 * dort - es gibt bewusst keine helle Variante.
 */

/* ───────────────────────── Fonts (lokal, kein CDN) ───────────────────────── */

@font-face {
  font-family: "Hanken Grotesk";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/hanken-grotesk-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Hanken Grotesk";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/hanken-grotesk-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Hanken Grotesk";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/hanken-grotesk-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/sora-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Sora";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/sora-latin-700-normal.woff2") format("woff2");
}

/* ───────────────────────── Tokens ───────────────────────── */

:root {
  --background: hsl(222 47% 11%);
  --foreground: hsl(210 40% 98%);
  --card: hsl(223 47% 8%);
  --card-foreground: hsl(210 40% 98%);
  --primary: hsl(204 70% 57%);
  --primary-foreground: hsl(0 0% 100%);
  --secondary: hsl(222 47% 25%);
  --muted: hsl(223 47% 15%);
  --muted-foreground: hsl(217 33% 70%);
  --accent: hsl(168 58% 43%);
  --destructive: hsl(0 70% 50%);
  --border: hsl(223 47% 18%);
  --ring: hsl(204 70% 57%);

  --shadow-xs: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 32px -8px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 24px 48px -12px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 6px 20px -4px hsl(204 70% 57% / 0.35);
  --shadow-glow-sm: 0 2px 10px -2px hsl(204 70% 57% / 0.3);

  /* Lichtkante oben + kuehler Schatten - die Elevation-Formel der beiden Referenzseiten. */
  --surface: inset 0 1px 0 0 rgba(255, 255, 255, 0.05), var(--shadow-md);

  --radius: 0.75rem;
  --radius-sm: 0.5rem;
  --radius-lg: 1rem;

  --font-sans: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-display: "Sora", var(--font-sans);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --header-height: 4rem;
  --sidebar-width: 16rem;
  --toc-width: 13rem;
  --container: 90rem;
}

/* ───────────────────────── Basis ───────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  /* Sprungziele nicht unter den fixierten Header schieben */
  scroll-padding-top: calc(var(--header-height) + 1.5rem);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  letter-spacing: 0.015em;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  text-underline-offset: 2px;
  transition: color 0.2s ease;
}

a:hover {
  color: hsl(204 73% 63%);
}

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

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

.icon {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.75rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

/* ───────────────────────── Header ───────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  border-bottom: 1px solid hsl(223 47% 18% / 0.8);
  background: hsl(222 47% 11% / 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  max-width: var(--container);
  margin: 0 auto;
  height: var(--header-height);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  color: var(--foreground);
}

.brand-logo {
  height: 2.25rem;
  width: auto;
  display: block;
}

.brand-label {
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-link {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted-foreground);
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease, background-color 0.2s ease;
}

.header-link:hover {
  color: var(--foreground);
  background: hsl(223 47% 15% / 0.6);
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  background: var(--card);
  border: 1px solid hsl(223 47% 18% / 0.6);
  border-radius: var(--radius);
  padding: 0.4375rem 0.75rem;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.search-trigger:hover {
  color: var(--foreground);
  border-color: hsl(204 70% 57% / 0.4);
}

.search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  line-height: 1;
  padding: 0.1875rem 0.3125rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: hsl(223 47% 15% / 0.8);
}

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  color: var(--muted-foreground);
  background: transparent;
  border: 1px solid hsl(223 47% 18% / 0.6);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.nav-toggle:hover {
  color: var(--foreground);
  border-color: hsl(204 70% 57% / 0.4);
}

/* ───────────────────────── Layout ───────────────────────── */

.layout {
  flex: 1;
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--toc-width);
  gap: 2.5rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: var(--header-height);
  max-height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: 2rem 0;
}

.content {
  min-width: 0;
  padding: 2rem 0 3rem;
}

/* ───────────────────────── Sidebar-Navigation ───────────────────────── */

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

.nav-item {
  margin: 0;
}

.nav-link {
  display: block;
  padding: 0.375rem 0.75rem;
  margin-bottom: 0.125rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.nav-link:hover {
  color: var(--foreground);
  background: hsl(223 47% 15% / 0.5);
}

.nav-link.is-active {
  color: var(--primary);
  font-weight: 600;
  background: hsl(204 70% 57% / 0.12);
  border-left-color: var(--primary);
}

.nav-depth-1 .nav-link {
  padding-left: 1.5rem;
  font-size: 0.8125rem;
  font-weight: 400;
}

/* ───────────────────────── Inhaltsverzeichnis ───────────────────────── */

.toc {
  position: sticky;
  top: var(--header-height);
  max-height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: 2rem 0;
}

.toc-title {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

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

.toc-link {
  display: block;
  padding: 0.25rem 0 0.25rem 0.75rem;
  margin-left: -1px;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--muted-foreground);
  border-left: 2px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.toc-link:hover,
.toc-link.is-active {
  color: var(--primary);
  border-left-color: var(--primary);
}

.toc-level-3 .toc-link {
  padding-left: 1.5rem;
  font-size: 0.75rem;
}

/* ───────────────────────── Fliesstext ───────────────────────── */

.prose {
  max-width: 52rem;
}

.prose > *:first-child {
  margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--foreground);
  scroll-margin-top: calc(var(--header-height) + 1.5rem);
}

.prose h1 {
  font-size: 2rem;
  margin: 0 0 1.25rem;
}

.prose h2 {
  font-size: 1.5rem;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid hsl(223 47% 18% / 0.6);
}

.prose h3 {
  font-size: 1.1875rem;
  margin: 2rem 0 0.75rem;
}

.prose h4 {
  font-size: 1rem;
  margin: 1.5rem 0 0.5rem;
}

.prose p {
  margin: 0 0 1.2em;
  max-width: 70ch;
}

.prose ul,
.prose ol {
  margin: 0 0 1.2em;
  padding-left: 1.5em;
}

.prose li {
  margin-bottom: 0.5em;
}

.prose li > ul,
.prose li > ol {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

.prose strong {
  font-weight: 600;
  color: var(--foreground);
}

.prose hr {
  height: 1px;
  margin: 2rem 0;
  border: 0;
  background: var(--border);
}

.prose blockquote {
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  border-left: 4px solid hsl(204 70% 57% / 0.6);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: hsl(204 70% 57% / 0.06);
  color: var(--muted-foreground);
}

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

.prose img {
  display: block;
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--surface);
}

.prose table {
  width: 100%;
  margin: 1.5rem 0;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.prose th {
  padding: 0.625rem 0.75rem;
  text-align: left;
  font-weight: 600;
  background: hsl(222 47% 25% / 0.5);
  border-bottom: 1px solid var(--border);
}

.prose td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid hsl(223 47% 18% / 0.6);
}

/* Anker neben Ueberschriften - erst beim Hover sichtbar */
.heading-anchor {
  margin-left: 0.5rem;
  color: var(--muted-foreground);
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease;
}

.prose h1:hover .heading-anchor,
.prose h2:hover .heading-anchor,
.prose h3:hover .heading-anchor,
.prose h4:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

/* ───────────────────────── Code ───────────────────────── */

.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  background: hsl(223 47% 15% / 0.7);
  color: var(--foreground);
}

.prose pre {
  position: relative;
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--surface);
}

.prose pre code {
  display: block;
  padding: 0;
  background: none;
  font-size: 0.875rem;
  line-height: 1.6;
}

.copy-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-family: inherit;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--muted-foreground);
  background: hsl(223 47% 15% / 0.9);
  border: 1px solid hsl(223 47% 18% / 0.8);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.prose pre:hover .copy-button,
.copy-button:focus-visible {
  opacity: 1;
}

.copy-button:hover {
  color: var(--foreground);
  border-color: hsl(204 70% 57% / 0.4);
}

.copy-button.is-done {
  opacity: 1;
  color: var(--accent);
  border-color: hsl(168 58% 43% / 0.5);
}

/* Syntax-Highlighting - eigene Zuordnung auf die Marken-Palette statt eines fremden Themes */
.hljs-comment,
.hljs-quote {
  color: hsl(217 20% 50%);
  font-style: italic;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-doctag,
.hljs-name {
  color: hsl(204 73% 68%);
}
.hljs-string,
.hljs-regexp,
.hljs-addition,
.hljs-attribute,
.hljs-meta .hljs-string {
  color: hsl(168 60% 58%);
}
.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-link {
  color: hsl(38 82% 62%);
}
.hljs-variable,
.hljs-template-variable,
.hljs-attr,
.hljs-selector-attr,
.hljs-selector-pseudo {
  color: hsl(210 40% 90%);
}
.hljs-title,
.hljs-title.function_,
.hljs-title.class_,
.hljs-built_in,
.hljs-type {
  color: hsl(204 73% 78%);
}
.hljs-meta,
.hljs-deletion {
  color: hsl(0 60% 68%);
}
.hljs-emphasis {
  font-style: italic;
}
.hljs-strong {
  font-weight: 600;
}

/* ───────────────────────── Vor/Zurueck ───────────────────────── */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid hsl(223 47% 18% / 0.6);
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.875rem 1.125rem;
  background: var(--card);
  border: 1px solid hsl(223 47% 18% / 0.6);
  border-radius: var(--radius);
  box-shadow: var(--surface);
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.pager-link:hover {
  border-color: hsl(204 70% 57% / 0.4);
  transform: translateY(-2px);
  box-shadow: inset 0 1px 0 0 rgba(255, 255, 255, 0.06), var(--shadow-lg);
}

.pager-next {
  text-align: right;
}

.pager-label {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.pager-title {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--foreground);
}

/* ───────────────────────── Footer ───────────────────────── */

.site-footer {
  margin-top: auto;
  border-top: 1px solid hsl(223 47% 18% / 0.6);
  background: hsl(223 47% 8% / 0.4);
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.footer-inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

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

.footer-links a {
  color: var(--muted-foreground);
}

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

/* ───────────────────────── Suche ───────────────────────── */

.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  justify-content: center;
  padding: 6rem 1rem 1rem;
  background: hsl(222 47% 6% / 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

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

.search-panel {
  width: 100%;
  max-width: 38rem;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid hsl(223 47% 18% / 0.6);
  color: var(--muted-foreground);
}

.search-field input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--foreground);
  background: transparent;
  border: 0;
  outline: none;
}

.search-field input::placeholder {
  color: var(--muted-foreground);
}

.search-field button {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--muted-foreground);
  background: hsl(223 47% 15% / 0.8);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1875rem 0.375rem;
  cursor: pointer;
}

.search-results {
  overflow-y: auto;
  padding: 0.5rem;
}

.search-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.search-hit {
  display: block;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.search-hit:hover,
.search-hit.is-active {
  background: hsl(223 47% 15% / 0.6);
  border-color: hsl(204 70% 57% / 0.4);
}

.search-hit-title {
  display: block;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--foreground);
}

.search-hit-text {
  display: block;
  margin-top: 0.125rem;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted-foreground);
}

.search-hit mark {
  background: hsl(204 70% 57% / 0.25);
  color: var(--foreground);
  border-radius: 2px;
  padding: 0 0.125em;
}

/* ───────────────────────── Responsive ───────────────────────── */

@media (min-width: 640px) {
  .layout,
  .header-inner,
  .footer-inner {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  }

  .toc {
    display: none;
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .nav-toggle {
    display: inline-flex;
  }

  .search-trigger span,
  .search-trigger kbd,
  .header-link {
    display: none;
  }

  .sidebar {
    display: none;
    position: static;
    max-height: none;
    padding: 1rem 0 0;
    border-bottom: 1px solid hsl(223 47% 18% / 0.6);
  }

  .sidebar.is-open {
    display: block;
  }

  .content {
    padding-top: 1.5rem;
  }

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

  .prose h1 {
    font-size: 1.625rem;
  }

  .prose h2 {
    font-size: 1.3125rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
