/* ============================================================
   LEGAL CODEX — Swiss editorial reference tool
   DM Mono (labels/¶ numbers) · Space Grotesk (headings) · DM Sans (body)
   One accent: deep judicial ink #1a3562. Hard black rules. White ground.
   ============================================================ */

:root {
  --ink: #111111;
  --mid: #555555;
  --faint: #8a8a8a;
  --rule: #000000;
  --accent: #1a3562;       /* deep judicial ink */
  --tint: #f8f8f8;         /* regional / area-specific ground */
  --white: #ffffff;
  --hairline: #e2e2e2;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--white);
  color: var(--ink);
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------- layout shell ---------- */

.codex {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  align-items: start;
  max-width: 1180px;
  margin: 0 auto;
}

.codex-main {
  min-width: 0;
  padding: 3rem 3rem 6rem 3rem;
  max-width: 820px;
}

/* ---------- sidebar TOC (desktop) ---------- */

.codex-toc {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 2px solid var(--rule);
  padding: 3rem 1.5rem 3rem 1.5rem;
}

.codex-toc .toc-kicker {
  font-family: "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.66rem;
  color: var(--faint);
  margin-bottom: 1rem;
  display: block;
}

.codex-toc .toc-home {
  font-family: "DM Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  display: inline-block;
  margin-bottom: 1.5rem;
}
.codex-toc .toc-home:hover { text-decoration: underline; }

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

.toc-list > li > a {
  display: block;
  padding: 0.3rem 0 0.3rem 0.75rem;
  margin-left: -0.75rem;
  border-left: 2px solid transparent;
  text-decoration: none;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.005em;
}

.toc-list ol a {
  display: block;
  padding: 0.22rem 0 0.22rem 1.4rem;
  margin-left: -0.75rem;
  border-left: 2px solid transparent;
  text-decoration: none;
  color: var(--mid);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.3;
}

.toc-list a:hover { color: var(--accent); }

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

/* ---------- document header ---------- */

.doc-header {
  border-bottom: 2px solid var(--rule);
  padding-bottom: 1.5rem;
  margin-bottom: 0.5rem;
}

.doc-header .eyebrow {
  font-family: "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.doc-header h1 {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.9rem;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 1rem 0;
}

.doc-header .meta {
  font-family: "DM Mono", monospace;
  font-size: 0.74rem;
  color: var(--mid);
  line-height: 1.5;
}
.doc-header .meta div { margin: 0.1rem 0; }
.doc-header .meta .k {
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.doc-header .meta a { color: var(--accent); text-decoration: none; word-break: break-all; }
.doc-header .meta a:hover { text-decoration: underline; }

/* ---------- companion note ---------- */

.companion {
  font-family: "DM Mono", monospace;
  font-size: 0.76rem;
  line-height: 1.55;
  color: var(--mid);
  border-left: 2px solid var(--accent);
  padding: 0.6rem 0 0.6rem 0.9rem;
  margin: 1.5rem 0 0 0;
}
.companion strong { color: var(--ink); }
.companion a { color: var(--accent); }

/* ---------- ground shifts (section groups) ---------- */

.ground { margin-top: 2.5rem; }

.ground-label {
  font-family: "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--accent);
  border-top: 2px solid var(--rule);
  padding-top: 0.7rem;
  margin-bottom: 1.75rem;
}

.ground-area {
  background: var(--tint);
  /* full-bleed within the reading column */
  margin-left: -3rem;
  margin-right: -3rem;
  padding: 0 3rem 2rem 3rem;
}
.ground-area .ground-label {
  /* keep label flush with the tinted band's top */
  padding-top: 1.4rem;
}

/* ---------- headings (weight, not size) ---------- */

.codex-main h2 {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.015em;
  line-height: 1.2;
  margin: 2.4rem 0 0.5rem 0;
  scroll-margin-top: 1rem;
}

.codex-main h3 {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 600;
  font-size: 1.04rem;
  letter-spacing: -0.01em;
  line-height: 1.25;
  margin: 1.9rem 0 0.4rem 0;
  scroll-margin-top: 1rem;
}

.codex-main h4 {
  font-family: "DM Mono", monospace;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.78rem;
  color: var(--mid);
  margin: 1.5rem 0 0.3rem 0;
}

/* ---------- body prose & paragraph numbers ---------- */

.sec-body { font-size: 0.95rem; }

.sec-body p { margin: 0.6rem 0; }

.sec-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* Top-level numbered paragraphs → ¶ markers in the left margin */
.sec-body > ol {
  list-style-position: outside;
  padding-left: 3.25rem;
  margin: 0.8rem 0;
}
.sec-body > ol > li {
  margin: 0.55rem 0;
  padding-left: 0.35rem;
}
.sec-body > ol > li::marker {
  content: "¶" counter(list-item) "\00a0\00a0";
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  color: var(--faint);
  font-weight: 400;
}

/* Nested lists keep ordinary markers (no ¶) */
.sec-body ol ol,
.sec-body ul ol,
.sec-body ol ul,
.sec-body ul ul {
  margin: 0.3rem 0;
}
.sec-body ol ol > li::marker {
  content: counter(list-item) ".\00a0";
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  color: var(--faint);
}
.sec-body ul { padding-left: 1.4rem; }
.sec-body ul > li::marker { color: var(--faint); }

/* De-nested sub-bullets: the scraped markdown sometimes places a numbered
   paragraph's bullet sub-list as a SIBLING <ul> right after the <ol> instead
   of nesting it inside the <li>. Align such a list under the parent paragraph
   text (≈ paragraph indent 3.6rem + nested-list indent 1.4rem) so the bullets
   read as sub-items rather than sitting further left than their paragraph.
   Targets only a <ul>/<ol> that directly follows an <ol>. */
.sec-body > ol + ul,
.sec-body > ol + ul + ul,
.sec-body > ol + ol { padding-left: 5rem; }

/* ---------- tables ---------- */

.sec-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.82rem;
}
.sec-body th {
  background: var(--ink);
  color: #fff;
  text-align: left;
  padding: 0.5rem 0.7rem;
  font-family: "DM Mono", monospace;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
}
.sec-body td {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--hairline);
  vertical-align: top;
}
.sec-body tr:nth-child(even) td { background: rgba(0,0,0,0.02); }

/* ---------- mixed-area notice ---------- */

.mixed-notice {
  font-family: "DM Mono", monospace;
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--mid);
  border: 1px solid var(--rule);
  padding: 0.5rem 0.75rem;
  margin: 1rem 0;
}

/* ---------- manual review ---------- */

#manual-review {
  border: 2px solid var(--rule);
  padding: 1.5rem;
  margin-top: 3rem;
}
#manual-review h2 { margin-top: 0; }

/* ---------- mobile pill + slide-in panel ---------- */

.toc-pill {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 300;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.05rem;
  font-family: "DM Mono", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  max-width: 80vw;
}
.toc-pill .pill-current {
  text-transform: none;
  font-size: 0.72rem;
  opacity: 0.92;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50vw;
}
.toc-pill .pill-current:empty { display: none; }
.toc-pill .pill-current:not(:empty)::before { content: "·"; margin: 0 0.4rem 0 0.1rem; opacity: 0.7; }

.toc-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.28);
  z-index: 250;
  opacity: 0;
  transition: opacity 0.2s;
}
.toc-backdrop.open { opacity: 1; }

/* ---------- responsive ---------- */

@media (max-width: 879px) {
  .codex { display: block; max-width: none; }
  .codex-main { padding: 4.5rem 1.25rem 4rem 1.25rem; max-width: none; }

  .codex-toc {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 320px;
    max-width: 88vw;
    background: #fff;
    border-right: 2px solid var(--rule);
    box-shadow: 4px 0 18px rgba(0,0,0,0.16);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    z-index: 280;
  }
  .codex-toc.open { transform: translateX(0); }

  .toc-pill { display: inline-flex; }
  .toc-backdrop { display: block; pointer-events: none; }
  .toc-backdrop.open { pointer-events: auto; }

  .ground-area { margin-left: -1.25rem; margin-right: -1.25rem; padding-left: 1.25rem; padding-right: 1.25rem; }
}

/* ---------- print ---------- */

@media print {
  .codex { display: block; }
  .codex-toc, .toc-pill, .toc-backdrop { display: none !important; }
  .codex-main { padding: 0; max-width: none; }
  .ground-area { background: none; margin: 0; padding: 0; }
  .ground-label { color: #000; }
  .codex-main h2, .codex-main h3 { page-break-after: avoid; }
  tr { page-break-inside: avoid; }
}
