/* ============================================================================
   components.css — layout chrome + content components for the manual site.
   Load order: fonts.css -> tokens.css -> type.css -> components.css
   ============================================================================ */

/* --- reset / base --------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--c-bg-soft); }
img, svg { max-width: 100%; height: auto; display: block; }
a { color: var(--c-accent-dark); text-underline-offset: .15em; }
a:hover { text-decoration: underline; }
:where(button) { font: inherit; cursor: pointer; }

/* visible focus everywhere (a11y) */
:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* skip link — first tab stop */
.skip-link {
  position: absolute;
  left: var(--sp-3);
  top: -56px;
  z-index: 100;
  background: var(--c-surface);
  color: var(--c-accent-dark);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  font-weight: 600;
  box-shadow: var(--sh-card);
  transition: top var(--t-fast) var(--ease);
}
.skip-link:focus { top: var(--sp-2); }

/* ===========================================================================
   LAYOUT SHELL (built around existing <main id="doc-main"> by layout.js)
   header spans top, sidebar left (sticky), content right, footer spans bottom.
   =========================================================================== */
#doc-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  min-height: 100vh;
}

/* --- header --------------------------------------------------------------- */
#doc-header {
  grid-area: header;
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: var(--header-h);
  padding-inline: clamp(var(--sp-3), 3vw, var(--sp-5));
  background: color-mix(in srgb, var(--c-surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--c-border);
}
.doc-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  color: var(--c-text);
  text-decoration: none;
  letter-spacing: -.01em;
}
.doc-brand:hover { text-decoration: none; }
.doc-brand .brand-mark {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  border-radius: var(--r-sm);
  background: var(--c-accent);
  color: #fff;
  font-weight: 700;
  flex: none;
}
.doc-brand .brand-name { font-size: var(--fs-step-0); }
.doc-brand .brand-name b { font-weight: 700; }
.doc-brand .brand-name span { color: var(--c-text-muted); font-weight: 500; }

.hamburger {
  display: none;                 /* shown < 1024 */
  margin-left: auto;
  align-items: center;
  justify-content: center;
  width: 42px; height: 42px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text);
}
.hamburger svg { width: 22px; height: 22px; }

/* --- sidebar -------------------------------------------------------------- */
#doc-sidebar {
  grid-area: sidebar;
  position: sticky;
  top: var(--header-h);
  align-self: start;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-3) var(--sp-6);
  background: var(--c-bg-soft);
  border-right: 1px solid var(--c-border);
}
.doc-nav-group { margin-bottom: var(--sp-4); }
.doc-nav-group > .group-label {
  display: block;
  font-size: var(--fs-step--1);
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: none;
  color: var(--c-text-muted);
  padding: 0 var(--sp-2) var(--sp-2);
}
.doc-nav-group ul { list-style: none; margin: 0; padding: 0; }
.doc-nav-link {
  display: block;
  position: relative;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--c-text-muted);
  text-decoration: none;
  font-size: var(--fs-step-0);
  line-height: 1.4;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.doc-nav-link:hover { background: var(--c-accent-tint); color: var(--c-text); text-decoration: none; }
.doc-nav-link[aria-current="page"] {
  color: var(--c-accent-dark);
  background: var(--c-accent-tint);
  font-weight: 600;
}
.doc-nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 2px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 1.1em;
  border-radius: var(--r-pill);
  background: var(--c-accent);
}

/* --- main content --------------------------------------------------------- */
#doc-main {
  grid-area: main;
  padding-block: clamp(var(--sp-4), 4vw, var(--sp-6));
  padding-inline: clamp(var(--sp-3), 5vw, var(--sp-6));
}
#doc-main > * { max-width: var(--content-max); }
#doc-main > * + * { margin-top: var(--sp-4); }
#doc-main h2 { margin-top: var(--sp-6); }
#doc-main h3 { margin-top: var(--sp-5); }
#doc-main h2 + *, #doc-main h3 + * { margin-top: var(--sp-3); }
/* deep-linked anchors (helpers.html#review etc.) must clear the sticky header */
#doc-main :is(h2, h3)[id] { scroll-margin-top: calc(var(--header-h) + var(--sp-3)); }
#doc-main p, #doc-main li { max-width: var(--content-max); }
#doc-main ul, #doc-main ol { padding-left: 1.4em; }
#doc-main li + li { margin-top: var(--sp-2); }

.lead {
  font-size: var(--fs-step-1);
  line-height: 1.55;
  color: var(--c-text-muted);
  font-weight: 400;
}

/* hero treatment only on the overview landing (one focal element) */
html[data-section="overview"] #doc-main > h1 { letter-spacing: -.02em; }

/* --- steps (ordered, accent number markers) ------------------------------- */
ol.steps {
  list-style: none;
  margin: var(--sp-4) 0;
  padding: 0;
  counter-reset: step;
}
ol.steps > li {
  position: relative;
  counter-increment: step;
  padding: 0 0 var(--sp-3) calc(var(--sp-5) + var(--sp-1));
  min-height: 36px;
}
ol.steps > li::before {
  content: counter(step);
  position: absolute;
  left: 0; top: -2px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--c-accent);
  color: #fff;
  font-weight: 700;
  font-size: var(--fs-step--1);
  font-variant-numeric: tabular-nums;
}
ol.steps > li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 17px; top: 36px; bottom: 4px;
  width: 2px;
  background: var(--c-border);
}
ol.steps > li > strong { display: block; font-weight: 600; }

/* --- callouts ------------------------------------------------------------- */
.callout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-3);
  margin: var(--sp-4) 0;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--c-border);
  border-left-width: 4px;
  border-radius: var(--r-md);
  background: var(--c-surface);
}
.callout > .callout-icon {
  width: 22px; height: 22px;
  flex: none;
  margin-top: 2px;
}
.callout > .callout-body { min-width: 0; }
.callout > .callout-body > :first-child { margin-top: 0; }
.callout > .callout-body > :last-child { margin-bottom: 0; }
.callout .callout-title { font-weight: 600; display: block; margin-bottom: var(--sp-1); }

.callout.tip  { border-left-color: var(--c-accent);    background: var(--c-accent-tint); }
.callout.tip  .callout-icon, .callout.tip  .callout-title { color: var(--c-accent-dark); }
.callout.note { border-left-color: var(--c-border-strong); background: var(--c-bg-soft); }
.callout.note .callout-icon, .callout.note .callout-title { color: var(--c-text-muted); }
.callout.warn { border-left-color: var(--c-warn);      background: var(--c-warn-tint); }
.callout.warn .callout-icon, .callout.warn .callout-title { color: var(--c-warn-text); }

/* --- figure / screenshot -------------------------------------------------- */
figure.shot { margin: var(--sp-4) 0; }
figure.shot img,
figure.shot .shot-ph {
  width: 100%;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-card);
  background: var(--c-bg-soft);
}
figure.shot .shot-ph {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--c-text-muted);
  border-style: dashed;
  border-color: var(--c-border-strong);
  padding: var(--sp-4);
  gap: var(--sp-1);
}
figure.shot .shot-ph .ph-tag {
  font-family: var(--font-mono);
  font-size: var(--fs-step--1);
  color: var(--c-accent-dark);
}
figure.shot figcaption {
  margin-top: var(--sp-2);
  font-size: var(--fs-step--1);
  color: var(--c-text-muted);
  line-height: 1.5;
}

/* --- comparison table (responsive scroll-x) ------------------------------- */
.cmp-table-wrap { overflow-x: auto; margin: var(--sp-4) 0; }
table.cmp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-step-0);
  min-width: 480px;
}
table.cmp-table caption {
  text-align: left;
  color: var(--c-text-muted);
  font-size: var(--fs-step--1);
  padding-bottom: var(--sp-2);
}
table.cmp-table th, table.cmp-table td {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--c-border);
  vertical-align: top;
}
table.cmp-table thead th {
  background: var(--c-bg-soft);
  font-weight: 600;
  border-bottom: 2px solid var(--c-border-strong);
}
table.cmp-table tbody tr:hover { background: var(--c-bg-soft); }

/* --- inline code + kbd ---------------------------------------------------- */
code {
  font-size: .92em;
  background: var(--c-bg-soft);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: .08em .4em;
  color: var(--c-text);
  word-break: break-word;
}
.kbd, kbd {
  font-family: var(--font-mono);
  font-size: .85em;
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  padding: .1em .45em;
  color: var(--c-text);
  white-space: nowrap;
}

/* --- badge ---------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  font-size: var(--fs-step--1);
  font-weight: 600;
  line-height: 1;
  padding: .3em .6em;
  border-radius: var(--r-pill);
  border: 1px solid var(--c-border-strong);
  background: var(--c-bg-soft);
  color: var(--c-text-muted);
  white-space: nowrap;
}
.badge.accent { background: var(--c-accent-tint); border-color: transparent; color: var(--c-accent-dark); }
.badge.warn   { background: var(--c-warn-tint);   border-color: transparent; color: var(--c-warn-text); }
.badge.ok     { background: var(--c-ok-tint);     border-color: transparent; color: var(--c-ok); }
.badge.danger { background: var(--c-danger-tint); border-color: transparent; color: var(--c-danger); }

/* --- pager (prev / next) -------------------------------------------------- */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin-top: var(--sp-6);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--c-border);
}
.pager a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  text-decoration: none;
  color: var(--c-text);
  background: var(--c-surface);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.pager a:hover { border-color: var(--c-accent); box-shadow: var(--sh-card); text-decoration: none; }
.pager a.next { text-align: right; }
.pager .pager-dir {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  font-size: var(--fs-step--1);
  color: var(--c-text-muted);
  font-weight: 500;
}
.pager a.next .pager-dir { justify-content: flex-end; }
.pager .pager-title { font-weight: 600; color: var(--c-accent-dark); }
.pager svg { width: 16px; height: 16px; flex: none; }

/* --- footer --------------------------------------------------------------- */
#doc-footer {
  grid-area: footer;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
  padding: var(--sp-4) clamp(var(--sp-3), 5vw, var(--sp-6));
  color: var(--c-text-muted);
  font-size: var(--fs-step--1);
}
#doc-footer .foot-inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  align-items: center;
  justify-content: space-between;
}

/* --- mobile drawer overlay ------------------------------------------------ */
.doc-overlay {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0 0;
  z-index: var(--z-overlay);
  background: rgba(15, 23, 42, .4);
}
.doc-overlay[data-open="true"] { display: block; }

/* ===========================================================================
   RESPONSIVE — sidebar collapses to an off-canvas drawer < 1024px
   =========================================================================== */
@media (max-width: 1023px) {
  #doc-shell {
    /* minmax(0,1fr) lets the content column shrink below its min-content so a
       wide .cmp-table scrolls inside .cmp-table-wrap instead of pushing the page
       (plain 1fr = minmax(auto,1fr) caused ~143px horizontal overflow < 1024px) */
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "header"
      "main"
      "footer";
  }
  .hamburger { display: inline-flex; }

  #doc-sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    height: auto;
    width: min(86vw, var(--sidebar-w));
    z-index: var(--z-drawer);
    transform: translateX(-100%);
    transition: transform var(--t-med) var(--ease);
    box-shadow: var(--sh-pop);
    border-right: 1px solid var(--c-border);
  }
  #doc-sidebar[data-open="true"] { transform: translateX(0); }

  #doc-main { padding-inline: clamp(var(--sp-3), 5vw, var(--sp-5)); }
  .pager { grid-template-columns: 1fr; }
}

/* ===========================================================================
   REDUCED MOTION — WCAG 2.2, non-negotiable. Kill all transitions/animations.
   =========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
