/* RestoreFlow components. Pattern numbers refer to docs/verification-matrix.md. */

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --------------------------------------------------------------- buttons
   Press feedback (1, 49): the face scales to 0.96 and sinks 1px while pressed, then
   springs back. Only transform and box-shadow change, so the hit area never moves.
   Raised buttons use the layered lighting recipe (44-48) with the theme's own values. */
.btn {
  --btn-bg: var(--surface); --btn-bg-top: var(--surface); --btn-fg: var(--text); --btn-border: var(--border-strong);
  --btn-glow: 0 0 0 transparent;
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-h); padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--btn-border);
  background: linear-gradient(var(--btn-bg-top), var(--btn-bg)); color: var(--btn-fg);
  font-weight: 600; font-size: var(--text-md); line-height: 1; white-space: nowrap; text-decoration: none;
  box-shadow: var(--btn-highlight), var(--btn-shade), var(--btn-contact), var(--btn-glow);
  transition: transform var(--dur-expand) var(--ease-spring), box-shadow var(--dur-fast), background var(--dur-fast), filter var(--dur-fast);
  -webkit-tap-highlight-color: transparent; user-select: none; touch-action: manipulation;
}
.btn:hover { filter: brightness(1.04); }
.btn:active, .btn.is-pressed {
  transform: translateY(1px) scale(0.96); box-shadow: var(--btn-pressed);
  transition-duration: var(--dur-press); transition-timing-function: var(--ease-out);
}
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; filter: none; transform: none; box-shadow: none; }
.btn .icon { width: 18px; height: 18px; }
.btn .label { color: inherit; font: inherit; }
.btn-primary {
  --btn-bg: var(--primary); --btn-bg-top: var(--primary-top); --btn-fg: var(--on-primary); --btn-border: transparent;
  --btn-glow: 0 8px 20px -8px var(--primary-glow);
}
.btn-danger {
  --btn-bg: var(--danger); --btn-bg-top: var(--danger-top); --btn-fg: #fff; --btn-border: transparent;
  --btn-glow: 0 8px 20px -8px rgb(179 38 30 / 0.35);
}
:root[data-theme="dark"] .btn-danger { --btn-fg: #2a0705; }
.btn-ghost { --btn-bg: transparent; --btn-bg-top: transparent; --btn-border: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-sunken); filter: none; }
.btn-ghost:active { box-shadow: none; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn-lg { min-height: 52px; padding: 0 22px; font-size: var(--text-base); }
.btn-block { width: 100%; }
@media (pointer: coarse) { .btn-sm { min-height: 40px; } }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: 32px; }
@media (pointer: coarse) { .btn-icon.btn-sm { width: 40px; } }
.topbar .btn-ghost, .sidebar .btn-ghost { color: inherit; }
.topbar .btn-ghost:hover, .sidebar .btn-ghost:hover { background: rgb(255 255 255 / 0.1); }
.btn .spinner { width: 16px; height: 16px; }
.btn.is-busy { pointer-events: none; }
.btn.is-busy > :not(.spinner):not(.sr-only) { opacity: 0.55; }

.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--text-sm); font-weight: 600; color: var(--text-2); }
.field .hint { font-size: var(--text-sm); color: var(--text-muted); }
.field .error { font-size: var(--text-sm); color: var(--danger); font-weight: 550; display: flex; gap: 6px; align-items: flex-start; }
.field .error .icon { width: 16px; height: 16px; margin-top: 2px; }
.input, .select, .textarea {
  width: 100%; min-height: var(--control-h); padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: max(16px, var(--text-md)); /* 16px+ stops iOS zoom */
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgb(21 147 214 / 0.25); }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); }
.select { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }
.form-actions { display: flex; gap: var(--space-2); justify-content: flex-end; flex-wrap: wrap; margin-top: var(--space-5); }
.error-summary { padding: 12px 14px; border-radius: var(--radius); background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); font-weight: 550; margin-bottom: var(--space-4); }
.error-summary a { color: inherit; }

/* Rejection feedback (10): a short damped shake of the field, never the only signal. */
.shake { animation: shake 360ms var(--ease-out); }
@keyframes shake { 0%,100% { transform: translateX(0); } 15% { transform: translateX(-7px); } 35% { transform: translateX(6px); } 55% { transform: translateX(-4px); } 75% { transform: translateX(2px); } }
@media (prefers-reduced-motion: reduce) { .shake { animation: none; } }

/* Switch with spring travel and stretch (7). The checked state updates at once;
   only the thumb's presentation animates, so rapid toggles stay interruptible. */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: var(--touch); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative; width: 46px; height: 28px; flex: none; border-radius: 14px; background: var(--border-strong);
  transition: background var(--dur-base) var(--ease-out);
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 11px; background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); display: grid; place-items: center;
  transition: transform var(--dur-expand) var(--ease-spring), width var(--dur-fast) var(--ease-out);
}
.switch-thumb svg { width: 12px; height: 12px; stroke: var(--primary); stroke-width: 3; opacity: 0; transition: opacity var(--dur-fast); }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:checked + .switch-track .switch-thumb svg { opacity: 1; }
.switch input:active + .switch-track .switch-thumb { width: 28px; }
.switch input:checked:active + .switch-track .switch-thumb { transform: translateX(12px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.45; }
.switch-label { font-weight: 550; }

.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; gap: 2px; border-radius: 12px; background: var(--surface-sunken); position: relative; }
.segmented button {
  position: relative; z-index: 1; min-height: 38px; padding: 0 16px; border: 0; border-radius: 9px; background: transparent;
  color: var(--text-2); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.segmented button[aria-checked="true"] { color: var(--text); }
.segmented .seg-thumb { position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; border-radius: 9px; background: var(--surface); box-shadow: var(--shadow-1); transition: transform var(--dur-base) var(--ease-out), width var(--dur-base) var(--ease-out); }
@media (pointer: coarse) { .segmented button { min-height: var(--touch); } }

.checkbox { width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; margin: 0; }
@media (pointer: coarse) { .checkbox { width: 22px; height: 22px; } }
.check-hit { display: grid; place-items: center; min-width: var(--touch); min-height: var(--touch); margin: -10px; }

/* --------------------------------------------------------- badges, chips */
.status {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 700; white-space: nowrap;
  color: var(--st, var(--text-2)); background: var(--st-bg, var(--surface-sunken));
}
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status[data-status="inquiry"] { --st: var(--st-inquiry); --st-bg: var(--st-inquiry-bg); }
.status[data-status="scheduled"] { --st: var(--st-scheduled); --st-bg: var(--st-scheduled-bg); }
.status[data-status="in_progress"] { --st: var(--st-in_progress); --st-bg: var(--st-in_progress-bg); }
.status[data-status="monitoring"] { --st: var(--st-monitoring); --st-bg: var(--st-monitoring-bg); }
.status[data-status="completed"] { --st: var(--st-completed); --st-bg: var(--st-completed-bg); }
.status[data-status="closed"] { --st: var(--st-closed); --st-bg: var(--st-closed-bg); }
.status[data-status="cancelled"] { --st: var(--st-cancelled); --st-bg: var(--st-cancelled-bg); }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--surface-sunken); color: var(--text-2); font-size: var(--text-xs); font-weight: 650; white-space: nowrap; }
.tag.urgent { background: var(--danger-bg); color: var(--danger); }
.tag.warn { background: var(--warning-bg); color: var(--warning); }
.tag.ok { background: var(--success-bg); color: var(--success); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  min-height: 34px; padding: 0 12px; border-radius: var(--radius-pill); border: 1px solid var(--border-strong); background: var(--surface);
  font-size: var(--text-sm); font-weight: 600; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--dur-fast), border-color var(--dur-fast), transform var(--dur-expand) var(--ease-spring);
}
.chip[aria-pressed="true"] { background: var(--selection); border-color: var(--primary); color: var(--primary); }
.chip:active { transform: scale(0.95); transition-duration: var(--dur-press); }
@media (pointer: coarse) { .chip { min-height: 40px; } }

/* ------------------------------------------------------------------ cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.card-pad { padding: var(--space-5); }
@media (max-width: 760px) { .card-pad { padding: var(--space-4); } }
.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { display: flex; align-items: center; gap: 8px; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; }
.card-body { padding: var(--space-4) var(--space-5); }
.card + .card { margin-top: var(--space-4); }
.grid > .card, .kpis > .card, .dash > .card, .job-side > .card { margin-top: 0; }
.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.stat { padding: var(--space-4) var(--space-5); }
.stat-label { font-size: var(--text-sm); color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; margin-top: 4px; display: flex; align-items: baseline; gap: 8px; }
.stat-note { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }

/* Rolling digits (3): each digit is a clipped window over a strip of numerals. The
   accessible name carries the final value; the strip itself is hidden from AT. */
.roll { display: inline-flex; font-variant-numeric: tabular-nums; }
.roll-digit { display: inline-block; height: 1.15em; overflow: hidden; line-height: 1.15; }
.roll-strip { display: flex; flex-direction: column; transition: transform 520ms var(--ease-out); }
.roll-strip span { height: 1.15em; }

/* Pattern 52: bars beside their numbers, drawn on a real 0-to-max scale and grown
   with the same 520 ms ease-out as the rolling digits (ui/motion.js growBars). */
.bar-cell { display: inline-flex; align-items: center; justify-content: flex-end; gap: 10px; }
.bar-track { width: 96px; height: 8px; border-radius: 4px; background: var(--surface-sunken); overflow: hidden; flex: none; }
.bar-fill { display: block; height: 100%; background: var(--primary); transform-origin: left center; transform: scaleX(0); }
.bar-val { min-width: 2ch; text-align: right; }
@media (max-width: 760px) { .bar-track { width: 48px; } }

/* Pattern 51: page groups rise into place, staggered (ui/motion.js enterPage).
   Transform only; an opacity-0 first frame can stick in some embedded browsers. */
@keyframes page-enter { from { transform: translateY(10px); } }
.enter { animation: page-enter 300ms var(--ease-out) both; animation-delay: calc(var(--enter-i, 0) * 45ms); }
@media (prefers-reduced-motion: reduce) { .enter { animation: none; } }

/* ------------------------------------------------------ lists and rows */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px var(--space-5);
  border-top: 1px solid var(--border); color: inherit; text-decoration: none; background: var(--surface);
}
.list > .row:first-child { border-top: 0; }
a.row:hover, button.row:hover { background: var(--surface-2); }
button.row { width: 100%; border: 0; border-top: 1px solid var(--border); text-align: left; font: inherit; }
.row-main { min-width: 0; flex: 1 1 160px; }
.row-title { font-weight: 600; color: var(--text); }
.row-sub { font-size: var(--text-sm); color: var(--text-muted); }
.row-meta { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: none; }
.row-time { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 72px; color: var(--text); }
/* Phones: a row's tags and buttons drop below the title instead of squeezing it
   into a narrow column. The title keeps at least 160px on the first line. */
@media (max-width: 760px) {
  .row { flex-wrap: wrap; row-gap: 8px; padding-inline: var(--space-4); }
  .row-meta { flex-wrap: wrap; }
}

/* Deletion with gap closure (12): the row stays in the flow while it fades and its
   height collapses; it is removed from the DOM only when that ends. */
.is-exiting { overflow: hidden; animation: row-exit var(--dur-base) var(--ease-in) forwards; pointer-events: none; }
@keyframes row-exit { 0% { opacity: 1; max-height: var(--h, 120px); } 40% { opacity: 0; } 100% { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; margin: 0; border-width: 0; } }
.is-entering { animation: row-enter var(--dur-base) var(--ease-out); }
@keyframes row-enter { from { transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) { .is-exiting, .is-entering { animation-duration: 0.01ms; } }

.empty { padding: var(--space-8) var(--space-5); text-align: center; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .icon { width: 28px; height: 28px; color: var(--text-muted); }
.empty-title { font-weight: 650; color: var(--text); }

.state {
  max-width: 520px; margin: var(--space-10) auto; text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
}
.state-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-sunken); color: var(--text-2); }
.state-icon .icon { width: 28px; height: 28px; }
.state.is-error .state-icon { background: var(--danger-bg); color: var(--danger); }
.state.is-denied .state-icon { background: var(--warning-bg); color: var(--warning); }
.state .ref { font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text-muted); }

.callout { display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--info-border); background: var(--info-bg); color: var(--info); font-size: var(--text-sm); }
.callout .icon { margin-top: 1px; }
.callout.warn { border-color: var(--warning-border); background: var(--warning-bg); color: var(--warning); }
.callout.ok { border-color: var(--success-border); background: var(--success-bg); color: var(--success); }
.callout.danger { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger); }
.callout p + p { margin-top: 4px; }
.callout strong { color: inherit; }

/* -------------------------------------------------------------- skeletons
   Placeholders reuse the real card's spacing (19) and reserve its footprint (21).
   The shimmer is a gradient moving across a clipped area (20), off under reduced motion. */
.sk { position: relative; overflow: hidden; background: var(--skeleton); border-radius: 6px; }
.sk::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
  animation: shimmer 1.6s ease-in-out infinite;
}
:root[dir="rtl"] .sk::after { animation-direction: reverse; }
@keyframes shimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .sk::after { animation: none; display: none; } }
.sk-line { height: 12px; margin: 6px 0; }
.sk-title { height: 16px; width: 55%; }
.sk-circle { border-radius: 50%; }
.sk-pill { height: 24px; width: 86px; border-radius: 12px; }

/* --------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-md); }
.table th {
  position: sticky; top: 0; z-index: 1; text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); font-weight: 700; background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background var(--dur-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr[aria-selected="true"] { background: var(--selection); }
.table .col-check { width: 44px; padding-right: 0; }
.table a.cell-link { color: var(--text); font-weight: 600; text-decoration: none; }
.table a.cell-link:hover { text-decoration: underline; }
.table .num { font-variant-numeric: tabular-nums; }
.table-foot { display: flex; align-items: center; gap: 12px; padding: 10px 12px; font-size: var(--text-sm); color: var(--text-muted); flex-wrap: wrap; }
.table-foot .pager { margin-left: auto; display: flex; gap: 6px; align-items: center; }

/* Selection bar (23-26): always states the scope by number. */
.selection-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: var(--radius);
  background: var(--brand); color: var(--on-brand); margin-bottom: var(--space-3); box-shadow: var(--shadow-2);
}
.selection-bar .btn { --btn-bg: rgb(255 255 255 / 0.1); --btn-bg-top: rgb(255 255 255 / 0.16); --btn-fg: #fff; --btn-border: rgb(255 255 255 / 0.18); box-shadow: none; }
.selection-bar .btn-danger { --btn-bg: var(--danger); --btn-bg-top: var(--danger-top); --btn-border: transparent; }
.selection-bar .link-btn { color: var(--accent); }
.selection-count { font-weight: 700; }
.link-btn { border: 0; background: none; padding: 4px 2px; color: var(--link); font-weight: 650; text-decoration: underline; text-underline-offset: 2px; min-height: 32px; }

/* ----------------------------------------------------------------- tabs
   One indicator slides between the active tab's measured bounds (11). */
.tabs { position: relative; display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
/* When tabs overflow, the clipped edge fades so it reads as "more this way". */
[data-more="end"] { mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); }
[data-more="start"] { mask-image: linear-gradient(to left, #000 calc(100% - 40px), transparent); }
[data-more="both"] { mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); }
.tab {
  position: relative; min-height: 44px; padding: 0 14px; border: 0; background: none; color: var(--text-muted);
  font-weight: 650; font-size: var(--text-md); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.tab[aria-selected="true"] { color: var(--text); }
.tab:hover { color: var(--text); }
.tab .count { font-size: var(--text-xs); padding: 1px 6px; border-radius: 9px; background: var(--surface-sunken); color: var(--text-2); }
.tabs-indicator { position: absolute; bottom: -1px; left: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--primary); transition: transform var(--dur-base) var(--ease-out), width var(--dur-base) var(--ease-out); }

/* ------------------------------------------------------------------ menus
   A menu grows from its trigger (9): transform-origin is set from the trigger's side. */
.menu {
  position: fixed; z-index: 60; min-width: 200px; max-width: min(320px, calc(100vw - 16px)); padding: 6px;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-3);
  transform-origin: var(--origin, top left); animation: menu-in var(--dur-base) var(--ease-out);
}
.menu.is-closing { animation: menu-out var(--dur-fast) var(--ease-in) forwards; }
/* entrance keyframes animate transform only: an opacity-0 first frame can stick in some
   embedded/emulated browsers and leave the surface invisible */
@keyframes menu-in { from { transform: scale(0.92); } }
@keyframes menu-out { to { opacity: 0; transform: scale(0.95); } }
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border: 0; border-radius: 7px;
  background: none; text-align: left; color: var(--text); font-weight: 550; font-size: var(--text-md);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-sunken); outline: none; }
.menu-item[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.menu-item.danger { color: var(--danger); }
.menu-item .hint { margin-left: auto; font-size: var(--text-xs); color: var(--text-muted); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu-label { padding: 6px 10px 4px; font-size: var(--text-xs); font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
@media (pointer: coarse) { .menu-item { min-height: var(--touch); } }

/* ---------------------------------------------------------------- dialogs */
dialog.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: min(88dvh, 860px); padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow-3);
  overflow: hidden; display: flex; flex-direction: column;
}
dialog.dialog:not([open]) { display: none; }
dialog.dialog.wide { width: min(760px, calc(100vw - 24px)); }
dialog.dialog::backdrop { background: var(--overlay); }
dialog.dialog[open] { animation: dialog-in var(--dur-expand) var(--ease-out); }
@keyframes dialog-in { from { transform: translateY(8px) scale(0.98); } }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: var(--text-lg); }
.dialog-head .btn { margin-left: auto; margin-right: -8px; }
.dialog-body { padding: 20px; overflow-y: auto; overscroll-behavior: contain; }
.dialog-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
@media (max-width: 760px) {
  /* on phones dialogs become bottom sheets that respect the keyboard and safe area */
  dialog.dialog, dialog.dialog.wide {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: calc(100dvh - 24px);
    padding-bottom: env(safe-area-inset-bottom);
  }
  dialog.dialog[open] { animation: sheet-in var(--dur-expand) var(--ease-out); }
  @keyframes sheet-in { from { transform: translateY(40px); } }
  .dialog-foot .btn { flex: 1; }
}

/* ----------------------------------------------------------------- toasts */
.toasts {
  position: fixed; z-index: 80; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none;
}
@media (max-width: 760px) { .toasts { left: 16px; right: 16px; width: auto; bottom: calc(76px + env(safe-area-inset-bottom)); } }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--gray-800); color: #fff; box-shadow: var(--shadow-3); animation: toast-in var(--dur-base) var(--ease-out);
}
:root[data-theme="dark"] .toast { background: var(--gray-700); }
.toast.is-closing { animation: toast-out var(--dur-fast) var(--ease-in) forwards; }
@keyframes toast-in { from { transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
.toast .icon { width: 20px; height: 20px; margin-top: 1px; }
.toast-main { flex: 1; min-width: 0; }
.toast-title { font-weight: 650; }
.toast-text { font-size: var(--text-sm); opacity: 0.85; }
.toast .toast-action { border: 0; background: none; color: var(--sky-300); font-weight: 700; padding: 4px 6px; margin: -4px 0; min-height: 32px; }
.toast .toast-close { border: 0; background: none; color: #fff; opacity: 0.7; padding: 2px; margin: -2px -4px 0 0; }
.toast.success .icon { color: #6fd3a2; } .toast.error .icon { color: #ff8f86; } .toast.warning .icon { color: #f5c56b; }
.toast-timer { height: 2px; margin-top: 8px; background: rgb(255 255 255 / 0.25); border-radius: 2px; overflow: hidden; }
.toast-timer > i { display: block; height: 100%; background: var(--sky-300); transform-origin: left; animation: timer linear forwards; }
@keyframes timer { to { transform: scaleX(0); } }

/* -------------------------------------------------------------- progress */
.progress { height: 6px; border-radius: 3px; background: var(--surface-sunken); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 100%; background: var(--primary); transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform 200ms linear; }
.progress.indeterminate > i { width: 35%; transform: none; animation: indet 1.2s var(--ease-standard) infinite; }
@keyframes indet { from { margin-left: -35%; } to { margin-left: 100%; } }
.stages { display: flex; flex-direction: column; gap: 6px; font-size: var(--text-sm); }
.stage { display: flex; align-items: center; gap: 8px; color: var(--text-muted); }
.stage .icon { width: 16px; height: 16px; }
.stage[data-state="active"] { color: var(--text); font-weight: 600; }
.stage[data-state="done"] { color: var(--success); }
.stage[data-state="failed"] { color: var(--danger); }

/* Success mark (6): circle draws, then the check. Static under reduced motion. */
.success-mark { width: 64px; height: 64px; color: var(--success); }
.success-mark circle { stroke-dasharray: 151; stroke-dashoffset: 151; animation: draw 300ms var(--ease-out) forwards; }
.success-mark path { stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw 170ms var(--ease-out) 300ms forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .success-mark circle, .success-mark path { animation: none; stroke-dashoffset: 0; } }

/* Pop and burst for a deliberate toggle (8). The burst is decoration only. */
.pop { animation: pop 300ms var(--ease-spring); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
.burst { position: absolute; inset: -8px; pointer-events: none; }
.burst i { position: absolute; left: 50%; top: 50%; width: 3px; height: 7px; border-radius: 2px; background: var(--accent); transform: rotate(var(--a)) translateY(-6px); animation: burst 420ms var(--ease-out) forwards; }
@keyframes burst { to { transform: rotate(var(--a)) translateY(-20px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .pop, .burst i { animation: none; } .burst { display: none; } }

/* Milestone celebration (37): short, non-blocking, never for routine saves. */
.celebrate { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.celebrate i { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; animation: fall var(--d, 1.4s) var(--ease-in) forwards; }
@keyframes fall { to { transform: translate(var(--x), 105vh) rotate(var(--r)); opacity: 0.2; } }

/* ------------------------------------------------- stateful icon buttons */
.ib { position: relative; display: inline-grid; place-items: center; }
.ib svg { overflow: visible; }
/* theme: sun rays retract and the disk is cut into a crescent (29) */
.ic-theme .rays { transform-origin: 12px 12px; transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-base); }
.ic-theme .cut { transition: transform var(--dur-slow) var(--ease-out); }
.ic-theme .disk { transform-origin: 12px 12px; transition: transform var(--dur-slow) var(--ease-out); }
.ic-theme[data-state="dark"] .rays { transform: scale(0.4) rotate(-45deg); opacity: 0; }
.ic-theme[data-state="dark"] .cut { transform: translate(-6px, 4px); }
.ic-theme[data-state="dark"] .disk { transform: scale(1.35); }
.ic-theme:not([data-state="dark"]) .cut { transform: translate(6px, -6px); }
/* search magnifier becomes a close X (30) */
.ic-search .ring { stroke-dasharray: 32; stroke-dashoffset: 0; transition: stroke-dashoffset var(--dur-base) var(--ease-out); }
.ic-search .l1, .ic-search .l2 { transition: d var(--dur-base) var(--ease-out); }
.ic-search[data-state="close"] .ring { stroke-dashoffset: 32; }
.ic-search[data-state="close"] .l1 { d: path('M6 6L18 18'); }
.ic-search[data-state="close"] .l2 { d: path('M18 6L6 18'); }
/* download arrow -> progress ring -> check (28) */
.ic-download .arrow, .ic-download .check, .ic-download .track, .ic-download .bar { transition: opacity var(--dur-fast), transform var(--dur-base) var(--ease-out); transform-origin: 12px 12px; }
.ic-download .bar { stroke-dasharray: 56.5; stroke-dashoffset: calc(56.5 * (1 - var(--p, 0))); transform: rotate(-90deg); transition: stroke-dashoffset 200ms linear, opacity var(--dur-fast); }
.ic-download:not([data-state="progress"]) .track, .ic-download:not([data-state="progress"]) .bar { opacity: 0; }
.ic-download[data-state="progress"] .arrow, .ic-download:not([data-state="done"]) .check { opacity: 0; transform: scale(0.6); }
.ic-download[data-state="done"] .arrow { opacity: 0; transform: translateY(6px); }
.ic-download[data-state="indeterminate"] .bar { opacity: 1; stroke-dashoffset: 40; animation: spin 0.9s linear infinite; }
.ic-download[data-state="indeterminate"] .track { opacity: 1; }
.ic-download[data-state="indeterminate"] .arrow { opacity: 0; }
/* paper plane flies out and springs back (31) */
.ic-send .plane { transition: transform var(--dur-expand) var(--ease-spring); }
.ic-send[data-state="sending"] .plane { animation: fly 420ms var(--ease-in) forwards; }
@keyframes fly { 60% { transform: translate(14px, -14px) scale(0.6); opacity: 0; } 61% { transform: translate(-10px, 10px) scale(0.6); opacity: 0; } 100% { transform: none; opacity: 1; } }
/* lock shackle springs open with overshoot (32) */
.ic-lock .shackle { transition: transform 420ms var(--ease-spring); transform-origin: 16px 11px; }
.ic-lock[data-state="open"] .shackle { transform: translateY(-3px) rotate(-12deg) translateX(-1px); }
/* play to pause (27) */
.ic-play .a, .ic-play .b { transition: d 300ms var(--ease-out); }
.ic-play[data-state="playing"] .a { d: path('M7 5L10 5L10 19L7 19Z'); }
.ic-play[data-state="playing"] .b { d: path('M14 5L17 5L17 19L14 19Z'); }
@media (prefers-reduced-motion: reduce) { .ib *, .ic-send[data-state="sending"] .plane { transition: none !important; animation: none !important; } }

/* -------------------------------------------------- reorderable list (4) */
.reorder-list { position: relative; }
.reorder-item { position: relative; display: flex; align-items: center; gap: 8px; background: var(--surface); transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base); }
.reorder-item.is-dragging { z-index: 5; transform: translateY(var(--dy, 0)) scale(1.03); box-shadow: var(--shadow-3); border-radius: var(--radius); transition: box-shadow var(--dur-base), transform 0s; }
.reorder-item.is-shifting { transition: transform var(--dur-base) var(--ease-out); }
.drag-handle { display: grid; place-items: center; width: 32px; min-height: var(--touch); color: var(--text-muted); cursor: grab; border: 0; background: none; touch-action: none; border-radius: 6px; }
.drag-handle:active { cursor: grabbing; }
.reorder-placeholder { border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }

/* -------------------------------------------------- pull to refresh (2) */
.ptr { position: relative; }
.ptr-indicator {
  position: absolute; left: 50%; top: 0; width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow-2); display: grid; place-items: center; color: var(--primary);
  transform: translateY(calc(var(--pull, 0px) - 48px)) rotate(calc(var(--pull, 0px) * 3deg)); opacity: var(--pull-o, 0);
}
.ptr-content { transform: translateY(var(--pull, 0px)); }
.ptr.is-settling .ptr-content, .ptr.is-settling .ptr-indicator { transition: transform var(--dur-base) var(--ease-out), opacity var(--dur-base); }
.ptr[data-state="refreshing"] .ptr-indicator .icon { animation: spin 0.8s linear infinite; }

/* --------------------------------------------- resizable split panel (38-43) */
.split { display: grid; grid-template-columns: var(--pane-w, 380px) auto minmax(0, 1fr); min-height: 0; }
.split[data-collapsed="true"] { grid-template-columns: 0 auto minmax(0, 1fr); }
.split[data-collapsed="true"] > .split-pane-a { visibility: hidden; overflow: hidden; }
.split-pane-a { min-width: 0; overflow: auto; }
.split-pane-b { min-width: 0; overflow: auto; }
.splitter { position: relative; width: 1px; background: var(--border); cursor: col-resize; touch-action: none; outline: none; }
.splitter::before { content: ''; position: absolute; inset: 0 -6px; } /* 12px grab area around a 1px line */
.splitter::after { content: ''; position: absolute; top: 0; bottom: 0; left: -1px; width: 3px; background: var(--primary); opacity: 0; transition: opacity var(--dur-fast); }
.splitter:hover::after, .splitter:focus-visible::after, .splitter.is-dragging::after { opacity: 1; }
.splitter-grip { position: absolute; top: 50%; left: -8px; width: 17px; height: 36px; margin-top: -18px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border-strong); display: grid; place-items: center; color: var(--text-muted); opacity: 0; transition: opacity var(--dur-fast); }
.splitter:hover .splitter-grip, .splitter:focus-visible .splitter-grip { opacity: 1; }
.drag-shield { position: fixed; inset: 0; z-index: 70; cursor: col-resize; background: transparent; }
body.is-resizing { user-select: none; cursor: col-resize; }
.split-reopen { position: absolute; left: 8px; top: 8px; z-index: 3; }

/* ------------------------------------------------- progressive image (15) */
.pimg { position: relative; overflow: hidden; background: var(--skeleton); border-radius: var(--radius); aspect-ratio: var(--ar, 4 / 3); }
.pimg img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pimg .pimg-preview { filter: blur(14px); transform: scale(1.1); }
.pimg .pimg-full { opacity: 0; transition: opacity var(--dur-slow) var(--ease-out); }
.pimg.is-loaded .pimg-full { opacity: 1; }

/* ------------------------------------------------------- expandable card (5) */
.expander { overflow: hidden; transition: height var(--dur-expand) var(--ease-out); }
.expand-toggle .icon { transition: transform var(--dur-expand) var(--ease-out); }
.expand-toggle[aria-expanded="true"] .icon { transform: rotate(180deg); }

/* --------------------------------------------------------------- timeline */
.timeline { position: relative; display: flex; flex-direction: column; }
.tl-item { position: relative; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; padding: 8px 0; }
.tl-item::before { content: ''; position: absolute; left: 13px; top: 30px; bottom: -8px; width: 2px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-sunken); color: var(--text-2); }
.tl-dot .icon { width: 14px; height: 14px; }
.tl-item[data-kind^="job.status"] .tl-dot { background: var(--info-bg); color: var(--info); }
.tl-item[data-kind^="file"] .tl-dot { background: var(--success-bg); color: var(--success); }
.tl-item[data-kind^="job.note"] .tl-dot { background: var(--warning-bg); color: var(--warning); }
.tl-summary { font-weight: 550; overflow-wrap: anywhere; }
.tl-meta { font-size: var(--text-xs); color: var(--text-muted); }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; font-size: var(--text-md); }
.kv dt { color: var(--text-muted); font-weight: 550; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.divider { height: 1px; background: var(--border); margin: var(--space-4) 0; }
.inline-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.avatars { display: flex; }
.avatars .avatar { border: 2px solid var(--surface); margin-left: -6px; }
.avatars .avatar:first-child { margin-left: 0; }
.kbd { font-family: var(--font-mono); font-size: 11px; padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-2); }
