/* ── Reset & Variables ──────────────────────────── */

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

:root {
  --bg: #0b0f14;
  --bg-raised: #111820;
  --surface: #151d28;
  --surface-hover: #1a2433;
  --border: #1e2d3d;
  --border-light: #2a3a4d;
  --text: #e1e7ef;
  --text-dim: #8899aa;
  --text-faint: #556677;
  --teal: #4fd1c5;
  --teal-dim: #2c7a7b;
  --teal-glow: rgba(79, 209, 197, 0.12);
  --teal-glow-strong: rgba(79, 209, 197, 0.25);
  --green: #48bb78;
  --green-soft: rgba(72, 187, 120, 0.12);
  --blue: #63b3ed;
  --orange: #ed8936;
  --red: #fc8181;
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-width: 260px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection {
  background: var(--teal-glow-strong);
  color: #fff;
}

/* ── Grain overlay ──────────────────────────────── */

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px;
}

/* ── Nav ─────────────────────────────────────────── */

nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(11, 15, 20, 0.85);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid rgba(30, 45, 61, 0.5);
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 32px;
}

nav .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.5px;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--teal), var(--blue));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--bg);
}

.nav-links {
  display: flex;
  gap: 28px;
  align-items: center;
}

.nav-links a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.2s;
}

.nav-links a:hover { color: var(--text); }
.nav-links a.active { color: var(--teal); }

.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 22px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; text-decoration: none; transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1); border: none; cursor: pointer; font-family: inherit; }
.btn-primary { background: transparent; color: #fff; font-weight: 700; border: 1px solid var(--border-light); box-shadow: none; }
.btn-primary:hover { border-color: #4a5d70; background: rgba(255,255,255,0.05); }

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

.docs-layout {
  display: flex;
  min-height: 100vh;
  padding-top: 64px; /* nav height */
}

/* ── Sidebar ────────────────────────────────────── */

.docs-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 32px 24px;
  position: fixed;
  top: 64px;
  bottom: 0;
  overflow-y: auto;
  background: var(--bg);
}

.sidebar-section {
  margin-bottom: 28px;
}

.sidebar-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-faint);
  margin-bottom: 10px;
  padding: 0 12px;
}

.sidebar-link {
  display: block;
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.sidebar-link:hover {
  color: var(--text);
  background: var(--surface);
}

.sidebar-link.active {
  color: var(--teal);
  background: var(--teal-glow);
}

.sidebar-link.sub {
  padding-left: 28px;
  font-size: 13px;
}

/* ── Content ────────────────────────────────────── */

.docs-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  max-width: 800px;
  padding: 48px 56px 120px;
}

.docs-header {
  margin-bottom: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

.docs-header h1 {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
  margin-bottom: 12px;
}

.docs-lead {
  font-size: 18px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* ── Doc cards (index page) ─────────────────────── */

.docs-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 48px;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.doc-card:hover {
  border-color: var(--teal-dim);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.doc-card-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.doc-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.doc-card p {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* ── Typography ─────────────────────────────────── */

.docs-section {
  margin-bottom: 48px;
}

.docs-section h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 16px;
  padding-top: 8px;
  color: var(--text);
}

.docs-section h2::before {
  content: '';
  display: block;
  width: 32px;
  height: 3px;
  background: var(--teal);
  border-radius: 2px;
  margin-bottom: 12px;
}

.docs-section h3 {
  font-size: 18px;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--text);
}

.docs-section p {
  margin-bottom: 16px;
  color: var(--text);
  font-size: 15px;
}

.docs-section ul, .docs-section ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.docs-section li {
  margin-bottom: 8px;
  font-size: 15px;
  color: var(--text);
}

.docs-section li strong {
  color: var(--text);
}

.docs-section a {
  color: var(--teal);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}

.docs-section a:hover {
  border-bottom-color: var(--teal);
}

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

code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 5px;
  color: var(--teal);
}

pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  overflow-x: auto;
  margin-bottom: 20px;
  line-height: 1.6;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: var(--text-dim);
}

/* ── Tables ─────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  border-bottom: 2px solid var(--border);
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* ── Info boxes ─────────────────────────────────── */

.info-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.info-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 8px 0;
  font-size: 14px;
}

.info-row + .info-row {
  border-top: 1px solid var(--border);
}

.tier {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.tier-read { background: rgba(99, 179, 237, 0.12); color: var(--blue); }
.tier-safe { background: var(--green-soft); color: var(--green); }
.tier-approval { background: rgba(237, 137, 54, 0.12); color: var(--orange); }

/* Source badges */
.source-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.source-local { background: rgba(99, 179, 237, 0.12); color: var(--blue); }
.source-bundled { background: var(--green-soft); color: var(--green); }
.source-fleet { background: rgba(79, 209, 197, 0.12); color: var(--teal); }

/* Callout boxes */
.callout {
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-bottom: 20px;
  font-size: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.callout-icon {
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1.5;
}

.callout-info {
  background: rgba(99, 179, 237, 0.08);
  border: 1px solid rgba(99, 179, 237, 0.2);
}

.callout-tip {
  background: var(--green-soft);
  border: 1px solid rgba(72, 187, 120, 0.2);
}

.callout-warn {
  background: rgba(237, 137, 54, 0.08);
  border: 1px solid rgba(237, 137, 54, 0.2);
}

/* ── Platform grid ──────────────────────────────── */

.platform-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.platform-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
}

.platform-icon { font-size: 28px; margin-bottom: 8px; }
.platform-card strong { display: block; margin-bottom: 4px; }
.platform-note { font-size: 13px; color: var(--text-dim); }

/* ── Precedence diagram ─────────────────────────── */

.precedence-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.precedence-level {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
}

.precedence-rank {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-faint);
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.precedence-info {
  flex: 1;
}

.precedence-info strong {
  display: block;
  margin-bottom: 2px;
}

.precedence-info span {
  font-size: 13px;
  color: var(--text-dim);
}

.precedence-level.top {
  border-color: var(--teal-dim);
  background: rgba(79, 209, 197, 0.05);
}

/* ── Navigation links ───────────────────────────── */

.docs-next {
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.docs-prev-next {
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.next-link, .prev-link {
  text-decoration: none;
  color: var(--text);
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.next-link:hover, .prev-link:hover {
  border-color: var(--teal-dim);
  background: var(--surface);
}

.next-label, .prev-label {
  display: block;
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.next-title, .prev-title {
  font-weight: 600;
  color: var(--teal);
}

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

footer {
  border-top: 1px solid var(--border);
  padding: 32px 0;
  margin-left: var(--sidebar-width);
}

footer p {
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
}

footer a {
  color: var(--text-dim);
  text-decoration: none;
}

footer a:hover { color: var(--text); }

/* ── Frontmatter example block ──────────────────── */

.fm-block {
  position: relative;
}

.fm-block .fm-label {
  position: absolute;
  top: -10px;
  left: 16px;
  background: var(--surface);
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* ── Mobile sidebar toggle ──────────────────────── */

.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 101;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--teal);
  color: var(--bg);
  border: none;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
}

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

@media (max-width: 900px) {
  .docs-sidebar {
    display: none;
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 99;
    background: var(--bg);
    padding: 24px;
  }

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

  .docs-content {
    margin-left: 0;
    padding: 32px 24px 80px;
  }

  footer {
    margin-left: 0;
  }

  .sidebar-toggle {
    display: flex;
  }

  .platform-grid {
    grid-template-columns: 1fr;
  }

  .hide-mobile { display: none; }
}

@media (max-width: 480px) {
  .docs-header h1 { font-size: 28px; }
  .docs-lead { font-size: 16px; }
  .docs-section h2 { font-size: 20px; }
  .info-row { flex-direction: column; gap: 8px; }
  .precedence-level { flex-direction: column; text-align: center; }
}
