/* ═══════════════════════════════════════════════════════════════════════════
   Global Layout
   ══════════════════════════════════════════════════════════════════════════ */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  background: #0c0c0e;
  color: #e5e5e5;
  line-height: 1.6;
}

body.sidebar-open {
  overflow: hidden;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #0a0a0a;
}

::-webkit-scrollbar-thumb {
  background: #27272a;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #3f3f46;
}

.sidebar-scroll::-webkit-scrollbar-track {
  background: #131316;
}

/* Three-column layout: sidebar | content | toc */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Left Sidebar
   ══════════════════════════════════════════════════════════════════════════ */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100vh;
  background: #131316;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  width: 42px;
  height: 42px;
  border: 1px solid #27272a;
  border-radius: 10px;
  background: rgba(17, 17, 17, 0.95);
  color: #fafafa;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 130;
}

.sidebar-overlay {
  display: none;
}

.sidebar-logo {
  padding: 20px 16px 16px;
  border-bottom: 1px solid #27272a;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}

.sidebar-logo img {
  width: 100%;
  max-width: 100px;
  height: auto;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 12px 12px;
}

/* Sidebar navigation */
.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar li {
  margin: 2px 0;
}

.sidebar a {
  display: block;
  padding: 6px 10px;
  color: #a1a1aa;
  text-decoration: none;
  font-size: 14px;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.sidebar a:hover {
  color: #e5e5e5;
  background: #18181b;
}

.sidebar a.active {
  color: #60a5fa;
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.1), rgba(139, 92, 246, 0.1));
  padding-left: 8px;
  font-weight: 600;
}

/* Section titles (NOT clickable - SpaceBot style) */
.sidebar .section-title {
  color: #71717a;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 16px 0 8px 0;
  margin-top: 8px;
  user-select: none;
  margin-left: 10px;
}

.sidebar .section-title:first-child {
  margin-top: 0;
  padding-top: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Sidebar Footer (GitHub Icon)
   ══════════════════════════════════════════════════════════════════════════ */

.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid #27272a;
  padding: 16px;
  background: #131316;
  display: flex;
  align-items: center;
}

.github-icon {
  color: #a1a1aa;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.github-icon:hover {
  color: #e5e5e5;
  background: #18181b;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Main Content
   ══════════════════════════════════════════════════════════════════════════ */

main {
  flex: 1;
  margin-left: 260px;
  /* ALWAYS reserve space for TOC + gap */
  margin-right: calc(240px + 40px);
  padding: 40px 60px;
  max-width: 1200px;
  box-sizing: border-box;
}

/* Force TOC to actually hide and adjust main */
@media (max-width: 1400px) {
  .toc {
    display: none !important;
  }
  main {
    margin-right: 60px;
  }
}

@media (max-width: 1280px) {
  main {
    margin-right: 40px;
  }
}

@media (max-width: 900px) {
  .sidebar {
    width: 220px;
  }
  main {
    margin-left: 220px;
    margin-right: 30px;
    padding: 30px;
  }
}

@media (max-width: 640px) {
  .sidebar-toggle {
    display: inline-flex;
  }
  .sidebar {
    width: min(82vw, 280px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.45);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 95;
  }
  .sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }
  main {
    margin-left: 0;
    margin-right: 0;
    padding: 72px 20px 20px;
  }
}

main h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin: 0 0 1rem 0;
  color: #fafafa;
  letter-spacing: -0.02em;
}

main h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 2.5rem 0 1rem 0;
  color: #fafafa;
  padding-top: 1rem;
  border-top: 1px solid #27272a;
}

main h3 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 2rem 0 0.75rem 0;
  color: #e5e5e5;
}

main h4 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem 0;
  color: #d4d4d8;
}

main p {
  margin: 0 0 1rem 0;
  color: #d4d4d8;
  font-size: 1rem;
  line-height: 1.75;
}

main ul, main ol {
  margin: 0 0 1rem 0;
  padding-left: 1.5rem;
  color: #d4d4d8;
}

main li {
  margin: 0.25rem 0;
}

main a {
  color: #60a5fa;
  text-decoration: none;
  transition: color 0.15s ease;
}

main a:hover {
  color: #93c5fd;
  text-decoration: underline;
}

main code {
  background: rgba(96, 165, 250, 0.19);
  color: #60a5fa;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
}

main pre {
  position: relative;
  background: #131316;
  border: 1px solid #212227;
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 1.5rem 0;
}

main pre code {
  background: transparent;
  color: #e5e5e5;
  padding: 0;
  border-radius: 0;
  font-size: 0.875rem;
  line-height: 1.7;
}

main blockquote {
  border-left: 4px solid #8b5cf6;
  background: rgba(139, 92, 246, 0.1);
  border-radius: 6px;
  padding: 12px 16px;
  margin: 1.5rem 0;
  color: #e5e5e5;
}

main blockquote p {
  margin: 0;
  color: #d4d4d8;
}

main table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9375rem;
}

main th, main td {
  border: 1px solid #27272a;
  padding: 10px 14px;
  text-align: left;
}

main th {
  background: #18181b;
  color: #fafafa;
  font-weight: 600;
}

main tr:nth-child(even) {
  background: #0f0f0f;
}

main hr {
  border: none;
  border-top: 1px solid #27272a;
  margin: 2.5rem 0;
}

.doc-home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 1.5rem 0 2rem;
}

.doc-home-actions a {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid #27272a;
  border-radius: 8px;
  background: #111;
  text-decoration: none;
}

.doc-home-actions a:hover {
  text-decoration: none;
  border-color: #3f3f46;
  background: #18181b;
}

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

.doc-section {
  background: #111;
  border: 1px solid #212227;
  border-radius: 12px;
  padding: 18px 20px;
}

.doc-section h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem 0;
  padding-top: 0;
  border-top: none;
}

.doc-section ul {
  margin: 0;
  padding-left: 1rem;
}

.doc-section li {
  margin: 0.4rem 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Right Sidebar: "On this page" navigation
   ══════════════════════════════════════════════════════════════════════════ */

.toc {
  position: fixed;
  top: 0;
  right: 0;
  width: 240px;
  height: 100vh;
  background: #0c0c0e;
  padding: 40px 40px 0 0;
  overflow-y: auto;
  z-index: 90;
}

.toc-title {
  font-size: 13px;
  font-weight: 700;
  color: #fafafa;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
  display: inline-flex;
  align-items: center;
}

.toc-title svg {
  width: 18px;
  height: 18px;
  margin-right: 8px;
}

.toc-nav {
  display: flex;
  flex-direction: column;
  border-left: .5px solid #3f3f46c2;
}

.toc-nav a {
  display: block;
  color: #71717a;
  text-decoration: none;
  font-size: 13px;
  padding: 6px 10px;
  border-left: 2px solid transparent;
  transition: all 0.15s ease;
  line-height: 1.4;
}

.toc-nav a:hover {
  color: #a1a1aa;
  border-left-color: #3f3f46;
}

.toc-nav a.active {
  color: #60a5fa;
  border-left-color: #60a5fa;
  background: rgba(96, 165, 250, 0.05);
  font-weight: 500;
}

/* h2 links (indented) */
.toc-nav a[data-level="2"] {
  font-size: 12px;
}

.toc-nav a[data-level="3"] {
  font-size: 12px;
  padding-left: 18px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Code Block: Copy Button
   ══════════════════════════════════════════════════════════════════════════ */

.copy-button {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #27272a;
  border: 1px solid #3f3f46;
  border-radius: 6px;
  padding: 6px 6px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

pre:hover .copy-button {
  opacity: 1;
}

.copy-button:hover {
  background: #3f3f46;
  border-color: #52525b;
}

.copy-button.copied {
  background: #10b981;
  border-color: #10b981;
}

.copy-button svg {
  width: 16px;
  height: 16px;
  stroke: #a1a1aa;
  transition: stroke 0.2s ease;
}

.copy-button.copied svg {
  stroke: #fff;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Syntax Highlighting Tokens
   ══════════════════════════════════════════════════════════════════════════ */

.token-comment    { color: #6a9955; font-style: italic; }
.token-string     { color: #ce9178; }
.token-keyword    { color: #c586c0; font-weight: 500; }
.token-function   { color: #dcdcaa; }
.token-number     { color: #b5cea8; }
.token-boolean    { color: #569cd6; }
.token-property   { color: #9cdcfe; }

/* ═══════════════════════════════════════════════════════════════════════════
   Responsive: Hide TOC on smaller screens
   ══════════════════════════════════════════════════════════════════════════ */

/* ════════════════════════════════════════════════════════════════════════════
   Previous / Next Navigation
   ════════════════════════════════════════════════════════════════════════════ */

.page-navigation {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid #27272a;
}

.nav-button {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  background: #111;
  border: 1px solid #27272a;
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.2s ease;
  min-height: 80px;
}

.nav-button:hover:not(.disabled) {
  background: #18181b;
  border-color: #3f3f46;
  transform: translateY(-2px);
  text-decoration: none;
}

.nav-button.prev {
  align-items: flex-start;
  text-align: left;
}

.nav-button.next {
  align-items: flex-end;
  text-align: right;
}

.nav-button.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.nav-label {
  font-size: 12px;
  color: #71717a;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.nav-title {
  font-size: 16px;
  font-weight: 600;
  color: #e5e5e5;
}

.nav-button:hover:not(.disabled) .nav-title {
  color: #60a5fa;
}

@media (max-width: 640px) {
  .page-navigation {
    flex-direction: column;
  }
  .nav-button.prev,
  .nav-button.next {
    align-items: flex-start;
    text-align: left;
  }
}
