/* ============================================================================
   Arion HTML guides — shared stylesheet
   ----------------------------------------------------------------------------
   Brand tokens are mirrored from packages/web/app/globals.css so the guides,
   the marketing site and the product app read as one brand. The diagrams use
   these same custom properties (see the `diagramColors` map in
   packages/web/components/diagrams/tokens.ts), which is what makes every
   inline SVG theme-aware for free with no per-diagram dark-mode branching.

   The sheet has two audiences:
     - screen  : a sticky-sidebar documentation layout
     - print   : an A4 document. Everything chrome-like is dropped, the palette
                 is forced back to light ink-on-paper, and sections break onto
                 their own pages. "Print → Save as PDF" is the export path.
   ========================================================================== */

/* ---------------------------------------------------------------- tokens -- */
:root {
  --brand-primary: #0d9488;
  --brand-primary-strong: #0f766e;
  --brand-ink: #0f172a;
  --brand-bg: #f7f8fb;
  --brand-surface: #ffffff;
  --brand-border: #e2e8f0;
  --brand-muted: #475569;
  --brand-accent: #f59e0b;
  --brand-deep: #0b1220;
  --brand-gradient: linear-gradient(135deg, #14b8a6 0%, #0d9488 45%, #0e7490 100%);

  /* Semantic surfaces derived from the brand palette. Kept as their own
     tokens so dark mode overrides one place rather than every callout. */
  --tint-primary: rgba(13, 148, 136, 0.08);
  --tint-accent: rgba(245, 158, 11, 0.10);
  --tint-danger: rgba(220, 38, 38, 0.09);
  --brand-danger: #dc2626;

  --font-heading: 'Sora', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-body: 'DM Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'SFMono-Regular', ui-monospace, 'JetBrains Mono', Menlo, Consolas, monospace;

  --sidebar-width: 17.5rem;
  --measure: 45rem;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 20px rgba(15, 23, 42, 0.07);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --brand-primary: #14b8a6;
    --brand-primary-strong: #2dd4bf;
    --brand-ink: #e4e4e4;
    --brand-bg: #1a1a2e;
    --brand-surface: #16213e;
    --brand-border: #0f3460;
    --brand-muted: #94a3b8;
    --tint-primary: rgba(20, 184, 166, 0.12);
    --tint-accent: rgba(245, 158, 11, 0.14);
    --tint-danger: rgba(248, 113, 113, 0.14);
    --brand-danger: #f87171;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme='dark'] {
  --brand-primary: #14b8a6;
  --brand-primary-strong: #2dd4bf;
  --brand-ink: #e4e4e4;
  --brand-bg: #1a1a2e;
  --brand-surface: #16213e;
  --brand-border: #0f3460;
  --brand-muted: #94a3b8;
  --tint-primary: rgba(20, 184, 166, 0.12);
  --tint-accent: rgba(245, 158, 11, 0.14);
  --tint-danger: rgba(248, 113, 113, 0.14);
  --brand-danger: #f87171;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
}

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

html { scroll-behavior: smooth; scroll-padding-top: 2rem; }

body {
  margin: 0;
  background: var(--brand-bg);
  color: var(--brand-ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  line-height: 1.2;
  color: var(--brand-ink);
  margin: 0;
}

a { color: var(--brand-primary-strong); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-primary); }

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--tint-primary);
  color: var(--brand-primary-strong);
  padding: 0.1em 0.4em;
  border-radius: 5px;
}

strong { font-weight: 600; color: var(--brand-ink); }

/* --------------------------------------------------------------- layout -- */
.shell { display: flex; align-items: flex-start; gap: 0; }

.sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2rem 1.25rem 3rem;
  border-right: 1px solid var(--brand-border);
  background: var(--brand-surface);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--brand-ink);
  text-decoration: none;
}
.sidebar__brand:hover { color: var(--brand-primary); }
.sidebar__mark { width: 26px; height: 26px; flex: none; }

.sidebar__doc {
  font-size: 0.78rem;
  color: var(--brand-muted);
  margin: 0 0 1.35rem 2.2rem;
}

.toc__heading {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--brand-muted);
  margin: 0 0 0.6rem 0.5rem;
}

.toc { list-style: none; margin: 0 0 1.75rem; padding: 0; }
.toc li { margin: 0; }

.toc a {
  display: flex;
  gap: 0.6rem;
  padding: 0.34rem 0.5rem;
  border-radius: 7px;
  border-left: 2px solid transparent;
  color: var(--brand-muted);
  font-size: 0.845rem;
  line-height: 1.4;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease;
}
.toc a:hover { background: var(--tint-primary); color: var(--brand-ink); }
.toc a.is-active {
  background: var(--tint-primary);
  border-left-color: var(--brand-primary);
  color: var(--brand-primary-strong);
  font-weight: 600;
}
.toc__num { flex: none; width: 1.15rem; font-variant-numeric: tabular-nums; opacity: 0.75; }

.sidebar__actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0 0 1.75rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--brand-border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--brand-border);
  border-radius: 9px;
  background: var(--brand-surface);
  color: var(--brand-ink);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease;
}
.btn:hover { border-color: var(--brand-primary); color: var(--brand-primary-strong); background: var(--tint-primary); }
.btn svg { width: 15px; height: 15px; flex: none; }

.btn--primary { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }
.btn--primary:hover { background: var(--brand-primary-strong); border-color: var(--brand-primary-strong); color: #fff; }

.main { flex: 1 1 auto; min-width: 0; padding: 0 3rem 6rem; }
.wrap { max-width: var(--measure); margin: 0 auto; }

/* ---------------------------------------------------------------- cover -- */
.cover {
  position: relative;
  margin: 0 -3rem 3.5rem;
  padding: 5rem 3rem 3.5rem;
  background: var(--brand-gradient);
  color: #fff;
  overflow: hidden;
}
.cover::after {
  /* A faint echo of the loop diagram, so the cover carries the same visual
     language as the concept diagrams inside the document. */
  content: '';
  position: absolute;
  right: -110px;
  top: -110px;
  width: 420px;
  height: 420px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  pointer-events: none;
}
.cover::before {
  content: '';
  position: absolute;
  right: -40px;
  top: -40px;
  width: 280px;
  height: 280px;
  border: 2px dashed rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  pointer-events: none;
}
.cover__inner { position: relative; max-width: var(--measure); margin: 0 auto; }

.cover__eyebrow {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}
.cover h1 {
  font-size: clamp(2.1rem, 4.4vw, 3.1rem);
  color: #fff;
  letter-spacing: -0.025em;
  margin-bottom: 0.9rem;
}
.cover__sub {
  font-size: 1.1rem;
  line-height: 1.55;
  color: rgba(255, 255, 255, 0.92);
  max-width: 34rem;
  margin: 0 0 2.25rem;
}
.cover__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2.25rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.22);
}
.cover__meta div { font-size: 0.9rem; }
.cover__meta dt {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.2rem;
}
.cover__meta dd { margin: 0; font-weight: 600; }

/* ------------------------------------------------------------- sections -- */
.section { padding-top: 1rem; }
.section + .section { margin-top: 3.5rem; }

.section > h2 {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  padding-bottom: 0.85rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--brand-border);
}
.section__num {
  flex: none;
  font-size: 1rem;
  font-weight: 700;
  color: var(--brand-primary);
  font-variant-numeric: tabular-nums;
}

h3 {
  font-size: 1.18rem;
  letter-spacing: -0.01em;
  margin: 2.25rem 0 0.75rem;
}
h4 {
  font-size: 0.95rem;
  margin: 1.75rem 0 0.5rem;
  color: var(--brand-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

p { margin: 0 0 1rem; }
.lede { font-size: 1.08rem; color: var(--brand-muted); line-height: 1.6; }

ul, ol { margin: 0 0 1.15rem; padding-left: 1.3rem; }
li { margin-bottom: 0.4rem; }
li::marker { color: var(--brand-primary); }

/* Numbered procedures get a heavier treatment than a plain <ol> — these are
   the "do this, then this" steps a user follows with the app open. */
.steps { list-style: none; counter-reset: step; padding: 0; margin: 0 0 1.5rem; }
.steps > li {
  position: relative;
  counter-increment: step;
  padding: 0 0 0 2.6rem;
  margin-bottom: 0.9rem;
  min-height: 1.75rem;
}
.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.05rem;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--brand-primary);
  color: #fff;
  font-family: var(--font-heading);
  font-size: 0.82rem;
  font-weight: 700;
}

/* -------------------------------------------------------------- callout -- */
.callout {
  position: relative;
  margin: 1.5rem 0;
  padding: 1.15rem 1.35rem;
  border: 1px solid var(--brand-border);
  border-left: 3px solid var(--brand-muted);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--brand-surface);
  box-shadow: var(--shadow-sm);
}
.callout > :last-child { margin-bottom: 0; }
.callout__label {
  display: block;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.45rem;
}

.callout--key { border-left-color: var(--brand-primary); background: var(--tint-primary); }
.callout--key .callout__label { color: var(--brand-primary-strong); }

.callout--warn { border-left-color: var(--brand-accent); background: var(--tint-accent); }
.callout--warn .callout__label { color: #b45309; }
:root[data-theme='dark'] .callout--warn .callout__label,
:root:not([data-theme='light']) .callout--warn .callout__label { color: var(--brand-accent); }

.callout--danger { border-left-color: var(--brand-danger); background: var(--tint-danger); }
.callout--danger .callout__label { color: var(--brand-danger); }

.callout--role { border-left-color: var(--brand-primary); }
.callout--role .callout__label { color: var(--brand-primary-strong); }

/* ------------------------------------------------------------- diagrams -- */
.diagram {
  margin: 2rem 0;
  padding: 1.75rem;
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
  background: var(--brand-surface);
  box-shadow: var(--shadow-sm);
}
.diagram svg { display: block; width: 100%; height: auto; margin: 0 auto; }
.diagram figcaption {
  margin-top: 1.15rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--brand-border);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--brand-muted);
  text-align: center;
}
.diagram__title {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand-muted);
  margin-bottom: 1.1rem;
}

/* ---------------------------------------------------------- screenshots -- */
.shot { margin: 1.75rem 0; }
.shot img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--brand-border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  background: var(--brand-surface);
}
.shot figcaption {
  margin-top: 0.7rem;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--brand-muted);
  text-align: center;
}

/* A capture that has not been supplied yet renders as a labelled slot rather
   than a broken image, so the document stays presentable and the gap is
   self-documenting. JS adds `.is-missing` on the img's error event; the
   `.shot--todo` class marks slots we already know are empty. */
.shot--todo img, .shot.is-missing img { display: none; }
.shot--todo .shot__slot, .shot.is-missing .shot__slot { display: flex; }
.shot__slot {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 9.5rem;
  padding: 1.75rem;
  border: 2px dashed var(--brand-border);
  border-radius: 10px;
  background: var(--brand-bg);
  text-align: center;
}
.shot__slot-label {
  font-family: var(--font-heading);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brand-accent);
}
.shot__slot-name { font-size: 0.92rem; font-weight: 600; color: var(--brand-ink); }
.shot__slot-file { font-family: var(--font-mono); font-size: 0.74rem; color: var(--brand-muted); }

/* --------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; margin: 1.5rem 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--brand-surface);
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
  overflow: hidden;
}
thead th {
  background: var(--tint-primary);
  color: var(--brand-ink);
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: left;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--brand-border);
}
tbody td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--brand-border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody th {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--brand-border);
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- chips -- */
.chip {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  border: 1px solid var(--brand-border);
  background: var(--brand-bg);
  color: var(--brand-muted);
}
.chip--primary { background: var(--tint-primary); border-color: var(--brand-primary); color: var(--brand-primary-strong); }
.chip--accent { background: var(--tint-accent); border-color: var(--brand-accent); color: #b45309; }
:root[data-theme='dark'] .chip--accent { color: var(--brand-accent); }
.chip--danger { background: var(--tint-danger); border-color: var(--brand-danger); color: var(--brand-danger); }

/* --------------------------------------------------------- quick-ref grid */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.card {
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--brand-border);
  border-radius: var(--radius);
  background: var(--brand-surface);
  box-shadow: var(--shadow-sm);
}
.card h4 { margin: 0 0 0.5rem; color: var(--brand-primary-strong); text-transform: none; letter-spacing: 0; font-size: 0.95rem; font-weight: 700; }
.card p, .card ul { font-size: 0.88rem; margin-bottom: 0; }
.card ul { padding-left: 1.1rem; }

/* -------------------------------------------------------------- footer --- */
.doc-footer {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--brand-border);
  font-size: 0.82rem;
  color: var(--brand-muted);
}

/* --------------------------------------------------------------- mobile -- */
@media (max-width: 60rem) {
  .shell { display: block; }
  .sidebar {
    position: static;
    width: auto;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--brand-border);
  }
  .main { padding: 0 1.25rem 4rem; }
  .cover { margin: 0 -1.25rem 2.5rem; padding: 3rem 1.25rem 2.5rem; }
}

/* ================================================================= PRINT ==
   Export path: open the guide in Chrome → Print → Destination "Save as PDF",
   A4, Default margins, and tick "Background graphics".
   ========================================================================== */
@media print {
  /* Force the light palette regardless of the reader's OS theme — a dark
     document would otherwise flood the page with ink. */
  :root, :root[data-theme='dark'], :root:not([data-theme='light']) {
    --brand-primary: #0d9488;
    --brand-primary-strong: #0f766e;
    --brand-ink: #0f172a;
    --brand-bg: #ffffff;
    --brand-surface: #ffffff;
    --brand-border: #d5dbe3;
    --brand-muted: #475569;
    --brand-accent: #b45309;
    --brand-danger: #b91c1c;
    --tint-primary: #eef7f6;
    --tint-accent: #fdf5e7;
    --tint-danger: #fdeeee;
    --shadow-sm: none;
    --shadow-md: none;
  }

  @page { size: A4; margin: 17mm 15mm 18mm; }

  html { font-size: 10.5pt; }
  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .sidebar, .no-print { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .wrap { max-width: none; }

  /* Cover owns page 1. Its inner column drops its measure cap so the cover
     aligns to the same @page box as the body text at any paper size. */
  .cover {
    margin: 0;
    padding: 4.5rem 0 3rem;
    background: none;
    color: var(--brand-ink);
    break-after: page;
  }
  .cover__inner { max-width: none; }
  .cover::before, .cover::after { display: none; }
  .cover h1 { color: var(--brand-ink); font-size: 30pt; }
  .cover__sub { color: var(--brand-muted); font-size: 12pt; }
  .cover__eyebrow { border-color: var(--brand-primary); color: var(--brand-primary-strong); }
  .cover__meta { border-top-color: var(--brand-border); }
  .cover__meta dt { color: var(--brand-muted); }
  .cover__meta dd { color: var(--brand-ink); }

  /* Each numbered section starts a fresh page, which is what makes the PDF
     read as a document rather than as a printed web page. */
  .section { break-before: page; padding-top: 0; }
  .section:first-of-type { break-before: auto; }
  .section + .section { margin-top: 0; }

  h2, h3, h4 { break-after: avoid; }
  p, li { orphans: 3; widows: 3; }

  .diagram, .shot, .callout, .card, table, figure { break-inside: avoid; }
  .steps > li { break-inside: avoid; }

  /* Keep large captures inside one page instead of spilling across a break. */
  .shot img { max-height: 135mm; width: auto; max-width: 100%; margin: 0 auto; box-shadow: none; }
  .diagram { padding: 0.75rem 0; border: none; box-shadow: none; }
  .diagram svg { max-height: 115mm; }

  .cards { grid-template-columns: 1fr 1fr; }

  a { color: var(--brand-ink); text-decoration: none; }

  .doc-footer { break-inside: avoid; }
}
