/* FourIA documentation — brand theme derived from docs/STYLE.md
   (warm, dark-first palette rooted in deep burgundy; system font stack). */

:root {
  /* Brand / action */
  --primary-color: #7c323e;
  --primary-hover: #98404e;

  /* Backgrounds */
  --bg-color: #1a1515;
  --surface-color: #111111;
  --surface-hover: #1e1a1a;
  --sidebar-bg: rgba(17, 17, 17, 0.92);

  /* Typography */
  --text-primary: #ede8e3;
  --text-secondary: #b6ada5;
  --text-muted: #8d847c;
  --header-color: #c4bdb7;

  /* Links — a lighter burgundy than --primary-color so text keeps contrast on
     the dark page background; --primary-color still drives buttons/active fills. */
  --link-color: #d9a3ad;
  --link-hover: #f0c6cd;

  /* Semantic */
  --success-color: #4ade80;
  --warning-color: #95aa69;
  --error-color: #ef4444;

  /* Borders & shadows (borders lightened for clearer structure) */
  --border-color: #3a3334;
  --border-radius: 10px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 40px -8px rgba(0, 0, 0, 0.6);

  /* Fonts */
  --font-sans:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'Fragment Mono', 'Courier New', monospace;

  --sidebar-width: 17.5rem;
  --content-width: 52rem;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--link-color);
  text-decoration: none;
  transition:
    color 0.15s ease,
    background-color 0.15s ease,
    border-color 0.15s ease;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--primary-color);
  color: #fff;
  padding: 0.5rem 1rem;
  z-index: 100;
}

.skip-link:focus {
  left: 0;
}

/* ── Top bar ─────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--sidebar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  max-width: 100rem;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 600;
  color: var(--text-primary);
}

.brand:hover {
  text-decoration: none;
  color: var(--text-primary);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 8px;
  background: var(--primary-color);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
}

.topnav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-left: auto;
}

.topnav a {
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

.topnav a:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.repo-link {
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Layout ──────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: 2.5rem;
  max-width: 100rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.sidebar {
  position: sticky;
  top: 4.2rem;
  align-self: start;
  max-height: calc(100vh - 5.5rem);
  overflow-y: auto;
  padding-right: 0.5rem;
}

/* ── Sidebar (foldable sections + hierarchy) ─────────────── */

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.side-group {
  margin: 0;
}

/* Section name: larger, high-contrast; shifted slightly left of the pages it
   owns, so the hierarchy reads as a tree. */
.side-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: -0.35rem;
  padding: 0.36rem 0.5rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.005em;
  color: var(--text-primary);
}

.side-title .side-label {
  color: inherit;
}

.side-title .side-label:hover {
  color: var(--link-hover);
  text-decoration: none;
}

.side-title:hover {
  background: var(--surface-hover);
}

.side-leaf {
  display: flex;
}

.side-title[data-active='true'] {
  background: rgba(124, 50, 62, 0.26);
  color: var(--text-primary);
}

summary.side-title {
  cursor: pointer;
  list-style: none;
}

summary.side-title::-webkit-details-marker {
  display: none;
}

.side-chevron {
  flex: 0 0 auto;
  width: 0.42rem;
  height: 0.42rem;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
}

details[open] > summary .side-chevron {
  transform: rotate(45deg);
}

/* The vertical rule marks the section boundary; nested levels accumulate
   indentation automatically because each group is nested in its parent. */
.side-children {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  margin: 0.1rem 0 0.35rem 0.15rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--border-color);
}

.side-page {
  display: block;
  padding: 0.26rem 0.5rem;
  border-radius: 7px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.side-page:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.side-page[data-active='true'] {
  background: rgba(124, 50, 62, 0.22);
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Content ─────────────────────────────────────────────── */

.content {
  min-width: 0;
  max-width: var(--content-width);
}

.hero {
  padding: 2rem 0 1.25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 2rem;
}

.eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--link-color);
  margin: 0 0 0.5rem;
}

.hero h1,
.doc-header h1 {
  font-size: 2.1rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 0.6rem;
  color: var(--text-primary);
}

.lede {
  font-size: 1.06rem;
  color: var(--text-secondary);
  margin: 0 0 1.2rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  background: var(--primary-color);
  color: #fff;
  font-weight: 500;
  font-size: 0.875rem;
  border: 1px solid transparent;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    border-color 0.15s ease;
}

.btn:hover {
  background: var(--primary-hover);
  color: #fff;
  text-decoration: none;
}

.btn.ghost {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn.ghost:hover {
  border-color: var(--primary-color);
  color: var(--text-primary);
}

.section-heading {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 2rem 0 1rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem;
  color: var(--text-primary);
  transition:
    border-color 0.15s ease,
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.card:hover {
  border-color: var(--primary-color);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  text-decoration: none;
  color: var(--text-primary);
}

.card h3 {
  margin: 0 0 0.35rem;
  font-size: 1.02rem;
  color: var(--text-primary);
}

.card p {
  margin: 0 0 0.9rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  flex: 1;
}

.card-arrow {
  color: var(--link-color);
  font-size: 0.85rem;
  font-weight: 600;
}

.subsection {
  margin-top: 2.5rem;
}

.subsection h2 {
  font-size: 1.3rem;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}

.breadcrumbs a {
  color: var(--text-secondary);
}

.doc-header {
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.toc {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 0.8rem 1rem;
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.toc summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-primary);
}

.toc ul {
  margin: 0.6rem 0 0;
  padding-left: 1.1rem;
}

.toc li {
  margin: 0.25rem 0;
}

/* ── Prose ───────────────────────────────────────────────── */

.doc-body h2,
.doc-body h3,
.doc-body h4 {
  scroll-margin-top: 5rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.doc-body h2 {
  font-size: 1.45rem;
  margin: 2.4rem 0 0.8rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-color);
}

.doc-body h3 {
  font-size: 1.15rem;
  margin: 1.8rem 0 0.6rem;
}

/* Heading anchors: the heading text itself is the link (no icon). Colour it
   like a link so the clickable affordance is obvious. */
.doc-body :is(h2, h3, h4) a {
  color: var(--link-color);
  text-decoration: none;
}

.doc-body :is(h2, h3, h4) a:hover {
  color: var(--link-hover);
  text-decoration: none;
}

.doc-body p,
.doc-body li {
  color: var(--text-primary);
}

.doc-body strong {
  color: var(--text-primary);
}

.doc-body code {
  background: var(--surface-hover);
  color: var(--text-primary);
  padding: 0.12em 0.38em;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.doc-body pre {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.6;
  font-family: var(--font-mono);
}

.doc-body pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

.doc-body blockquote {
  margin: 1.2rem 0;
  padding: 0.4rem 1rem;
  border-left: 3px solid var(--primary-color);
  background: rgba(124, 50, 62, 0.12);
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  color: var(--text-secondary);
}

.doc-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2rem 0;
  font-size: 0.9rem;
  display: block;
  overflow-x: auto;
}

.doc-body th,
.doc-body td {
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.7rem;
  text-align: left;
}

.doc-body th {
  background: var(--surface-color);
  color: var(--text-primary);
}

.doc-body tr:nth-child(even) td {
  background: rgba(30, 26, 26, 0.5);
}

.doc-body img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.doc-body hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2rem 0;
}

/* ── Footer ──────────────────────────────────────────────── */

.footer {
  border-top: 1px solid var(--border-color);
  padding: 1.5rem 1.25rem 2.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer p {
  margin: 0.2rem 0;
}

/* ── Scrollbar ───────────────────────────────────────────── */

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

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-muted);
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding-top: 1rem;
  }

  .sidebar {
    position: static;
    max-height: none;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
  }
}

@media (max-width: 640px) {
  .hero h1,
  .doc-header h1 {
    font-size: 1.7rem;
  }

  .hero,
  .doc-header {
    padding-bottom: 0.75rem;
  }
}
