/* ==========================================================================
   Components — one block per component in js/components/
   ========================================================================== */

/* ---- Icon ----------------------------------------------------------- */
.icon {
  width: var(--icon-size, 20px);
  height: var(--icon-size, 20px);
  stroke: currentColor;
  fill: none;
  stroke-width: var(--icon-stroke, 1.75);
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
  flex-shrink: 0;
}
.icon--flip { transform: scaleX(-1); }
[dir="ltr"] .icon--flip { transform: none; }

/* ---- Button --------------------------------------------------------- */
.btn {
  --btn-h: var(--control-h);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--btn-h);
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-input);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out), transform var(--dur-1) var(--ease-out);
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(1px); }
.btn .icon { --icon-size: 18px; }
.btn--sm { --btn-h: var(--control-h-sm); padding: 0 var(--space-3); font-size: 0.8125rem; border-radius: var(--radius-sm); gap: 6px; }
.btn--sm .icon { --icon-size: 16px; }
.btn--lg { --btn-h: var(--control-h-lg); padding: 0 var(--space-6); font-size: var(--fs-md); border-radius: var(--radius-md); }
.btn--lg .icon { --icon-size: 20px; }
.btn--block { display: flex; width: 100%; }
.btn--icon-only { width: var(--btn-h); padding: 0; }

.btn--primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-button); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--primary:active { background: var(--primary-active); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
.btn--secondary:hover { background: var(--surface-2); border-color: var(--text-subtle); }
.btn--ghost { background: transparent; color: var(--text); }
.btn--ghost:hover { background: var(--surface-3); }
.btn--soft { background: var(--primary-soft); color: var(--primary-text); }
.btn--soft:hover { background: var(--primary-soft-2); }
.btn--danger { background: var(--danger); color: #fff; box-shadow: var(--shadow-button); }
.btn--danger:hover { background: var(--danger-hover); }
.btn--danger-soft { background: var(--danger-soft); color: var(--danger-text); }
.btn--danger-soft:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.btn--success { background: var(--success); color: #fff; box-shadow: var(--shadow-button); }
.btn--success:hover { background: var(--success-hover); }
.btn--link { height: auto; padding: 0; border: 0; background: none; color: var(--primary-text); font-weight: var(--fw-semibold); }
.btn--link:hover { text-decoration: underline; }
.btn--on-dark { background: rgba(255, 255, 255, 0.1); color: #fff; border-color: rgba(255, 255, 255, 0.16); }
.btn--on-dark:hover { background: rgba(255, 255, 255, 0.16); }

.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; box-shadow: none; cursor: not-allowed; }
.btn.is-loading { cursor: progress; opacity: 0.9; }
.btn__spinner { --spinner-size: 16px; }

.shell--mobile .btn:not(.btn--sm):not(.btn--link) { --btn-h: var(--touch); font-size: var(--fs-md); border-radius: var(--radius-md); }

.btn-group { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; }

/* ---- IconButton ----------------------------------------------------- */
.icon-btn {
  --ib-size: 40px;
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--ib-size);
  height: var(--ib-size);
  border-radius: var(--radius-input);
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  transition: background var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out);
}
.icon-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { background: var(--surface-3); color: var(--text); }
.icon-btn:disabled { opacity: 0.45; }
.icon-btn--sm { --ib-size: 32px; border-radius: var(--radius-sm); }
.icon-btn--sm .icon { --icon-size: 18px; }
.icon-btn--lg { --ib-size: var(--touch); border-radius: var(--radius-md); }
.icon-btn--lg .icon { --icon-size: 22px; }
.icon-btn--solid { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-xs); color: var(--text); }
.icon-btn--solid:hover:not(:disabled) { background: var(--surface-2); }
.icon-btn--primary { background: var(--primary); color: var(--on-primary); }
.icon-btn--primary:hover:not(:disabled) { background: var(--primary-hover); color: var(--on-primary); }
.icon-btn--danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger-text); }
.icon-btn--on-dark { color: rgba(255, 255, 255, 0.85); }
.icon-btn--on-dark:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); color: #fff; }
.icon-btn__badge {
  position: absolute;
  top: 3px;
  inset-inline-end: 3px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: var(--fw-bold);
  line-height: 1;
  box-shadow: 0 0 0 2px var(--surface);
  animation: badge-pop var(--dur-4) var(--ease-spring);
  font-variant-numeric: tabular-nums;
}
.icon-btn__badge--dot { min-width: 9px; width: 9px; height: 9px; padding: 0; top: 8px; inset-inline-end: 8px; }
@keyframes badge-pop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Field ---------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text);
}
.field__required { color: var(--danger-text); font-weight: var(--fw-bold); }
.field__optional { color: var(--text-subtle); font-weight: var(--fw-regular); font-size: var(--fs-xs); }
.field__hint { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.45; }
.field__error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--danger-text);
  line-height: 1.45;
  animation: fade-up var(--dur-2) var(--ease-out);
}
.field__error .icon { --icon-size: 14px; margin-top: 1px; }
.field__warning { display: flex; gap: 6px; font-size: var(--fs-xs); color: var(--warning-text); font-weight: var(--fw-medium); }
.field__warning .icon { --icon-size: 14px; margin-top: 1px; }
.field__footer { display: flex; justify-content: space-between; gap: var(--space-2); }
.field__counter { font-size: var(--fs-xs); color: var(--text-subtle); font-variant-numeric: tabular-nums; margin-inline-start: auto; }

/* ---- Input / Textarea / Select ------------------------------------- */
.input {
  width: 100%;
  min-width: 0;
  height: var(--control-h);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-input);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.4;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out);
}
.input::placeholder { color: var(--text-placeholder); opacity: 1; }
.input:hover:not(:disabled):not(:focus) { border-color: var(--text-subtle); }
.input:focus, .input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.input.is-invalid, .input[aria-invalid="true"] { border-color: var(--danger); }
.input.is-invalid:focus, .input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-ring); }
.input:disabled, .input[readonly] { background: var(--surface-3); color: var(--text-muted); box-shadow: none; }
.input:disabled { cursor: not-allowed; }
.input--sm { height: var(--control-h-sm); font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.input--lg { height: var(--control-h-lg); font-size: var(--fs-lg); }
.shell--mobile .input:not(.input--sm) { height: var(--touch); }
textarea.input { height: auto; min-height: 96px; padding: 10px var(--space-3); line-height: var(--lh-normal); resize: vertical; }
textarea.input.is-autosize { resize: none; overflow: hidden; }
/* No native spinners: tiny targets on touch and they collide with unit suffixes (arrow keys still step). */
input[type="number"].input { -moz-appearance: textfield; appearance: textfield; }
input[type="number"].input::-webkit-inner-spin-button,
input[type="number"].input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.input-wrap { position: relative; display: flex; align-items: center; min-width: 0; }
.input-wrap > .input { flex: 1; }
.input-wrap__prefix, .input-wrap__suffix {
  position: absolute;
  inset-block: 0;
  display: flex;
  align-items: center;
  color: var(--text-subtle);
  pointer-events: none;
}
.input-wrap__prefix { inset-inline-start: var(--space-3); }
.input-wrap__suffix { inset-inline-end: 4px; pointer-events: auto; }
.input-wrap__suffix--text { inset-inline-end: var(--space-3); pointer-events: none; font-size: var(--fs-sm); }
.input-wrap.has-prefix > .input { padding-inline-start: 40px; }
.input-wrap.has-suffix > .input { padding-inline-end: 44px; }
/* Unit text (e.g. 'מסירות', 'ק״מ'): room sized by its length, set as --suffix-chars by Input.js. */
.input-wrap.has-suffix-text > .input { padding-inline-end: calc(var(--space-3) + var(--suffix-chars, 3) * 0.6em + 10px); }
.input-wrap__prefix .icon { --icon-size: 18px; }
/* LTR inputs (tel / email / url / dir="ltr" / .ltr, and number when marked LTR) inside the RTL page:
   the prefix/suffix are placed by the wrapper's (RTL) inline axis — prefix on the right, suffix on
   the left — but the input's own logical padding follows ITS direction (LTR, or RTL while the
   placeholder shows), which put the digits under the icon. Pin the room to physical sides that
   match the wrapper instead, so it is correct in both states. (The app is always dir="rtl".) */
.input-wrap > .input:is([type="tel"], [type="email"], [type="url"], [dir="ltr"], .ltr) { padding-left: var(--space-3); padding-right: var(--space-3); }
.input-wrap.has-prefix > .input:is([type="tel"], [type="email"], [type="url"], [dir="ltr"], .ltr) { padding-right: 40px; }
.input-wrap.has-suffix > .input:is([type="tel"], [type="email"], [type="url"], [dir="ltr"], .ltr) { padding-left: 44px; }
.input-wrap.has-suffix-text > .input:is([type="tel"], [type="email"], [type="url"], [dir="ltr"], .ltr) { padding-left: calc(var(--space-3) + var(--suffix-chars, 3) * 0.6em + 10px); }

.select-wrap { position: relative; }
select.input {
  -webkit-appearance: none;
  appearance: none;
  padding-inline-end: 38px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238390A6' 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-position: left 12px center;
  background-size: 16px;
}
select.input option { color: var(--text); background: var(--surface); }

/* ---- Checkbox / Radio ---------------------------------------------- */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  font-size: var(--fs-body);
  line-height: 1.45;
  min-height: 24px;
}
.check.is-disabled { cursor: not-allowed; opacity: 0.55; }
.check__input {
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  border: 1.5px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface) no-repeat center / 14px;
  cursor: inherit;
  transition: background-color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2);
}
.check__input:hover { border-color: var(--primary); }
.check__input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); border-color: var(--primary); }
.check__input:checked {
  border-color: var(--primary);
  background-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}
.check__input:indeterminate {
  border-color: var(--primary);
  background-color: var(--primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round'%3E%3Cpath d='M6 12h12'/%3E%3C/svg%3E");
}
.check__input[type="radio"] { border-radius: 50%; }
.check__input[type="radio"]:checked {
  background-image: none;
  background-color: var(--surface);
  border-width: 6px;
}
.check__input[aria-invalid="true"] { border-color: var(--danger); }
.check__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.check__label { color: var(--text); font-weight: var(--fw-medium); }
.check__hint { color: var(--text-muted); font-size: var(--fs-xs); }

.radio-group { display: flex; flex-direction: column; gap: var(--space-3); }
.radio-group__legend { margin-bottom: var(--space-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.radio-group__options { display: flex; flex-direction: column; gap: var(--space-3); }
.radio-group--inline .radio-group__options { flex-direction: row; flex-wrap: wrap; gap: var(--space-3) var(--space-6); }
.radio-group--cards .radio-group__options { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: var(--space-3); }
.radio-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out), box-shadow var(--dur-2);
}
.radio-card:hover { border-color: var(--border-strong); }
.radio-card.is-checked { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary) inset; }
.radio-card.is-disabled { opacity: 0.55; cursor: not-allowed; }
.radio-card__icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--surface-3); color: var(--text-muted); flex-shrink: 0; }
.radio-card.is-checked .radio-card__icon { background: var(--primary); color: var(--on-primary); }
.radio-card:has(:focus-visible) { outline: var(--focus-width) solid var(--focus-color); outline-offset: 2px; }
.shell--mobile .radio-card { padding: var(--space-4); min-height: var(--touch); }

/* ---- Switch --------------------------------------------------------- */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); min-width: 0; }
.switch-row__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-row__label { font-weight: var(--fw-medium); color: var(--text); cursor: pointer; }
.switch-row__hint { font-size: var(--fs-xs); color: var(--text-muted); }
.switch {
  --sw-w: 44px;
  --sw-h: 26px;
  --sw-pad: 3px;
  position: relative;
  flex-shrink: 0;
  width: var(--sw-w);
  height: var(--sw-h);
  border-radius: 999px;
  background: var(--border-strong);
  transition: background var(--dur-3) var(--ease-out), box-shadow var(--dur-2);
}
.switch::after {
  content: "";
  position: absolute;
  top: var(--sw-pad);
  inset-inline-start: var(--sw-pad);
  width: calc(var(--sw-h) - 2 * var(--sw-pad));
  height: calc(var(--sw-h) - 2 * var(--sw-pad));
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.25), 0 1px 1px rgba(16, 24, 40, 0.08);
  transition: transform var(--dur-3) var(--ease-spring);
}
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { transform: translateX(calc(-1 * (var(--sw-w) - var(--sw-h)))); }
[dir="ltr"] .switch[aria-checked="true"]::after { transform: translateX(calc(var(--sw-w) - var(--sw-h))); }
.switch:disabled { opacity: 0.5; }
.switch:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); }
.switch--success[aria-checked="true"] { background: var(--success); }
.switch--lg { --sw-w: 56px; --sw-h: 32px; }

/* ---- Autocomplete --------------------------------------------------- */
.autocomplete { position: relative; }
.autocomplete__list {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline: 0;
  z-index: var(--z-dropdown);
  max-height: 300px;
  overflow-y: auto;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--dur-2) var(--ease-out);
}
.autocomplete__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 9px var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-body);
}
.autocomplete__option + .autocomplete__option { margin-top: 1px; }
.autocomplete__option.is-active { background: var(--primary-soft); color: var(--text); }
.autocomplete__option[aria-selected="true"] { font-weight: var(--fw-semibold); }
.autocomplete__option mark { background: transparent; color: var(--primary-text); font-weight: var(--fw-bold); padding: 0; }
.autocomplete__meta { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.autocomplete__status { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3); color: var(--text-muted); font-size: var(--fs-sm); }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---- ChipGroup (multi-select toggles) ------------------------------ */
.chip-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transition: background var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out), color var(--dur-2);
}
.chip-toggle:hover { border-color: var(--primary); }
.chip-toggle[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-text); font-weight: var(--fw-semibold); }
.chip-toggle .icon { --icon-size: 16px; }
.shell--mobile .chip-toggle { min-height: 42px; padding: 0 16px; }

/* ---- StatusChip ----------------------------------------------------- */
.chip {
  --chip-solid: var(--stage-cancelled);
  --chip-soft: var(--stage-cancelled-soft);
  --chip-text: var(--stage-cancelled-text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--chip-soft);
  color: var(--chip-text);
  font-size: 0.8125rem;
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}
.chip .icon { --icon-size: 14px; --icon-stroke: 2.1; color: var(--chip-solid); }
.chip__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chip-solid);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--chip-solid) 22%, transparent);
  flex-shrink: 0;
}
.chip--sm { height: 22px; padding: 0 8px; font-size: var(--fs-xs); gap: 5px; }
.chip--sm .icon { --icon-size: 12px; }
.chip--lg { height: 34px; padding: 0 14px; font-size: var(--fs-sm); gap: 8px; }
.chip--lg .icon { --icon-size: 16px; }
.chip--outline { background: transparent; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--chip-solid) 45%, transparent); }
:root[data-contrast="high"] .chip { box-shadow: inset 0 0 0 1px currentColor; }

/* ---- Badge ---------------------------------------------------------- */
.badge {
  --b-bg: var(--surface-3);
  --b-fg: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-xs);
  background: var(--b-bg);
  color: var(--b-fg);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
.badge .icon { --icon-size: 13px; --icon-stroke: 2; }
.badge--pill { border-radius: 999px; }
.badge--primary { --b-bg: var(--primary-soft); --b-fg: var(--primary-text); }
.badge--success { --b-bg: var(--success-soft); --b-fg: var(--success-text); }
.badge--warning { --b-bg: var(--warning-soft); --b-fg: var(--warning-text); }
.badge--danger { --b-bg: var(--danger-soft); --b-fg: var(--danger-text); }
.badge--info { --b-bg: var(--info-soft); --b-fg: var(--info-text); }
.badge--solid.badge--primary { --b-bg: var(--primary); --b-fg: #fff; }
.badge--solid.badge--success { --b-bg: var(--success); --b-fg: #fff; }
.badge--solid.badge--warning { --b-bg: var(--warning); --b-fg: #fff; }
.badge--solid.badge--danger { --b-bg: var(--danger); --b-fg: #fff; }
.badge--solid.badge--info { --b-bg: var(--info); --b-fg: #fff; }
.badge--solid.badge--neutral { --b-bg: var(--text-muted); --b-fg: var(--surface); }
.badge--outline { background: transparent; box-shadow: inset 0 0 0 1px currentColor; }
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--tier { --b-bg: var(--tier-soft); --b-fg: var(--tier); border-radius: 999px; }
.badge--tier .icon { color: var(--tier); }

/* ---- Card ----------------------------------------------------------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .card, [data-theme="dark"].card { border-color: var(--border); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .card { border-color: var(--border); } }
.card__header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) 0;
}
.card__header-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary-text);
  flex-shrink: 0;
}
.card__heading { flex: 1; min-width: 0; }
.card__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: var(--lh-snug); margin: 0; }
.card__subtitle { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-muted); }
.card__actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; margin-top: -4px; }
.card__body { padding: var(--space-4) var(--space-5) var(--space-5); flex: 1; min-width: 0; }
.card__header + .card__body { padding-top: var(--space-4); }
.card > .card__body:first-child { padding-top: var(--space-5); }
.card__footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-2);
  border-end-start-radius: inherit;
  border-end-end-radius: inherit;
}
.card--flush > .card__body { padding: 0; }
.card--flush > .card__header { padding-bottom: var(--space-4); border-bottom: 1px solid var(--border-subtle); }
.card--compact > .card__body { padding: var(--space-4); }
.card--compact > .card__header { padding: var(--space-4) var(--space-4) 0; }
.card--muted { background: var(--surface-2); box-shadow: none; }
.card--interactive { cursor: pointer; transition: box-shadow var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-out), border-color var(--dur-3); text-decoration: none; color: inherit; }
.card--interactive:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); border-color: var(--border); text-decoration: none; }
.card--interactive:active { transform: translateY(0); }
.card--accent::before {
  content: "";
  position: absolute;
  inset-block: 14px;
  inset-inline-start: -1px;
  width: 3px;
  border-start-end-radius: 3px;
  border-end-end-radius: 3px;
  background: var(--card-accent, var(--primary));
}
.card--ink { background: linear-gradient(160deg, var(--ink-3), var(--ink)); color: var(--ink-text); border-color: transparent; }
.card--ink .card__subtitle { color: var(--ink-muted); }
.card--ink .card__title { color: #fff; }

/* ---- KpiCard -------------------------------------------------------- */
.kpi {
  --kpi-tone: var(--primary);
  --kpi-soft: var(--primary-soft);
  --kpi-text: var(--primary-text);
  position: relative;
  overflow: hidden;
  padding: var(--space-5);
  gap: var(--space-2);
}
.kpi__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.kpi__label { font-size: var(--fs-sm); color: var(--text-muted); font-weight: var(--fw-medium); }
.kpi__icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--kpi-soft);
  color: var(--kpi-text);
}
.kpi__value {
  font-size: 1.875rem;
  font-weight: var(--fw-bold);
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.kpi__value small { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-muted); margin-inline-start: 4px; letter-spacing: 0; }
.kpi__num { display: inline-block; unicode-bidi: isolate; }
.kpi__num small { margin-inline-start: 1px; }
.kpi__bottom { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-3); min-height: 32px; }
.kpi__meta { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; font-size: var(--fs-xs); color: var(--text-muted); }
.kpi__delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  background: var(--surface-3);
  color: var(--text-muted);
}
.kpi__delta .icon { --icon-size: 13px; --icon-stroke: 2.2; }
.kpi__delta.is-good { background: var(--success-soft); color: var(--success-text); }
.kpi__delta.is-bad { background: var(--danger-soft); color: var(--danger-text); }
.kpi__spark { width: 104px; height: 34px; color: var(--kpi-tone); flex-shrink: 0; }
.kpi--success { --kpi-tone: var(--success); --kpi-soft: var(--success-soft); --kpi-text: var(--success-text); }
.kpi--warning { --kpi-tone: var(--warning); --kpi-soft: var(--warning-soft); --kpi-text: var(--warning-text); }
.kpi--danger { --kpi-tone: var(--danger); --kpi-soft: var(--danger-soft); --kpi-text: var(--danger-text); }
.kpi--info { --kpi-tone: var(--info); --kpi-soft: var(--info-soft); --kpi-text: var(--info-text); }
.kpi--violet { --kpi-tone: var(--stage-in_progress); --kpi-soft: var(--stage-in_progress-soft); --kpi-text: var(--stage-in_progress-text); }
.kpi--teal { --kpi-tone: var(--stage-served); --kpi-soft: var(--stage-served-soft); --kpi-text: var(--stage-served-text); }

.sparkline { overflow: visible; }
.sparkline__area { fill: currentColor; opacity: 0.12; stroke: none; }
.sparkline__line { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.sparkline__dot { fill: var(--surface); stroke: currentColor; stroke-width: 2; vector-effect: non-scaling-stroke; }

/* ---- EmptyState ----------------------------------------------------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-12) var(--space-6);
}
.empty__art { width: 148px; height: 112px; margin-bottom: var(--space-3); color: var(--primary); }
.empty__art .art-bg { fill: var(--primary-soft); }
.empty__art .art-paper { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.5; }
.empty__art .art-line { stroke: var(--border-strong); stroke-width: 3; stroke-linecap: round; }
.empty__art .art-accent { fill: var(--primary); }
.empty__art .art-accent-stroke { stroke: var(--primary); fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.empty__art .art-soft { fill: var(--primary-soft-2); }
.empty--danger .empty__art { color: var(--danger); }
.empty--danger .empty__art .art-bg { fill: var(--danger-soft); }
.empty--danger .empty__art .art-accent { fill: var(--danger); }
.empty--danger .empty__art .art-accent-stroke { stroke: var(--danger); }
.empty--success .empty__art .art-bg { fill: var(--success-soft); }
.empty--success .empty__art .art-accent { fill: var(--success); }
.empty--success .empty__art .art-accent-stroke { stroke: var(--success); }
.empty--warning .empty__art .art-bg { fill: var(--warning-soft); }
.empty--warning .empty__art .art-accent { fill: var(--warning); }
.empty--warning .empty__art .art-accent-stroke { stroke: var(--warning); }
.empty__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text); margin: 0; }
.empty__text { max-width: 440px; color: var(--text-muted); font-size: var(--fs-body); margin: 0; }
.empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); margin-top: var(--space-4); }
.empty--compact { padding: var(--space-8) var(--space-4); }
.empty--compact .empty__art { width: 104px; height: 80px; }

/* ---- Skeleton / Spinner -------------------------------------------- */
.skeleton {
  position: relative;
  display: block;
  overflow: hidden;
  background: var(--skeleton);
  border-radius: var(--radius-xs);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(100%);
  background: linear-gradient(90deg, transparent, var(--skeleton-shine), transparent);
  animation: shimmer 1.5s ease-in-out infinite;
}
@keyframes shimmer { to { transform: translateX(-100%); } }
.skeleton--text { height: 0.75em; margin-block: 0.4em; border-radius: 4px; }
.skeleton--circle { border-radius: 50%; }
.skeleton-lines { display: flex; flex-direction: column; }

.spinner {
  --spinner-size: 20px;
  display: inline-block;
  width: var(--spinner-size);
  height: var(--spinner-size);
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 22%, transparent);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
  vertical-align: middle;
}
.spinner--sm { --spinner-size: 14px; }
.spinner--lg { --spinner-size: 32px; border-width: 3px; }
.spinner-block { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--space-10); color: var(--text-muted); }
.spinner-block .spinner { color: var(--primary); }

/* ---- Countdown ------------------------------------------------------ */
.countdown {
  --cd-size: 96px;
  --cd-tone: var(--primary);
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--cd-size);
  height: var(--cd-size);
  flex-shrink: 0;
}
.countdown__svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.countdown__track { fill: none; stroke: var(--surface-3); }
.countdown__progress { fill: none; stroke: var(--cd-tone); stroke-linecap: round; transition: stroke-dashoffset 1s linear, stroke var(--dur-4); }
.countdown__text { position: relative; display: flex; flex-direction: column; align-items: center; line-height: 1.05; text-align: center; }
.countdown__value { font-weight: var(--fw-bold); font-size: calc(var(--cd-size) * 0.22); font-variant-numeric: tabular-nums; color: var(--text); letter-spacing: -0.01em; direction: ltr; }
.countdown__label { font-size: max(10px, calc(var(--cd-size) * 0.11)); color: var(--text-muted); margin-top: 2px; }
.countdown--warn { --cd-tone: var(--warning); }
.countdown--danger { --cd-tone: var(--danger); }
.countdown--danger .countdown__value { color: var(--danger-text); }
.countdown--danger.is-urgent .countdown__progress { animation: pulse 1s ease-in-out infinite; }
.countdown--expired { --cd-tone: var(--border-strong); }
.countdown--expired .countdown__value { color: var(--text-subtle); }
.countdown--inline { width: auto; height: auto; display: inline-flex; gap: 6px; align-items: center; }
.countdown--inline .countdown__value { font-size: inherit; }

/* ---- ProgressBar ---------------------------------------------------- */
.progress { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.progress__head { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-medium); }
.progress__value { font-variant-numeric: tabular-nums; color: var(--text); font-weight: var(--fw-semibold); }
.progress__track { position: relative; height: var(--progress-h, 8px); border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress__bar {
  height: 100%;
  border-radius: inherit;
  background: var(--progress-tone, var(--primary));
  transition: width var(--dur-5) var(--ease-out);
}
.progress--success { --progress-tone: var(--success); }
.progress--warning { --progress-tone: var(--warning); }
.progress--danger { --progress-tone: var(--danger); }
.progress--sm { --progress-h: 4px; }
.progress--lg { --progress-h: 12px; }
.progress--indeterminate .progress__bar { position: absolute; width: 40% !important; animation: progress-indet 1.3s var(--ease-in-out) infinite; }
@keyframes progress-indet { from { inset-inline-start: -40%; } to { inset-inline-start: 100%; } }

/* ---- Stepper -------------------------------------------------------- */
.stepper { display: flex; list-style: none; margin: 0; padding: 0; counter-reset: step; }
.stepper__step {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  text-align: center;
  min-width: 0;
  margin: 0;
}
.stepper__step + .stepper__step { margin-top: 0; }
.stepper__step:not(:first-child)::before {
  content: "";
  position: absolute;
  top: 16px;
  inset-inline-start: calc(-50% + 22px);
  inset-inline-end: calc(50% + 22px);
  height: 2px;
  border-radius: 2px;
  background: var(--border);
  transition: background var(--dur-4) var(--ease-out);
}
.stepper__step.is-complete::before, .stepper__step.is-current::before { background: var(--primary); }
.stepper__marker {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  transition: all var(--dur-4) var(--ease-out);
}
.stepper__marker .icon { --icon-size: 16px; --icon-stroke: 2.6; }
.stepper__step.is-complete .stepper__marker { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.stepper__step.is-current .stepper__marker { border-color: var(--primary); color: var(--primary-text); box-shadow: 0 0 0 5px var(--primary-soft); }
.stepper__button { display: contents; color: inherit; }
.stepper__button:focus-visible .stepper__marker { outline: var(--focus-width) solid var(--focus-color); outline-offset: 3px; }
.stepper__text { display: flex; flex-direction: column; gap: 2px; padding-inline: var(--space-2); min-width: 0; }
.stepper__label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-muted); line-height: 1.3; }
.stepper__step.is-current .stepper__label, .stepper__step.is-complete .stepper__label { color: var(--text); font-weight: var(--fw-semibold); }
.stepper__desc { font-size: var(--fs-xs); color: var(--text-subtle); }

.stepper--vertical { flex-direction: column; gap: 0; }
.stepper--vertical .stepper__step { flex-direction: row; align-items: flex-start; text-align: start; gap: var(--space-3); padding-bottom: var(--space-6); }
.stepper--vertical .stepper__step:last-child { padding-bottom: 0; }
.stepper--vertical .stepper__step:not(:first-child)::before { display: none; }
.stepper--vertical .stepper__step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 38px;
  bottom: 4px;
  inset-inline-start: 16px;
  width: 2px;
  border-radius: 2px;
  background: var(--border);
}
.stepper--vertical .stepper__step.is-complete::after { background: var(--primary); }
.stepper--vertical .stepper__text { padding: 6px 0 0; }

.stepper-compact { display: flex; flex-direction: column; gap: var(--space-2); }
.stepper-compact__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); font-size: var(--fs-sm); }
.stepper-compact__count { color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stepper-compact__label { font-weight: var(--fw-semibold); color: var(--text); }
.stepper-compact__bars { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.stepper-compact__bar { height: 4px; border-radius: 999px; background: var(--surface-3); transition: background var(--dur-4) var(--ease-out); }
.stepper-compact__bar.is-done { background: var(--primary); }
.stepper-compact__bar.is-current { background: color-mix(in srgb, var(--primary) 55%, var(--surface-3)); }

/* ---- Tabs ----------------------------------------------------------- */
.tabs__list {
  position: relative;
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs__list::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px var(--space-3) 12px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color var(--dur-2) var(--ease-out);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary-text); font-weight: var(--fw-semibold); }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-inline: var(--space-2);
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--primary);
  animation: fade-in var(--dur-3) var(--ease-out);
}
.tab:disabled { opacity: 0.45; }
.tab .icon { --icon-size: 17px; }
.tab__badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; font-size: 11px; font-weight: var(--fw-bold); background: var(--surface-3); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.tab[aria-selected="true"] .tab__badge { background: var(--primary-soft); color: var(--primary-text); }
.tabs__panel { padding-top: var(--space-5); outline: none; }
.tabs--pills .tabs__list { border: 0; padding: 4px; background: var(--surface-3); border-radius: var(--radius-md); display: inline-flex; max-width: 100%; }
.tabs--pills .tab { padding: 7px 14px; border-radius: 9px; }
.tabs--pills .tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.tabs--pills .tab[aria-selected="true"]::after { display: none; }

/* ---- SegmentedControl ---------------------------------------------- */
.segmented {
  position: relative;
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--surface-3);
  max-width: 100%;
  isolation: isolate;
}
.segmented--block { display: flex; width: 100%; }
.segmented__thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  z-index: -1;
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow-sm), var(--shadow-ring);
  transition: left var(--dur-4) var(--ease-out), width var(--dur-4) var(--ease-out);
}
.segmented__option {
  position: relative;
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 var(--space-3);
  border-radius: 9px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition: color var(--dur-2) var(--ease-out);
}
.segmented__option:hover { color: var(--text); }
.segmented__option[aria-checked="true"] { color: var(--text); font-weight: var(--fw-semibold); }
.segmented__option .icon { --icon-size: 16px; }
.segmented__count { font-size: 11px; font-weight: var(--fw-bold); color: var(--text-subtle); font-variant-numeric: tabular-nums; }
.segmented__option[aria-checked="true"] .segmented__count { color: var(--primary-text); }
.segmented:not(.has-thumb) .segmented__option[aria-checked="true"] { background: var(--surface); box-shadow: var(--shadow-sm); }
.shell--mobile .segmented__option { min-height: 40px; }

/* ---- Alert ---------------------------------------------------------- */
.alert {
  --a-tone: var(--info);
  --a-soft: var(--info-soft);
  --a-text: var(--info-text);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--a-soft);
  border: 1px solid color-mix(in srgb, var(--a-tone) 22%, transparent);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.alert__icon { color: var(--a-text); margin-top: 1px; flex-shrink: 0; }
.alert__icon .icon { --icon-size: 20px; }
.alert__content { flex: 1; min-width: 0; }
.alert__title { font-weight: var(--fw-semibold); color: var(--text); font-size: var(--fs-sm); }
.alert__title + .alert__body { margin-top: 2px; }
.alert__body { color: var(--text); opacity: 0.9; }
.alert__actions { display: flex; gap: var(--space-2); align-items: center; flex-shrink: 0; align-self: center; }
.alert--success { --a-tone: var(--success); --a-soft: var(--success-soft); --a-text: var(--success-text); }
.alert--warning { --a-tone: var(--warning); --a-soft: var(--warning-soft); --a-text: var(--warning-text); }
.alert--danger { --a-tone: var(--danger); --a-soft: var(--danger-soft); --a-text: var(--danger-text); }
.alert--neutral { --a-tone: var(--text-muted); --a-soft: var(--surface-3); --a-text: var(--text-muted); }
.alert--banner { padding: var(--space-4) var(--space-5); border-radius: var(--radius-card); }
.alert--banner .alert__title { font-size: var(--fs-md); }
@media (max-width: 639.98px) { .alert { flex-wrap: wrap; } .alert__actions { width: 100%; justify-content: flex-end; } }

/* ---- Modal ---------------------------------------------------------- */
.overlay-layer {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--space-6);
}
.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur-3) var(--ease-out);
}
.modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--modal-w, 560px);
  max-height: calc(100dvh - 2 * var(--space-6));
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  animation: modal-in var(--dur-4) var(--ease-out);
  outline: none;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal--sm { --modal-w: 420px; }
.modal--md { --modal-w: 560px; }
.modal--lg { --modal-w: 760px; }
.modal--xl { --modal-w: 1040px; }
.modal--full { --modal-w: calc(100vw - 2 * var(--space-6)); height: calc(100dvh - 2 * var(--space-6)); }
.modal__header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6) var(--space-3);
}
.modal__heading { flex: 1; min-width: 0; }
.modal__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); line-height: var(--lh-snug); }
.modal__desc { margin-top: 4px; color: var(--text-muted); font-size: var(--fs-sm); }
.modal__close { margin-top: -6px; margin-inline-end: -10px; }
.modal__icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; background: var(--primary-soft); color: var(--primary-text); }
.modal__icon--danger { background: var(--danger-soft); color: var(--danger-text); }
.modal__icon--warning { background: var(--warning-soft); color: var(--warning-text); }
.modal__icon--success { background: var(--success-soft); color: var(--success-text); }
.modal__body { flex: 1; overflow-y: auto; padding: var(--space-2) var(--space-6) var(--space-6); overscroll-behavior: contain; }
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-2);
  border-end-start-radius: inherit;
  border-end-end-radius: inherit;
}
.modal__footer-start { margin-inline-end: auto; }
@media (max-width: 639.98px) {
  .overlay-layer--modal { place-items: end stretch; padding: 0; }
  .overlay-layer--modal .modal {
    max-width: none;
    max-height: 92dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: sheet-in var(--dur-5) var(--ease-out);
    padding-bottom: var(--safe-bottom);
  }
  .overlay-layer--modal .modal--full { height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .overlay-layer--modal .modal::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 999px;
    background: var(--border-strong);
  }
  .modal__footer { padding-bottom: calc(var(--space-4) + var(--safe-bottom)); }
  .modal__footer .btn { flex: 1; }
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }

/* ---- Drawer --------------------------------------------------------- */
.overlay-layer--drawer { display: block; padding: 0; z-index: var(--z-drawer); }
.drawer {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  display: flex;
  flex-direction: column;
  width: min(var(--drawer-w, 560px), 100vw);
  background: var(--surface-raised);
  box-shadow: var(--shadow-xl);
  border-inline-start: 1px solid var(--border-subtle);
  animation: drawer-in-end var(--dur-5) var(--ease-out);
  outline: none;
}
.drawer--start { inset-inline-end: auto; inset-inline-start: 0; border-inline-start: 0; border-inline-end: 1px solid var(--border-subtle); animation-name: drawer-in-start; }
.drawer--sm { --drawer-w: 400px; }
.drawer--lg { --drawer-w: 760px; }
.drawer--xl { --drawer-w: 960px; }
@keyframes drawer-in-end { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes drawer-in-start { from { transform: translateX(100%); } to { transform: none; } }
.drawer__header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: calc(var(--space-5) + var(--safe-top)) var(--space-6) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.drawer__heading { flex: 1; min-width: 0; }
.drawer__title { font-size: var(--fs-lg); font-weight: var(--fw-bold); line-height: var(--lh-snug); }
.drawer__desc { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-muted); }
.drawer__body { flex: 1; overflow-y: auto; padding: var(--space-5) var(--space-6); overscroll-behavior: contain; }
.drawer__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6) calc(var(--space-4) + var(--safe-bottom));
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-2);
}

/* ---- Popover / Menu ------------------------------------------------- */
.popover-anchor { position: relative; display: inline-flex; }
.popover {
  position: absolute;
  top: calc(100% + 8px);
  z-index: var(--z-dropdown);
  min-width: 220px;
  max-width: min(360px, calc(100vw - 24px));
  padding: var(--space-1-5);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--dur-2) var(--ease-out);
  outline: none;
  text-align: start;
}
.popover--end { inset-inline-end: 0; }
.popover--start { inset-inline-start: 0; }
.popover--top { top: auto; bottom: calc(100% + 8px); }
.popover--flush { padding: 0; }
.popover__header { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.popover__title { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.popover__footer { padding: var(--space-2) var(--space-3); border-top: 1px solid var(--border-subtle); display: flex; justify-content: center; }
@media (max-width: 639.98px) {
  .popover--sheet-mobile {
    position: fixed;
    top: auto;
    bottom: 0;
    inset-inline: 0;
    max-width: none;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding-bottom: calc(var(--space-3) + var(--safe-bottom));
    animation: sheet-in var(--dur-4) var(--ease-out);
    z-index: var(--z-popover);
    max-height: 85dvh;
    overflow-y: auto;
  }
}

.menu { display: flex; flex-direction: column; gap: 1px; }
.menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-align: start;
  text-decoration: none;
  white-space: nowrap;
}
.menu__item .icon { --icon-size: 18px; color: var(--text-muted); }
.menu__item:hover, .menu__item:focus-visible, .menu__item.is-focused { background: var(--surface-3); text-decoration: none; outline: none; }
.menu__item--danger { color: var(--danger-text); }
.menu__item--danger .icon { color: var(--danger-text); }
.menu__item[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.menu__item-desc { display: block; font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-regular); white-space: normal; }
.menu__item-check { margin-inline-start: auto; color: var(--primary-text) !important; }
.menu__divider { height: 1px; margin: var(--space-1-5) calc(-1 * var(--space-1-5)); background: var(--border-subtle); }
.menu__label { padding: 6px 10px 4px; font-size: var(--fs-2xs); font-weight: var(--fw-semibold); color: var(--text-subtle); letter-spacing: 0.03em; }
.menu__user { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 10px var(--space-3); }
.menu__user-name { font-weight: var(--fw-semibold); font-size: var(--fs-sm); line-height: 1.3; }
.menu__user-meta { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---- Toast ---------------------------------------------------------- */
/* --toast-avoid (px) is measured by ToastHost: the height of bottom bars (sticky save bar, courier
   action bar, bottom tabs, [data-toast-avoid]) so the stack always sits above them. */
.toast-host {
  --toast-base: var(--space-6);
  position: fixed;
  z-index: var(--z-toast);
  bottom: max(var(--toast-base), calc(var(--toast-avoid, 0px) + var(--space-3)));
  inset-inline-end: var(--space-6);
  transition: bottom var(--dur-3) var(--ease-out);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  width: min(400px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}
.toast {
  --t-tone: #7C9BFF;
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-radius: var(--radius-card);
  background: #13204A;
  color: #F2F5FC;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 32px -8px rgba(8, 14, 30, 0.45), 0 2px 6px rgba(8, 14, 30, 0.2);
  overflow: hidden;
  pointer-events: auto;
  animation: toast-in var(--dur-5) var(--ease-spring);
}
.toast.is-leaving { animation: toast-out var(--dur-3) var(--ease-out) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }
.toast__icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: color-mix(in srgb, var(--t-tone) 22%, transparent); color: var(--t-tone); margin-top: 1px; }
.toast__icon .icon { --icon-size: 16px; --icon-stroke: 2.2; }
.toast__body { min-width: 0; padding-top: 3px; }
.toast__title { font-weight: var(--fw-semibold); font-size: var(--fs-sm); line-height: 1.35; }
.toast__message { font-size: var(--fs-sm); color: rgba(242, 245, 252, 0.78); line-height: 1.45; margin-top: 1px; }
.toast__title + .toast__message { margin-top: 2px; }
.toast__action { margin-top: var(--space-2); color: #A9BEFF; font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.toast__action:hover { text-decoration: underline; }
.toast__close { color: rgba(242, 245, 252, 0.6); --ib-size: 28px; }
.toast__close:hover:not(:disabled) { color: #fff; background: rgba(255, 255, 255, 0.1); }
.toast__progress {
  position: absolute;
  bottom: 0;
  inset-inline-start: 0;
  height: 2px;
  width: 100%;
  background: var(--t-tone);
  opacity: 0.7;
  transform-origin: right;
  animation: toast-progress linear forwards;
}
.toast:hover .toast__progress, .toast:focus-within .toast__progress { animation-play-state: paused; }
@keyframes toast-progress { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.toast--success { --t-tone: #4ADE9B; }
.toast--error { --t-tone: #FF8A8A; }
.toast--warning { --t-tone: #FBBF4E; }
.toast--info { --t-tone: #7CC8F8; }
/* Touch / narrow screens: the close button's hit area grows to --touch (48px) while it still looks
   and lays out as 28px. The negative margin gives the extra room back to the grid, and the hover
   fill is clipped to the inner 28px (padding 9 + border 1 per side) with the same corner radius. */
@media (pointer: coarse), (max-width: 767.98px) {
  .toast__close {
    --ib-size: var(--touch);
    margin: -10px;
    padding: 9px;
    background-clip: content-box;
    border-radius: calc(var(--radius-sm) + 10px);
  }
}
@media (max-width: 767.98px) {
  .toast-host { --toast-base: calc(var(--space-4) + var(--safe-bottom)); inset-inline: var(--space-3); width: auto; }
  /* Fallbacks before the first measurement (CSS only). */
  body:has(.bottom-nav) .toast-host { --toast-base: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--space-3)); }
  body:has(.shell--mobile .action-bar) .toast-host { --toast-base: calc(var(--bottomnav-h) + var(--safe-bottom) + 76px); }
  body:has(.shell--mobile.no-bottom-nav .action-bar) .toast-host { --toast-base: calc(var(--safe-bottom) + 84px); }
}

/* ---- DataTable ------------------------------------------------------ */
.datatable { display: flex; flex-direction: column; min-width: 0; }
.datatable__frame {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
[data-theme="dark"] .datatable__frame { border-color: var(--border); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .datatable__frame { border-color: var(--border); } }
.datatable__scroll { overflow: auto; max-height: var(--table-max-h, none); }
.datatable--sticky .datatable__scroll { max-height: var(--table-max-h, min(72vh, 900px)); }
.table { width: 100%; font-size: var(--fs-sm); }
.table th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 11px var(--space-4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-align: start;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.table td {
  padding: 13px var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  color: var(--text);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--dur-1) var(--ease-out); }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:focus-visible { outline: none; }
.table tbody tr.is-clickable:focus-visible td { background: var(--primary-soft); box-shadow: inset 0 2px 0 var(--primary), inset 0 -2px 0 var(--primary); }
.table tbody tr.is-selected td { background: var(--primary-soft); }
.table .is-num, .table .align-end { text-align: end; font-variant-numeric: tabular-nums; }
.table .align-center { text-align: center; }
.table .is-nowrap { white-space: nowrap; }
.table .is-muted { color: var(--text-muted); }
.table__check { width: 44px; padding-inline-end: 0 !important; }
.table--dense td { padding-block: 8px; }
.table--dense th { padding-block: 8px; }
.table__sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: inherit;
  font: inherit;
  margin: -4px -6px;
  padding: 4px 6px;
  border-radius: 6px;
}
.table__sort:hover { color: var(--text); background: var(--surface-3); }
.table__sort .icon { --icon-size: 14px; opacity: 0.35; transition: opacity var(--dur-2), transform var(--dur-2); }
.table__sort.is-sorted { color: var(--text); }
.table__sort.is-sorted .icon { opacity: 1; color: var(--primary-text); }
.table__sort.is-desc .icon { transform: rotate(180deg); }
.table__primary { font-weight: var(--fw-semibold); color: var(--text); }
.table__secondary { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.table__skeleton td { padding-block: 16px; }

.datatable__selbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-4);
  background: var(--primary-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--primary) 18%, transparent);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--primary-text);
  animation: fade-in var(--dur-2);
}
.datatable__selbar-actions { display: flex; gap: var(--space-2); margin-inline-start: auto; flex-wrap: wrap; }

.datatable__cards { display: flex; flex-direction: column; gap: var(--space-3); }
.table-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-xs);
  text-align: start;
  width: 100%;
  color: inherit;
}
[data-theme="dark"] .table-card { border-color: var(--border); }
.table-card.is-clickable { cursor: pointer; transition: box-shadow var(--dur-2), border-color var(--dur-2); }
.table-card.is-clickable:hover { box-shadow: var(--shadow-md); }
.table-card.is-selected { border-color: var(--primary); background: var(--primary-soft); }
.table-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.table-card__title { font-weight: var(--fw-semibold); font-size: var(--fs-md); min-width: 0; }
.table-card__row { display: flex; justify-content: space-between; gap: var(--space-3); font-size: var(--fs-sm); }
.table-card__label { color: var(--text-muted); flex-shrink: 0; }
.table-card__value { text-align: end; min-width: 0; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: 10px var(--space-4);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.datatable__frame .pagination { border-top: 1px solid var(--border-subtle); }
.pagination__info { font-variant-numeric: tabular-nums; }
.pagination__info strong { color: var(--text); font-weight: var(--fw-semibold); }
.pagination__controls { display: flex; align-items: center; gap: 4px; }
.pagination__page {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
}
.pagination__page:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.pagination__page[aria-current="page"] { background: var(--primary-soft); color: var(--primary-text); font-weight: var(--fw-bold); }
.pagination__ellipsis { padding: 0 4px; color: var(--text-subtle); }
.pagination__size { display: flex; align-items: center; gap: var(--space-2); }
.pagination__size select.input { width: auto; height: 32px; font-size: var(--fs-sm); padding-inline-start: 10px; }

/* ---- Timeline ------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__day { margin: var(--space-4) 0 var(--space-3); font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-subtle); letter-spacing: 0.02em; }
.timeline__day:first-child { margin-top: 0; }
.timeline__item {
  --tl-tone: var(--text-muted);
  --tl-soft: var(--surface-3);
  position: relative;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: var(--space-3);
  padding-bottom: var(--space-5);
  margin: 0;
}
.timeline__item:last-child { padding-bottom: 0; }
.timeline__item:not(:last-child)::before {
  content: "";
  position: absolute;
  top: 34px;
  bottom: 2px;
  inset-inline-start: 15px;
  width: 2px;
  border-radius: 2px;
  background: var(--border);
}
.timeline__marker {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--tl-soft);
  color: var(--tl-tone);
  box-shadow: 0 0 0 4px var(--surface);
}
.timeline__marker .icon { --icon-size: 16px; --icon-stroke: 2; }
.timeline__content { padding-top: 5px; min-width: 0; }
.timeline__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px var(--space-3); }
.timeline__title { font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--text); }
.timeline__time { font-size: var(--fs-xs); color: var(--text-subtle); font-variant-numeric: tabular-nums; white-space: nowrap; }
.timeline__desc { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-muted); }
.timeline__actor { margin-top: 2px; font-size: var(--fs-xs); color: var(--text-subtle); }
.timeline__item--primary { --tl-tone: var(--primary-text); --tl-soft: var(--primary-soft); }
.timeline__item--success { --tl-tone: var(--success-text); --tl-soft: var(--success-soft); }
.timeline__item--warning { --tl-tone: var(--warning-text); --tl-soft: var(--warning-soft); }
.timeline__item--danger { --tl-tone: var(--danger-text); --tl-soft: var(--danger-soft); }
.timeline__item--info { --tl-tone: var(--info-text); --tl-soft: var(--info-soft); }
.timeline__item.is-latest .timeline__marker { box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px var(--tl-soft); }

/* ---- Dropzone ------------------------------------------------------- */
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 160px;
  padding: var(--space-6) var(--space-5);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-card);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}
.dropzone:hover { border-color: var(--primary); background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface-2)); }
.dropzone:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.dropzone.is-dragover { border-style: solid; border-color: var(--primary); background: var(--primary-soft); transform: scale(1.005); }
.dropzone.is-invalid { border-color: var(--danger); background: var(--danger-soft); }
.dropzone.is-disabled { opacity: 0.55; cursor: not-allowed; }
.dropzone--compact { min-height: 0; flex-direction: row; justify-content: flex-start; text-align: start; padding: var(--space-4); gap: var(--space-4); }
.dropzone__icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--primary-text);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-1);
}
.dropzone__icon .icon { --icon-size: 24px; }
.dropzone--compact .dropzone__icon { margin: 0; width: 44px; height: 44px; }
.dropzone__title { font-weight: var(--fw-semibold); color: var(--text); }
.dropzone__title u { color: var(--primary-text); text-decoration: none; }
.dropzone__hint { font-size: var(--fs-xs); color: var(--text-muted); }
.file-chips { display: flex; flex-direction: column; gap: var(--space-2); list-style: none; margin: var(--space-3) 0 0; padding: 0; }
.file-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 8px 8px var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  background: var(--surface);
  animation: fade-up var(--dur-3) var(--ease-out);
  margin: 0;
}
.file-chip__icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: var(--danger-soft); color: var(--danger-text); flex-shrink: 0; }
.file-chip__icon--sheet { background: var(--success-soft); color: var(--success-text); }
.file-chip__icon--image { background: var(--info-soft); color: var(--info-text); }
.file-chip__icon--generic { background: var(--surface-3); color: var(--text-muted); }
.file-chip__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-chip__name { font-size: var(--fs-sm); font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right; unicode-bidi: plaintext; }
.file-chip__meta { font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---- SignaturePad --------------------------------------------------- */
.sigpad { display: flex; flex-direction: column; gap: var(--space-2); }
.sigpad__surface {
  position: relative;
  height: var(--sig-h, 220px);
  border-radius: var(--radius-card);
  background: var(--paper);
  border: 1px solid var(--border-strong);
  box-shadow: inset 0 1px 3px rgba(16, 24, 40, 0.06), var(--shadow-xs);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: crosshair;
}
.sigpad__surface:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); border-color: var(--primary); }
.sigpad__canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.sigpad__baseline {
  position: absolute;
  inset-inline: 24px;
  bottom: 28%;
  border-bottom: 1.5px dashed var(--paper-line);
  pointer-events: none;
}
.sigpad__x {
  position: absolute;
  inset-inline-start: 26px;
  bottom: calc(28% + 6px);
  color: #9AA4B8;
  font-size: 22px;
  font-weight: 300;
  line-height: 1;
  pointer-events: none;
}
.sigpad__hint {
  position: absolute;
  inset: 0 0 28% 0;
  display: grid;
  place-items: center;
  color: #8E98AE;
  font-size: var(--fs-lg);
  font-weight: var(--fw-medium);
  pointer-events: none;
  transition: opacity var(--dur-3) var(--ease-out);
}
.sigpad.has-ink .sigpad__hint { opacity: 0; }
.sigpad__actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.sigpad__status { font-size: var(--fs-xs); color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.sigpad__status .icon { --icon-size: 14px; }
.sigpad.has-ink .sigpad__status { color: var(--success-text); }
.sigpad.is-invalid .sigpad__surface { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-ring); }
.sigpad.is-disabled .sigpad__surface { opacity: 0.6; cursor: not-allowed; }

/* ---- CameraCapture -------------------------------------------------- */
.camera { display: flex; flex-direction: column; gap: var(--space-3); }
.camera__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--space-3); }
.camera__thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--border);
  animation: scale-in var(--dur-3) var(--ease-out);
}
.camera__thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.camera__thumb-btn { display: block; width: 100%; height: 100%; }
.camera__remove {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(8, 14, 30, 0.62);
  color: #fff;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.camera__remove .icon { --icon-size: 16px; --icon-stroke: 2.2; }
.camera__remove:hover { background: var(--danger); }
.camera__index {
  position: absolute;
  bottom: 6px;
  inset-inline-start: 6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: var(--fw-bold);
  background: rgba(8, 14, 30, 0.62);
  color: #fff;
}
.camera__processing { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--primary); }
.camera__add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  border: 2px dashed var(--border-strong);
  color: var(--primary-text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  background: var(--surface-2);
}
.camera__add:hover { border-color: var(--primary); background: var(--primary-soft); }
.camera__add .icon { --icon-size: 26px; }
.camera__buttons { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.camera.is-invalid .camera__add { border-color: var(--danger); }

/* ---- MapView -------------------------------------------------------- */
.map {
  position: relative;
  height: var(--map-h, 360px);
  border-radius: var(--radius-card);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-3);
  isolation: isolate;
}
.map__canvas { position: absolute; inset: 0; }
.map .leaflet-container { width: 100%; height: 100%; font-family: var(--font-sans); background: var(--surface-3); }
.map .leaflet-control-attribution { font-size: 10px; background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--text-muted); }
.map .leaflet-control-attribution a { color: var(--text-muted); }
.map .leaflet-bar { border: 1px solid var(--border) !important; box-shadow: var(--shadow-md) !important; border-radius: 10px !important; overflow: hidden; }
.map .leaflet-bar a { background: var(--surface); color: var(--text); border-bottom-color: var(--border); width: 34px; height: 34px; line-height: 34px; }
.map .leaflet-bar a:hover { background: var(--surface-2); }
.map .leaflet-popup-content-wrapper { border-radius: 12px; background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-lg); }
.map .leaflet-popup-tip { background: var(--surface-raised); }
.map .leaflet-popup-content { direction: rtl; text-align: right; font-family: var(--font-sans); font-size: var(--fs-sm); line-height: 1.5; margin: 12px 14px; }
.map .leaflet-popup-content strong { display: block; font-size: var(--fs-sm); margin-bottom: 2px; }
.map__notice {
  position: absolute;
  z-index: 800;
  top: var(--space-3);
  inset-inline: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px var(--space-3);
  border-radius: var(--radius-input);
  background: var(--surface-overlay);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.map__loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); z-index: 2; }
.map-pin { position: relative; width: 30px; height: 40px; filter: drop-shadow(0 3px 4px rgba(8, 14, 30, 0.35)); transition: transform var(--dur-2) var(--ease-spring); }
.map-pin:hover { transform: translateY(-2px) scale(1.06); }
.map-pin svg { width: 30px; height: 40px; overflow: visible; }
.map-pin__body { fill: var(--pin, var(--primary)); stroke: #fff; stroke-width: 2; }
.map-pin__dot { fill: #fff; }
.map-pin__num { position: absolute; top: 5px; inset-inline: 0; text-align: center; color: #fff; font: 700 12px/20px var(--font-sans); font-variant-numeric: tabular-nums; }
.map-cluster {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--cluster, var(--primary));
  color: #fff;
  font: 700 13px var(--font-sans);
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--cluster, var(--primary)) 28%, transparent), 0 4px 10px rgba(8, 14, 30, 0.3);
  font-variant-numeric: tabular-nums;
}
.map-user { position: relative; width: 18px; height: 18px; }
.map-user::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  background: rgba(47, 123, 246, 0.22);
  animation: user-pulse 2s ease-out infinite;
}
.map-user::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #2F7BF6;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(8, 14, 30, 0.35);
}
@keyframes user-pulse { from { transform: scale(0.5); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
:root[data-theme="dark"] .map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.7); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.7); }
}

/* ---- PdfViewer ------------------------------------------------------ */
.pdf {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.pdf__toolbar { display: flex; align-items: center; gap: var(--space-2); padding: 8px var(--space-2) 8px var(--space-4); border-bottom: 1px solid var(--border-subtle); background: var(--surface-2); }
.pdf__title { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-2); font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.pdf__title .icon { color: var(--danger-text); }
.pdf__frame { display: block; width: 100%; height: var(--pdf-h, 70vh); background: #525659; }
.pdf__fallback { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-10) var(--space-6); text-align: center; color: var(--text-muted); }

/* ---- QrCode --------------------------------------------------------- */
.qr { display: inline-flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.qr__frame { padding: 12px; border-radius: var(--radius-card); background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow-sm); line-height: 0; }
.qr__frame svg { display: block; shape-rendering: crispEdges; }
.qr__caption { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---- Lightbox ------------------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-popover);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(5, 8, 16, 0.94);
  color: #fff;
  animation: fade-in var(--dur-3) var(--ease-out);
  outline: none;
}
.lightbox__bar { display: flex; align-items: center; gap: var(--space-2); padding: calc(var(--space-3) + var(--safe-top)) var(--space-4) var(--space-3); }
.lightbox__counter { flex: 1; font-size: var(--fs-sm); color: rgba(255, 255, 255, 0.75); font-variant-numeric: tabular-nums; }
.lightbox__stage { position: relative; display: grid; place-items: center; padding: 0 var(--space-16); min-height: 0; touch-action: pan-y; }
.lightbox__img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-sm); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); animation: scale-in var(--dur-3) var(--ease-out); -webkit-user-select: none; user-select: none; }
.lightbox__nav { position: absolute; top: 50%; transform: translateY(-50%); --ib-size: 48px; border-radius: 50%; background: rgba(255, 255, 255, 0.1); color: #fff; }
.lightbox__nav:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); color: #fff; }
.lightbox__nav--prev { inset-inline-start: var(--space-4); }
.lightbox__nav--next { inset-inline-end: var(--space-4); }
.lightbox__caption { padding: var(--space-3) var(--space-4) calc(var(--space-4) + var(--safe-bottom)); text-align: center; font-size: var(--fs-sm); color: rgba(255, 255, 255, 0.8); min-height: 48px; }
@media (max-width: 639.98px) {
  .lightbox__stage { padding: 0 var(--space-2); }
  .lightbox__nav { top: auto; bottom: var(--space-2); transform: none; }
}

/* ---- Avatar --------------------------------------------------------- */
.avatar {
  --av-size: 36px;
  display: inline-grid;
  place-items: center;
  width: var(--av-size);
  height: var(--av-size);
  border-radius: 50%;
  flex-shrink: 0;
  color: #fff;
  font-weight: var(--fw-bold);
  font-size: calc(var(--av-size) * 0.38);
  letter-spacing: 0;
  background: linear-gradient(135deg, hsl(var(--av-h, 225) 72% 58%), hsl(calc(var(--av-h, 225) + 28) 70% 44%));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  -webkit-user-select: none;
  user-select: none;
}
.avatar--sm { --av-size: 28px; }
.avatar--lg { --av-size: 48px; }
.avatar--xl { --av-size: 72px; }

/* ---- Description list ---------------------------------------------- */
.dl { display: grid; grid-template-columns: minmax(120px, max-content) minmax(0, 1fr); gap: var(--space-3) var(--space-6); margin: 0; font-size: var(--fs-sm); }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; color: var(--text); font-weight: var(--fw-medium); min-width: 0; overflow-wrap: anywhere; }
.dl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(var(--min, 180px), 100%), 1fr)); gap: var(--space-4) var(--space-6); margin: 0; }
.dl-grid__item { min-width: 0; }
.dl-grid dt { font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: 2px; }
.dl-grid dd { margin: 0; font-weight: var(--fw-medium); overflow-wrap: anywhere; }
@media (max-width: 639.98px) {
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .dl dd { margin-bottom: var(--space-3); }
}

/* ---- Notifications -------------------------------------------------- */
.notif-panel { width: min(400px, calc(100vw - 24px)); }
.notif-list { display: flex; flex-direction: column; list-style: none; margin: 0; padding: var(--space-1-5); max-height: min(440px, 70dvh); overflow-y: auto; }
.notif-item {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: var(--space-3);
  width: 100%;
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  text-align: start;
  color: inherit;
  text-decoration: none;
  transition: background var(--dur-1) var(--ease-out);
}
.notif-item:hover, .notif-item:focus-visible { background: var(--surface-3); text-decoration: none; }
.notif-item__icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--n-soft, var(--primary-soft)); color: var(--n-tone, var(--primary-text)); }
.notif-item__icon .icon { --icon-size: 18px; }
.notif-item__body { min-width: 0; }
.notif-item__title { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); line-height: 1.35; }
.notif-item:not(.is-unread) .notif-item__title { font-weight: var(--fw-medium); color: var(--text-muted); }
.notif-item__text { margin-top: 2px; font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif-item__time { font-size: var(--fs-2xs); color: var(--text-subtle); white-space: nowrap; padding-top: 2px; font-variant-numeric: tabular-nums; }
.notif-item__dot { position: absolute; top: 50%; inset-inline-end: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.notif-item.is-unread .notif-item__time { color: var(--primary-text); font-weight: var(--fw-semibold); }

/* ---- Search input --------------------------------------------------- */
.search { position: relative; }
.search .input { height: 40px; padding-inline-start: 40px; padding-inline-end: 44px; background: var(--surface-3); border-color: transparent; box-shadow: none; font-size: var(--fs-sm); }
.search .input:hover:not(:focus) { border-color: var(--border); }
/* The resting field has no border or shadow, and `.search .input` (same specificity as the base
   `.input:focus`, declared later) would also wipe the focus ring, so it is restated here. */
.search .input:focus, .search .input:focus-visible { background: var(--surface); border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.search__icon { position: absolute; inset-block: 0; inset-inline-start: 12px; display: flex; align-items: center; color: var(--text-subtle); pointer-events: none; }
.search__icon .icon { --icon-size: 18px; }
.search__kbd { position: absolute; inset-block: 0; inset-inline-end: 10px; display: flex; align-items: center; pointer-events: none; }
.search__kbd kbd { font-size: 11px; color: var(--text-subtle); }

/* ---- Accessibility menu -------------------------------------------- */
.a11y-panel { width: min(340px, calc(100vw - 24px)); padding: 0; }
.a11y-panel__body { padding: var(--space-2) var(--space-4) var(--space-3); display: flex; flex-direction: column; }
.a11y-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 10px 0; border-bottom: 1px solid var(--border-subtle); }
.a11y-row:last-child { border-bottom: 0; }
.a11y-row__label { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.a11y-row__label .icon { color: var(--text-muted); --icon-size: 18px; }
.a11y-scale { display: flex; align-items: center; gap: 4px; }
.a11y-scale__value { min-width: 48px; text-align: center; font-size: var(--fs-sm); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; }
.a11y-panel__footer { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-top: 1px solid var(--border-subtle); background: var(--surface-2); border-radius: 0 0 var(--radius-card) var(--radius-card); }

/* ---- Misc ----------------------------------------------------------- */
.divider { height: 1px; background: var(--border-subtle); border: 0; margin: var(--space-4) 0; }
.divider--text { display: flex; align-items: center; gap: var(--space-3); height: auto; background: none; color: var(--text-subtle); font-size: var(--fs-xs); }
.divider--text::before, .divider--text::after { content: ""; flex: 1; height: 1px; background: var(--border-subtle); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--text-subtle)); flex-shrink: 0; }
.dot--success { --dot: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot--danger { --dot: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot--warning { --dot: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.dot--muted { --dot: var(--border-strong); }
.dot--live { animation: pulse 1.6s ease-in-out infinite; }
.kbd-hint { font-size: var(--fs-xs); color: var(--text-subtle); }
.error-boundary { padding: var(--space-8); }

/* ---- User menu trigger ---------------------------------------------- */
.user-trigger { --btn-h: 44px; gap: 10px; padding: 0 8px 0 10px; font-weight: var(--fw-medium); }
.user-trigger__text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; text-align: start; min-width: 0; }
.user-trigger__name { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.user-trigger__role { font-size: var(--fs-2xs); color: var(--text-muted); font-weight: var(--fw-medium); }
.user-trigger > .icon { --icon-size: 16px; color: var(--text-subtle); }
@media (max-width: 767.98px) { .user-trigger__text, .user-trigger > .icon { display: none; } .user-trigger { padding: 0 4px; } }

/* ---- Leaflet extras (MapView) --------------------------------------- */
.map .map-divicon { background: none; border: 0; }
.map .map-route { stroke: var(--primary); stroke-width: 4; stroke-opacity: 0.85; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.map .map-accuracy { fill: #2F7BF6; fill-opacity: 0.12; stroke: #2F7BF6; stroke-opacity: 0.35; stroke-width: 1; }

/* ---- Route loading bar ---------------------------------------------- */
.route-progress { position: fixed; top: 0; inset-inline: 0; z-index: var(--z-toast); height: 3px; overflow: hidden; pointer-events: none; }
.route-progress span { position: absolute; inset-block: 0; width: 35%; background: var(--primary); border-radius: 0 0 2px 2px; box-shadow: 0 0 10px var(--primary-ring); animation: progress-indet 1.1s var(--ease-in-out) infinite; }
