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

:root {
  --primary: #4f46e5;
  --primary-light: #6366f1;
  --primary-dark: #4338ca;
  --primary-bg: #eef2ff;

  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-code: #1e293b;
  --bg-inline-code: #f1f5f9;

  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-code: #e2e8f0;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --callout-info-bg: #eff6ff;
  --callout-info-border: #3b82f6;
  --callout-warn-bg: #fffbeb;
  --callout-warn-border: #f59e0b;
  --callout-tip-bg: #f0fdf4;
  --callout-tip-border: #22c55e;
  --callout-danger-bg: #fef2f2;
  --callout-danger-border: #ef4444;

  --sidebar-width: 260px;
  --header-height: 56px;
  --content-max: 800px;
  --toc-width: 200px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);

  --radius: 8px;
  --radius-sm: 4px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-code: #0f172a;
  --bg-inline-code: #334155;

  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-code: #e2e8f0;

  --border: #334155;
  --border-strong: #475569;

  --primary-bg: #1e1b4b;

  --callout-info-bg: #1e293b;
  --callout-warn-bg: #1e293b;
  --callout-tip-bg: #1e293b;
  --callout-danger-bg: #1e293b;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Layout ===== */
.app {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.sidebar-header img {
  width: 32px;
  height: 32px;
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-group {
  margin-bottom: 4px;
}

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

.nav-link {
  display: block;
  padding: 6px 20px 6px 24px;
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.15s ease;
}

.nav-link:hover {
  color: var(--text);
  background: var(--border);
}

.nav-link.active {
  color: var(--primary);
  background: var(--primary-bg);
  border-left-color: var(--primary);
  font-weight: 500;
}

.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
}

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

/* ===== Main Content ===== */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 50;
  backdrop-filter: blur(8px);
  background: rgba(255,255,255,0.9);
}

[data-theme="dark"] .header {
  background: rgba(15,23,42,0.9);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text);
}

.hamburger svg {
  width: 24px;
  height: 24px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
}

.breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--primary);
}

.breadcrumb-sep {
  color: var(--border-strong);
}

.breadcrumb-current {
  color: var(--text);
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  min-width: 200px;
}

.search-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.search-btn kbd {
  font-family: var(--font-sans);
  font-size: 11px;
  padding: 1px 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-left: auto;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-secondary);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ===== Content ===== */
.content-wrapper {
  display: flex;
  flex: 1;
}

.content {
  flex: 1;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 32px 40px 80px;
  width: 100%;
}

/* ===== Table of Contents ===== */
.toc {
  position: sticky;
  top: calc(var(--header-height) + 24px);
  width: var(--toc-width);
  max-height: calc(100vh - var(--header-height) - 48px);
  overflow-y: auto;
  padding: 0 24px 24px 0;
  flex-shrink: 0;
  align-self: flex-start;
}

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

.toc a {
  display: block;
  padding: 3px 12px;
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
}

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

.toc a.active {
  color: var(--primary);
  border-left-color: var(--primary);
}

.toc a.toc-h3 {
  padding-left: 24px;
  font-size: 12px;
}

/* ===== Typography ===== */
.content h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 8px;
  color: var(--text);
}

.content .subtitle {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 32px;
  line-height: 1.5;
}

.content h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.content h2:first-of-type {
  margin-top: 32px;
}

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

.content h4 {
  font-size: 16px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--text);
}

.content p {
  margin-bottom: 16px;
  color: var(--text-secondary);
}

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

.content li {
  margin-bottom: 6px;
  color: var(--text-secondary);
}

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

.content a {
  color: var(--primary);
  text-decoration: none;
}

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

.content strong {
  font-weight: 600;
  color: var(--text);
}

.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* ===== Code ===== */
.content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-inline-code);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.code-block {
  position: relative;
  margin-bottom: 20px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-code);
  box-shadow: var(--shadow-sm);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(0,0,0,0.2);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 12px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.copy-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  color: #94a3b8;
  font-size: 12px;
  font-family: var(--font-sans);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.copy-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #e2e8f0;
}

.copy-btn.copied {
  color: #22c55e;
  border-color: #22c55e;
}

.code-block pre {
  padding: 16px;
  overflow-x: auto;
  margin: 0;
}

.code-block code {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-code);
  background: none;
  padding: 0;
  border-radius: 0;
}

/* Syntax highlighting */
.token-keyword { color: #c084fc; }
.token-string { color: #86efac; }
.token-number { color: #fbbf24; }
.token-comment { color: #64748b; font-style: italic; }
.token-function { color: #7dd3fc; }
.token-operator { color: #f472b6; }
.token-property { color: #67e8f9; }
.token-type { color: #fbbf24; }
.token-variable { color: #e2e8f0; }
.token-punctuation { color: #94a3b8; }
.token-method { color: #38bdf8; }
.token-endpoint { color: #86efac; }
.token-http-method { color: #c084fc; font-weight: 600; }
.token-flag { color: #fb923c; }

/* ===== Tables ===== */
.content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.content thead {
  background: var(--bg-secondary);
  position: sticky;
  top: var(--header-height);
}

.content th {
  text-align: left;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.content td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

.content tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}

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

/* ===== Callouts ===== */
.callout {
  padding: 16px 20px;
  border-radius: var(--radius);
  border-left: 4px solid;
  margin-bottom: 20px;
}

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

.callout-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

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

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

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

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

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

.page-nav a {
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: all 0.15s ease;
  flex: 1;
  max-width: 50%;
}

.page-nav a:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.page-nav-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.page-nav-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--primary);
}

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

/* ===== Search Modal ===== */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.search-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.search-modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-height: 400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.98) translateY(-8px);
  transition: transform 0.2s ease;
}

.search-overlay.open .search-modal {
  transform: scale(1) translateY(0);
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}

.search-input-wrapper svg {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: var(--font-sans);
  background: none;
  color: var(--text);
}

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

.search-results {
  overflow-y: auto;
  padding: 8px;
}

.search-result {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: background 0.1s ease;
}

.search-result:hover,
.search-result.selected {
  background: var(--primary-bg);
}

.search-result-title {
  font-size: 14px;
  font-weight: 500;
}

.search-result-section {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.search-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

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

/* ===== Feature Grid ===== */
.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.feature-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

.feature-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.feature-card h4 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 15px;
}

.feature-card p {
  font-size: 14px;
  margin-bottom: 0;
  color: var(--text-muted);
}

/* ===== Steps / Numbered Steps ===== */
.steps {
  counter-reset: step;
  margin-bottom: 24px;
}

.step {
  position: relative;
  padding-left: 40px;
  padding-bottom: 24px;
  border-left: 2px solid var(--border);
  margin-left: 14px;
}

.step:last-child {
  border-left-color: transparent;
  padding-bottom: 0;
}

.step::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: -15px;
  top: 0;
  width: 28px;
  height: 28px;
  background: var(--primary);
  color: white;
  font-size: 13px;
  font-weight: 600;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.step h4 {
  margin-top: 2px;
}

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

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

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

  .main {
    margin-left: 0;
  }

  .hamburger {
    display: flex;
  }

  .search-btn {
    min-width: auto;
  }

  .search-btn span,
  .search-btn kbd {
    display: none;
  }

  .content {
    padding: 24px 20px 60px;
  }

  .content h1 {
    font-size: 26px;
  }

  .content h2 {
    font-size: 20px;
  }

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

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

  .page-nav a {
    max-width: 100%;
  }

  .search-modal {
    width: calc(100vw - 32px);
    margin: 0 16px;
  }

  .content table {
    display: block;
    overflow-x: auto;
  }
}
