/* components.css — token-driven, context-free widget classes. The proven markup/behaviour
   is lifted from archive/cobalt-palettes.html and retargeted to design-system tokens; the
   nav/dropdown coupling is replaced by an explicit .dropdown--nav modifier so any dropdown
   works anywhere. Everything lives in the sg.components layer, so unlayered consumer CSS wins.

   This file pulls in the other two system sheets, keeping the consumer contract to three
   includes: tokens.css + components.css + ui.js. */
@layer sg.tokens, sg.layout, sg.components, sg.anim;
@import "layouts.css" layer(sg.layout);
@import "animations.css" layer(sg.anim);
@import "content.css" layer(sg.components);

@layer sg.components {
  /* ---- base / reset ---- */
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font-family: var(--font-body); font-size: 16px; line-height: var(--leading);
    -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-x: clip;
  }
  img, svg { max-width: 100%; display: block; }
  a { color: var(--link); text-decoration: none; }
  h1, h2, h3, h4, p, ul, figure { margin: 0; }
  h1, h2, h3, h4, p { overflow-wrap: anywhere; }   /* `anywhere` (not break-word) also cuts min-content, so a long unbroken token can't blow out a flex/grid item */
  button { font: inherit; }
  :focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
  [hidden] { display: none !important; }
  .num { font-variant-numeric: tabular-nums; }
  .sr-only {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }

  /* ---- nav shell ---- */
  .nav {
    position: sticky; top: env(safe-area-inset-top, 0px); z-index: var(--z-nav);
    background: var(--nav-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .nav-inner { display: flex; align-items: center; gap: 1rem; min-height: var(--nav-h); padding-block: 0.5rem; }
  .brand {
    display: inline-flex; align-items: center; gap: 0.55rem; color: var(--ink);
    font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; letter-spacing: -0.01em;
  }
  .brand-mark {
    display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; overflow: hidden;
    border: 1.5px dashed var(--muted); background: transparent; color: var(--muted);
  }
  .brand-mark img, .brand-mark svg { width: 100%; height: 100%; object-fit: contain; }   /* any logo drops in */
  .brand-mark:has(> img) { border: 0; }   /* the edge-served /site-icon.png carries its own frame */
  .brand-tag {
    font-family: var(--font-mono); font-size: 0.66rem; color: var(--muted);
    border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 0.15em 0.5em;
  }
  .nav-toggle {
    display: none; margin-left: auto; width: 40px; height: 40px; align-items: center;
    justify-content: center; background: transparent; border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--ink); cursor: pointer;
  }
  .nav-menu { display: flex; align-items: center; gap: 0.35rem; margin-left: auto; }
  .nav-links { display: flex; align-items: center; gap: 0.15rem; list-style: none; padding: 0; margin: 0; }
  .nav-links a {
    display: inline-flex; padding: 0.5rem 0.7rem; border-radius: var(--radius); color: var(--muted);
    font-weight: 500; font-size: 0.92rem; transition: color var(--dur-fast), background-color var(--dur-fast);
  }
  .nav-links a:hover { color: var(--ink); background: var(--surface-2); }
  .nav-links > li > a[aria-current="page"] { color: var(--ink); }   /* the page you are on (stamped on consumer nav links) */
  /* menu items nested in the nav are <a> and would otherwise inherit the muted .nav-links a
     colour — restore the legible --ink menuitem colour on the dark dropdown panel */
  .nav-links .dropdown-item { color: var(--ink); }
  .nav-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: 0.35rem; }

  /* palette chips (rendered by UI.palette.renderChips) */
  .palette-swatches { display: flex; flex-wrap: wrap; gap: 0.4rem; }
  .palette-swatch {
    display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.28rem 0.6rem 0.28rem 0.32rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-pill); cursor: pointer;
    font: inherit; font-size: 0.8rem; font-weight: 500; color: var(--muted);
    transition: color var(--dur-fast), background-color var(--dur-fast), border-color var(--dur-fast);
  }
  .palette-swatch:hover { color: var(--ink); background: var(--surface-2); }
  .palette-swatch[aria-pressed="true"] { color: var(--ink); background: var(--accent-weak); border-color: var(--accent); }
  .palette-preview { display: inline-flex; overflow: hidden; border-radius: var(--radius-pill); border: 1px solid var(--border); }
  .palette-chip { width: 12px; height: 18px; display: block; }
  .palette-name { white-space: nowrap; }

  /* hamburger icon (3 morphable bars; the morph itself lives in animations.css) */
  .ham { position: relative; display: block; width: 20px; height: 14px; }
  .ham-bar {
    position: absolute; left: 0; right: 0; height: 2px; border-radius: 2px; background: currentColor;
  }
  .ham-bar:nth-child(1) { top: 0; }
  .ham-bar:nth-child(2) { top: 6px; }
  .ham-bar:nth-child(3) { top: 12px; }

  /* avatar + user menu (dropdown variant) */
  .avatar {
    display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
    background: var(--accent-weak); color: var(--accent); font-family: var(--font-display);
    font-weight: 700; font-size: 0.82rem; flex-shrink: 0;
  }
  /* wrapper has no width (= the avatar), so the panel's right:0 lands on the avatar's right edge */
  .user-menu { width: auto; }
  .user-menu-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.9rem; color: var(--ink); }
  .user-menu .dropdown-trigger { width: auto; min-height: 0; padding: 3px; border-radius: var(--radius-pill); }
  .user-menu .dropdown-trigger:hover { background: var(--surface-2); }

  /* ---- dropdown (one component: select, menu, kebab, meatball, user-menu) ---- */
  .dropdown { position: relative; }
  .dropdown--control { width: 260px; max-width: 100%; }
  .dropdown--field { width: 100%; }
  .dropdown--nav { width: auto; }
  .dropdown--nav .dropdown-menu { left: auto; right: 0; width: max-content; min-width: 100%; max-width: 360px; }
  .dropdown-trigger {
    display: inline-flex; align-items: center; gap: 0.45rem; width: 100%; min-height: 40px;
    padding: 0.5rem 0.8rem; font: inherit; font-size: 0.92rem; font-weight: 500; color: var(--muted);
    background: transparent; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
    transition: color var(--dur-fast), background-color var(--dur-fast), border-color var(--dur-fast);
  }
  .dropdown--nav .dropdown-trigger:hover { color: var(--ink); background: var(--surface-2); }
  .dropdown--control .dropdown-trigger,
  .dropdown--field .dropdown-trigger { background: var(--surface); border-color: var(--border); color: var(--ink); }
  .dropdown--control .dropdown-trigger:hover { background: var(--surface-2); }
  .dropdown--field .dropdown-trigger:focus-visible {
    outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--accent-weak);
  }
  /* icon trigger (kebab ⋮ / meatball •••) */
  .dropdown-trigger.btn-icon { width: 40px; min-height: 40px; padding: 0; justify-content: center; }
  .dd-prefix { color: var(--muted); font-size: 0.8rem; font-weight: 500; }
  .dropdown .chev { margin-left: auto; transition: transform var(--dur) var(--ease-out); }
  .dropdown-trigger[aria-expanded="true"] .chev { transform: rotate(180deg); }
  /* connected look: trigger + menu read as one control when open (field/control placements) */
  .dropdown--control .dropdown-trigger[aria-expanded="true"],
  .dropdown--field .dropdown-trigger[aria-expanded="true"] {
    background: var(--surface); border-color: var(--border);
    border-bottom-left-radius: 0; border-bottom-right-radius: 0;
  }
  .dropdown-menu {
    position: absolute; top: 100%; left: 0; width: 100%; min-width: 180px; margin-top: -1px;
    padding: 0.35rem; background: var(--surface); border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow-2); z-index: var(--z-menu);
  }
  /* end-aligned menu (kebab/meatball/user-menu open toward their trigger corner) */
  .dropdown--end .dropdown-menu,
  .user-menu .dropdown-menu { left: auto; right: 0; width: max-content; min-width: 210px; border-radius: var(--radius); margin-top: 0.35rem; }
  /* open-up variant (sidebar foot): flips above the trigger, left-anchored */
  .user-menu--up .dropdown-menu { top: auto; bottom: calc(100% + 0.35rem); left: 0; right: auto; margin-top: 0; }
  .dropdown-search {
    width: 100%; min-height: 34px; margin-bottom: 0.35rem; padding: 0 0.6em; font: inherit;
    font-size: 0.88rem; color: var(--ink); background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm);
  }
  .dropdown-search::placeholder { color: var(--muted); }
  .dropdown-search:focus-visible { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--accent-weak); }
  .dropdown-list { list-style: none; margin: 0; padding: 0; max-height: 230px; overflow: auto; }
  /* nav dropdowns hold a short, fixed set of links (e.g. 8 templates) — show them all with
     no scroll cap; the 230px cap stays for the long searchable select/menu lists */
  .dropdown--nav .dropdown-list { max-height: none; overflow: visible; }
  .dropdown-item {
    display: flex; width: 100%; align-items: center; gap: 0.5rem; padding: 0.55rem 0.6rem; font: inherit;
    font-size: 0.9rem; color: var(--ink); background: transparent; border: 0; border-radius: var(--radius-sm);
    text-align: left; cursor: pointer;
  }
  .dropdown-item:hover { background: var(--accent-weak); }
  .dropdown-item:focus-visible { outline: none; background: var(--accent-weak); box-shadow: inset 0 0 0 2px var(--ring); }
  .dropdown-item[aria-current] { color: var(--accent); font-weight: 600; }
  /* a nav dropdown holding the current page (stamp.py marks it aria-current="page") accents its trigger */
  .dropdown--nav:has([aria-current]) .dropdown-trigger { color: var(--accent); }
  .dropdown-item-danger { color: var(--danger); }
  .dropdown-item-danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
  .dropdown-group-label { padding: 0.5rem 0.6rem 0.2rem; font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
  .dropdown-item--hint { flex-direction: column; align-items: flex-start; gap: 0.1rem; }
  .dropdown-item-hint { display: block; font-size: 0.76rem; font-weight: 400; color: var(--muted); line-height: 1.3; }
  .dropdown-sep { height: 1px; margin: 0.35rem 0.2rem; background: var(--border); border: 0; }
  .dropdown-empty { padding: 0.55rem 0.6rem; font-size: 0.88rem; color: var(--muted); font-style: italic; }

  /* ---- buttons ---- */
  .btn {
    --_h: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
    min-height: var(--_h); padding-inline: 1.1em; font-family: var(--font-body); font-weight: 600;
    font-size: 0.92rem; line-height: 1; white-space: nowrap; border: 1px solid transparent;
    border-radius: var(--radius); cursor: pointer; text-decoration: none;
    transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast), transform 0.06s;
  }
  .btn-sm { --_h: 32px; font-size: 0.8rem; padding-inline: 0.85em; }
  .btn-lg { --_h: 48px; font-size: 1rem; padding-inline: 1.5em; }
  .btn-icon { width: var(--_h); padding-inline: 0; }
  .btn:active { transform: translateY(1px); }
  .btn:disabled, .btn[aria-disabled="true"], .btn[aria-busy="true"] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
  .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
  .btn-primary:hover { background: color-mix(in oklab, var(--accent) 86%, var(--ink)); }
  .btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
  .btn-secondary:hover { background: var(--surface-2); border-color: color-mix(in oklab, var(--border), var(--ink) 22%); }
  .btn-ghost { background: transparent; color: var(--ink); border-color: transparent; }
  .btn-ghost:hover { background: var(--surface-2); }
  .btn-destructive { background: var(--danger); color: #fff; border-color: var(--danger); }
  .btn-destructive:hover { background: color-mix(in oklab, var(--danger) 86%, #000); }
  .btn-tonal {
    background: color-mix(in srgb, var(--secondary) 16%, var(--surface));
    color: color-mix(in srgb, var(--secondary) 72%, var(--ink));
    border-color: color-mix(in srgb, var(--secondary) 32%, transparent);
  }
  .btn-tonal:hover { background: color-mix(in srgb, var(--secondary) 26%, var(--surface)); }

  /* ---- form controls ---- */
  .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 1.1rem; max-width: 780px; }
  .field { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
  .field-label { font-size: 0.82rem; font-weight: 600; color: var(--ink); }
  .control {
    min-height: 40px; width: 100%; padding: 0 0.8em; font: inherit; font-size: 0.92rem; color: var(--ink);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  }
  textarea.control { min-height: 96px; padding: 0.6em 0.8em; resize: vertical; }
  .control::placeholder { color: var(--muted); }
  .control:hover { border-color: color-mix(in oklab, var(--border), var(--ink) 20%); }
  .control:focus-visible { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px var(--accent-weak); }
  select.control {
    appearance: none; -webkit-appearance: none; padding-right: 2.4em;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.8em center; background-size: 14px;
  }
  .field-error .control { border-color: var(--danger); }
  .field-error .control:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 25%, transparent); }
  .field-hint { font-size: 0.78rem; color: var(--muted); }
  .field-error .field-hint { color: var(--danger); }

  .checkbox, .radio { display: inline-flex; align-items: center; gap: 0.55rem; cursor: pointer; font-size: 0.92rem; color: var(--ink); }
  .checkbox input, .radio input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

  .switch { display: inline-flex; align-items: center; gap: 0.6rem; cursor: pointer; font-size: 0.92rem; color: var(--ink); }
  .switch input { position: absolute; opacity: 0; width: 0; height: 0; }
  .switch-track {
    position: relative; width: 40px; height: 22px; flex: none; border-radius: var(--radius-pill);
    background: var(--surface-2); border: 1px solid var(--border);
    transition: background-color var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out);
  }
  .switch-track::after {
    content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
    background: var(--bg); box-shadow: var(--shadow-1); transition: transform var(--dur) var(--ease-spring);
  }
  .switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
  .switch input:checked + .switch-track::after { transform: translateX(18px); }
  .switch input:focus-visible + .switch-track { outline: 2px solid var(--ring); outline-offset: 2px; }

  .seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
  .seg-option {
    appearance: none; border: 0; background: transparent; color: var(--muted); font: inherit;
    font-size: 0.85rem; font-weight: 600; padding: 0.4rem 0.8rem; border-radius: var(--radius-sm);
    cursor: pointer; transition: color var(--dur-fast), background-color var(--dur-fast);
  }
  .seg-option:hover { color: var(--ink); }
  .seg-option[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
  /* .seg--grid: on a phone a long seg becomes one full-width control of equal cells, 3 per row; a short
     last row stretches to fill (…+2 → two halves, …+1 → one full cell) instead of wrapping ragged */
  @media (max-width: 480px) {
    .seg--grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); width: 100%; }
    .seg--grid > .seg-option { grid-column: span 2; padding-inline: 0.4rem; }
    .seg--grid > .seg-option:nth-child(3n+1):nth-last-child(2),
    .seg--grid > .seg-option:nth-child(3n+1):nth-last-child(2) + .seg-option { grid-column: span 3; }
    .seg--grid > .seg-option:nth-child(3n+1):last-child { grid-column: span 6; }
    .pref-controls:has(> .seg--grid) { width: 100%; }   /* stacked settings segs share one full-width column grid */
  }

  /* ---- cards + stats ---- */
  .cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
  .card {
    display: flex; flex-direction: column; gap: 0.7rem; padding: 1.4rem; min-width: 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1);
  }
  .card-interactive { cursor: pointer; transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast), border-color var(--dur-fast); }
  .card-interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: color-mix(in oklab, var(--border), var(--ink) 18%); }
  .card-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: var(--radius); background: var(--accent-weak); color: var(--accent); }
  /* --_tint hook: a modifier only retints the icon + link (DRY — the same two rules serve every tint) */
  .card--secondary { --_tint: var(--secondary); }
  .card--accent-2 { --_tint: var(--accent-2); }
  .card--secondary .card-icon, .card--accent-2 .card-icon { background: color-mix(in oklch, var(--_tint) 18%, var(--surface)); color: color-mix(in srgb, var(--_tint) 72%, var(--ink)); }
  .card--secondary .card-link, .card--accent-2 .card-link { color: color-mix(in srgb, var(--_tint) 72%, var(--ink)); }
  .card-eyebrow { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
  .card-title { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.18rem; letter-spacing: var(--display-tracking); }
  .card-body { color: var(--muted); flex: 1; font-size: 0.95rem; }
  .card-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 0.3rem; }
  .card-link { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--accent-2); font-weight: 600; font-size: 0.9rem; transition: gap var(--dur-fast); }
  .card-link:hover { gap: 0.55rem; }
  .card-metric { font-size: 0.78rem; color: var(--muted); }

  .stat {
    --_tint: var(--accent);
    display: flex; flex-direction: column; gap: 0.3rem; padding: 1.2rem; min-width: 0;
    background: color-mix(in oklch, var(--_tint) 8%, var(--surface)); border: 1px solid var(--border);
    border-radius: var(--radius-lg);
  }
  .stat--secondary { --_tint: var(--secondary); }
  .stat--accent-2 { --_tint: var(--accent-2); }
  .stat-label { font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
  .stat-value { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.9rem; letter-spacing: var(--display-tracking); overflow-wrap: anywhere; }
  .stat-delta { font-size: 0.8rem; font-weight: 600; }
  /* semantic, decoupled from arrow direction: a down-arrow can be "good" (e.g. error rate) */
  .stat-delta.good { color: var(--ok); }
  .stat-delta.bad { color: var(--danger); }

  /* ---- table ---- */
  /* overflow:visible (not auto) so a row's kebab/⋮ menu can escape the wrap and stay reachable;
     safe because table-layout:fixed keeps the table within the wrap — no horizontal scroll is needed. */
  .table-wrap { overflow: visible; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
  /* table-layout:fixed → columns fit the container instead of the auto-layout min-content that
     leaks past .table-wrap (paint-clipped by body{overflow-x:clip}, cutting off the last columns
     + row menus on a phone). Cells wrap; numeric cells stay on one line; the actions column is
     sized for the icon trigger. */
  /* separate + 0 spacing (not collapse) so the corner cells can take the wrap's radius — the header
     fill and the last-row hover otherwise poke square corners past the rounded border. */
  .table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; table-layout: fixed; }
  .table thead tr:first-child > th:first-child { border-top-left-radius: calc(var(--radius-lg) - 1px); }
  .table thead tr:first-child > th:last-child { border-top-right-radius: calc(var(--radius-lg) - 1px); }
  .table tbody tr:last-child > :first-child { border-bottom-left-radius: calc(var(--radius-lg) - 1px); }
  .table tbody tr:last-child > :last-child { border-bottom-right-radius: calc(var(--radius-lg) - 1px); }
  .table th, .table td { text-align: left; padding: 0.65rem 0.6rem; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
  .table th.num, .table td.num { white-space: nowrap; padding-inline: 0.4rem; font-variant-numeric: tabular-nums; }
  .table .col-actions { text-align: right; padding-inline: 2px 8px; }
  .table th { background: var(--table-head-bg); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover { background: var(--surface-2); }

  /* ---- badges ---- */
  .badges { display: flex; flex-wrap: wrap; gap: 0.55rem; }
  .badge { display: inline-flex; align-items: center; gap: 0.45em; padding: 0.42em 0.75em; font-size: 0.76rem; font-weight: 600; line-height: 1; border-radius: var(--radius-pill); border: 1px solid transparent; white-space: nowrap; }
  .badge .dot { width: 0.5em; height: 0.5em; border-radius: 50%; background: currentColor; }
  .badge-neutral { background: var(--surface-2); color: color-mix(in srgb, var(--muted) 70%, var(--ink)); border-color: var(--border); }
  .badge-secondary { color: color-mix(in srgb, var(--secondary) 40%, var(--ink)); background: color-mix(in srgb, var(--secondary) 15%, transparent); border-color: color-mix(in srgb, var(--secondary) 34%, transparent); }
  .badge-accent { color: var(--accent); background: var(--accent-weak); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
  /* status badge text is the status colour mixed toward --ink (like .badge-secondary): the raw --ok / --warn /
     --danger read at 1.4-3.2:1 on their own tint in light themes; these mixes clear 4.5:1 in every palette x theme */
  .badge-good { color: color-mix(in srgb, var(--ok) 55%, var(--ink)); background: color-mix(in srgb, var(--ok) 14%, transparent); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
  .badge-warn { color: color-mix(in srgb, var(--warn) 45%, var(--ink)); background: color-mix(in srgb, var(--warn) 16%, transparent); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
  .badge-critical { color: color-mix(in srgb, var(--danger) 60%, var(--ink)); background: color-mix(in srgb, var(--danger) 14%, transparent); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

  /* ---- tabs ---- */
  .tabs { display: flex; gap: 0.2rem; border-bottom: 1px solid var(--border); }
  .tab {
    appearance: none; background: transparent; border: 0; border-bottom: 2px solid transparent;
    color: var(--muted); font: inherit; font-weight: 600; font-size: 0.92rem; padding: 0.6rem 0.9rem;
    cursor: pointer; margin-bottom: -1px; transition: color var(--dur-fast), border-color var(--dur-fast);
  }
  .tab:hover { color: var(--ink); }
  .tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

  /* ---- toast ---- */
  .toast {
    display: flex; align-items: flex-start; gap: 0.7rem; max-width: 360px; padding: 0.9rem 1rem;
    background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
    border-radius: var(--radius); box-shadow: var(--shadow-2);
  }
  .toast-good { border-left-color: var(--ok); }
  .toast-warn { border-left-color: var(--warn); }
  .toast-critical { border-left-color: var(--danger); }
  .toast-title { font-weight: 600; font-size: 0.92rem; }
  .toast-body { font-size: 0.85rem; color: var(--muted); }

  /* ---- modal (native <dialog>) ---- */
  .modal {
    max-width: min(92vw, 520px); width: 100%; padding: 0; color: var(--ink); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-3);
  }
  .modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.2rem 1.4rem; border-bottom: 1px solid var(--border); }
  .modal-title { font-family: var(--font-display); font-weight: var(--display-weight); font-size: 1.25rem; letter-spacing: var(--display-tracking); }
  .modal-body { padding: 1.4rem; color: var(--muted); }
  .modal-foot { display: flex; justify-content: flex-end; gap: 0.6rem; padding: 1rem 1.4rem; border-top: 1px solid var(--border); }

  /* ---- content blocks (hero / band / group / footer) — reusable across marketing + guide ---- */
  .eyebrow { display: inline-block; font-family: var(--font-eyebrow); font-size: 0.76rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--eyebrow-ink); }
  .hero { background: var(--hero-bg); padding-block: clamp(3rem, 8vw, 6rem) clamp(2.5rem, 6vw, 4.5rem); }
  .hero-title { margin-block: 0.9rem 0.85rem; font-family: var(--font-display); font-weight: var(--display-weight); font-size: var(--fs-display); line-height: 1.04; letter-spacing: var(--display-tracking); text-wrap: balance; max-width: 20ch; }
  .hero-sub { max-width: 65ch; color: var(--muted); font-size: clamp(1.02rem, 1.4vw, 1.18rem); }
  .hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.7rem; }
  .band { --band-pad-y: clamp(2.5rem, 6vw, 4.5rem); padding-block: var(--band-pad-y); border-top: 1px solid var(--border); background: var(--band-bg); }
  .band-head { max-width: 60ch; margin-bottom: 2rem; }
  .band-title { margin-block: 0.7rem 0.6rem; font-family: var(--font-display); font-weight: var(--display-weight); font-size: clamp(1.7rem, 3.4vw, 2.4rem); letter-spacing: var(--display-tracking); text-wrap: balance; }
  .band-sub { color: var(--muted); }
  .band--tint { background: var(--band-tint-bg); }
  /* the cream/tan contrast band: --raised surface + --raised-ink text in every mode */
  .band--raised { background: var(--raised); color: var(--raised-ink); }
  .band--raised .band-sub, .band--raised .eyebrow { color: color-mix(in srgb, var(--raised-ink) 72%, var(--raised)); }
  /* semantic badge text can't clear AA on the cream — tone the pill to the band's ink, keep the dot semantic */
  .band--raised .badge { color: var(--raised-ink); background: color-mix(in srgb, var(--raised-ink) 8%, transparent); border-color: color-mix(in srgb, var(--raised-ink) 28%, transparent); }
  .band--raised .badge-good .dot { background: var(--ok); }
  .band--raised .badge-warn .dot { background: var(--warn); }
  .band--raised .badge-critical .dot { background: var(--danger); }
  /* the accent fill is near-invisible on the cream — primary becomes the solid dark chip (an accent-
     leaning raised-ink, raised text), tonal the quiet raised-ink outline, so primary stays strongest */
  .band--raised .btn-primary {
    --_fill: color-mix(in oklch, var(--accent) 22%, var(--raised-ink));
    background: var(--_fill); color: var(--raised); border-color: var(--_fill);
  }
  .band--raised .btn-primary:hover { background: color-mix(in oklch, var(--accent) 34%, var(--raised-ink)); }
  /* Hue anchor for the stat tint + raised CTA: when BOTH mix ends are near-grey (oklch C < 0.02) Chrome
     treats both hues as powerless and paints hue 0° (eucalyptus/fieldstone classic dark went pink-grey).
     Re-stating the tint through relative colour gives it a concrete hue for the grey end to take; every
     other palette/theme renders identically. @supports keeps the plain mix above where unsupported. */
  @supports (color: oklch(from red l c h)) {
    .stat { background: color-mix(in oklch, oklch(from var(--_tint) l c h) 8%, var(--surface)); }
    .band--raised .btn-primary { --_fill: color-mix(in oklch, oklch(from var(--accent) l c h) 22%, var(--raised-ink)); }
    .band--raised .btn-primary:hover { background: color-mix(in oklch, oklch(from var(--accent) l c h) 34%, var(--raised-ink)); }
    /* Vivid neutral: raised-ink is the vivid (brown-leaning) bg, so an accent mix into it went khaki on the
       yellow accents — fill from the GREY canvas instead (charcoal chip, accent text); hover lifts in L only */
    :root[data-theme="dark-vivid-neutral"] .band--raised .btn-primary { --_fill: var(--tint-base-bg); color: var(--accent); }
    :root[data-theme="dark-vivid-neutral"] .band--raised .btn-primary:hover { background: color-mix(in oklch, #ffffff 8%, var(--tint-base-bg)); }
    /* contrast-safe eyebrow (hero, bands, tints, sidebar): keep its hue + chroma, clamp only the lightness
       (theme-scoped bounds in tokens.css) so it clears 4.5:1 over the page's bg-family surfaces and both hero
       stops; inks already past the bound are untouched. .band--raised .eyebrow keeps its own ink (higher
       specificity). */
    .eyebrow { color: oklch(from var(--eyebrow-ink) clamp(var(--eyebrow-l-min), l, var(--eyebrow-l-max)) c h); }
  }
  .band--raised .btn-tonal {
    background: color-mix(in srgb, var(--raised-ink) 7%, transparent); color: var(--raised-ink);
    border-color: color-mix(in srgb, var(--raised-ink) 30%, transparent);
  }
  .band--raised .btn-tonal:hover { background: color-mix(in srgb, var(--raised-ink) 13%, transparent); }
  .group { padding-block: 2rem; border-top: 1px solid var(--border); }
  .group:first-of-type { border-top: 0; padding-top: 0; }
  .group-title { font-family: var(--font-mono); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 1.1rem; }
  .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
  .cluster + .cluster { margin-top: 1.1rem; }
  .cluster-label { width: 100%; font-size: 0.8rem; color: var(--muted); }
  .note { margin-top: 1.1rem; font-size: 0.78rem; color: var(--muted); font-style: italic; }
  .footer { border-top: 1px solid var(--border); background: var(--footer-bg); padding-block: 3rem 2.5rem; }
  .footer-grid { display: grid; grid-template-columns: 1.5fr 1fr 1fr 1fr; gap: 2rem; }
  .footer-tag { color: var(--muted); font-size: 0.9rem; max-width: 32ch; margin-top: 0.7rem; }
  .footer-col h4 { margin: 0 0 0.85rem; font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
  .footer-col ul { list-style: none; display: flex; flex-direction: column; gap: 0.55rem; padding: 0; }
  .footer-col a { color: var(--muted); font-size: 0.92rem; }
  .footer-col a:hover { color: var(--ink); }
  .footer-fine { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; justify-content: space-between; color: var(--muted); font-size: 0.82rem; }

  /* ---- responsive nav ---- */
  @media (max-width: 860px) { .footer-grid { grid-template-columns: 1fr 1fr; } .cards { grid-template-columns: 1fr; } }
  @media (max-width: 720px) {
    .nav-toggle { display: inline-flex; }
    .nav-menu {
      position: absolute; left: 0; right: 0; top: 100%; flex-direction: column; align-items: stretch;
      gap: 0.25rem; margin: 0; padding: 1rem var(--gutter) 1.2rem; background: var(--surface);
      border-bottom: 1px solid var(--border); box-shadow: var(--shadow-2); display: none;
    }
    .nav-menu.is-open { display: flex; }
    .nav-links { flex-direction: column; align-items: stretch; }
    .nav-links a { padding: 0.7rem 0.8rem; }
    .dropdown--nav, .dropdown--nav .dropdown-trigger { width: 100%; }
    .dropdown--nav .dropdown-trigger { justify-content: space-between; border: 1px solid var(--border); }
    .dropdown--nav .dropdown-menu { position: static; box-shadow: none; margin-top: 0.25rem; border-radius: var(--radius); width: 100%; max-width: none; }
    .nav-actions .user-menu, .nav-actions .user-menu .dropdown-menu { width: 100%; }
    .nav-actions .user-menu .dropdown-menu { position: static; box-shadow: none; margin-top: 0.25rem; }
    .nav-actions { margin: 0.4rem 0 0; }
    .nav-actions .btn { flex: 1; }
    /* Below 720px table-layout:fixed over-compresses multi-column tables and
       overflow-wrap:anywhere then breaks words mid-word ("SERVIC/E",
       "Operatio/nal"). Let columns size to content and scroll the wrap
       horizontally instead — no mid-word breaks, and the wrap (position:relative
       so absolutely-positioned cell content resolves against it, not the page)
       keeps any overflow inside the scroller, so the page never scrolls. */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; position: relative; }
    .table { table-layout: auto; }
    .table th, .table td { overflow-wrap: normal; white-space: nowrap; }
  }
  @media (max-width: 560px) { .footer-grid { grid-template-columns: 1fr; } .hero-actions .btn { flex: 1 1 auto; } }

  /* ---- layout-state overrides of component classes (.eyebrow, .user-menu .dropdown-trigger, global `a`) ----
     They live HERE, in the top-level sg.components layer, because layouts.css is imported with
     layer(sg.layout): any @layer block inside it becomes a sg.layout.* sub-layer that loses to this file.
     Same layer + higher specificity / later order = they win, without !important. */
  .app-sidebar-foot .user-menu .dropdown-trigger { width: 100%; min-width: 0; max-width: 100%; justify-content: flex-start; gap: 0.6rem; border-radius: var(--radius); padding: 0.3rem 0.4rem; }
  .layout-app[data-sidebar="collapsed"] .app-nav-label,
  .layout-app[data-sidebar="collapsed"] .app-sidebar-head-label,
  .layout-app[data-sidebar="collapsed"] .app-user-text { display: none; }
  .layout-app[data-sidebar="collapsed"] .app-sidebar-foot .user-menu .dropdown-trigger { justify-content: center; padding: 3px; }
  /* sidebar-only shell, strip mode (<=860px): every collapsed-state hide is undone, the menu drops DOWN from the top-right avatar */
  @media (max-width: 860px) {
    .layout-app--full .app-sidebar-foot .user-menu .dropdown-trigger { width: auto; padding: 3px; }
    .layout-app--full .app-sidebar-head [data-sidebar-toggle],
    .layout-app--full .app-sidebar-foot .app-user-text { display: none; }   /* a strip has nothing to collapse */
    .layout-app--full .user-menu--up .dropdown-menu { top: calc(100% + 0.35rem); bottom: auto; left: auto; right: 0; }
    .layout-app--full[data-sidebar] .app-sidebar { display: grid; }
    .layout-app--full[data-sidebar] .app-nav-label { display: inline; }
    .layout-app--full[data-sidebar] .app-sidebar-head-label { display: inline; }
  }
  .settings-nav a { color: var(--muted); }
  .settings-nav a:hover { color: var(--ink); }
  .settings-nav a[aria-current="true"] { color: color-mix(in srgb, var(--accent) 45%, var(--ink)); }   /* ink-weighted: readable on accent-weak even when the accent is pale (Ember) */
  .doc-toc a { color: var(--muted); padding-left: 0.55rem; }   /* room between the active marker and its label */
  .doc-toc a:hover { color: var(--ink); }
  .doc-toc a[aria-current="true"] { color: var(--accent); font-weight: 600; box-shadow: -0.7rem 0 0 -0.45rem var(--accent); }
  .pref-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.7rem 1rem; }
  .setting-row > .pref-controls { margin-left: auto; }   /* stays right-aligned when a narrow row wraps it below the copy */
  .pref-controls .nav-toggle { display: inline-flex; }   /* a hamburger preview inside a settings row stays visible at every width */
}
