/* =========================================================
   XCB design system — base, shell and components.
   One implementation of each pattern, shared by the client
   portal, provider pages and the admin back office.
   Colours come from tokens.css only. See /ds/README.md.
   ========================================================= */

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.ds {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-body); line-height: 1.5;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
/* Zero-specificity resets so every component rule wins over them */
:where(.ds) :where(button, select, input, textarea) { font: inherit; color: inherit; }
:where(.ds) :where(button) { cursor: pointer; }
:where(.ds) :where(button:disabled) { cursor: not-allowed; }
:where(.ds) :where(a) { color: inherit; }
:where(.ds) :where(h1, h2, h3, h4, p) { margin: 0; }
:where(.ds) :where(svg) { flex: none; }
.ds :focus-visible { outline: 2px solid var(--red-text); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.tnum { font-variant-numeric: tabular-nums; }
.up, .gain { color: var(--green-text); }
.down, .loss { color: var(--red-text); }
.warn-text, .dd { color: var(--warn); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-meta); color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 50;
  display: flex; flex-direction: column; gap: 24px;
  padding: 20px 14px; background: var(--panel); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; text-decoration: none; }
.logo { display: flex; flex-direction: column; line-height: 1; }
.logo-mark { font-size: 26px; font-weight: 800; letter-spacing: -0.04em; color: var(--text); }
.logo-mark span { color: var(--red); }
.logo-sub { font-size: 9px; font-weight: 800; letter-spacing: .08em; color: var(--text-2); margin-top: 2px; }
.brand-area { font-size: 12px; color: var(--muted); padding-left: 12px; border-left: 1px solid var(--line); }
/* Environment marker: staff must never confuse admin with the client portal */
.env-tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: var(--r-pill); background: var(--panel-3); border: 1px solid var(--line-strong); color: var(--text); font-size: 11px; font-weight: 800; }
.sidebar .sidebar-close { display: none; margin-left: auto; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 44px; padding: 0 12px; border-radius: 10px; border: 0; background: transparent;
  color: var(--text-2); font-size: 14px; font-weight: 600; text-decoration: none; text-align: left;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--red-soft); color: var(--text); }
.nav-item[aria-current="page"]::before,
.nav-sub a[aria-current="page"]::before { content: ""; position: absolute; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--red); }
.nav-item[aria-current="page"]::before { left: -14px; }
.nav-item.has-current { color: var(--text); }
.nav-item .chev { margin-left: auto; color: var(--muted); transition: transform .2s; }
.nav-item[aria-expanded="true"] .chev { transform: rotate(90deg); }
.nav-sub { display: flex; flex-direction: column; gap: 2px; padding: 2px 0 6px 36px; }
.nav-sub a { position: relative; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border-radius: 10px; color: var(--muted); font-size: 14px; font-weight: 600; text-decoration: none; }
.nav-sub a:hover { color: var(--text); background: var(--panel-2); }
.nav-sub a[aria-current="page"] { color: var(--text); background: var(--red-soft); }
.nav-sub a[aria-current="page"]::before { left: -12px; }
.nav-sub a .lock { margin-left: auto; font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.nav-sub a[aria-disabled="true"] { opacity: .6; }

.refer { margin-top: auto; padding: 16px; border-radius: var(--r-tile); background: var(--panel-2); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.refer strong { font-size: 14px; }
.refer p { font-size: 12px; color: var(--muted); line-height: 1.5; }
.refer a, .refer button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; border-radius: 10px; border: 1px solid var(--line-strong); background: transparent; font-size: 13px; font-weight: 700; text-decoration: none; }
.refer a:hover, .refer button:hover { border-color: var(--red-line); color: var(--red-text); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  min-height: 64px; padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.menu-btn { display: none !important; }
.topbar-title { font-size: 15px; font-weight: 800; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title span { color: var(--muted); font-weight: 600; }
.mobile-brand { display: none; text-decoration: none; }
.topbar-search { flex: 1; max-width: 420px; margin-right: auto; }

.acct { display: flex; align-items: center; height: 44px; border-radius: var(--r-control); border: 1px solid var(--line-strong); background: var(--panel); overflow: hidden; }
.acct-switch { position: relative; display: flex; align-items: center; gap: 8px; height: 100%; padding: 0 10px 0 12px; font-size: 13px; font-weight: 700; }
.acct-switch select { appearance: none; -webkit-appearance: none; border: 0; background: transparent; height: 100%; padding: 0 18px 0 0; font-size: 13px; font-weight: 700; cursor: pointer; }
.acct-switch select option { background: var(--panel); color: var(--text); }
.acct-switch svg { position: absolute; right: 10px; pointer-events: none; color: var(--muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.live-dot.demo { background: var(--warn); }
.acct-id { padding: 0 12px; height: 100%; display: flex; align-items: center; border-left: 1px solid var(--line); font-size: 12px; color: var(--muted); white-space: nowrap; }
.acct-bal { padding: 0 14px; height: 100%; display: flex; align-items: center; border-left: 1px solid var(--line); font-size: 14px; font-weight: 800; white-space: nowrap; }

.icon-btn {
  flex: none; position: relative; width: 44px; height: 44px; border-radius: var(--r-control);
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none; padding: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--muted); }
.icon-btn .count { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: var(--r-pill); background: var(--red); color: var(--on-fill); font-size: 10px; font-weight: 800; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg); }
.icon-btn .count:empty, .icon-btn .count[data-zero] { display: none; }
.text-btn { height: 44px; padding: 0 14px; border-radius: var(--r-control); border: 1px solid var(--line-strong); background: var(--panel); font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; white-space: nowrap; }
.text-btn:hover { border-color: var(--muted); }
.me { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--red); background: var(--red-soft); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; color: var(--text); padding: 0; }
/* Admin: neutral ring so the environment reads differently at a glance */
.is-admin .me { border-color: var(--text-2); background: var(--panel-3); }

.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 24px 24px 48px; display: flex; flex-direction: column; gap: var(--gap); }
.has-tray .content { padding-bottom: 120px; }
.scrim { display: none; }

/* Popover (notifications, profile) — anchored under a top-bar control */
.pop-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: min(340px, calc(100vw - 24px));
  max-height: 70vh; overflow-y: auto; padding: 8px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line-strong); box-shadow: var(--shadow);
}
.popover-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 10px; font-size: 14px; font-weight: 800; }
.pop-item { display: block; padding: 10px; border-radius: 10px; font-size: 13px; text-decoration: none; }
.pop-item + .pop-item { border-top: 1px solid var(--line); }
.pop-item strong { display: block; font-size: 13px; }
.pop-item p { color: var(--muted); font-size: 12px; margin-top: 2px; }
.pop-item small { color: var(--muted); font-size: 11px; }
.pop-item[data-read="false"] strong::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: var(--red); vertical-align: middle; }
a.pop-item:hover { background: var(--panel-2); }
.pop-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; font-size: 13px; }
.pop-row span { color: var(--muted); }

/* Mobile bottom navigation (client portal, < 1024px) */
.bottom-nav { display: none; }

/* ---------- Page head ---------- */
.page-head { padding: 24px 28px; display: flex; flex-wrap: wrap; gap: 20px; align-items: center; justify-content: space-between; }
.page-head h1 { font-size: var(--fs-page); font-weight: 800; letter-spacing: -0.025em; line-height: 1.15; }
.page-head p { margin-top: 4px; font-size: 14px; color: var(--muted); max-width: 70ch; line-height: 1.55; }
.page-status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { text-decoration: none; } .crumbs a:hover { color: var(--text); }
.clock { display: inline-flex; gap: 10px; font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.clock b { color: var(--text-2); font-weight: 700; }

/* ---------- Panel / card ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel); min-width: 0; }
.card { padding: var(--pad); display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: var(--fs-card); font-weight: 800; }
.card-head p { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card-head > :first-child { min-width: 0; }
.card-foot { margin-top: auto; }
.section-label { font-size: 13px; font-weight: 800; margin: 0 0 10px; }
.link { font-size: 13px; font-weight: 700; color: var(--red-text); text-decoration: none; white-space: nowrap; background: none; border: 0; padding: 0; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 0; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 16px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 700; text-align: right; overflow-wrap: anywhere; }

/* ---------- Planned grids ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); align-items: stretch; }
.grid.thirds { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.grid > .card, .grid > .panel { height: 100%; }
.grid .empty { flex: 1; justify-content: center; }

/* ---------- Pills, badges, tags ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r-pill); font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--panel-3); color: var(--text-2); }
.pill.ok { background: var(--green-soft); color: var(--green-text); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--red-soft); color: var(--red-text); }
.pill.sm { height: 24px; padding: 0 8px; font-size: 11px; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill .dot.pulse { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-pill); background: var(--gold-soft); border: 1px solid var(--gold-line); color: var(--gold); font-size: 11px; font-weight: 700; white-space: nowrap; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 4px 9px; border-radius: var(--r-pill); background: var(--panel-3); color: var(--text-2); font-size: 11px; font-weight: 700; }

/* ---------- Buttons ---------- */
.btn {
  height: 44px; padding: 0 18px; border-radius: var(--r-control); font-size: 14px; font-weight: 700; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  border: 1px solid transparent; background: transparent; color: var(--text); transition: background .15s, border-color .15s;
}
.btn-money { background: var(--green); color: var(--on-fill); font-weight: 800; }
.btn-money:hover { background: var(--green-hover); }
.btn-brand, .btn-danger { background: var(--red); color: var(--on-fill); font-weight: 800; }
.btn-brand:hover, .btn-danger:hover { background: var(--red-hover); }
.btn-ghost { border-color: var(--line-strong); background: transparent; color: var(--text); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-ghost.is-danger { color: var(--red-text); }
.btn-ghost.is-danger:hover { border-color: var(--red-line); }
.btn-sm { height: 40px; padding: 0 14px; font-size: 13px; }
.btn-xs { height: 32px; padding: 0 10px; font-size: 12px; border-radius: 10px; }
.btn-sq { width: 44px; padding: 0; }
.btn-sm.btn-sq { width: 40px; }
.btn-block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--track); border-color: transparent; color: var(--muted); }
.btn-ghost:disabled { background: transparent; border-color: var(--line); }
.btn[aria-pressed="true"].btn-toggle { border-color: var(--red-line); background: var(--red-soft); color: var(--red-text); }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); border-top-color: var(--text); animation: spin .8s linear infinite; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Forms ---------- */
.field { position: relative; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label, .field > span:first-child:not(.sr-only) { font-size: 13px; font-weight: 700; color: var(--text-2); }
.input, .field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), .field select, .field textarea, .select {
  width: 100%; min-height: 44px; border-radius: var(--r-control); border: 1px solid var(--line-strong);
  background: var(--panel-2); color: var(--text); font-size: 14px; font-weight: 500; padding: 0 12px;
}
.field textarea, textarea.input { min-height: 96px; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.field select, .select { font-weight: 600; appearance: auto; }
.field input::placeholder, .input::placeholder, .field textarea::placeholder { color: var(--muted); }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: none; border-color: var(--red-line); box-shadow: 0 0 0 3px var(--red-soft); }
.field input[type="file"] { font-size: 13px; padding: 10px; border: 1px dashed var(--line-strong); border-radius: var(--r-control); background: var(--panel-2); }
.field select.is-set { border-color: var(--red-line); }
.field.is-invalid input, .field.is-invalid select, .field.is-invalid textarea, [aria-invalid="true"] { border-color: var(--red-text) !important; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.field-error { font-size: 12px; color: var(--red-text); font-weight: 600; }
.search { position: relative; display: block; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { width: 100%; height: 44px; border-radius: var(--r-control); border: 1px solid var(--line-strong); background: var(--panel-2); color: var(--text); padding: 0 12px 0 38px; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full, .form-grid > .span-all { grid-column: 1 / -1; }
.form-grid.thirds { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.check { display: flex; align-items: flex-start; gap: 10px; min-height: 44px; padding: 10px 0; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--red); flex: none; }
/* Switch: a checkbox styled as a toggle; keeps native semantics */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-size: 14px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; flex: none; width: 42px; height: 24px; margin: 0; border-radius: var(--r-pill); background: var(--track); position: relative; transition: background .15s; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--on-fill); transition: transform .15s; }
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(18px); }
.form-message { padding: 12px 14px; border-radius: var(--r-control); font-size: 13px; font-weight: 600; line-height: 1.5; background: var(--panel-2); border: 1px solid var(--line); }
.form-message.success { background: var(--green-soft); border-color: var(--green-line); color: var(--green-text); }
.form-message.error { background: var(--red-soft); border-color: var(--red-line); color: var(--red-text); }
.form-message.info { color: var(--text-2); }

/* ---------- Chips, segmented, tabs ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 15px; border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: transparent; color: var(--text-2); font-size: 13px; font-weight: 600; white-space: nowrap; text-decoration: none; }
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"], .chip[aria-current="page"] { border-color: var(--red); background: var(--red); color: var(--on-fill); }
.chip .n { font-size: 11px; font-weight: 700; opacity: .75; }
.segmented, .tabs { display: inline-flex; flex-wrap: wrap; padding: 3px; border-radius: 11px; background: var(--panel-2); border: 1px solid var(--line); max-width: 100%; }
.segmented button, .tabs button, .tabs a { height: 34px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap; }
.segmented button[aria-pressed="true"], .tabs [aria-selected="true"], .tabs [aria-current="page"] { background: var(--panel-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.segmented button:hover, .tabs button:hover { color: var(--text); }
.reset { height: 40px; padding: 0 12px; border: 0; background: transparent; color: var(--red-text); font-size: 13px; font-weight: 700; }

/* Filter bar */
.filters { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.filter-row { display: grid; grid-template-columns: minmax(220px, 1.6fr) repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: end; }
.chip-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }

/* ---------- Data table ----------
   Real <table>. Below the breakpoint each row becomes a card that shows
   the same cells (labelled from data-label) and the same actions. */
.table-wrap { overflow-x: auto; border-radius: var(--r-panel); }
.dtable { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--row-fs); }
.dtable th, .dtable td { padding: 0 16px; height: var(--row-h); text-align: left; vertical-align: middle; border-top: 1px solid var(--line); }
.dtable thead th { position: sticky; top: 0; z-index: 1; height: 44px; background: var(--panel-2); border-top: 0; font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.dtable thead th:first-child { border-top-left-radius: var(--r-panel); }
.dtable thead th:last-child { border-top-right-radius: var(--r-panel); }
.dtable tbody tr { transition: background .15s; }
.dtable tbody tr:hover { background: var(--panel-2); }
.dtable tbody tr[aria-selected="true"], .dtable tbody tr.is-selected { background: var(--red-soft); }
.dtable td { padding-top: 10px; padding-bottom: 10px; }
.dtable .num, .dtable th.num { text-align: right; white-space: nowrap; }
.dtable .actions-cell { text-align: right; white-space: nowrap; }
.dtable .actions-cell .btn-row { justify-content: flex-end; flex-wrap: nowrap; }
.dtable .sel { width: 44px; padding-right: 0; }
.dtable .sel input, .dtable .sel-all { width: 18px; height: 18px; margin: 0; accent-color: var(--red); cursor: pointer; }
.cell-main { font-weight: 700; }
.dtable code, .dtable pre { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; font-size: 12px; }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.sort-h { background: none; border: 0; padding: 6px 0; font-size: inherit; font-weight: inherit; color: var(--muted); text-align: left; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.sort-h:hover { color: var(--text-2); }
th[aria-sort] .sort-h { color: var(--text); }
th[aria-sort="ascending"] .sort-h::after { content: "↑"; }
th[aria-sort="descending"] .sort-h::after { content: "↓"; }
/* Compact density for operators: 40px rows, 13px text. Primary buttons stay 44px. */
.density-compact { --row-h: 40px; --row-fs: 13px; }
.density-compact .dtable td { padding-top: 6px; padding-bottom: 6px; }
.density-compact .dtable .btn-sm { height: 32px; padding: 0 10px; font-size: 12px; }
.table-foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 16px; border-top: 1px solid var(--line); }
.table-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.table-toolbar .search { flex: 1; min-width: 200px; max-width: 380px; }

/* Card grid view of records */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }

/* Pagination */
.foot { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.foot-text { font-size: 13px; color: var(--muted); }
.foot-text b { color: var(--text); }
.pager { display: flex; gap: 6px; flex-wrap: wrap; }
.pager button, .pager a { min-width: 40px; height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line-strong); background: transparent; color: var(--text-2); font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.pager [aria-current="page"] { background: var(--red); border-color: var(--red); color: var(--on-fill); }
.pager button:disabled { opacity: .35; }

/* ---------- Stats, metrics, meters ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat-grid.fours { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 12px 14px; border-radius: var(--r-control); background: var(--panel-2); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat b { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.stat small { font-size: 11px; color: var(--muted); }
/* Stat strip: tiles divided by hairlines inside one panel */
.strip { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr)); }
.strip .stat { background: none; border-radius: 0; padding: 18px 20px; border-right: 1px solid var(--line); }
.strip .stat:last-child { border-right: 0; }
.metrics { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; padding: 12px; border-radius: var(--r-tile); background: var(--panel-2); }
.metric { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.metric + .metric { padding-left: 10px; margin-left: 10px; border-left: 1px solid var(--line); }
.m-label { font-size: 11px; color: var(--muted); font-weight: 600; }
.m-value { font-size: 15px; font-weight: 800; white-space: nowrap; }
.m-value.roi { font-size: 20px; line-height: 1.1; color: var(--green-text); }
.meter { display: flex; gap: 2px; }
.meter span { width: 8px; height: 14px; border-radius: 2px; background: var(--track); }
.meter .on-low { background: var(--green-text); } .meter .on-mod { background: var(--warn); } .meter .on-high { background: var(--red-text); }
.risk { display: flex; align-items: center; gap: 10px; }
.risk-text { font-size: 12px; color: var(--text-2); }
.risk-text b { font-weight: 800; }
.bar { height: 4px; border-radius: 2px; background: var(--track); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--text-2); border-radius: 2px; }
.bar.money > span { background: var(--green); }
.spark { display: block; width: 100%; height: 56px; }
.ring { position: relative; width: 64px; height: 64px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring > span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; }
.chart-box { position: relative; width: 100%; min-height: 220px; }

/* ---------- Identity: animated avatar ---------- */
.avatar {
  --size: 50px; position: relative; flex: none; width: var(--size); height: var(--size); border-radius: 50%;
  display: block; text-decoration: none; perspective: 400px; border: 0; padding: 0; background: none;
}
.avatar.sm { --size: 40px; } .avatar.lg { --size: 72px; }
.avatar-ring { position: absolute; inset: -3px; border-radius: 50%; opacity: 0; transition: opacity .3s; background: conic-gradient(from 0deg, var(--red) 0deg, var(--red-text) 70deg, transparent 140deg, transparent 220deg, var(--red) 360deg); }
.avatar.is-top .avatar-ring, .row-hover:hover .avatar-ring, tr:hover .avatar-ring, .card:hover .avatar-ring, .avatar:focus-visible .avatar-ring { opacity: 1; animation: spin 3.2s linear infinite; }
.avatar-flip { position: absolute; inset: 0; border-radius: 50%; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2, .7, .2, 1); }
.avatar:hover .avatar-flip, .avatar:focus-visible .avatar-flip, tr:hover .avatar-flip { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; border-radius: 50%; backface-visibility: hidden; display: flex; align-items: center; justify-content: center; background: var(--face); border: 2px solid var(--panel); }
.face-front { font-size: calc(var(--size) * .31); font-weight: 800; color: var(--on-fill); letter-spacing: .02em; }
.face-front span { display: inline-block; }
.intro .face-front span { animation: rise .55s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--d) * 1ms); }
.face-back { transform: rotateY(180deg); background: var(--red); color: var(--on-fill); }
.flag-dot { position: absolute; right: -2px; bottom: -2px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--panel); overflow: hidden; background: var(--panel-3); display: flex; align-items: center; justify-content: center; color: var(--text-2); }
.avatar.lg .flag-dot { width: 26px; height: 26px; }
.flag-dot img { width: 100%; height: 100%; object-fit: cover; }
.flag { width: 17px; height: 12px; border-radius: 2px; object-fit: cover; vertical-align: -1px; }
.initials { flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--face); color: var(--on-fill); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; }
.who { display: flex; gap: 12px; align-items: center; min-width: 0; }
.who-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.name { font-size: 15px; font-weight: 800; text-decoration: none; background: none; border: 0; padding: 0; text-align: left; color: var(--text); }
button.name:hover, a.name:hover { text-decoration: underline; text-underline-offset: 3px; }
.meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.meta b { color: var(--text); font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Overlays ---------- */
dialog.sheet {
  margin: 0 0 0 auto; height: 100%; max-height: 100%; width: min(560px, 100%); max-width: 100%;
  padding: 0; border: 0; border-left: 1px solid var(--line); background: var(--panel); color: var(--text);
}
dialog.sheet.wide { width: min(880px, 100%); }
dialog.sheet[open] { animation: sheet-in .28s cubic-bezier(.2, .8, .2, 1); }
dialog.sheet::backdrop, dialog.dialog::backdrop { background: var(--overlay); }
@keyframes sheet-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-inner { display: flex; flex-direction: column; height: 100%; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 16px; font-weight: 800; }
.sheet-body { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 20px; }
.sheet-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); }
.sheet-foot .grow { flex: 1; }

/* Centred dialog — confirmations and short forms */
dialog.dialog { width: min(520px, calc(100% - 24px)); max-height: calc(100% - 48px); padding: 0; border: 1px solid var(--line-strong); border-radius: var(--r-panel); background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
dialog.dialog.wide { width: min(760px, calc(100% - 24px)); }
dialog.dialog[open] { animation: dialog-in .2s cubic-bezier(.2, .8, .2, 1); }
@keyframes dialog-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog form, .dialog-inner { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 16px; font-weight: 800; }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; font-size: 14px; line-height: 1.55; }
.dialog-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.effect { padding: 12px 14px; border-radius: var(--r-control); background: var(--panel-2); border: 1px solid var(--line); }
.effect dl { margin: 0; }

/* Selection / compare tray */
.tray {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px)); width: min(720px, calc(100% - 24px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 10px 10px 16px; border-radius: 16px; background: var(--panel-2);
  border: 1px solid var(--line-strong); box-shadow: var(--shadow);
}
.tray-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tray-avatars { display: flex; }
.tray-avatars span { width: 34px; height: 34px; margin-right: -8px; border-radius: 50%; background: var(--face); border: 2px solid var(--panel-2); color: var(--on-fill); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; }
.tray-text { font-size: 13px; color: var(--text-2); padding-left: 10px; }
.tray-text b { color: var(--text); }
.tray-right { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

/* Toast */
.toast { position: fixed; z-index: 1000; left: 50%; top: 80px; transform: translate(-50%, -8px); opacity: 0; pointer-events: none; max-width: calc(100% - 24px); padding: 12px 16px; border-radius: var(--r-control); background: var(--text); color: var(--bg); font-size: 14px; font-weight: 700; box-shadow: var(--shadow); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--red); color: var(--on-fill); }
.toast.ok { background: var(--green); color: var(--on-fill); }

/* ---------- Feedback states ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 28px 16px; border-radius: var(--r-tile); background: var(--panel-2); border: 1px dashed var(--line-strong); }
.empty-icon { width: 44px; height: 44px; border-radius: var(--r-control); background: var(--panel-3); color: var(--muted); display: flex; align-items: center; justify-content: center; }
.empty strong { font-size: 15px; }
.empty p { font-size: 13px; color: var(--muted); max-width: 46ch; line-height: 1.5; }
.empty .btn-row { justify-content: center; margin-top: 4px; }
.inline-error { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: var(--r-tile); background: var(--red-soft); border: 1px solid var(--red-line); color: var(--text); font-size: 13px; line-height: 1.5; }
.inline-error svg { color: var(--red-text); margin-top: 1px; }
.inline-error strong { display: block; font-size: 14px; }
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-control); background: var(--panel-2); color: var(--text-2); font-size: 13px; font-weight: 600; line-height: 1.5; }
.callout.ok { background: var(--green-soft); color: var(--green-text); }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
.callout.bad { background: var(--red-soft); color: var(--red-text); }
.sk { position: relative; overflow: hidden; border-radius: 8px; background: var(--panel-3); }
.sk::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 6%, transparent), transparent); animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.sk-line { height: 12px; } .sk-title { height: 18px; width: 40%; } .sk-num { height: 28px; width: 60%; }
.sk-block { height: 120px; border-radius: var(--r-tile); }
.sk-row { height: 44px; border-radius: 10px; }
.sk-card { padding: var(--pad); display: flex; flex-direction: column; gap: 12px; }

/* ---------- Account states ---------- */
.steps { display: flex; flex-direction: column; gap: 8px; list-style: none; margin: 0; padding: 0; }
.step { display: flex; align-items: center; gap: 14px; padding: 12px 12px 12px 14px; border-radius: var(--r-tile); background: var(--panel-2); border: 1px solid var(--line); }
.step.next { border-color: var(--red-line); }
.step-num { flex: none; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line-strong); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; color: var(--muted); }
.step.next .step-num { border-color: var(--red); color: var(--red-text); }
.step.done .step-num { border-color: var(--green); background: var(--green); color: var(--on-fill); }
.step.pending .step-num { border-color: var(--warn); color: var(--warn); }
.step-body { flex: 1; min-width: 0; }
.step-body strong { display: block; font-size: 14px; }
.step-body span { font-size: 12px; color: var(--muted); }
.perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.perm { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: var(--r-tile); background: var(--panel-2); border: 1px solid var(--line); }
.perm-icon { flex: none; width: 32px; height: 32px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.perm.on .perm-icon { background: var(--green-soft); color: var(--green-text); }
.perm.off .perm-icon { background: var(--panel-3); color: var(--muted); }
.perm strong { display: block; font-size: 13px; }
.perm span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.45; }
.perm.on span { color: var(--green-text); font-weight: 700; }
.alerts { display: flex; flex-direction: column; gap: 8px; list-style: none; margin: 0; padding: 0; }
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: var(--r-tile); background: var(--panel-2); border: 1px solid var(--line); }
.alert-icon { flex: none; width: 32px; height: 32px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--panel-3); color: var(--text-2); }
.alert.warn .alert-icon { background: var(--warn-soft); color: var(--warn); }
.alert.bad .alert-icon { background: var(--red-soft); color: var(--red-text); }
.alert.ok .alert-icon { background: var(--green-soft); color: var(--green-text); }
.alert-body { flex: 1; min-width: 0; }
.alert-body strong { display: block; font-size: 14px; }
.alert-body p { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.alert-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.alert-meta span { font-size: 11px; color: var(--muted); font-weight: 600; }

/* Audit trail / timeline */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { position: relative; padding: 0 0 16px 22px; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.timeline li::after { content: ""; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.ok::before { background: var(--green-text); } .timeline li.bad::before { background: var(--red-text); } .timeline li.warn::before { background: var(--warn); }
.timeline strong { display: block; font-size: 13px; }
.timeline span { color: var(--muted); font-size: 12px; }

/* List rows (activity, quotes, picks) */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-top: 1px solid var(--line); min-width: 0; text-decoration: none; }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow > * { display: block; }
.cell-sub { display: block; }
.list-row .end { text-align: right; display: flex; flex-direction: column; gap: 2px; white-space: nowrap; }
.tile-link { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--r-tile); background: var(--panel-2); border: 1px solid var(--line); text-decoration: none; }
.tile-link:hover { border-color: var(--line-strong); }
.tile-list { display: flex; flex-direction: column; gap: 8px; }
.option { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--r-tile); background: var(--panel-2); border: 1px solid var(--line); text-align: left; width: 100%; color: var(--text); text-decoration: none; }
.option:hover { border-color: var(--line-strong); }
.option[aria-pressed="true"], .option.is-selected { border-color: var(--red-line); background: var(--red-soft); }
.option.is-disabled { opacity: .55; cursor: not-allowed; }
.option:has(input:focus-visible) { outline: 2px solid var(--red-text); outline-offset: 2px; }
label.option { cursor: pointer; }
.option-icon { flex: none; width: 40px; height: 40px; border-radius: var(--r-control); background: var(--panel-3); color: var(--text-2); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.option-icon img { width: 26px; height: 26px; object-fit: contain; }
/* Payment brand marks (provider logos keep their own colours) */
.funding-icon { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.funding-icon svg { width: 36px; height: auto; display: block; }
.funding-icon-hero svg { width: 48px; }

/* Shortcuts */
.shortcuts { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 10px; }
.shortcut { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 88px; padding: 12px 6px; border-radius: var(--r-tile); background: var(--panel-2); border: 1px solid var(--line); text-decoration: none; text-align: center; font-size: 12px; font-weight: 700; color: var(--text-2); }
.shortcut:hover { border-color: var(--red-line); color: var(--text); }
.shortcut svg { color: var(--red-text); }

/* Chat */
.chat-log { display: flex; flex-direction: column; gap: 10px; min-height: 240px; max-height: 52vh; overflow-y: auto; padding: 4px; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 16px; background: var(--panel-2); border: 1px solid var(--line); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.bubble.mine { align-self: flex-end; background: var(--red-soft); border-color: var(--red-line); }
.bubble small { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }

/* ---------- Notice + legal ---------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; border-radius: var(--r-tile); background: var(--panel); border: 1px solid var(--line); font-size: 13px; color: var(--text-2); line-height: 1.55; }
.notice svg { color: var(--warn); margin-top: 1px; }
.legal { padding: 28px 24px 40px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); line-height: 1.6; }
.legal-inner { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.legal-inner p { margin: 0; }
.legal a { color: var(--text-2); }
.has-tray .legal { padding-bottom: 120px; }

/* ---------- Auth layout (login, register…) ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; }
.auth-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; }
.auth-main { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px 48px; }
.auth-card { width: min(480px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.auth-card.wide { width: min(720px, 100%); }
.auth-card h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.auth-card > p, .auth-card .lead { color: var(--muted); font-size: 14px; line-height: 1.55; }
.auth-alt { font-size: 13px; color: var(--muted); text-align: center; }
.auth-alt a { color: var(--red-text); font-weight: 700; text-decoration: none; }

/* ---------- Long-form documents (legal pages) ---------- */
.doc { width: min(860px, 100%); padding: 40px; line-height: 1.7; }
.doc h1 { font-size: var(--fs-page); font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; margin: 6px 0 8px; }
.doc h2 { font-size: 18px; font-weight: 800; margin: 28px 0 8px; }
.doc p, .doc li { color: var(--text-2); font-size: 15px; max-width: 72ch; }
.doc p + p { margin-top: 10px; }
.doc .section-kicker { font-size: 12px; font-weight: 700; color: var(--red-text); }
.doc .doc-updated { color: var(--muted); font-size: 13px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.doc a { color: var(--red-text); }
@media (max-width: 720px) { .doc { padding: 22px; } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .shortcuts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.thirds { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strip { --cols: 2 !important; }
  .strip .stat:nth-child(2n) { border-right: 0; }
  .strip .stat { border-bottom: 1px solid var(--line); }
}
@media (max-width: 1023px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; height: 100%; transform: translateX(-100%); transition: transform .25s ease; visibility: hidden; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); visibility: visible; }
  .sidebar .sidebar-close { display: inline-flex; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: var(--overlay); opacity: 0; pointer-events: none; transition: opacity .2s; }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex !important; }
  .topbar-title { display: none; }
  .mobile-brand { display: flex; margin-right: auto; align-items: center; gap: 8px; }
  .mobile-brand .logo-mark { font-size: 22px; }
  .topbar-search { display: none; }
  .hide-md { display: none !important; }
  body.drawer-open { overflow: hidden; }
  /* Client bottom navigation */
  .has-bottom-nav .content { padding-bottom: 96px; }
  .has-bottom-nav .legal { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .has-bottom-nav .tray { bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; z-index: 25; left: 0; right: 0; bottom: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); background: color-mix(in srgb, var(--panel) 94%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  }
  .bottom-nav a, .bottom-nav button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; text-decoration: none; }
  .bottom-nav [aria-current="page"] { color: var(--text); }
  .bottom-nav [aria-current="page"]::before { content: ""; position: absolute; top: 0; width: 24px; height: 3px; border-radius: 3px; background: var(--red); }
  .bottom-nav [aria-current="page"] svg { color: var(--red-text); }
}
/* Below 900px: one centred column of equal-width cards, in priority order */
@media (max-width: 899px) {
  .content { max-width: 640px; }
  .grid, .grid.thirds { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .span-2 { grid-column: auto; }
  .grid > .card, .grid > .panel { height: auto; }
  .form-grid, .form-grid.thirds { grid-template-columns: minmax(0, 1fr); }
  .stat-grid.fours { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Wide tables become cards with the same data and actions */
  .dtable.stack-sm thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .dtable.stack-sm, .dtable.stack-sm tbody, .dtable.stack-sm tr, .dtable.stack-sm td { display: block; width: 100%; }
  .dtable.stack-sm tbody tr { padding: 12px 16px; border-top: 1px solid var(--line); }
  .dtable.stack-sm tbody tr:first-child { border-top: 0; }
  .dtable.stack-sm td { height: auto; border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; min-width: 0; overflow-wrap: anywhere; }
  .dtable.stack-sm td > * { min-width: 0; }
  .dtable.stack-sm td::before { content: attr(data-label); flex: none; font-size: 12px; color: var(--muted); font-weight: 600; text-align: left; }
  .dtable.stack-sm td[data-label=""]::before, .dtable.stack-sm td:not([data-label])::before { display: none; }
  .dtable.stack-sm td.cell-lead { display: block; text-align: left; padding-bottom: 8px; }
  .dtable.stack-sm td.cell-lead::before { display: none; }
  .dtable.stack-sm td.sel { position: absolute; right: 12px; width: auto; }
  .dtable.stack-sm tbody tr { position: relative; }
  .dtable.stack-sm td.actions-cell { display: block; padding-top: 10px; }
  .dtable.stack-sm td.actions-cell::before { display: none; }
  .dtable.stack-sm td.actions-cell .btn-row { justify-content: stretch; flex-wrap: wrap; }
  .dtable.stack-sm td.actions-cell .btn-row > * { flex: 1; }
  .table-wrap.stack-wrap { overflow: visible; }
}
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); gap: 8px; }
  .content { padding: 16px 14px 40px; }
  .hide-sm { display: none !important; }
  .page-head { padding: 20px; }
  .page-head h1 { font-size: 24px; }
  .page-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .page-actions > :only-child { grid-column: 1 / -1; }
  .page-actions .btn { white-space: normal; min-width: 0; line-height: 1.2; text-align: center; }
  .btn-row .btn { white-space: normal; line-height: 1.2; }
  .perm-grid { grid-template-columns: minmax(0, 1fr); }
  .step { flex-wrap: wrap; row-gap: 10px; }
  .step-body { flex: 1 1 calc(100% - 42px); }
  .step .btn, .step .pill { margin-left: 42px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabs, .segmented.fill { width: 100%; }
  .tabs button, .tabs a, .segmented.fill button { flex: 1; padding: 0 6px; }
  .shortcut { min-height: 80px; font-size: 11px; }
  .filters { padding: 14px; }
  .filter-row { grid-template-columns: minmax(0, 1fr); }
  .chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -14px; padding: 0 14px; scrollbar-width: none; width: calc(100% + 28px); }
  .chips.scroll::-webkit-scrollbar { display: none; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .metrics { padding: 10px; }
  .metric + .metric { padding-left: 8px; margin-left: 8px; }
  .m-value { font-size: 14px; } .m-value.roi { font-size: 18px; }
  .foot { flex-direction: column-reverse; align-items: stretch; }
  .tray-text .long { display: none; }
  .legal { padding: 24px 16px 40px; }
  .auth-card { padding: 20px; }
  .auth-top { padding: 12px 16px; }
  .dialog-foot .btn { flex: 1; }
  .strip { --cols: 2 !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .avatar:hover .avatar-flip, tr:hover .avatar-flip, .avatar:focus-visible .avatar-flip { transform: none; }
}

/* Legacy toggle state used by order tickets (class kept for app.js) */
.segmented button.active { background: var(--panel-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.segmented [data-ticket-side="buy"].active { color: var(--green-text); }
.segmented [data-ticket-side="sell"].active { color: var(--red-text); }

/* Deposit details remain readable while payment confirmation is pending. */
.crypto-payment-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 16px;
  text-align: center;
  color: var(--text);
}
.crypto-payment-box[hidden] { display: none; }
.crypto-payment-box img { width: 180px; height: 180px; max-width: 100%; border-radius: 10px; background: #fff; padding: 8px; }
.crypto-payment-box code { display: block; width: 100%; overflow-wrap: anywhere; word-break: break-all; user-select: all; font-size: 13px; line-height: 1.6; }
.crypto-payment-box [data-crypto-countdown] { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.crypto-payment-box small { line-height: 1.6; color: var(--muted); }
[data-funding-modal] .form-grid[hidden], [data-funding-modal] label[hidden] { display: none; }
