/* design/interactive/components.css — the REFERENCE IMPLEMENTATION of every component
   in the spec. Inlined into styleguide.html so the examples are real, working controls;
   written so export.html can adopt it wholesale. Semantic tokens only — audit.mjs rules.
   Class prefix kx- (Keswick). Native elements first: details/summary, radio, checkbox,
   range — JS (components.js) only where HTML alone cannot (slider↔number sync). */

/* ---------- box model: every kx component is border-box ----------
   The reference CSS may be inlined into pages without a global reset (the styleguide
   is one); without this the summary row's padding inflates it past size.row-min and
   every center calculation lands a few px off. */
.kx-demo, .kx-demo *, [class*="kx-"], [class*="kx-"] * { box-sizing: border-box; }

/* ---------- focus: one ring everywhere ---------- */
.kx :focus-visible, [class*="kx-"]:focus-visible {
  outline: var(--border-width-focus) solid var(--color-border-focus);
  outline-offset: var(--size-focus-offset);
}

/* ---------- buttons (option D — crest & cream) ---------- */
.kx-btn {
  font-family: var(--font-body); font-size: var(--font-size-body);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  height: var(--size-control-md); padding: 0 var(--space-md);
  border-radius: var(--radius-control); cursor: pointer;
  border: var(--border-width-hairline) solid transparent;
  background: none; color: var(--color-text-primary);
  transition: background var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast), transform 50ms;
}
.kx-btn:active { transform: translateY(1px); }
.kx-btn:disabled { cursor: default; pointer-events: none; color: var(--color-text-disabled); border-color: var(--color-border-subtle); background: none; }
.kx-btn svg { flex: none; }
/* Navigation drawn as a button (an <a> wearing .kx-btn — patterns/navigation: navigation
   is a link): the anchor's own underline and link color must not leak through. */
a.kx-btn { text-decoration: none; }

.kx-btn--primary { background: var(--color-action-primary); color: var(--color-action-primary-text); font-weight: var(--font-weight-semibold); }
.kx-btn--primary:hover { background: var(--color-action-primary-hover); }
.kx-btn--lg { height: var(--size-control-lg); font-size: var(--font-size-title); padding: 0 var(--space-lg); }
.kx-btn--sm { height: var(--size-control-sm); font-size: var(--font-size-small); padding: 0 var(--space-sm); }

/* Secondary: cream fill, crest label. The edge is border.control at rest — the cream
   fill alone cannot carry SC 1.4.11 against a white card — and moves to crest on hover. */
.kx-btn--secondary { background: var(--color-action-secondary); color: var(--color-action-secondary-text);
  border-color: var(--color-border-control); font-weight: var(--font-weight-medium); }
.kx-btn--secondary:hover { border-color: var(--color-action-secondary-hover); }

/* Microsoft: "Sign in with Microsoft" in Microsoft's own button (their branding guidelines:
   the four-color mark, never one color, never inside a filled shape of ours). The mark is
   the caller's <img>; the fill is theirs; like secondary, hover moves only the edge. */
.kx-btn--microsoft { background: var(--color-action-microsoft); color: var(--color-action-microsoft-text);
  border-color: var(--color-action-microsoft-border); font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-body); gap: var(--space-sm); }
.kx-btn--microsoft:hover { border-color: var(--color-action-microsoft-text); }
.kx-btn--microsoft img { flex: none; display: block; }

.kx-btn--ghost { color: var(--color-text-action); }
.kx-btn--ghost:hover { background: var(--color-action-hover-wash); }

/* Destructive: outlined in D — cream fill, error ink. */
.kx-btn--destructive { background: var(--color-action-destructive); color: var(--color-action-destructive-text);
  border-color: var(--color-action-destructive-text); }
.kx-btn--destructive:hover { background: var(--color-feedback-error-bg); }

/* Loading: THE BUTTON THAT WAS PRESSED IS THE PROGRESS INDICATOR (2026-08-23). An
   action that finishes in a couple of seconds needs an indeterminate indicator and
   nothing more — percent-done and step lists only earn their place past ~10s
   (Nielsen's response-time limits) — and the feedback belongs at the point of action,
   not on a surface of its own. The LABEL names the work, because a spinner with no
   words is the Progress component's own first don't; the ring is the second voice,
   never the only one. Set `aria-busy`, swap the label, and guard the click: a real
   `disabled` would drop focus to the body, which inside a dialog loses the keyboard. */
.kx-btn[aria-busy="true"] { cursor: default; }
.kx-btn[aria-busy="true"]::before {
  content: ""; flex: none; width: 0.9em; height: 0.9em; border-radius: var(--radius-pill);
  border: var(--border-width-marker) solid currentColor; border-top-color: transparent;
  opacity: 0.75; animation: kx-spin var(--duration-spin) linear infinite;
}
/* The state must survive with motion off, so the ring stays and only the turning
   stops — the label is what carries the meaning either way. */
@media (prefers-reduced-motion: reduce) { .kx-btn[aria-busy="true"]::before { animation: none; } }
@keyframes kx-spin { to { transform: rotate(360deg); } }

/* ---------- input / select wells ---------- */
.kx-field { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2xs);
  font-family: var(--font-body); font-size: var(--font-size-small); color: var(--color-text-secondary); }
.kx-well, .kx-select {
  height: var(--size-control-md); padding: 0 var(--space-sm);
  background: var(--color-surface-sunken); color: var(--color-text-primary);
  border: var(--border-width-hairline) solid var(--color-border-control);
  border-radius: var(--radius-control);
  font-family: var(--font-body); font-size: var(--font-size-body);
  transition: border-color var(--duration-fast), background var(--duration-fast);
}
/* The compact size, for a field that lives INSIDE a dense row rather than in a form
   group — the inline rename on a features-list row, where the md height would grow the
   row it sits in. It exists as a named size because it was being spelled as a private
   `height:` on the page (2026-08-23); a page that needs a shorter control asks for one
   here, so "which heights does an Input have" has an answer. NOT for form rows: three
   controls stacked in a settings group are all md, or they step. */
/* HEIGHT ONLY — the type stays at the base size. A compact field is usually an inline
   edit standing in for text that is already on screen (a features-list row's name at
   font-size.row), and shrinking the type would make the field read smaller than the
   thing it replaces. */
.kx-well--sm { height: var(--size-control-sm); }
.kx-well:hover, .kx-select:hover { border-color: var(--color-border-strong); }
.kx-well:focus, .kx-select:focus { border-color: var(--color-border-focus); background: var(--color-surface-card); outline: none; }
.kx-well[aria-invalid="true"] { border: var(--border-width-focus) solid var(--color-feedback-error); }
.kx-well:disabled, .kx-select:disabled { color: var(--color-text-disabled); border-color: var(--color-border-subtle); }
/* A Select is one of the clickable set, so it wears the same pointer as Button, Chip,
   Segmented and Switch (2026-08-23 — a native <select> defaults to `cursor: default`,
   which made this the only control on the page that did not say it was clickable).
   A .kx-well is a TEXT field and keeps its caret. */
.kx-select { cursor: pointer; }
.kx-select:disabled { cursor: default; }
.kx-selectw { position: relative; display: inline-flex; }
.kx-selectw .kx-select { appearance: none; -webkit-appearance: none; padding-right: 40px; }
.kx-selectw .car { position: absolute; right: var(--space-xs); top: 50%; margin-top: -12px;
  width: 24px; height: 24px; display: grid; place-items: center;
  color: var(--color-text-subtle); pointer-events: none; }
.kx-selectw .kx-select:disabled ~ .car { color: var(--color-text-disabled); }
@supports selector(::picker(select)) {
  .kx-selectw .kx-select { appearance: base-select; display: inline-flex; align-items: center; }
  .kx-selectw .kx-select::picker-icon { display: none; }
  ::picker(select) { appearance: base-select; background: var(--color-surface-card);
    border: var(--border-width-hairline) solid var(--color-border-subtle);
    border-radius: var(--radius-control); box-shadow: var(--shadow-overlay);
    padding: var(--space-2xs); margin-top: var(--space-3xs); }
  .kx-selectw option { display: flex; align-items: center; align-content: center; gap: var(--space-xs);
    cursor: pointer;
    min-height: var(--size-control-sm); padding: var(--space-2xs) var(--space-sm); line-height: 1.2;
    border-radius: var(--radius-chip); font-family: var(--font-body);
    font-size: var(--font-size-body); color: var(--color-text-primary); }
  /* Grouped options (the export page's paper sizes): base-select makes an optgroup an
     ordinary block container, so the group heading is a real <legend> we style — a
     small caps label with a hairline above each group after the first. Classic
     pickers keep using the optgroup's `label` attribute and their own OS styling. */
  .kx-selectw optgroup { display: block; padding: 0; }
  .kx-selectw optgroup + optgroup,
  .kx-selectw optgroup + option { margin-top: var(--space-2xs); padding-top: var(--space-2xs);
    border-top: var(--border-width-hairline) solid var(--color-border-subtle); }
  .kx-selectw optgroup legend { padding: var(--space-3xs) var(--space-sm) var(--space-2xs);
    font-family: var(--font-body); font-size: var(--font-size-caption);
    font-weight: var(--font-weight-medium); letter-spacing: var(--letter-spacing-wide);
    text-transform: uppercase; color: var(--color-text-subtle); }
  .kx-selectw option:hover, .kx-selectw option:focus-visible { background: var(--color-action-hover-wash); }
  .kx-selectw option:checked { background: var(--color-state-selected-bg); color: var(--color-state-selected-text); }
  .kx-selectw option::checkmark { color: var(--color-state-selected-text); }
}
.kx-well--num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
input.kx-well::-webkit-outer-spin-button, input.kx-well::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input.kx-well[type="number"] { -moz-appearance: textfield; appearance: textfield; }
/* Color well: a native color input wearing the well — the swatch IS the value, so it
   fills the well edge to edge inside a slim frame of the sunken surface. */
.kx-well--color { padding: var(--space-3xs); height: var(--size-control-sm); cursor: pointer; }
.kx-well--color::-webkit-color-swatch-wrapper { padding: 0; }
.kx-well--color::-webkit-color-swatch { border: none; border-radius: var(--radius-chip); }
.kx-well--color::-moz-color-swatch { border: none; border-radius: var(--radius-chip); }
.kx-unitwell { display: inline-flex; align-items: center; gap: var(--space-2xs); height: var(--size-control-md);
  background: var(--color-surface-sunken); border: var(--border-width-hairline) solid var(--color-border-control);
  border-radius: var(--radius-control); padding: 0 var(--space-sm); }
.kx-unitwell:focus-within { border-color: var(--color-border-focus); background: var(--color-surface-card); }
/* "Spinners are suppressed" is the Input contract, but it was written against
   `input.kx-well` only — a unitwell's input is a BARE input inside the well span, so it
   kept the browser's stepper arrows and they printed on top of the unit. Every
   number-with-unit field wants this; nothing noticed because the Page zone's custom size
   uses `input.kx-well--num`, which the original selector already covered. */
.kx-unitwell input::-webkit-outer-spin-button,
.kx-unitwell input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.kx-unitwell input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.kx-unitwell input { border: 0; background: none; outline: none; width: 44px; color: var(--color-text-primary);
  font-family: var(--font-mono); font-size: var(--font-size-body); text-align: right; }
.kx-unitwell .unit { color: var(--color-text-subtle); font-size: var(--font-size-small); }
.kx-msg { display: block; margin-top: var(--space-2xs); font-size: var(--font-size-small); color: var(--color-feedback-error); }

/* ---------- checkbox rows ----------
   input.kx-check is the BOX on its own, for rows whose layout the app owns (the layer
   tree, the name checklist); .kx-checkrow is the ready-made label-wrapped row. */
.kx-checkrow { display: flex; align-items: center; gap: var(--space-sm); min-height: var(--size-row-min);
  padding: 0 var(--space-sm); border-radius: var(--radius-control); cursor: pointer;
  font-family: var(--font-body); font-size: var(--font-size-row); color: var(--color-text-primary); }
.kx-checkrow:hover { background: var(--color-action-hover-wash); }
.kx-checkrow input, input.kx-check { appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: 20px; height: 20px; border-radius: var(--radius-chip);
  border: var(--border-width-hairline) solid var(--color-border-control);
  background: var(--color-surface-card); display: grid; place-items: center; cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast); }
.kx-checkrow input:checked, .kx-checkrow input:indeterminate,
input.kx-check:checked, input.kx-check:indeterminate { background: var(--color-action-primary); border-color: var(--color-action-primary); }
.kx-checkrow input:checked::before, input.kx-check:checked::before {
  content: ""; width: 13px; height: 13px;
  background: var(--color-action-primary-text);
  clip-path: polygon(18% 46%, 8% 58%, 40% 86%, 92% 24%, 81% 15%, 39% 65%);
}
.kx-checkrow input:indeterminate::before, input.kx-check:indeterminate::before { content: ""; width: 11px; height: 2px; background: var(--color-action-primary-text); }
.kx-checkrow input:disabled, input.kx-check:disabled { border-color: var(--color-border-subtle); background: var(--color-surface-subtle); cursor: default; }
.kx-checkrow .hint { color: var(--color-text-subtle); font-size: var(--font-size-small); }
/* contextual rows hide whole (the flex display above would otherwise defeat [hidden]) */
.kx-checkrow[hidden] { display: none; }

/* ---------- switch rows ----------
   A standalone on/off SETTING with immediate effect (page elements, parking marks).
   The split is semantic (2026-08-21, dpolar): membership in a list of named things
   stays a Checkbox row; a setting row that applies NOW is a switch. Same DOM shape
   as .kx-checkrow — a label wrapping a real checkbox input — so app wiring
   (parentElement, .checked, onchange) is identical; the input IS the track, the
   thumb its ::before, and it sits at the END of the row (settings-list idiom). */
.kx-switchrow { display: flex; align-items: center; gap: var(--space-sm); min-height: var(--size-row-min);
  padding: 0 var(--space-sm); border-radius: var(--radius-control); cursor: pointer;
  font-family: var(--font-body); font-size: var(--font-size-row); color: var(--color-text-primary); }
.kx-switchrow:hover { background: var(--color-action-hover-wash); }
.kx-switchrow input { appearance: none; -webkit-appearance: none; margin: 0 0 0 auto; flex: none; order: 2;
  width: 36px; height: 21px; border-radius: var(--radius-pill); position: relative;
  border: var(--border-width-hairline) solid var(--color-border-control);
  background: var(--color-surface-sunken); cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast); }
/* the thumb: a hairline keeps it legible on the dark theme, where card-on-sunken
   alone is a low-contrast pair and shadow-raised barely reads */
.kx-switchrow input::before { content: ""; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: var(--radius-pill);
  background: var(--color-surface-card); box-shadow: var(--shadow-raised);
  border: var(--border-width-hairline) solid var(--color-border-control); box-sizing: border-box;
  transition: transform var(--duration-fast); }
.kx-switchrow input:checked { background: var(--color-action-primary); border-color: var(--color-action-primary); }
.kx-switchrow input:checked::before { transform: translateX(15px);
  background: var(--color-action-primary-text); border-color: var(--color-action-primary); }
.kx-switchrow input:focus-visible { outline: var(--border-width-focus) solid var(--color-border-focus);
  outline-offset: var(--size-focus-offset); }
.kx-switchrow input:disabled { border-color: var(--color-border-subtle); background: var(--color-surface-subtle); cursor: default; }
.kx-switchrow input:disabled::before { border-color: var(--color-border-subtle); box-shadow: none; }
.kx-switchrow .hint { color: var(--color-text-subtle); font-size: var(--font-size-small); }
/* contextual rows hide whole, same as .kx-checkrow */
.kx-switchrow[hidden] { display: none; }

/* ---------- segmented ---------- */
/* THE TRACK OWNS THE HEIGHT (2026-08-23). A seg had no height declaration at all —
   it came out at whatever padding + content produced, which was 42.25px in
   export.html's rail and 31.55px in its header, and never the 40px the spec has
   claimed since it was written. So a Segmented, an Input and a Select stacked in one
   settings group were three different heights. min-height + stretching segments is
   what fixes it: `min-height`, not `height`, so the rail's wrapping two-line label
   still grows the track, and stretch is what makes the SPAN take the track's height
   instead of setting it. The span's VERTICAL padding must therefore stay under the
   stretched height (space-2xs, not space-md's partner space-xs) — push it past and
   intrinsic content wins again and the track re-inflates. */
.kx-seg { display: inline-flex; align-items: stretch; box-sizing: border-box;
  min-height: var(--size-control-md);
  background: var(--color-surface-sunken); border-radius: var(--radius-control); padding: var(--space-3xs); }
.kx-seg label { position: relative; display: inline-flex; }
.kx-seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.kx-seg span { display: inline-flex; align-items: center; justify-content: center;
  padding: var(--space-2xs) var(--space-md); border-radius: var(--radius-chip);
  font-family: var(--font-body); font-size: var(--font-size-body); color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium); /* constant — selection may never change geometry */
  border: var(--border-width-hairline) solid transparent; transition: background var(--duration-fast), color var(--duration-fast); }
/* an icon+text segment centers both on one flex line — never baseline-staggered */
.kx-seg span svg { flex: none; }
.kx-seg label:hover input:not(:checked):not(:disabled) + span { background: var(--color-action-hover-wash); }
.kx-seg input:checked + span { background: var(--color-surface-card); color: var(--color-text-primary);
  box-shadow: var(--shadow-raised); border-color: var(--color-state-selected-border); }
.kx-seg input:focus-visible + span { outline: var(--border-width-focus) solid var(--color-border-focus); outline-offset: var(--size-focus-offset); }
.kx-seg input:disabled + span { color: var(--color-text-disabled); cursor: default; }
.kx-seg input:disabled { cursor: default; }

/* ---------- chips ---------- */
.kx-chips { display: flex; gap: var(--space-xs); align-items: center; flex-wrap: wrap; }
.kx-chip { position: relative; display: inline-flex; }
.kx-chip input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.kx-chip span { height: var(--size-control-sm); display: inline-flex; align-items: center; padding: 0 var(--space-md);
  border-radius: var(--radius-pill); border: var(--border-width-hairline) solid var(--color-border-control);
  color: var(--color-text-secondary); font-family: var(--font-body); font-size: var(--font-size-small);
  font-weight: var(--font-weight-medium); /* constant — see .kx-seg */
  transition: background var(--duration-fast), color var(--duration-fast), border-color var(--duration-fast); }
.kx-chip:hover input:not(:checked):not(:disabled) + span { background: var(--color-action-hover-wash); }
.kx-chip input:checked + span { background: var(--color-state-selected-bg); border-color: var(--color-state-selected-border);
  color: var(--color-state-selected-text); }
.kx-chip input:focus-visible + span { outline: var(--border-width-focus) solid var(--color-border-focus); outline-offset: var(--size-focus-offset); }
/* :not(:checked): the CUSTOM chip is checked+disabled — read-only, but it wears the
   selected treatment (chip spec's custom-pressed state), never the disabled gray */
.kx-chip input:disabled:not(:checked) + span { color: var(--color-text-disabled); border-color: var(--color-border-subtle); cursor: default; }
.kx-chip input:disabled { cursor: default; }
/* ONE idea, two mechanisms (2026-08-22, dpolar): a chip group of FIXED, short options
   inside a fixed-width container FILLS that width rather than packing left with a
   ragged edge. Both variants center their labels in tighter padding to buy the room.
   Use --fill when the set fits on one row, --grid when it cannot. Neither is for a set
   that can grow or holds a variable-length member (a Custom chip) — those keep the
   default wrap, which sizes each chip to its own label.

   Fill: the chips share one row. Five aspect chips overhung the 380px rail by a few
   pixels and orphaned "16:9" onto a line of its own; flex-grow spends the slack so the
   row ends flush at both edges. Wrapping still works and a wrapped line fills too. */
.kx-chips--fill .kx-chip { flex: 1 1 auto; min-width: 0; }
.kx-chips--fill .kx-chip span { flex: 1; justify-content: center; padding: 0 var(--space-xs); }
/* Grid: a set too wide for any one row becomes a regular block of `--chip-cols` equal
   columns (default 2) instead of a wrap whose two lines end at different places — the
   four parking treatments wrapped 2+2 and left ~100px ragged on both. Equal columns
   buy the regularity: a short label simply wears more air than a long one. */
.kx-chips--grid { display: grid; grid-template-columns: repeat(var(--chip-cols, 2), 1fr); }
.kx-chips--grid .kx-chip span { flex: 1; justify-content: center; padding: 0 var(--space-xs); }

/* Swatch chip: a chip whose value IS a color — the swatch is the WHOLE control, no
   pill shell (2026-08-21, dpolar: a rounded square inside a pill outline read as two
   competing shapes). The swatch's background is data (the artwork's own value),
   never a design token. Selected = selected-border ring with a card-colored inner
   gap, so it reads on any swatch color. */
.kx-chip--sw span { padding: 0; border: 0; background: none; height: auto;
  border-radius: var(--radius-chip); }
.kx-chip--sw b { width: 24px; height: 24px; display: block; border-radius: var(--radius-chip);
  border: var(--border-width-hairline) solid var(--color-border-control);
  transition: border-color var(--duration-fast); }
.kx-chip--sw:hover input:not(:checked):not(:disabled) + span { background: none; }
.kx-chip--sw:hover input:not(:checked):not(:disabled) + span b { border-color: var(--color-border-strong); }
.kx-chip--sw input:checked + span { background: none; border: 0; }
.kx-chip--sw input:checked + span b { border: var(--border-width-marker) solid var(--color-state-selected-border);
  box-shadow: inset 0 0 0 var(--border-width-hairline) var(--color-surface-card); }
/* the None swatch (an absent surface): the standard no-color mark — card with a slash */
.kx-chip--none b { background-color: var(--color-surface-card);
  background-image: linear-gradient(to top right, transparent calc(50% - 1px),
    var(--color-feedback-error) calc(50% - 1px), var(--color-feedback-error) calc(50% + 1px),
    transparent calc(50% + 1px)); }
/* swatch rows pack tighter than word chips — the values are small and numerous */
.kx-chips--sw { gap: var(--space-2xs); }

/* ---------- slider (+ paired number, synced by components.js) ---------- */
.kx-sliderrow { display: flex; align-items: center; gap: var(--space-sm); min-height: var(--size-row-min);
  font-family: var(--font-body); }
.kx-sliderrow > .lbl { flex: none; color: var(--color-text-secondary); font-size: var(--font-size-row); font-weight: var(--font-weight-medium); }
/* A range input inherits `cursor: default` like every other native control, so the
   track you can click and the thumb you can drag both said nothing (2026-08-23 — the
   same lapse the Select had, found by the audit's new cursor rule rather than by a
   hover). */
.kx-sliderrow input[type="range"] { flex: 1; min-width: 0; accent-color: var(--color-action-primary); height: 20px;
  cursor: pointer; }
.kx-sliderrow input[type="range"]:disabled { cursor: default; }
.kx-sliderrow output { flex: none; color: var(--color-text-primary); font-family: var(--font-mono); font-size: var(--font-size-small); min-width: 44px; text-align: right; }

/* ---------- summary rows / expanders (native details) ----------
   Disclosure geometry is ONE system: a 24px caret slot at right --space-xs, row
   padding-right 40px. The caret is centered in its slot, so nothing sits off-balance
   regardless of glyph. No per-row modified mark (the 2px gold bar went 2026-08-21,
   dpolar: an unexplained accent that read as noise) — the value shows the change,
   and history lives in the header undo/redo, never as a per-row button.
   An OPEN expander is a contained card: the whole details gets the subtle surface and
   an inset hairline ring, with a hairline between header and body — a left indent
   alone was not enough to say what belongs to the section (dpolar, 2026-08-21). */
.kx-srw { position: relative; }
details.kx-x { border-radius: var(--radius-control); }
details.kx-x[open] { background: var(--color-surface-subtle);
  box-shadow: inset 0 0 0 var(--border-width-hairline) var(--color-border-subtle); }
/* two open expander cards stacked need air between them (dpolar, 2026-08-21).
   margin-BOTTOM only (2026-08-22, dpolar): a margin-top here sits on the same .kx-srw
   whose <summary> it is, so opening a card pushed its own title down the instant it
   opened — the air belongs below an open card, never above it. */
.kx-srw:has(> details.kx-x[open]) { margin-bottom: var(--space-2xs); }
.kx-srw:last-child:has(> details.kx-x[open]) { margin-bottom: 0; }
details.kx-x > summary { list-style: none; cursor: pointer; }
details.kx-x > summary::-webkit-details-marker { display: none; }
.kx-srow { position: relative; display: flex; align-items: center; gap: var(--space-xs);
  min-height: var(--size-row-min); padding: var(--space-2xs) 40px var(--space-2xs) var(--space-sm);
  border-radius: var(--radius-control); font-family: var(--font-body); font-size: var(--font-size-row);
  transition: background var(--duration-fast); }
.kx-srow:hover { background: var(--color-action-hover-wash); }
/* the container carries the open surface; the header row stays transparent over it */
details.kx-x[open] > summary .kx-srow { background: none; }
.kx-srow .lbl { flex: none; color: var(--color-text-secondary); font-weight: var(--font-weight-medium); }
.kx-srow .val { flex: 1; min-width: 0; text-align: right; color: var(--color-text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kx-srow .car { position: absolute; right: var(--space-xs); top: 50%; margin-top: -12px;
  width: 24px; height: 24px; display: grid; place-items: center; color: var(--color-text-subtle);
  transition: transform var(--duration-base); }
details.kx-x[open] > summary .kx-srow .car { transform: rotate(180deg); }
.kx-xbody { padding: var(--space-sm); margin: 0;
  border-top: var(--border-width-hairline) solid var(--color-border-subtle);
  font-family: var(--font-body); font-size: var(--font-size-small); color: var(--color-text-secondary); }

/* ---------- zone ----------
   Each zone is a CARD (2026-08-21, dpolar: a heading and a hairline rule alone did
   not separate the rail's chapters strongly enough): surface-card on the page-tinted
   rail, hairline ring, surface radius. The header is the card's header and its one
   disclosure; the old mid-header rule is gone — the card edge now does that job.
   overflow:clip keeps the header's hover wash inside the radius, so the header's
   focus ring is drawn INSET. The host lays cards out (margins are the page's). */
details.kx-zone, .kx-zrw { background: var(--color-surface-card);
  border: var(--border-width-hairline) solid var(--color-border-subtle);
  border-radius: var(--radius-surface); box-shadow: var(--shadow-raised);
  overflow: clip; }
details.kx-zone > summary { list-style: none; cursor: pointer;
  padding: var(--space-xs) var(--space-sm); }
details.kx-zone > summary::-webkit-details-marker { display: none; }
details.kx-zone > summary:hover { background: var(--color-action-hover-wash); }
details.kx-zone > summary:focus-visible { outline: var(--border-width-focus) solid var(--color-border-focus);
  outline-offset: calc(-1 * var(--border-width-focus)); }
.kx-zhead { display: flex; align-items: center; gap: var(--space-xs); }
.kx-zhead b { flex: 1; min-width: 0; font-family: var(--font-display); font-size: var(--font-size-heading);
  font-weight: var(--font-weight-semibold); color: var(--color-text-primary); }
.kx-zhead .car { width: 24px; height: 24px; display: grid; place-items: center;
  color: var(--color-text-subtle); transition: transform var(--duration-base); }
details.kx-zone:not([open]) .kx-zhead .car { transform: rotate(-90deg); }
/* Zone-level drill-in: a whole zone that IS a summary row — the same card and header
   face, but a real button with a › caret and no expansion. Its face carries no value
   (2026-08-21, dpolar) — where it leads is the readout. */
.kx-zlink { display: block; width: 100%; border: 0; background: none;
  padding: var(--space-xs) var(--space-sm);
  font: inherit; color: inherit; text-align: left; cursor: pointer; }
.kx-zlink:hover { background: var(--color-action-hover-wash); }
.kx-zlink:focus-visible { outline: var(--border-width-focus) solid var(--color-border-focus);
  outline-offset: calc(-1 * var(--border-width-focus)); }
.kx-zhead .val { min-width: 0; max-width: 50%; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-family: var(--font-body); font-size: var(--font-size-row);
  font-weight: var(--font-weight-regular); color: var(--color-text-primary); }

/* ---------- gallery tiles ---------- */
.kx-gallery { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-xs); }
.kx-tile { position: relative; display: block; border-radius: var(--radius-control); overflow: hidden;
  border: var(--border-width-marker) solid var(--color-border-subtle); cursor: pointer;
  background: var(--color-surface-card); transition: border-color var(--duration-fast); }
.kx-tile:hover { border-color: var(--color-border-control); }
.kx-tile input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.kx-tile .thumb { height: 88px; display: grid; place-items: center; background: var(--color-surface-paper); }
.kx-tile .thumb.pending { background: var(--color-surface-subtle); font-family: var(--font-body);
  font-size: var(--font-size-caption); color: var(--color-text-subtle); }
.kx-tile .gnm { display: block; padding: var(--space-xs); font-family: var(--font-body); font-size: var(--font-size-small);
  color: var(--color-text-secondary); }
.kx-tile .gnm { font-weight: var(--font-weight-medium); } /* constant — selection never reflows */
.kx-tile:has(input:checked) { border-color: var(--color-state-selected-border); box-shadow: var(--shadow-raised); }
.kx-tile:has(input:checked) .gnm { color: var(--color-state-selected-text); }
.kx-tile:has(input:focus-visible) { outline: var(--border-width-focus) solid var(--color-border-focus); outline-offset: var(--size-focus-offset); }

/* ---------- changes chip ---------- */
details.kx-chipmod > summary { list-style: none; cursor: pointer; display: inline-flex; }
details.kx-chipmod > summary::-webkit-details-marker { display: none; }
.kx-chipmod-pill { height: var(--size-control-sm); display: inline-flex; align-items: center; gap: var(--space-2xs);
  padding: 0 var(--space-sm); border-radius: var(--radius-pill);
  background: var(--color-state-modified-bg); color: var(--color-state-modified-text);
  font-family: var(--font-body); font-size: var(--font-size-small); font-weight: var(--font-weight-medium); }
.kx-chipmod-pill .dot { width: 6px; height: 6px; border-radius: var(--radius-pill); background: var(--color-state-modified); }
.kx-chipmod-pill .car { display: grid; place-items: center; transition: transform var(--duration-base); }
details.kx-chipmod[open] .kx-chipmod-pill .car { transform: rotate(180deg); }
.kx-changelist { margin-top: var(--space-xs); background: var(--color-surface-card);
  border: var(--border-width-hairline) solid var(--color-border-subtle);
  border-radius: var(--radius-control); box-shadow: var(--shadow-panel); padding: var(--space-2xs); }
.kx-changeitem { display: flex; align-items: center; gap: var(--space-xs); min-height: var(--size-control-md); padding: 0 var(--space-xs); }
.kx-changeitem .what { flex: 1; font-family: var(--font-body); font-size: var(--font-size-small); color: var(--color-text-primary); }
.kx-changeitem .what small { color: var(--color-text-subtle); font-size: inherit; }
.kx-changeitem .x { flex: none; width: 24px; height: 24px; display: grid; place-items: center;
  border: 0; background: none; cursor: pointer; padding: 0;
  color: var(--color-state-modified); border-radius: var(--radius-chip); }
.kx-changeitem .x:hover { background: var(--color-state-modified-bg); }

/* ---------- toast / validation / progress ---------- */
.kx-toast { display: flex; align-items: center; gap: var(--space-sm);
  background: var(--color-surface-card); border: var(--border-width-hairline) solid var(--color-border-subtle);
  border-radius: var(--radius-control); box-shadow: var(--shadow-overlay);
  padding: var(--space-sm) var(--space-md); font-family: var(--font-body); }
.kx-toast .ico { flex: none; display: grid; place-items: center; }
.kx-toast .ico.ok { color: var(--color-feedback-success); }
.kx-toast .ico.err { color: var(--color-feedback-error); }
.kx-toast .msg { flex: 1; font-size: var(--font-size-small); color: var(--color-text-primary); }
.kx-note { display: flex; gap: var(--space-xs); border-radius: var(--radius-control);
  padding: var(--space-xs) var(--space-sm); font-family: var(--font-body); font-size: var(--font-size-small); }
.kx-note .ico { flex: none; display: grid; place-items: center; }
.kx-note--warn { background: var(--color-feedback-warning-bg); color: var(--color-feedback-warning); }
.kx-note--error { background: var(--color-feedback-error-bg); color: var(--color-feedback-error); }
.kx-note--info { color: var(--color-text-subtle); padding-left: 0; }

/* ---------- popover / dialog cards ---------- */
.kx-pop { background: var(--color-surface-card); border: var(--border-width-hairline) solid var(--color-border-subtle);
  border-radius: var(--radius-surface); box-shadow: var(--shadow-overlay); padding: var(--space-md);
  font-family: var(--font-body); }
.kx-pop .title { font-family: var(--font-display); font-size: var(--font-size-title);
  font-weight: var(--font-weight-semibold); color: var(--color-text-primary); margin-bottom: var(--space-2xs); }
.kx-pop .sub { font-size: var(--font-size-small); color: var(--color-text-secondary); margin-bottom: var(--space-md); }
.kx-pop .acts { display: flex; gap: var(--space-xs); justify-content: flex-end; }

/* A dialog with TWO exits (the export dialog's Print and Download) needs a way out
   that is neither of them, so the way out is a corner close and the footer carries
   only the exits. Absolute against the card, so the card is the containing block. */
.kx-pop { position: relative; }
.kx-pop:has(.x) .title { padding-right: var(--size-control-sm); }
.kx-pop .x { position: absolute; top: var(--space-sm); right: var(--space-sm);
  width: var(--size-control-sm); height: var(--size-control-sm); padding: 0; border: 0;
  display: grid; place-items: center; border-radius: var(--radius-control);
  background: none; color: var(--color-text-subtle); cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast); }
.kx-pop .x:hover { background: var(--color-action-hover-wash); color: var(--color-text-primary); }
.kx-pop .x:disabled { cursor: default; color: var(--color-text-disabled); background: none; }

/* ---------- demo scaffolding (styleguide only) ---------- */
.kx-demo { font-family: var(--font-body); background: var(--color-surface-page);
  padding: var(--space-md); border-radius: var(--radius-surface); }
.kx-demo--stage { background: var(--color-surface-stage); }
.kx-demo--card { background: var(--color-surface-card); }

@media (prefers-reduced-motion: reduce) {
  .kx-srow .car, .kx-zhead .car, .kx-chipmod-pill .car, .kx-btn, .kx-chip span, .kx-seg span,
  .kx-switchrow input, .kx-switchrow input::before { transition: none; }
}

/* ---------- mobile shell: bottom bar + bottom sheet ---------- */
.kx-bbar { display: flex; align-items: center; gap: var(--space-sm);
  padding: var(--space-xs) var(--space-md) calc(var(--space-xs) + env(safe-area-inset-bottom, 0px));
  min-height: var(--size-bottombar); background: var(--color-surface-card);
  border-top: var(--border-width-hairline) solid var(--color-border-subtle); }
.kx-bbar .kx-btn--primary { flex: 1; }
.kx-bsheet { background: var(--color-surface-card);
  border: var(--border-width-hairline) solid var(--color-border-subtle); border-bottom: 0;
  border-radius: var(--radius-surface) var(--radius-surface) 0 0; box-shadow: var(--shadow-overlay); }
.kx-bsheet .grab { display: block; width: var(--size-grabber); height: 4px; margin: var(--space-xs) auto;
  border-radius: var(--radius-pill); background: var(--color-border-control); }
.kx-bsheet .body { padding: 0 var(--space-sm) var(--space-sm); max-height: 46vh; overflow-y: auto; }
