/* ============================================================
   components.css — reusable pieces, shared by every screen.

   PHASE 1 scope: the components that already existed across the
   templates, moved onto tokens and deduplicated. The full set the
   direction calls for (voice-row, tier-selector, credit-meter,
   toast, empty-state, progress-row) is built out in PHASE 2.

   Radius is chosen by surface size, never by taste:
   tag 2 -> input 6 -> button 10 -> card 14 -> panel 20.
   Fully round belongs to the ribbon alone.
   ============================================================ */

/* ---- buttons -------------------------------------------------
   Exactly one filled --signal button per screen. Everything else
   is a ghost. .btn on its own is the ghost, so a template has to
   ask for the primary explicitly and the count stays visible. */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
  border-radius: var(--radius-button);
  border: var(--border-width) solid var(--line-control);
  background: transparent;
  color: var(--tx);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
/* Every state restates its own colour. A button is often an <a>, and the
   generic a:hover rule in base.css is (0,1,1) - it outranks a bare .btn
   (0,1,0) and would repaint the label mid-hover. It cannot outrank these,
   which are (0,2,0). Leaving colour out here is what made the primary
   button's text vanish into its own hover background. */
.btn:hover { background: var(--surface-sunken); color: var(--tx); }

.btn--primary {
  background: var(--signal-solid);
  border-color: var(--signal-solid);
  color: var(--signal-on);
}
.btn--primary:hover {
  background: var(--signal-solid-hover);
  border-color: var(--signal-solid-hover);
  color: var(--signal-on);
}

.btn--danger { border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger-bg); color: var(--danger); }

/* A button that reads as a link. Still a button, so it still gets the
   focus ring and the touch target from tokens.css. */
.btn--quiet {
  border-color: transparent; background: none; color: var(--tx-muted);
  padding: var(--space-2) var(--space-3);
}
.btn--quiet:hover { background: var(--surface-sunken); color: var(--tx); }

.btn:disabled, .btn[aria-disabled="true"] {
  color: var(--tx-faint);
  border-color: var(--line);
  background: transparent;
  cursor: not-allowed;
}
.btn--primary:disabled, .btn--primary[aria-disabled="true"] {
  background: var(--surface-sunken); border-color: var(--line);
}

/* One step heavier than the rest of the button set. Reserved for the single
   action a screen exists to perform. */
.btn--strong { font-weight: var(--weight-display); }

.btn--sm { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }
.btn--lg { padding: var(--space-4) var(--space-8); font-size: var(--text-md); }
.btn--block { width: 100%; }

/* Icon-only control. Needs a label for screen readers — see .sr-only. */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border-radius: var(--radius-input);
  border: var(--border-width) solid var(--line);
  background: transparent; color: var(--tx-muted);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.icon-btn:hover {
  background: var(--surface-sunken);
  border-color: var(--line-control);
  color: var(--tx);
}

/* ---- form fields ---------------------------------------------
   The border is what identifies the control: the sunken fill sits
   only ~1.1:1 from the canvas in both modes, so --line-control is
   required here, not --line. */
input[type="text"], input[type="email"], input[type="password"],
input[type="search"], input[type="url"], select, textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  color: var(--tx);
  background: var(--surface-sunken);
  border: var(--border-width) solid var(--line-control);
  border-radius: var(--radius-input);
  transition: border-color var(--dur-fast) var(--ease-out);
}
input:hover, select:hover, textarea:hover { border-color: var(--tx-faint); }
/* No `outline: none` here. `input:focus` is (0,1,1) and the :focus-visible
   rule in tokens.css is (0,1,0), so killing the outline on :focus would
   outrank it and leave text fields with a colour-only focus cue - which is
   the exact thing the checklist forbids. The border change stays as a
   second, redundant signal. */
input:focus, select:focus, textarea:focus { border-color: var(--signal); }
input::placeholder, textarea::placeholder { color: var(--tx-muted); opacity: 1; }

textarea { resize: vertical; }
select { cursor: pointer; }
option { color: var(--tx); background: var(--surface-raised); }
optgroup { color: var(--tx-muted); font-style: normal; }

input[type="checkbox"], input[type="radio"] {
  width: 16px; height: 16px; accent-color: var(--signal); cursor: pointer;
}
/* ---- range slider --------------------------------------------
   A thin track with the travelled portion filled, and a solid
   circular thumb - the shape a JS delivery control reads as, not
   a raw browser default. --fill is written by the component's own
   JS as a percentage (see studio.js bindSlider/updateSliderFill);
   custom properties inherit into the pseudo-elements below, which
   is what lets the fill and the thumb agree without JS touching
   the track itself. */
input[type="range"] {
  --fill: 0%;
  width: 100%; height: 24px; margin: 0;
  padding: 0; background: none; border: none;
  appearance: none; -webkit-appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: var(--radius-tag);
  background: linear-gradient(to right,
    var(--signal-solid) var(--fill),
    var(--line-strong) var(--fill));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; margin-top: -6px;
  border-radius: 50%;
  background: var(--signal-solid);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-card);
  transition: transform var(--dur-fast) var(--ease-out);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.1); }

input[type="range"]::-moz-range-track {
  height: 4px; border-radius: var(--radius-tag); background: var(--line-strong);
}
/* Firefox fills the travelled portion natively through this pseudo-element -
   no --fill needed on this engine. */
input[type="range"]::-moz-range-progress {
  height: 4px; border-radius: var(--radius-tag); background: var(--signal-solid);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--signal-solid);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-card);
}

.field { margin: 0 0 var(--space-4); }
.field > label {
  display: block; margin: 0 0 var(--space-2);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--tx-muted);
}
.field .hint { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--tx-muted); }
.field .error { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--danger); }
.field.has-error input,
.field.has-error textarea { border-color: var(--danger); }

.checkline {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-sm); color: var(--tx-muted);
}

/* Explanatory copy under a control, and secondary paragraph copy. Both
   replace inline styles that named tokens which no longer exist. */
.field-hint {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
  color: var(--tx-muted);
}
.muted-copy { color: var(--tx-muted); font-size: var(--text-sm); }

/* ---- surfaces ------------------------------------------------ */
.card {
  background: var(--surface);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.panel {
  background: var(--surface);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-panel);
}

/* ---- badges --------------------------------------------------
   Amber means it carries sound. Teal means sealed. Red means
   failed or destructive. Everything else is neutral on purpose. */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-tag);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.04em;
  border: var(--border-width) solid var(--line);
  color: var(--tx-muted);
  background: var(--surface-sunken);
}
.badge--signal { color: var(--signal-text); background: var(--signal-bg); border-color: var(--signal-line); }
.badge--seal   { color: var(--seal);        background: var(--seal-bg);   border-color: var(--seal-line); }
.badge--danger { color: var(--danger);      background: var(--danger-bg); border-color: var(--danger-line); }

/* ---- status notes --------------------------------------------
   Normal is quiet. Only a problem gets colour — that keeps the
   palette meaningful and keeps the states apart in greyscale. */
.note {
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-input);
  background: var(--surface-sunken);
  color: var(--tx-muted);
  font-size: var(--text-sm);
}
.note--warn   { border-color: var(--warn);   background: var(--warn-bg);   color: var(--warn); }
.note--danger { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger); }
.note--seal   { border-color: var(--seal-line);   background: var(--seal-bg);   color: var(--seal); }

/* ---- brand mark ----------------------------------------------
   Four bars today. The direction asks for five bars and one seam -
   the take ribbon reduced to a wordmark - which lands in PHASE 3
   alongside the ribbon itself, so the two stay one shape. */
.brand-link {
  display: inline-flex; align-items: center; gap: var(--space-3);
  text-decoration: none; color: var(--tx);
}
.brand-link:hover { color: var(--tx); }
.logo-mark { display: flex; align-items: flex-end; gap: 3px; height: 18px; flex: none; }
.logo-mark span { width: 4px; background: var(--signal); border-radius: var(--radius-tag); }
.logo-mark span:nth-child(1) { height: 45%; }
.logo-mark span:nth-child(2) { height: 100%; }
.logo-mark span:nth-child(3) { height: 65%; }
.logo-mark span:nth-child(4) { height: 85%; }
.wordmark {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: var(--weight-display);
  letter-spacing: var(--tracking-display);
}

/* ---- theme toggle --------------------------------------------
   Server-rendered: the icon shown follows the resolved theme, and
   both icons exist in the DOM so no JS is needed to swap them. */
.theme-toggle .icon-sun, .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .icon-sun { display: block; }
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .theme-toggle .icon-moon { display: block; }
}

/* ---- modal ---------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: var(--scrim);
  display: none; align-items: flex-start; justify-content: center;
  padding: 6vh var(--space-4);
}
.modal-backdrop.is-open { display: flex; }
.modal {
  position: relative;
  width: min(640px, 100%);
  max-height: 86vh;
  overflow: auto;
  padding: var(--space-6);
  background: var(--surface-raised);
  border: var(--border-width) solid var(--line-control);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-panel);
}
/* The close control is absolutely positioned, so the heading has to keep its
   corner clear or a long title runs underneath it, and whatever follows the
   heading has to start below it rather than beside it. */
.modal h2 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-1);
  padding-right: var(--space-10);
}
.modal .modal-sub {
  margin: 0 0 var(--space-4);
  color: var(--tx-muted); font-size: var(--text-sm);
}
.modal h2 + *:not(.modal-sub) { margin-top: var(--space-5); }
.modal .modal-close { position: absolute; top: var(--space-3); right: var(--space-3); }
.modal--narrow { width: min(420px, 100%); }
.modal-actions {
  display: flex; justify-content: flex-end; gap: var(--space-2);
  margin-top: var(--space-5);
}

/* A ledger line inside a dialog: label left, value right. Used by the
   confirm-before-generate step, where the whole point is that the numbers
   line up and can be read down the column. */
.confirm-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  font-size: var(--text-sm);
  color: var(--tx-muted);
}
.confirm-row > span:last-child { color: var(--tx); text-align: right; }
.confirm-row--total {
  margin-top: var(--space-2);
  padding-top: var(--space-3);
  border-top: var(--border-width) solid var(--line);
  font-weight: var(--weight-medium);
}

/* ---- voice row -----------------------------------------------
   Selection is carried by the border and the radio dot, never by a
   filled background: a filled row would read as "playing", and
   amber has to keep meaning sound. */
.voice-row {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; padding: var(--space-3);
  text-align: left; font-family: inherit; font-size: var(--text-base);
  background: var(--surface);
  color: var(--tx);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-card);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.voice-row + .voice-row { margin-top: var(--space-2); }
.voice-row:hover { border-color: var(--line-control); }
.voice-row.is-selected { border-color: var(--signal); }
.voice-row[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.voice-row .voice-dot {
  width: 12px; height: 12px; flex: none;
  border-radius: 50%;
  border: 2px solid var(--line-control);
}
.voice-row.is-selected .voice-dot {
  border-color: var(--signal); background: var(--signal);
  box-shadow: inset 0 0 0 2px var(--surface);
}
.voice-row .voice-info { flex: 1; min-width: 0; }
/* Both are <span> in the markup so the whole row can stay one <button>.
   Without display:block they share a line and text-overflow has nothing to
   clip against, which pushes the row wider than its container. */
.voice-row .voice-name { display: block; font-weight: var(--weight-medium); }
.voice-row .voice-desc {
  display: block;
  font-size: var(--text-xs); color: var(--tx-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Round because it plays sound - the one place roundness is earned
   outside the ribbon is the control that starts it. */
.voice-row .voice-play {
  width: 32px; height: 32px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: var(--border-width) solid var(--line-control);
  background: transparent; color: var(--tx-muted);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}
.voice-row .voice-play:hover { border-color: var(--signal); color: var(--signal-text); }
.voice-row .voice-play.is-playing {
  background: var(--signal-solid); border-color: var(--signal-solid); color: var(--signal-on);
}
.voice-row .voice-play .icon { width: 13px; height: 13px; }
.voice-row .voice-play .icon-pause,
.voice-row .voice-play.is-playing .icon-play { display: none; }
.voice-row .voice-play.is-playing .icon-pause { display: block; }
.voice-row .voice-play[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; }

/* ---- tier selector -------------------------------------------
   Three slots. The selected one is marked by border, tint and its
   own label, so it survives greyscale and colour-blind mode. */
.tier-selector { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.tier {
  position: relative;
  padding: var(--space-4) var(--space-3);
  text-align: center; font-family: inherit;
  background: var(--surface);
  color: var(--tx);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-card);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.tier:hover { border-color: var(--line-control); }
.tier.is-selected { border-color: var(--signal); background: var(--signal-bg); }
.tier[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.tier .tier-name {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: var(--weight-display);
}
.tier .tier-mult {
  display: block; margin-top: 2px;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--signal-text);
}
.tier .tier-tag {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  padding: 1px var(--space-2);
  background: var(--signal-solid); color: var(--signal-on);
  border-radius: var(--radius-tag);
  white-space: nowrap;
}

/* ---- credit meter --------------------------------------------
   Credits are a count of sound, so this is allowed amber. It is
   not an action, so it never becomes a filled button. */
.credit-meter {
  display: flex; flex-direction: column; gap: var(--space-2);
  min-width: 190px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-sunken);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-card);
}
.credit-meter .meter-line {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3);
}
.credit-meter .meter-plan {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--tx-muted);
}
.credit-meter .meter-left { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.credit-meter .meter-track {
  height: 4px; border-radius: var(--radius-tag);
  background: var(--canvas); overflow: hidden;
}
.credit-meter .meter-fill {
  height: 100%; width: 0; background: var(--signal);
  transition: width var(--dur-slow) var(--ease-out);
}
.credit-meter.is-low .meter-fill { background: var(--warn); }
.credit-meter.is-empty .meter-fill { background: var(--danger); }
.credit-meter.is-empty .meter-left { color: var(--danger); }

/* ---- progress row --------------------------------------------
   One line per file in a batch: what it is, where it got to. */
.progress-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: var(--border-width) solid var(--line);
}
.progress-row:last-child { border-bottom: none; }
.progress-row .progress-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Shrinkable, not fixed: at 375px a rigid 140px track plus the filename and
   the percentage cannot fit, and the row would push the page sideways. */
.progress-row .progress-track {
  flex: 0 1 140px; min-width: 48px; height: 6px;
  border-radius: var(--radius-tag);
  background: var(--surface-sunken); overflow: hidden;
}
.progress-row .progress-fill { height: 100%; background: var(--signal); }
.progress-row.is-failed .progress-fill { background: var(--danger); }
.progress-row.is-done .progress-fill { background: var(--seal); }
.progress-row .progress-pct {
  width: 4ch; flex: none; text-align: right;
  font-size: var(--text-xs); color: var(--tx-muted);
}

/* ---- toast ---------------------------------------------------
   Stacked bottom-right, above the ribbon dock. The close control
   is a real button so it is reachable by keyboard; auto-dismiss
   alone would strand anyone reading with a screen reader. */
.toast-stack {
  position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 100;
  display: flex; flex-direction: column-reverse; gap: var(--space-2);
  max-width: min(380px, calc(100vw - var(--space-8)));
}
body.has-ribbon .toast-stack { bottom: calc(84px + var(--space-4)); }
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-raised);
  color: var(--tx);
  border: var(--border-width) solid var(--line-control);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-raised);
}
.toast .toast-body { flex: 1; min-width: 0; font-size: var(--text-sm); }
.toast .toast-close {
  flex: none; width: 24px; height: 24px; min-width: 24px; min-height: 24px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; border: none; background: none;
  color: var(--tx-muted); cursor: pointer;
  border-radius: var(--radius-tag);
}
.toast .toast-close:hover { color: var(--tx); background: var(--surface-sunken); }
/* The left edge carries the meaning, and each variant also names its
   state in the text, so colour is never the only signal. */
.toast--seal   { border-left: 3px solid var(--seal); }
.toast--warn   { border-left: 3px solid var(--warn); }
.toast--danger { border-left: 3px solid var(--danger); }
.toast--signal { border-left: 3px solid var(--signal); }

/* ---- tables --------------------------------------------------
   Always inside a wrapper that scrolls on its own, so the page
   itself never scrolls sideways. */
/* A table scrolls inside its own wrapper, never by moving the page.
   min-width:0 is the part that makes that true: as a grid or flex child the
   wrapper's automatic minimum size is its content, so without this it grows
   to the table's width and takes the page sideways with it. */
.table-wrap { overflow-x: auto; min-width: 0; max-width: 100%; position: relative; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td {
  text-align: left; padding: var(--space-3) var(--space-2);
  border-bottom: var(--border-width) solid var(--line);
}
th {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  font-weight: var(--weight-medium);
  color: var(--tx-muted);
}
td.num, th.num { text-align: right; }

/* ---- empty state ---------------------------------------------
   An invitation with the action attached, never a report that
   something is missing. */
.empty-state {
  padding: var(--space-12) var(--space-6);
  text-align: center;
}
.empty-state h2 { margin-bottom: var(--space-2); }
.empty-state p {
  margin: 0 auto var(--space-5);
  max-width: 44ch;
  color: var(--tx-muted);
}
