/* 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); }
}

/* ---------- 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: 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: 2px 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); }

/* ---------- Table ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-secondary);
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  color: var(--text-tertiary);
  font-weight: var(--fw-medium);
  text-align: left;
  padding: var(--space-8) var(--space-12);
  border-bottom: 1px solid var(--border-subtle);
}
.table tbody td {
  padding: var(--space-8) var(--space-12);
  border-bottom: 1px solid var(--border-subtle);
}
.table tbody tr:hover {
  background: var(--bg-elevated);
}

/* ---------- Modal ---------- */
.modal__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 200;
}
.modal {
  width: min(480px, calc(100% - var(--space-32)));
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  padding: var(--space-24);
  box-shadow: var(--shadow-lg);
}
.modal__title { margin: 0 0 var(--space-12); font-size: var(--fs-section); }
.modal__footer { display: flex; gap: var(--space-12); justify-content: flex-end; margin-top: var(--space-24); }
.modal__footer--multi {
  flex-wrap: wrap;
  gap: var(--space-8);
}

/* Phase D — danger-styled modal for irreversible confirms (spec §12.5). */
.modal--danger .modal__primary,
.modal--danger .modal__footer .btn--primary {
  background: linear-gradient(135deg, var(--danger), color-mix(in srgb, var(--danger) 70%, #000));
  border-color: var(--danger);
  color: #fff;
}
.modal--danger .modal__primary:hover,
.modal--danger .modal__footer .btn--primary:hover {
  filter: brightness(0.92);
}
.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;
  gap: var(--space-8);
  /* Above the slide-in panel (950) AND the modal layer (2000) — a save error
     must stay visible while the mapping panel is open. */
  z-index: 2100;
}
.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; }

/* ---------- 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;
  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: 32px; 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) ---------- */
.sheet__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  z-index: 220;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg-surface);
  border-radius: var(--radius-12) var(--radius-12) 0 0;
  border: 1px solid var(--border-default);
  padding: var(--space-12) var(--space-16) calc(var(--bottom-tab-height, 0px) + var(--space-16));
  box-shadow: var(--shadow-lg);
}
@keyframes sheet-slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.sheet__grabber {
  width: 36px;
  height: 4px;
  background: var(--border-default);
  border-radius: 999px;
  margin: 0 auto var(--space-12);
}
.sheet__title { margin: 0 0 var(--space-8); font-size: var(--fs-section); }
.sheet__body  { font-size: var(--fs-secondary); color: var(--text-secondary); }
.sheet__footer { display: flex; gap: var(--space-8); margin-top: var(--space-16); justify-content: flex-end; }

/* ---------- Pull-to-refresh indicator (Plan 5 D.3) ---------- */
.ptr-indicator {
  position: absolute;
  top: -28px;
  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;
}

/* ---------- Swipe actions (Plan 5 D.4) ---------- */
.swipe-card { position: relative; transition: transform 200ms ease; }
.swipe-card__lane {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
  gap: 1px;
  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: 10px;
  letter-spacing: 0;
}

/* ---------- Live editor overlay (E.3) ---------- */
.le-sheet {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: flex-end; justify-content: center;
}
.le-sheet__backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.5);
}
.le-sheet__body {
  position: relative; background: var(--bg-surface);
  border-top: 1px solid var(--border-default);
  border-left: 1px solid var(--border-default);
  border-right: 1px solid var(--border-default);
  border-radius: 8px 8px 0 0;
  width: min(600px, 100%); padding: 18px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.le-sheet__head {
  display: flex; justify-content: space-between; align-items: center;
}
.le-sheet__close {
  background: transparent; border: 0; color: var(--text-muted); cursor: pointer;
}
.le-sheet__info code {
  font-family: var(--font-mono); font-size: 12px; color: var(--accent-soft-text);
  background: var(--bg-input); padding: 2px 6px; border-radius: 3px;
}
.le-sheet__info small {
  margin-left: 8px; color: var(--text-muted); font-size: 11px;
}
.le-sheet__field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.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: 4px; padding: 6px 10px;
  font: inherit; font-size: 13px;
}
.le-sheet__actions {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px;
}

/* ---------- Replay controls (E.4) ---------- */
.rc-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 14px; background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle); font-size: 12px;
}
.rc-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-canvas); color: var(--text-secondary);
  border: 1px solid var(--border-subtle); border-radius: 4px;
  padding: 4px 8px; font: inherit; font-size: 12px; 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: 2px; margin: 0 8px; }
.rc-progress__label { font-size: 11px; color: var(--text-muted); }
.rc-progress__bar { height: 4px; background: var(--bg-input); border-radius: 2px; 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: 4px;
  padding: 4px 6px; font-size: 11px;
}

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

.tpp-modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; }
.tpp-modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.tpp-modal__body {
  position: relative; background: var(--bg-surface);
  border: 1px solid var(--border-default); border-radius: 8px;
  width: min(480px, 100%); padding: 20px;
}
.tpp-modal__body h3 { font-size: 14px; margin-bottom: 4px; }
.tpp-modal__hint { color: var(--text-tertiary); font-size: 11px; margin-bottom: 12px; }
.tpp-modal__fields { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.tpp-modal__fields label { display: grid; grid-template-columns: 100px 1fr 1fr; gap: 8px; align-items: center; font-size: 12px; }
.tpp-modal__fields label > span { color: var(--text-tertiary); font-family: var(--font-mono); font-size: 11px; }
.tpp-modal__fields input {
  background: var(--bg-input); border: 1px solid var(--border-subtle);
  color: var(--text-primary); padding: 4px 8px; border-radius: 4px; font-size: 12px;
}
.tpp-modal__actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* --- 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;
}
