/* ============================================
   STRATUM PROTOCOL — Documentation Stylesheet
   Version: 1.0.0
   ============================================ */

/* ── CSS Custom Properties ── */
:root {
  --bg-primary: #0A0A0F;
  --bg-sidebar: #0E0E16;
  --bg-content: #12121A;
  --bg-card: #16161F;
  --border: #1E1E2E;
  --border-light: #2A2A3E;
  --purple: #9945FF;
  --purple-dim: rgba(153, 69, 255, 0.15);
  --purple-glow: rgba(153, 69, 255, 0.3);
  --teal: #14F195;
  --teal-dim: rgba(20, 241, 149, 0.15);
  --teal-glow: rgba(20, 241, 149, 0.3);
  --blue: #00C2FF;
  --blue-dim: rgba(0, 194, 255, 0.15);
  --text: #FFFFFF;
  --text-secondary: #8B8B9E;
  --text-muted: #5A5A6E;
  --code-bg: #1A1A28;
  --code-border: #2A2A3E;
  --sidebar-width: 280px;
  --topbar-height: 56px;
  --content-max: 880px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text);
  line-height: 1.7;
  overflow-x: hidden;
  min-height: 100vh;
}

/* ── Custom 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);
}
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

/* ── Reading Progress Bar ── */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--purple), var(--teal));
  z-index: 10000;
  transition: width 80ms linear;
  pointer-events: none;
}

/* ── Top Bar ── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: rgba(10, 10, 15, 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 24px;
  z-index: 1000;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: 0.04em;
}

.topbar-logo .logo-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--purple), var(--teal));
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
}

.topbar-badge {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--purple);
  background: var(--purple-dim);
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

/* Search */
.search-container {
  position: relative;
}

.search-input {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px 7px 36px;
  color: var(--text);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  width: 240px;
  transition: var(--transition-base);
  outline: none;
}
.search-input::placeholder {
  color: var(--text-muted);
}
.search-input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-dim);
  width: 300px;
}
.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.85rem;
  pointer-events: none;
}
.search-shortcut {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.65rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  pointer-events: none;
}

/* Search Results */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  display: none;
  z-index: 2000;
}
.search-results.active {
  display: block;
}
.search-result-item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: var(--transition-fast);
}
.search-result-item:last-child {
  border-bottom: none;
}
.search-result-item:hover {
  background: var(--purple-dim);
}
.search-result-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.search-result-preview {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-preview mark {
  background: var(--purple-dim);
  color: var(--purple);
  border-radius: 2px;
  padding: 0 2px;
}
.search-no-results {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.topbar-link {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  transition: var(--transition-base);
  white-space: nowrap;
}
.topbar-link:hover {
  color: var(--teal);
  border-color: var(--teal);
  background: var(--teal-dim);
}

/* Mobile menu toggle */
.mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

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

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 0;
  z-index: 500;
  transition: transform var(--transition-base);
}

.sidebar-section {
  margin-bottom: 4px;
}

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  user-select: none;
  transition: var(--transition-fast);
}
.sidebar-heading:hover {
  color: var(--text);
}
.sidebar-heading .heading-icon {
  margin-right: 8px;
  font-size: 0.85rem;
}
.sidebar-heading .chevron {
  font-size: 0.6rem;
  transition: transform var(--transition-base);
  color: var(--text-muted);
}
.sidebar-heading.collapsed .chevron {
  transform: rotate(-90deg);
}

.sidebar-links {
  list-style: none;
  overflow: hidden;
  transition: max-height var(--transition-base), opacity var(--transition-base);
  max-height: 500px;
  opacity: 1;
}
.sidebar-links.collapsed {
  max-height: 0;
  opacity: 0;
}

.sidebar-links a {
  display: block;
  padding: 5px 20px 5px 44px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition-fast);
  border-left: 2px solid transparent;
  position: relative;
}
.sidebar-links a:hover {
  color: var(--text-secondary);
  background: rgba(255,255,255,0.02);
}
.sidebar-links a.active {
  color: var(--purple);
  border-left-color: var(--purple);
  background: var(--purple-dim);
  font-weight: 500;
}

/* ── Content Area ── */
.content-area {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  background: var(--bg-content);
}

.content-wrapper {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 40px 48px 80px;
}

/* ── Content Section ── */
.doc-section {
  display: none;
  animation: fadeIn var(--transition-slow) ease;
}
.doc-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Typography ── */
.doc-section h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.doc-section .section-subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
  line-height: 1.6;
}

.doc-section h2 {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
  margin: 40px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}
.doc-section h2:first-of-type {
  margin-top: 0;
}

.doc-section h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin: 28px 0 12px;
}

.doc-section h4 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 20px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.doc-section p {
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.75;
}

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

.doc-section a {
  color: var(--purple);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: var(--transition-fast);
}
.doc-section a:hover {
  border-bottom-color: var(--purple);
}

/* ── Lists ── */
.doc-section ul, .doc-section ol {
  margin: 0 0 16px 0;
  padding-left: 24px;
}
.doc-section li {
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  line-height: 1.7;
}
.doc-section li strong {
  color: var(--text);
}
.doc-section ul li::marker {
  color: var(--purple);
}
.doc-section ol li::marker {
  color: var(--teal);
  font-weight: 600;
}

/* ── Code Blocks ── */
.code-block {
  position: relative;
  margin: 16px 0 24px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--code-border);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(26, 26, 40, 0.8);
  border-bottom: 1px solid var(--code-border);
}
.code-lang {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.code-copy {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-family: var(--font-sans);
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition-fast);
}
.code-copy:hover {
  color: var(--teal);
  border-color: var(--teal);
}
.code-copy.copied {
  color: var(--teal);
  border-color: var(--teal);
}

pre {
  background: var(--code-bg);
  padding: 16px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  color: #c9d1d9;
  margin: 0;
}

code {
  font-family: var(--font-mono);
  font-size: 0.84em;
}

/* Inline code */
p code, li code, td code {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.84em;
  color: var(--purple);
}

/* Syntax Highlighting (manual) */
.token-keyword { color: #c678dd; }
.token-string { color: #98c379; }
.token-number { color: #d19a66; }
.token-comment { color: #5c6370; font-style: italic; }
.token-function { color: #61afef; }
.token-type { color: #e5c07b; }
.token-operator { color: #56b6c2; }
.token-param { color: #e06c75; }
.token-decorator { color: #c678dd; }
.token-const { color: #d19a66; }
.token-punctuation { color: #abb2bf; }
.token-property { color: #e06c75; }
.token-builtin { color: #e5c07b; }

/* ── Tables ── */
.table-wrapper {
  overflow-x: auto;
  margin: 16px 0 24px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead {
  background: var(--bg-card);
}

th {
  text-align: left;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--text);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 16px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(255,255,255,0.015);
}

/* ── Blockquotes / Callouts ── */
blockquote {
  margin: 16px 0 24px;
  padding: 16px 20px;
  border-left: 3px solid var(--purple);
  background: var(--purple-dim);
  border-radius: 0 8px 8px 0;
  font-size: 0.88rem;
  color: var(--text-secondary);
}
blockquote p {
  margin-bottom: 0;
}
blockquote p + p {
  margin-top: 8px;
}

.callout {
  margin: 16px 0 24px;
  padding: 16px 20px;
  border-radius: 10px;
  font-size: 0.88rem;
  border: 1px solid;
}
.callout-title {
  font-weight: 700;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.callout-info {
  background: var(--blue-dim);
  border-color: rgba(0, 194, 255, 0.3);
}
.callout-info .callout-title { color: var(--blue); }
.callout-warning {
  background: rgba(255, 178, 36, 0.1);
  border-color: rgba(255, 178, 36, 0.3);
}
.callout-warning .callout-title { color: #FFB224; }
.callout-success {
  background: var(--teal-dim);
  border-color: rgba(20, 241, 149, 0.3);
}
.callout-success .callout-title { color: var(--teal); }

/* ── Feature Cards / Grids ── */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 20px 0 28px;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  transition: var(--transition-base);
}
.feature-card:hover {
  border-color: var(--purple);
  box-shadow: 0 4px 20px var(--purple-dim);
  transform: translateY(-1px);
}
.feature-card .card-icon {
  font-size: 1.5rem;
  margin-bottom: 10px;
}
.feature-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 6px;
}
.feature-card p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* ── Step Lists ── */
.step-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 24px;
  counter-reset: steps;
}
.step-list li {
  counter-increment: steps;
  padding: 14px 16px 14px 52px;
  position: relative;
  border-left: 2px solid var(--border);
  margin-left: 16px;
  margin-bottom: 4px;
}
.step-list li::before {
  content: counter(steps);
  position: absolute;
  left: -15px;
  top: 14px;
  width: 28px;
  height: 28px;
  background: var(--purple);
  color: #fff;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.step-list li:last-child {
  border-left-color: transparent;
}

/* ── Formula / Math ── */
.formula {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 10px;
  padding: 20px 24px;
  margin: 16px 0 24px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--teal);
  letter-spacing: 0.02em;
}
.formula .formula-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
  font-family: var(--font-sans);
}

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

/* ── Badges / Tags ── */
.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}
.badge-purple { background: var(--purple-dim); color: var(--purple); }
.badge-teal { background: var(--teal-dim); color: var(--teal); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }
.badge-amber { background: rgba(255, 178, 36, 0.15); color: #FFB224; }

/* ── Tier Cards ── */
.tier-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin: 16px 0;
  transition: var(--transition-base);
}
.tier-card:hover {
  border-color: var(--purple);
}
.tier-card .tier-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.tier-card .tier-name {
  font-size: 1.2rem;
  font-weight: 700;
}
.tier-card .tier-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Back to Top ── */
.back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 40px;
  height: 40px;
  background: var(--purple);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: var(--transition-base);
  z-index: 900;
  box-shadow: 0 4px 16px var(--purple-dim);
}
.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.back-to-top:hover {
  background: #a855f7;
  transform: translateY(-2px);
}

/* ── Section Navigation (bottom of section) ── */
.section-nav {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.section-nav a {
  display: flex;
  flex-direction: column;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  transition: var(--transition-base);
  max-width: 48%;
}
.section-nav a:hover {
  border-color: var(--purple);
  box-shadow: 0 4px 16px var(--purple-dim);
}
.section-nav .nav-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.section-nav .nav-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Mobile Overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 450;
}

/* ── ASCII Art ── */
.ascii-diagram {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 10px;
  padding: 20px 24px;
  margin: 16px 0 24px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre;
}

/* ── Print Styles ── */
@media print {
  .topbar, .sidebar, .sidebar-overlay, .back-to-top,
  #reading-progress, .code-copy, .mobile-toggle,
  .search-container, .section-nav { display: none !important; }
  .content-area { margin-left: 0 !important; }
  .content-wrapper { max-width: 100%; padding: 20px; }
  .doc-section { display: block !important; page-break-inside: avoid; }
  body { background: #fff; color: #000; }
  .doc-section h1, .doc-section h2, .doc-section h3 { color: #000; }
  .doc-section p, .doc-section li, .doc-section td { color: #333; }
  pre { border: 1px solid #ddd; }
  table { border: 1px solid #ddd; }
  th, td { border: 1px solid #ddd; }
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .content-wrapper {
    padding: 32px 32px 60px;
  }
}

@media (max-width: 768px) {
  .mobile-toggle {
    display: block;
  }
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,0.4);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.active {
    display: block;
  }
  .content-area {
    margin-left: 0;
  }
  .content-wrapper {
    padding: 24px 20px 60px;
  }
  .topbar {
    padding: 0 16px;
  }
  .search-input {
    width: 160px;
  }
  .search-input:focus {
    width: 200px;
  }
  .topbar-link {
    display: none;
  }
  .feature-grid {
    grid-template-columns: 1fr;
  }
  .doc-section h1 {
    font-size: 1.5rem;
  }
  .section-nav {
    flex-direction: column;
  }
  .section-nav a {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .search-input {
    width: 120px;
  }
  .search-shortcut {
    display: none;
  }
  .topbar-badge {
    display: none;
  }
  .content-wrapper {
    padding: 20px 16px 60px;
  }
}
