/* ═══════════════════════════════════════════════════════════════════════════
   TRAIN LIBRE — DEDICATED DOCUMENTATION PORTAL STYLESHEET
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;
  --bg: #070807;
  --bg-soft: #0e100e;
  --panel: #151815;
  --panel-2: #1b1f1b;
  --panel-3: #242924;
  --fg: #f4f6f4;
  --muted: #b0b8b0;
  --quiet: #788278;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.18);
  --accent: #ddff00;
  --accent-ink: #121800;
  --accent-hover: #e6ff33;
  --blue: #85d7f4;
  --green: #66c86d;
  --orange: #ff9b05;
  --red: #f55353;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 16px;
  --max: 1180px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --transition-snappy: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f8faf8;
  --bg-soft: #edf1ed;
  --panel: #ffffff;
  --panel-2: #f2f5f2;
  --panel-3: #e6ebe6;
  --fg: #131713;
  --muted: #4e574e;
  --quiet: #7c887c;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.16);
  --accent: #cae600;
  --accent-ink: #121800;
  --accent-hover: #b8d400;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
}

body.docs-body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ─── Header ──────────────────────────────────────────────────────────── */
.docs-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(7, 8, 7, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

[data-theme="light"] .docs-header {
  background: rgba(248, 250, 248, 0.9);
}

.docs-nav {
  width: min(var(--max, 1180px), calc(100% - 32px));
  height: 72px;
  margin: 0 auto;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--fg);
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #050505;
  border: 1px solid rgba(221, 255, 0, 0.34);
  box-shadow: 0 0 28px rgba(221, 255, 0, 0.16);
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-name {
  display: inline-block;
}

.docs-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  background: var(--line-strong);
  color: var(--accent);
  border-radius: 4px;
  margin-left: 2px;
}

[data-theme="light"] .docs-badge {
  color: #556400;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-s);
  transition: all var(--transition-snappy);
}

.nav-link:hover {
  color: var(--fg);
  background: var(--line);
}

.nav-link.active {
  color: var(--fg);
  background: var(--line);
}

.nav-priority {
  background: var(--accent) !important;
  color: var(--accent-ink) !important;
  padding: 6px 14px !important;
  border-radius: var(--radius-s) !important;
  font-weight: 700 !important;
  text-decoration: none !important;
  font-size: 0.88rem !important;
  transition: opacity var(--transition-snappy);
}

.nav-priority:hover {
  opacity: 0.9;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--fg);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-s);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-snappy);
  padding: 0;
}

.control-btn:hover {
  border-color: var(--line-strong);
  background: var(--panel-2);
}

.control-btn svg {
  width: 18px;
  height: 18px;
}

[data-theme="dark"] .sun-icon { display: block; }
[data-theme="dark"] .moon-icon { display: none; }
[data-theme="light"] .sun-icon { display: none; }
[data-theme="light"] .moon-icon { display: block; }

.mobile-menu-btn {
  display: none;
}

/* ─── 3-Column Layout ─────────────────────────────────────────────────── */
.docs-container {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 240px;
  gap: 40px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  position: relative;
}

/* ─── Left Sidebar ────────────────────────────────────────────────────── */
.docs-sidebar {
  position: sticky;
  top: 92px;
  height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  padding-right: 20px;
}

.sidebar-header-search {
  margin-bottom: 16px;
  flex-shrink: 0;
}

#sidebar-filter {
  width: 100%;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition-snappy);
}

#sidebar-filter:focus {
  border-color: var(--accent);
}

.sidebar-scroll-area {
  overflow-y: auto;
  padding-bottom: 24px;
  scrollbar-width: thin;
}

.sidebar-group {
  margin-bottom: 24px;
}

.sidebar-group-title {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--quiet);
  margin-bottom: 8px;
  padding: 0 8px;
}

.sidebar-nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav-list li {
  margin-bottom: 2px;
}

.sidebar-link {
  display: block;
  padding: 6px 10px;
  border-radius: var(--radius-s);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.86rem;
  line-height: 1.35;
  transition: all var(--transition-snappy);
}

.sidebar-link:hover {
  color: var(--fg);
  background: var(--panel-2);
}

.sidebar-link.active {
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 700;
}

/* ─── Center Article Content ──────────────────────────────────────────── */
.docs-main {
  min-width: 0;
  max-width: 820px;
}

.docs-breadcrumb {
  font-size: 0.84rem;
  color: var(--quiet);
  margin-bottom: 20px;
}

.docs-breadcrumb a {
  color: var(--muted);
  text-decoration: none;
  transition: color var(--transition-snappy);
}

.docs-breadcrumb a:hover {
  color: var(--accent);
}

.bc-sep {
  margin: 0 6px;
  opacity: 0.4;
}

.docs-article {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--fg);
}

.doc-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.22;
  margin: 0 0 24px 0;
  color: var(--fg);
}

.doc-h2 {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  position: relative;
  display: flex;
  align-items: baseline;
}

.doc-h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 32px;
  margin-bottom: 12px;
  position: relative;
  display: flex;
  align-items: baseline;
}

.doc-h4 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 24px;
  margin-bottom: 8px;
}

.header-anchor {
  margin-left: 8px;
  color: var(--quiet);
  text-decoration: none;
  font-weight: normal;
  font-size: 0.8em;
  opacity: 0;
  transition: opacity var(--transition-snappy), color var(--transition-snappy);
}

.doc-h2:hover .header-anchor,
.doc-h3:hover .header-anchor {
  opacity: 0.8;
}

.header-anchor:hover {
  color: var(--accent);
}

.anchor-target {
  position: relative;
  top: -88px;
  display: block;
}

.docs-article p {
  margin: 0 0 18px 0;
}

.docs-article strong {
  font-weight: 700;
  color: var(--fg);
}

.docs-article a:not(.header-anchor) {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(221, 255, 0, 0.45);
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
  font-weight: 600;
  transition: all var(--transition-snappy);
}

.docs-article a:not(.header-anchor):hover {
  color: var(--accent-hover, #e6ff33);
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
}

.docs-article a strong,
.docs-article a em {
  color: inherit;
  font-weight: 700;
}

.docs-article a code {
  color: inherit;
  border-color: rgba(221, 255, 0, 0.35);
  background: rgba(221, 255, 0, 0.08);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(221, 255, 0, 0.45);
  transition: all var(--transition-snappy);
}

.docs-article a:hover code {
  border-color: var(--accent);
  background: rgba(221, 255, 0, 0.16);
  text-decoration-color: var(--accent);
}

[data-theme="light"] .docs-article a:not(.header-anchor) {
  color: #4a5900;
  text-decoration-color: rgba(74, 89, 0, 0.45);
}

[data-theme="light"] .docs-article a:not(.header-anchor):hover {
  color: #2e3800;
  text-decoration-color: #2e3800;
}

[data-theme="light"] .docs-article a code {
  color: inherit;
  border-color: rgba(74, 89, 0, 0.3);
  background: rgba(74, 89, 0, 0.08);
  text-decoration-color: rgba(74, 89, 0, 0.45);
}

[data-theme="light"] .docs-article a:hover code {
  border-color: #4a5900;
  background: rgba(74, 89, 0, 0.15);
  text-decoration-color: #4a5900;
}

.ext-icon {
  display: inline-block;
  font-size: 0.75em;
  vertical-align: middle;
  margin-left: 3px;
  opacity: 0.8;
  transition: transform var(--transition-snappy), opacity var(--transition-snappy);
}

.docs-article a:hover .ext-icon {
  opacity: 1;
  transform: translate(1px, -1px);
}

.doc-list {
  padding-left: 24px;
  margin: 0 0 20px 0;
}

.doc-list li {
  margin-bottom: 6px;
  line-height: 1.65;
}

/* Callouts / Admonitions */
.callout {
  margin: 24px 0;
  padding: 16px 20px;
  background: var(--panel);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-m) var(--radius-m) 0;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.callout-title {
  margin-bottom: 8px;
}

.callout-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--line-strong);
  color: var(--fg);
}

.callout-note {
  border-left-color: var(--blue);
}
.callout-note .callout-badge {
  background: rgba(133, 215, 244, 0.18);
  color: var(--blue);
}

.callout-tip {
  border-left-color: var(--green);
}
.callout-tip .callout-badge {
  background: rgba(102, 200, 109, 0.18);
  color: var(--green);
}

.callout-warning, .callout-caution {
  border-left-color: var(--orange);
}
.callout-warning .callout-badge, .callout-caution .callout-badge {
  background: rgba(255, 155, 5, 0.2);
  color: var(--orange);
}

.callout-body {
  font-size: 0.94rem;
  line-height: 1.6;
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  margin: 28px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--panel);
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  line-height: 1.5;
}

.doc-table th {
  background: var(--panel-2);
  font-weight: 700;
  color: var(--fg);
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-strong);
  text-align: left;
}

.doc-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.doc-table tr:last-child td {
  border-bottom: none;
}

.doc-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .doc-table tr:hover td {
  background: rgba(0, 0, 0, 0.02);
}

/* Code Blocks */
.code-block-wrapper {
  margin: 24px 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-m);
  background: #0d0f0d;
  overflow: hidden;
}

[data-theme="light"] .code-block-wrapper {
  background: #171a17;
}

.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--line);
}

.code-lang {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--quiet);
}

.copy-btn {
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.75rem;
  padding: 3px 8px;
  cursor: pointer;
  transition: all var(--transition-snappy);
}

.copy-btn:hover {
  background: var(--panel-3);
  color: var(--fg);
}

.code-block-wrapper pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.55;
  color: #e4eee4;
}

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

[data-theme="light"] code {
  color: #4a5700;
}

pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
}

/* KaTeX Math Blocks & Formulas */
.math-block {
  margin: 24px 0;
  padding: 20px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  overflow-x: auto;
  text-align: center;
  box-shadow: var(--shadow);
}

.math-inline {
  display: inline-block;
  vertical-align: middle;
}

/* KaTeX MathML Accessibility: hide duplicated MathML text cleanly */
.katex .katex-mathml {
  position: absolute;
  clip: rect(1px, 1px, 1px, 1px);
  padding: 0;
  border: 0;
  height: 1px;
  width: 1px;
  overflow: hidden;
}

.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 40px 0;
}

/* ─── Right Table of Contents ─────────────────────────────────────────── */
.docs-toc {
  position: sticky;
  top: 92px;
  height: calc(100vh - 110px);
  padding-left: 12px;
  overflow-y: auto;
}

.toc-sticky-box {
  border-left: 1px solid var(--line);
  padding-left: 16px;
}

.toc-heading {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--quiet);
  margin-bottom: 12px;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin-bottom: 8px;
}

.toc-item a {
  display: block;
  font-size: 0.82rem;
  color: var(--quiet);
  text-decoration: none;
  line-height: 1.4;
  transition: color var(--transition-snappy);
}

.toc-item a:hover {
  color: var(--fg);
}

.toc-item a.active {
  color: var(--accent);
  font-weight: 600;
}

[data-theme="light"] .toc-item a.active {
  color: #667700;
}

.toc-item-l3 {
  padding-left: 12px;
}

/* ─── Prev / Next Pagination ──────────────────────────────────────────── */
.docs-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.pager-card {
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  text-decoration: none;
  transition: all var(--transition-snappy);
}

.pager-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.pager-prev {
  text-align: left;
}

.pager-next {
  text-align: right;
}

.pager-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--quiet);
  margin-bottom: 4px;
}

.pager-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
}

/* ─── Mermaid Diagrams ────────────────────────────────────────────────── */
.mermaid-container {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 28px 20px;
  margin: 32px 0;
  overflow-x: auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.mermaid {
  margin: 0;
  font-family: var(--font);
  text-align: center;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ─── Responsive Media Queries ────────────────────────────────────────── */
@media (max-width: 1160px) {
  .docs-container {
    grid-template-columns: 260px minmax(0, 1fr);
  }
  .docs-toc {
    display: none;
  }
}

@media (max-width: 820px) {
  .docs-container {
    display: block;
    padding: 20px 16px;
  }

  .docs-sidebar {
    position: fixed;
    top: 72px;
    left: 0;
    width: 280px;
    height: calc(100vh - 72px);
    background: var(--bg);
    border-right: 1px solid var(--line-strong);
    padding: 20px;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
  }

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

  .mobile-menu-btn {
    display: inline-flex;
  }

  .doc-title {
    font-size: 1.8rem;
  }

  .docs-pager {
    grid-template-columns: 1fr;
  }
}
