/* ========== Variables ========== */
:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #0c1222;
  --bg-code: #0c1222;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --success: #22c55e;
  --warning: #eab308;
  --error: #ef4444;
  --info: #3b82f6;
  --sidebar-w: 240px;
  --toc-w: 200px;
  --content-max: 720px;
  --topbar-h: 52px;
  --bp-tablet: 768px;
  --bp-desktop: 1024px;
}

@media (max-width: 1023px) {
  :root { --toc-w: 0; }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ========== Top Bar ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 24px;
}

.topbar-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}
.topbar-brand:hover { text-decoration: none; color: var(--primary); }

.topbar-links {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar-links a {
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
}
.topbar-links a:hover {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
  text-decoration: none;
}

.topbar-links .btn-primary {
  background: var(--primary);
  color: white !important;
}
.topbar-links .btn-primary:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

/* ========== Layout ========== */
.layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
}

/* ========== Sidebar ========== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  overflow-y: auto;
}

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

.sidebar-group {
  margin-bottom: 16px;
}

.sidebar-group-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 20px 8px;
}

.sidebar-group ul {
  list-style: none;
}

.sidebar-group a {
  display: block;
  margin: 0 12px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text-muted);
  border-radius: 6px;
  border-left: 3px solid transparent;
}
.sidebar-group a:hover {
  color: var(--text);
  background: rgba(99, 102, 241, 0.08);
  text-decoration: none;
}
.sidebar-group a.active {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
  border-left-color: var(--primary);
  font-weight: 500;
}

/* ========== Main Content ========== */
.main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: row;
  padding: 32px 24px 48px;
  gap: 32px;
}

.main-content {
  flex: 1;
  min-width: 0;
  max-width: var(--content-max);
}

/* ========== Right TOC ========== */
.toc-wrap {
  width: var(--toc-w);
  flex-shrink: 0;
  padding: 32px 24px 48px;
}

.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
}

.toc-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.toc-list {
  list-style: none;
  font-size: 13px;
}

.toc-list a {
  display: block;
  padding: 4px 0;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  padding-left: 12px;
  margin-left: -2px;
}
.toc-list a:hover {
  color: var(--primary);
  text-decoration: none;
}
.toc-list a.active {
  color: var(--primary);
  border-left-color: var(--primary);
}

/* ========== Breadcrumb ========== */
.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span { color: var(--text-muted); margin: 0 6px; }

/* ========== Prose ========== */
.prose h1 {
  font-size: 28px;
  font-weight: 700;
  font-size: 28px;
  margin-bottom: 12px;
  color: var(--text);
  border-bottom: none;
}

.prose .lead {
  font-size: 17px;
  color: var(--text-muted);
  margin-bottom: 32px;
  line-height: 1.6;
}

.prose h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 40px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  scroll-margin-top: calc(var(--topbar-h) + 16px);
}

.prose h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 28px 0 12px;
  color: var(--text-muted);
}

.prose h4 {
  font-size: 14px;
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--text-muted);
}

.prose p {
  margin-bottom: 16px;
  color: var(--text-muted);
  max-width: 65ch;
}

.prose ul, .prose ol {
  margin: 16px 0;
  padding-left: 24px;
  color: var(--text-muted);
}

.prose li { margin-bottom: 8px; }

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
  overflow-x: auto;
  display: block;
}

.prose th, .prose td {
  border: 1px solid var(--border);
  padding: 12px 16px;
  text-align: left;
}

.prose th {
  background: var(--bg-card);
  color: var(--text-muted);
  font-weight: 600;
}

.prose td { color: var(--text); }

.prose tr:nth-child(even) td {
  background: rgba(30, 41, 59, 0.4);
}

.code-block {
  position: relative;
  margin: 16px 0;
}

.prose pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
}

.prose pre code {
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  color: var(--text);
}

.prose :not(pre) > code {
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 13px;
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--primary);
}

.code-block .code-block-label {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* ========== Callouts ========== */
.callout {
  padding: 16px 20px;
  border-radius: 8px;
  margin: 20px 0;
  border-left: 4px solid;
}

.callout-note {
  background: rgba(59, 130, 246, 0.1);
  border-color: var(--info);
}
.callout-note .callout-title { color: var(--info); }

.callout-tip {
  background: rgba(34, 197, 94, 0.1);
  border-color: var(--success);
}
.callout-tip .callout-title { color: var(--success); }

.callout-warning {
  background: rgba(234, 179, 8, 0.1);
  border-color: var(--warning);
}
.callout-warning .callout-title { color: var(--warning); }

.callout-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}

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

/* ========== Cards (Home) ========== */
.hero {
  margin-bottom: 40px;
}

.hero h1 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: 18px;
  color: var(--text-muted);
  max-width: 540px;
}

.quick-start {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 40px;
}

.quick-start h3 {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
  color: var(--text);
}

.quick-start ol {
  list-style: none;
  counter-reset: step;
}

.quick-start li {
  counter-increment: step;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.quick-start li::before {
  content: counter(step);
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
}

.section-cards {
  margin: 0 -12px;
}

.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  transition: border-color 0.2s;
}

.section-card:hover {
  border-color: var(--primary);
}

.section-card h3 {
  font-size: 18px;
  color: var(--text);
  margin-bottom: 8px;
}

.section-card p {
  font-size: 14px;
  margin-bottom: 16px;
}

.section-card ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.section-card li {
  margin: 0;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.section-card li:last-child { border-bottom: none; }

.section-card a {
  font-size: 14px;
  font-weight: 500;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
}

.quick-actions a {
  display: inline-flex;
  align-items: center;
  padding: 10px 20px;
  background: var(--primary);
  color: white !important;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.quick-actions a:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

.quick-actions a.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text) !important;
}
.quick-actions a.secondary:hover {
  border-color: var(--primary);
  color: var(--primary) !important;
}

.btn-inline {
  display: inline-flex;
  align-items: center;
  padding: 10px 20px;
  background: var(--primary);
  color: white !important;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.btn-inline:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

/* ========== Prev/Next ========== */
.doc-nav {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.doc-nav a {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.doc-nav a:hover {
  border-color: var(--primary);
  text-decoration: none;
}

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

.doc-nav span {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ========== Footer ========== */
.footer {
  padding: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.footer a { margin: 0 8px; }

/* ========== Mobile Sidebar Toggle ========== */
.sidebar-toggle {
  display: none;
  padding: 8px 12px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* ========== Responsive ========== */
@media (max-width: 1023px) {
  .toc-wrap { display: none; }
}

@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.2s;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  }

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

  .sidebar-toggle {
    display: block;
  }

  .main-wrap {
    padding: 24px 16px 40px;
  }

  .topbar {
    padding: 0 16px;
  }

  .topbar-links {
    gap: 8px;
  }

  .topbar-links a {
    font-size: 12px;
    padding: 6px 10px;
  }

  .section-cards {
    margin: 0;
  }

  .quick-actions {
    flex-direction: column;
  }

  .quick-actions a {
    justify-content: center;
  }

  .doc-nav {
    flex-direction: column;
  }
}

/* ========== Overlay for mobile sidebar ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 85;
}

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

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

@media (min-width: 768px) {
  .sidebar-overlay { display: none !important; }
}
