/* ===== CSS Variables ===== */
:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-hover: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-bg: #eff6ff;
  --border: #e2e8f0;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #0f172a;
    --bg-subtle: #1e293b;
    --bg-hover: #334155;
    --text: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --primary: #60a5fa;
    --primary-hover: #3b82f6;
    --primary-bg: rgba(59, 130, 246, 0.2);
    --border: #334155;
    --success: #34d399;
    --success-bg: rgba(16, 185, 129, 0.2);
    --warning: #fbbf24;
    --warning-bg: rgba(245, 158, 11, 0.2);
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  }
}
html.dark {
  --bg: #0f172a;
  --bg-subtle: #1e293b;
  --bg-hover: #334155;
  --text: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --primary: #60a5fa;
  --primary-hover: #3b82f6;
  --primary-bg: rgba(59, 130, 246, 0.2);
  --border: #334155;
  --success: #34d399;
  --success-bg: rgba(16, 185, 129, 0.2);
  --warning: #fbbf24;
  --warning-bg: rgba(245, 158, 11, 0.2);
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}

/* ===== Base ===== */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'SF Pro Display',
    'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover { color: var(--primary-hover); }
.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}
.page-wide { max-width: 1200px; }
@media (max-width: 768px) {
  .page { padding: 24px 16px 64px; }
}

/* ===== Breadcrumb ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }

/* ===== Endpoint Header ===== */
.endpoint-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.method-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--success-bg);
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  margin-right: 12px;
  font-family: ui-monospace, monospace;
}
.method-badge-get {
  background: var(--primary-bg);
  color: var(--primary);
}
.method-badge-ws {
  background: var(--warning-bg);
  color: var(--warning);
}
.endpoint-path {
  font-size: 15px;
  color: var(--text-secondary);
  font-family: ui-monospace, monospace;
}
.endpoint-path span {
  color: var(--border);
  margin: 0 2px;
}
h1 {
  margin: 16px 0 8px;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.025em;
}
.subtitle {
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.6;
}

/* ===== Section ===== */
.section { margin-top: 40px; }
.section-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 16px;
  color: var(--text);
}
.section-desc {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

/* ===== Code Block ===== */
.code-block {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.03);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
@media (prefers-color-scheme: dark) {
  .code-header { background: rgba(255, 255, 255, 0.03); }
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    'Liberation Mono', 'Courier New', monospace;
  font-size: 13px;
}
pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
}
pre code {
  color: var(--text);
  line-height: 1.6;
}
.code-content {
  background: rgba(15, 23, 42, 0.05);
  margin: 0 16px 16px;
  border-radius: 8px;
}
@media (prefers-color-scheme: dark) {
  .code-content { background: rgba(0, 0, 0, 0.3); }
}

/* ===== Inline Code ===== */
:not(pre) > code {
  background: rgba(15, 23, 42, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :not(pre) > code { background: rgba(255, 255, 255, 0.1); }
}

/* ===== Table ===== */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 16px 0;
  background: var(--bg);
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}
th {
  background: var(--bg-subtle);
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}
th:last-child { border-right: none; }
td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: top;
  line-height: 1.5;
}
td:last-child { border-right: none; }
tr:last-child td { border-bottom: none; }
tr:nth-child(even) td { background: rgba(15, 23, 42, 0.02); }
@media (prefers-color-scheme: dark) {
  tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }
}
tr:hover td { background: var(--bg-hover); }
.required { color: var(--success); font-weight: 500; }
.optional { color: var(--text-muted); }

/* ===== Status Codes ===== */
.status-200 { color: var(--success); }
.status-400 { color: var(--warning); }

/* ===== Alert / Info Box ===== */
.alert {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 24px 0;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.alert-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--primary);
}
.alert-icon-warn { color: var(--warning); }
.alert-content {
  flex: 1;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.info-box {
  background: var(--primary-bg);
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 16px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Doc Meta ===== */
.doc-meta-section {
  margin-top: 32px;
}

.doc-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.doc-meta-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: var(--bg-subtle);
}

.doc-meta-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.doc-meta-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.doc-meta-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
}

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

.doc-toc-section {
  margin-top: 20px;
}

.doc-toc-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.doc-toc-link {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 12px;
  text-decoration: none;
}

.doc-toc-link:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.doc-pager-section {
  margin-top: 28px;
}

.doc-pager-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.doc-pager-link {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--bg-subtle);
  text-decoration: none;
}

.doc-pager-link:hover {
  border-color: var(--primary);
  background: var(--bg-hover);
}

.doc-pager-kicker {
  font-size: 12px;
  color: var(--text-muted);
}

.doc-pager-title {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}

.doc-pager-link.is-next {
  text-align: right;
}

/* ===== Realtime Builder ===== */
.realtime-builder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.realtime-preview-card {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
  padding: 12px 14px;
}

.realtime-preview-title {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.realtime-preview-code {
  display: block;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  word-break: break-all;
}

.realtime-preview-pre {
  margin: 0;
  padding: 0;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}

.realtime-flow-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.realtime-flow-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
  padding: 12px 14px;
}

.realtime-flow-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.realtime-flow-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.realtime-flow-desc {
  margin-top: 3px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ===== Endpoint List ===== */
.endpoint-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.endpoint-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.endpoint-method {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: var(--success-bg);
  color: var(--success);
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
}
.endpoint-url {
  font-family: ui-monospace, monospace;
  font-size: 13px;
  color: var(--text);
}

/* ===== Card Grid ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
@media (max-width: 640px) {
  .card-grid { grid-template-columns: 1fr; }
}
.card {
  display: flex;
  flex-direction: column;
  padding: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: all 0.2s ease;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.card-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
  border-radius: 10px;
  margin-bottom: 16px;
  font-size: 20px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}
.card:hover .card-title { color: var(--primary); }
.card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}
.card-arrow {
  margin-top: 12px;
  color: var(--text-muted);
  font-size: 18px;
}
.card:hover .card-arrow { color: var(--primary); }

/* ===== Test Section ===== */
.test-section {
  margin-top: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.test-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}
.test-header:hover { background: var(--bg-hover); }
.test-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.test-header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.test-header-desc {
  font-size: 13px;
  color: var(--text-muted);
}
.test-toggle {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
.test-toggle.expanded { transform: rotate(180deg); }
.test-content {
  display: none;
  padding: 20px;
  background: var(--bg);
}
.test-content.expanded { display: block; }

/* Test Form */
.test-form-group { margin-bottom: 16px; }
.test-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.test-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: ui-monospace, monospace;
  transition: border-color 0.15s ease;
}
.test-input:focus {
  outline: none;
  border-color: var(--primary);
}
.test-textarea {
  min-height: 200px;
  resize: vertical;
  line-height: 1.5;
}

.test-model-selector-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.test-model-select {
  flex: 1;
}

.test-model-refresh {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.test-model-refresh:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.test-model-refresh:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.test-model-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.test-model-hint.is-error {
  color: #ef4444;
}

@media (max-width: 640px) {
  .test-model-selector-row {
    flex-direction: column;
    align-items: stretch;
  }

  .test-model-refresh {
    width: 100%;
  }
}

/* Test Button */
.test-header-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  margin-left: auto;
  margin-right: 12px;
}
.test-header-button:hover { background: var(--primary-hover); }
.test-header-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.test-header-button .method-badge-header {
  font-size: 11px;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  font-weight: 600;
}
.test-button-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Test Subsection */
.test-subsection { margin-bottom: 20px; }
.test-subsection-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.test-subsection-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.test-subsection-toggle {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
.test-subsection-toggle.expanded { transform: rotate(180deg); }
.test-subsection-content { display: none; }
.test-subsection-content.expanded { display: block; }

/* Test Response */
.test-response {
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.test-response-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}
.test-response-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.status-success { color: var(--success); }
.status-error { color: #ef4444; }
.test-response-body {
  padding: 16px;
  background: rgba(15, 23, 42, 0.03);
  max-height: 400px;
  overflow: auto;
}
@media (prefers-color-scheme: dark) {
  .test-response-body { background: rgba(255, 255, 255, 0.03); }
}
.test-response-body pre {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Test Tabs */
.test-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
.test-tab {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.test-tab:hover { background: var(--bg-hover); }
.test-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== TOC Sidebar (auto-generated) ===== */
.docs-layout {
  display: flex;
  gap: 40px;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
}
.toc-sidebar {
  flex-shrink: 0;
  width: 200px;
  position: sticky;
  top: 24px;
  align-self: flex-start;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
}
.toc-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 12px 12px;
  margin: 0;
}
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.toc-item {
  margin: 2px 0;
}
.toc-link {
  display: block;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
}
.toc-link:hover {
  color: var(--primary);
  background: var(--bg-subtle);
}
.toc-link.active {
  color: var(--primary);
  background: var(--primary-bg);
  border-left-color: var(--primary);
  font-weight: 600;
}
@media (max-width: 1024px) {
  .toc-sidebar { display: none; }
  .docs-layout { gap: 0; }
}

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