/* ============================================================
   EuroTracker
   Same family as TankTracker: soft ground, glass panes, one accent.
   The accent is a deep green here — money, not fuel.
   Dark is defined twice: behind prefers-color-scheme for "System",
   and behind [data-theme="dark"] for an explicit choice.
   ============================================================ */

:root {
  color-scheme: light dark;
  --ground: #f2f3f1;
  --ground-2: #e8eae6;
  --pane: rgba(255, 255, 255, 0.74);
  --pane-strong: rgba(255, 255, 255, 0.9);
  --pane-solid: #ffffff;
  --rim: rgba(255, 255, 255, 0.9);
  --hairline: rgba(0, 0, 0, 0.08);
  --hairline-2: rgba(0, 0, 0, 0.14);
  --blur: saturate(140%) blur(20px);

  --ink: #1b1d1c;
  --ink-2: #545957;
  --ink-3: #858a88;

  --accent: #0e8a62;
  --accent-ink: #0a6e4e;
  --accent-wash: rgba(14, 138, 98, 0.10);
  --accent-rim: rgba(14, 138, 98, 0.30);

  --pos: #13885a;  --pos-wash: rgba(19,136,90,.10);
  --neg: #c2413a;  --neg-wash: rgba(194,65,58,.10);
  --warn: #b7791f; --warn-wash: rgba(183,121,31,.12);
  --danger: #c0392f;

  --r-xs: 8px; --r-sm: 12px; --r: 18px; --r-lg: 26px; --r-full: 999px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.05);
  --shadow-2: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px -12px rgba(0,0,0,.18);
  --shadow-3: 0 2px 6px rgba(0,0,0,.07), 0 28px 56px -20px rgba(0,0,0,.30);
  --gloss: inset 0 1px 0 var(--rim), inset 0 0 0 1px var(--hairline);

  --rail: 232px;
  --content: 1320px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI",
          ui-sans-serif, system-ui, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0f1110; --ground-2: #181b1a;
    --pane: rgba(36, 40, 38, 0.74); --pane-strong: rgba(42, 47, 45, 0.9); --pane-solid: #202422;
    --rim: rgba(255,255,255,.08); --hairline: rgba(255,255,255,.09); --hairline-2: rgba(255,255,255,.16);
    --ink: #eef1ef; --ink-2: #b3bab6; --ink-3: #87908b;
    --accent: #3cc98f; --accent-ink: #6ddbab; --accent-wash: rgba(60,201,143,.14); --accent-rim: rgba(60,201,143,.34);
    --pos: #4fd08f; --pos-wash: rgba(79,208,143,.14);
    --neg: #f07a70; --neg-wash: rgba(240,122,112,.14);
    --warn: #e5b458; --warn-wash: rgba(229,180,88,.14);
    --danger: #f07a70;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px -14px rgba(0,0,0,.8);
    --shadow-3: 0 2px 8px rgba(0,0,0,.5), 0 30px 60px -22px rgba(0,0,0,.95);
  }
}
:root[data-theme="dark"] {
  --ground: #0f1110; --ground-2: #181b1a;
  --pane: rgba(36, 40, 38, 0.74); --pane-strong: rgba(42, 47, 45, 0.9); --pane-solid: #202422;
  --rim: rgba(255,255,255,.08); --hairline: rgba(255,255,255,.09); --hairline-2: rgba(255,255,255,.16);
  --ink: #eef1ef; --ink-2: #b3bab6; --ink-3: #87908b;
  --accent: #3cc98f; --accent-ink: #6ddbab; --accent-wash: rgba(60,201,143,.14); --accent-rim: rgba(60,201,143,.34);
  --pos: #4fd08f; --pos-wash: rgba(79,208,143,.14);
  --neg: #f07a70; --neg-wash: rgba(240,122,112,.14);
  --warn: #e5b458; --warn-wash: rgba(229,180,88,.14);
  --danger: #f07a70;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px -14px rgba(0,0,0,.8);
  --shadow-3: 0 2px 8px rgba(0,0,0,.5), 0 30px 60px -22px rgba(0,0,0,.95);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5;
  color: var(--ink); background: var(--ground);
  background-image: radial-gradient(1200px 600px at 100% -10%, var(--accent-wash), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
@media (hover: hover) { a:hover { text-decoration: underline; } }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -0.01em; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 .8em; }
.muted { color: var(--ink-2); }
.meta { color: var(--ink-3); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- panes ---------- */
.pane {
  background: var(--pane); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  border-radius: var(--r); box-shadow: var(--gloss), var(--shadow-2); padding: 18px 20px;
  min-width: 0;
}
.pane-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.pane-head h2 { margin: 0; }
.pane-head .spacer { flex: 1; }

/* ---------- controls ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--r-full); color: #fff; background: var(--accent);
  box-shadow: var(--shadow-1); transition: transform .12s, filter .12s, background .12s;
  white-space: nowrap; text-decoration: none !important;
}
@media (hover: hover) { .btn:hover { filter: brightness(1.06); } }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--pane-strong); color: var(--ink); box-shadow: var(--gloss); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.icon { padding: 7px; width: 34px; height: 34px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--pane-solid); border: 1px solid var(--hairline-2);
  border-radius: var(--r-sm); padding: 9px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); padding: 0; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }

.seg { display: inline-flex; background: var(--ground-2); border-radius: var(--r-full); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  appearance: none; border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--ink-2); padding: 6px 12px; border-radius: var(--r-full); cursor: pointer; transition: all .15s;
}
@media (hover: hover) { .seg button:hover { color: var(--ink); } }
.seg button.on { background: var(--pane-solid); color: var(--ink); box-shadow: var(--shadow-1); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: var(--r-full);
  font-size: 12.5px; font-weight: 600; background: var(--ground-2); color: var(--ink-2); white-space: nowrap;
  border: 0; cursor: pointer; font-family: inherit; max-width: 100%;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
@media (hover: hover) { .chip:hover { filter: brightness(.97); } }
.chip:active { filter: brightness(.94); }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: var(--r-full); background: var(--accent-wash); color: var(--accent-ink); }
.badge.warn { background: var(--warn-wash); color: var(--warn); }
.badge.neg { background: var(--neg-wash); color: var(--neg); }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--hairline);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 17px; padding: 4px 10px 18px; color: var(--ink); }
.brand svg { width: 30px; height: 30px; }
.rail a.nav {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 600; text-decoration: none; transition: background .12s, color .12s;
}
.rail a.nav svg { width: 19px; height: 19px; flex: none; }
@media (hover: hover) { .rail a.nav:hover { background: var(--pane); color: var(--ink); } }
.rail a.nav.on { background: var(--pane-strong); color: var(--ink); box-shadow: var(--gloss); }
.rail a.nav.on svg { color: var(--accent); }
.rail .grow { flex: 1; }
.rail .lock { font-size: 12px; color: var(--ink-3); padding: 10px 12px; display: flex; gap: 8px; align-items: flex-start; }
.rail .lock svg { width: 15px; height: 15px; flex: none; margin-top: 2px; color: var(--accent); }

main { padding: 24px 28px 80px; max-width: var(--content); width: 100%; margin: 0 auto; min-width: 0; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .spacer { flex: 1; }

.tabbar { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
  main { padding: 16px 16px 96px; }
  h1 { font-size: 24px; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40; justify-content: space-around;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--pane-strong);
    backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); border-top: 1px solid var(--hairline);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; font-weight: 600;
    color: var(--ink-3); padding: 4px 6px; text-decoration: none; min-width: 52px; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a.on { color: var(--accent); }
  .pane { padding: 14px 14px; }
}

/* ---------- timeline bar ---------- */
.timeline {
  position: sticky; top: 8px; z-index: 30; margin-bottom: 18px; padding: 10px 14px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
}
.timeline .brush { position: relative; height: 44px; min-width: 0; }
.timeline .brush canvas { width: 100%; height: 44px; display: block; }
.timeline .sel {
  position: absolute; top: 0; bottom: 0; background: var(--accent-wash); border: 1.5px solid var(--accent-rim);
  border-radius: 8px; cursor: grab;
}
.timeline .sel:active { cursor: grabbing; }
.timeline .sel .h { position: absolute; top: 8px; bottom: 8px; width: 8px; border-radius: 4px; background: var(--accent); cursor: ew-resize; }
.timeline .sel .h.l { left: -5px; } .timeline .sel .h.r { right: -5px; }
.timeline .label { font-size: 13px; font-weight: 650; white-space: nowrap; text-align: right; }
.timeline .label small { display: block; font-weight: 500; color: var(--ink-3); }
.timeline .custom { display: flex; gap: 6px; align-items: center; }
.timeline .custom input { width: 140px; padding: 5px 8px; font-size: 13px; }
@media (max-width: 1100px) {
  .timeline { grid-template-columns: 1fr; top: 0; border-radius: 0 0 var(--r) var(--r); margin: -16px -16px 16px; }
  .timeline .label { text-align: left; }
  .timeline .seg { overflow-x: auto; flex-wrap: nowrap; max-width: 100%; }
}

/* ---------- dashboard grid ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
@media (max-width: 1100px) {
  .span-3 { grid-column: span 6; } .span-4, .span-5, .span-7, .span-8, .span-6 { grid-column: span 12; }
}
@media (max-width: 560px) { .span-3 { grid-column: span 12; } }

.kpi { position: relative; overflow: hidden; }
.kpi .k-label { font-size: 13px; font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi .k-value { font-size: 28px; font-weight: 750; letter-spacing: -0.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi .k-delta { font-size: 12.5px; font-weight: 650; }
.kpi .k-delta.good { color: var(--pos); } .kpi .k-delta.bad { color: var(--neg); } .kpi .k-delta.flat { color: var(--ink-3); }
.kpi canvas.spark { position: absolute; right: 0; bottom: 0; width: 55%; height: 46px; opacity: .9; pointer-events: none; }

.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }
.chart-box.short { height: 220px; }

.crumbs { display: flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 600; flex-wrap: wrap; }
.crumbs button { appearance: none; border: 0; background: none; color: var(--accent-ink); font: inherit; cursor: pointer; padding: 0; position: relative; }
.crumbs button::after { content: ""; position: absolute; inset: -13px -4px; } /* 44px to tap, no layout change */
.crumbs span.sep { color: var(--ink-3); }

.legend-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.legend-list li {
  display: grid; grid-template-columns: 12px 1fr auto auto; gap: 10px; align-items: center; padding: 7px 8px;
  border-radius: var(--r-xs); cursor: pointer; font-size: 14px;
}
.legend-list li.hl, .legend-list li:active { background: var(--accent-wash); }
@media (hover: hover) { .legend-list li:hover { background: var(--accent-wash); } }
.legend-list .sw { width: 12px; height: 12px; border-radius: 4px; }
.legend-list .pct { color: var(--ink-3); font-size: 12.5px; width: 44px; text-align: right; }
.donut-wrap { display: grid; grid-template-columns: minmax(200px, 1fr) minmax(220px, 1.1fr); gap: 18px; align-items: center; }
@media (max-width: 700px) { .donut-wrap { grid-template-columns: 1fr; } }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; text-align: center; }
.donut-center b { font-size: 22px; font-variant-numeric: tabular-nums; }
.donut-center span { font-size: 12px; color: var(--ink-3); max-width: 120px; }

/* merchants */
.m-list { display: grid; gap: 4px; }
.m-row { display: grid; grid-template-columns: 34px 1fr 90px auto; gap: 12px; align-items: center; padding: 6px 6px; border-radius: var(--r-xs); cursor: pointer; }
.m-row:active { background: var(--accent-wash); }
@media (hover: hover) { .m-row:hover { background: var(--accent-wash); } }
.m-logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 750; color: #fff; font-size: 14px; }
.m-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-bar { height: 5px; border-radius: 3px; background: var(--accent); margin-top: 4px; opacity: .7; }
.m-row canvas { width: 90px; height: 28px; }

/* heatmap */
.heat { display: flex; gap: 3px; overflow-x: auto; padding-bottom: 6px; }
.heat .col { display: grid; grid-template-rows: repeat(7, 13px); gap: 3px; }
.heat-wrap { display: flex; gap: 8px; }
.heat-days { display: grid; grid-template-rows: repeat(7, 13px); gap: 3px; font-size: 10px; color: var(--ink-3); padding-top: 18px; }
.heat-months { display: flex; font-size: 10.5px; color: var(--ink-3); height: 16px; position: relative; }
.heat-legend { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-3); margin-top: 6px; justify-content: flex-end; }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* insights */
.insights { display: grid; gap: 10px; }
.insight { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-sm); background: var(--pane-strong); box-shadow: var(--gloss); font-size: 14px; cursor: default; }
.insight .ic { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; flex: none; font-size: 15px; }
.insight.up .ic { background: var(--neg-wash); color: var(--neg); }
.insight.down .ic { background: var(--pos-wash); color: var(--pos); }
.insight.info .ic { background: var(--accent-wash); color: var(--accent); }
.insight[data-cat], .insight[data-tx], .insight[role="button"] { cursor: pointer; }

/* subscriptions */
.subs { display: grid; gap: 6px; }
.sub-row { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 12px; align-items: center; padding: 8px 6px; border-radius: var(--r-xs); }
.sub-row:active { background: var(--accent-wash); }
@media (hover: hover) { .sub-row:hover { background: var(--accent-wash); } }
.sub-row.inactive { opacity: .5; }

/* budgets */
.budgets { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.budget { display: grid; grid-template-columns: 74px 1fr; gap: 14px; align-items: center; padding: 12px; border-radius: var(--r-sm); background: var(--pane-strong); box-shadow: var(--gloss); cursor: pointer; }
.ring { width: 74px; height: 74px; }
.ring circle { fill: none; stroke-width: 8; }
.ring .track { stroke: var(--ground-2); }
.ring .val { stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .8s cubic-bezier(.2,.8,.2,1); }
.ring text { font-size: 15px; font-weight: 750; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }

/* ---------- transactions ---------- */
.tx-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.tx-tools .search { flex: 1 1 260px; position: relative; }
.tx-tools .search input { padding-left: 36px; }
.tx-tools .search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--ink-3); }
.tx-tools select { width: auto; }
.tx-sum { display: flex; gap: 18px; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; flex-wrap: wrap; }
.tx-sum b { color: var(--ink); }
.tx-list { position: relative; overflow-y: auto; height: calc(100vh - 290px); height: calc(100dvh - 290px); min-height: 400px; border-radius: var(--r-sm); }
.tx-list .spacer { position: relative; }
.tx-row {
  position: absolute; left: 0; right: 0; height: 58px; display: grid;
  grid-template-columns: 28px 38px minmax(0, 1fr) minmax(0, 220px) 120px; gap: 12px; align-items: center;
  padding: 0 10px; border-bottom: 1px solid var(--hairline); cursor: pointer;
}
@media (hover: hover) { .tx-row:hover { background: var(--accent-wash); } }
.tx-row.sel { background: var(--accent-wash); }
.tx-row .who { min-width: 0; }
.tx-row .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tx-row .who small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-3); font-size: 12.5px; }
.tx-row .amt { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-row .m-logo { width: 34px; height: 34px; }
.tx-day { position: absolute; left: 0; right: 0; height: 30px; display: flex; align-items: flex-end; padding: 0 10px 4px; font-size: 12px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; justify-content: space-between; }
@media (max-width: 700px) {
  .tx-row { grid-template-columns: 34px minmax(0, 1fr) auto; }
  .tx-row .cb, .tx-row .catcell { display: none; }
  .tx-list { height: calc(100vh - 330px); height: calc(100dvh - 330px); }
}
.bulkbar { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--r-full); background: var(--pane-strong); backdrop-filter: var(--blur); box-shadow: var(--gloss), var(--shadow-3); }
@media (max-width: 900px) { .bulkbar { bottom: 84px; } }

/* ---------- popovers, drawers, modals, toasts ---------- */
.pop {
  position: fixed; z-index: 100; width: 320px; max-height: 420px; display: flex; flex-direction: column;
  background: var(--pane-solid); border-radius: var(--r); box-shadow: var(--gloss), var(--shadow-3); padding: 10px;
}
.pop input { margin-bottom: 8px; }
.pop .opts { overflow-y: auto; position: relative; }
.pop .grp { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 8px 8px 4px; display: flex; gap: 6px; align-items: center; }
.pop .opt { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--r-xs); cursor: pointer; font-size: 14px; }
.pop .opt.kb { background: var(--accent-wash); }
@media (hover: hover) { .pop .opt:hover { background: var(--accent-wash); } }
.pop .opt.cur { font-weight: 700; color: var(--accent-ink); }

.drawer-back { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 80; animation: fade .18s; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 90; overflow-y: auto;
  background: var(--pane-solid); box-shadow: var(--shadow-3); padding: 22px; animation: slidein .22s cubic-bezier(.2,.8,.2,1);
}
.drawer .close { position: absolute; right: 16px; top: 16px; }
.drawer .big { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 8px 0; }
.drawer dl { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 14px; margin: 16px 0; }
.drawer dt { color: var(--ink-3); }
.drawer dd { margin: 0; word-break: break-word; }
.drawer:focus { outline: none; }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 110; display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.modal { background: var(--pane-solid); border-radius: var(--r-lg); box-shadow: var(--shadow-3); padding: 24px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; animation: pop .2s cubic-bezier(.2,.8,.2,1); }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }

.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; }
.toast { background: #232826; color: #f1f4f2; border: .5px solid rgba(255,255,255,.08); padding: 10px 16px; border-radius: var(--r-full); font-size: 14px; font-weight: 600; box-shadow: var(--shadow-3); animation: pop .2s; display: flex; gap: 12px; align-items: center; }
.toast button { background: none; border: 0; color: #6ddbab; padding: 4px 2px; white-space: nowrap; font: inherit; font-weight: 700; cursor: pointer; }

.tip { position: fixed; z-index: 150; pointer-events: none; background: var(--ink); color: var(--ground); font-size: 12.5px; padding: 6px 10px; border-radius: 8px; max-width: 260px; box-shadow: var(--shadow-2); }

/* ---------- sheets: modal, drawer and popover become bottom sheets on phones ---------- */
:root { --sheet-bg: var(--ground); --cell: var(--pane-solid); --kb: 0px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --sheet-bg: #181b1a; --cell: #282c2a; } }
:root[data-theme="dark"] { --sheet-bg: #181b1a; --cell: #282c2a; }

.sheet-grab, .pop-head, .pop-searchwrap > svg { display: none; }
.drawer .sheet-top { display: contents; }
.pop-searchwrap { position: relative; }
.pop .grp { position: sticky; top: 0; z-index: 1; background: var(--pane-solid); }
.pop .opt-l { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop .opt-ck { color: var(--accent); font-weight: 800; }
.pop .opt-none { padding: 18px 10px; color: var(--ink-3); text-align: center; font-size: 14px; }
.toast.out { opacity: 0; transform: translateY(-6px); transition: opacity .18s, transform .18s; }
.closing { pointer-events: none !important; }
.modal-back.closing, .drawer-back.closing, .pop-back.closing { background: transparent !important; }
@keyframes sheet-up { from { transform: translateY(100%); } }

@media (max-width: 900px) {
  .sheet-grab { display: flex; justify-content: center; align-items: center; height: 22px; flex: none; touch-action: none; cursor: grab; }
  .sheet-grab i { width: 36px; height: 5px; border-radius: 3px; background: var(--hairline-2); }

  /* modal → sheet */
  .modal-back {
    place-items: end stretch; padding: calc(var(--safe-top) + 10px) 0 var(--kb); background: rgba(0,0,0,.42);
    transition: background-color .2s;
  }
  .modal {
    width: 100%; max-height: min(92vh, calc(var(--vvh, 100vh) - var(--safe-top) - 10px));
    border-radius: 14px 14px 0 0; padding: 0 16px; background: var(--sheet-bg);
    box-shadow: 0 -8px 40px rgba(0,0,0,.28); animation: sheet-up .3s cubic-bezier(.2,.8,.2,1);
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch; transition: transform .25s cubic-bezier(.2,.8,.2,1);
  }
  .modal::after { content: ""; display: block; height: calc(16px + var(--safe-bottom)); }
  .modal:has(> .actions)::after { display: none; }
  .modal > .sheet-grab { position: sticky; top: 0; z-index: 3; margin: 0 -16px; background: var(--sheet-bg); }
  .modal > h2 { font-size: 17px; font-weight: 650; text-align: center; margin: 0 0 14px; padding: 0 8px; touch-action: none; }
  .modal .actions {
    position: sticky; bottom: 0; z-index: 2; margin: 18px -16px 0; padding: 10px 16px calc(10px + var(--safe-bottom));
    background: var(--sheet-bg); border-top: .5px solid var(--hairline); gap: 8px; flex-wrap: nowrap;
  }
  .modal .actions .btn { flex: 1 1 0; min-width: 0; min-height: 48px; padding: 12px 14px; font-size: 16px; border-radius: 13px; white-space: normal; line-height: 1.2; }
  /* three or more choices: the main one full width on top, the rest side by side */
  .modal .actions.many { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .modal .actions.many .btn:not(.ghost):not(.danger) { grid-column: 1 / -1; order: -1; }
  .modal .actions.many .btn.danger { background: var(--pane-strong); color: var(--danger); box-shadow: var(--gloss); }

  /* drawer → sheet */
  .drawer-back { background: rgba(0,0,0,.42); transition: background-color .2s; }
  .drawer {
    top: auto; left: 0; right: 0; bottom: var(--kb); width: auto;
    max-height: min(92vh, calc(var(--vvh, 100vh) - var(--safe-top) - 10px));
    border-radius: 14px 14px 0 0; padding: 0 16px calc(24px + var(--safe-bottom));
    background: var(--sheet-bg); box-shadow: 0 -8px 40px rgba(0,0,0,.28);
    animation: sheet-up .3s cubic-bezier(.2,.8,.2,1); transition: transform .25s cubic-bezier(.2,.8,.2,1);
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  }
  .drawer .sheet-top {
    display: block; position: sticky; top: 0; z-index: 5; height: 44px; margin: 0 -16px;
    background: var(--sheet-bg); touch-action: none;
  }
  .drawer .sheet-top .sheet-grab { height: 16px; }
  .drawer .sheet-top .close {
    position: absolute; right: 12px; top: 8px; width: 30px; height: 30px; padding: 6px; border-radius: 50%;
    min-height: 30px; background: color-mix(in srgb, var(--ink) 10%, transparent); box-shadow: none; color: var(--ink-2);
  }
  .drawer .sheet-top .close::before { content: ""; position: absolute; inset: -7px; }

  /* popover → sheet */
  .pop-back { position: fixed; inset: 0; z-index: 99; background: rgba(0,0,0,.42); animation: fade .18s; transition: background-color .2s; }
  .pop.sheet {
    left: 0; right: 0; top: auto; bottom: var(--kb); width: auto; max-height: none;
    height: min(80vh, calc(var(--vvh, 100vh) - var(--safe-top) - 10px));
    border-radius: 14px 14px 0 0; padding: 0 0 var(--safe-bottom); background: var(--sheet-bg);
    box-shadow: 0 -8px 40px rgba(0,0,0,.28); animation: sheet-up .3s cubic-bezier(.2,.8,.2,1);
    transition: transform .25s cubic-bezier(.2,.8,.2,1);
  }
  .pop.sheet .pop-head {
    display: flex; align-items: center; justify-content: center; position: relative; flex: none;
    height: 30px; touch-action: none; font-size: 17px;
  }
  .pop-cancel {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%); appearance: none; border: 0; background: none;
    font: inherit; font-size: 16px; font-weight: 500; color: var(--accent-ink); padding: 10px 8px; cursor: pointer;
  }
  .pop.sheet .pop-searchwrap { margin: 10px 16px 4px; flex: none; }
  .pop.sheet .pop-searchwrap > svg {
    display: block; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--ink-3); pointer-events: none;
  }
  .pop.sheet input.pop-search {
    margin: 0; height: 38px; padding: 7px 12px 7px 34px; border: 0; border-radius: 10px;
    background: color-mix(in srgb, var(--ink) 9%, transparent); box-shadow: none;
  }
  .pop.sheet .opts { flex: 1; min-height: 0; padding: 0 16px 16px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .pop.sheet .grp { padding: 16px 4px 7px; font-size: 12.5px; letter-spacing: .03em; background: var(--sheet-bg); }
  .pop.sheet .grp span { font-size: 14px; }
  .pop.sheet .opt {
    position: relative; min-height: 48px; padding: 0 16px; gap: 12px; border-radius: 0; font-size: 16px;
    background: var(--cell);
  }
  .pop.sheet .opt + .opt::before { content: ""; position: absolute; top: 0; left: 37px; right: 0; border-top: .5px solid var(--hairline-2); }
  .pop.sheet .grp + .opt { border-radius: 12px 12px 0 0; }
  .pop.sheet .opt:last-child { border-radius: 0 0 12px 12px; }
  .pop.sheet .grp + .opt:last-child { border-radius: 12px; }
  .pop.sheet .opt:hover { background: var(--cell); }
  .pop.sheet .opt:active { background: color-mix(in srgb, var(--cell) 80%, var(--ink)); }
  .pop.sheet .opt.cur { color: var(--ink); font-weight: 600; }
  .pop.sheet .opt-ck { font-size: 17px; }

  .toast { padding: 12px 18px; border-radius: 16px; font-size: 15px; }
  .toast button { min-height: 40px; padding: 8px 6px; margin: -10px -6px -10px 0; }

  /* The page behind an open sheet doesn't scroll along (iOS 16+ honours overflow on the root). */
  html:has(.modal-back:not(.closing), .drawer-back:not(.closing), .pop-back:not(.closing), .tl-sheet-back:not(.closing)) { overflow: hidden; }
}

/* ---------- import ---------- */
.drop {
  border: 2px dashed var(--hairline-2); border-radius: var(--r-lg); padding: 40px 20px; text-align: center;
  transition: all .15s; cursor: pointer; background: var(--pane);
}
.drop.over { border-color: var(--accent); background: var(--accent-wash); transform: scale(1.01); }
.drop svg { width: 44px; height: 44px; color: var(--accent); }
.bank-help { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.bank-help ol { padding-left: 20px; margin: 0; font-size: 14px; color: var(--ink-2); }
.preview-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.preview-table th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 650; padding: 6px 8px; border-bottom: 1px solid var(--hairline-2); position: sticky; top: 0; background: var(--pane-solid); }
.preview-table td { padding: 6px 8px; border-bottom: 1px solid var(--hairline); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-scroll { max-height: 420px; overflow: auto; border-radius: var(--r-sm); }
.progress { height: 6px; background: var(--ground-2); border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- rules ---------- */
.rule { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--r-sm); background: var(--pane-strong); box-shadow: var(--gloss); margin-bottom: 8px; }
.rule code { font-family: var(--mono); font-size: 13px; background: var(--ground-2); padding: 1px 6px; border-radius: 5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; }
.cat-tree { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.cat-card h3 { display: flex; align-items: center; gap: 8px; }
.cat-card ul { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.cat-card li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--hairline); color: var(--ink-2); }

/* ---------- empty / loading ---------- */
.empty { text-align: center; padding: 60px 20px; }
.empty svg { width: 64px; height: 64px; color: var(--accent); margin-bottom: 10px; }
.loading { display: grid; place-items: center; min-height: 60vh; gap: 14px; text-align: center; color: var(--ink-2); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--accent-wash); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.reveal { animation: rise .45s cubic-bezier(.2,.8,.2,1) both; }
/* In the app only a page's first render rises in (the router sets .entering on
   #view); redraws — a filter, an expanded row, a sync — must not replay it. */
#view:not(.entering) .reveal { animation: none; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- public pages ---------- */
.public { max-width: 1080px; margin: 0 auto; padding: 24px 20px 60px; }
.public-top { display: flex; align-items: center; gap: 12px; margin-bottom: 40px; }
.public-top .spacer { flex: 1; }
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: center; margin-bottom: 60px; }
.hero h1 { font-size: 46px; letter-spacing: -0.03em; line-height: 1.05; }
.hero p.lead { font-size: 18px; color: var(--ink-2); }
.hero .cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.hero-art { aspect-ratio: 1.1; border-radius: var(--r-lg); padding: 22px; display: grid; gap: 12px; grid-template-rows: auto 1fr auto; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.features .pane svg { width: 28px; height: 28px; color: var(--accent); margin-bottom: 8px; }
@media (max-width: 800px) { .hero { grid-template-columns: 1fr; } .hero h1 { font-size: 34px; } }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.auth-card { width: min(440px, 100%); padding: 30px; }
.auth-card .brand { justify-content: center; padding-bottom: 8px; }
.auth-card h1 { text-align: center; font-size: 24px; }
.auth-card .sub { text-align: center; color: var(--ink-2); margin-bottom: 22px; font-size: 14px; }
.auth-card .btn { width: 100%; padding: 11px; }
.auth-card .alt { text-align: center; font-size: 14px; margin-top: 16px; color: var(--ink-2); }
.err { background: var(--neg-wash); color: var(--neg); padding: 10px 12px; border-radius: var(--r-sm); font-size: 14px; margin-bottom: 14px; }
.note { background: var(--accent-wash); color: var(--ink); padding: 12px 14px; border-radius: var(--r-sm); font-size: 13.5px; margin-bottom: 14px; }
.note.warn { background: var(--warn-wash); }
.code-box { font-family: var(--mono); font-size: 19px; font-weight: 700; letter-spacing: .06em; text-align: center; padding: 18px 10px; border-radius: var(--r-sm); background: var(--ground-2); word-break: break-all; user-select: all; margin: 12px 0; }
.meter { height: 5px; border-radius: 3px; background: var(--ground-2); margin: -8px 0 14px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; transition: width .2s, background .2s; }
.langsw { font-size: 13px; }
.langsw a { color: var(--ink-3); font-weight: 600; }
.langsw a.on { color: var(--ink); }
.prose { max-width: 720px; }
.prose h2 { margin-top: 28px; }
.prose li { margin-bottom: 6px; }

/* ============================================================
   iPhone / touch foundation
   Applies everywhere. Home-screen mode runs under the status bar
   (black-translucent), so the top and bottom pad for the safe areas.
   ============================================================ */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 58px;
}
/* Nothing may ever push the page sideways. Containers that should scroll
   sideways (tables, charts) set overflow-x:auto themselves. */
html, body { overflow-x: clip; max-width: 100%; }
html { -webkit-tap-highlight-color: transparent; }
button, a, .chip, .seg button, [role="button"] { touch-action: manipulation; }
img, svg, canvas, video { max-width: 100%; }

@media (max-width: 900px) {
  main {
    padding-top: calc(var(--safe-top) + 14px);
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 28px);
  }
  /* A strip behind the status bar so content scrolling under it stays legible. */
  body::before {
    content: ""; position: fixed; z-index: 45; left: 0; right: 0; top: 0;
    height: var(--safe-top); background: var(--ground);
  }
  /* iOS zooms into any field with text under 16px: don't let it. */
  input, select, textarea { font-size: 16px; }

  .tabbar {
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding: 6px calc(4px + var(--safe-right)) var(--safe-bottom) calc(4px + var(--safe-left));
    align-items: flex-start;
    background: color-mix(in srgb, var(--pane-solid) 92%, transparent);
    backdrop-filter: saturate(160%) blur(24px); -webkit-backdrop-filter: saturate(160%) blur(24px);
    border-top: 0.5px solid var(--hairline-2);
    -webkit-user-select: none; user-select: none;
  }
  .tabbar a { flex: 1 1 0; min-width: 0; padding: 4px 2px; gap: 3px; font-size: 10px; letter-spacing: .01em; }
  .tabbar a span, .tabbar a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .tabbar a svg { width: 24px; height: 24px; }
  .tabbar a:active { opacity: .6; }

  .toasts { top: calc(var(--safe-top) + 10px); width: calc(100% - 32px); }
  .toast { justify-content: center; }
  .bulkbar { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); max-width: calc(100% - 24px); }
}

/* Public pages (welcome, login, privacy) in home-screen mode. */
.public, .auth-wrap {
  padding-top: max(24px, calc(var(--safe-top) + 12px));
  padding-bottom: max(40px, calc(var(--safe-bottom) + 24px));
}

/* ============================================================
   App shell, public pages and shared controls, iPhone-grade.
   (Owned by the pages work: .shell/.tabbar/.page-head, .public*,
   .auth-*, .btn/.seg/.switch/.glist. Overlays live elsewhere.)
   ============================================================ */
:root { --fill: rgba(120, 120, 128, .16); --fill-2: rgba(120, 120, 128, .24); --cell: var(--pane-solid); --r-cell: 14px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --fill: rgba(120, 120, 128, .28); --fill-2: rgba(120, 120, 128, .38); --cell: #1c201e; } }
:root[data-theme="dark"] { --fill: rgba(120, 120, 128, .28); --fill-2: rgba(120, 120, 128, .38); --cell: #1c201e; }

/* ---------- iOS switch: <input type="checkbox" class="switch"> ---------- */
input[type="checkbox"].switch {
  -webkit-appearance: none; appearance: none; flex: none; position: relative; cursor: pointer;
  width: 51px; height: 31px; margin: 0; padding: 0; border: 0; border-radius: 16px;
  background: var(--fill-2); transition: background .2s;
}
input[type="checkbox"].switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 1px 1px rgba(0,0,0,.16); transition: transform .22s cubic-bezier(.3,.7,.4,1);
}
input[type="checkbox"].switch:checked { background: var(--accent); }
input[type="checkbox"].switch:checked::after { transform: translateX(20px); }
input[type="checkbox"].switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- grouped inset list (iOS Settings) ---------- */
.glist-title {
  margin: 26px 16px 7px; font-size: 13px; font-weight: 500; letter-spacing: .02em; text-transform: uppercase; color: var(--ink-3);
}
.glist-wrap:first-child > .glist-title { margin-top: 4px; }
.glist {
  background: var(--cell); border-radius: var(--r-cell); overflow: hidden; box-shadow: inset 0 0 0 .5px var(--hairline);
  min-width: 0;
}
.glist-foot { margin: 7px 16px 0; font-size: 13px; line-height: 1.4; color: var(--ink-3); }
.gcell {
  --sep: 16px;
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 16px;
  width: 100%; color: var(--ink); background: none; border: 0; font: inherit; font-size: 16px; text-align: left;
  text-decoration: none !important;
}
.gcell.has-ic { --sep: 58px; }
.gcell + .gcell::before, .gcell + details > .gcell::before, details + .gcell::before, details + details > .gcell::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--sep); height: 1px; transform: scaleY(.5); transform-origin: top;
  background: var(--hairline-2);
}
a.gcell, button.gcell, summary.gcell, label.gcell { cursor: pointer; -webkit-user-select: none; user-select: none; }
a.gcell:active, button.gcell:active, summary.gcell:active { background: var(--fill); }
@media (hover: hover) { a.gcell:hover, button.gcell:hover, summary.gcell:hover { background: var(--fill); } }
.cell-ic {
  width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; color: #fff;
  background: var(--accent); font-size: 15px;
}
.cell-ic svg { width: 18px; height: 18px; }
.cell-main { flex: 1 1 auto; min-width: 0; }
.cell-main > b, .cell-main > span:first-child { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-main > .meta, .cell-main > small { display: block; font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-val { color: var(--ink-3); font-size: 15px; white-space: nowrap; flex: none; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.cell-chev { width: 8px; height: 14px; flex: none; color: var(--ink-3); opacity: .7; transition: transform .2s; }
.gcell.danger { color: var(--danger); justify-content: center; font-weight: 500; }
.gcell.accent { color: var(--accent-ink); font-weight: 500; }
.gcell > input:not([type="checkbox"]):not([type="color"]), .gcell > select {
  border: 0; background: transparent; box-shadow: none !important; padding: 6px 0; text-align: right; flex: 1 1 50%; min-width: 0; color: var(--ink-2);
}
.gcell > input:not([type="checkbox"]):focus { color: var(--ink); }
details > summary.gcell { list-style: none; }
details > summary.gcell::-webkit-details-marker { display: none; }
details[open] > summary.gcell .cell-chev { transform: rotate(90deg); }
.glist .cell-body { padding: 2px 16px 16px; font-size: 15px; color: var(--ink-2); }

/* ---------- controls on touch screens ---------- */
@media (max-width: 900px) {
  .btn { min-height: 44px; padding: 10px 18px; font-size: 15px; }
  .btn.small { min-height: 36px; padding: 7px 14px; font-size: 14px; position: relative; }
  :where(.btn.small)::after { content: ""; position: absolute; inset: -4px 0; }
  .btn.icon { width: 44px; height: 44px; min-height: 44px; padding: 10px; }
  .btn.icon.small { width: 36px; height: 36px; min-height: 36px; padding: 6px; }
  button.chip:not(.txd-chip) { position: relative; }
  :where(button.chip:not(.txd-chip))::after { content: ""; position: absolute; inset: -9px -2px; } /* ~44px to tap */
  .btn.block, .pg-actions.stack .btn { width: 100%; }
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="range"]), select { min-height: 44px; }
  .seg { flex-wrap: nowrap; }
  .seg button { padding: 7px 13px; min-height: 38px; font-size: 14px; position: relative; }
  :where(.seg button)::after { content: ""; position: absolute; inset: -3px 0; } /* + the bar's padding = 44px */
  .pane { border-radius: 16px; }
  .note, .err { border-radius: 12px; }
}

/* ---------- app shell on phones ---------- */
.m-back { display: none; }
@media (max-width: 900px) {
  .shell { align-content: start; }
  /* Large titles, iOS style, one rhythm on every page. */
  main { padding-top: calc(var(--safe-top) + 10px); }
  .page-head { margin-bottom: 18px; gap: 10px 12px; }
  .page-head h1 { font-size: 32px; font-weight: 750; letter-spacing: -.025em; line-height: 1.12; }
  .page-head .pg-sub { font-size: 15px; line-height: 1.4; margin-top: 4px; }
  .page-head > .pg-actions { flex: 1 1 100%; margin-top: 2px; }
  .page-head h1 .t-long { display: none; }
  /* Back to Settings for the pages that live under it on a phone. */
  .shell[data-view="budgets"] .m-back, .shell[data-view="categories"] .m-back, .shell[data-view="banking"] .m-back,
  .shell[data-view="averages"] .m-back, .shell[data-view="savings"] .m-back, .shell[data-view="accounts"] .m-back {
    display: inline-flex; align-items: center; gap: 6px; justify-self: start;
    min-height: 44px; margin-top: var(--safe-top); padding: 6px 16px 0 calc(10px + var(--safe-left));
    font-size: 17px; color: var(--accent-ink); text-decoration: none; -webkit-user-select: none; user-select: none;
  }
  .m-back svg { width: 12px; height: 20px; }
  .m-back:active { opacity: .5; }
  .shell[data-view="budgets"] main, .shell[data-view="categories"] main, .shell[data-view="banking"] main,
  .shell[data-view="averages"] main, .shell[data-view="savings"] main, .shell[data-view="accounts"] main { padding-top: 2px; }

  /* Tab bar: five even tabs, labels whole, active tab tinted. */
  .tabbar { justify-content: space-between; padding-top: 7px; }
  .tabbar a { padding: 0 1px; gap: 3px; font-size: 10px; font-weight: 600; letter-spacing: -.01em; color: var(--ink-3); text-overflow: clip; }
  .tabbar a span { display: block; max-width: 100%; overflow: visible; text-overflow: clip; }
  .tabbar a svg { width: 25px; height: 25px; transition: transform .15s; }
  .tabbar a.on { color: var(--accent); }
  .tabbar a.on span { font-weight: 700; }
  .tabbar a:active svg { transform: scale(.88); }
  .tabbar a:active { opacity: 1; }
}
@media (min-width: 901px) { .page-head h1 .t-short { display: none; } }

/* ---------- install hint ---------- */
.install-hint {
  position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(14px + var(--safe-bottom));
  max-width: 480px; margin: 0 auto; display: flex; gap: 12px; align-items: center; padding: 12px 10px 12px 14px;
  border-radius: 18px; background: color-mix(in srgb, var(--pane-solid) 97%, transparent);
  backdrop-filter: saturate(160%) blur(24px); -webkit-backdrop-filter: saturate(160%) blur(24px);
  box-shadow: inset 0 0 0 .5px var(--hairline-2), var(--shadow-3); animation: hint-up .3s cubic-bezier(.2,.8,.2,1);
}
.has-install-hint .install-hint { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 10px); }
@media (min-width: 901px) { .has-install-hint .install-hint { bottom: 20px; } }
.install-hint.out { opacity: 0; transform: translateY(12px); transition: all .2s; }
.install-logo { width: 40px; height: 40px; flex: none; }
.install-text { flex: 1; min-width: 0; font-size: 14px; line-height: 1.35; }
.install-text b { display: block; font-size: 15px; }
.install-text p { margin: 2px 0 0; color: var(--ink-2); }
.install-share { display: inline-grid; place-items: center; vertical-align: -4px; width: 22px; height: 22px; color: #0a84ff; }
.install-share svg { width: 19px; height: 19px; }
.install-x {
  appearance: none; border: 0; background: var(--fill); color: var(--ink-2); width: 30px; height: 30px; border-radius: 50%;
  font-size: 13px; cursor: pointer; flex: none; align-self: flex-start; position: relative;
}
.install-x::after { content: ""; position: absolute; inset: -7px; }
@keyframes hint-up { from { transform: translateY(20px); opacity: 0; } }

/* ---------- public pages ---------- */
.back-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-size: 17px; color: var(--accent-ink);
  text-decoration: none !important; margin-left: -4px;
}
.back-link svg { width: 11px; height: 18px; }
.back-link:active { opacity: .5; }
.public-top .brand, .auth-card .brand { padding-top: 0; padding-bottom: 0; }
.auth-card .brand { margin-bottom: 14px; }
.langsw { display: inline-flex; align-items: center; }
.langsw a { display: inline-grid; place-items: center; min-width: 30px; min-height: 36px; }
.public-foot { margin-top: 44px; padding-top: 18px; border-top: 1px solid var(--hairline); display: flex; gap: 10px 22px; flex-wrap: wrap; font-size: 14px; color: var(--ink-3); }
.public-foot a { color: var(--ink-2); }
.features-head { margin: 0 0 14px; }
.cta-band { margin-top: 28px; padding: 26px 22px; text-align: center; }
.cta-band h2 { font-size: 22px; }
.cta-band .cta { justify-content: center; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.hero h1 { text-wrap: balance; }
.prose .lead { font-size: 17px; }

@media (max-width: 900px) {
  .public { padding-left: calc(18px + var(--safe-left)); padding-right: calc(18px + var(--safe-right)); }
  .public-top { margin-bottom: 22px; gap: 8px; min-height: 44px; }
  .hero { gap: 26px; margin-bottom: 34px; }
  .hero h1 { font-size: 36px; line-height: 1.08; margin: 12px 0 12px; }
  .hero p.lead { font-size: 17px; line-height: 1.5; }
  .hero .cta { flex-direction: column; gap: 10px; margin-top: 22px; }
  .hero .cta .btn, .cta-band .btn { width: 100%; min-height: 50px; font-size: 17px; border-radius: 14px; }
  .hero-art { aspect-ratio: auto; padding: 14px; gap: 12px; border-radius: 22px; }
  .hero-art > svg { height: 120px !important; }
  /* Features as one grouped list of rows. */
  .features {
    grid-template-columns: 1fr; gap: 0; background: var(--cell); border-radius: var(--r-cell); overflow: hidden;
    box-shadow: inset 0 0 0 .5px var(--hairline);
  }
  .features .pane {
    position: relative; display: grid; grid-template-columns: 38px minmax(0, 1fr); column-gap: 14px; align-items: start;
    background: none; box-shadow: none; border-radius: 0; backdrop-filter: none; -webkit-backdrop-filter: none; padding: 14px 16px;
  }
  .features .pane + .pane::before {
    content: ""; position: absolute; top: 0; right: 0; left: 68px; height: 1px; transform: scaleY(.5); background: var(--hairline-2);
  }
  .features .pane svg {
    grid-row: span 2; width: 38px; height: 38px; padding: 8px; margin: 0; border-radius: 10px;
    background: var(--accent-wash); color: var(--accent);
  }
  .features .pane h3 { margin: 1px 0 2px; font-size: 16px; }
  .features .pane p { margin: 0; font-size: 14.5px; line-height: 1.45; }
  .cta-band { padding: 22px 18px; }

  /* Auth: top-aligned card so the keyboard never makes it jump. */
  .auth-wrap {
    display: block; place-items: normal; min-height: 100vh; min-height: 100svh;
    padding: calc(var(--safe-top) + 4px) calc(16px + var(--safe-right)) calc(var(--safe-bottom) + 28px) calc(16px + var(--safe-left));
  }
  .auth-card { margin: 3vh auto 0; padding: 26px 20px 22px; border-radius: 22px; }
  .auth-card h1 { font-size: 28px; letter-spacing: -.02em; }
  .auth-card .sub { font-size: 15px; margin-bottom: 20px; }
  .auth-card input:not([type="checkbox"]) { min-height: 50px; border-radius: 12px; padding: 12px 14px; }
  .auth-card .btn { min-height: 50px; font-size: 17px; border-radius: 14px; }
  .auth-card .alt a { display: inline-block; padding: 8px 2px; }
  .auth-card .alt { margin-top: 10px; }
  .code-box { font-size: 18px; }
}
.auth-top { display: none; }
@media (max-width: 900px) { .auth-top { display: flex; align-items: center; min-height: 44px; } }

/* Recovery code: groups wrap whole, never mid-group. */
.code-box { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 12px; word-break: normal; line-height: 1.3; }
.code-box span { white-space: nowrap; }
.code-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.auth-card .code-actions .btn { width: 100%; }
.code-actions .btn svg { width: 18px; height: 18px; }
.check-row { display: flex; gap: 12px; align-items: center; font-size: 15px; margin-bottom: 16px; cursor: pointer; padding: 6px 0; }
.check-row input[type="checkbox"] { width: 22px; height: 22px; flex: none; }
@media (max-width: 480px) { .code-actions { grid-template-columns: 1fr; } }

/* iOS zooms into any field with text under 16px. Rules above (and in the view
   stylesheets) set smaller sizes on some fields, so this one has to win. */
@media (max-width: 900px), (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea {
    font-size: max(16px, 1em) !important;
  }
}
