/* ═══════════════════════════════════════════
   SPGG Tech Docs — Premium Dark Theme
   ═══════════════════════════════════════════ */

/* ─── CSS Variables ─── */
:root {
  --bg-primary: #0a0d14;
  --bg-secondary: #0f1219;
  --bg-tertiary: #151a24;
  --bg-card: #141922;
  --bg-code: #1a1f2e;
  --bg-hover: rgba(99, 102, 241, 0.08);
  --bg-active: rgba(99, 102, 241, 0.12);

  --text-primary: #e4e8f1;
  --text-secondary: #8b92a5;
  --text-muted: #5a6177;
  --text-link: #818cf8;
  --text-link-hover: #a5b4fc;

  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --cyan: #22d3ee;
  --cyan-glow: rgba(34, 211, 238, 0.15);
  --green: #34d399;
  --red: #f43f5e;
  --orange: #fb923c;
  --yellow: #fbbf24;

  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);

  --sidebar-width: 280px;
  --toc-width: 220px;
  --navbar-height: 56px;
  --content-max: 840px;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  font-size: 15px;
  overflow-x: hidden;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--transition);
}

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

::selection {
  background: var(--accent-glow);
  color: var(--text-primary);
}

/* ─── Navbar ─── */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--navbar-height);
  background: rgba(10, 13, 20, 0.85);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}

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

.navbar-center {
  flex: 1;
  max-width: 480px;
  margin: 0 24px;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.sidebar-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
}

.brand-icon {
  font-size: 20px;
}

.brand-text {
  letter-spacing: -0.5px;
}

.brand-sub {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 14px;
  padding-left: 4px;
  border-left: 1px solid var(--border-light);
  margin-left: 4px;
}

.version-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-light);
  background: var(--accent-glow);
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

/* ─── Search ─── */
.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 12px;
  transition: all var(--transition);
}

.search-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 10px;
  width: 100%;
}

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

.search-kbd {
  font-family: var(--font-sans);
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  flex-shrink: 0;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 110;
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: capitalize;
}

.search-result-snippet {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Layout ─── */
.layout {
  display: flex;
  margin-top: var(--navbar-height);
  min-height: calc(100vh - var(--navbar-height));
}

/* ─── Sidebar ─── */
.sidebar {
  position: fixed;
  top: var(--navbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 0;
  z-index: 50;
  transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar {
  width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

/* Sidebar items */
.sidebar-group {
  margin-bottom: 4px;
}

.sidebar-group-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition);
}

.sidebar-group-title:hover {
  color: var(--text-secondary);
}

.sidebar-group-title .chevron {
  transition: transform var(--transition);
  font-size: 10px;
}

.sidebar-group-title.collapsed .chevron {
  transform: rotate(-90deg);
}

.sidebar-group-items {
  padding: 0;
}

.sidebar-group-title.collapsed+.sidebar-group-items {
  display: none;
}

.sidebar-link {
  display: block;
  padding: 6px 20px 6px 28px;
  font-size: 13px;
  color: var(--text-secondary);
  border-left: 2px solid transparent;
  transition: all var(--transition);
  cursor: pointer;
}

.sidebar-link:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.sidebar-link.active {
  color: var(--accent-light);
  border-left-color: var(--accent);
  background: var(--bg-active);
  font-weight: 500;
}

/* ─── Content ─── */
.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  margin-right: var(--toc-width);
  padding: 32px 48px 80px;
  max-width: calc(100% - var(--sidebar-width) - var(--toc-width));
  min-height: calc(100vh - var(--navbar-height));
}

.doc-content {
  max-width: var(--content-max);
  margin: 0 auto;
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─── TOC ─── */
.toc {
  position: fixed;
  top: var(--navbar-height);
  right: 0;
  bottom: 0;
  width: var(--toc-width);
  padding: 24px 16px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
}

.toc-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.toc-link {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  padding: 3px 0 3px 0;
  border-left: 2px solid transparent;
  padding-left: 10px;
  transition: all var(--transition);
  line-height: 1.5;
}

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

.toc-link.active {
  color: var(--accent-light);
  border-left-color: var(--accent);
}

.toc-link.toc-h3 {
  padding-left: 22px;
  font-size: 11.5px;
}

.toc-link.toc-h4 {
  padding-left: 34px;
  font-size: 11px;
}

/* ─── Loading ─── */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  color: var(--text-muted);
  gap: 16px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ═══════════════════════════════════════════
   Typography & Content Styles
   ═══════════════════════════════════════════ */

.doc-content h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  margin-bottom: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.doc-content h1 .header-anchor {
  display: none;
}

.doc-content h2 {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.doc-content h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
}

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

.header-anchor {
  float: left;
  margin-left: -20px;
  padding-right: 4px;
  font-size: 0.85em;
  opacity: 0;
  color: var(--accent);
  text-decoration: none;
  transition: opacity var(--transition);
}

h2:hover .header-anchor,
h3:hover .header-anchor,
h4:hover .header-anchor {
  opacity: 1;
}

.doc-content p {
  margin-bottom: 16px;
}

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

.doc-content li {
  margin-bottom: 4px;
}

.doc-content li::marker {
  color: var(--text-muted);
}

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

.doc-content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-code);
  color: var(--cyan);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.doc-content pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 20px;
  overflow-x: auto;
  position: relative;
}

.doc-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Copy button */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition);
}

pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ─── Tables ─── */
.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 13.5px;
}

.doc-content thead th {
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border-light);
}

.doc-content tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.doc-content tbody tr:hover {
  background: var(--bg-hover);
}

.doc-content tbody td code {
  font-size: 12px;
  white-space: nowrap;
}

/* ─── Blockquote ─── */
.doc-content blockquote {
  border-left: 3px solid var(--accent);
  margin: 0 0 16px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

/* ─── Alerts ─── */
.alert {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 20px;
  border-left: 4px solid;
}

.alert-title {
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 14px;
}

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

.alert-note {
  background: rgba(99, 102, 241, 0.08);
  border-color: var(--accent);
}

.alert-note .alert-title {
  color: var(--accent-light);
}

.alert-tip {
  background: rgba(34, 211, 238, 0.08);
  border-color: var(--cyan);
}

.alert-tip .alert-title {
  color: var(--cyan);
}

.alert-important {
  background: rgba(168, 85, 247, 0.08);
  border-color: #a855f7;
}

.alert-important .alert-title {
  color: #c084fc;
}

.alert-warning {
  background: rgba(251, 191, 36, 0.08);
  border-color: var(--yellow);
}

.alert-warning .alert-title {
  color: var(--yellow);
}

.alert-caution {
  background: rgba(244, 63, 94, 0.08);
  border-color: var(--red);
}

.alert-caution .alert-title {
  color: var(--red);
}

/* ─── Badges ─── */
.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  vertical-align: middle;
  margin: 0 2px;
}

.badge-active {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.badge-deprecated {
  background: rgba(244, 63, 94, 0.15);
  color: var(--red);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.badge-internal {
  background: rgba(251, 191, 36, 0.15);
  color: var(--yellow);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.badge-unused-caller {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.badge-fc24 {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-light);
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge-fc25 {
  background: rgba(34, 211, 238, 0.15);
  color: var(--cyan);
  border: 1px solid rgba(34, 211, 238, 0.3);
}

.badge-und {
  background: rgba(251, 146, 60, 0.15);
  color: var(--orange);
  border: 1px solid rgba(251, 146, 60, 0.3);
}

/* ─── HR ─── */
.doc-content hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 32px 0;
}

/* ─── Images ─── */
.doc-content img {
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════
   Syntax Highlighting (GitHub Dark)
   ═══════════════════════════════════════════ */
.hljs-keyword {
  color: #ff7b72;
}

.hljs-string {
  color: #a5d6ff;
}

.hljs-number {
  color: #79c0ff;
}

.hljs-function {
  color: #d2a8ff;
}

.hljs-title {
  color: #d2a8ff;
}

.hljs-params {
  color: #e4e8f1;
}

.hljs-comment {
  color: #5a6177;
  font-style: italic;
}

.hljs-built_in {
  color: #ffa657;
}

.hljs-literal {
  color: #79c0ff;
}

.hljs-attr {
  color: #79c0ff;
}

.hljs-variable {
  color: #ffa657;
}

.hljs-type {
  color: #ff7b72;
}

.hljs-symbol {
  color: #79c0ff;
}

.hljs-meta {
  color: #8b949e;
}

.hljs-selector-tag {
  color: #7ee787;
}

.hljs-selector-class {
  color: #d2a8ff;
}

.hljs-property {
  color: #79c0ff;
}

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

  .content {
    margin-right: 0;
    max-width: calc(100% - var(--sidebar-width));
  }
}

@media (max-width: 768px) {
  .sidebar-toggle {
    display: block;
  }

  .sidebar {
    transform: translateX(-100%);
    z-index: 60;
    width: 280px;
  }

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

  .sidebar-overlay.active {
    display: block;
    z-index: 55;
  }

  .content {
    margin-left: 0;
    max-width: 100%;
    padding: 24px 16px 80px;
  }

  .navbar-center {
    margin: 0 12px;
  }

  .search-kbd {
    display: none;
  }

  .brand-sub {
    display: none;
  }

  .doc-content h1 {
    font-size: 1.5rem;
  }

  .doc-content h2 {
    font-size: 1.2rem;
  }

  .doc-content table {
    font-size: 12px;
  }

  .doc-content thead th,
  .doc-content tbody td {
    padding: 8px 10px;
  }

  .doc-content pre {
    padding: 12px 14px;
  }

  .doc-content pre code {
    font-size: 12px;
  }
}

/* ═══════════════════════════════════════════
   Scrollbar
   ═══════════════════════════════════════════ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ─── Lock Button in Navbar ─── */
.lock-docs-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-right: 8px;
}

.lock-docs-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.lock-docs-btn svg {
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .lock-docs-btn span {
    display: none;
  }
  .lock-docs-btn {
    padding: 6px;
    margin-right: 4px;
  }
}


/* ─── Lock Screen Overlay ─── */
.lock-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  background-image: radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.15), var(--bg-primary));
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  backdrop-filter: blur(8px);
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lock-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.lock-card {
  background: rgba(15, 18, 25, 0.7);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg), 0 0 30px rgba(99, 102, 241, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: lockFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes lockFadeIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.lock-avatar {
  width: 90px;
  height: 90px;
  margin: 0 auto 20px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  overflow: hidden;
  background: var(--bg-tertiary);
}

.lock-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.lock-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.lock-subtitle {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.lock-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lock-input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 12px 16px;
  outline: none;
  transition: all var(--transition);
  text-align: center;
  letter-spacing: 2px;
}

.lock-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.lock-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.lock-btn:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.3);
}

.lock-btn:active {
  transform: translateY(0);
}

.lock-error {
  color: var(--red);
  font-size: 12.5px;
  margin-top: 16px;
  min-height: 18px;
  font-weight: 500;
}