/*
   docs.css — single unified stylesheet for all three doc types
   (PRD, build plan, design spec). One typography system, one heading
   hierarchy, one set of table / list / code rules. Applies to both PDF
   and HTML; on HTML it's scoped to .doc-main by render.scope_css(), so
   nothing leaks into the sidebar chrome.

   Generic professional-but-friendly theme — slate, teal, amber accents
   on a warm cream surface. Project-specific brand illustrations (the
   .brand-gradient, .neon-sample classes used inside the design-spec
   page) remain on their own colours and are documented as overrides at
   the bottom of this file.
*/

/* ========== Page setup (PDF only — ignored in screen rendering) ========== */
@page {
  size: A4;
  margin: 22mm 20mm 22mm 20mm;
}

.doc-main, .doc-main * { box-sizing: border-box; }

/* ========== Body ========== */
.doc-main {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Helvetica Neue", Arial, sans-serif;
  font-size: 10.5pt;
  line-height: 1.55;
  color: #2B2B2A;
  background: #F5F2EC;
  margin: 0;
  padding: 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ========== Title page (first H1 + first metadata table) ==========
   Every doc opens with `# Title` followed by a bold subtitle paragraph
   and a 2-column metadata table. We style those three pieces directly
   via :first-of-type so no special markup is needed.
*/

.doc-main h1:first-of-type {
  font-size: 36pt;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #2B2B2A;
  margin: 32pt 0 6pt 0;
  padding-bottom: 14pt;
  border-bottom: 5pt solid #1F3D5C;
  page-break-before: avoid;
}

.doc-main h1:first-of-type + p {
  margin: 0 0 18pt 0;
}
.doc-main h1:first-of-type + p strong {
  font-size: 14pt;
  font-weight: 500;
  color: #2A5F65;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.doc-main h1:first-of-type ~ table:first-of-type {
  width: auto;
  font-size: 10pt;
  margin: 0 0 12pt 0;
  border: none;
  page-break-inside: avoid;
}
.doc-main h1:first-of-type ~ table:first-of-type th {
  background: transparent;
  border: none;
  padding: 4pt 24pt 4pt 0;
  color: #2A5F65;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 8.5pt;
  font-weight: 600;
  white-space: nowrap;
  text-align: left;
  vertical-align: top;
}
.doc-main h1:first-of-type ~ table:first-of-type td {
  border: none;
  padding: 4pt 0;
  vertical-align: top;
}
.doc-main h1:first-of-type ~ table:first-of-type tr:last-child td, .doc-main h1:first-of-type ~ table:first-of-type tr:last-child th {
  border-bottom: none;
}

/* ========== Subsequent headings ========== */

.doc-main h1 {
  font-size: 22pt;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #2B2B2A;
  margin: 0 0 10pt 0;
  padding-bottom: 8pt;
  border-bottom: 3pt solid #1F3D5C;
  page-break-before: always;
  page-break-after: avoid;
}

.doc-main h2 {
  font-size: 16pt;
  font-weight: 700;
  color: #2B2B2A;
  margin: 22pt 0 8pt 0;
  padding-bottom: 5pt;
  border-bottom: 1.5pt solid #3E8B93;
  page-break-after: avoid;
}

.doc-main h3 {
  font-size: 13pt;
  font-weight: 600;
  color: #2B2B2A;
  margin: 16pt 0 6pt 0;
  page-break-after: avoid;
}

.doc-main h4 {
  font-size: 11.5pt;
  font-weight: 600;
  color: #2B2B2A;
  margin: 12pt 0 4pt 0;
  page-break-after: avoid;
}

.doc-main h5, .doc-main h6 {
  font-size: 11pt;
  font-weight: 600;
  color: #2B2B2A;
  margin: 10pt 0 4pt 0;
  page-break-after: avoid;
}

/* ========== Body text ========== */

.doc-main p { margin: 0 0 8pt 0; }
.doc-main p + p { margin-top: 0; }

/* ========== Lists ========== */

.doc-main ul, .doc-main ol { margin: 0 0 10pt 0; padding-left: 22pt; }
.doc-main li { margin-bottom: 4pt; line-height: 1.55; }
.doc-main li > p:first-child { margin-bottom: 4pt; }

/* ========== Inline ========== */

.doc-main a {
  color: #1F3D5C;
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px dotted #1F3D5C;
}
.doc-main a:hover { border-bottom-style: solid; }
.doc-main strong { font-weight: 600; color: #2B2B2A; }
.doc-main em { font-style: italic; }

/* ========== Code ========== */

.doc-main code {
  font-family: "JetBrains Mono", "Cascadia Code", "Consolas", monospace;
  font-size: 0.92em;
  background: #EAF1F1;
  padding: 1px 5px;
  border-radius: 3px;
  color: #1F3D5C;
}

.doc-main pre {
  background: #FAF7F1;
  border-left: 3pt solid #1F3D5C;
  padding: 12pt 14pt;
  border-radius: 4pt;
  overflow-x: auto;
  font-family: "JetBrains Mono", "Cascadia Code", "Consolas", monospace;
  font-size: 8.8pt;
  line-height: 1.45;
  page-break-inside: avoid;
  margin: 8pt 0 12pt 0;
  color: #2B2B2A;
}
.doc-main pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  white-space: pre;
  color: inherit;
}

/* ========== Tables ========== */

.doc-main table {
  border-collapse: collapse;
  width: 100%;
  margin: 8pt 0 14pt 0;
  font-size: 9.5pt;
  page-break-inside: avoid;
  background: #FFFFFF;
}
.doc-main th {
  text-align: left;
  background: #E8EEF4;
  font-weight: 600;
  padding: 7pt 9pt;
  border-bottom: 1.5pt solid #1F3D5C;
  color: #2B2B2A;
  vertical-align: top;
}
.doc-main td {
  padding: 6pt 9pt;
  border-bottom: 0.5pt solid #D9D5CC;
  vertical-align: top;
}
.doc-main tr:last-child td { border-bottom: 0.5pt solid #B5B0A4; }
.doc-main table.wide-table { page-break-inside: auto; }

/* ========== Mermaid diagrams ==========
   Diagrams are inline ```mermaid blocks rewritten to <div class="mermaid">.
   The mermaid runtime emits a fixed-size SVG; bound it to the parent doc
   column so wide flows scale down instead of overflowing. `overflow-x:auto`
   on the wrapper is a fallback for diagrams that genuinely cannot scale
   (e.g. sequence diagrams with long actor names). */

.doc-main .mermaid {
  display: block;
  margin: 18pt auto;
  text-align: center;
  overflow-x: auto;
  max-width: 100%;
}

.doc-main .mermaid svg {
  display: block;
  max-width: 100% !important;
  height: auto !important;
  margin: 0 auto;
}

@media print {
  .doc-main .mermaid { page-break-inside: avoid; overflow: visible; }
}

/* ========== Design-spec layout ==========
   Each H2 section in the design-spec docs is wrapped in `.spec-section`
   so the page reads as a stack of focused cards rather than one long
   wall of text. A sticky right-rail TOC built from H2 / H3 anchors
   floats over the page on wide screens. Mobile collapses the TOC down
   to a static block at the top. */

.doc-main .spec-section {
  background: #FFFFFF;
  border: 1px solid #E8E1D4;
  border-radius: 10pt;
  padding: 18pt 22pt 22pt;
  margin: 0 0 18pt;
  box-shadow: 0 1px 0 rgba(0,0,0,0.02);
}
.doc-main .spec-section > h2:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
  font-size: 22pt;
  letter-spacing: -0.01em;
  color: #1F1933;
}
.doc-main .spec-section > h2:first-child::before {
  content: "";
  display: block;
  width: 36pt;
  height: 3px;
  background: linear-gradient(90deg, #FF009F 0%, #961EEF 70%, transparent 100%);
  border-radius: 2px;
  margin-bottom: 10pt;
}
.doc-main .spec-section h3 {
  margin-top: 18pt;
  font-size: 14pt;
  color: #2A2440;
}

/* Sticky TOC — appears as a floating right-rail card on wide screens.
   The renderer's HTML template positions .doc-main inside a max-w-5xl
   container; the TOC anchors via fixed positioning so it sits in the
   right gutter of the viewport.

   On narrow screens (< 1280 px) the TOC drops to a static block at the
   top of the page — works on tablet / phone without overlapping the
   content. */

.doc-main .spec-toc {
  display: none;
}

/* Show the floating TOC only when the viewport has enough room to fit it
   without overlapping the centred .doc-main column.
   Math: .doc-main max-width 1024px (max-w-5xl), centred. TOC width 220px +
   24px right offset + 16px gap = 260px clear from right edge needed.
   Required viewport ≥ 1024px + 2 × 260px = 1544px. Use 1560px to add slack
   for scrollbar gutters. Below this breakpoint the in-content h2/h3 anchors
   carry navigation. */
@media (min-width: 1560px) {
  .doc-main .spec-toc {
    display: block;
    position: fixed;
    top: 88px;
    right: 24px;
    width: 220px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    padding: 14px 14px 14px 14px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #E8E1D4;
    border-radius: 10pt;
    box-shadow: 0 4px 14px rgba(31, 25, 51, 0.06);
    font-size: 12px;
    line-height: 1.4;
    z-index: 10;
    backdrop-filter: blur(8px);
    scrollbar-width: thin;
    scrollbar-color: #D9D2C2 transparent;
  }
  .doc-main .spec-toc::-webkit-scrollbar { width: 6px; }
  .doc-main .spec-toc::-webkit-scrollbar-thumb { background: #D9D2C2; border-radius: 3px; }
  .doc-main .spec-toc::-webkit-scrollbar-track { background: transparent; }
}

.doc-main .spec-toc__heading {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #7E7390;
  padding: 0 0 8px 0;
  border-bottom: 1px solid #EEE7DA;
  margin-bottom: 8px;
}

.doc-main .spec-toc nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.doc-main .spec-toc__item, .doc-main .spec-toc__sub {
  display: block;
  text-decoration: none;
  color: #5A536B;
  padding: 4px 8px;
  border-radius: 5px;
  transition: background-color 0.12s, color 0.12s;
}
.doc-main .spec-toc__item {
  font-weight: 600;
  color: #2A2440;
}
.doc-main .spec-toc__sub {
  font-size: 11px;
  padding-left: 18px;
  position: relative;
}
.doc-main .spec-toc__sub::before {
  content: "·";
  position: absolute;
  left: 8px;
  color: #B5AC9D;
}
.doc-main .spec-toc__item:hover, .doc-main .spec-toc__sub:hover {
  background: #F4EFE7;
  color: #1F1933;
}

@media print {
  .doc-main .spec-toc { display: none; }
  .doc-main .spec-section {
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
    margin-bottom: 24pt;
  }
  .doc-main .spec-section > h2:first-child::before { display: none; }
}

/* ========== Hr & blockquote ========== */

.doc-main hr {
  border: none;
  border-top: 0.5pt solid #D9D5CC;
  margin: 18pt 0;
}

.doc-main blockquote {
  border-left: 3pt solid #E8A857;
  padding: 8pt 14pt;
  margin: 10pt 0;
  background: #FAF1E0;
  color: #5A3E14;
  border-radius: 0 4pt 4pt 0;
}

/* ========== Phase tags (used in PRD + build plan) ========== */

.doc-main .phase-tag {
  display: inline-block;
  padding: 0px 6px;
  border-radius: 3px;
  font-size: 0.86em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 0.5pt solid currentColor;
  vertical-align: 1pt;
}
.doc-main .phase-mvp { background: #EAF1EC; color: #2E5A3A; border-color: #4F8A5E; }
.doc-main .phase-alpha { background: #FAF1E0; color: #5A3E14; border-color: #B07820; }
.doc-main .phase-beta { background: #E8EEF4; color: #1F3D5C; border-color: #1F3D5C; }
.doc-main .phase-production { background: #EAF1F1; color: #2A5F65; border-color: #3E8B93; }
.doc-main .phase-stretch { background: #F8E8E6; color: #7A2424; border-color: #B83A3A; }
.doc-main .phase-compound { background: #F5F2EC; color: #6B6962; border-color: #D9D5CC; }
.doc-main h2 .phase-tag { font-size: 10pt; vertical-align: 3pt; margin-left: 8pt; }

/* ========== App-scope chips (next to section headers) ========== */

.doc-main .scope-chips { display: inline-block; margin-left: 8pt; vertical-align: 1pt; }
.doc-main .scope-chip {
  display: inline-block;
  padding: 0px 5px;
  margin-left: 3pt;
  border-radius: 2pt;
  font-size: 0.78em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 0.5pt solid currentColor;
}
.doc-main .scope-project { background: #F5F2EC; color: #6B6962; border-color: #D9D5CC; }
.doc-main .scope-designer { background: #FAF1E0; color: #5A3E14; border-color: #B07820; }
.doc-main .scope-host { background: #E8EEF4; color: #1F3D5C; border-color: #1F3D5C; }
.doc-main .scope-client { background: #EAF1F1; color: #2A5F65; border-color: #3E8B93; }
.doc-main .scope-remote { background: #EAF1EC; color: #2E5A3A; border-color: #4F8A5E; }

/* ========== Table of contents (PRD) ========== */

.doc-main .toc-list { list-style: none; padding-left: 0; }
.doc-main .toc-list li {
  border-bottom: 0.5pt dotted #D9D5CC;
  padding: 4pt 0;
  margin: 0;
}
.doc-main .toc-list a { font-weight: 500; }

/* ========== Avoid orphaned headings ========== */

.doc-main h2 + p, .doc-main h2 + ul, .doc-main h2 + ol, .doc-main h2 + table, .doc-main h3 + p, .doc-main h3 + ul, .doc-main h3 + ol, .doc-main h3 + table {
  page-break-before: avoid;
}
.doc-main ul li { page-break-inside: avoid; }

/* ========== Build plan foldouts + task checkboxes ========== */

/* Each <h2> section in the build plan is wrapped in <details><summary>
   by post_process_build_plan_foldouts() in render.py. This collapses
   sections so the user sees the feature list first and expands details
   only when interested. */

.doc-main details.bp-section {
  background: #FFFFFF;
  border: 0.75pt solid #D9D5CC;
  border-radius: 5pt;
  padding: 0;
  margin: 8pt 0;
  page-break-inside: avoid;
}
.doc-main details.bp-section[open] {
  border-color: #3E8B93;
  box-shadow: 0 1pt 4pt rgba(31, 61, 92, 0.06);
}
.doc-main details.bp-section > summary {
  cursor: pointer;
  list-style: none;
  padding: 10pt 14pt;
  font-size: 13pt;
  font-weight: 600;
  color: #1F3D5C;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12pt;
  border-radius: 5pt;
  user-select: none;
}
.doc-main details.bp-section > summary::-webkit-details-marker { display: none; }
.doc-main details.bp-section > summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8pt;
  color: #6B6962;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.doc-main details.bp-section[open] > summary::before { transform: rotate(90deg); }
.doc-main details.bp-section > summary:hover { background: #FAF7F1; }
.doc-main details.bp-section > summary .bp-summary-text { flex: 1; }
.doc-main details.bp-section > summary .bp-progress {
  font-size: 0.78em;
  font-weight: 500;
  color: #6B6962;
  background: #F5F2EC;
  padding: 2pt 8pt;
  border-radius: 10pt;
  border: 0.5pt solid #D9D5CC;
  white-space: nowrap;
  flex-shrink: 0;
}
.doc-main details.bp-section > summary .bp-progress.bp-progress-complete {
  background: #EAF1EC;
  color: #2E5A3A;
  border-color: #4F8A5E;
}
.doc-main details.bp-section > .bp-body {
  padding: 4pt 16pt 12pt 16pt;
  border-top: 0.5pt solid #D9D5CC;
}
.doc-main details.bp-section > .bp-body > h3:first-child { margin-top: 8pt; }

/* Print + PDF: force every section open so nothing is hidden in the artefact. */
@media print {
  .doc-main details.bp-section { border: none; box-shadow: none; }
  .doc-main details.bp-section > summary { padding: 0; cursor: default; }
  .doc-main details.bp-section > summary::before { display: none; }
  .doc-main details.bp-section > .bp-body { padding: 0; border-top: none; }
}

/* Per-app top-level foldouts wrapping every `<details.bp-section>` belonging
   to a single source file (project / designer / host / client / remote).
   Authored by generate_build_plans._wrap_app_regions(). Typography +
   colour follow the H2 register from the rest of the docs theme so the
   bp-app summary reads like a section heading, with bp-section foldouts
   nested inside reading like H3-scale subheads. */
.doc-main details.bp-app {
  background: transparent;
  border: none;
  border-top: 1.5pt solid #3E8B93;
  border-radius: 0;
  padding: 0;
  margin: 26pt 0 14pt 0;
  page-break-inside: avoid;
}
.doc-main details.bp-app:first-of-type { margin-top: 18pt; }
.doc-main details.bp-app > summary.bp-app-summary {
  cursor: pointer;
  list-style: none;
  padding: 12pt 4pt 10pt 4pt;
  font-family: inherit;
  font-size: 16pt;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: #2B2B2A;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12pt;
  user-select: none;
}
.doc-main details.bp-app > summary.bp-app-summary::-webkit-details-marker { display: none; }
.doc-main details.bp-app > summary.bp-app-summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 10pt;
  font-size: 13pt;
  color: #3E8B93;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.doc-main details.bp-app[open] > summary.bp-app-summary::before { transform: rotate(90deg); }
.doc-main details.bp-app > summary.bp-app-summary:hover { color: #1F3D5C; }
.doc-main details.bp-app > summary.bp-app-summary:hover::before { color: #1F3D5C; }
.doc-main details.bp-app > summary.bp-app-summary .bp-app-label { flex: 0 0 auto; }
.doc-main details.bp-app > summary.bp-app-summary .bp-progress {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.62em;
  font-weight: 500;
  color: #6B6962;
  background: #F5F2EC;
  padding: 3pt 10pt;
  border-radius: 12pt;
  border: 0.5pt solid #D9D5CC;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0;
}
.doc-main details.bp-app > summary.bp-app-summary .bp-progress.bp-progress-complete {
  background: #EAF1EC;
  color: #2E5A3A;
  border-color: #4F8A5E;
}
.doc-main details.bp-app > .bp-app-body {
  padding: 4pt 0 4pt 0;
}

@media print {
  .doc-main details.bp-app { border-top: 1.5pt solid #3E8B93; margin: 18pt 0 10pt 0; }
  .doc-main details.bp-app > summary.bp-app-summary { padding: 8pt 0; cursor: default; }
  .doc-main details.bp-app > summary.bp-app-summary::before { display: none; }
  .doc-main details.bp-app > .bp-app-body { padding: 0; }
}

/* Task checkboxes — post_process_task_checkboxes() rewrites
   `<li>[ ] text</li>` and `<li>[x] text</li>` into spans. */
.doc-main li.task {
  list-style: none;
  margin-left: -16pt;
  padding-left: 22pt;
  position: relative;
  margin-bottom: 5pt;
  min-height: 14pt;
}
.doc-main li.task::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.18em;
  width: 12pt;
  height: 12pt;
  border-radius: 2.5pt;
  border: 1pt solid #6B6962;
  background: #FFFFFF;
  box-sizing: border-box;
}
.doc-main li.task.done::before {
  background: #4F8A5E;
  border-color: #4F8A5E;
}
.doc-main li.task.done::after {
  content: "";
  position: absolute;
  left: 2.8pt;
  top: calc(0.18em + 3.5pt);
  width: 6.5pt;
  height: 3pt;
  border-left: 1.4pt solid #FFFFFF;
  border-bottom: 1.4pt solid #FFFFFF;
  transform: rotate(-45deg);
}
.doc-main li.task.done {
  color: #6B6962;
  text-decoration: line-through;
  text-decoration-color: #B5B0A4;
}
.doc-main li.task.done strong { color: #6B6962; font-weight: 500; }

/* ========== Color swatch (design spec — auto-injected next to <code>#XXXXXX</code>) ========== */

.doc-main .swatch {
  display: inline-block;
  width: 22pt;
  height: 12pt;
  margin-left: 6pt;
  border-radius: 2pt;
  border: 0.5pt solid rgba(0, 0, 0, 0.15);
  vertical-align: -2pt;
}

/* Generic sample-frame styling for design-spec gradient swatches.
   The actual gradient + sample-class definitions live in project-side
   overrides (e.g. `.claude/context/styles/design-spec-extras.css`). */
.doc-main .gradient-sample {
  height: 60pt;
  border-radius: 4pt;
  margin: 8pt 0 16pt 0;
  border: 0.5pt solid rgba(0, 0, 0, 0.15);
  page-break-inside: avoid;
}

/* ========== Mermaid diagrams (inline blocks) ========== */
/* `useMaxWidth: true` in the init JSON makes Mermaid emit a width-responsive
   SVG that scales down to fit the column. The wrapper provides a soft paper
   backdrop matching the rest of the chrome, with horizontal scroll only as
   a fallback for diagrams that cannot scale (long sequence diagrams). */
.doc-main .mermaid {
  background: #F8F5F0;
  border: 1px solid #DDD5C8;
  border-radius: 12px;
  padding: 24px;
  margin: 24px 0;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
  box-shadow: 0 1px 2px rgba(31, 25, 51, 0.04);
}
.doc-main .mermaid svg { max-width: 100% !important; height: auto; display: inline-block; }
/* While Mermaid hasn't yet replaced the source text with an SVG, hide the
   raw text so the page doesn't flash unstyled mermaid source. */
.doc-main .mermaid:not([data-processed="true"]) { color: transparent; }

/* ========== HTML-only: hide nav in print previews ========== */
@media print { .doc-main .docs-nav { display: none !important; } }
