/* Trail Docs — F185 stylesheet.
   Nav structure, theme-toggle, mobile menu, color tokens are LIFTED VERBATIM
   from apps/landing's deployed CSS so docs.trailmem.com is pixel-identical
   to trailmem.com landing's chrome. The "docs" suffix (.brand-section) is
   the only addition; it mirrors how apps/admin renders "trail admin".

   Keep this file in sync with landing's <style> block when landing changes.
   The doc-content / sidebar block at the bottom is docs-specific; everything
   above the marker comment is landing's CSS verbatim except for class-name
   scope (.nav-mobile etc renamed where landing's selectors use IDs we don't
   carry).
*/

:root,
html[data-theme="light"] {
  --bg: #FAF9F5;
  --bg-card: #FFFFFF;
  --fg: #1a1715;
  --accent: #e8a87c;
  --accent-tint: rgba(232, 168, 124, 0.06);
  --fg-10: rgba(26, 23, 21, 0.10);
  --fg-20: rgba(26, 23, 21, 0.20);
  --fg-40: rgba(26, 23, 21, 0.40);
  --fg-60: rgba(26, 23, 21, 0.60);
  --fg-70: rgba(26, 23, 21, 0.70);
  --fg-90: rgba(26, 23, 21, 0.90);
  --bg-50: rgba(250, 249, 245, 0.50);
  --bg-80: rgba(250, 249, 245, 0.80);
  /* Graph-canvas tokens — the script reads these and renders the
     neuron-particle background. RGB-triplet form so the script can
     wrap them in rgba(triplet, alpha). Lifted from apps/landing. */
  --graph-node: #1a1715;
  --graph-accent: #e8a87c;
  --graph-line: 26, 23, 21;
  --graph-accent-line: 232, 168, 124;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", "Courier New", monospace;
}

html[data-theme="dark"] {
  --bg: #17140F;
  --bg-card: #1F1B16;
  --fg: #F5F1EA;
  --accent: #e8a87c;
  --accent-tint: rgba(232, 168, 124, 0.08);
  --fg-10: rgba(245, 241, 234, 0.10);
  --fg-20: rgba(245, 241, 234, 0.20);
  --fg-40: rgba(245, 241, 234, 0.40);
  --fg-60: rgba(245, 241, 234, 0.60);
  --fg-70: rgba(245, 241, 234, 0.70);
  --fg-90: rgba(245, 241, 234, 0.90);
  --bg-50: rgba(23, 20, 15, 0.50);
  --bg-80: rgba(23, 20, 15, 0.80);
  --graph-node: #f5f1ea;
  --graph-accent: #e8a87c;
  --graph-line: 245, 241, 234;
  --graph-accent-line: 232, 168, 124;
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg);
  transition: background-color 0.15s ease, color 0.15s ease;
}
html, body { overflow-x: hidden; max-width: 100vw; }
body {
  font-family: var(--font-sans);
  background: transparent;
  color: var(--fg);
  line-height: 1.5;
  min-height: 100vh;
  /* Fixed nav is 56px tall + 1px border. Push content down so it doesn't
     hide under the navbar. */
  padding-top: 57px;
}
@media (min-width: 768px) {
  body { padding-top: 73px; } /* 1rem padding × 2 + 40px logo + 1px border */
}

::selection { background: rgba(232, 168, 124, 0.3); color: var(--fg); }

/* Neuron-particle canvas — sits at z-index: -1 behind everything,
   visible through translucent backgrounds. Lifted verbatim from
   apps/landing's #trail-graph rule. */
#trail-graph {
  position: fixed; inset: 0;
  pointer-events: none; opacity: 0.4; z-index: -1;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; height: auto; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
svg { max-width: 100%; height: auto; }

/* ── Navbar (LIFTED VERBATIM from apps/landing) ─────── */

.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  padding: 0.75rem 1rem;
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-80);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--fg-10);
}
@media (min-width: 768px) { .nav { padding: 1rem 1.5rem; } }
.nav-brand { display: flex; align-items: center; gap: 0.625rem; min-width: 0; color: var(--fg); }
.nav-brand img, .nav-brand svg { width: 32px; height: 32px; flex-shrink: 0; }
@media (min-width: 768px) { .nav-brand { gap: 0.875rem; } .nav-brand img, .nav-brand svg { width: 40px; height: 40px; } }
.nav-brand .brand-text {
  font-family: var(--font-mono);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (min-width: 768px) { .nav-brand .brand-text { font-size: 1.375rem; } }

/* "docs" suffix — mirrors admin's "trail admin" pattern verbatim:
   - font-family inherited from body (sans-serif), NOT mono. Admin's
     <span class="text-fg-subtle text-sm md:text-base ml-1">admin</span>
     in apps/admin/src/app.tsx has no font-mono class, so it falls
     back to the body's --font-sans.
   - text-sm (14px) mobile / text-base (16px) desktop
   - ml-1 (0.25rem)
   - color: --fg-40 (matches Tailwind's text-fg-subtle = 0.40 alpha).
   - line-height: 1 + flex align-items: baseline alternative — we
     explicitly set line-height: 1 on BOTH .brand-text and
     .brand-section so flex centering hits the glyph midpoints
     rather than centering wildly different line-boxes. (Mono +
     sans at different sizes have different default line-heights;
     without this both would render but "docs" appears to "hop"
     vertically relative to "trail".) */
.nav-brand .brand-text { line-height: 1; }
.nav-brand .brand-section {
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  color: var(--fg-40);
  margin-left: 0.25rem;
  white-space: nowrap;
}
@media (min-width: 768px) { .nav-brand .brand-section { font-size: 1rem; } }

.nav-links { display: none; gap: 2rem; font-size: 0.875rem; font-weight: 500; color: var(--fg-70); }
.nav-links a { transition: color 0.15s; }
.nav-links a:hover { color: var(--fg); }
@media (min-width: 768px) { .nav-links { display: flex; } }

.nav-actions { display: flex; gap: 0.5rem; align-items: center; }
@media (min-width: 768px) { .nav-actions { gap: 1rem; } }
.nav-signin {
  font-size: 0.875rem; font-weight: 500; color: var(--fg);
  transition: color 0.15s;
  display: none;
}
@media (min-width: 768px) { .nav-signin { display: inline; } }
.nav-signin:hover { color: var(--accent); }
.nav-cta {
  padding: 0.45rem 0.85rem;
  background: var(--fg); color: var(--bg);
  font-size: 0.8rem; font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}
@media (min-width: 768px) { .nav-cta { padding: 0.5rem 1rem; font-size: 0.875rem; } }
.nav-cta:hover { background: var(--fg-90); border-color: var(--accent); }

/* Theme toggle — sun in dark, moon in light */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--fg-10);
  border-radius: 6px;
  color: var(--fg-70);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { background: var(--bg-50); color: var(--fg); border-color: var(--fg-20); }
.theme-toggle:active { transform: scale(0.96); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Mobile hamburger toggle */
.nav-toggle {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 40px; height: 40px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--fg-10);
  border-radius: 6px;
  cursor: pointer;
  gap: 4px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.nav-toggle:hover { background: var(--bg-50); }
.nav-toggle:active { transform: scale(0.96); }
.nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--fg);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}
@media (min-width: 768px) { .nav-toggle { display: none; } }
body[data-menu-open="true"] .nav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
body[data-menu-open="true"] .nav-toggle span:nth-child(2) { opacity: 0; }
body[data-menu-open="true"] .nav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* Mobile menu overlay */
.nav-mobile {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg);
  z-index: 49;
  padding: 5rem 1.5rem 2rem;
  display: flex; flex-direction: column; gap: 1.5rem;
  transform: translateX(100%);
  transition: transform 0.25s ease-out;
  overflow-y: auto;
}
body[data-menu-open="true"] .nav-mobile { transform: translateX(0); }
@media (min-width: 768px) { .nav-mobile { display: none; } }
.nav-mobile a {
  font-size: 1.125rem; font-weight: 500; color: var(--fg);
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--fg-10);
}
.nav-mobile a:last-child { border-bottom: none; }
body[data-menu-open="true"] { overflow: hidden; }

/* ════════════════════════════════════════════════════════
   Docs-specific layout (sidebar + main content)
   This block is NOT lifted from landing — it's the docs-only
   layout below the shared navbar.
   ════════════════════════════════════════════════════════ */

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  max-width: 1180px;
  margin: 0 auto;
  min-height: calc(100vh - 73px);
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
}

.sidebar {
  border-right: 1px solid var(--fg-10);
  background: var(--bg-card);
  padding: 1.5rem 0;
  font-size: 0.93rem;
  position: sticky;
  top: 73px;
  align-self: start;
  max-height: calc(100vh - 73px);
  overflow-y: auto;
}
@media (max-width: 720px) {
  .sidebar {
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--fg-10);
    max-height: none;
    padding: 1rem 0;
    background: transparent;
  }
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a {
  display: block;
  padding: 0.4rem 1.5rem;
  color: var(--fg-70);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: color 0.15s, background 0.15s, border-left-color 0.15s;
}
.sidebar li a:hover {
  color: var(--fg);
  background: var(--bg);
}
.sidebar li a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--bg);
  font-weight: 500;
}

.content {
  padding: 2.5rem 3rem 6rem;
  max-width: 820px;
}
@media (max-width: 720px) {
  .content { padding: 1.75rem 1.25rem 4rem; }
}

.doc-header h1 {
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 0.5rem;
  color: var(--fg);
}
.doc-summary {
  margin: 0 0 2.5rem;
  color: var(--fg-70);
  font-size: 1.08rem;
  line-height: 1.55;
}

/* Markdown body — inline links DO underline + use accent. */
.doc-body { color: var(--fg); }
.doc-body a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(232, 168, 124, 0.45);
  text-underline-offset: 0.18em;
  transition: text-decoration-color 0.15s, color 0.15s;
}
.doc-body a:hover { text-decoration-color: var(--accent); }

.doc-body h2 {
  margin-top: 2.75rem;
  margin-bottom: 0.75rem;
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  border-bottom: 1px solid var(--fg-10);
  padding-bottom: 0.35rem;
  color: var(--fg);
}
.doc-body h3 {
  margin-top: 1.85rem;
  margin-bottom: 0.5rem;
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--fg);
}
.doc-body p { margin: 0.85rem 0; line-height: 1.65; }
.doc-body ul, .doc-body ol { padding-left: 1.5rem; margin: 0.85rem 0; }
.doc-body li { margin: 0.25rem 0; line-height: 1.6; }

.doc-body blockquote {
  margin: 1.5rem 0;
  padding: 0.75rem 1.15rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-tint);
  color: var(--fg);
  font-style: normal;
  border-radius: 0 4px 4px 0;
}
.doc-body blockquote p:first-child { margin-top: 0; }
.doc-body blockquote p:last-child { margin-bottom: 0; }

.doc-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-card);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  color: var(--fg);
  border: 1px solid var(--fg-10);
}

/* shiki output: <pre class="shiki ..."><code>... — keep its own bg + text. */
.doc-body pre.shiki,
.doc-body pre {
  padding: 1rem 1.15rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 1.25rem 0;
  border: 1px solid var(--fg-10);
}
.doc-body pre code {
  background: transparent !important;
  padding: 0;
  color: inherit;
  font-size: inherit;
  border: none;
}

.doc-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5rem 0;
  font-size: 0.94rem;
}
.doc-body th, .doc-body td {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--fg-10);
  vertical-align: top;
}
.doc-body th {
  font-weight: 600;
  background: var(--bg-card);
  border-bottom-width: 2px;
}

.doc-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--fg-10);
  font-size: 0.88rem;
  color: var(--fg-70);
}
.doc-footer a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(232, 168, 124, 0.45);
  text-underline-offset: 0.18em;
}
.doc-footer a:hover { text-decoration-color: var(--accent); }
