/* ============================================================================
   ds/components.css — Harbor primitives + re-skins of existing generic classes
   ----------------------------------------------------------------------------
   Two kinds of rules live here:
   1. New primitives with an `af-` prefix (buttons, fields, cards, stat tiles,
      list rows, chips, segmented/tabs, badges, skeletons, empty/error states,
      sheets). Screens adopt them in Phase 4.
   2. Safe re-skins of the generic classes every page already uses (.btn*,
      form controls, .card, .modal*, .txn-modal, deposit/loan modals,
      confirm dialog) so existing markup picks up the Harbor look now.
      IDs, classes and JS hooks are untouched (CSS only).
   Breakpoints: 480 / 768 / 1024 / 1280 (min-width).
   ============================================================================ */

/* ---------------------------------------------------------------------------
   1. Buttons
   --------------------------------------------------------------------------- */
.btn,
.af-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--af-sp-2);
  min-height: var(--af-control-h);
  padding: 0 var(--af-sp-5);
  border-radius: var(--af-r-md);
  border: 1px solid transparent;
  font-family: var(--af-font-body);
  font-size: var(--af-fs-md);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: none;
  filter: none;
  transition: background-color var(--af-dur-fast) var(--af-ease),
              border-color var(--af-dur-fast) var(--af-ease),
              color var(--af-dur-fast) var(--af-ease),
              transform var(--af-dur-fast) var(--af-ease);
}
.btn:hover, .af-btn:hover { transform: none; filter: none; box-shadow: none; text-decoration: none; }
.btn:active:not(:disabled), .af-btn:active:not(:disabled) { transform: scale(.98); }
.btn:focus-visible, .af-btn:focus-visible { outline: 2px solid var(--af-focus); outline-offset: 2px; }

.btn-primary, .af-btn--primary,
.btn-success, .btn-retry {
  background: var(--af-primary);
  color: var(--af-on-primary);
  border-color: transparent;
}
.btn-primary:hover, .af-btn--primary:hover,
.btn-success:hover, .btn-retry:hover {
  background: var(--af-primary-hover);
  color: var(--af-on-primary);
}

.btn-secondary, .btn-outline, .af-btn--secondary {
  background: var(--af-surface);
  color: var(--af-ink);
  border-color: var(--af-border-strong);
}
.btn-secondary:hover, .btn-outline:hover, .af-btn--secondary:hover {
  background: var(--af-surface-sunken);
  color: var(--af-ink);
  border-color: var(--af-border-strong);
}

.btn-ghost, .af-btn--ghost {
  background: transparent;
  color: var(--af-primary-text);
  border-color: transparent;
}
.btn-ghost:hover, .af-btn--ghost:hover { background: var(--af-primary-soft); color: var(--af-primary-text); }

.btn-danger, .af-btn--danger {
  background: var(--af-danger);
  color: var(--af-on-danger);
  border-color: transparent;
}
.btn-danger:hover, .af-btn--danger:hover { background: var(--af-danger); color: var(--af-on-danger); filter: brightness(.92); }

.btn-warning { background: var(--af-warning-soft); color: var(--af-warning); border-color: transparent; }

.btn-sm, .af-btn--sm { min-height: var(--af-control-h-sm); padding: 0 var(--af-sp-4); font-size: var(--af-fs-sm); }
.btn-lg { min-height: 52px; padding: 0 var(--af-sp-6); font-size: var(--af-fs-md); }
.btn-block, .af-btn--block { display: flex; width: 100%; }

.btn:disabled, .btn[disabled], .btn[aria-disabled="true"],
.af-btn:disabled, .af-btn[aria-disabled="true"] {
  background: var(--af-surface-sunken);
  color: var(--af-ink-faint);
  border-color: transparent;
  opacity: 1;
  cursor: not-allowed;
  transform: none;
}
.btn[aria-busy="true"], .af-btn[aria-busy="true"] { cursor: progress; }

/* Icon button: 44×44 circle (app bar, row actions, close). */
.af-iconbtn {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--af-target-min);
  height: var(--af-target-min);
  padding: 0;
  border: 0;
  border-radius: var(--af-r-pill);
  background: transparent;
  color: var(--af-ink);
  cursor: pointer;
  text-decoration: none;
}
.af-iconbtn:hover { background: var(--af-surface-sunken); color: var(--af-ink); }
.btn-close { width: var(--af-target-min); height: var(--af-target-min); border-radius: var(--af-r-pill); }

/* Spinner for busy buttons */
.af-spinner {
  width: 16px; height: 16px; flex: none;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  animation: afSpin .8s linear infinite;
}
@keyframes afSpin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   2. Form controls (16px text at every width = no iOS focus zoom; ≥44px tall)
   --------------------------------------------------------------------------- */
.form-group input,
.form-group select,
.form-group textarea,
input[type="text"], input[type="email"], input[type="password"], input[type="tel"],
input[type="number"], input[type="date"], input[type="time"], input[type="search"],
input[type="url"], input[type="datetime-local"], input[type="month"],
select, textarea,
.af-input {
  min-height: var(--af-control-h);
  padding: 0 var(--af-sp-4);
  font-family: var(--af-font-body);
  font-size: var(--af-fs-md);
  color: var(--af-ink);
  background-color: var(--af-surface);
  border: 1px solid var(--af-border-strong);
  border-radius: var(--af-r-md);
  box-shadow: none;
  line-height: 1.4;
}
textarea, .form-group textarea, textarea.af-input {
  min-height: 96px;
  padding-block: var(--af-sp-3);
  resize: vertical;
}
.form-group input:hover, .form-group select:hover, .form-group textarea:hover { border-color: var(--af-ink-soft); }

.form-group input:focus, .form-group select:focus, .form-group textarea:focus,
input:focus, select:focus, textarea:focus, .af-input:focus {
  outline: none;
  border-color: var(--af-focus);
  box-shadow: 0 0 0 1px var(--af-focus);
  background-color: var(--af-surface);
}
input::placeholder, textarea::placeholder { color: var(--af-ink-faint); opacity: 1; }

input:disabled, select:disabled, textarea:disabled {
  background-color: var(--af-surface-sunken);
  color: var(--af-ink-faint);
  opacity: 1;
}

/* Native select with a chevron at inline-end (Aurora had it at the wrong side's padding in RTL). */
select, select.af-input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%234A5753' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  padding-inline-start: var(--af-sp-4);
  padding-inline-end: 40px;
}
[dir="rtl"] select { background-position: left 14px center; padding-inline-start: var(--af-sp-4); padding-inline-end: 40px; }
[dir="ltr"] select { background-position: right 14px center; padding-inline-start: var(--af-sp-4); padding-inline-end: 40px; }
:root[data-theme="dark"] select, :root[data-ac-contrast="dark"] select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23B2BFBB' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
}
select[multiple], select[size]:not([size="1"]) { background-image: none; padding-inline-end: var(--af-sp-4); min-height: 96px; }

input[type="checkbox"], input[type="radio"] { accent-color: var(--af-primary); width: 20px; height: 20px; min-height: 0; }
input[type="range"] { accent-color: var(--af-primary); min-height: 0; }
input[type="color"] { min-height: var(--af-control-h); padding: 4px; }

/* Labels */
.form-group label, .af-field > label, .af-label {
  display: block;
  margin-block-end: 6px;
  color: var(--af-ink);
  font-size: var(--af-fs-sm);
  font-weight: 500;
  letter-spacing: 0;
}
.form-group small, .af-field-hint {
  display: block;
  margin-block-start: 6px;
  color: var(--af-ink-faint);
  font-size: var(--af-fs-sm);
  line-height: 1.45;
}
.af-field { margin-block-start: var(--af-sp-4); min-width: 0; }
.af-field:first-child { margin-block-start: 0; }
.af-form-grid { display: grid; gap: var(--af-sp-4); grid-template-columns: 1fr; }
@media (min-width: 480px) { .af-form-grid--pair { grid-template-columns: 1fr 1fr; } }

/* Error state keys off aria-invalid, never a class, so a11y and visuals can't drift. */
[aria-invalid="true"]:is(input, select, textarea, .af-input) {
  border-color: var(--af-danger);
  box-shadow: 0 0 0 1px var(--af-danger);
}
[aria-invalid="true"]:is(input, select, textarea, .af-input):focus {
  border-color: var(--af-danger);
  box-shadow: 0 0 0 2px var(--af-danger);
}
.af-field-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-block-start: 6px;
  color: var(--af-danger);
  font-size: var(--af-fs-sm);
  font-weight: 500;
}
.af-field-error::before {
  content: "!";
  flex: none;
  display: grid;
  place-items: center;
  width: 16px; height: 16px;
  margin-block-start: 2px;
  border-radius: 50%;
  background: var(--af-danger);
  color: var(--af-on-danger);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.af-field-error[hidden] { display: none; }
.af-error-summary {
  padding: var(--af-sp-4);
  border-radius: var(--af-r-md);
  background: var(--af-danger-soft);
  border: 1px solid color-mix(in srgb, var(--af-danger) 30%, transparent);
  color: var(--af-ink);
}
.af-error-summary a { color: var(--af-danger); font-weight: 500; }

/* Amount affix field */
.af-amount { position: relative; }
.af-amount > input { font-family: var(--af-font-display); font-variant-numeric: tabular-nums; padding-inline-end: 40px; }
.af-amount > .af-amount-cur { position: absolute; inset-inline-end: 14px; inset-block: 0; display: grid; place-items: center; color: var(--af-ink-faint); pointer-events: none; }

/* Search field */
.af-search {
  display: flex;
  align-items: center;
  gap: var(--af-sp-2);
  min-height: var(--af-control-h);
  padding-inline: var(--af-sp-4) var(--af-sp-1);
  border-radius: var(--af-r-pill);
  border: 1px solid var(--af-border-strong);
  background: var(--af-surface);
  color: var(--af-ink-faint);
}
.af-search input { border: 0; box-shadow: none; min-height: 44px; padding: 0; background: transparent; flex: 1; }
.af-search input:focus { box-shadow: none; }
.af-search:focus-within { border-color: var(--af-focus); box-shadow: 0 0 0 1px var(--af-focus); }

/* ---------------------------------------------------------------------------
   3. Card / stat tile / list row
   --------------------------------------------------------------------------- */
.af-card {
  background: var(--af-surface);
  border: 1px solid var(--af-border);
  border-radius: var(--af-r-lg);
  padding: var(--af-sp-4);
  box-shadow: none;
}
@media (min-width: 1024px) { .af-card { padding: var(--af-sp-5) var(--af-sp-6); } }
.af-card + .af-card { margin-block-start: var(--af-sp-4); }
.af-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--af-sp-3); margin-block-end: var(--af-sp-3); }
.af-card-title { font-size: var(--af-fs-lg); font-weight: 600; margin: 0; }
.af-card-link { display: inline-flex; align-items: center; min-height: 44px; padding-inline: var(--af-sp-2); color: var(--af-primary-text); font-weight: 500; font-size: var(--af-fs-sm); text-decoration: none; }

/* Existing generic .card picks up the flat Harbor card. */
.card {
  background: var(--af-surface);
  border: 1px solid var(--af-border);
  border-radius: var(--af-r-lg);
  box-shadow: none;
}

.af-tiles { display: grid; gap: var(--af-sp-3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); }
.af-tile {
  min-width: 0;
  padding: var(--af-sp-4);
  background: var(--af-surface);
  border: 1px solid var(--af-border);
  border-radius: var(--af-r-md);
  container-type: inline-size;
}
.af-tile-top { display: flex; align-items: center; gap: var(--af-sp-2); color: var(--af-ink-soft); font-size: var(--af-fs-sm); }
/* The value element may be a data-ssr-slot: it stays plain text, .money goes on it directly. */
.af-tile-value { display: block; margin-block-start: var(--af-sp-2); font-size: clamp(1rem, 15cqi, var(--af-fs-xl)); color: var(--af-ink); }
@media (min-width: 1024px) { .af-tile-value { font-size: clamp(1rem, 15cqi, var(--af-fs-2xl)); } }
.af-tile-caption { margin-block-start: var(--af-sp-1); color: var(--af-ink-faint); font-size: var(--af-fs-xs); }
[dir="rtl"] .af-tile-value { text-align: right; }
[dir="ltr"] .af-tile-value { text-align: left; }

.af-ichip { display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: var(--af-r-sm); background: var(--af-primary-soft); color: var(--af-primary-text); }
.af-ichip--income { background: var(--af-income-soft); color: var(--af-income); }
.af-ichip--expense { background: var(--af-expense-soft); color: var(--af-expense); }
.af-ichip--transfer { background: var(--af-transfer-soft); color: var(--af-transfer); }
.af-ichip--warning { background: var(--af-warning-soft); color: var(--af-warning); }

.af-hero {
  background: var(--af-hero-bg);
  color: var(--af-hero-ink);
  border-radius: var(--af-r-lg);
  padding: var(--af-sp-5);
}
.af-hero .af-hero-label { color: var(--af-hero-soft); font-size: var(--af-fs-sm); }
.af-hero .af-hero-value { display: block; font-size: var(--af-fs-money-hero); letter-spacing: -.02em; line-height: 1.1; }

.af-rows { list-style: none; margin: 0; padding: 0; background: var(--af-surface); border: 1px solid var(--af-border); border-radius: var(--af-r-lg); overflow: hidden; }
.af-row {
  display: flex;
  align-items: center;
  gap: var(--af-sp-3);
  min-height: var(--af-row-min-h);
  padding: var(--af-sp-3) var(--af-sp-4);
  color: var(--af-ink);
  text-decoration: none;
}
.af-row + .af-row { border-block-start: 1px solid var(--af-border); }
a.af-row:active, button.af-row:active { background: var(--af-surface-sunken); }
.af-row-icon { display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: var(--af-r-md); background: var(--af-surface-sunken); color: var(--af-ink-soft); }
.af-row-body { flex: 1; min-width: 0; }
.af-row-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.af-row-meta { font-size: var(--af-fs-sm); color: var(--af-ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.af-row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.af-row-group-head { display: flex; justify-content: space-between; padding-block: var(--af-sp-4) var(--af-sp-2); color: var(--af-ink-soft); font-size: var(--af-fs-sm); font-weight: 500; }

/* ---------------------------------------------------------------------------
   4. Chips, segmented control, tabs, badges
   --------------------------------------------------------------------------- */
.af-chips { display: flex; gap: var(--af-sp-2); overflow-x: auto; scrollbar-width: none; padding-block: var(--af-sp-1); }
.af-chips::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) { .af-chips { flex-wrap: wrap; overflow: visible; } }
.af-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-height: 36px;
  padding-inline: 14px;
  border-radius: var(--af-r-pill);
  border: 1px solid var(--af-border-strong);
  background: var(--af-surface);
  color: var(--af-ink);
  font: inherit;
  font-size: var(--af-fs-sm);
  font-weight: 500;
  cursor: pointer;
}
.af-chip::after { content: ""; position: absolute; inset: -5px 0; } /* 44px hit area: ::after sits inside the 1px border, so -5px (Q1-07) */
.af-chip[aria-pressed="true"], .af-chip[aria-selected="true"] { background: var(--af-ink); border-color: var(--af-ink); color: var(--af-bg); }

.af-seg {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--af-r-pill);
  background: var(--af-surface-sunken);
}
.af-seg-btn {
  min-height: 40px;
  padding-inline: var(--af-sp-3);
  border: 0;
  border-radius: var(--af-r-pill);
  background: transparent;
  color: var(--af-ink-soft);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.af-seg-btn[aria-checked="true"], .af-seg-btn[aria-pressed="true"], .af-seg-btn[aria-selected="true"] {
  background: var(--af-surface);
  color: var(--af-ink);
  font-weight: 600;
  box-shadow: var(--af-shadow-1);
}
.af-seg--sm .af-seg-btn { min-height: 36px; font-size: var(--af-fs-sm); }

.af-tabs { display: flex; gap: var(--af-sp-1); overflow-x: auto; scrollbar-width: none; border-block-end: 1px solid var(--af-border); scroll-snap-type: x proximity; }
.af-tabs::-webkit-scrollbar { display: none; }
.af-tab-btn {
  flex: none;
  min-height: 48px;
  padding-inline: var(--af-sp-4);
  border: 0;
  border-block-end: 2px solid transparent;
  background: transparent;
  color: var(--af-ink-soft);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  scroll-snap-align: start;
}
.af-tab-btn[aria-selected="true"] { color: var(--af-primary-text); border-block-end-color: var(--af-primary); font-weight: 600; }

.af-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding-inline: 8px;
  border-radius: var(--af-r-pill);
  background: var(--af-surface-sunken);
  color: var(--af-ink-soft);
  font-size: var(--af-fs-xs);
  font-weight: 500;
  white-space: nowrap;
}
.af-badge--primary { background: var(--af-primary-soft); color: var(--af-primary-text); }
.af-badge--success { background: var(--af-income-soft); color: var(--af-income); }
.af-badge--warning { background: var(--af-warning-soft); color: var(--af-warning); }
.af-badge--danger { background: var(--af-danger-soft); color: var(--af-danger); }
.af-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding-inline: 4px;
  border-radius: var(--af-r-pill);
  background: var(--af-danger);
  color: var(--af-on-danger);
  font-size: var(--af-fs-xs);
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 0 0 2px var(--af-surface);
}

/* ---------------------------------------------------------------------------
   5. Loading, empty, error states
   --------------------------------------------------------------------------- */
.af-skeleton {
  background: linear-gradient(90deg, var(--af-surface-sunken) 0%, var(--af-track) 50%, var(--af-surface-sunken) 100%);
  background-size: 200% 100%;
  animation: afShimmer 1.4s linear infinite;
  border-radius: var(--af-r-xs);
  color: transparent;
}
@keyframes afShimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .af-skeleton { animation: none; } }
:root[data-ac-motion="reduced"] .af-skeleton { animation: none; }
.af-skeleton--line { display: block; height: 12px; margin-block: 6px; }
.af-skeleton--row { display: block; height: var(--af-row-min-h); border-radius: var(--af-r-md); }

.af-empty { text-align: center; padding: var(--af-sp-7) var(--af-sp-5); }
.af-empty-art { display: inline-grid; place-items: center; width: 64px; height: 64px; margin-block-end: var(--af-sp-4); border-radius: var(--af-r-lg); background: var(--af-primary-soft); color: var(--af-primary-text); }
.af-empty-title { font-size: var(--af-fs-lg); font-weight: 600; margin: 0 0 var(--af-sp-2); }
.af-empty-text { max-width: 36ch; margin: 0 auto var(--af-sp-5); color: var(--af-ink-soft); font-size: var(--af-fs-sm); }

.af-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--af-sp-3);
  padding: var(--af-sp-4);
  border-radius: var(--af-r-md);
  background: var(--af-danger-soft);
  border: 1px solid color-mix(in srgb, var(--af-danger) 30%, transparent);
  color: var(--af-ink);
}
.af-alert--warning { background: var(--af-warning-soft); border-color: color-mix(in srgb, var(--af-warning) 30%, transparent); }
.af-alert--info { background: var(--af-info-soft); border-color: color-mix(in srgb, var(--af-info) 30%, transparent); }
.af-alert-title { font-weight: 600; }
.af-alert-text { margin: 2px 0 var(--af-sp-3); font-size: var(--af-fs-sm); color: var(--af-ink-soft); }

/* ---------------------------------------------------------------------------
   6. Dialogs and bottom sheets for the EXISTING modal containers
   ---------------------------------------------------------------------------
   No ID or open/close JS changes: the modal JS still toggles .active /
   style.display / .txn-modal-active. Phones (<768) get a bottom sheet (short
   forms) or a full-screen sheet (long forms: transaction modal, .modal-large);
   768+ get a centered dialog. The `body` prefix lifts specificity above the
   page sheets that load later in <body>.
   --------------------------------------------------------------------------- */
body .modal,
body .txn-modal,
body .deposit-modal,
body .loan-payment-modal,
body .delete-modal {
  background: var(--af-scrim);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  z-index: var(--af-z-sheet);
  overscroll-behavior: contain;
}

body .modal .modal-content,
body .txn-modal .txn-modal-content,
body .deposit-modal .deposit-modal-content,
body .loan-payment-modal .loan-payment-modal-content,
body .delete-modal .delete-modal-content {
  background: var(--af-surface-elev);
  color: var(--af-ink);
  border: 0;
  border-radius: var(--af-r-lg);
  box-shadow: var(--af-shadow-3);
  overscroll-behavior: contain;
  max-height: calc(100dvh - 48px);
}

body .modal .modal-header,
body .txn-modal .txn-modal-header {
  border-block-end: 1px solid var(--af-border);
  background: var(--af-surface-elev);
}
body .modal .modal-header h2,
body .modal .modal-header h3 { font-size: var(--af-fs-xl); font-weight: 600; }

/* 44px close buttons on every modal flavour */
body .modal .modal-close,
body .modal .close-modal,
body .modal .close,
body .txn-modal .txn-modal-close,
body .deposit-modal .deposit-modal-close,
body .loan-payment-modal .loan-payment-modal-close {
  width: var(--af-target-min);
  height: var(--af-target-min);
  min-width: var(--af-target-min);
  border-radius: var(--af-r-pill);
  border: 0;
  background: transparent;
  color: var(--af-ink);
  font-size: 24px;
  line-height: 1;
  display: inline-grid;
  place-items: center;
  padding: 0;
}
body .modal .modal-close:hover,
body .modal .close-modal:hover,
body .txn-modal .txn-modal-close:hover,
body .deposit-modal .deposit-modal-close:hover { background: var(--af-surface-sunken); }

body .modal .modal-footer {
  background: var(--af-surface-elev);
  border-block-start: 1px solid var(--af-border);
}

@media (max-width: 767.98px) {
  /* Bottom sheet */
  body .modal,
  body .deposit-modal,
  body .loan-payment-modal {
    align-items: flex-end !important;
    justify-content: stretch;
    padding: 0 !important;
  }
  body .modal .modal-content,
  body .deposit-modal .deposit-modal-content,
  body .loan-payment-modal .loan-payment-modal-content {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    max-height: calc(100dvh - var(--af-safe-top) - 24px);
    border-radius: var(--af-r-xl) var(--af-r-xl) 0 0;
    padding-block-end: var(--af-safe-bottom);
    overflow-y: auto;
    animation: afSheetIn var(--af-dur-slow) var(--af-ease) both;
  }
  /* Long forms → full-screen sheet */
  body .modal .modal-content.modal-large,
  body .txn-modal .txn-modal-content {
    width: 100% !important;
    max-width: none !important;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0 !important;
    border-radius: 0;
    padding-block-start: var(--af-safe-top);
    padding-block-end: var(--af-safe-bottom);
  }
  body .txn-modal { align-items: stretch !important; padding: 0 !important; }
  body .modal .modal-header,
  body .txn-modal .txn-modal-header {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  body .modal .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    padding-block-end: calc(var(--af-sp-3) + var(--af-safe-bottom));
  }
  body .modal .modal-footer .btn,
  body .modal .modal-actions .btn { flex: 1 1 auto; }
}
@keyframes afSheetIn { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  body .modal .modal-content, body .deposit-modal .deposit-modal-content, body .loan-payment-modal .loan-payment-modal-content { animation: none; }
}

/* Shared confirm dialog from notifications.js (showConfirm/showAlert) */
.confirm-modal-overlay { background: var(--af-scrim); z-index: var(--af-z-sheet); padding: var(--af-sp-4); }
.confirm-modal {
  background: var(--af-surface-elev);
  color: var(--af-ink);
  border-radius: var(--af-r-lg);
  box-shadow: var(--af-shadow-3);
  width: min(400px, 100%);
}
.confirm-modal-title { font-family: var(--af-font-display); font-weight: 600; color: var(--af-ink); }
.confirm-modal-message { color: var(--af-ink-soft); }
.confirm-modal-footer { background: transparent; }
.confirm-modal-btn { min-height: 44px; border-radius: var(--af-r-md); font-weight: 600; }
.confirm-modal-btn.cancel { background: var(--af-surface); color: var(--af-ink); border: 1px solid var(--af-border-strong); }
.confirm-modal-btn.confirm { background: var(--af-primary); color: var(--af-on-primary); border: 0; }
.confirm-modal-btn.confirm.danger,
.confirm-modal.danger .confirm-modal-btn.confirm { background: var(--af-danger); color: var(--af-on-danger); }

/* ---------------------------------------------------------------------------
   7. Shared sheet primitive (shell More sheet, future native <dialog> sheets)
   --------------------------------------------------------------------------- */
.af-sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--af-z-scrim);
  background: var(--af-scrim);
}
.af-sheet {
  position: fixed;
  z-index: var(--af-z-sheet);
  inset-inline: 0;
  inset-block-end: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - var(--af-safe-top) - 24px);
  background: var(--af-surface-elev);
  color: var(--af-ink);
  border-radius: var(--af-r-xl) var(--af-r-xl) 0 0;
  box-shadow: var(--af-shadow-3);
  overscroll-behavior: contain;
  animation: afSheetIn var(--af-dur-slow) var(--af-ease) both;
}
.af-sheet[hidden], .af-sheet-scrim[hidden] { display: none; }
.af-sheet-grabber { width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--af-border-strong); flex: none; }
.af-sheet-head { display: flex; align-items: center; gap: var(--af-sp-2); padding: var(--af-sp-2) var(--af-sp-4); padding-inline-end: var(--af-sp-2); flex: none; }
.af-sheet-title { flex: 1; margin: 0; font-size: var(--af-fs-xl); font-weight: 600; }
.af-sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 0 var(--af-sp-4) calc(var(--af-sp-4) + var(--af-safe-bottom)); }
.af-sheet-foot { flex: none; padding: var(--af-sp-3) var(--af-sp-4) calc(var(--af-sp-3) + var(--af-safe-bottom)); border-block-start: 1px solid var(--af-border); background: var(--af-surface-elev); }

/* Phase 5: swipe down to dismiss (js/ds/dialog.js). The drag starts only on
   the grabber (with a taller invisible hit area) or the .af-sheet-head;
   touch-action is limited to those handles so sheet bodies keep scrolling.
   No swipe under reduced motion (OS setting or AccessCore). */
@media (max-width: 767.98px) and (prefers-reduced-motion: no-preference) {
  html:not([data-ac-motion="reduced"]) .af-sheet-grabber { position: relative; touch-action: none; cursor: grab; }
  html:not([data-ac-motion="reduced"]) .af-sheet-grabber::before { content: ""; position: absolute; inset: -12px -56px -10px; }
  html:not([data-ac-motion="reduced"]) .af-sheet-head { touch-action: none; }
}

.af-kbd {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding-inline: 6px;
  border-radius: var(--af-r-xs);
  border: 1px solid var(--af-border);
  background: var(--af-surface-sunken);
  color: var(--af-ink-faint);
  font-family: var(--af-font-body);
  font-size: var(--af-fs-xs);
  direction: ltr;
  unicode-bidi: isolate;
}

/* Terms / Privacy acceptance checkbox (sign-up, family and accountant
   invitations; compliance audit 2026-11-18). The links sit inside the label and open in a new tab. */
.af-consent {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: var(--af-sp-3);
  align-items: start;
  margin-block-start: var(--af-sp-4);
  color: var(--af-ink);
  font-size: var(--af-fs-sm);
  line-height: 1.5;
}
.af-consent input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  cursor: pointer;
}
.af-consent label { cursor: pointer; min-height: 24px; }
.af-consent a { text-decoration: underline; }
.af-consent .af-field-error { grid-column: 1 / -1; }
.af-legal-notice a { text-decoration: underline; }
