/* Base look shared with Passbook (copied from it). TILAK-specific parts are in tilak.css. */

:root {
  color-scheme: light;
  --paper: #F3F5F9;          /* the page */
  --paper-2: #E9EDF3;
  --sheet: #FFFFFF;          /* panels */
  --sunk: #F6F8FB;           /* hover and inset areas on a panel */
  --ink: #0F172A;
  --ink-2: #334155;
  --muted: #64748B;
  --rule: #DDE3EC;
  --rule-soft: #EBEFF5;
  --brand: #2563EB;
  --brand-soft: #DBEAFE;
  --recv: #1D4ED8;           /* money in, links */
  --recv-soft: #DBEAFE;
  --spend: #64748B;          /* money out: bars */
  --spend-ink: #334155;
  --spend-soft: #E2E8F0;
  --spend-dim: #CBD5E1;
  --owe: #DC2626;            /* owed or late */
  --owe-soft: #FEE2E2;
  --focus: #2563EB;
  --btn: #2563EB; --btn-hover: #1D4ED8; --btn-fg: #FFFFFF;
  --cover: #2563EB; --cover-2: #1E3A8A;
  --side-bg: #0F172A;
  --lift: 0 1px 2px rgb(15 23 42 / 0.05), 0 14px 32px -16px rgb(15 23 42 / 0.28);
  --r-xl: 22px; --r-l: 16px; --r-m: 12px; --r-s: 10px;
  --display: "Funnel Display", "Hanken Grotesk", system-ui, sans-serif;
  --font: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --side-w: 68px;
  --top-h: 56px;             /* kept in step with the real bar height by app.js */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #1C1F24; --paper-2: #20242A; --sheet: #262A31; --sunk: #2E333B; --ink: #E6E8EC; --ink-2: #C1C5CD; --muted: #969CA8;
    --rule: #383D47; --rule-soft: #2F343C; --brand: #60A5FA; --brand-soft: #23364F;
    --recv: #60A5FA; --recv-soft: #23364F; --spend: #969CA8; --spend-ink: #C8CDD6; --spend-soft: #353A43; --spend-dim: #555C68;
    --owe: #F87171; --owe-soft: #4A2020; --focus: #60A5FA;
    --btn: #3B82F6; --btn-hover: #60A5FA; --btn-fg: #FFFFFF;
    --cover: #1E40AF; --cover-2: #172554; --side-bg: #16181D;
    --lift: 0 14px 32px -16px rgb(0 0 0 / 0.7); --seg-on: #414854;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1C1F24; --paper-2: #20242A; --sheet: #262A31; --sunk: #2E333B; --ink: #E6E8EC; --ink-2: #C1C5CD; --muted: #969CA8;
  --rule: #383D47; --rule-soft: #2F343C; --brand: #60A5FA; --brand-soft: #23364F;
  --recv: #60A5FA; --recv-soft: #23364F; --spend: #969CA8; --spend-ink: #C8CDD6; --spend-soft: #353A43; --spend-dim: #555C68;
  --owe: #F87171; --owe-soft: #4A2020; --focus: #60A5FA;
  --btn: #3B82F6; --btn-hover: #60A5FA; --btn-fg: #FFFFFF;
  --cover: #1E40AF; --cover-2: #172554; --side-bg: #16181D;
  --lift: 0 14px 32px -16px rgb(0 0 0 / 0.7); --seg-on: #414854;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top-h) + 16px); }
/* no pinch / double-tap zoom: it's an app, not a page */
html, body { touch-action: pan-x pan-y; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 15px/1.5 var(--font); font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-family: var(--display); font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
h2 { font-size: 1.02rem; }
code { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 0.85em; background: var(--rule-soft); padding: 1px 6px; border-radius: 5px; word-break: break-all; }
kbd { font: 600 0.72rem var(--font); padding: 1px 6px; border-radius: 5px; border: 1px solid currentColor; opacity: 0.75; }
a { color: inherit; }
summary { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* loading bar: shows only while a page is fetching */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 40; pointer-events: none; opacity: 0; transition: opacity .15s; overflow: hidden; }
.progress::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--brand); border-radius: 3px; }
body.loading .progress { opacity: 1; }
@media (prefers-reduced-motion: no-preference) {
  body.loading .progress::after { animation: slide 1s ease-in-out infinite; }
  @keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
}
body.loading main { cursor: progress; }

/* ---------- controls ---------- */
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--sheet);
  border: 1px solid var(--rule); border-radius: var(--r-s);
  padding: 9px 12px; width: 100%; min-height: 44px;
}
select { cursor: pointer; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
textarea { resize: vertical; }
label { display: grid; gap: 5px; font-size: 0.86rem; color: var(--ink-2); font-weight: 500; }
label.check { display: flex; align-items: center; gap: 9px; font-weight: 400; cursor: pointer; }
label.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--btn); flex: none; }
.btn {
  font: 600 0.92rem var(--font); color: var(--ink); background: var(--sheet);
  border: 1px solid var(--rule); border-radius: var(--r-s);
  padding: 8px 16px; min-height: 44px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn .ic { width: 17px; height: 17px; }
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--btn); color: var(--btn-fg); border-color: var(--btn); }
.btn.primary:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.btn.small { min-height: 34px; padding: 4px 12px; font-size: 0.84rem; border-radius: 9px; }
.btn.danger { color: var(--owe); border-color: color-mix(in srgb, var(--owe) 35%, transparent); }
.btn.danger:hover { background: var(--owe-soft); }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; color: var(--ink); background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; }
.icon-btn:hover { background: var(--rule-soft); }
.link { font: 600 0.86rem var(--font); color: var(--recv); background: none; border: 0; padding: 2px 4px; cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--owe); }
.link.small { font-size: 0.8rem; justify-self: start; padding: 0; }
.linkish { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row.gap { margin-top: 16px; }
.grow { flex: 1 1 140px; }
.stack { display: grid; gap: 12px; }
.hint { color: var(--muted); font-size: 0.86rem; margin: 2px 0 12px; }
.hint-inline { color: var(--muted); font-size: 0.8rem; text-align: right; }
.result { margin: 0; font-size: 0.9rem; min-height: 1.2em; }
.result:empty { display: none; }
.result.bad, .error { color: var(--owe); }
.empty { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }
.meta { color: var(--muted); font-size: 0.82rem; }
.blur { filter: blur(4px); user-select: none; }

/* one switch, used for entry type, card basis and appearance */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; padding: 3px; background: var(--rule-soft); border-radius: var(--r-m); }
.seg.two { grid-template-columns: 1fr 1fr; margin: 12px 0 10px; }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg label { display: block; color: var(--ink-2); }
.seg input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; min-height: 0; padding: 0; }
.seg span { display: block; text-align: center; padding: 8px 4px; cursor: pointer; font-weight: 600; font-size: 0.86rem; border-radius: 9px; line-height: 1.25; }
.seg input:checked + span { background: var(--seg-on, var(--sheet)); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.14); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font: 700 1.2rem var(--display); letter-spacing: -0.02em; text-decoration: none; color: var(--ink); }
.brand.big { font-size: 2rem; }
/* a closed passbook: blue cover, white ribbon */
.mark { width: 24px; height: 28px; border-radius: 4px 7px 7px 4px; background: var(--mark, var(--cover)); position: relative; flex: none; box-shadow: inset 3px 0 0 rgb(0 0 0 / 0.22); }
.mark::after { content: ""; position: absolute; right: 5px; top: 0; width: 5px; height: 12px; background: var(--ribbon, #FFFFFF); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); }
.brand.big .mark { width: 36px; height: 42px; border-radius: 5px 9px 9px 5px; }
.brand.big .mark::after { width: 7px; height: 18px; right: 8px; }

/* banknote rings, shared by the cover and the login screen */
.hero, .login {
  background:
    repeating-radial-gradient(circle at 100% 0, transparent 0 17px, rgb(255 255 255 / 0.05) 17px 18px),
    repeating-radial-gradient(circle at 78% -30%, transparent 0 23px, rgb(255 255 255 / 0.035) 23px 24px),
    linear-gradient(150deg, var(--cover), var(--cover-2));
}

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 16px; padding: 30px 24px; background: var(--sheet); border-radius: var(--r-xl); box-shadow: 0 30px 60px -30px rgb(0 0 0 / 0.6); }
.login-card p { margin: 0; color: var(--muted); }

/* ---------- shell: phone first ---------- */
.shell { min-height: 100dvh; }
.side { display: none; }
.main { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title switch" "crumbs crumbs";
  align-items: center; column-gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 14px 8px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.page-title { grid-area: title; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.month-switch { grid-area: switch; display: flex; align-items: center; background: var(--sheet); border-radius: 999px; padding: 3px; box-shadow: 0 0 0 1px var(--rule); }
.month-switch .icon-btn { width: 34px; height: 34px; }
.month-label { font: 600 0.9rem var(--font); color: var(--ink); background: none; border: 0; padding: 6px 4px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.month-label:hover { color: var(--recv); }
.add-top { grid-area: add; display: none; }
/* app.js hides the switch on pages with no month; give its room back to the title */
.month-switch[style*="hidden"] { display: none; }
.crumbs { grid-area: crumbs; display: none; flex-wrap: wrap; align-items: center; gap: 2px 4px; min-width: 0; margin-top: 6px; font-size: 0.8rem; color: var(--muted); line-height: 1.3; }
/* on a phone the tabs say where you are; the trail shows only once you've drilled into a filter */
.crumbs:has(> :nth-child(6)) { display: flex; }
.crumbs a { color: var(--muted); text-decoration: none; padding: 2px 4px; margin: -2px -4px; border-radius: 5px; }
.crumbs a:hover, .crumbs a:focus-visible { color: var(--ink); background: var(--rule-soft); }
.crumbs [aria-current] { color: var(--ink); font-weight: 600; max-width: 24ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb-sep { opacity: 0.6; padding: 0 2px; }
main { padding: 8px 14px calc(104px + env(safe-area-inset-bottom)); margin: 0 auto; }
.view { display: grid; gap: 12px; }

/* bottom tabs: four places and a raised Add in the middle */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: start;
  background: color-mix(in srgb, var(--sheet) 92%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: 0 -1px 0 var(--rule);
  padding: 0 4px env(safe-area-inset-bottom);
}
.tabbar > a, .tab-more {
  font: 600 0.68rem var(--font); color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer;
  padding: 8px 2px 7px; display: grid; justify-items: center; gap: 4px; position: relative; isolation: isolate;
}
.tabbar > a .ic, .tab-more .ic { width: 22px; height: 22px; margin: 4px 0; }
.tabbar > a::before, .tab-more::before { content: ""; position: absolute; z-index: -1; top: 7px; left: 50%; width: 56px; height: 32px; margin-left: -28px; border-radius: 16px; background: var(--brand-soft); opacity: 0; transform: scaleX(0.6); transition: opacity .15s, transform .2s; }
.tabbar > a[aria-current="page"], .tabbar:has(.more-menu a[aria-current="page"]) .tab-more { color: var(--ink); }
.tabbar > a[aria-current="page"]::before, .tabbar:has(.more-menu a[aria-current="page"]) .tab-more::before { opacity: 1; transform: none; }
.tabbar > a[aria-current="page"] .ic { color: var(--recv); stroke-width: 2.1; }
.tabbar > a .badge { position: absolute; top: 5px; left: calc(50% + 8px); }
.tabbar:has(.more-menu .badge:not([hidden])) .tab-more::after { content: ""; position: absolute; top: 9px; left: calc(50% + 10px); width: 9px; height: 9px; border-radius: 50%; background: var(--owe); box-shadow: 0 0 0 2px var(--sheet); }
.tab-add {
  justify-self: center; width: 56px; height: 56px; margin-top: -16px; border-radius: 50%; border: 4px solid var(--paper);
  display: grid; place-items: center; background: var(--btn); color: var(--btn-fg); cursor: pointer;
  box-shadow: 0 10px 20px -8px color-mix(in srgb, var(--cover) 70%, transparent);
}
.tab-add .ic { width: 24px; height: 24px; stroke-width: 2.2; }
.tab-add:active { transform: scale(0.94); }
.more-menu {
  position: fixed; inset: auto 10px calc(74px + env(safe-area-inset-bottom)) auto; margin: 0; padding: 6px; min-width: 210px;
  border: 0; border-radius: 18px; background: var(--sheet); color: var(--ink); box-shadow: 0 0 0 1px var(--rule), var(--lift);
}
.more-menu:popover-open { display: grid; gap: 2px; }
.more-menu.open { display: grid; gap: 2px; }
@supports not selector(:popover-open) { .more-menu:not(.open) { display: none; } }
.more-menu a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; font: 600 0.95rem var(--font); text-decoration: none; }
.more-menu a .ic { color: var(--muted); }
.more-menu a[aria-current="page"] { background: var(--brand-soft); }
.more-menu a[aria-current="page"] .ic { color: var(--recv); }
.more-menu .badge { margin-left: auto; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--owe); color: #fff; font-size: 0.68rem; font-weight: 700; line-height: 18px; text-align: center; }
:root[data-theme="dark"] .badge { color: #2A0A0A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge { color: #2A0A0A; } }

/* ---------- panels ---------- */
.panel { background: var(--sheet); border-radius: var(--r-l); padding: 16px; min-width: 0; }
.panel > h2 { margin-bottom: 12px; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; margin-bottom: 12px; }
.panel-head .legend { flex: none; }
.panel-head .link { margin-right: -4px; }
.panel-head select { width: auto; min-height: 34px; padding: 4px 10px; margin: -7px 0; }
.dash, .dash-main, .dash-side, .dash-pair { display: grid; gap: 12px; min-width: 0; align-content: start; }
@media (max-width: 1099px) { .dash-side { order: 1; } }

/* ---------- the cover: the month in one line ---------- */
.hero {
  /* inside the cover every colour is re-pointed, so the same markup reads on green */
  --ink: #FFFFFF; --ink-2: rgb(255 255 255 / 0.84); --muted: rgb(255 255 255 / 0.68);
  --rule: rgb(255 255 255 / 0.16); --recv: #DBEAFE; --owe: #FECACA; --focus: #FFFFFF;
  display: grid; color: var(--ink); border-radius: var(--r-xl); box-shadow: var(--lift); overflow: hidden;
}
.hero-main { padding: 20px 20px 18px; display: grid; gap: 4px; min-width: 0; }
.hero-line { margin: 0; display: grid; gap: 4px; justify-items: start; }
.hero-lbl { font: 500 0.95rem var(--font); color: var(--ink-2); }
.fig {
  font: 700 clamp(2.5rem, 12vw, 3.5rem)/1 var(--display); letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.fig .fig-cur { font-family: var(--font); font-size: 0.34em; font-weight: 600; letter-spacing: 0; color: var(--muted); margin-right: 0.2em; vertical-align: 0.55em; }
a.fig:hover { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 6px; text-decoration-color: #FFFFFF; }
.hero-of { margin: 4px 0 0; font: 400 0.98rem/1.4 var(--font); color: var(--ink-2); }
.hero-of a { color: var(--recv); font-weight: 700; text-decoration: none; white-space: nowrap; }
.hero-of a:hover { text-decoration: underline; text-underline-offset: 3px; }
.gauge { position: relative; height: 10px; border-radius: 5px; background: rgb(255 255 255 / 0.18); margin: 16px 0 8px; overflow: hidden; }
.gauge > span { position: absolute; top: 0; bottom: 0; left: 0; background: #FFFFFF; border-radius: 5px; }
.gauge.over { background: #FFFFFF; }
.gauge.over > span { background: repeating-linear-gradient(-45deg, #FCA5A5 0 5px, #DC2626 5px 10px); left: auto; right: 0; border-radius: 0 5px 5px 0; }
.gauge-legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 16px; font-size: 0.86rem; color: var(--muted); }
.gauge-legend b { color: var(--ink); font-weight: 650; }
.gauge-legend .neg b { color: var(--owe); }
/* the forecast line on the cover: one tappable row under the gauge */
.left-line { display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 14px; padding: 11px 12px 11px 14px; border: 0; border-radius: var(--r-m); background: rgb(255 255 255 / 0.12); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.left-line:hover { background: rgb(255 255 255 / 0.18); }
.left-line span { flex: 1; min-width: 0; color: var(--ink-2); font-size: 0.92rem; }
.left-line b { font: 700 1.15rem var(--display); white-space: nowrap; }
.left-line b.owe { color: var(--owe); }
.left-line .ic { width: 16px; height: 16px; color: var(--muted); }
.hero-side { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); border-top: 1px solid var(--rule); background: rgb(0 0 0 / 0.14); }
.tile { display: grid; gap: 1px; padding: 13px 20px; text-decoration: none; color: inherit; min-width: 0; }
.tile + .tile { border-left: 1px solid var(--rule); }
a.tile:hover { background: rgb(255 255 255 / 0.07); }
.tile .t-lbl { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.tile b { font: 700 1.25rem var(--display); letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile b.owe { color: var(--owe); }
.tile b.recv { color: var(--recv); }
.tile small { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- charts ---------- */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--spend); }
.chart .bar.dim { fill: var(--spend-dim); }
.chart .bar.on, .chart .bar:hover { fill: var(--spend-ink); }
.chart .bar.income { fill: var(--recv); }
.chart .bar.spent { fill: var(--spend); }
.chart .bar.income.on, .chart .bar.income:hover { fill: color-mix(in srgb, var(--recv) 70%, var(--ink)); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:focus-visible { outline: none; fill: color-mix(in srgb, var(--focus) 10%, transparent); }
.chart .axis { fill: var(--muted); font: 500 11px var(--font); }
.chart .axis.sel { fill: var(--ink); font-weight: 700; }
.chart .grid { stroke: var(--rule-soft); stroke-width: 1; }
.chart .base { stroke: var(--rule); stroke-width: 1; }
.legend { display: flex; gap: 10px; align-items: center; font-size: 0.76rem; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 3px; vertical-align: -1px; }
.lg-paid, .lg-income { background: var(--recv); }
.lg-spent { background: var(--spend); }
.lg-due { background: var(--owe); }
.lg-exp { border: 1.5px dashed var(--ink-2); }

/* ---------- category and source rows ---------- */
/* rows carry 6px of side padding for their hover fill; pull the lists out by the same amount
   so icons and text line up with the panel heading above them */
.cats, .mini-ledger, #merchants, #month-bills, #bills-monthly, #subs { margin-inline: -6px; }
.cats { display: grid; gap: 2px; }
.cat { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 0 12px; align-items: center; background: none; border: 0; padding: 8px 6px; border-radius: var(--r-m); font: inherit; color: inherit; text-align: left; cursor: pointer; width: 100%; }
.cat:hover { background: var(--sunk); }
.cat-ic, .row-ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--rule-soft); color: var(--ink-2); }
.cat-ic.in, .row-ic.in { background: var(--recv-soft); color: var(--recv); }
.cat-ic.mv, .row-ic.mv { color: var(--muted); }
.cat-ic .ic, .row-ic .ic { width: 18px; height: 18px; }
.cat .name { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; min-width: 0; }
.cat .name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat .name small { color: var(--muted); font-weight: 500; flex: none; }
.cat .val { font-weight: 650; text-align: right; white-space: nowrap; }
.cat .delta { display: block; font-size: 0.74rem; font-weight: 600; text-align: right; }
.delta.up { color: var(--owe); }
.delta.down { color: var(--recv); }
.delta.flat { color: var(--muted); }
.cat .track { display: block; height: 5px; border-radius: 3px; background: var(--rule-soft); overflow: hidden; margin-top: 6px; }
.cat .fill { display: block; height: 100%; background: var(--spend); border-radius: 3px; }
.cat .fill.income { background: var(--recv); }
.more-cats { display: block; margin: 6px 6px 0; }

/* income sources open in place */
.src > summary { list-style: none; }
.src > summary::-webkit-details-marker { display: none; }
.src .chev { width: 16px; height: 16px; color: var(--muted); transition: transform .15s; vertical-align: -3px; margin-left: 2px; }
.src[open] .chev { transform: rotate(90deg); }
.src[open] > summary { background: var(--sunk); border-radius: var(--r-m) var(--r-m) 0 0; }
.src-items { background: var(--sunk); border-radius: 0 0 var(--r-m) var(--r-m); padding: 2px 6px 6px 54px; margin-bottom: 4px; }
.src-item { display: grid; grid-template-columns: 4.2em minmax(0, 1fr) auto; gap: 10px; align-items: baseline; width: 100%; padding: 8px 6px; border: 0; border-top: 1px solid var(--rule); background: none; font: inherit; font-size: 0.88rem; color: inherit; text-align: left; cursor: pointer; border-radius: 6px; }
.src-item:first-child { border-top: 0; }
.src-item:hover { background: var(--sheet); }
.src-item .d { color: var(--muted); }
.src-item .w { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-item .a { color: var(--recv); font-weight: 650; white-space: nowrap; }

/* ---------- list rows (merchants, mini ledger, bills) ---------- */
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 6px; border: 0; border-bottom: 1px solid var(--rule-soft); width: 100%; background: none; font: inherit; color: inherit; text-align: left; }
.list-row:last-child { border-bottom: 0; }
button.list-row { cursor: pointer; border-radius: 8px; }
button.list-row:hover { background: var(--sunk); }
.mini-ledger .entry { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px 6px; border-radius: var(--r-m); cursor: pointer; background: none; border: 0; width: 100%; font: inherit; color: inherit; text-align: left; }
.mini-ledger .entry:hover { background: var(--sunk); }
.entry .who { min-width: 0; }
.entry .who b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .who b .kind-ic { margin-right: 6px; vertical-align: -4px; }
.entry .amount { font-weight: 650; text-align: right; white-space: nowrap; }
.amount.credit { color: var(--recv); }
.amount.moved { color: var(--muted); font-weight: 500; }

/* status tags */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 0.74rem; font-weight: 600; line-height: 1.6; white-space: nowrap; background: var(--owe-soft); color: var(--owe); }
.tag .ic { width: 13px; height: 13px; stroke-width: 2.4; }
.tag.paid { background: var(--recv-soft); color: var(--recv); }
.tag.soft { background: var(--rule-soft); color: var(--ink-2); }

.mb { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 9px 6px; border: 0; border-bottom: 1px solid var(--rule-soft); width: 100%; background: none; font: inherit; color: inherit; text-align: left; }
.mb:last-child { border-bottom: 0; }
button.mb { cursor: pointer; border-radius: 8px; }
button.mb:hover { background: var(--sunk); }
.mb .who { min-width: 0; }
.mb .who b { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mb .right { text-align: right; display: grid; gap: 3px; justify-items: end; }
.mb .right strong { font-weight: 650; }
.mb-total { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px; margin: 0 6px 6px; border-radius: var(--r-m); background: var(--sunk); font-size: 0.86rem; }
.mb-total b { font-weight: 700; }

.bill { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--rule-soft); align-items: center; }
.bill:last-child { border-bottom: 0; }
.bill .amt { font-weight: 700; text-align: right; }
.bill .actions { grid-column: 1 / -1; display: flex; gap: 8px; }

/* ---------- ledger ---------- */
.toolbar { display: grid; gap: 10px; }
.toolbar-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar-row select { width: auto; flex: 1 1 140px; max-width: 240px; }
.search { position: relative; display: block; }
.search .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.search input { padding-left: 42px; border-radius: 999px; border-color: transparent; box-shadow: 0 0 0 1px var(--rule); }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 1px 14px; }
.chips::-webkit-scrollbar { display: none; }
.chips button { font: 600 0.86rem var(--font); color: var(--ink-2); background: var(--sheet); border: 1px solid var(--rule); border-radius: 999px; padding: 7px 16px; cursor: pointer; white-space: nowrap; }
.chips button:hover { border-color: var(--muted); }
.chips button[aria-pressed="true"] { background: var(--btn); color: var(--btn-fg); border-color: var(--btn); }
.filter-chip { display: inline-flex; align-items: center; gap: 6px; font: 600 0.82rem var(--font); color: var(--btn-fg); background: var(--btn); border: 0; border-radius: 999px; padding: 7px 12px; cursor: pointer; }
.filter-chip .ic { width: 14px; height: 14px; }

.ledger { background: var(--sheet); border-radius: var(--r-l); overflow: clip; }
.lg-head { display: none; }
.lg-day { display: flex; justify-content: space-between; padding: 7px 14px; font-size: 0.78rem; font-weight: 650; color: var(--muted); background: var(--sunk); border-bottom: 1px solid var(--rule-soft); position: sticky; top: var(--top-h); z-index: 1; }
.lg-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--rule-soft); cursor: pointer; }
.lg-row:hover { background: var(--sunk); }
.lg-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 0; }
.lg-row .c-desc { min-width: 0; display: grid; gap: 3px; }
.d-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.d-top b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.d-sub { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; padding-left: 28px; font-size: 0.78rem; color: var(--muted); min-width: 0; }
.d-sub > span { min-width: 0; flex: none; }
.d-sub > .d-mob, .d-sub > .d-info { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-info { max-width: 100%; }
.lg-row .c-cat, .lg-row .c-acct { display: none; }
.lg-row .c-amt { text-align: right; font-weight: 650; white-space: nowrap; }
.lg-row .c-amt.income { color: var(--recv); }
.lg-row .c-amt.transfer, .lg-row .c-amt.bill { color: var(--muted); font-weight: 500; }
.fx { display: block; color: var(--muted); font-size: 0.74rem; font-weight: 400; }
.flag { display: inline-block; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--owe); }
/* which way the money went */
.kind-ic { display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; border-radius: 6px; color: var(--muted); }
.kind-ic .ic { width: 13px; height: 13px; stroke-width: 2.5; }
.kind-ic.expense { color: var(--spend-ink); background: var(--spend-soft); }
.kind-ic.income { color: var(--recv); background: var(--recv-soft); }
.srcs { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.src-chip { font: 600 0.66rem/1 var(--font); color: var(--ink-2); background: var(--rule-soft); border: 1px solid transparent; border-radius: 999px; padding: 3px 8px; cursor: pointer; }
.src-chip:hover { border-color: var(--muted); }
.src-chip.stmt { background: var(--recv-soft); color: var(--recv); }
.src-chip.static { cursor: default; }
.src-chip.static:hover { border-color: transparent; }
.ledger-foot { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: flex-end; color: var(--muted); font-size: 0.86rem; padding: 2px 4px; }
.ledger-foot b { color: var(--ink); }
.more { display: block; width: 100%; padding: 14px; border: 0; background: var(--sunk); color: var(--recv); font: 600 0.9rem var(--font); cursor: pointer; }
.empty-state { padding: 32px 18px; text-align: center; display: grid; gap: 10px; justify-items: center; color: var(--muted); }
.empty-state .ic { width: 30px; height: 30px; color: var(--rule); stroke-width: 1.5; }

/* ---------- bills: calendar ---------- */
.bills-layout, .inbox-layout { display: grid; gap: 12px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--rule-soft); border: 1px solid var(--rule-soft); border-radius: var(--r-m); overflow: hidden; }
.cal-dow { font-size: 0.72rem; font-weight: 650; color: var(--muted); padding: 6px; background: var(--sunk); text-align: center; }
.cal-day { min-height: 64px; padding: 4px; display: flex; flex-direction: column; gap: 3px; min-width: 0; background: var(--sheet); }
.cal-day.out { background: var(--sunk); }
.cal-day .n { font-size: 0.74rem; font-weight: 600; color: var(--ink-2); width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .n { background: var(--btn); color: var(--btn-fg); }
.cal-chip { font: 650 0.68rem/1.25 var(--font); padding: 2px 5px; border-radius: 5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border: 0; text-align: left; cursor: pointer; background: none; color: inherit; }
.cal-chip.paid { background: var(--recv-soft); color: var(--recv); }
.cal-chip.unpaid, .cal-chip.late { background: var(--owe-soft); color: var(--owe); }
.cal-chip.expected, .cal-chip.later { border: 1.5px dashed var(--rule); color: var(--ink-2); }
@media (max-width: 599px) {
  .cal-day { min-height: 48px; align-items: center; }
  .cal-chip { font-size: 0; padding: 0; height: 6px; width: 100%; border-radius: 3px; }
  .cal-chip.paid { background: var(--recv); }
  .cal-chip.unpaid, .cal-chip.late { background: var(--owe); }
  .cal-chip.expected, .cal-chip.later { border: 1.5px dashed var(--ink-2); height: 6px; }
}

/* ---------- inbox ---------- */
.msg { padding: 12px 0; border-bottom: 1px solid var(--rule-soft); display: grid; gap: 6px; }
.msg:last-child { border-bottom: 0; }
.msg .head { display: flex; justify-content: space-between; gap: 8px; font-size: 0.82rem; color: var(--muted); }
.msg .head b { color: var(--ink-2); }
.msg .text { white-space: pre-wrap; word-break: break-word; font-size: 0.9rem; max-height: 7.5em; overflow: hidden; }
.msg .why { font-size: 0.82rem; font-weight: 600; }
.msg .why.failed { color: var(--owe); }
.msg .why.parsed { color: var(--recv); }
.msg .why.ignored, .msg .why.matched { color: var(--muted); }
.msg .actions { display: flex; gap: 6px; flex-wrap: wrap; }
#paste-form select { width: auto; }

/* ---------- setup ----------
   Grouped like a phone's Settings: a section title with one plain sentence under it,
   then a card of rows. Rules come first because they're the screen's main job. */
.setup { display: grid; gap: 20px; max-width: 760px; margin: 0 auto; width: 100%; }
.setup-index { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 1px 14px 2px; }
.setup-index::-webkit-scrollbar { display: none; }
.setup-index button { flex: none; font: 600 0.84rem var(--font); color: var(--ink-2); background: var(--sheet); border: 1px solid var(--rule); border-radius: 999px; padding: 7px 14px; cursor: pointer; }
.setup-index button:hover { color: var(--ink); border-color: var(--muted); }
.setup-body { display: grid; gap: 28px; min-width: 0; }
.sgroup { display: grid; gap: 10px; scroll-margin-top: calc(var(--top-h) + 16px); min-width: 0; }
.sgroup-head h2 { font-size: 1.25rem; letter-spacing: -0.02em; }
.sgroup-head p { margin: 3px 0 0; color: var(--muted); font-size: 0.88rem; max-width: 62ch; }

.scard { background: var(--sheet); border-radius: var(--r-l); padding: 4px 16px; min-width: 0; }
.scard.stack { padding: 16px; }
.scard.flush { padding: 0; overflow: hidden; }
.scard-head { padding: 12px 0 4px; }
.scard-head h3 { font-size: 0.95rem; }
.scard-head p, .scard-note { margin: 2px 0 0; color: var(--muted); font-size: 0.84rem; line-height: 1.45; }
.scard > .scard-note { padding: 0 0 12px; }

/* label | value | action rows */
.srow { display: grid; grid-template-columns: minmax(84px, auto) minmax(0, 1fr) auto; align-items: center; gap: 4px 12px; padding: 12px 0; border-top: 1px solid var(--rule-soft); min-width: 0; }
.scard > .srow:first-child, .scard-head + div > .srow:first-child { border-top: 0; }
.srow-label { color: var(--muted); font-size: 0.86rem; }
.srow-value { min-width: 0; overflow-wrap: anywhere; }
code.srow-value { background: none; padding: 0; font-size: 0.82rem; }
.srow-acts { display: flex; gap: 2px; }
.srow > .link, .srow-acts { margin-right: -4px; }   /* link text, not its padding, meets the card edge */
.srow-end { grid-template-columns: minmax(0, 1fr) auto; }
.srow > .seg { grid-column: 2 / -1; justify-self: end; width: min(100%, 340px); }
#rules .srow { grid-template-columns: minmax(0, 1fr) auto auto; }

/* rules */
.prule { border-top: 1px solid var(--rule-soft); }
.prule:first-child { border-top: 0; }
.prule > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 16px; min-height: 56px; }
.prule > summary::-webkit-details-marker { display: none; }
.prule > summary:hover, .prule[open] > summary { background: var(--sunk); }
.pr-sum { flex: 1; min-width: 0; display: grid; gap: 3px; }
.pr-when { color: var(--muted); font-size: 0.82rem; overflow-wrap: anywhere; }
.pr-then { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.pr-then::before { content: ""; width: 10px; height: 10px; border-left: 1.5px solid var(--brand); border-bottom: 1.5px solid var(--brand); border-bottom-left-radius: 3px; margin: -6px 0 0 2px; flex: none; }
.pr-then b { font-weight: 650; }
.pr-tag { font-size: 0.75rem; font-weight: 600; color: var(--recv); background: var(--recv-soft); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.pr-tag.off { color: var(--muted); background: var(--rule-soft); }
.pr-chev { width: 16px; height: 16px; color: var(--muted); transition: transform .15s; }
.prule[open] .pr-chev { transform: rotate(90deg); }
.pr-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 4px 16px 16px; background: var(--sunk); }
.pr-fields label { display: grid; gap: 4px; font-size: 0.8rem; font-weight: 600; color: var(--ink-2); min-width: 0; }
.pr-fields input, .pr-fields select { min-width: 0; }
.pr-group { grid-column: 1 / -1; margin: 8px 0 -4px; font: 650 0.86rem var(--display); color: var(--ink); }
.pr-name { grid-column: 1 / -1; }
.pr-del { grid-column: 1 / -1; justify-self: start; margin-top: 4px; }
.prule-list > .empty { padding: 16px; margin: 0; }
.prule-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.prule-bar .btn.primary { margin-left: auto; }
.prule-dirty { font-size: 0.84rem; font-weight: 600; color: var(--recv); }
@media (min-width: 640px) {
  .pr-fields { grid-template-columns: 1.4fr 1fr 0.8fr 0.8fr; }
  .pr-name { grid-column: span 2; }
}

.billing-help summary, .guides summary, .advanced summary, .pw summary { font-weight: 600; font-size: 0.9rem; }
.billing-help { font-size: 0.86rem; }
.billing-help summary { color: var(--recv); width: max-content; }
.billing-help dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 10px 0 0; padding: 14px 16px; background: var(--sheet); border-radius: var(--r-l); }
.billing-help dt { font-weight: 600; }
.billing-help dd { margin: 0; color: var(--ink-2); }
.remembered { margin-top: 6px; }
.remembered #rules { padding-bottom: 4px; }
.guides { padding: 0 16px; }
.guides details, .scard .pw { border-top: 1px solid var(--rule-soft); padding: 14px 0; }
.guides details:first-child, .scard .pw:first-child { border-top: 0; }
.guides details[open] summary, .pw[open] summary { margin-bottom: 4px; }
.pw form { padding-top: 8px; }
.advanced summary { color: var(--ink-2); }
.advanced .stack { margin-top: 10px; }
.steps { padding-left: 1.3em; margin: 10px 0 0; display: grid; gap: 8px; max-width: 72ch; font-size: 0.9rem; }
.scard .row .result { flex: 1 1 100%; }
.app-version { margin-top: 12px; }

/* ---------- entry sheet ---------- */
.sheet { border: 0; padding: 0; background: var(--sheet); color: var(--ink); max-height: calc(100dvh - 16px); overflow-y: auto; overflow-x: hidden; box-shadow: var(--lift); }
.sheet .row > label { min-width: 0; }
.sheet input[type=datetime-local] { min-width: 0; max-width: 100%; }
.sheet::backdrop { background: rgb(8 15 30 / 0.55); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.sheet form, .src-dialog > .stack { padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet .sheet-head form { padding: 0; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--rule); margin: -4px auto 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { font-size: 1.25rem; }
.sheet-head h2:focus { outline: none; }   /* focus lands on the title when a sheet opens, not on Close */
.sheet-head .icon-btn { background: var(--rule-soft); width: 34px; height: 34px; }
.cur { width: 5.5em; text-transform: uppercase; }
.original { background: var(--sunk); border: 1px dashed var(--rule); border-radius: var(--r-s); padding: 10px; font-size: 0.84rem; white-space: pre-wrap; word-break: break-word; color: var(--ink-2); }
.original img { max-width: 100%; border-radius: 6px; margin-top: 8px; }
.sheet:not(.is-bill) .bill-only { display: none; }
.sheet:not(.is-credit) .instalment-only { display: none; }
.sheet-actions { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); margin: 0 -18px calc(-18px - env(safe-area-inset-bottom)); padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); background: var(--sheet); box-shadow: 0 -1px 0 var(--rule-soft); }
@media (max-width: 719px) {
  .sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: calc(100dvh - env(safe-area-inset-top) - 24px); }
  .sheet-actions .btn.primary { flex: 1; }
}
@media (min-width: 720px) {
  .sheet { width: min(540px, calc(100% - 32px)); border-radius: 18px; }
  .sheet-grip { display: none; }
}

/* forecast breakdown: groups of lines that add up to the figure at the bottom */
.fc-group { margin-bottom: 14px; }
.fc-group h3 { display: flex; justify-content: space-between; gap: 12px; font: 650 0.8rem var(--font); color: var(--muted); padding: 0 2px 6px; }
.fc-group > .meta, .fc-group > .empty { margin: 6px 2px 0; }
.fc-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; background: var(--sunk); color: inherit; font: inherit; text-align: left; }
.fc-row + .fc-row { margin-top: 1px; }
.fc-group h3 + .fc-row { border-radius: var(--r-s) var(--r-s) 0 0; }
.fc-row:last-of-type { border-radius: 0 0 var(--r-s) var(--r-s); }
.fc-group h3 + .fc-row:last-of-type { border-radius: var(--r-s); }
button.fc-row { cursor: pointer; }
button.fc-row:hover { background: var(--rule-soft); }
.fc-what { flex: 1; min-width: 0; display: grid; }
.fc-what b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-what small { color: var(--muted); font-size: 0.8rem; }
.fc-row.late .fc-what small { color: var(--owe); }
.fc-amt { font-weight: 650; white-space: nowrap; }
.fc-row > .ic { width: 15px; height: 15px; color: var(--muted); }
.fc-total { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 14px 2px 2px; border-top: 2px solid var(--rule); font-weight: 600; }
.fc-total b { font: 700 1.5rem var(--display); color: var(--recv); }
.fc-total.neg b { color: var(--owe); }

/* source popup */
.src-dialog .sheet-head { align-items: flex-start; }
.src-dialog .sheet-head .meta { margin: 2px 0 0; }
.src-block { border: 1px solid var(--rule); border-radius: var(--r-m); padding: 12px; display: grid; gap: 8px; margin-bottom: 10px; }
.src-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.src-head .meta { margin-left: auto; }
.src-text { white-space: pre-wrap; word-break: break-word; font-size: 0.9rem; background: var(--sunk); border-radius: var(--r-s); padding: 10px; }
.src-block img { max-width: 100%; border-radius: var(--r-s); }
.stmt-line { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: baseline; font-size: 0.9rem; background: var(--sunk); border-radius: var(--r-s); padding: 10px; }
.stmt-line span:first-child { color: var(--muted); white-space: nowrap; }
.stmt-line span:last-child { font-weight: 650; white-space: nowrap; }
.stmt-line span.in { color: var(--recv); }

.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--ink); color: var(--paper); font-size: 0.8rem; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; background: var(--ink); color: var(--paper); padding: 11px 18px; border-radius: 999px; font-size: 0.9rem; font-weight: 500; max-width: calc(100% - 32px); box-shadow: var(--lift); }
.update-bar { position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 40; display: flex; align-items: center; gap: 10px; background: var(--ink); color: var(--paper); padding: 8px 8px 8px 16px; border-radius: 14px; font-size: 0.9rem; max-width: calc(100% - 32px); box-shadow: var(--lift); }
.update-bar .btn { padding: 4px 12px; min-height: 34px; }
#update-msg { white-space: nowrap; }

/* ---------- year ---------- */
.year-switch { display: flex; align-items: center; justify-content: center; gap: 6px; }
.year-switch h2 { font-size: 1.5rem; min-width: 5ch; text-align: center; letter-spacing: -0.02em; }
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.year-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.year-table th, .year-table td { padding: 10px; border-bottom: 1px solid var(--rule-soft); text-align: right; white-space: nowrap; }
.year-table th:first-child, .year-table td:first-child { text-align: left; }
.year-table th { font-size: 0.78rem; color: var(--muted); font-weight: 650; background: var(--sunk); }
.year-table th:first-child { border-radius: 8px 0 0 8px; }
.year-table th:last-child { border-radius: 0 8px 8px 0; }
.year-table tr.month-row { cursor: pointer; }
.year-table tr.month-row:hover td { background: var(--sunk); }
.year-table td.in { color: var(--recv); font-weight: 600; }
.year-table td.neg { color: var(--owe); }
.year-table tfoot td { font-weight: 700; border-top: 2px solid var(--rule); border-bottom: 0; }
.year-table tr.future td { color: var(--muted); }

/* ---------- accounts: cards drawn as cards, accounts as a list ---------- */
#accounts { display: grid; gap: 16px; max-width: 980px; }
.acct-tabs { display: flex; gap: 3px; padding: 3px; border-radius: var(--r-m); background: var(--rule-soft); justify-self: start; }
.acct-tabs button { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: 600 0.88rem var(--font); color: var(--ink-2); background: none; border: 0; border-radius: 9px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.acct-tabs button .ic { width: 16px; height: 16px; }
.acct-tabs button:hover { color: var(--ink); }
.acct-tabs button[aria-selected="true"] { background: var(--seg-on, var(--sheet)); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.14); }
.tab-note { font-size: 0.74rem; font-weight: 600; color: var(--owe); }
@media (max-width: 599px) {
  .acct-tabs { justify-self: stretch; }
  .acct-tabs button { flex-wrap: wrap; gap: 0 7px; padding: 8px 6px; min-width: 0; }
  .tab-note { flex-basis: 100%; text-align: center; }
}
.acct-lede { margin: 0; font-size: 1rem; color: var(--ink-2); }
.acct-lede b { color: var(--ink); font-weight: 650; }
.acct-lede b.owe { color: var(--owe); }
.acct-lede .meta { display: block; margin-top: 2px; }
.ccs { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); align-items: start; }
.cc { display: grid; gap: 10px; }
.cc-face {
  --face: #2A3550; --face-2: #1C2438;
  aspect-ratio: 1.586; width: 100%; max-width: 400px; border: 0; border-radius: 18px; padding: 18px 20px; cursor: pointer;
  display: grid; grid-template-rows: auto auto 1fr auto; text-align: left; color: #F4F6FB; font: inherit;
  background: repeating-radial-gradient(circle at 100% 0, transparent 0 17px, rgb(255 255 255 / 0.05) 17px 18px), linear-gradient(135deg, var(--face), var(--face-2));
  box-shadow: 0 14px 28px -16px rgb(0 0 0 / 0.6), inset 0 1px 0 rgb(255 255 255 / 0.1);
}
.cc-face.combank { --face: #0D4FA3; --face-2: #062F6B; }
.cc-face.sampath { --face: #E2620E; --face-2: #9C3F05; }
.cc-face:hover { filter: brightness(1.06); }
.cc-face:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 18px; }
.cc-top { display: flex; justify-content: space-between; font: 650 0.95rem var(--display); }
.cc-kind { font: 500 0.8rem var(--font); opacity: 0.8; }
.cc-no { margin-top: 14px; font: 600 1.15rem var(--font); letter-spacing: 0.12em; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 10px; }
.cc-no small { font-size: 0.7rem; letter-spacing: 0; opacity: 0.7; }
.cc-owed { align-self: end; display: grid; }
.cc-owed small, .cc-limit small { font-size: 0.72rem; opacity: 0.75; }
.cc-owed .fig { display: block; color: #fff; font-size: clamp(1.6rem, 6vw, 2.1rem); line-height: 1.05; }
.cc-owed .fig .fig-cur { color: rgb(255 255 255 / 0.7); }
.cc-limit { display: grid; gap: 4px; margin-top: 8px; }
.cc-bar { height: 4px; border-radius: 2px; background: rgb(255 255 255 / 0.2); overflow: hidden; }
.cc-bar > span { display: block; height: 100%; background: #fff; }
.cc-info { display: grid; gap: 6px; max-width: 400px; }
.cc-plans { display: grid; border-radius: var(--r-m); overflow: hidden; background: var(--sheet); }
.plan { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--rule-soft); background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.plan:last-child { border-bottom: 0; }
.plan:hover { background: var(--sunk); }
.plan-name { display: grid; min-width: 0; font-size: 0.88rem; }
.plan-left { display: grid; text-align: right; font-weight: 650; white-space: nowrap; font-size: 0.9rem; }
.cc-foot { margin: 0; font-size: 0.82rem; color: var(--muted); }
.acct-bank { display: grid; background: var(--sheet); border-radius: var(--r-l); overflow: hidden; }
.acct-bank h2 { font: 650 0.8rem var(--font); color: var(--muted); padding: 12px 16px 4px; }
.acct-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 16px; gap: 14px; align-items: center; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--rule-soft); background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; width: 100%; }
.acct-row:last-child { border-bottom: 0; }
.acct-row:hover { background: var(--sunk); }
.acct-row > .ic { width: 16px; height: 16px; color: var(--muted); }
/* the bank balance sits under its account row and opens the working behind it */
.acct-row:has(+ .acct-bal) { border-bottom: 0; padding-bottom: 6px; }
.acct-bal { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; width: 100%; padding: 6px 16px 12px; border: 0; border-bottom: 1px solid var(--rule-soft); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.acct-bal:last-child { border-bottom: 0; }
.acct-bal:hover { background: var(--sunk); }
.acct-bal b { font: 700 1.05rem var(--display); white-space: nowrap; }
.acct-bal b.owe { color: var(--owe); }
.acct-row.fd { cursor: default; grid-template-columns: minmax(0, 1fr) auto; }
.acct-row.fd:hover { background: none; }
.acct-id { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; min-width: 0; }
.acct-id b { font-weight: 650; }
.acct-no { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.acct-cards { display: flex; flex-wrap: wrap; gap: 5px; flex-basis: 100%; }
.card-chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border: 1px solid var(--rule); border-radius: 999px; font-size: 0.74rem; color: var(--ink-2); }
.card-chip .ic { width: 13px; height: 13px; color: var(--muted); }
.card-chip.closed { opacity: 0.5; text-decoration: line-through; }
.acct-flow { display: flex; gap: 18px; }
.acct-flow > span { display: grid; text-align: right; min-width: 84px; }
.acct-flow small { font-size: 0.72rem; color: var(--muted); }
.acct-flow b { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.acct-flow b.recv { color: var(--recv); }
.acct-quiet { display: grid; text-align: right; font-size: 0.82rem; color: var(--muted); }
.acct-row.quiet .acct-id b { color: var(--ink-2); }
@media (max-width: 599px) {
  .acct-row { grid-template-columns: minmax(0, 1fr) 16px; }
  .acct-flow, .acct-quiet { grid-column: 1; grid-row: 2; justify-content: flex-start; text-align: left; }
  .acct-flow > span { text-align: left; min-width: 0; }
  .acct-row > .ic { grid-column: 2; grid-row: 1 / 3; }
}

/* motion: the gauge fills when a month loads; sheets and menus rise when you open them */
@media (prefers-reduced-motion: no-preference) {
  .sheet[open], .more-menu:popover-open { animation: rise .22s cubic-bezier(.2, .7, .2, 1); }
  @keyframes rise { from { transform: translateY(24px); opacity: 0; } }
  .gauge > span, .cc-bar > span { animation: fill .6s cubic-bezier(.2, .7, .2, 1); transform-origin: left; }
  .gauge.over > span { transform-origin: right; }
  @keyframes fill { from { transform: scaleX(0); } }
}
/* iOS zooms into any field under 16px when focused */
@media (pointer: coarse) { input, select, textarea { font-size: 16px !important; } }

/* ---------- tablet and up: a system, not a phone app ---------- */
@media (min-width: 720px) {
  body { font-size: 14px; line-height: 1.45; }
  h2 { font-size: 0.98rem; }
  input, select, textarea { min-height: 38px; padding: 7px 11px; }
  .btn { min-height: 38px; padding: 6px 14px; font-size: 0.88rem; }
  .btn.small { min-height: 30px; }
  .icon-btn { width: 36px; height: 36px; }
  .shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .tabbar { display: none; }

  .side {
    display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100dvh;
    padding: 16px 10px; background: var(--side-bg); color: #fff; box-shadow: inset -1px 0 0 rgb(255 255 255 / 0.06);
    --mark: #3B82F6; --ribbon: #FFFFFF; --focus: #93C5FD;
  }
  .side .brand { justify-content: center; margin-bottom: 18px; color: #fff; min-height: 36px; }
  .side .label, .side-foot { display: none; }
  .side-nav { display: grid; gap: 2px; }
  .side-nav a {
    display: flex; align-items: center; justify-content: center; gap: 12px; position: relative;
    font: 600 0.9rem var(--font); color: rgb(255 255 255 / 0.7); text-decoration: none; border-radius: var(--r-s); padding: 10px;
  }
  .side-nav a:hover { background: rgb(255 255 255 / 0.07); color: #fff; }
  .side-nav a[aria-current="page"] { background: rgb(255 255 255 / 0.13); color: #fff; }
  .side-nav a[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 9px; bottom: 9px; width: 4px; border-radius: 0 4px 4px 0; background: #60A5FA; }
  .side-nav .badge { position: absolute; top: 2px; right: 2px; background: #3B82F6; color: #FFFFFF; }
  .side-sep { height: 1px; margin: 8px 6px; background: rgb(255 255 255 / 0.1); }

  .top {
    grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "title switch add" "crumbs switch add";
    column-gap: 14px; padding: 10px 24px; box-shadow: 0 1px 0 var(--rule);
  }
  .page-title { font-size: 1.3rem; }
  .top:not(:has(.crumbs > :nth-child(4))) .page-title { grid-row: 1 / -1; }   /* no trail: the title takes the full bar height */
  .crumbs, .crumbs:has(> :nth-child(6)) { display: none; margin-top: 1px; }
  .crumbs:has(> :nth-child(4)) { display: flex; }   /* a trail only when there is somewhere to go back to */
  .add-top { display: inline-flex; }
  .add-top kbd { margin-left: 2px; }
  .month-switch .icon-btn { width: 30px; height: 30px; }
  .month-label { min-width: 13ch; }
  main { padding: 20px 24px 40px; }
  .view, .dash, .dash-main, .dash-side, .dash-pair, .bills-layout, .inbox-layout { gap: 14px; }

  .hero { grid-template-columns: minmax(0, 1fr) minmax(230px, 0.4fr); }
  .hero-main { padding: 26px 30px 24px; }
  .fig { font-size: 3.4rem; }
  .hero-side { grid-auto-flow: row; grid-auto-columns: auto; border-top: 0; border-left: 1px solid var(--rule); }
  .tile { padding: 16px 24px; align-content: center; }
  .tile + .tile { border-left: 0; border-top: 1px solid var(--rule); }

  .cat { grid-template-columns: 32px minmax(0, 1fr) auto; padding: 6px; }
  .cat-ic, .row-ic { width: 32px; height: 32px; border-radius: 9px; }
  .cat-ic .ic, .row-ic .ic { width: 16px; height: 16px; }
  .mb, .mini-ledger .entry { grid-template-columns: 32px minmax(0, 1fr) auto; padding: 7px 6px; }
  .src-items { padding-left: 50px; }
  .toolbar { grid-template-columns: minmax(200px, 1fr) auto; align-items: center; }
  .toolbar-row { grid-column: 1 / -1; }
  .chips { margin: 0; padding: 1px; }
  .chips button { padding: 5px 14px; font-size: 0.82rem; }
  .lg-row { padding: 8px 14px; }
  .setup { margin: 0; }   /* starts under the page title, like every other view */
  .setup-index { margin: 0; padding: 1px 0 2px; flex-wrap: wrap; }
  .table-wrap { margin: 0; padding: 0; }
  .toast { bottom: 24px; }
}

/* ---------- desktop: full sidebar, dashboard grid, ledger as a table ---------- */
@media (min-width: 1100px) {
  :root { --side-w: 224px; }
  .side { padding: 18px 12px; }
  .side .brand { justify-content: flex-start; padding: 0 12px; }
  .side .label { display: inline; }
  .side-nav a { justify-content: flex-start; padding: 9px 12px; }
  .side-nav a[aria-current="page"]::before { left: -12px; }
  .side-nav .badge { position: static; margin-left: auto; }
  .side-sep { margin: 8px 12px; }
  .side-foot { display: grid; gap: 6px; margin-top: auto; padding: 12px 12px 2px; font-size: 0.78rem; color: rgb(255 255 255 / 0.6); border-top: 1px solid rgb(255 255 255 / 0.1); }
  .side-foot span { display: flex; justify-content: space-between; align-items: center; }
  main { padding: 22px 28px 48px; }
  .top { padding: 10px 28px; }

  .dash { grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); align-items: start; }
  .dash-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }

  /* Month: an even three-column grid */
  #view-month { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #view-month .dash, #view-month .dash-main, #view-month .dash-side, #view-month .dash-pair { display: contents; }
  #view-month > .hero { grid-column: 1 / -1; }
  #view-month .panel:has(#cats) { grid-column: 1; grid-row: 2; }
  #view-month .panel:has(#income-sources) { grid-column: 2; grid-row: 2; }
  #view-month .panel:has(#month-bills) { grid-column: 3; grid-row: 2; }
  #view-month .panel:has(#trend) { grid-column: 1 / 3; grid-row: 3; display: grid; grid-template-rows: auto 1fr; }
  #trend { align-self: center; }
  #view-month .panel:has(#merchants) { grid-column: 3; grid-row: 3; }
  #view-month .panel:has(#recent) { grid-column: 1 / -1; grid-row: 4; }
  #month-bills .mb { padding: 5px 6px; }
  #view-month .mini-ledger { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 24px; }

  .lg-head, .lg-row { grid-template-columns: minmax(0, 1fr) 170px 170px 160px; gap: 0; padding: 0; }
  .lg-head { display: grid; font-size: 0.76rem; font-weight: 650; color: var(--muted); border-bottom: 1px solid var(--rule); }
  .lg-head > div, .lg-row > div { padding: 8px 16px; min-width: 0; }
  .lg-day { padding: 7px 16px; }
  .lg-head .num { text-align: right; }
  .lg-row .c-cat { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 0.86rem; min-width: 0; }
  .lg-row .c-cat span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lg-row .c-cat .ic { width: 16px; height: 16px; color: var(--muted); }
  .lg-row .c-acct { display: block; color: var(--muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .d-mob { display: none; }

  .bills-layout { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; }
  /* left: calendar, then subscriptions. right: monthly bills beside both, then unpaid bills. */
  .bills-layout > .panel:nth-child(1) { grid-column: 1; grid-row: 1; }
  .bills-layout > .panel:nth-child(4) { grid-column: 1; grid-row: 2; }
  .bills-layout > .panel:nth-child(2) { grid-column: 2; grid-row: 1 / span 2; }
  .bills-layout > .panel:nth-child(3) { grid-column: 2; grid-row: 3; }
  .cal-day { min-height: 92px; }
  .inbox-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); align-items: start; }

  .setup { grid-template-columns: 170px minmax(0, 760px); max-width: 970px; gap: 40px; }
  .setup-index { flex-direction: column; flex-wrap: nowrap; position: sticky; top: calc(var(--top-h) + 22px); align-self: start; gap: 2px; }
  .setup-index button { background: none; border: 0; border-radius: var(--r-s); text-align: left; padding: 8px 12px; }
  .setup-index button:hover { background: var(--rule-soft); }
}

#bal-form { padding: 0; margin-bottom: 14px; }

/* bank charge rules: switch, what happens, amount */
.fee-rules .srow { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto; }
.fee-amt { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.fee-amt input { width: 6.5em; text-align: right; }
.fee-save { padding: 12px 0; border-top: 1px solid var(--rule-soft); align-items: center; }
@media (max-width: 599px) { .fee-rules .srow { grid-template-columns: minmax(0, 1fr) auto; } .fee-rules .srow-value { display: none; } }

/* statements you upload yourself: the reminder across the app, and the upload strip on Accounts */
.due-note { display: flex; align-items: center; gap: 10px; width: 100%; margin: 0 0 14px; padding: 10px 14px; border: 1px solid var(--owe); border-radius: var(--r-s); background: var(--sunk); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.due-note[hidden] { display: none; }
.due-note .ic { flex: none; color: var(--owe); }
.due-note .grow { flex: 1; min-width: 0; }
.stmt-up { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; padding: 10px 16px; border-bottom: 1px solid var(--rule-soft); }
.stmt-up-text { display: flex; align-items: flex-start; gap: 8px; flex: 1 1 260px; min-width: 0; font-size: 0.92rem; }
.stmt-up-text small { display: block; color: var(--muted, inherit); opacity: 0.75; }
.stmt-up.due .stmt-up-text { color: var(--owe); }
.stmt-up .ic { flex: none; margin-top: 2px; }
.stmt-up label.btn { cursor: pointer; }
.fc-what small.bad { color: var(--owe); }
