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

:root {
  --sidebar-width:   260px;
  --onpage-width:    220px;
  --header-height:   56px;
  --pat-bar-height:  0px;

  --sidebar-bg:      rgba(20,50,75,.9);
  --sidebar-border:  rgba(255,255,255,0.08);
  --header-bg:       rgba(20,50,75,.9);
  --header-border:   rgba(255,255,255,0.08);

  --content-bg:      #fafafa;

  --accent:          #2563eb;
  --accent-hover:    #1d4ed8;
  --accent-subtle:   rgba(37,99,235,0.08);

  --text-primary:    #0f172a;
  --text-secondary:  #475569;
  --text-tertiary:   #94a3b8;
  --text-sidebar:    #94a3b8;
  --text-sidebar-active: #f1f5f9;

  --border:          #e2e8f0;
  --border-subtle:   #f1f5f9;
  --code-bg:         #f1f5f9;
  --code-border:     #e2e8f0;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --transition: 150ms cubic-bezier(.4,0,.2,1);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--content-bg);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--header-bg);
  border-bottom: 1px solid var(--header-border);
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr auto;
  align-items: center;
  padding-right: 20px;
  z-index: 100;
}

.header-center {
  display: flex;
  align-items: center;
  padding: 0 24px;
}

.header-left { display: flex; align-items: center; height: 100%; }

.header-logo-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  height: 100%;
  border-right: 1px solid var(--header-border);
  width: var(--sidebar-width);
  text-decoration: none;
}

.logo-img {
  height: 22px;
  width: auto;
  flex-shrink: 0;
}
.logo-sub { font-size: 10px; font-weight: 500; color: rgba(255,255,255,0.45); letter-spacing: 0.04em; text-transform: uppercase; line-height: 1; }

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

.version-badge {
  font-size: 11px; font-weight: 600;
  color: #3b82f6;
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.20);
  border-radius: 20px;
  padding: 3px 10px;
}

/* ─── Search ─────────────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
}

.search-icon {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: #4b5563;
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 32px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  padding: 0 12px 0 32px;
  font-size: 13px;
  color: #e2e8f0;
  font-family: inherit;
  outline: none;
  transition: all var(--transition);
}
.search-input::placeholder { color: #4b5563; }
.search-input:focus {
  background: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.2);
}
.search-input::-webkit-search-cancel-button { display: none; }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: #1a1d2e;
  border: 1px solid #2a2d3e;
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  overflow: hidden;
  z-index: 200;
}

.search-result {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  text-decoration: none;
  border-bottom: 1px solid #2a2d3e;
  transition: background var(--transition);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result:focus {
  background: rgba(37,99,235,0.15);
  outline: none;
}

.search-result-title {
  font-size: 13px;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-title mark {
  background: none;
  color: #60a5fa;
  font-weight: 600;
}

.search-result-section {
  font-size: 11px;
  color: #4b5563;
  white-space: nowrap;
  flex-shrink: 0;
}

.search-empty {
  padding: 12px 14px;
  font-size: 13px;
  color: #4b5563;
}
.search-empty strong { color: #6b7280; }

/* ─── Auth ───────────────────────────────────────────────────────────────── */
.auth-status { display: flex; align-items: center; gap: 8px; }

.auth-btn {
  font-size: 12px; font-weight: 500;
  border-radius: 6px;
  padding: 5px 14px;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.auth-btn--login {
  color: #f1f5f9;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
}
.auth-btn--login:hover {
  background: rgba(255,255,255,0.13);
  border-color: rgba(255,255,255,0.2);
}
.auth-btn--logout {
  color: #94a3b8;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.08);
}
.auth-btn--logout:hover {
  color: #f1f5f9;
  border-color: rgba(255,255,255,0.15);
}
.auth-user-label {
  font-size: 12px; color: #64748b;
}

/* ─── Env badge ──────────────────────────────────────────────────────────── */
.env-badge {
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(251,146,60,0.18);
  color: #fb923c;
  border: 1px solid rgba(251,146,60,0.35);
  text-transform: uppercase;
}

/* ─── PAT toggle button (in header-right) ────────────────────────────────── */
.pat-toggle-btn {
  font-size: 12px; font-weight: 500;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-family: inherit;
}
.pat-toggle-btn:hover {
  background: rgba(255,255,255,0.11);
  border-color: rgba(255,255,255,0.2);
  color: #f1f5f9;
}
.pat-toggle-btn.active,
.pat-toggle-btn.pat-active {
  background: rgba(13,148,136,0.18);
  border-color: rgba(13,148,136,0.4);
  color: #2dd4bf;
}

/* ─── PAT bar (fixed sub-bar below header) ───────────────────────────────── */
.pat-bar {
  position: fixed;
  top: var(--header-height);
  left: 0; right: 0;
  height: 48px;
  z-index: 98;
  background: rgba(15,40,60,0.97);
  border-bottom: 1px solid rgba(13,148,136,0.3);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  padding: 0 20px;
}
.pat-bar[hidden] { display: none; }
body.pat-bar-open { --pat-bar-height: 48px; }

.pat-bar-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* Env toggle */
.pat-bar-env-toggle {
  display: flex;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}
.pat-bar-env-btn {
  font-size: 11px; font-weight: 600;
  padding: 3px 10px;
  background: transparent;
  color: rgba(255,255,255,0.4);
  border: none;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.05em;
  transition: all var(--transition);
}
.pat-bar-env-btn:hover { color: rgba(255,255,255,0.7); }
.pat-bar-env-btn.active[data-env="live"] { background: rgba(13,148,136,0.3); color: #2dd4bf; }
.pat-bar-env-btn.active[data-env="dev"]  { background: rgba(251,146,60,0.22); color: #fb923c; }

/* Divider */
.pat-bar-divider {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.12);
  flex-shrink: 0;
  margin: 0 2px;
}

/* Client ID input — narrower than PAT */
.pat-bar-input-wrap--clientid { flex: 0 0 220px; max-width: 220px; }

.pat-bar-label {
  font-size: 12px; font-weight: 600;
  color: rgba(255,255,255,0.5);
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.pat-bar-input-wrap { flex: 1; max-width: 360px; }

.pat-bar-input {
  width: 100%;
  height: 30px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-md);
  padding: 0 10px;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  color: #e2e8f0;
  outline: none;
  transition: all var(--transition);
}
.pat-bar-input:focus {
  background: rgba(255,255,255,0.10);
  border-color: rgba(13,148,136,0.5);
}
.pat-bar-input:disabled { opacity: 0.7; cursor: default; }
.pat-bar-input::placeholder { color: rgba(255,255,255,0.25); }

/* Mask PAT value without type="password" (avoids password-manager triggers) */
.pat-bar-input--pat:not(:focus):not(.pat-bar-input--show) { -webkit-text-security: disc; }

.pat-bar-btn {
  font-size: 12px; font-weight: 500;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pat-bar-btn--apply {
  background: #0d9488;
  color: white;
  border-color: #0d9488;
}
.pat-bar-btn--apply:hover { background: #0f766e; border-color: #0f766e; }
.pat-bar-btn--clear {
  background: transparent;
  color: rgba(255,255,255,0.5);
  border-color: rgba(255,255,255,0.15);
}
.pat-bar-btn--clear:hover { color: #f1f5f9; border-color: rgba(255,255,255,0.3); }

.pat-active-status {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; color: #2dd4bf; font-weight: 500;
}
.pat-active-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #2dd4bf;
  box-shadow: 0 0 5px #2dd4bf;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  padding-top: calc(var(--header-height) + var(--pat-bar-height));
  min-height: 100vh;
  transition: padding-top var(--transition);
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: calc(var(--header-height) + var(--pat-bar-height)); left: 0; bottom: 0;
  transition: top var(--transition);
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto; overflow-x: hidden;
  z-index: 90;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.sidebar-section { padding: 20px 0 8px; }
.sidebar-section + .sidebar-section { border-top: 1px solid var(--sidebar-border); }

.sidebar-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px 8px;
  cursor: pointer; gap: 8px;
}
.sidebar-section-title {
  font-size: 11px; font-weight: 600;
  color: #6b7280;
  text-transform: uppercase; letter-spacing: 0.06em; line-height: 1;
}
.sidebar-section-header.open .sidebar-section-title { color: #94a3b8; }
.sidebar-section-header svg {
  width: 12px; height: 12px; color: #6b7280;
  transition: transform var(--transition); flex-shrink: 0;
}
.sidebar-section-header.open svg { transform: rotate(90deg); color: #94a3b8; }

.sidebar-item {
  display: flex; align-items: center;
  padding: 5px 16px 5px 22px;
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none; gap: 6px;
}
.sidebar-item:hover { background: rgba(255,255,255,0.035); }
.sidebar-item.active {
  background: rgba(37,99,235,0.12);
  border-left-color: var(--accent);
}

.sidebar-item-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #4b5563;
  flex-shrink: 0;
  transition: background var(--transition);
}
.sidebar-item:hover .sidebar-item-dot { background: #6b7280; }
.sidebar-item.active .sidebar-item-dot { background: var(--accent); }

.sidebar-item-label { font-size: 13px; font-weight: 400; color: var(--text-sidebar); line-height: 1.3; }
.sidebar-item.active .sidebar-item-label { color: var(--text-sidebar-active); font-weight: 500; }

.sidebar-bottom-group {
  padding: 20px 0 8px;
  border-top: 1px solid var(--sidebar-border);
}
.sidebar-static-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px; cursor: pointer;
  transition: all var(--transition); text-decoration: none;
}
.sidebar-static-item:hover { background: rgba(255,255,255,0.03); }
.sidebar-static-icon { width: 14px; height: 14px; color: #6b7280; flex-shrink: 0; }
.sidebar-static-label { font-size: 13px; color: #6b7280; }
.sidebar-static-item:hover .sidebar-static-label { color: #94a3b8; }

/* ─── Content ────────────────────────────────────────────────────────────── */
.content {
  margin-left: var(--sidebar-width);
  flex: 1;
  background: var(--content-bg);
  min-height: calc(100vh - var(--header-height));
}
.content-inner {
  padding: 48px 48px 96px;
}

@media (min-width: 1200px) {
  .content-inner {
    padding-right: calc(var(--onpage-width) + 32px);
  }
}

/* ─── Breadcrumb ─────────────────────────────────────────────────────────── */
.breadcrumb { display: flex; align-items: center; gap: 6px; margin-bottom: 20px; }
.breadcrumb-item { font-size: 12.5px; color: var(--text-tertiary); text-decoration: none; transition: color var(--transition); }
.breadcrumb-item:hover { color: var(--text-secondary); }
.breadcrumb-item.active { color: var(--text-secondary); font-weight: 500; }
.breadcrumb-sep { color: #cbd5e1; font-size: 12px; }

/* ─── Page header ────────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 36px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}
.page-title {
  font-size: 30px; font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.025em; line-height: 1.2;
  margin-bottom: 10px;
}
.page-meta { display: flex; align-items: center; gap: 16px; }
.page-updated {
  font-size: 12px; color: var(--text-tertiary);
  display: flex; align-items: center; gap: 5px;
}
.tag-pill {
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 20px; letter-spacing: 0.02em;
}
.tag-pill.v5 {
  background: rgba(37,99,235,0.08); color: var(--accent);
  border: 1px solid rgba(37,99,235,0.15);
}

/* ─── Prose content (Markdown sections) ─────────────────────────────────── */
.prose-content { margin-bottom: 36px; }

.prose-content h2 {
  font-size: 19px; font-weight: 650;
  color: var(--text-primary);
  letter-spacing: -0.015em;
  margin: 32px 0 14px;
}
.prose-content h2:first-child { margin-top: 0; }

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

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

.prose-content p {
  font-size: 15px; line-height: 1.75; color: #334155;
  margin-bottom: 14px;
}

.prose-content ul {
  list-style: none;
  display: flex; flex-direction: column; gap: 6px;
  margin: 4px 0 20px;
  padding-left: 4px;
  border-left: 2px solid var(--border);
}
.prose-content ul li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 4px 0 4px 16px;
  font-size: 14px; color: var(--text-secondary); line-height: 1.65;
}
.prose-content ul li::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 7px;
}
.prose-content ul li strong { color: var(--text-primary); }

.prose-content a { color: var(--accent); text-decoration: underline; }

.prose-content pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0 18px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.6;
  color: #1e293b;
  white-space: pre;
}
.prose-content pre code {
  background: none; border: none; padding: 0;
  font-size: inherit; color: inherit;
}

.prose-content code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  color: #1e293b;
}

/* ─── Reference section ──────────────────────────────────────────────────── */
.reference-section { margin-top: 8px; }

.reference-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.reference-title {
  font-size: 19px; font-weight: 650;
  color: var(--text-primary); letter-spacing: -0.015em;
}
.live-note {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-tertiary);
  background: white; border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px;
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 2px rgba(16,185,129,0.25);
  animation: pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 2px rgba(16,185,129,0.25); }
  50%       { box-shadow: 0 0 0 4px rgba(16,185,129,0.15); }
}

.loading-message {
  padding: 24px; text-align: center;
  font-size: 14px; color: var(--text-tertiary); font-style: italic;
}
.error-message {
  padding: 16px; background: #fef2f2;
  border: 1px solid #fecaca; border-radius: var(--radius-md);
  color: #dc2626; font-size: 14px;
}

/* ─── Divider ────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 36px 0; }

/* ─── On this page (right TOC) ───────────────────────────────────────────── */
.onpage-nav {
  position: fixed;
  top: calc(var(--header-height) + 40px);
  right: 0;
  width: 200px;
  padding: 0 24px 0 0;
  max-height: calc(100vh - var(--header-height) - 60px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.onpage-nav-title {
  font-size: 11px; font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.onpage-nav-item {
  display: block;
  font-size: 12.5px; line-height: 1.4;
  color: var(--text-tertiary);
  text-decoration: none;
  padding: 3px 0 3px 10px;
  border-left: 2px solid var(--border);
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.onpage-nav-item:hover {
  color: var(--text-secondary);
  border-left-color: #94a3b8;
}

.onpage-nav-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1199px) {
  .onpage-nav { display: none; }
}
@media (max-width: 900px) {
  .content-inner { padding: 32px 24px 64px; }
}
