/* components.css — visual building blocks.
 * Depends on tokens.css. */

/* ---------- Icon (Lucide-style inline SVG from lib/icons.js) ----------
 * The symbol pool ships stroke-based outlines. Without these defaults the
 * browser paints each <path> with the SVG default (fill:black, stroke:none),
 * so every icon reads as a solid black blob. fill:none + stroke:currentColor
 * renders crisp line icons that inherit the surrounding text colour. Symbols
 * that need a solid fill (i-play, the i-tag dot) carry their own
 * fill="currentColor" attribute, which overrides this base.
 * NB: size comes from the width/height attributes set by icon() — do not set
 * width/height here or every icon collapses to one size. */
.icon {
  display: inline-block;
  vertical-align: middle;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Button ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  min-height: 34px;
  padding: 0 var(--space-16);
  border: 1px solid transparent;
  border-radius: var(--radius-6);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard),
    color var(--dur-fast) var(--ease-standard),
    transform var(--dur-micro) var(--ease-standard);
}
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft-bg);
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn--primary {
  background: var(--accent);
  color: #ffffff;
}
.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn--secondary {
  background: transparent;
  border-color: var(--border-default);
  color: var(--text-secondary);
}
.btn--secondary:hover:not(:disabled) {
  border-color: var(--accent-soft-border);
  color: var(--text-primary);
}
.btn--danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn--ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-elevated);
}
.btn[data-state='saving'] {
  cursor: progress;
}
.btn[data-state='saving']::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
.btn[data-state='saved'] {
  color: var(--ok);
}
.btn[data-state='saved']::before {
  content: "✓";
  font-weight: var(--fw-bold);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- beautiful checkbox — unified on/off tick (Variant A) ---------- */
/* Base style for every REAL (visible) checkbox in the panel. The visually-hidden
   checkbox inside .vac-switch (pages.css, loaded AFTER this) overrides size/opacity
   and stays invisible under its custom track — so switches are unaffected.
   Checkmark is a layered background-image SVG (pseudo-elements on <input> are
   unreliable, esp. Safari). Transitions never fire on first paint, so pre-checked
   boxes render already ticked with no load flash. */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-6);
  background-color: var(--bg-input);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 0 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23fff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.4l3 3 6-6.6'/%3E%3C/svg%3E");
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard),
              background-size var(--dur-base) var(--ease-spring),
              box-shadow var(--dur-fast) var(--ease-standard),
              transform var(--dur-micro) var(--ease-standard);
}
input[type="checkbox"]:hover:not(:disabled) {
  border-color: var(--accent-soft-text);
}
input[type="checkbox"]:checked {
  background-color: var(--accent);
  border-color: transparent;
  background-size: 68% 68%;
}
input[type="checkbox"]:indeterminate {
  background-color: var(--accent);
  border-color: transparent;
  background-size: 62% 62%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' stroke='%23fff' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M4 8h8'/%3E%3C/svg%3E");
}
input[type="checkbox"]:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft-border);
}
input[type="checkbox"]:active:not(:disabled) {
  transform: scale(0.92);
}
input[type="checkbox"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
@media (prefers-reduced-motion: reduce) {
  input[type="checkbox"] {
    transition: border-color var(--dur-fast) var(--ease-standard),
                box-shadow var(--dur-fast) var(--ease-standard);
  }
}

/* ---------- Inputs ---------- */
.input,
.select,
.textarea {
  width: 100%;
  min-height: 34px;
  padding: var(--space-8) var(--space-12);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-6);
  color: var(--text-primary);
  font: inherit;
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent-soft-border);
  box-shadow: 0 0 0 2px var(--accent-soft-bg);
}
.textarea {
  min-height: 96px;
  resize: vertical;
}

/* ---------- Toggle ---------- */
.toggle {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  background: var(--border-default);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 150ms ease;
}
.toggle::after {
  content: "";
  position: absolute;
  /* top/left:2px = knob inset, coupled to the fixed 32×18 track + translateX(14px)
     checked geometry; snapping 2→4 would break centering — leave literal */
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 150ms ease;
}
.toggle[aria-checked="true"] {
  background: var(--ok);
}
.toggle[aria-checked="true"]::after {
  transform: translateX(14px);
}

/* ---------- Pill ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-8);
  border-radius: var(--radius-pill);
  font-size: var(--fs-label);
  font-weight: var(--fw-bold);
  letter-spacing: 0.3px;
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill--ok    { color: var(--ok);    background: var(--ok-soft-bg); }
.pill--warn  { color: var(--warn);  background: var(--warn-soft-bg); }
.pill--danger{ color: var(--danger);background: var(--danger-soft-bg); }
.pill--info  { color: var(--info);  background: var(--info-soft-bg); }
.pill--muted { color: var(--text-muted); background: var(--bg-elevated); }
.pill--accent{ color: var(--accent-soft-text); background: var(--accent-soft-bg); }

/* ---------- Card ---------- */
.card {
  position: relative;
  padding: var(--space-16);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-8);
}
.card--ok    { border-left: 3px solid var(--ok); }
.card--warn  { border-left: 3px solid var(--warn); }
.card--danger{ border-left: 3px solid var(--danger); }
.card__title { font-size: var(--fs-section); font-weight: var(--fw-bold); margin: 0 0 var(--space-8); }
.card__subtitle { color: var(--text-tertiary); font-size: var(--fs-secondary); }

/* ---------- Modal ---------- */
/* Backdrop, surface and title shell, the footer layout rule (plus its
   multi-action variant) and the danger-styled primary-button override all
   moved onto the shared overlay core (css/overlay.css, js/lib/overlay.js) —
   the old hand-rolled rules rendered onto no real node and were deleted
   (BB1 Phase 5; footer layout now comes from overlay__footer /
   overlay__footer--multi, danger styling from overlay--danger). The
   warn-banner below is still emitted as live content inside openModal()
   bodies (managers.js, operators.js, live-editor.js ×2), so it stays. */
.modal__warn-banner {
  padding: var(--space-12);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-6);
  color: var(--danger);
  font-size: var(--fs-label);
  margin-bottom: var(--space-12);
}

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed;
  top: var(--space-16);
  right: var(--space-16);
  display: flex;
  flex-direction: column;
  /* Above every overlay layer (modal 1300, popover 1400) in the --z-* ladder —
     a save error must stay visible while a dialog / mapping panel is open. */
  z-index: var(--z-toast);
}
/* Micro W2a — two persistent aria-live regions (assertive/danger, polite/
   everything else — see lib/toast.js ensureRegions()) laid out as plain flex
   children of .toast-stack so they read as one visual corner stack even
   though they're two separate live-region subtrees. Each region stacks its
   own toasts via `gap`; the :not(:empty) rule below adds spacing BETWEEN the
   two regions only when both actually hold a toast at once (an empty region
   is a childless div with zero height, so it never reserves a phantom gap
   when the other region is the only one in use — the common case). */
.toast-stack__region {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}
.toast-stack__region--assertive:not(:empty) + .toast-stack__region--polite:not(:empty) {
  margin-top: var(--space-8);
}
.toast {
  min-width: 280px;
  max-width: 380px;
  padding: var(--space-12) var(--space-16);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-8);
  box-shadow: var(--shadow-md);
  display: flex;
  gap: var(--space-12);
  align-items: flex-start;
}
.toast--ok    { border-left: 3px solid var(--ok); }
.toast--info  { border-left: 3px solid var(--info); }
.toast--warn  { border-left: 3px solid var(--warn); }
.toast--danger{ border-left: 3px solid var(--danger); }
.toast__title { font-weight: var(--fw-bold); margin: 0; }
.toast__body  { color: var(--text-tertiary); font-size: var(--fs-secondary); margin: var(--space-4) 0 0; }
/* D3 — dismiss button; pinned top-right regardless of content width (margin-left:
   auto eats any slack the flex `gap` doesn't need). */
.toast__close {
  flex-shrink: 0;
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: var(--radius-6);
  color: var(--text-muted);
  cursor: pointer;
}
.toast__close:hover { color: var(--text-primary); background: var(--bg-input); }
.toast__close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toast__close svg { display: block; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: var(--space-24);
  border-bottom: 1px solid var(--border-subtle);
}
.tabs button {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  padding: var(--space-12) 0;
  margin-bottom: -1px; /* border-collapse overlap: pulls the tab's bottom edge onto the tab-list border-bottom line — structural, leave */
  font: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.sub-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.sub-nav button {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  padding: var(--space-8) var(--space-12);
  border-left: 2px solid transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
  border-radius: 0 var(--radius-6) var(--radius-6) 0;
}
.sub-nav button[aria-selected="true"] {
  color: var(--text-primary);
  border-left-color: var(--accent);
  background: var(--accent-soft-bg);
}

/* ---------- Skeleton ---------- */
.skeleton {
  display: inline-block;
  background: linear-gradient(90deg, var(--bg-elevated), var(--bg-input), var(--bg-elevated));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-4);
  color: transparent;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Empty / Loading / Error patterns (Plan 5 D.5) ---------- */
.state-empty {
  display: grid;
  place-items: center;
  text-align: center;
  padding: var(--space-32);
  color: var(--text-tertiary);
  gap: var(--space-12);
}
.state-empty__icon { font-size: var(--fs-display); color: var(--text-muted); }
.state-empty__title { font-weight: var(--fw-bold); color: var(--text-primary); margin: 0; }
.state-empty__subtext { margin: 0; max-width: 36ch; color: var(--text-tertiary); }
.state-loading {
  display: grid;
  gap: var(--space-8);
}
.state-loading__row {
  display: flex;
  gap: var(--space-8);
}
.state-loading .skeleton {
  height: 14px;
  border-radius: var(--radius-4);
  flex: 1;
}
.state-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  background: var(--danger-soft-bg);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-6);
  color: var(--text-secondary);
}
.state-error__icon { color: var(--danger); font-weight: var(--fw-heavy); }
.state-error__body { flex: 1; }
.state-error__title { margin: 0; color: var(--danger); font-weight: var(--fw-bold); }
.state-error__detail { margin: var(--space-4) 0 0; font-size: var(--fs-secondary); color: var(--text-tertiary); }
.state-error__actions { display: flex; gap: var(--space-8); margin-top: var(--space-8); }
.state-error a.state-error__journal { color: var(--accent-soft-text); font-size: var(--fs-secondary); }

/* ---------- Bottom sheet (Plan 5 D.2) ---------- */
/* Backdrop, surface, slide-up keyframes, grabber, title, body and footer
   shell all now come from the shared .overlay--sheet core (css/overlay.css,
   js/lib/overlay.js) — the old hand-rolled rules rendered onto no real node
   and were deleted (BB1 Phase 5). bottom-sheet.js already emits the core
   classes, so there is no re-home left to do here. */

/* ---------- Pull-to-refresh indicator (Plan 5 D.3) ---------- */
.ptr-indicator {
  position: absolute;
  top: -28px; /* parks the 32px spinner just above the viewport until pulled; ≥28px = structural (audit §B.4), not a space-scale value — leave */
  left: 50%;
  transform: translateX(-50%) translateY(0);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
  opacity: 0;
  transition: opacity 120ms ease;
  z-index: 5;
  pointer-events: none;
}
/* D4 — reduced motion: kills the opacity return-fade in reset(); transform has
   no transition to begin with (direct-manipulation drag stays 1:1 either way). */
.ptr-indicator--no-motion { transition: none; }

/* ---------- Swipe actions (Plan 5 D.4) ---------- */
.swipe-card { position: relative; transition: transform 200ms ease; }
/* D4 — reduced motion: kills the settle/return transition (open()/close());
   setX()'s direct-manipulation drag writes are unaffected either way since
   they never relied on the transition to feel right. */
.swipe-card--no-motion { transition: none; }
.swipe-card__lane {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
  gap: 1px; /* hairline seam between swipe-action buttons; no --space-1 token — leave literal */
  padding: 0;
  z-index: 0;
}
.swipe-card__action {
  appearance: none;
  border: none;
  padding: 0 var(--space-12);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font: inherit;
  font-weight: var(--fw-bold);
  cursor: pointer;
  min-width: 48px;
}
.swipe-card__action--info   { background: var(--accent-soft-bg); color: var(--accent-soft-text); }
.swipe-card__action--warn   { background: var(--warn-soft-bg);   color: var(--warn); }
.swipe-card__action--danger { background: var(--danger-soft-bg); color: var(--danger); }

/* ---------- Cross-operator toast (Plan 5 D.6) ---------- */
.toast__user {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--fs-small);
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}
.toast__user-chip {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  font-weight: var(--fw-heavy);
  font-size: var(--fs-micro);
  letter-spacing: 0;
}

/* ---------- Live editor overlay (E.3) ---------- */
/* Container/backdrop/surface/head/close-button shell now comes from the
   shared .overlay--sheet core (css/overlay.css, js/lib/overlay.js) — the old
   hand-rolled wrapper rules rendered onto no real node and were deleted
   (BB1 Phase 5). The inter-field flex/gap the old surface rule provided is
   re-homed onto `.le-sheet__form` below (see js/lib/element-overlay.js
   showAddStepSheet()). */
.le-sheet__form {
  display: flex; flex-direction: column; gap: var(--space-12);
}
.le-sheet__info code {
  font-family: var(--font-mono); font-size: var(--fs-small); color: var(--accent-soft-text);
  background: var(--bg-input); padding: var(--space-4) var(--space-6); border-radius: var(--radius-4);
}
.le-sheet__info small {
  margin-left: var(--space-8); color: var(--text-muted); font-size: var(--fs-label);
}
.le-sheet__field { display: flex; flex-direction: column; gap: var(--space-4); font-size: var(--fs-small); }
.le-sheet__field > span { color: var(--text-tertiary); }
.le-sheet__field select, .le-sheet__field input {
  background: var(--bg-input); border: 1px solid var(--border-subtle);
  color: var(--text-primary); border-radius: var(--radius-4); padding: var(--space-6) var(--space-10);
  font: inherit; font-size: var(--fs-secondary);
}
.le-sheet__actions {
  display: flex; gap: var(--space-8); justify-content: flex-end; margin-top: var(--space-12); /* was 4px + inline var(--space-12), re-homed Phase 5 */
}

/* ---------- Replay controls (E.4) ---------- */
.rc-bar {
  display: flex; gap: var(--space-8); align-items: center;
  padding: var(--space-8) var(--space-16); background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle); font-size: var(--fs-small);
}
.rc-btn {
  display: inline-flex; align-items: center; gap: var(--space-6);
  background: var(--bg-canvas); color: var(--text-secondary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-4);
  padding: var(--space-4) var(--space-8); font: inherit; font-size: var(--fs-small); cursor: pointer;
}
.rc-btn:hover { color: var(--text-primary); border-color: var(--border-default); }
.rc-btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.rc-btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.rc-progress { flex: 1; display: flex; flex-direction: column; gap: var(--space-4); margin: 0 var(--space-8); }
.rc-progress__label { font-size: var(--fs-label); color: var(--text-muted); }
.rc-progress__bar { height: 4px; background: var(--bg-input); border-radius: var(--radius-4); overflow: hidden; }
.rc-progress__fill { height: 100%; background: var(--ok); transition: width 200ms ease; }
.rc-speed {
  background: var(--bg-input); color: var(--text-secondary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-4);
  padding: var(--space-4) var(--space-6); font-size: var(--fs-label);
}

/* ---------- Test profile picker (E.5) ---------- */
.tpp { display: inline-flex; gap: var(--space-4); align-items: center; }
.tpp__select {
  background: var(--bg-input); color: var(--text-secondary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-4);
  padding: var(--space-4) var(--space-8); font-size: var(--fs-small);
}
.tpp__edit {
  background: var(--bg-elevated); border: 1px solid var(--border-subtle);
  color: var(--text-secondary); border-radius: var(--radius-4); padding: var(--space-4) var(--space-6); cursor: pointer;
}
.tpp__edit:hover { color: var(--text-primary); border-color: var(--border-default); }

/* Container/backdrop/surface/heading shell now comes from the shared
   openModal()/.overlay--modal core (js/lib/modal.js, css/overlay.css) — the
   old hand-rolled rules rendered onto no real node and were deleted (BB1
   Phase 5). openModal's `title` renders the real heading now, so the old
   surface-scoped heading rule is gone too. `.tpp-modal__hint`/`__fields`
   already carry their own spacing and need no re-home
   (js/lib/test-profile-picker.js). */
.tpp-modal__hint { color: var(--text-tertiary); font-size: var(--fs-label); margin-bottom: var(--space-12); }
.tpp-modal__fields { display: flex; flex-direction: column; gap: var(--space-8); max-height: 50vh; overflow-y: auto; }
.tpp-modal__fields label { display: grid; grid-template-columns: 100px 1fr 1fr; gap: var(--space-8); align-items: center; font-size: var(--fs-small); }
.tpp-modal__fields label > span { color: var(--text-tertiary); font-family: var(--font-mono); font-size: var(--fs-label); }
.tpp-modal__fields input {
  background: var(--bg-input); border: 1px solid var(--border-subtle);
  color: var(--text-primary); padding: var(--space-4) var(--space-8); border-radius: var(--radius-4); font-size: var(--fs-small);
}

/* --- Motion: micro-feedback (press / hover / focus) --- */
.btn:active {
  transform: scale(0.97);
}

.card {
  transition: transform var(--dur-fast) var(--ease-standard),
    box-shadow var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard);
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Pill / badge value change: a subtle pop. Add the class for one frame via JS
 * where values update, or rely on the spring token in scripted accents. */
.pill,
.badge {
  transition: background var(--dur-fast) var(--ease-standard),
    color var(--dur-fast) var(--ease-standard);
}

/* Focus ring glides in on keyboard focus (does not change focus colors). */
.btn:focus-visible,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  transition: box-shadow var(--dur-fast) var(--ease-standard),
    border-color var(--dur-fast) var(--ease-standard);
}

/* --- Motion: empty/error states ease in --- */
.state-empty,
.state-error {
  animation: mo-fade-in var(--dur-base) var(--ease-out) both;
}
