/* ── Google Fonts loaded via <link> in layout ──────────────────────── */

/* ── Light theme (default) ─────────────────────────────────────────── */
:root,
[data-theme="light"] {
  --bg:          #f2f6fc;
  --bg-surf:     #ffffff;
  --bg-elev:     #e8f1fb;
  --bg-code:     #1a2540;
  --border:      #b8cfe8;
  --text:        #0a1628;
  --muted:       #466080;
  --accent:      #0077a8;
  --accent-glow: rgba(0, 119, 168, .1);
  --warn-bg:     #fef3c7;
  --warn-border: #d97706;
  --warn-text:   #92400e;
  --code-fg:     #e2ecfc;
  --sidebar-bg:  #ffffff;
  --sidebar-border: #d0e2f4;
}

/* ── Dark theme ─────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:          #0c1220;
  --bg-surf:     #111a2e;
  --bg-elev:     #172138;
  --bg-code:     #0f1828;
  --border:      #253d5e;
  --text:        #d8e8f8;
  --muted:       #8ab4d4;
  --accent:      #00c8e8;
  --accent-glow: rgba(0, 200, 232, .13);
  --warn-bg:     rgba(180, 100, 0, .15);
  --warn-border: #c07800;
  --warn-text:   #f0c060;
  --code-fg:     #d8e8f8;
  --sidebar-bg:  #0d1525;
  --sidebar-border: #1e3050;
}

/* ── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { height: 100%; }

/* ── Base ───────────────────────────────────────────────────────────── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 0.94rem;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* ── Mobile topbar ──────────────────────────────────────────────────── */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
  z-index: 200;
}

.topbar-logo {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-github {
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.topbar-github:hover { color: var(--accent); }

.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.375rem;
  color: var(--text);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.sidebar-toggle:hover { background: var(--bg-elev); }

/* ── Sidebar backdrop ───────────────────────────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.sidebar-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ── Layout ─────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
  width: 252px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 160;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: -0.01em;
}
.sidebar-logo:hover { opacity: 0.85; }

.sidebar-github {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s;
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: 4px;
}
.sidebar-github:hover { color: var(--accent); }

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.nav-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.75rem 0.6rem 0.3rem;
  margin-top: 0.25rem;
}

.nav-section-single {
  margin-bottom: 0.125rem;
}

.nav-section {
  margin-bottom: 0.5rem;
}

.nav-link {
  display: block;
  padding: 0.38rem 0.6rem;
  border-radius: 5px;
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.12s, background 0.12s;
  border-left: 2px solid transparent;
  line-height: 1.4;
}
.nav-link:hover {
  color: var(--text);
  background: var(--accent-glow);
}
.nav-link.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
  font-weight: 500;
}

.nav-sub {
  font-size: 0.84rem;
  padding-left: 0.9rem;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  padding: 0.3rem 0.5rem;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-family: inherit;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.theme-toggle:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-glow);
}

/* Dark mode: show sun (to switch to light) */
[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
/* Light mode: show moon (to switch to dark) */
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: block; }
/* Default fallback before JS runs */
:root:not([data-theme]) .icon-sun  { display: none; }
:root:not([data-theme]) .icon-moon { display: block; }

.theme-label { font-size: 0.78rem; }

.sidebar-version {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
  opacity: 0.7;
}

/* ── Content area ───────────────────────────────────────────────────── */
.content {
  flex: 1;
  margin-left: 252px;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
}

.content-body {
  flex: 1;
  max-width: 860px;
  width: 100%;
  padding: 3rem 3rem 3rem 3.5rem;
  overflow-wrap: break-word;
}

/* ── Footer ─────────────────────────────────────────────────────────── */
.page-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 3.5rem;
  max-width: 860px;
  width: 100%;
}
.page-footer p {
  color: var(--muted);
  font-size: 0.8rem;
}
.page-footer a {
  color: var(--accent);
  text-decoration: none;
}
.page-footer a:hover { text-decoration: underline; }

/* ── Typography ─────────────────────────────────────────────────────── */
h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 1.25rem;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  line-height: 1.3;
  letter-spacing: -0.015em;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
  letter-spacing: -0.01em;
}

h4 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 1.5rem;
  margin-bottom: 0.4rem;
}

p {
  margin-bottom: 1rem;
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

strong { font-weight: 600; }
em { font-style: italic; }

ul, ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}
li {
  margin-bottom: 0.3rem;
  color: var(--text);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: var(--accent-glow);
  border-radius: 0 6px 6px 0;
  color: var(--muted);
  font-style: italic;
}
blockquote p { margin-bottom: 0; color: var(--muted); }

/* ── Inline code ────────────────────────────────────────────────────── */
code {
  font-family: 'IBM Plex Mono', monospace;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent);
  white-space: nowrap;
}

/* ── Code blocks ────────────────────────────────────────────────────── */
pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  word-break: normal;
  white-space: pre;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  margin-bottom: 0;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--code-fg);
  font-size: 0.84rem;
  white-space: pre;
}

/* Rouge syntax highlight — works in both themes */
.highlight .k, .highlight .kd, .highlight .kn { color: #7dd3fc; font-weight: 500; }
.highlight .s, .highlight .s1, .highlight .s2  { color: #86efac; }
.highlight .c, .highlight .c1, .highlight .cm   { color: var(--muted); font-style: italic; }
.highlight .n, .highlight .nv { color: var(--code-fg); }
.highlight .o  { color: #94a3b8; }
.highlight .mi { color: #fda4af; }
.highlight .nb { color: #67e8f9; }

/* Tables code cells must not break */
td code { white-space: nowrap; }

/* ── Scroll wrapper ─────────────────────────────────────────────────── */
.scroll-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  max-width: 100%;
  margin-bottom: 1.5rem;
}

/* ── Tables ─────────────────────────────────────────────────────────── */
.content-body table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.875rem;
  margin-bottom: 0;
}

th {
  text-align: left;
  padding: 0.55rem 0.9rem;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

td {
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

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

/* ── Callouts (admonitions) ─────────────────────────────────────────── */
.callout {
  border-radius: 6px;
  padding: 0.875rem 1rem;
  margin-bottom: 1.25rem;
  border-left: 4px solid;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  line-height: 1.6;
}

.callout-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.callout-content { flex: 1; }
.callout-content strong { display: block; margin-bottom: 0.25rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.callout-content p { margin-bottom: 0; font-size: 0.9rem; }

.callout-warning {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}
.callout-warning .callout-content strong { color: var(--warn-border); }
.callout-warning .callout-content p { color: var(--warn-text); }

.callout-info {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--muted);
}
.callout-info .callout-content strong { color: var(--accent); }

/* ── Hero section (index page) ──────────────────────────────────────── */
.hero {
  padding: 2rem 0 2.5rem;
}

.hero-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 1.25rem;
}

.hero-brand img {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}

.hero-brand-text h1 {
  font-size: 2.5rem;
  margin-bottom: 0;
}

.hero-brand-text .tagline {
  font-size: 1rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.1rem;
}

.hero-desc {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 600px;
  margin-bottom: 2rem;
  line-height: 1.65;
}

.hero-buttons {
  display: flex;
  gap: 0.875rem;
  flex-wrap: wrap;
  margin-bottom: 3rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.6rem 1.3rem;
  border-radius: 7px;
  font-weight: 600;
  font-size: 0.875rem;
  text-decoration: none;
  transition: opacity 0.15s, transform 0.1s;
  font-family: 'IBM Plex Sans', sans-serif;
}
.btn:hover { opacity: 0.85; text-decoration: none; transform: translateY(-1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
[data-theme="dark"] .btn-primary { color: #070b13; }

.btn-secondary {
  background: var(--bg-surf);
  color: var(--text);
  border: 1px solid var(--border);
}

/* ── Feature grid ───────────────────────────────────────────────────── */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.875rem;
  margin: 2rem 0;
}

.feature-card {
  background: var(--bg-surf);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  transition: border-color 0.15s;
}
.feature-card:hover { border-color: var(--accent); }

.feature-card .fc-icon {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
  display: block;
}

.feature-card h3 {
  margin-top: 0;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.feature-card p {
  font-size: 0.83rem;
  color: var(--muted);
  margin-bottom: 0;
}

/* ── Architecture diagram ───────────────────────────────────────────── */
.arch-diagram {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.83rem;
  line-height: 1.7;
  color: var(--code-fg);
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

/* ── Mermaid diagrams ───────────────────────────────────────────────── */
.mermaid {
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* ── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .topbar { display: flex; }

  .sidebar {
    top: 52px;
    height: calc(100vh - 52px);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 160;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: block; }
  .sidebar-header { display: none; }

  .content {
    margin-left: 0;
    padding-top: 52px;
  }

  .content-body {
    padding: 1.75rem 1.25rem;
  }

  .page-footer {
    padding: 1.25rem 1.25rem;
  }

  h1 { font-size: 1.65rem; }
  .hero-brand-text h1 { font-size: 2rem; }
  .features-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 500px) {
  .features-grid { grid-template-columns: 1fr; }
}

@media (min-width: 1400px) {
  .content-body {
    max-width: 980px;
    padding: 3.5rem 4rem 3.5rem 4.5rem;
  }
  .page-footer {
    max-width: 980px;
    padding-left: 4.5rem;
  }
}
