/* ==========================================================================
   Component layer — shared across portal and console
   Every interactive component defines: default / hover / active / focus /
   selected / loading / disabled states.
   ========================================================================== */

/* ==========================================================================
   Button
   ========================================================================== */
.btn {
  --btn-h: 34px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: var(--btn-h);
  padding: 0 var(--s4);
  border-radius: var(--r-md);
  border: 1px solid transparent;
  font-size: var(--fs-secondary);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-body);
  white-space: nowrap;
  user-select: none;
  isolation: isolate;
  transform: translate3d(var(--btn-dx, 0px), var(--btn-dy, 0px), 0);
  transition:
    background-color var(--dur-1) var(--ease-out),
    border-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out),
    transform var(--dur-2) var(--ease-spring),
    opacity var(--dur-1) linear;
}
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(120px 60px at var(--px, 50%) var(--py, 50%), rgba(255, 255, 255, 0.16), transparent 70%);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease-out);
  pointer-events: none;
  z-index: -1;
}
.btn:hover::after { opacity: 1; }
.btn:active { transform: translate3d(var(--btn-dx, 0px), 1px, 0) scale(0.985); }

.btn--sm { --btn-h: 28px; padding: 0 var(--s3); font-size: var(--fs-caption); }
.btn--lg { --btn-h: 44px; padding: 0 var(--s6); font-size: var(--fs-title); border-radius: var(--r-lg); }
.btn--block { width: 100%; }
.btn--icon { width: var(--btn-h); padding: 0; }

.btn--primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
.btn--primary:hover { background: var(--accent-hover); box-shadow: 0 4px 14px -4px var(--accent-ring), inset 0 1px 0 rgba(255, 255, 255, 0.2); }

.btn--secondary {
  background: var(--surface-raised);
  border-color: var(--border-strong);
  color: var(--text-primary);
  box-shadow: var(--e1);
}
.btn--secondary:hover { border-color: var(--border-hover); --btn-dy: -1px; }

.btn--ghost { color: var(--text-secondary); }
.btn--ghost:hover { background: var(--accent-soft); color: var(--text-primary); }

.btn--quiet { color: var(--text-muted); }
.btn--quiet:hover { color: var(--text-primary); background: var(--surface-raised); }

.btn--danger {
  background: var(--error-soft);
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 28%, transparent);
}
.btn--danger:hover { background: var(--error); color: var(--text-on-accent); border-color: transparent; }

.btn--inverse {
  background: var(--surface-inverse);
  color: var(--text-on-inverse);
}
.btn--inverse:hover { --btn-dy: -1px; box-shadow: var(--e3); }

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.42;
  pointer-events: none;
  box-shadow: none;
}
.btn[data-loading="true"] {
  pointer-events: none;
  color: transparent;
}
.btn[data-loading="true"]::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  color: var(--text-on-accent);
  animation: spin 620ms linear infinite;
}
.btn--secondary[data-loading="true"]::before,
.btn--ghost[data-loading="true"]::before,
.btn--quiet[data-loading="true"]::before { color: var(--text-secondary); }

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

.btn__kbd {
  display: inline-flex;
  gap: 2px;
  margin-left: var(--s1);
  opacity: 0.55;
  font-family: var(--font-mono);
  font-size: 10px;
}

/* Icon glyph — inline SVG sprite driven */
.ico {
  width: 15px;
  height: 15px;
  flex: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  transition: transform var(--dur-2) var(--ease-spring), opacity var(--dur-1) linear;
}
.ico--sm { width: 13px; height: 13px; }
.ico--lg { width: 18px; height: 18px; }
.ico--xl { width: 22px; height: 22px; stroke-width: 1.5; }
.btn:hover .ico--spin { transform: rotate(90deg); }
.btn:hover .ico--nudge { transform: translateX(2px); }
.btn:hover .ico--pop { transform: scale(1.12); }

/* ==========================================================================
   Badge / Chip / Status
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  height: 20px;
  padding: 0 var(--s2);
  border-radius: var(--r-xs);
  font-size: var(--fs-label);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.02em;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge--success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.badge--warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 22%, transparent); }
.badge--error { background: var(--error-soft); color: var(--error); border-color: color-mix(in srgb, var(--error) 22%, transparent); }
.badge--info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.badge--accent { background: var(--accent-soft); color: var(--accent); border-color: var(--border-accent); }
.badge--count { min-width: 20px; justify-content: center; font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  height: 28px;
  padding: 0 var(--s3);
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--fs-caption);
  transition: all var(--dur-1) var(--ease-out);
}
.chip:hover { border-color: var(--border-hover); color: var(--text-primary); }
.chip[aria-pressed="true"],
.chip[data-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--border-accent);
  color: var(--accent);
}

/* Live status indicator: colour + text + motion, never colour alone */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--fs-caption);
  color: var(--text-secondary);
  white-space: nowrap;
}
.status__dot {
  position: relative;
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--status-color, var(--text-muted));
}
.status--live .status__dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid var(--status-color, var(--text-muted));
  animation: status-pulse 1.8s var(--ease-out) infinite;
}
.status--success { --status-color: var(--success); }
.status--warning { --status-color: var(--warning); }
.status--error { --status-color: var(--error); }
.status--info { --status-color: var(--info); }
.status--accent { --status-color: var(--accent); }
.status--idle { --status-color: var(--text-faint); }
@keyframes status-pulse {
  0% { transform: scale(0.7); opacity: 0.85; }
  100% { transform: scale(2.1); opacity: 0; }
}

.dots { display: inline-flex; gap: 3px; align-items: center; }
.dots i {
  width: 3px; height: 3px; border-radius: 50%;
  background: currentColor;
  animation: dots 1.1s var(--ease-in-out) infinite;
}
.dots i:nth-child(2) { animation-delay: 0.14s; }
.dots i:nth-child(3) { animation-delay: 0.28s; }
@keyframes dots { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* Progress ring for long-running work */
.ring { width: 16px; height: 16px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 2; }
.ring .ring__track { stroke: var(--border-strong); }
.ring .ring__fill { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset var(--dur-4) var(--ease-out); }

/* ==========================================================================
   Fields
   ========================================================================== */
.field { display: grid; gap: var(--s2); min-width: 0; }
.field__label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
}
.field__req { color: var(--accent); font-size: var(--fs-label); }
.field__hint { font-size: var(--fs-caption); color: var(--text-muted); }
.field__error {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--fs-caption);
  color: var(--error);
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: var(--field-h, 36px);
  padding: 0 var(--s3);
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-primary);
  font-size: var(--fs-body);
  transition:
    border-color var(--dur-1) var(--ease-out),
    background-color var(--dur-1) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out);
}
.textarea { padding: var(--s3); min-height: 96px; resize: vertical; line-height: var(--lh-normal); }
.select { appearance: none; padding-right: var(--s8); cursor: pointer; }

.input::placeholder,
.textarea::placeholder { color: var(--text-faint); }

.input:hover,
.textarea:hover,
.select:hover { border-color: var(--border-hover); }

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--accent);
  background: var(--surface-raised);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.input[aria-invalid="true"],
.textarea[aria-invalid="true"] { border-color: var(--error); }
.input[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--error) 24%, transparent); }
.input[disabled],
.textarea[disabled],
.select[disabled] { opacity: 0.5; cursor: not-allowed; }

.field--select { position: relative; }
.select-wrap { position: relative; display: block; }
.select-wrap .ico {
  position: absolute;
  right: var(--s3);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
}

.input-group { position: relative; display: flex; align-items: center; }
.input-group .ico { position: absolute; left: var(--s3); color: var(--text-muted); pointer-events: none; }
.input-group .input { padding-left: var(--s8); }

/* Checkbox / consent block */
.check {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: var(--s3);
  align-items: start;
  padding: var(--s3);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease-out), background-color var(--dur-1) var(--ease-out);
}
.check:hover { border-color: var(--border-hover); }
.check__box {
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: var(--r-xs);
  border: 1.5px solid var(--border-hover);
  display: grid;
  place-items: center;
  transition: all var(--dur-2) var(--ease-spring);
}
.check__box .ico { width: 11px; height: 11px; stroke-width: 2.4; color: var(--text-on-accent); opacity: 0; transform: scale(0.5); }
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check input:checked ~ .check__box,
.check[data-checked="true"] .check__box {
  background: var(--accent);
  border-color: var(--accent);
}
.check input:checked ~ .check__box .ico,
.check[data-checked="true"] .check__box .ico { opacity: 1; transform: scale(1); }
.check[data-checked="true"] { border-color: var(--border-accent); background: var(--accent-soft); }
.check input:focus-visible ~ .check__box { box-shadow: 0 0 0 3px var(--accent-ring); }
.check__text { font-size: var(--fs-secondary); line-height: var(--lh-normal); color: var(--text-secondary); }

/* Toggle with spring motion */
.toggle {
  position: relative;
  width: 36px;
  height: 21px;
  flex: none;
  border-radius: var(--r-full);
  background: var(--border-strong);
  transition: background-color var(--dur-2) var(--ease-out);
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--surface-raised);
  box-shadow: var(--e2);
  transition: transform var(--dur-3) var(--ease-spring);
}
.toggle[aria-checked="true"] { background: var(--accent); }
.toggle[aria-checked="true"]::after { transform: translateX(15px); }

/* Segmented control with sliding indicator */
.segmented {
  position: relative;
  display: inline-flex;
  padding: 2px;
  border-radius: var(--r-md);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
}
.segmented__thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 0;
  border-radius: calc(var(--r-md) - 2px);
  background: var(--surface-raised);
  box-shadow: var(--e2);
  transform: translateX(var(--thumb-x, 0px));
  width: var(--thumb-w, 0px);
  transition: transform var(--dur-3) var(--ease-spring), width var(--dur-3) var(--ease-spring);
}
.segmented button {
  position: relative;
  z-index: 1;
  height: 28px;
  padding: 0 var(--s3);
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  border-radius: calc(var(--r-md) - 2px);
  transition: color var(--dur-2) var(--ease-out);
}
.segmented button:hover { color: var(--text-secondary); }
.segmented button[aria-selected="true"] { color: var(--text-primary); }

/* ==========================================================================
   Surface & panel primitives (used instead of ubiquitous cards)
   ========================================================================== */
.panel {
  position: relative;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}
.panel--raised { background: var(--surface-raised); box-shadow: var(--e2); }
.panel--flush { border-radius: 0; border-left: 0; border-right: 0; }
.panel__head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--border);
}
.panel__body { padding: var(--s5); }
.panel__body--flush { padding: 0; }
.panel__foot {
  padding: var(--s3) var(--s5);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* Spotlight hover — a faint radial highlight tracking the pointer */
.spotlight { position: relative; overflow: hidden; }
.spotlight::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(260px 180px at var(--px, 50%) var(--py, 50%), var(--accent-soft), transparent 68%);
  opacity: 0;
  transition: opacity var(--dur-3) var(--ease-out);
  pointer-events: none;
}
.spotlight:hover::before { opacity: 1; }

/* Section header — typography-led structure, no container needed */
.section-head {
  display: flex;
  align-items: flex-end;
  gap: var(--s4);
  padding-bottom: var(--s3);
  border-bottom: 1px solid var(--border);
}
.section-head__text { display: grid; gap: 2px; min-width: 0; }

/* ==========================================================================
   Metric — animated counters, delta, sparkline slot
   ========================================================================== */
.metrics {
  display: grid;
  grid-template-columns: repeat(var(--metric-cols, 4), minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.metric {
  position: relative;
  display: grid;
  gap: var(--s2);
  padding: var(--s4) var(--s5) var(--s5);
  border-right: 1px solid var(--border);
  text-align: left;
  transition: background-color var(--dur-2) var(--ease-out);
}
.metric:last-child { border-right: 0; }
.metric[data-clickable="true"] { cursor: pointer; }
.metric[data-clickable="true"]:hover { background: var(--surface-raised); }
.metric[data-clickable="true"]:hover .metric__go { opacity: 1; transform: translateX(0); }
.metric__go {
  position: absolute;
  top: var(--s4);
  right: var(--s4);
  opacity: 0;
  transform: translateX(-4px);
  color: var(--text-muted);
  transition: all var(--dur-2) var(--ease-out);
}
.metric__value {
  font-size: 1.625rem;
  line-height: 1.1;
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-heading);
  font-variant-numeric: tabular-nums;
}
.metric__unit { font-size: var(--fs-caption); color: var(--text-muted); font-weight: var(--fw-regular); margin-left: 2px; }
.metric__foot { display: flex; align-items: center; gap: var(--s2); min-height: 16px; }
.metric--alert .metric__value { color: var(--error); }
.metric--warn .metric__value { color: var(--warning); }

/* ==========================================================================
   Data table
   ========================================================================== */
.table-wrap { position: relative; overflow: auto; max-width: 100%; }
.table { font-size: var(--fs-secondary); }
.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0 var(--s4);
  height: 34px;
  text-align: left;
  white-space: nowrap;
  background: var(--surface);
  border-bottom: 1px solid var(--border-strong);
  font-size: var(--fs-label);
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  backdrop-filter: blur(8px);
}
.table th[data-sortable="true"] { cursor: pointer; user-select: none; }
.table th[data-sortable="true"]:hover { color: var(--text-primary); }
.table th .ico { width: 11px; height: 11px; opacity: 0; transition: opacity var(--dur-1) linear, transform var(--dur-2) var(--ease-out); }
.table th[data-sort="asc"] .ico,
.table th[data-sort="desc"] .ico { opacity: 1; color: var(--accent); }
.table th[data-sort="desc"] .ico { transform: rotate(180deg); }
.table th[data-sortable="true"]:hover .ico { opacity: 0.5; }

.table tbody td {
  padding: 0 var(--s4);
  height: var(--row-h, 40px);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}
.table tbody tr { transition: background-color var(--dur-instant) linear; }
.table tbody tr:hover td { background: var(--surface-raised); color: var(--text-primary); }
.table tbody tr[data-selected="true"] td { background: var(--accent-soft); color: var(--text-primary); }
.table tbody tr[data-clickable="true"] { cursor: pointer; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .cell--num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.table .cell--strong { color: var(--text-primary); font-weight: var(--fw-medium); }
.table .cell--tight { width: 1%; white-space: nowrap; }
.table .cell--actions { opacity: 0; transition: opacity var(--dur-1) linear; }
.table tbody tr:hover .cell--actions,
.table tbody tr:focus-within .cell--actions { opacity: 1; }

/* Toolbar above lists */
.datatable { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.table__search { width: min(280px, 46vw); }
.table__search .input { height: 30px; font-size: var(--fs-secondary); }

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar__count {
  font-size: var(--fs-caption);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Floating contextual toolbar for multi-select */
.float-toolbar {
  position: fixed;
  left: 50%;
  bottom: var(--s8);
  z-index: var(--z-dock);
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-full);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  box-shadow: var(--e4);
  backdrop-filter: blur(20px) saturate(160%);
  transform: translate(-50%, 0) scale(1);
  animation: float-in var(--dur-3) var(--ease-spring);
}
@keyframes float-in {
  from { transform: translate(-50%, 14px) scale(0.96); opacity: 0; }
  to { transform: translate(-50%, 0) scale(1); opacity: 1; }
}

/* ==========================================================================
   Task queue rows — the primary "what do I do next" surface
   ========================================================================== */
.queue { display: grid; }
.queue__row {
  display: grid;
  grid-template-columns: 3px 1fr auto;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) var(--s5) var(--s3) 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  width: 100%;
  transition: background-color var(--dur-1) var(--ease-out);
}
.queue__row:last-child { border-bottom: 0; }
.queue__row:hover { background: var(--surface-raised); }
.queue__row:hover .queue__action { opacity: 1; transform: translateX(0); }
.queue__rail { align-self: stretch; background: var(--queue-color, var(--border-strong)); border-radius: 0 2px 2px 0; }
.queue__row[data-priority="high"] { --queue-color: var(--error); }
.queue__row[data-priority="medium"] { --queue-color: var(--warning); }
.queue__row[data-priority="low"] { --queue-color: var(--info); }
.queue__body { display: grid; gap: 3px; min-width: 0; padding-left: var(--s5); }
.queue__action { opacity: 0; transform: translateX(-4px); transition: all var(--dur-2) var(--ease-out); }

/* ==========================================================================
   Timeline
   ========================================================================== */
.timeline { display: grid; gap: 0; }
.timeline__item {
  position: relative;
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: var(--s4);
  padding-bottom: var(--s5);
}
.timeline__item:last-child { padding-bottom: 0; }
.timeline__item::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 18px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}
.timeline__item:last-child::before { display: none; }
.timeline__node {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  z-index: 1;
}
.timeline__node .ico { width: 10px; height: 10px; stroke-width: 2.2; }
.timeline__item[data-state="done"] .timeline__node { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 34%, transparent); color: var(--success); }
.timeline__item[data-state="active"] .timeline__node { background: var(--accent-soft); border-color: var(--border-accent); color: var(--accent); }
.timeline__item[data-state="blocked"] .timeline__node { background: var(--error-soft); border-color: color-mix(in srgb, var(--error) 34%, transparent); color: var(--error); }
.timeline__body { display: grid; gap: 3px; padding-top: 1px; min-width: 0; }

/* ==========================================================================
   Skeleton & progressive loading
   ========================================================================== */
.sk {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-sm);
  background: var(--skeleton-base);
}
.sk::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--skeleton-sheen), transparent);
  animation: sheen 1.5s var(--ease-in-out) infinite;
}
@keyframes sheen { to { transform: translateX(100%); } }
.sk--text { height: 10px; }
.sk--line { height: 13px; }
.sk--title { height: 19px; border-radius: var(--r-xs); }
.sk--num { height: 28px; width: 72px; }
.sk--block { height: 100%; min-height: 84px; border-radius: var(--r-md); }
.sk--circle { border-radius: 50%; }
.sk--avatar { width: 22px; height: 22px; flex: none; }
.sk-group { display: grid; gap: var(--s3); }
.sk-w-40 { width: 40%; }
.sk-w-55 { width: 55%; }
.sk-w-70 { width: 70%; }
.sk-w-85 { width: 85%; }

/* ==========================================================================
   Empty & error states
   ========================================================================== */
.state {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: var(--s4);
  padding: var(--s16) var(--s6);
  max-width: 460px;
  margin: 0 auto;
}
.state__art {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: var(--r-xl);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  color: var(--text-faint);
}
.state__art .ico { width: 28px; height: 28px; stroke-width: 1.3; }
.state--error .state__art { background: var(--error-soft); border-color: color-mix(in srgb, var(--error) 22%, transparent); color: var(--error); }
.state__text { display: grid; gap: var(--s2); }
.state__actions { display: flex; gap: var(--s2); margin-top: var(--s1); }
.state__debug {
  width: 100%;
  margin-top: var(--s2);
  text-align: left;
}
.state__debug summary {
  cursor: pointer;
  font-size: var(--fs-caption);
  color: var(--text-muted);
  list-style: none;
}
.state__debug summary::-webkit-details-marker { display: none; }
.state__debug summary:hover { color: var(--text-secondary); }
.state__debug pre {
  margin: var(--s2) 0 0;
  padding: var(--s3);
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ==========================================================================
   Overlays — scrim, drawer, modal, popover, context menu
   ========================================================================== */
.overlay-root { position: relative; z-index: var(--z-overlay); }

.scrim {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur-2) var(--ease-out);
}
.scrim[data-closing="true"] { animation: fade-out var(--dur-2) var(--ease-out) forwards; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(var(--drawer-w, 480px), 100vw);
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--e4);
  animation: drawer-in var(--dur-4) var(--ease-spring);
}
.drawer[data-closing="true"] { animation: drawer-out var(--dur-2) var(--ease-in-out) forwards; }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes drawer-out { to { transform: translateX(16px); opacity: 0; } }

.drawer__head {
  display: flex;
  align-items: flex-start;
  gap: var(--s4);
  padding: var(--s5) var(--s5) var(--s4);
  border-bottom: 1px solid var(--border);
}
.drawer__body { overflow: auto; padding: var(--s5); display: grid; gap: var(--s5); align-content: start; }
.drawer__foot {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s4) var(--s5);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 86vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  box-shadow: var(--e4);
  animation: sheet-in var(--dur-4) var(--ease-spring);
}
.sheet[data-closing="true"] { animation: sheet-out var(--dur-2) var(--ease-in-out) forwards; }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheet-out { to { transform: translateY(100%); } }
.sheet__grip {
  width: 34px;
  height: 4px;
  border-radius: var(--r-full);
  background: var(--border-hover);
  margin: var(--s3) auto 0;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  width: min(var(--modal-w, 440px), calc(100vw - var(--s8)));
  max-height: calc(100vh - var(--s16));
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-radius: var(--r-lg);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  box-shadow: var(--e4);
  transform: translate(-50%, -50%);
  animation: modal-in var(--dur-3) var(--ease-spring);
}
.modal[data-closing="true"] { animation: modal-out var(--dur-2) var(--ease-in-out) forwards; }
@keyframes modal-in {
  from { transform: translate(-50%, -48%) scale(0.96); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes modal-out { to { transform: translate(-50%, -50%) scale(0.98); opacity: 0; } }
.modal__body { padding: var(--s5); overflow: auto; display: grid; gap: var(--s4); }
.modal__foot { display: flex; gap: var(--s2); padding: var(--s4) var(--s5); border-top: 1px solid var(--border); }
.modal__art {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  padding: 0;
}

.menu {
  position: fixed;
  z-index: var(--z-popover);
  min-width: 196px;
  padding: var(--s1);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  box-shadow: var(--e3);
  backdrop-filter: blur(20px) saturate(160%);
  animation: menu-in var(--dur-1) var(--ease-out);
  transform-origin: var(--origin, top left);
}
@keyframes menu-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.menu__item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  height: 30px;
  padding: 0 var(--s3);
  border-radius: var(--r-sm);
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
  text-align: left;
}
.menu__item:hover,
.menu__item[data-active="true"] { background: var(--accent-soft); color: var(--text-primary); }
.menu__item[data-variant="danger"] { color: var(--error); }
.menu__item[data-variant="danger"]:hover { background: var(--error-soft); }
.menu__item[disabled] { opacity: 0.4; pointer-events: none; }
.menu__kbd { margin-left: auto; font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); }
.menu__sep { height: 1px; margin: var(--s1) 0; background: var(--border); }
.menu__label { padding: var(--s2) var(--s3) var(--s1); }

/* ==========================================================================
   Command palette / spotlight
   ========================================================================== */
.palette-scrim {
  position: fixed;
  inset: 0;
  display: grid;
  align-items: start;
  justify-items: center;
  padding-top: 12vh;
  background: var(--scrim);
  backdrop-filter: blur(8px) saturate(120%);
  animation: fade-in var(--dur-2) var(--ease-out);
}
.palette-scrim[data-closing="true"] { animation: fade-out var(--dur-1) linear forwards; }
.palette {
  width: min(620px, calc(100vw - var(--s8)));
  max-height: 60vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-radius: var(--r-lg);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  box-shadow: var(--e4);
  overflow: hidden;
  animation: palette-in var(--dur-3) var(--ease-spring);
}
@keyframes palette-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.palette__search {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: 0 var(--s4);
  height: 50px;
  border-bottom: 1px solid var(--border);
}
.palette__search input {
  flex: 1;
  border: 0;
  background: none;
  font-size: var(--fs-h3);
  letter-spacing: var(--tracking-heading);
}
.palette__search input::placeholder { color: var(--text-faint); }
.palette__list { overflow: auto; padding: var(--s2); }
.palette__group { padding: var(--s3) var(--s3) var(--s1); }
.palette__item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-sm);
  text-align: left;
  color: var(--text-secondary);
  transition: background-color var(--dur-instant) linear;
}
.palette__item[data-active="true"] {
  background: var(--accent-soft);
  color: var(--text-primary);
}
.palette__item[data-active="true"] .palette__go { opacity: 1; }
.palette__item .ico { color: var(--text-muted); }
.palette__item[data-active="true"] .ico { color: var(--accent); }
.palette__text { display: grid; gap: 1px; min-width: 0; flex: 1; }
.palette__go { margin-left: auto; opacity: 0; }
.palette__foot {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s2) var(--s4);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-xs);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 1px 0 var(--border-strong);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

/* ==========================================================================
   Toast
   ========================================================================== */
.toast-root {
  position: fixed;
  right: var(--s5);
  bottom: var(--s5);
  z-index: var(--z-toast);
  display: grid;
  gap: var(--s2);
  justify-items: end;
  pointer-events: none;
}
.toast {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: var(--s3);
  width: min(380px, calc(100vw - var(--s8)));
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  box-shadow: var(--e3);
  pointer-events: auto;
  overflow: hidden;
  animation: toast-in var(--dur-3) var(--ease-spring);
}
.toast[data-closing="true"] { animation: toast-out var(--dur-2) var(--ease-in-out) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(18px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(12px) scale(0.98); } }
.toast__icon { margin-top: 1px; color: var(--text-muted); }
.toast--success .toast__icon { color: var(--success); }
.toast--warning .toast__icon { color: var(--warning); }
.toast--error .toast__icon { color: var(--error); }
.toast--info .toast__icon { color: var(--info); }
.toast__text { display: grid; gap: 2px; min-width: 0; }
.toast__bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  transform-origin: left;
  background: var(--accent);
  animation: toast-bar linear forwards;
}
@keyframes toast-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ==========================================================================
   Tooltip
   ========================================================================== */
.tip {
  position: fixed;
  z-index: var(--z-popover);
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 5px var(--s2);
  border-radius: var(--r-sm);
  background: var(--surface-inverse);
  color: var(--text-on-inverse);
  font-size: var(--fs-caption);
  white-space: nowrap;
  box-shadow: var(--e3);
  pointer-events: none;
  animation: tip-in var(--dur-1) var(--ease-out);
}
@keyframes tip-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.tip .kbd { background: color-mix(in srgb, var(--surface-inverse) 70%, var(--text-on-inverse)); border-color: transparent; color: inherit; box-shadow: none; }

/* ==========================================================================
   Charts — restrained axes, expressive data
   ========================================================================== */
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; overflow: visible; }
.chart .ch-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .ch-axis { fill: var(--text-faint); font-size: 10px; font-family: var(--font-mono); }
.chart .ch-area { opacity: 0.16; }
.chart .ch-line { fill: none; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.chart .ch-bar { transition: opacity var(--dur-1) linear; }
.chart .ch-bar--dim { opacity: 0.35; }
.chart .ch-cross { stroke: var(--border-hover); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .ch-node { stroke: var(--surface); stroke-width: 2; }
.chart .ch-enter { animation: ch-reveal var(--dur-5) var(--ease-out) forwards; }
@keyframes ch-reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.chart__tip {
  position: absolute;
  z-index: 3;
  min-width: 128px;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-sm);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  box-shadow: var(--e3);
  pointer-events: none;
  transform: translate(var(--tip-x, 0), var(--tip-y, 0));
  transition: transform var(--dur-instant) linear;
}
.chart__legend { display: flex; flex-wrap: wrap; gap: var(--s4); }
.chart__legend button {
  display: flex; align-items: center; gap: var(--s2);
  font-size: var(--fs-caption); color: var(--text-secondary);
  transition: opacity var(--dur-1) linear;
}
.chart__legend button[aria-pressed="false"] { opacity: 0.4; }
.legend-swatch { width: 8px; height: 8px; border-radius: 2px; background: var(--swatch, var(--accent)); }

/* Distribution bar — compact composition visual */
.bar-track {
  display: flex;
  height: 6px;
  border-radius: var(--r-full);
  overflow: hidden;
  background: var(--skeleton-base);
}
.bar-track span {
  height: 100%;
  width: var(--w, 0%);
  background: var(--c, var(--accent));
  transition: width var(--dur-4) var(--ease-out);
}

/* Ranked bars */
.rank { display: grid; gap: var(--s1); }
.rank__row {
  display: grid;
  grid-template-columns: minmax(80px, 150px) minmax(0, 1fr) 56px;
  gap: var(--s3);
  align-items: center;
  padding: var(--s2) var(--s2);
  border-radius: var(--r-sm);
  text-align: left;
  transition: background-color var(--dur-1) var(--ease-out);
}
.rank__row:hover { background: var(--surface-raised); }
.rank__track { height: 8px; border-radius: var(--r-full); background: var(--skeleton-base); overflow: hidden; }
.rank__label { min-width: 0; }
.rank__fill {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  border-radius: var(--r-full);
  background: var(--c, var(--accent));
  transition: width var(--dur-5) var(--ease-out);
}
.rank__value { text-align: right; color: var(--text-primary); }
.rank__row:hover .rank__fill { filter: brightness(1.12); }

/* Donut */
.donut { display: flex; align-items: center; gap: var(--s6); flex-wrap: wrap; }
.donut__figure { position: relative; display: grid; place-items: center; flex: none; }
.donut__center { position: absolute; display: grid; justify-items: center; gap: 0; text-align: center; pointer-events: none; }
.donut__legend { display: grid; gap: var(--s2); min-width: 160px; flex: 1; }
.donut circle { transition: stroke-width var(--dur-2) var(--ease-out); cursor: pointer; }

.spark { display: block; overflow: visible; }

/* ==========================================================================
   Misc
   ========================================================================== */
.avatar {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-caption);
  font-weight: var(--fw-semibold);
}
.avatar--lg { width: 34px; height: 34px; border-radius: var(--r-md); font-size: var(--fs-secondary); }

/* Definition list — label / value pairs inside inspectors and detail views */
.dl { display: grid; gap: var(--s3); }
.dl__row { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: var(--s4); align-items: start; }
.dl__row dd { margin: 0; min-width: 0; word-break: break-word; }

.code-block {
  padding: var(--s3);
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--fs-caption);
  color: var(--text-secondary);
  overflow: auto;
  white-space: pre;
}

.notice {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}
.notice .ico { margin-top: 2px; color: var(--text-muted); }
.notice--warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 22%, transparent); color: color-mix(in srgb, var(--warning) 82%, var(--text-primary)); }
.notice--warning .ico { color: var(--warning); }
.notice--error { background: var(--error-soft); border-color: color-mix(in srgb, var(--error) 22%, transparent); }
.notice--error .ico { color: var(--error); }
.notice--info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.notice--info .ico { color: var(--info); }
.notice--success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.notice--success .ico { color: var(--success); }

/* Step indicator for multi-step forms */
.steps { display: flex; align-items: center; gap: var(--s2); }
.steps__item { display: flex; align-items: center; gap: var(--s2); }
.steps__dot {
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  transition: all var(--dur-2) var(--ease-spring);
}
.steps__item[data-state="active"] .steps__dot { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }
.steps__item[data-state="done"] .steps__dot { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 40%, transparent); color: var(--success); }
.steps__item[data-state="active"] .steps__name { color: var(--text-primary); }
.steps__name { font-size: var(--fs-caption); color: var(--text-muted); }
.steps__link { width: 20px; height: 1px; background: var(--border-strong); }

/* Impact preview: before → after */
.impact {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-md);
  background: var(--bg-sunken);
  border: 1px dashed var(--border-strong);
  font-family: var(--font-mono);
  font-size: var(--fs-secondary);
  font-variant-numeric: tabular-nums;
}
.impact__from { color: var(--text-muted); }
.impact__to { color: var(--text-primary); font-weight: var(--fw-semibold); }
.impact__arrow { color: var(--accent); }

/* Result receipt after a write */
.receipt {
  display: grid;
  gap: var(--s3);
  padding: var(--s5);
  border-radius: var(--r-lg);
  background: var(--success-soft);
  border: 1px solid color-mix(in srgb, var(--success) 26%, transparent);
}
.receipt__rows { display: grid; gap: var(--s2); }
.receipt__row { display: flex; gap: var(--s4); font-size: var(--fs-secondary); }
.receipt__row dt { width: 88px; flex: none; color: var(--text-muted); }
.receipt__row dd { margin: 0; font-family: var(--font-mono); word-break: break-all; }

/* Registration notice live preview (console events page) */
.notice-preview {
  margin: 0;
  padding: var(--s4);
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: var(--fs-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
}

/* View transition wrapper */
.view { animation: view-in var(--dur-3) var(--ease-out); }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.view[data-leaving="true"] { animation: view-out var(--dur-1) var(--ease-in-out) forwards; }
@keyframes view-out { to { opacity: 0; transform: translateY(-4px); } }

/* Staggered list entrance */
.stagger > * {
  animation: stagger-in var(--dur-4) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 34ms);
}
@keyframes stagger-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
