/* ─── LIGHT THEME (default) ─── */
:root, [data-theme="light"] {
  --primary: #2563EB;
  --primary-light: #EFF6FF;
  --primary-border: #BFDBFE;
  --text: #1E293B;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  --bg: #FFFFFF;
  --bg-surface: #F8FAFC;
  --bg-code: #F1F5F9;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --success: #059669;
  --success-bg: #ECFDF5;
  --purple: #7C3AED;
  --purple-bg: #F5F3FF;
  --teal: #0891B2;
  --teal-bg: #ECFEFF;
  --amber: #D97706;
  --amber-bg: #FFFBEB;
  --red: #DC2626;
  --sidebar-w: 272px;
  --header-h: 56px;
  --radius: 8px;
  --radius-sm: 5px;
  --jk: #0F5499; --js: #0D6E3F; --jn: #B45309; --jb: #7C3AED; --jnl: #94A3B8;
}

/* ─── DARK THEME ─── */
[data-theme="dark"] {
  --primary: #60A5FA;
  --primary-light: #1E293B;
  --primary-border: #334155;
  --text: #E2E8F0;
  --text-muted: #94A3B8;
  --text-light: #64748B;
  --bg: #0F172A;
  --bg-surface: #1E293B;
  --bg-code: #1E293B;
  --border: #334155;
  --border-strong: #475569;
  --success: #34D399;
  --success-bg: #064E3B;
  --purple: #A78BFA;
  --purple-bg: #2E1065;
  --teal: #22D3EE;
  --teal-bg: #164E63;
  --amber: #FBBF24;
  --amber-bg: #78350F;
  --red: #F87171;
  --jk: #93C5FD; --js: #6EE7B7; --jn: #FCD34D; --jb: #C4B5FD; --jnl: #64748B;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; font-size: 15px; }
body { font-family: 'Inter', sans-serif; color: var(--text); background: var(--bg); line-height: 1.6; }

/* ─── HEADER ─── */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h); background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px;
  justify-content: space-between;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-logo-img {
  height: 28px; width: auto;
}
.brand-name { font-weight: 700; font-size: 15px; color: var(--text); }
.brand-sep { color: var(--border-strong); margin: 0 4px; }
.brand-sub { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.version-badge {
  background: var(--primary-light); color: var(--primary);
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; border: 1px solid var(--primary-border);
  letter-spacing: .04em;
}
.header-links { display: flex; align-items: center; gap: 4px; }
.header-link {
  font-size: 13px; color: var(--text-muted); text-decoration: none;
  padding: 5px 10px; border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
}
.header-link:hover { background: var(--bg-surface); color: var(--text); }

/* ─── SIDEBAR ─── */
.sidebar {
  position: fixed; top: var(--header-h); left: 0; bottom: 0;
  width: var(--sidebar-w); background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto; z-index: 90;
  display: flex; flex-direction: column;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.sidebar-search {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-surface); z-index: 1;
}
.sidebar-search input {
  width: 100%; padding: 7px 12px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); outline: none;
  font-family: inherit;
  transition: border-color .15s;
}
.sidebar-search input:focus { border-color: var(--primary); }
.sidebar-search input::placeholder { color: var(--text-light); }

.nav-section { padding: 16px 16px 4px; }
.nav-section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-light);
}
.nav-item {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 16px 6px 20px; font-size: 13px;
  color: var(--text-muted); text-decoration: none;
  border-radius: 0;
  transition: color .15s, background .15s;
  border-left: 2px solid transparent;
  margin-left: -1px;
}
.nav-item:hover { color: var(--text); background: var(--bg); }
.nav-item.active {
  color: var(--primary); background: var(--primary-light);
  border-left-color: var(--primary); font-weight: 500;
}
.nav-num {
  font-size: 10px; font-weight: 600; color: var(--text-light);
  min-width: 18px; text-align: right;
}
.nav-item.active .nav-num { color: var(--primary); }
.nav-badge {
  font-size: 9px; font-weight: 700; padding: 1px 5px;
  border-radius: 3px; text-transform: uppercase; letter-spacing: .04em;
  flex-shrink: 0; margin-left: auto;
}
.nav-badge.cb { background: var(--purple-bg); color: var(--purple); }
.nav-badge.re { background: var(--teal-bg); color: var(--teal); }

/* ─── MAIN CONTENT ─── */
.main-content {
  margin-left: var(--sidebar-w);
  margin-top: var(--header-h);
  min-height: calc(100vh - var(--header-h));
  padding: 0;
}
.content-inner { max-width: 1140px; padding: 48px 48px 80px; }

/* ─── SECTIONS ─── */
.doc-section {
  padding-bottom: 48px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 48px;
}
.doc-section:last-child { border-bottom: none; }

.section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--primary); margin-bottom: 8px;
}
h1.section-title { font-size: 28px; font-weight: 700; margin-bottom: 12px; line-height: 1.3; }
h2.section-title { font-size: 20px; font-weight: 700; margin-bottom: 10px; }
h2.group-heading {
  font-size: 18px; font-weight: 700; margin-bottom: 4px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}
.section-intro { font-size: 15px; color: var(--text-muted); max-width: 860px; line-height: 1.7; }

/* ─── CALLOUTS ─── */
.callout {
  padding: 14px 16px; border-radius: var(--radius);
  border-left: 4px solid; font-size: 13.5px; margin: 16px 0;
}
.callout-info { background: var(--primary-light); border-color: var(--primary); color: #1E40AF; }
.callout-warning { background: var(--amber-bg); border-color: var(--amber); color: #92400E; }
.callout-success { background: var(--success-bg); border-color: var(--success); color: #065F46; }
.callout strong { font-weight: 600; }

/* ─── TABLES ─── */
.doc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 16px 0; }
.doc-table th {
  background: var(--bg-surface); text-align: left;
  padding: 10px 14px; font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
  border-bottom: 2px solid var(--border);
}
.doc-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc-table tr:last-child td { border-bottom: none; }
.doc-table tr:hover td { background: var(--bg-surface); }
.code-inline {
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
  background: var(--bg-code); padding: 2px 6px;
  border-radius: 3px; color: var(--red);
}
.status-ok { color: var(--success); font-weight: 600; }
.status-err { color: var(--red); font-weight: 600; }

/* ─── STEP LIST ─── */
.step-list { display: flex; flex-direction: column; gap: 16px; margin: 20px 0; }
.step {
  display: flex; gap: 16px; padding: 16px 20px;
  background: var(--bg-surface); border-radius: var(--radius);
  border: 1px solid var(--border);
}
.step-num {
  width: 28px; height: 28px; background: var(--primary); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex-shrink: 0;
}
.step-body h4 { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.step-body p { font-size: 13px; color: var(--text-muted); }

/* ─── COMPATIBILITY GRID ─── */
.compat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 20px 0; }
.compat-card {
  padding: 18px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg);
}
.compat-card h4 { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.compat-card p { font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }
.compat-card .compat-badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 3px; margin-bottom: 8px;
  text-transform: uppercase; letter-spacing: .04em;
}
.native { background: #DCFCE7; color: #15803D; }
.hybrid { background: var(--amber-bg); color: var(--amber); }
.partial { background: var(--bg-code); color: var(--text-muted); }

/* ─── CONNECTION MODE TABLE ─── */
.mode-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 2px 7px;
  border-radius: 3px;
}
.mode-full { background: #DCFCE7; color: #15803D; }
.mode-partial { background: var(--amber-bg); color: var(--amber); }
.mode-none { background: #FEE2E2; color: var(--red); }

/* ─── API OPERATION ─── */
.api-operation {
  padding-bottom: 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}
.api-operation:last-child { border-bottom: none; margin-bottom: 0; }

.op-header {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 10px;
}
.op-number {
  font-size: 11px; font-weight: 700; color: var(--text-light);
  background: var(--bg-surface); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 3px; font-family: 'JetBrains Mono', monospace;
}
.op-name {
  font-size: 18px; font-weight: 700; color: var(--text);
}
.op-type-badge {
  font-size: 10px; font-weight: 700; padding: 3px 8px;
  border-radius: 20px; text-transform: uppercase; letter-spacing: .05em;
}
.badge-callback { background: var(--purple-bg); color: var(--purple); border: 1px solid #DDD6FE; }
.badge-restful  { background: var(--teal-bg); color: var(--teal); border: 1px solid #A5F3FC; }
.op-direction {
  font-size: 12px; color: var(--text-muted); font-weight: 500;
  display: flex; align-items: center; gap: 5px;
}
.op-direction .arrow { color: var(--primary); }
.op-desc { font-size: 14px; color: var(--text-muted); margin-bottom: 16px; max-width: 860px; }

/* ─── CODE PANELS ─── */
.code-panels { display: flex; flex-direction: column; gap: 10px; }
.code-panel {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.code-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.code-panel-label {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.code-panel-header.req .code-panel-label { color: var(--purple); }
.code-panel-header.res .code-panel-label { color: var(--success); }
.copy-btn {
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  background: none; border: 1px solid var(--border); padding: 2px 10px;
  border-radius: 4px; cursor: pointer; font-family: inherit;
  transition: all .15s;
}
.copy-btn:hover { background: var(--bg); color: var(--text); border-color: var(--border-strong); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }
pre {
  background: var(--bg-code); padding: 16px 18px; overflow-x: auto;
  font-family: 'JetBrains Mono', monospace; font-size: 12.5px; line-height: 1.7;
}
pre code { background: none; padding: 0; }

/* JSON syntax highlighting - colors defined via CSS vars at bottom */

/* ─── FIELDS GRID ─── */
.fields-grid { display: grid; gap: 8px; margin: 16px 0; }
.field-row {
  display: grid; grid-template-columns: 180px 1fr;
  gap: 12px; padding: 10px 14px;
  background: var(--bg-surface); border-radius: var(--radius-sm);
  border: 1px solid var(--border); font-size: 13px;
}
.field-name { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--primary); font-weight: 500; }
.field-desc { color: var(--text-muted); }
.field-desc strong { color: var(--text); font-weight: 500; }

/* ─── FOOTER ─── */
.site-footer {
  margin-left: var(--sidebar-w);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 28px 48px;
  font-size: 13px; color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  flex-wrap: wrap;
}
.footer-links { display: flex; gap: 16px; }
.footer-links a { color: var(--text-muted); text-decoration: none; }
.footer-links a:hover { color: var(--primary); }

/* ─── RESPONSIVE ─── */
.mob-menu-btn { display: none; }
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-272px); transition: transform .25s; width: 272px; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .site-footer { margin-left: 0; }
  .mob-menu-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: none; cursor: pointer; color: var(--text);
    font-size: 18px; margin-right: 12px;
  }
  .content-inner { padding: 28px 20px 60px; }
  .compat-grid { grid-template-columns: 1fr; }
}

/* ─── COLLAPSIBLE NAV GROUPS ─── */
.nav-collapsible {
  cursor: pointer; display: flex; align-items: center;
  justify-content: space-between; padding-right: 4px;
  user-select: none; transition: color .15s;
}
.nav-collapsible:hover { color: var(--text-muted); }
.nav-chevron {
  font-size: 10px; transition: transform .2s;
  color: var(--text-light); flex-shrink: 0;
}
.nav-collapsible.expanded .nav-chevron { transform: rotate(90deg); }
.nav-group {
  overflow: hidden; transition: max-height .25s ease;
}
.nav-group.collapsed { max-height: 0; }
.nav-group.expanded { max-height: 2000px; }

/* ─── THEME TOGGLE ─── */
.theme-toggle {
  width: 34px; height: 34px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-surface);
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; font-size: 16px; padding: 0;
  transition: all .15s; margin-right: 4px; position: relative;
}
.theme-toggle:hover { border-color: var(--border-strong); background: var(--bg); }
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: inline; }

/* ─── DARK THEME OVERRIDES ─── */
[data-theme="dark"] .callout-info { color: #93C5FD; }
[data-theme="dark"] .callout-warning { color: #FCD34D; }
[data-theme="dark"] .callout-success { color: #6EE7B7; }
[data-theme="dark"] .status-ok { color: var(--success); }
[data-theme="dark"] .status-err { color: var(--red); }
[data-theme="dark"] .code-inline { color: var(--red); background: var(--bg-code); }
[data-theme="dark"] .site-header { box-shadow: 0 1px 3px rgba(0,0,0,0.3); }

/* ─── JSON SYNTAX (themed via vars) ─── */
.jk  { color: var(--jk); font-weight: 500; }
.js  { color: var(--js); }
.jn  { color: var(--jn); }
.jb  { color: var(--jb); }
.jnl { color: var(--jnl); }
.jt  { color: var(--text-light); font-style: italic; }

/* ─── ARCHITECTURE DIAGRAM ─── */
.arch-diagram {
  margin: 24px 0; padding: 32px 24px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow-x: auto;
}
.arch-diagram svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }

/* ─── BACK TO TOP BUTTON ─── */
#backToTop {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  font-size: 18px; cursor: pointer; opacity: 0;
  transform: translateY(16px);
  transition: opacity .25s, transform .25s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
#backToTop.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
#backToTop:hover { background: var(--text); }

/* ─── PRINT STYLESHEET ─── */
@media print {
  .sidebar, .site-header, .mob-menu-btn, .theme-toggle,
  .copy-btn, #backToTop, .sidebar-search, .header-links { display: none !important; }
  .main-content { margin-left: 0 !important; margin-top: 0 !important; }
  .site-footer { margin-left: 0 !important; }
  .content-inner { padding: 0 !important; max-width: 100% !important; }
  body { font-size: 12px; color: #000; background: #fff; }
  .doc-section { page-break-inside: avoid; border-bottom: 1px solid #ccc; }
  .api-operation { page-break-inside: avoid; }
  pre { white-space: pre-wrap; word-wrap: break-word; font-size: 10px; border: 1px solid #ccc; }
  .callout { border-left-width: 3px; }
  a { color: #000; text-decoration: underline; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9px; color: #666; }
}