/* Arvis dashboard: tokens, layout, top bar, shared components, tables, phone layout. Page rules live in pages/<page>.css */
:root {
  color-scheme: dark;
  --bg: #0e0f11;
  --surface: #16181b;
  --surface-2: #1d2024;
  --surface-3: #24282d;
  --border: #2a2e33;
  --text: #e6e8eb;
  --muted: #8b9098;
  --faint: #5d626a;
  --accent: #8ab4ff;
  --pos: #3ecf8e;
  --neg: #f0616d;
  --warn: #e8b04b;
  --radius: 12px;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --top-h: 56px;
  --page-max: 1400px;
  /* chart marks: validated (dataviz validate_palette, dark, on --surface) */
  --viz-1: #3987e5;
  --viz-1-hi: #6da7ec;
  --viz-2: #199e70;
  --viz-2-hi: #2fc08c;
  --viz-grid: #23272c;
  --viz-base: #343940;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(1100px 520px at 85% -12%, #191c22 0%, transparent 60%) fixed, var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
::selection { background: rgba(138, 180, 255, .3); }

/* ---------- layout: top bar ---------- */
#app { min-height: 100dvh; }
.topbar { position: sticky; top: 0; z-index: 30; }
/* blur on a pseudo element: backdrop-filter on .topbar itself would trap the phones' fixed tab bar inside it */
.topbar::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: rgba(14, 15, 17, .74);
  backdrop-filter: blur(14px) saturate(140%); -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid rgba(42, 46, 51, .75);
}
.topbar-in {
  display: flex; align-items: center; gap: 22px;
  max-width: var(--page-max); height: var(--top-h); margin: 0 auto; padding: 0 32px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; font-weight: 600; font-size: 15px; border-radius: 8px; }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
#nav { position: relative; display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; }
#nav a {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px; border-radius: 8px;
  color: var(--muted); font-size: 13.5px; font-weight: 500; white-space: nowrap;
  transition: background .15s, color .15s;
}
#nav a .ico { width: 17px; height: 17px; transition: color .2s; }
#nav a:hover { background: rgba(255, 255, 255, .035); color: var(--text); }
#nav a.active { color: var(--text); background: transparent; }
#nav a.active .ico { color: var(--accent); }
#nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
/* the pill that slides to the active link (main.js moveInk), with a short accent line on the bar's bottom edge */
.nav-ink {
  position: absolute; left: 0; top: 50%; width: 0; height: 36px; margin-top: -18px;
  border-radius: 8px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border);
  opacity: 0; pointer-events: none;
  transition: transform .34s var(--ease), width .34s var(--ease), opacity .2s;
}
.nav-ink::after {
  content: ""; position: absolute; left: 14px; right: 14px; bottom: calc((36px - var(--top-h)) / 2);
  height: 2px; border-radius: 2px 2px 0 0; background: var(--accent); box-shadow: 0 0 12px rgba(138, 180, 255, .45);
}
.nav-ink.on { opacity: 1; }
.nav-ink.instant { transition: none; }
#nav .short, .nav-more { display: none; }
.profile { display: flex; align-items: center; gap: 10px; flex: none; margin-left: auto; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--muted); font-weight: 600; font-size: 13px;
  object-fit: cover;
}
.profile .who { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#view { max-width: var(--page-max); margin: 0 auto; padding: 30px 32px 64px; }

/* narrower desktops: short labels, then icons only */
@media (max-width: 1180px) {
  #nav .long, .profile .who { display: none; }
  #nav .short { display: inline; }
}
@media (max-width: 1000px) {
  .topbar-in { gap: 14px; padding: 0 20px; }
  #view { padding: 26px 20px 56px; }
  #nav .short { display: none; }
  #nav a { padding: 0 11px; }
}

/* ---------- page ---------- */
.page { animation: page-in .18s var(--ease) both; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section { margin-top: 28px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-title h2 { color: var(--text); }
.section-title .note { color: var(--muted); font-size: 12.5px; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); } /* auto-fit: a short row stretches across the full width */
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 0;
}
/* clip, not hidden: hidden would make the card a scroll container and stop sticky table headers */
.card.flush { padding: 0; overflow: hidden; overflow: clip; }
.card.flush > .card-head { padding: 16px 20px 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head .note { color: var(--muted); font-size: 12.5px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.num { font-variant-numeric: tabular-nums; }
.hint { color: var(--faint); font-size: 12px; margin-top: 8px; }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 12px 0 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.rise { animation: rise .34s var(--ease) both; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  transition: background .15s;
}
.row:first-child { border-top: 0; }
.row:hover { background: rgba(255, 255, 255, .015); }
.row .main { flex: 1; min-width: 0; }
.row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row .end .meta { text-align: right; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }

/* ---------- tables (core.js dataTable) ---------- */
.dt { transition: opacity .2s; }
.dt.stale { opacity: .5; pointer-events: none; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
th { color: var(--muted); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--border); user-select: none; }
th.sortable { cursor: pointer; transition: color .15s; }
th.sortable:hover, th.sorted { color: var(--text); }
th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; border-radius: 6px; }
th .arrow { display: inline-block; margin-left: 5px; opacity: 0; transition: opacity .15s, transform .22s var(--ease); }
th.sortable:hover .arrow { opacity: .4; }
th.sorted .arrow { opacity: .9; }
th.asc .arrow { transform: rotate(180deg); }
td { border-top: 1px solid rgba(42, 46, 51, .6); font-variant-numeric: tabular-nums; }
tbody tr:first-child td { border-top: 0; }
tbody tr { transition: background .15s; animation: fade .25s ease-out both; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }
th.mono { font-family: inherit; font-size: 12px; }
th.num, td.num { text-align: right; }
td.item { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.fit td.item { width: 100%; max-width: 0; min-width: 180px; } /* wide tables: item takes the leftover width and ellipsizes */
td .small { display: block; color: var(--muted); font-size: 12px; }
td .roi { font-weight: 500; }
/* group header row (dataTable groupBy): label left, summary right. Not sticky: only the column header is */
.dt-group th { position: static; padding-top: 7px; padding-bottom: 7px; background: rgba(255, 255, 255, .025); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); box-shadow: none; }
.dt-group:first-child th { border-top: 0; }
.dt-group + tr td { border-top: 0; }
.dt-group-in { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.dt-group-in > :first-child { color: var(--text); }
/* filterSort(): invisible on desktop, its children lay out in the parent */
.fs, .fs-body { display: contents; }
.fs .fs-btn { display: none; }
.skel-tr td .skel { height: 12px; width: 64%; }
.skel-tr td.item .skel { width: 82%; }
.skel-tr:nth-child(3n+2) td.item .skel { width: 58%; }
.skel-tr td.num .skel { margin-left: auto; width: 52%; }
.skel-tr:hover { background: transparent; }
.dt-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums;
  overflow-anchor: none; /* appended rows never scroll the page to follow the button */
}
/* sticky header row where the table needs no sideways scroll (a scroll container would stop it sticking) */
@media (min-width: 1181px) {
  .table-wrap { overflow: visible; }
  th { position: sticky; top: var(--top-h); z-index: 2; background: var(--surface); border-bottom: 0; box-shadow: inset 0 -1px 0 var(--border); }
}

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); align-items: center; }
.toolbar .grow { flex: 1 1 220px; }

/* ---------- controls ---------- */
input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(138, 180, 255, .15); }
input[type="date"] { color-scheme: dark; }
textarea { width: 100%; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
label.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12.5px; }
.search { position: relative; display: flex; align-items: center; }
.search .ico { position: absolute; left: 11px; color: var(--faint); pointer-events: none; }
.search input { padding-left: 34px; width: 100%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: 500 13.5px/1.3 inherit;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .08s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: #0d1220; }
.btn.primary:hover { background: #a1c3ff; }
.btn.danger { background: rgba(240, 97, 109, .1); border-color: rgba(240, 97, 109, .3); color: var(--neg); }
.btn.danger:hover { background: rgba(240, 97, 109, .18); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.busy::before {
  content: ""; width: 13px; height: 13px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 8px;
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s, transform .08s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.danger:hover { color: var(--neg); }

.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ico.sm { width: 14px; height: 14px; }

/* segmented control (core.js segmented) */
.seg {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 3px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border);
}
.seg button {
  position: relative; z-index: 1; min-width: 78px; padding: 6px 14px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 500; line-height: 1.3; cursor: pointer;
  transition: color .2s; -webkit-tap-highlight-color: transparent;
}
.seg button:hover, .seg button[aria-pressed="true"] { color: var(--text); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / 3);
  border-radius: 7px; background: var(--surface-3); box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
  transition: transform .28s var(--ease);
}

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 1px 9px; border-radius: 999px;
  font-size: 12px; line-height: 20px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}
.chip.pos { color: var(--pos); background: rgba(62, 207, 142, .08); border-color: rgba(62, 207, 142, .25); }
.chip.neg { color: var(--neg); background: rgba(240, 97, 109, .08); border-color: rgba(240, 97, 109, .25); }
.chip.warn { color: var(--warn); background: rgba(232, 176, 75, .08); border-color: rgba(232, 176, 75, .25); }
.chip.info { color: var(--accent); background: rgba(138, 180, 255, .08); border-color: rgba(138, 180, 255, .25); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
/* ROI (core.js roiChip / roiCell): $ on top, % below, colour set inline. With .chip a tinted pill, without it bare for a table cell */
.roi-chip { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 0; line-height: 1.25; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.roi-chip .roi-usd { font-size: 14px; font-weight: 600; }
.roi-chip .roi-pct { font-size: 11.5px; opacity: .8; }
.roi-chip:not(.chip) .roi-usd { font-size: inherit; }
.chip.roi-chip {
  min-width: 88px; padding: 4px 10px; border-radius: 10px;
  border-color: color-mix(in srgb, currentColor 32%, transparent); background: color-mix(in srgb, currentColor 9%, transparent);
}
.roi-chip.none { align-items: center; color: var(--faint); }

/* ---------- more sheet (phones) ---------- */
.sheet { padding: 0; border: 0; background: transparent; color: var(--text); margin: auto 0 0; width: 100%; max-width: none; max-height: 80dvh; }
.sheet::backdrop { background: rgba(5, 6, 8, .55); backdrop-filter: blur(2px); }
.sheet[open] .sheet-card { animation: sheet-in .26s var(--ease) both; }
.sheet[open]::backdrop { animation: fade .2s ease-out both; }
.sheet-card {
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0;
  padding: 10px 10px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -18px 50px rgba(0, 0, 0, .5);
}
.sheet-card::before { content: ""; display: block; width: 36px; height: 4px; margin: 0 auto 10px; border-radius: 4px; background: var(--surface-3); }
.sheet nav { display: flex; flex-direction: column; gap: 2px; }
.sheet nav a { display: flex; align-items: center; gap: 14px; min-height: 50px; padding: 0 14px; border-radius: 10px; color: var(--muted); font-size: 15px; transition: background .15s, color .15s; }
.sheet nav a:active, .sheet nav a:hover { background: var(--surface-2); color: var(--text); }
.sheet nav a.active { color: var(--accent); background: var(--surface-2); }
.sheet nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---------- skeleton ---------- */
.skel {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 0%, #262a30 45%, var(--surface-2) 90%);
  background-size: 220% 100%;
  animation: shimmer 1.3s linear infinite;
  height: 12px;
}
.skel.big { height: 26px; width: 60%; margin-top: 12px; }
.skel.line { width: 40%; }
.skel.row-line { height: 14px; margin: 15px 20px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 14px 11px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--pos);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  animation: toast-in .22s var(--ease) both;
  overflow-wrap: anywhere;
}
.toast.error { border-left-color: var(--neg); }
.toast.out { animation: toast-out .2s ease-in forwards; }

/* ---------- modal ---------- */
.modal {
  padding: 0; border: 0; background: transparent; color: var(--text);
  max-width: calc(100vw - 32px);
}
.modal::backdrop { background: rgba(5, 6, 8, .62); backdrop-filter: blur(3px); }
.modal[open] .modal-card { animation: pop .17s var(--ease) both; }
.modal[open]::backdrop { animation: fade .17s ease-out both; }
.modal-card {
  width: 420px; max-width: 100%; max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.modal-card h2 { font-size: 17px; }
.modal-body { color: var(--muted); margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.modal-body strong { color: var(--text); font-weight: 600; }
.modal-body .box { font-family: var(--mono); color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere; }
.modal-body .warn { color: var(--warn); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, calc(100vw - 32px)); text-align: center; padding: 36px 28px; animation: pop .25s var(--ease) both; }
.login-logo { display: block; margin: 0 auto 18px; }
.login-card p { margin: 8px 0 26px; }
.btn.discord { width: 100%; padding: 11px 16px; background: #5865f2; border-color: transparent; color: #fff; }
.btn.discord:hover { background: #6974f3; }

.error-card { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.error-card .msg { color: var(--neg); overflow-wrap: anywhere; }

/* ---------- animations ---------- */
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -100% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.97); } }
@keyframes fade { from { opacity: 0; } }
@keyframes chip-out { to { opacity: 0; transform: scale(.85); } }
@keyframes flash { from { background: rgba(62, 207, 142, .12); } }
@keyframes bar-grow { from { transform: scaleY(0); } }
@keyframes bar-x { from { transform: scaleX(0); } }
@keyframes sheet-in { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: .001ms !important;
  }
}

/* ---------- phones ---------- */
@media (max-width: 720px) {
  /* top row: brand + profile (not sticky); the page links become the fixed bottom tab bar */
  .topbar { position: relative; }
  .topbar::before { display: none; }
  .topbar-in { height: auto; gap: 0; padding: 0 max(8px, env(safe-area-inset-right)) 0 0; }
  .brand { padding: 16px; padding-left: max(16px, env(safe-area-inset-left)); }
  .profile .who { display: none; }
  .nav-ink { display: none; }
  #view { padding: 4px max(16px, env(safe-area-inset-right)) calc(92px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }

  /* bottom tab bar: 5 pages + More (the rest live in the sheet) */
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    flex-direction: row; gap: 0;
    padding: 4px max(4px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
    background: rgba(14, 15, 17, .92);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
  }
  #nav a, .nav-more {
    flex: 1 1 0; min-width: 0; height: auto; min-height: 52px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    padding: 6px 2px; border: 0; border-radius: 10px; background: transparent;
    color: var(--muted); font-family: inherit; font-size: 10.5px; font-weight: 500; line-height: 1.2; cursor: pointer;
    -webkit-tap-highlight-color: transparent; transition: color .15s;
  }
  #nav a .ico, .nav-more .ico { width: 18px; height: 18px; }
  #nav a.in-more { display: none; }
  #nav a:hover { background: transparent; }
  #nav a.active, .nav-more.active { background: transparent; color: var(--accent); }
  #nav a .ico, .nav-more .ico { transition: transform .2s var(--ease); }
  #nav a.active .ico, .nav-more.active .ico { transform: translateY(-1px) scale(1.06); }
  #nav a:focus-visible, .nav-more:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .ico.dots { stroke-width: 3.2; }
  #nav .long { display: none; }
  #nav .short { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .page-head { margin-bottom: 18px; }
  .page-head > .actions { width: 100%; }
  .page-head .seg { width: 100%; }
  .seg button { min-width: 0; min-height: 40px; }
  .stat .value { font-size: 23px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 15px 16px; }
  .card.flush > .card-head { padding: 14px 16px 0; }
  .row { padding: 12px 16px; }
  .row .title, .row .meta { white-space: normal; overflow-wrap: anywhere; }
  .toolbar { padding: 14px 16px; }
  .toolbar > * { flex: 1 1 140px; }
  .hide-sm { display: none; }
  .toasts { left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); align-items: stretch; }
  .toast { max-width: none; }

  /* tap targets >= 40px, inputs >= 16px (no iOS zoom on focus) */
  .btn, .btn.sm { min-height: 40px; }
  .icon-btn { width: 40px; height: 40px; }
  .section-title a.note { display: inline-flex; align-items: center; min-height: 40px; }
  input, select, textarea { font-size: 16px; min-height: 44px; }
  textarea { min-height: 88px; }

  /* tables become stacked cards: item on its own wrapping line, then label/value pairs */
  .table-wrap { overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap td { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap .has-sort thead { display: block; }
  .table-wrap .has-sort thead tr { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table-wrap .has-sort thead tr::before { content: "Sort"; color: var(--faint); font-size: 12px; margin-right: 2px; }
  .table-wrap th { display: none; }
  .table-wrap th.sortable {
    display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px;
    border: 1px solid var(--border); border-bottom: 1px solid var(--border); border-radius: 999px; background: var(--surface-2);
  }
  .table-wrap th.sorted { border-color: rgba(138, 180, 255, .35); color: var(--accent); }
  .table-wrap th:not(.sorted) .arrow { display: none; }
  .table-wrap tbody tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px;
    padding: 14px 16px; border-top: 1px solid var(--border);
  }
  .table-wrap tbody tr:first-child { border-top: 0; }
  .table-wrap table[data-cols="3"] tbody tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .table-wrap tbody tr:hover { background: transparent; }
  .table-wrap td { padding: 0; border: 0; min-width: 0; white-space: normal; text-align: left; overflow-wrap: anywhere; }
  .table-wrap td::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    color: var(--faint); font: 400 11.5px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  }
  .table-wrap td.late { order: 1; }
  .table-wrap td.item { order: -1; grid-column: 1 / -1; width: auto; max-width: none; min-width: 0; overflow: visible; font-weight: 500; font-size: 14.5px; }
  .table-wrap td.item::before { display: none; }
  .table-wrap td.act { align-self: end; justify-self: end; }
  .table-wrap td.act::before { display: none; }
  .table-wrap td:empty { display: none; }
  .table-wrap .skel-tr td::before { display: none; }
  .table-wrap .skel-tr td.num .skel { margin-left: 0; }
  .dt-foot { padding: 10px 16px; }
  /* group header: one full-width line (.dt prefix: out-ranks the pages' own row layouts) */
  .dt .table-wrap tbody tr.dt-group { display: block; padding: 0; border-top: 0; }
  .dt .table-wrap .dt-group th { display: block; padding: 7px 16px; }
  .dt .table-wrap .dt-group + tr { border-top: 0; }

  /* tap-to-expand rows (a column with primary: true): item line, then the primary values; the rest on tap */
  .dt-x .table-wrap tr[aria-expanded] { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .dt-x .table-wrap tr[aria-expanded]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .dt-x .table-wrap tr[aria-expanded]::after {
    content: ""; position: absolute; top: 18px; right: 18px; width: 7px; height: 7px;
    border: solid var(--faint); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); transition: transform .2s var(--ease);
  }
  .dt-x .table-wrap tr[aria-expanded="true"]::after { transform: translateY(3px) rotate(-135deg); }
  .dt-x .table-wrap td.item { flex: 1 1 100%; padding-right: 26px; }
  .dt-x .table-wrap td.pri::before { display: none; }
  .dt-x .table-wrap tr[aria-expanded="false"] > td:not(.pri) { display: none; }
  .dt-x .table-wrap tr[aria-expanded="true"]::before { content: ""; order: 1; flex: 0 0 100%; } /* line break: the rest starts below the primary values */
  .dt-x .table-wrap tr[aria-expanded="true"] > td:not(.pri) { order: 2; flex: 1 1 40%; animation: rise .22s var(--ease) both; }

  /* filterSort(): the filters and the table's sort chips sit behind one button */
  .fs { display: block; flex: 1 1 100%; min-width: 0; }
  .fs .fs-btn { display: flex; width: 100%; }
  .fs-btn::after { content: ""; width: 6px; height: 6px; margin-left: 2px; border: solid var(--muted); border-width: 0 1.5px 1.5px 0; transform: translateY(-2px) rotate(45deg); transition: transform .2s var(--ease); }
  .fs-btn[aria-expanded="true"]::after { transform: translateY(1px) rotate(-135deg); }
  .fs-count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: rgba(138, 180, 255, .14); color: var(--accent); font-size: 12px; line-height: 20px; }
  .fs-body { display: none; }
  .fs.open .fs-body { display: grid; gap: 12px; margin-top: 12px; animation: rise .22s var(--ease) both; }
  .dt.fs-closed .table-wrap .has-sort thead { display: none; }

  .modal { max-width: calc(100vw - 24px); }
  .modal-card { padding: 20px 18px; }
  .modal-actions .btn { flex: 1; min-height: 44px; }
}
@media (max-width: 380px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
}
