/* ==========================================================================
   Amana Design System: components
   Every interactive component ships: default, hover, focus-visible, active,
   disabled, loading (where it makes sense), error (inputs). All spacing uses
   logical properties so RTL is the source of truth and LTR is the mirror.
   ========================================================================== */

/* ---------- Button ---------- */
.btn {
  --btn-bg: transparent; --btn-fg: var(--text); --btn-border: transparent;
  --btn-bg-hover: var(--hover-wash); --btn-bg-active: var(--pressed-wash);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--control-h); min-width: var(--control-h);
  padding-inline: var(--space-5);
  border: 1px solid var(--btn-border); border-radius: var(--radius-sm);
  background: var(--btn-bg); color: var(--btn-fg);
  font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: 1.2; text-decoration: none; white-space: nowrap;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out);
}
.btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); }
.btn:active { background: var(--btn-bg-active); transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--disabled-bg); color: var(--disabled-fg); border-color: transparent; cursor: not-allowed; transform: none; pointer-events: none; }

.btn--primary { --btn-bg: var(--brand); --btn-fg: var(--on-brand); --btn-bg-hover: var(--brand-hover); --btn-bg-active: var(--brand-active); }
.btn--accent  { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bg-hover: var(--accent-hover); --btn-bg-active: var(--accent-active); }
.btn--secondary { --btn-bg: var(--surface); --btn-border: var(--border-strong); --btn-bg-hover: var(--hover-wash); }
.btn--secondary:hover { background: color-mix(in oklab, var(--surface), var(--text) 6%); }
.btn--tertiary { --btn-fg: var(--text-link); padding-inline: var(--space-3); }
.btn--ghost { --btn-fg: var(--text-2); }
.btn--danger { --btn-bg: var(--danger-solid); --btn-fg: var(--on-danger-solid); --btn-bg-hover: var(--danger-solid-hover); --btn-bg-active: var(--danger-solid-hover); }
.btn--danger-quiet { --btn-fg: var(--danger-fg); --btn-border: var(--danger-border); --btn-bg: var(--surface); --btn-bg-hover: var(--danger-bg); }
.btn--success { --btn-bg: var(--success-solid); --btn-fg: var(--on-success-solid); }

.btn--sm { min-height: var(--control-h-sm); padding-inline: var(--space-3); font-size: var(--fs-sm); border-radius: var(--radius-xs); }
.btn--lg { min-height: var(--control-h-lg); padding-inline: var(--space-6); font-size: var(--fs-base); }
.btn--xl { min-height: var(--control-h-xl); padding-inline: var(--space-8); font-size: var(--fs-lg); border-radius: var(--radius-md); }
.btn--pill { border-radius: var(--radius-pill); }
.btn--block { display: flex; width: 100%; }
.btn--icon { padding-inline: 0; width: var(--control-h); }
.btn--icon.btn--sm { width: var(--control-h-sm); }
.btn--icon.btn--lg { width: var(--control-h-lg); }
/* Hit area stays 44px even when the visual control is small */
.btn--sm::after, .btn--icon.btn--sm::after { content: ""; position: absolute; inset-block: calc((var(--hit-min) - 100%) / -2); inset-inline: 0; min-height: var(--hit-min); }

.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::before {
  content: ""; position: absolute; inset: 0; margin: auto; width: 1.1em; height: 1.1em;
  border: 2px solid var(--btn-fg); border-inline-end-color: transparent; border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.btn--primary.is-loading::before { border-color: var(--on-brand); border-inline-end-color: transparent; }
.btn--accent.is-loading::before { border-color: var(--on-accent); border-inline-end-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn.is-loading::before { animation: none; border-inline-end-color: var(--btn-fg); opacity: 0.6; } }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-start-start-radius: var(--radius-sm); border-end-start-radius: var(--radius-sm); }
.btn-group .btn:last-child { border-start-end-radius: var(--radius-sm); border-end-end-radius: var(--radius-sm); }
.btn-group .btn + .btn { margin-inline-start: -1px; }

/* Link-style action inside running text */
.link { color: var(--text-link); text-decoration: underline; text-underline-offset: 0.2em; cursor: pointer; font-weight: var(--fw-medium); }
.link:hover { color: var(--text-link-hover); }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.field__label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); line-height: 1.4; display: flex; align-items: center; gap: var(--space-1); }
.field__label .req { color: var(--danger-fg); }
.field__label .opt { color: var(--text-3); font-weight: var(--fw-regular); }
.field__hint { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.5; }
.field__error { display: none; align-items: flex-start; gap: var(--space-1); font-size: var(--fs-xs); color: var(--danger-fg); line-height: 1.5; font-weight: var(--fw-medium); }
.field.is-invalid .field__error, .field__error.is-visible { display: flex; }
.field.is-invalid .field__hint { display: none; }

.input, .select, .textarea {
  width: 100%; min-height: var(--control-h);
  padding-inline: var(--space-3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: var(--fs-base); line-height: 1.4;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-2); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible, .input:focus, .textarea:focus, .select:focus { border-color: var(--border-focus); box-shadow: var(--focus-ring); outline: none; }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--disabled-bg); color: var(--disabled-fg); border-color: var(--border); cursor: not-allowed; }
.input[readonly] { background: var(--surface-sunken); border-color: var(--border); }
.input[aria-invalid="true"], .is-invalid .input, .is-invalid .select, .is-invalid .textarea, .is-invalid .input-group { border-color: var(--danger-solid); }
.is-invalid .input:focus, .input[aria-invalid="true"]:focus { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--danger-solid); }
.is-valid .input { border-color: var(--success-solid); }
.input--lg { min-height: var(--control-h-lg); font-size: var(--fs-lg); }
.input--sm { min-height: var(--control-h-sm); font-size: var(--fs-md); }
.textarea { padding-block: var(--space-3); min-height: 6.5rem; resize: vertical; }

.select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-inline-end: 2.5rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23837e84' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-size: 18px; background-position: left 0.75rem center;
}
[dir="rtl"] .select { background-position: left 0.75rem center; }
[dir="ltr"] .select { background-position: right 0.75rem center; }

/* Input with leading or trailing adornment (icon, "+20", unit) */
.input-group {
  display: flex; align-items: stretch; width: 100%; min-height: var(--control-h);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.input-group:hover { border-color: var(--text-2); }
.input-group:focus-within { border-color: var(--border-focus); box-shadow: var(--focus-ring); }
.input-group .input { border: 0; border-radius: 0; box-shadow: none; flex: 1 1 auto; min-width: 0; background: transparent; }
.input-group .input:focus { box-shadow: none; }
.input-addon {
  display: inline-flex; align-items: center; gap: var(--space-2); padding-inline: var(--space-3);
  background: var(--surface-sunken); color: var(--text-2); font-size: var(--fs-md); font-weight: var(--fw-medium);
  border-inline-end: 1px solid var(--border);
}
.input-addon--end { border-inline-end: 0; border-inline-start: 1px solid var(--border); }
.input-addon--plain { background: transparent; border: 0; color: var(--text-3); }
.input-group .icon-btn { align-self: center; margin-inline: var(--space-1); }

.search { position: relative; }
.search .icon { position: absolute; inset-inline-start: var(--space-3); inset-block-start: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-inline-start: 2.5rem; border-radius: var(--radius-pill); }

/* Icon-only affordance (close, clear, reveal password) with a 44px hit area */
.icon-btn {
  display: inline-grid; place-items: center; width: var(--hit-min); height: var(--hit-min); min-width: var(--hit-min);
  border-radius: var(--radius-sm); color: var(--text-2); position: relative;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.icon-btn:hover { background: var(--hover-wash); color: var(--text); }
.icon-btn:active { background: var(--pressed-wash); }
.icon-btn--sm { --hit-min: 2.25rem; }
.icon-btn--round { border-radius: 50%; }
.icon-btn .dot { position: absolute; inset-block-start: 9px; inset-inline-end: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger-solid); box-shadow: 0 0 0 2px var(--surface); }

/* Checkbox and radio */
.check, .radio-input {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 1.25rem; height: 1.25rem; border: 1.5px solid var(--border-strong); background: var(--surface); cursor: pointer;
  display: inline-grid; place-items: center;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.check { border-radius: 6px; }
.radio-input { border-radius: 50%; }
.check:hover, .radio-input:hover { border-color: var(--text-2); }
.check:checked, .check:indeterminate { background: var(--brand); border-color: var(--brand); }
.check:checked::after { content: ""; width: 10px; height: 6px; border-left: 2px solid var(--on-brand); border-bottom: 2px solid var(--on-brand); transform: translateY(-1px) rotate(-45deg); }
.check:indeterminate::after { content: ""; width: 10px; height: 2px; background: var(--on-brand); border-radius: 1px; }
.radio-input:checked { border-color: var(--brand); border-width: 6px; background: var(--surface); }
.check:disabled, .radio-input:disabled { background: var(--disabled-bg); border-color: var(--border); cursor: not-allowed; }
.check:checked:disabled { background: var(--disabled-fg); border-color: var(--disabled-fg); }
.check:focus-visible, .radio-input:focus-visible { box-shadow: var(--focus-ring); }
.is-invalid .check, .check[aria-invalid="true"] { border-color: var(--danger-solid); }
.choice { display: flex; align-items: flex-start; gap: var(--space-3); min-height: var(--hit-min); padding-block: var(--space-2); cursor: pointer; font-size: var(--fs-base); line-height: 1.5; }
.choice > .check, .choice > .radio-input { margin-block-start: 0.15rem; }
.choice small { display: block; color: var(--text-3); font-size: var(--fs-xs); }
/* Choice card: large selectable option (worker language picker, request type) */
.choice-card {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); min-height: var(--row-h);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md); cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}
.choice-card:hover { background: var(--hover-wash); }
.choice-card:has(input:checked) { border-color: var(--brand); background: var(--selected-bg); box-shadow: inset 0 0 0 1px var(--brand); }
.choice-card:has(input:focus-visible) { box-shadow: var(--focus-ring); }
.choice-card > input { position: absolute; opacity: 0; pointer-events: none; }
.choice-card__mark { margin-inline-start: auto; width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 1.5px solid var(--border-strong); display: grid; place-items: center; color: transparent; }
.choice-card:has(input:checked) .choice-card__mark { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

/* Switch */
.switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; margin: 0; cursor: pointer;
  width: 2.75rem; height: 1.625rem; border-radius: var(--radius-pill); background: var(--border-strong);
  transition: background-color var(--dur-base) var(--ease-out);
}
.switch::after {
  content: ""; position: absolute; inset-block-start: 3px; inset-inline-start: 3px; width: 1.25rem; height: 1.25rem; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur-base) var(--ease-out);
}
.switch:checked { background: var(--brand); }
.switch:checked::after { transform: translateX(1.125rem); }
[dir="rtl"] .switch:checked::after { transform: translateX(-1.125rem); }
.switch:disabled { opacity: 0.5; cursor: not-allowed; }
.switch:focus-visible { box-shadow: var(--focus-ring); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); min-height: var(--row-h); }

/* Range */
.range { appearance: none; -webkit-appearance: none; width: 100%; height: 1.5rem; background: transparent; cursor: pointer; }
.range::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to var(--range-dir, right), var(--brand) var(--fill, 50%), var(--border) var(--fill, 50%)); }
[dir="rtl"] .range { --range-dir: left; }
.range::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 1.5rem; height: 1.5rem; margin-block-start: -9px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); box-shadow: var(--shadow-sm); }
.range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--border); }
.range::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--brand); }
.range::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }

/* Segmented control */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-sunken); border-radius: var(--radius-md); border: 1px solid var(--border); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: inline-flex; align-items: center; gap: var(--space-2); min-height: calc(var(--control-h) - 8px); padding-inline: var(--space-4); border-radius: var(--radius-sm); font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--text-2); transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); font-weight: var(--fw-semibold); }
.segmented input:focus-visible + span { box-shadow: var(--focus-ring); }
.segmented--block { display: flex; width: 100%; } .segmented--block label { flex: 1; } .segmented--block span { justify-content: center; width: 100%; }

/* OTP: six cells, auto-advance handled by ui.js */
.otp { display: flex; gap: var(--space-2); justify-content: center; direction: ltr; }
.otp__cell { width: 3rem; height: 3.5rem; text-align: center; font-size: var(--fs-2xl); font-weight: var(--fw-semibold); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); font-variant-numeric: tabular-nums; }
.otp__cell:focus { border-color: var(--border-focus); box-shadow: var(--focus-ring); }
.otp__cell.filled { border-color: var(--brand); }
[data-surface="worker"] .otp__cell { width: 3.25rem; height: 4rem; }

/* Dropzone and capture tile (documents, ID, selfie) */
.dropzone {
  display: grid; place-items: center; gap: var(--space-2); text-align: center; padding: var(--space-6);
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-md); background: var(--surface-sunken); color: var(--text-2); cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand); background: var(--brand-subtle); color: var(--brand-subtle-fg); }
.dropzone strong { color: var(--text); font-weight: var(--fw-semibold); }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2); min-height: 2.25rem; padding-inline: var(--space-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill); background: var(--surface); color: var(--text);
  font-size: var(--fs-md); font-weight: var(--fw-medium); cursor: pointer; white-space: nowrap; position: relative;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.chip:hover { background: var(--hover-wash); }
a.chip { text-decoration: none; color: var(--text); }
.chip[aria-pressed="true"], .chip.is-selected { background: var(--brand-subtle-2); border-color: var(--brand); color: var(--brand-subtle-fg); }
.chip .icon { --icon-size: 16px; }
.chip--static { cursor: default; border-color: var(--border); background: var(--surface-sunken); }
.chip--static:hover { background: var(--surface-sunken); }
.chip--sm { min-height: 1.75rem; font-size: var(--fs-xs); padding-inline: var(--space-2); }
.chip__x { margin-inline-end: -4px; display: inline-grid; place-items: center; width: 1.25rem; height: 1.25rem; border-radius: 50%; color: var(--text-2); }
.chip__x:hover { background: var(--pressed-wash); }
.chips-scroll { display: flex; gap: var(--space-2); overflow-x: auto; padding-block: var(--space-1); scrollbar-width: none; margin-inline: calc(var(--space-4) * -1); padding-inline: var(--space-4); }
.chips-scroll::-webkit-scrollbar { display: none; }

/* ---------- Badge and status pill ---------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1); min-height: 1.5rem; padding-inline: var(--space-2);
  border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 1; white-space: nowrap;
  background: var(--surface-sunken); color: var(--text-2); border: 1px solid transparent;
}
.badge .icon { --icon-size: 14px; }
.badge--success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-border); }
.badge--warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-border); }
.badge--danger  { background: var(--danger-bg);  color: var(--danger-fg);  border-color: var(--danger-border); }
.badge--info    { background: var(--info-bg);    color: var(--info-fg);    border-color: var(--info-border); }
.badge--brand   { background: var(--brand-subtle); color: var(--brand-subtle-fg); border-color: var(--brand-border); }
.badge--accent  { background: var(--accent-subtle); color: var(--accent-subtle-fg); border-color: var(--accent-border); }
.badge--solid-brand { background: var(--brand); color: var(--on-brand); }
.badge--lg { min-height: 1.875rem; padding-inline: var(--space-3); font-size: var(--fs-sm); }
.badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.count { display: inline-grid; place-items: center; min-width: 1.25rem; height: 1.25rem; padding-inline: 5px; border-radius: var(--radius-pill); background: var(--danger-solid); color: var(--on-danger-solid); font-size: 11px; font-weight: var(--fw-bold); line-height: 1; font-variant-numeric: tabular-nums; }
.count--neutral { background: var(--surface-sunken); color: var(--text-2); }
.count--brand { background: var(--brand); color: var(--on-brand); }

/* ---------- Avatar. Initials on a deterministic hue; photos are placeholders until real assets exist. ---------- */
.avatar {
  --av: 40px; --h: 320;
  position: relative; display: inline-grid; place-items: center; flex: none; width: var(--av); height: var(--av); border-radius: 50%;
  background: light-dark(oklch(0.88 0.05 var(--h)), oklch(0.38 0.07 var(--h))); color: light-dark(oklch(0.32 0.08 var(--h)), oklch(0.92 0.04 var(--h))); font-size: calc(var(--av) * 0.38); font-weight: var(--fw-semibold); line-height: 1;
  overflow: hidden; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--xs { --av: 24px; } .avatar--sm { --av: 32px; } .avatar--lg { --av: 56px; } .avatar--xl { --av: 72px; } .avatar--2xl { --av: 96px; }
.avatar--square { border-radius: var(--radius-md); }
.avatar__status { position: absolute; inset-block-end: 0; inset-inline-end: 0; width: 28%; height: 28%; min-width: 8px; min-height: 8px; border-radius: 50%; background: var(--success-solid); box-shadow: 0 0 0 2px var(--surface); }
.avatar__tier { position: absolute; inset-block-end: -2px; inset-inline-end: -2px; width: 38%; height: 38%; border-radius: 50%; display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface); background: var(--tier-2-bg); color: var(--tier-2-fg); }
.avatar__tier .icon { --icon-size: 62%; stroke-width: 2.4; }
.avatar__tier.t3 { background: var(--tier-3-bg); color: var(--tier-3-fg); }
.avatar-wrap { position: relative; display: inline-block; line-height: 0; }
.avatar-wrap .avatar { overflow: visible; }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar + .avatar { margin-inline-start: -10px; }
/* Photo placeholder (no illustrations: real photography only, per brand rules) */
.ph { background: var(--surface-sunken); color: var(--text-3); display: grid; place-items: center; font-size: var(--fs-xs); border-radius: inherit; }
.photo { background: linear-gradient(160deg, var(--brand-subtle-2), var(--accent-subtle)); display: grid; place-items: center; color: var(--text-3); }

/* ---------- Card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); min-width: 0; }
.card--lg { padding: var(--space-6); }
.card--flat { border-color: transparent; background: var(--surface-sunken); }
.card--flush { padding: 0; overflow: hidden; }
.card--interactive { cursor: pointer; transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); text-decoration: none; color: inherit; display: block; }
.card--interactive:hover { border-color: var(--border-strong); background: color-mix(in oklab, var(--surface), var(--text) 2.5%); }
.card--selected { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-block-end: var(--space-3); }
.card__title { font-size: var(--fs-base); font-weight: var(--fw-semibold); }
.card__foot { display: flex; align-items: center; gap: var(--space-2); margin-block-start: var(--space-4); padding-block-start: var(--space-3); border-block-start: 1px solid var(--border); }

/* ---------- List ---------- */
.list { display: flex; flex-direction: column; }
.list__item { display: flex; align-items: center; gap: var(--space-3); min-height: var(--row-h); padding-block: var(--space-2); padding-inline: var(--space-4); color: inherit; text-decoration: none; position: relative; }
.list__item + .list__item { border-block-start: 1px solid var(--border); }
a.list__item, button.list__item, .list__item--action { cursor: pointer; width: 100%; text-align: start; transition: background-color var(--dur-fast) var(--ease-out); }
a.list__item:hover, button.list__item:hover, .list__item--action:hover { background: var(--hover-wash); }
.list__item[aria-current="page"], .list__item[aria-selected="true"], .list__item.is-selected { background: var(--brand-subtle-2); color: var(--brand-subtle-fg); font-weight: var(--fw-semibold); }
.list__lead { flex: none; display: grid; place-items: center; width: 2.5rem; height: 2.5rem; border-radius: var(--radius-sm); background: var(--brand-subtle); color: var(--brand-subtle-fg); }
.list__body { flex: 1 1 0; min-width: 0; }
.list__title, .list__sub { display: block; }
.list__title { font-size: var(--fs-base); font-weight: var(--fw-medium); line-height: 1.4; }
.list__sub { font-size: var(--fs-sm); color: var(--text-2); line-height: 1.5; }
.list__trail { flex: none; display: flex; align-items: center; gap: var(--space-2); color: var(--text-3); }
.list--inset { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }

/* Key-value pairs */
.kv { display: grid; grid-template-columns: minmax(6rem, 38%) 1fr; gap: var(--space-2) var(--space-4); font-size: var(--fs-md); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: var(--fw-medium); min-width: 0; }

/* ---------- Table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: auto; }
.table { width: 100%; font-size: var(--fs-md); }
.table th, .table td { padding: var(--pad-y) var(--pad-x); text-align: start; vertical-align: middle; border-block-end: 1px solid var(--border); white-space: nowrap; }
.table th { position: sticky; inset-block-start: 0; z-index: var(--z-raised); background: var(--surface-sunken); color: var(--text-2); font-size: var(--fs-xs); font-weight: var(--fw-semibold); height: 2.5rem; }
.table tbody tr { height: var(--row-h); transition: background-color var(--dur-fast) var(--ease-out); }
.table tbody tr:hover { background: var(--hover-wash); }
.table tbody tr:last-child td { border-block-end: 0; }
.table tbody tr[aria-selected="true"], .table tbody tr.is-selected { background: var(--selected-bg); }
.table .num, .table .is-num { text-align: end; font-variant-numeric: tabular-nums lining-nums; }
.table .col-check { width: 2.75rem; padding-inline-end: 0; }
.table .col-actions { width: 1%; text-align: end; }
.table th[aria-sort] { cursor: pointer; }
.table th[aria-sort] .icon { --icon-size: 14px; vertical-align: -2px; margin-inline-start: 4px; color: var(--text-3); }
.table th[aria-sort="ascending"] .icon, .table th[aria-sort="descending"] .icon { color: var(--brand); }
.table .cell-user { display: flex; align-items: center; gap: var(--space-3); }
.table .cell-sub { display: block; font-size: var(--fs-xs); color: var(--text-3); }
.table--wrap td, .table--wrap th { white-space: normal; }
.table-toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-block-end: var(--space-3); }
.bulkbar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-4); background: var(--surface-inverse); color: var(--text-inverse); border-radius: var(--radius-md); }
.bulkbar .btn { --btn-fg: var(--text-inverse); }
.bulkbar .btn:hover { background: oklch(1 0 0 / 0.14); }
.pagination { display: flex; align-items: center; gap: var(--space-1); }
.pagination .page { display: inline-grid; place-items: center; min-width: 2.25rem; height: 2.25rem; padding-inline: var(--space-2); border-radius: var(--radius-sm); font-size: var(--fs-md); font-variant-numeric: tabular-nums; color: var(--text-2); cursor: pointer; text-decoration: none; }
.pagination .page:hover { background: var(--hover-wash); }
.pagination .page[aria-current="page"] { background: var(--brand); color: var(--on-brand); font-weight: var(--fw-semibold); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--space-1); box-shadow: inset 0 -1px 0 var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--hit-min); padding-inline: var(--space-4);
  font-size: var(--fs-md); font-weight: var(--fw-medium); color: var(--text-2); white-space: nowrap; cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--brand); font-weight: var(--fw-semibold); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: var(--space-2); inset-block-end: 0; height: 2px; background: var(--brand); border-radius: 2px 2px 0 0; }
.tab:focus-visible { box-shadow: inset 0 0 0 2px var(--border-focus); border-radius: var(--radius-sm); }
.tabpanel { padding-block-start: var(--space-4); }
.tabpanel[hidden] { display: none; }

/* ---------- Breadcrumb ---------- */
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-1); font-size: var(--fs-sm); color: var(--text-3); }
.breadcrumb a { color: var(--text-2); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); text-decoration: underline; }
.breadcrumb .icon { --icon-size: 14px; }
.breadcrumb [aria-current="page"] { color: var(--text); font-weight: var(--fw-medium); }

/* ---------- Stepper (placement lifecycle, onboarding, forms) ---------- */
.stepper { display: flex; gap: 0; counter-reset: step; }
.step { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center; position: relative; min-width: 0; counter-increment: step; }
.step::before { /* connector, runs from the previous step to this one in the reading direction */
  content: ""; position: absolute; inset-block-start: 0.9rem; inset-inline-start: -50%; width: 100%; height: 2px; background: var(--border); z-index: 0;
}
.step:first-child::before { display: none; }
.step.is-done::before, .step.is-current::before { background: var(--brand); }
.step__dot { position: relative; z-index: 1; display: grid; place-items: center; width: 1.85rem; height: 1.85rem; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); color: var(--text-3); font-size: var(--fs-xs); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.step__dot::before { content: counter(step); }
.step.is-done .step__dot { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.step.is-done .step__dot::before { content: ""; width: 10px; height: 6px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-1px) rotate(-45deg); }
.step.is-current .step__dot { border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 4px var(--brand-subtle-2); }
.step.is-blocked .step__dot { border-color: var(--danger-solid); color: var(--danger-fg); }
.step__label { font-size: var(--fs-xs); color: var(--text-2); line-height: 1.4; max-width: 7rem; }
.step.is-current .step__label { color: var(--text); font-weight: var(--fw-semibold); }
.stepper--vertical { flex-direction: column; gap: 0; }
.stepper--vertical .step { flex-direction: row; align-items: flex-start; text-align: start; padding-block-end: var(--space-5); gap: var(--space-3); }
.stepper--vertical .step::before { inset-block-start: 0; inset-inline-start: 0.8rem; width: 2px; height: 100%; transform: translateY(-50%); }
.stepper--vertical .step:first-child::before { display: none; }
.stepper--vertical .step__label { max-width: none; font-size: var(--fs-md); padding-block-start: 0.2rem; }

/* ---------- Progress ---------- */
.progress { height: 8px; background: var(--border); border-radius: var(--radius-pill); overflow: hidden; }
.progress > span { display: block; height: 100%; width: var(--value, 0%); background: var(--brand); border-radius: inherit; transition: width var(--dur-slow) var(--ease-out); }
.progress--success > span { background: var(--success-solid); }
.progress--accent > span { background: var(--accent); }
.progress--sm { height: 4px; }
.segments { display: flex; gap: 3px; }
.segments > i { flex: 1; height: 6px; border-radius: 3px; background: var(--border); }
.segments > i.on { background: var(--brand); }
.segments > i.on.gold { background: var(--accent); }

/* ---------- Alerts and banners ---------- */
.alert {
  --a-bg: var(--info-bg); --a-border: var(--info-border); --a-fg: var(--info-fg);
  display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4);
  background: var(--a-bg); border: 1px solid var(--a-border); border-radius: var(--radius-md); color: var(--text); font-size: var(--fs-md); line-height: 1.55;
}
.alert > .icon { color: var(--a-fg); margin-block-start: 0.1rem; }
.alert__title { font-weight: var(--fw-semibold); color: var(--a-fg); }
.alert__body { flex: 1 1 0; min-width: 0; }
.alert__actions { display: flex; gap: var(--space-2); margin-block-start: var(--space-2); flex-wrap: wrap; }

.alert--info { --a-bg: var(--info-bg); --a-border: var(--info-border); --a-fg: var(--info-fg); }
.alert--success { --a-bg: var(--success-bg); --a-border: var(--success-border); --a-fg: var(--success-fg); }
.alert--warning { --a-bg: var(--warning-bg); --a-border: var(--warning-border); --a-fg: var(--warning-fg); }
.alert--danger  { --a-bg: var(--danger-bg);  --a-border: var(--danger-border);  --a-fg: var(--danger-fg); }
.alert--brand   { --a-bg: var(--brand-subtle); --a-border: var(--brand-border); --a-fg: var(--brand-subtle-fg); }
.alert--accent  { --a-bg: var(--accent-subtle); --a-border: var(--accent-border); --a-fg: var(--accent-subtle-fg); }

/* ---------- Toast ---------- */
.toast-region { position: fixed; inset-block-end: var(--space-4); inset-inline: var(--space-4); z-index: var(--z-toast); display: flex; flex-direction: column; align-items: center; gap: var(--space-2); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--space-3); min-width: min(100%, 20rem); max-width: 28rem;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--surface-inverse); color: var(--text-inverse); box-shadow: var(--shadow-lg);
  font-size: var(--fs-md); animation: toast-in var(--dur-base) var(--ease-out);
}
.toast .icon { color: var(--accent); }
.toast .btn { --btn-fg: var(--accent); min-height: 2rem; padding-inline: var(--space-2); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity var(--dur-fast), transform var(--dur-fast); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* ---------- Dialog, sheet, drawer (native <dialog>) ---------- */
dialog { color: inherit; padding: 0; border: 0; max-width: none; max-height: none; }
dialog::backdrop { background: var(--scrim); animation: fade-in var(--dur-base) var(--ease-out); }
@keyframes fade-in { from { opacity: 0; } }
.dialog {
  width: min(32rem, calc(100vw - 2rem)); margin: auto; background: var(--surface-2); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: pop-in var(--dur-base) var(--ease-out);
}
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog__head { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-6) var(--space-2); }
.dialog__title { font-size: var(--fs-xl); font-weight: var(--fw-semibold); flex: 1; line-height: 1.4; }
.dialog__body { padding: var(--space-2) var(--space-6) var(--space-5); color: var(--text-2); font-size: var(--fs-base); line-height: var(--lh-base); }
.dialog__foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-6); border-block-start: 1px solid var(--border); flex-wrap: wrap; }
/* Destructive confirmation puts the safe action first in reading order and the destructive action last. */
.sheet { /* bottom sheet: mobile only. Handle + content. */
  width: 100%; max-width: 32rem; margin: auto auto 0; background: var(--surface-2); border-start-start-radius: var(--radius-lg); border-start-end-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: sheet-in var(--dur-slow) var(--ease-out-expo);
}
@keyframes sheet-in { from { transform: translateY(100%); } }
.sheet::before { content: ""; display: block; width: 2.5rem; height: 4px; border-radius: 2px; background: var(--border-strong); margin: var(--space-2) auto var(--space-1); }
.sheet__body { padding: var(--space-2) var(--space-4) var(--space-4); }
.drawer { margin: 0; margin-inline-start: auto; width: min(26rem, 100vw); height: 100dvh; background: var(--surface-2); box-shadow: var(--shadow-lg); animation: drawer-in var(--dur-slow) var(--ease-out-expo); flex-direction: column; }
[dir="rtl"] .drawer { margin-inline-start: 0; margin-inline-end: auto; }
.drawer[open] { display: flex; }
.drawer:not([open]) { display: none; }
@keyframes drawer-in { from { transform: translateX(-100%); } }
[dir="ltr"] .drawer { animation-name: drawer-in-ltr; }
@keyframes drawer-in-ltr { from { transform: translateX(100%); } }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-block-end: 1px solid var(--border); }
.drawer__body { flex: 1; overflow: auto; padding: var(--space-5); }
.drawer__foot { padding: var(--space-4) var(--space-5); border-block-start: 1px solid var(--border); display: flex; gap: var(--space-2); }

/* ---------- Menu and popover ---------- */
.popover-anchor { position: relative; display: inline-block; }
.menu {
  position: absolute; inset-block-start: calc(100% + 6px); inset-inline-start: 0; z-index: var(--z-dropdown); min-width: 13rem; padding: var(--space-1);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  animation: pop-in var(--dur-fast) var(--ease-out);
}
.menu--end { inset-inline-start: auto; inset-inline-end: 0; }
.menu[hidden] { display: none; }
.menu__item { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 2.5rem; padding-inline: var(--space-3); border-radius: var(--radius-sm); font-size: var(--fs-md); color: var(--text); text-decoration: none; cursor: pointer; text-align: start; }
.menu__item:hover, .menu__item:focus-visible { background: var(--hover-wash); }
.menu__item .icon { color: var(--text-2); --icon-size: 18px; }
.menu__item--danger, .menu__item--danger .icon { color: var(--danger-fg); }
.menu__item .kbd { margin-inline-start: auto; }
.menu__sep { height: 1px; background: var(--border); margin-block: var(--space-1); }
.menu__label { padding: var(--space-2) var(--space-3); font-size: var(--fs-xs); color: var(--text-3); font-weight: var(--fw-semibold); }
.kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 1.5rem; height: 1.5rem; padding-inline: 5px; border: 1px solid var(--border-strong); border-block-end-width: 2px; border-radius: 5px; font-family: var(--font-mono); font-size: 11px; color: var(--text-2); background: var(--surface); direction: ltr; }

/* Tooltip: short labels only (icon buttons, truncated text). CSS-driven via data-tip, also on focus. */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; z-index: var(--z-tooltip); inset-block-end: calc(100% + 6px); inset-inline-start: 50%; transform: translate(-50%, 2px);
  padding: 4px 8px; border-radius: var(--radius-xs); background: var(--surface-inverse); color: var(--text-inverse); font-size: var(--fs-xs); font-weight: var(--fw-medium); line-height: 1.4; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}
[dir="rtl"] [data-tip]::after { transform: translate(50%, 2px); inset-inline-start: auto; inset-inline-end: 50%; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }
[dir="rtl"] [data-tip]:hover::after, [dir="rtl"] [data-tip]:focus-visible::after { transform: translate(50%, 0); }
[data-tip][data-tip-pos="bottom"]::after { inset-block-end: auto; inset-block-start: calc(100% + 6px); }

/* ---------- Skeleton ---------- */
.skeleton { display: block; background: linear-gradient(90deg, var(--surface-sunken) 0%, color-mix(in oklab, var(--surface-sunken), var(--text) 7%) 50%, var(--surface-sunken) 100%); background-size: 200% 100%; border-radius: var(--radius-sm); animation: shimmer 1.4s linear infinite; min-height: 1em; }
.skeleton--line { height: 0.85rem; } .skeleton--title { height: 1.25rem; width: 55%; } .skeleton--circle { border-radius: 50%; } .skeleton--block { height: 6rem; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- Empty state: explains, then offers the next action ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-3); padding: var(--space-10) var(--space-6); color: var(--text-2); max-width: 26rem; margin-inline: auto; }
.empty__icon { display: grid; place-items: center; width: 3.5rem; height: 3.5rem; border-radius: var(--radius-md); background: var(--brand-subtle); color: var(--brand); }
.empty__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text); }
.empty__text { font-size: var(--fs-md); line-height: var(--lh-base); }

/* ---------- Accordion (native details) ---------- */
.accordion { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); overflow: hidden; }
.accordion details + details { border-block-start: 1px solid var(--border); }
.accordion summary { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: var(--row-h); padding: var(--space-3) var(--space-4); cursor: pointer; font-weight: var(--fw-medium); font-size: var(--fs-base); list-style: none; }
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after { content: ""; width: 10px; height: 10px; border-right: 2px solid var(--text-2); border-bottom: 2px solid var(--text-2); transform: rotate(45deg); transition: transform var(--dur-base) var(--ease-out); flex: none; margin-block-start: -4px; }
.accordion details[open] summary::after { transform: rotate(-135deg); margin-block-start: 4px; }
.accordion summary:hover { background: var(--hover-wash); }
.accordion .acc-body { padding: 0 var(--space-4) var(--space-4); color: var(--text-2); font-size: var(--fs-md); line-height: var(--lh-loose); }

/* ---------- Stars (structured rating; ui.js renders the glyphs) ---------- */
.stars { display: inline-flex; gap: 2px; color: var(--accent); vertical-align: middle; }
.stars .icon { --icon-size: 16px; fill: currentColor; stroke: none; }
.stars .icon.empty { fill: var(--border-strong); }
.stars .icon.half { fill: url(#half-star-fill); }
.rating-row { display: flex; align-items: center; gap: var(--space-3); font-size: var(--fs-sm); }
.rating-row .progress { flex: 1; height: 6px; }

/* ---------- Divider with label ---------- */
.divider-label { display: flex; align-items: center; gap: var(--space-3); color: var(--text-3); font-size: var(--fs-xs); }
.divider-label::before, .divider-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Spinner ---------- */
.spinner { width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 3px solid var(--border); border-block-start-color: var(--brand); animation: spin 800ms linear infinite; }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; border-color: var(--brand); border-block-start-color: var(--border); } }

/* Dense table variant (also used by the chart "show as table" fallback) */
.table--dense th, .table--dense td { padding: var(--space-2) var(--space-3); }
.table--dense tbody tr { height: 2.25rem; }
.table--dense th { height: 2.25rem; }
