/* ============================================================
   components.css — shared component vocabulary (REDESIGN.md §3).
   Every value comes from tokens.css. No raw colors, no raw px
   radii/shadows. Hover = one surface step. 4px spacing grid.
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: var(--fs-base)/1.5 var(--font-ui);
  min-height: 100vh;
  transition: background var(--dur-open) var(--ease);
}

.mono { font-family: var(--font-data); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }

[hidden] { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
a { color: var(--accent); text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::placeholder { color: var(--text-faint); }
::selection { background: var(--accent-tint); }

/* themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--hairline) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: var(--radius-pill); border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background-color: var(--text-faint); }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------------- buttons (all pills) ---------------- */

.btn {
  height: 32px;
  padding: 0 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background var(--dur-hover) var(--ease),
              color var(--dur-hover) var(--ease),
              border-color var(--dur-hover) var(--ease),
              filter var(--dur-hover) var(--ease);
}

.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent-solid);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-primary:active:not(:disabled) { filter: brightness(.95); }

.btn-cta { /* hero CTA only — one per view */
  height: 44px;
  padding: 0 26px;
  font-size: 14px;
  box-shadow: var(--cta-glow);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--hairline);
}
.btn-secondary:hover:not(:disabled) { background: var(--hairline); }
.btn-secondary:active:not(:disabled) { filter: brightness(.96); }

.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }

.btn-ghost-danger { color: var(--danger); }
.btn-ghost-danger:hover:not(:disabled) { background: var(--danger-tint); }

.btn .spin { /* inline loading state */
  width: 12px; height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- fields ---------------- */

.field label, .field .label {
  display: block;
  font-size: var(--fs-label);
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.field input, .field select, .field textarea, .enh select, .input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font: var(--fs-base) var(--font-ui);
  transition: border-color var(--dur-hover) var(--ease);
}

.field textarea { font: 12px/1.7 var(--font-data); resize: vertical; }

.field :is(input, select, textarea):focus, .input:focus {
  border-color: var(--accent);
  outline: none;
}

.field :is(input, select, textarea):disabled { opacity: .4; cursor: not-allowed; }

.field .help { font-size: var(--fs-label); color: var(--text-faint); margin-top: 5px; }
.field.invalid :is(input, select, textarea) { border-color: var(--danger); }
.field .error-text { font-size: var(--fs-label); color: var(--danger); margin-top: 5px; }

.field input.mono { font-family: var(--font-data); font-size: 13px; }

/* chip select (preset picker over textarea) */
.chip-select, .field .chip-select, .field select.chip-select {
  width: auto;
  font-size: var(--fs-label);
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  width: auto;
  transition: border-color var(--dur-hover) var(--ease);
}
.chip-select:hover { border-color: var(--text-faint); }
.chip-select:focus { border-color: var(--accent); outline: none; }

/* compact stepper (−5s / +5s flanking a mono time input) */
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .btn { height: 26px; padding: 0 9px; font-size: 11px; }
.stepper input { text-align: center; width: 96px; padding: 6px 8px; }

/* ---------------- segmented pill (theme toggle, cut mode) ---------------- */

.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-label);
  font-weight: 500;
  color: var(--text-muted);
  transition: background var(--dur-hover) var(--ease), color var(--dur-hover) var(--ease);
}
.segmented button:hover:not(.on) { color: var(--text); }
.segmented button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgb(0 0 0 / .25);
}
[data-theme="light"] .segmented button.on { box-shadow: 0 1px 3px rgb(20 20 20 / .12); }

/* ---------------- cards & panels ---------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 24px;
}

/* no overflow:hidden here — the ⋯ menu pops out past the card edge;
   children that need corner clipping (the thumb) clip themselves */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: border-color var(--dur-hover) var(--ease), transform var(--dur-hover) var(--ease);
}
.card:hover { border-color: var(--text-faint); transform: translateY(-2px); }

/* ---------------- pills & badges ---------------- */

.pill {
  border-radius: var(--radius-pill);
  padding: 3px 11px;
  font: var(--fs-label)/1.6 var(--font-data);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pill-success { background: var(--success-tint); color: var(--success); }
.pill-warn    { background: var(--warn-tint);    color: var(--warn); }
.pill-danger  { background: var(--danger-tint);  color: var(--danger); }
.pill-accent  { background: var(--accent-tint);  color: var(--accent); }
.pill-neutral { background: var(--surface-2);    color: var(--text-muted); }

/* ---------------- timeline rail (signature) ---------------- */

.rail-wrap { margin-bottom: 28px; }
.rail-meta {
  display: flex;
  justify-content: space-between;
  font: 11px var(--font-data);
  color: var(--text-faint);
  margin-bottom: 7px;
}
.rail {
  position: relative;
  height: 7px;
  background: var(--surface-2);
  border-radius: 4px;
}
.rail .seg {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  cursor: pointer;
  border: none;
  padding: 0;
  min-width: 4px;
  transition: filter var(--dur-hover) var(--ease);
}
.rail .seg:hover, .rail .seg:focus-visible { filter: brightness(1.25); }

/* Layer 1: "most replayed" intensity area, time-aligned above the rail */
.rail-heat { height: 26px; margin-bottom: 5px; }
.rail-heat svg { width: 100%; height: 100%; display: block; }
.rail-heat .heat-area {
  fill: var(--accent);
  opacity: .16;
  stroke: var(--accent);
  stroke-opacity: .5;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.mini-rail {
  position: relative;
  height: 3px;
  background: var(--surface-2);
  border-radius: 2px;
}
.mini-rail .seg {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  min-width: 3px;
}

/* dual-handle selection rail (composer range picker) */
.range-rail { position: relative; height: 28px; }
.range-rail .rail-track,
.range-rail .rail-fill {
  position: absolute;
  top: 11px;
  height: 6px;
  border-radius: 4px;
}
.range-rail .rail-track { width: 100%; background: var(--surface-2); }
.range-rail .rail-fill { background: var(--accent); }
.range-rail input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 28px;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: none;
  pointer-events: none;
}
.range-rail input[type="range"]:focus-visible { outline: none; }
.range-rail input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--hairline);
  cursor: grab;
  transition: transform var(--dur-hover) var(--ease);
}
.range-rail input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
.range-rail input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.range-rail input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  cursor: grab;
}

/* ---------------- progress strip ---------------- */

.progress-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  padding: 10px 10px 10px 18px;
}
.progress-strip .p-label {
  font: var(--fs-label) var(--font-data);
  color: var(--text-muted);
  white-space: nowrap;
}
.progress-strip .p-time {
  font: var(--fs-label) var(--font-data);
  color: var(--text-faint);
  white-space: nowrap;
}
.progress-strip .p-time:empty { display: none; }
.progress-strip .bar {
  flex: 1;
  height: 5px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-strip .bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .4s var(--ease);
}
.progress-strip .bar i.indeterminate {
  width: 34%;
  animation: slide 1.5s var(--ease) infinite;
}
@keyframes slide { from { margin-left: -34%; } to { margin-left: 100%; } }

/* ---------------- banner (persistent inline notice) ---------------- */

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--accent-tint);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
}

/* ---------------- error block ---------------- */

.error-block {
  background: var(--danger-tint);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.error-block h3 { font-size: var(--fs-base); font-weight: 600; color: var(--danger); margin-bottom: 4px; }
.error-block p { font-size: 13px; }
.error-block details { margin-top: 10px; }
.error-block summary { cursor: pointer; color: var(--text-muted); font-size: var(--fs-label); }
.error-block pre {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px;
  font: 11px/1.6 var(--font-data);
  white-space: pre-wrap;
  max-height: 280px;
  overflow: auto;
  margin-top: 8px;
}

/* ---------------- empty state ---------------- */

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty svg { width: 24px; height: 24px; color: var(--text-faint); margin-bottom: 10px; }
.empty p { margin-bottom: 16px; }

/* ---------------- tooltip (icons & truncations only) ---------------- */

[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--hairline);
  color: var(--text);
  font: var(--fs-label) var(--font-ui);
  padding: 5px 11px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  animation: tipin var(--dur-hover) var(--ease) .3s forwards;
  pointer-events: none;
  z-index: 60;
}
@keyframes tipin { to { opacity: 1; } }

/* ---------------- menu (popover) ---------------- */

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 190px;
  padding: 6px;
  display: none;
  z-index: 40;
}
.menu.open { display: block; animation: menuin var(--dur-hover) var(--ease); }
@keyframes menuin { from { opacity: 0; transform: translateY(-3px); } }
.menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  text-align: left;
}
.menu button:hover { background: var(--surface-2); }
.menu button:disabled { opacity: .4; cursor: not-allowed; }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: var(--danger-tint); }
.menu hr { border: 0; border-top: 1px solid var(--hairline); margin: 5px 0; }

/* ---------------- modal ---------------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.backdrop.open { display: flex; }
.modal {
  width: 560px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  animation: modalin var(--dur-open) var(--ease);
}
@keyframes modalin { from { opacity: 0; transform: translateY(8px); } }
.modal h2 { font-size: var(--fs-title); font-weight: 600; margin-bottom: 5px; }
.modal > p { color: var(--text-muted); margin-bottom: 16px; font-size: 13px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.modal-foot .foot-status { margin-right: auto; font: var(--fs-label) var(--font-data); color: var(--text-muted); }

/* ---------------- toast ---------------- */

.toast-zone {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 70;
  align-items: flex-end;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow);
  padding: 10px 18px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastin var(--dur-open) var(--ease);
}
.toast .t-ok { color: var(--success); }
.toast .t-err { color: var(--danger); }
.toast .t-action { color: var(--accent); font-weight: 500; }
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } }

/* ---------------- disclosure ---------------- */

.disclosure {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  transition: color var(--dur-hover) var(--ease);
}
.disclosure:hover { color: var(--text); }
.disclosure svg { transition: transform var(--dur-hover) var(--ease); }
.disclosure.open svg { transform: rotate(180deg); }

/* ---------------- motion preference ---------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
