[hidden] { display: none !important; }

/* Colors: light by default; dark when the user picks Dark, or picks System and the device is in dark mode. */
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --card-2: #fafbfc;
  --ink: #1d2330;
  --muted: #6b7280;
  --faint: #9aa1ad;
  --line: #e4e7ec;
  --line-soft: #f0f2f5;
  --code-bg: #f0f2f5;
  --input-bg: #ffffff;
  --input-border: #cfd4dc;
  --input-disabled: #f3f4f6;
  --focus-ring: #c7d4f6;
  --hover: #f4f5f7;
  --nav-hover: #f2f4f7;
  --nav-on: #eef2fd;
  --accent: #2f5bd3;
  --accent-btn: #2f5bd3;
  --accent-btn-hover: #2549b0;
  --accent-ink: #ffffff;
  --pos: #137a4b;
  --neg: #c0362c;
  --danger-border: #efc4c0;
  --danger-hover: #fdf1f0;
  --error-bg: #fdf1f0;
  --error-border: #f4cdc9;
  --ok-bg: #ecf6f0;
  --ok-border: #c6e6d3;
  --ok-ink: #145c3a;
  --warn-bg: #fff8eb;
  --warn-border: #f3dcae;
  --warn-ink: #7a4b05;
  --warn-muted: #a37a3b;
  --badge-warn-bg: #fff1e0;
  --badge-warn-ink: #a5560b;
  --badge-warn-hover: #ffe3c2;
  --badge-ok-bg: #e3f4ea;
  --badge-ok-ink: #146c41;
  --badge-ok-hover: #d2ecdc;
  --badge-grey-bg: #eef0f3;
  --needs-bg: #fffbf2;
  --needs-input: #e8b96a;
  --est-bg: #eef4ff;
  --est-bar: #3b6fe0;
  --est-badge-bg: #dbe6ff;
  --est-ink: #2448a8;
  --est-btn-border: #b9cdf5;
  --est-btn-hover: #dfe9ff;
  --negbal-bg: #fdecea;
  --alarm-bg: #b42318;
  --alarm-shadow: rgba(180, 35, 24, .35);
  --marker-bg: #eef2fd;
  --marker-ink: #2448a8;
  --marker-line: #9db4ef;
  --chart-line: #2f5bd3;
  --chart-area: rgba(47, 91, 211, .10);
  --chart-grid: #eceef2;
  --chart-axis: #6b7280;
  --chart-today: #1d2330;
  --chart-zero: #c0362c;
  --chart-dot-ring: #ffffff;
  --tooltip-bg: #1d2330;
  --tooltip-ink: #ffffff;
  --past-opacity: .58;
  --radius: 10px;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
}
:root[data-theme="dark"] {
  --bg: #111418;
  --card: #1a1e24;
  --card-2: #20252c;
  --ink: #e6e8eb;
  --muted: #9aa3af;
  --faint: #6f7782;
  --line: #2e343c;
  --line-soft: #252a31;
  --code-bg: #262b32;
  --input-bg: #14181d;
  --input-border: #3a414b;
  --input-disabled: #1f242a;
  --focus-ring: #2f4a8f;
  --hover: #252b33;
  --nav-hover: #252b33;
  --nav-on: #1e2a45;
  --accent: #8aa8f5;
  --accent-btn: #3f68d8;
  --accent-btn-hover: #5079e6;
  --accent-ink: #ffffff;
  --pos: #4cc38a;
  --neg: #f07a6f;
  --danger-border: #6b2f2a;
  --danger-hover: #2c1a19;
  --error-bg: #2c1a19;
  --error-border: #6b2f2a;
  --ok-bg: #15291f;
  --ok-border: #24533a;
  --ok-ink: #7fd6a8;
  --warn-bg: #2a2213;
  --warn-border: #5c4720;
  --warn-ink: #f0c674;
  --warn-muted: #b8975a;
  --badge-warn-bg: #3a2a14;
  --badge-warn-ink: #f3b066;
  --badge-warn-hover: #4a3518;
  --badge-ok-bg: #163626;
  --badge-ok-ink: #6fd39f;
  --badge-ok-hover: #1d4530;
  --badge-grey-bg: #2a3038;
  --needs-bg: #251f14;
  --needs-input: #9c7a3a;
  --est-bg: #1a2440;
  --est-bar: #6e93f0;
  --est-badge-bg: #243561;
  --est-ink: #a9c0fa;
  --est-btn-border: #3a5296;
  --est-btn-hover: #223060;
  --negbal-bg: #3a1d1b;
  --alarm-bg: #b42318;
  --alarm-shadow: rgba(0, 0, 0, .5);
  --marker-bg: #1e2a45;
  --marker-ink: #a9c0fa;
  --marker-line: #3a5296;
  --chart-line: #6f8fec;
  --chart-area: rgba(111, 143, 236, .12);
  --chart-grid: #262b32;
  --chart-axis: #9aa3af;
  --chart-today: #e6e8eb;
  --chart-zero: #f07a6f;
  --chart-dot-ring: #1a1e24;
  --tooltip-bg: #e6e8eb;
  --tooltip-ink: #111418;
  --past-opacity: .55;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #111418;
    --card: #1a1e24;
    --card-2: #20252c;
    --ink: #e6e8eb;
    --muted: #9aa3af;
    --faint: #6f7782;
    --line: #2e343c;
    --line-soft: #252a31;
    --code-bg: #262b32;
    --input-bg: #14181d;
    --input-border: #3a414b;
    --input-disabled: #1f242a;
    --focus-ring: #2f4a8f;
    --hover: #252b33;
    --nav-hover: #252b33;
    --nav-on: #1e2a45;
    --accent: #8aa8f5;
    --accent-btn: #3f68d8;
    --accent-btn-hover: #5079e6;
    --accent-ink: #ffffff;
    --pos: #4cc38a;
    --neg: #f07a6f;
    --danger-border: #6b2f2a;
    --danger-hover: #2c1a19;
    --error-bg: #2c1a19;
    --error-border: #6b2f2a;
    --ok-bg: #15291f;
    --ok-border: #24533a;
    --ok-ink: #7fd6a8;
    --warn-bg: #2a2213;
    --warn-border: #5c4720;
    --warn-ink: #f0c674;
    --warn-muted: #b8975a;
    --badge-warn-bg: #3a2a14;
    --badge-warn-ink: #f3b066;
    --badge-warn-hover: #4a3518;
    --badge-ok-bg: #163626;
    --badge-ok-ink: #6fd39f;
    --badge-ok-hover: #1d4530;
    --badge-grey-bg: #2a3038;
    --needs-bg: #251f14;
    --needs-input: #9c7a3a;
    --est-bg: #1a2440;
    --est-bar: #6e93f0;
    --est-badge-bg: #243561;
    --est-ink: #a9c0fa;
    --est-btn-border: #3a5296;
    --est-btn-hover: #223060;
    --negbal-bg: #3a1d1b;
    --alarm-bg: #b42318;
    --alarm-shadow: rgba(0, 0, 0, .5);
    --marker-bg: #1e2a45;
    --marker-ink: #a9c0fa;
    --marker-line: #3a5296;
    --chart-line: #6f8fec;
    --chart-area: rgba(111, 143, 236, .12);
    --chart-grid: #262b32;
    --chart-axis: #9aa3af;
    --chart-today: #e6e8eb;
    --chart-zero: #f07a6f;
    --chart-dot-ring: #1a1e24;
    --tooltip-bg: #e6e8eb;
    --tooltip-ink: #111418;
    --past-opacity: .55;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--ink); }
.book-name { color: var(--muted); }
.book-switch { width: auto; padding: .3rem .5rem; }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a { padding: .35rem .7rem; border-radius: 6px; color: var(--ink); }
.topbar nav a.on { background: var(--nav-on); color: var(--accent); }
.topbar nav a:hover { text-decoration: none; background: var(--nav-hover); }
.spacer { flex: 1; }

main { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.25rem; }
main.narrow { max-width: 560px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.card.auth { margin-top: 3rem; }
details.card > summary { cursor: pointer; font-weight: 600; color: var(--accent); list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 1rem; }

/* forms */
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .8rem; }
label .hint { font-weight: 400; color: var(--muted); margin-left: .3rem; }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; padding: .5rem .6rem; font: inherit;
  border: 1px solid var(--input-border); border-radius: 7px; background: var(--input-bg); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus-ring); border-color: var(--accent); }
input:disabled { background: var(--input-disabled); color: var(--muted); }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
label.check input { width: auto; margin: 0; }
button, .button { display: inline-block; font: inherit; font-weight: 600; padding: .5rem 1rem; border-radius: 7px;
  border: 1px solid var(--input-border); background: var(--input-bg); color: var(--ink); cursor: pointer; }
button:hover, .button:hover { background: var(--hover); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent-btn); border-color: var(--accent-btn); color: var(--accent-ink); }
button.primary:hover { background: var(--accent-btn-hover); }
button.danger { color: var(--neg); border-color: var(--danger-border); }
button.danger:hover { background: var(--danger-hover); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 500; }
button.link:hover { text-decoration: underline; background: none; }
button.wide { width: 100%; margin-top: .25rem; }
form.inline { display: inline; }
.buttons { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; }

.row-form { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.row-form label { margin-bottom: 0; }
.row-form .grow { flex: 1; min-width: 160px; }
.row-form button { margin-bottom: 1px; }
.grid-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; align-items: end; }
.grid-form .span2 { grid-column: span 2; }
.grid-form .span3 { grid-column: span 3; }
.grid-form .check { margin-top: 1.4rem; }

.error { color: var(--neg); background: var(--error-bg); border: 1px solid var(--error-border); padding: .6rem .8rem; border-radius: 7px; }
.flash { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-ink); padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-error { background: var(--error-bg); border-color: var(--error-border); color: var(--neg); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* summary */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 1000px) { .summary { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; display: flex; flex-direction: column; }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .85rem; color: var(--muted); }

/* tables */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin: 1rem 0 .5rem; }
.tabs { display: flex; gap: .25rem; }
.tabs a { padding: .3rem .75rem; border-radius: 20px; color: var(--muted); border: 1px solid transparent; font-size: .9rem; }
.tabs a.on { border-color: var(--line); background: var(--card); color: var(--ink); font-weight: 600; }
.jump { font-size: .9rem; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
.card .table-wrap { margin-top: 1rem; }
table.ledger { width: 100%; border-collapse: collapse; }
table.ledger th { position: sticky; top: 0; background: var(--card-2); text-align: left; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); padding: .6rem .8rem; border-bottom: 1px solid var(--line); z-index: 1; }
table.ledger td { padding: .55rem .8rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.ledger tr:last-child td { border-bottom: 0; }
table.ledger .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.ledger .date { white-space: nowrap; }
table.ledger .note { color: var(--muted); max-width: 300px; }
table.ledger .act { text-align: right; white-space: nowrap; }
table.ledger .act form + form { margin-left: .75rem; }
table.ledger .bal { font-weight: 600; }
table.ledger tr.inactive td { color: var(--faint); }
table.ledger .empty { text-align: center; color: var(--muted); padding: 2rem; }
.pos { color: var(--pos); }
.neg { color: var(--neg) !important; }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; background: var(--badge-warn-bg); color: var(--badge-warn-ink); border-radius: 4px; padding: 1px 6px; margin-left: .3rem; vertical-align: 1px; }
.badge.grey { background: var(--badge-grey-bg); color: var(--muted); }
.sched { color: var(--faint); margin-left: .25rem; font-size: .85rem; }
.nowrap { white-space: nowrap; }

/* ledger: part of the page (no inner scroll box); header sticks under the top bar */
#ledger-wrap { overflow: visible; }
#ledger-wrap table.ledger th { top: var(--topbar-h, 49px); }
#ledger-wrap table.ledger th:first-child { border-top-left-radius: var(--radius); }
#ledger-wrap table.ledger th:last-child { border-top-right-radius: var(--radius); }
table.ledger tr.past td { opacity: var(--past-opacity); }
table.ledger tr.past:hover td, table.ledger tr.past:focus-within td { opacity: 1; }
table.ledger tr.today-marker td { background: var(--marker-bg); color: var(--marker-ink); font-size: .82rem; font-weight: 600;
  padding: .45rem .8rem; border-top: 2px solid var(--marker-line); border-bottom: 2px solid var(--marker-line);
  scroll-margin-top: calc(var(--topbar-h, 49px) + 3rem); }
.today-marker .tm-inner { display: flex; justify-content: space-between; gap: 1rem; }
.today-marker .tm-bal { font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .summary { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr; }
  .grid-form .span2, .grid-form .span3 { grid-column: auto; }
  table.ledger .note { display: none; }
  table.ledger td.acct { white-space: normal; }
}
@media (max-width: 1000px) {
  table.ledger td.acct { white-space: normal; }
}
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .stats-grid .stat { padding: .8rem .9rem; }
  .stat .value.sm { font-size: 1.1rem; }
  .topbar { gap: .5rem; padding: .5rem .75rem; }
  .topbar nav { flex-wrap: wrap; }
  .topbar nav a { padding: .35rem .5rem; }
}
/* narrow screens: the table swipes sideways on its own (as before); the page itself never does */
@media (max-width: 899px) {
  #ledger-wrap { overflow-x: auto; }
  #ledger-wrap table.ledger th { position: static; }
}

/* --- per-entry amounts, manual payments, account numbers --- */
.attention { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; background: var(--warn-bg); border: 1px solid var(--warn-border);
  color: var(--warn-ink); border-radius: 8px; padding: .65rem 1rem; margin-bottom: 1rem; font-size: .92rem; }
.attention .muted { color: var(--warn-muted); }
.acctno { color: var(--muted); font-size: .85em; font-variant-numeric: tabular-nums; margin-left: .2rem; }
table.ledger td.acct { white-space: nowrap; }
button.badge { border: 0; cursor: pointer; font: inherit; font-size: .72rem; font-weight: 600; line-height: 1.5; }
.badge.todo { background: var(--badge-warn-bg); color: var(--badge-warn-ink); }
.badge.todo:hover { background: var(--badge-warn-hover); }
.badge.done { background: var(--badge-ok-bg); color: var(--badge-ok-ink); }
.badge.done:hover { background: var(--badge-ok-hover); }
td.amt { min-width: 120px; }
.amt-form { display: none; gap: .3rem; justify-content: flex-end; align-items: center; }
.amt-form.open { display: flex; }
.amt-form input { width: 7.5rem; margin: 0; padding: .3rem .45rem; text-align: right; }
.small-btn { padding: .3rem .6rem; font-size: .85rem; }
.amt-show { border: 0; background: none; padding: 0 0 0 .2rem; font: inherit; font-variant-numeric: tabular-nums;
  cursor: pointer; border-bottom: 1px dashed transparent; border-radius: 0; }
.amt-show:hover { background: none; border-bottom-color: currentColor; }
.amt-show.pos { color: var(--pos); }
table.ledger tr.needs td { background: var(--needs-bg); }
table.ledger tr.needs td.amt input { border-color: var(--needs-input); background: var(--input-bg); }

/* --- account types, estimates, below-zero alarm --- */
.page-head { display: flex; justify-content: space-between; align-items: baseline; }
label a.hint { font-weight: 400; }
.type-rename { display: flex; gap: .4rem; align-items: center; }
.type-rename input { margin: 0; max-width: 260px; padding: .35rem .5rem; }
button.danger-link { color: var(--neg); }
fieldset.seg { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .8rem .2rem; margin: 0 0 .8rem; }
fieldset.seg legend { font-size: .85rem; font-weight: 600; padding: 0 .3rem; }
fieldset.seg label { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin-bottom: .5rem; }
fieldset.seg input { width: auto; margin: 0; }
.row-form .est-check { margin-bottom: .55rem; white-space: nowrap; }

.alarm { display: flex; gap: 1rem; align-items: flex-start; background: var(--alarm-bg); color: #fff; border-radius: var(--radius);
  padding: 1rem 1.25rem; margin-bottom: 1rem; box-shadow: 0 2px 10px var(--alarm-shadow); }
.alarm a { color: #fff; text-decoration: underline; }
.alarm-icon { flex: none; width: 2rem; height: 2rem; border-radius: 50%; background: #fff; color: #b42318;
  font-weight: 800; font-size: 1.2rem; display: grid; place-items: center; animation: alarm-pulse 1.6s ease-in-out infinite; }
.alarm strong { font-size: 1.15rem; display: block; }
.alarm-detail { display: block; margin-top: .15rem; }
.alarm-sub { margin-top: .35rem; font-size: .9rem; opacity: .9; }
@keyframes alarm-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { .alarm-icon { animation: none; } }

table.ledger tr.estimate td { background: var(--est-bg); }
table.ledger tr.estimate td:first-child { box-shadow: inset 3px 0 0 var(--est-bar); }
.badge.est { background: var(--est-badge-bg); color: var(--est-ink); }
.est-amt { font-style: italic; }
.est-btn { background: var(--est-bg); border-color: var(--est-btn-border); color: var(--est-ink); }
.est-btn:hover { background: var(--est-btn-hover); }
table.ledger tr.below-zero td.bal { background: var(--negbal-bg); }

/* --- settings: appearance --- */
.theme-choice { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.theme-choice label { display: flex; align-items: center; gap: .45rem; margin: 0; font-weight: 500; padding: .45rem .8rem;
  border: 1px solid var(--input-border); border-radius: 8px; cursor: pointer; }
.theme-choice label:has(input:checked) { border-color: var(--accent); background: var(--nav-on); }
.theme-choice input { width: auto; margin: 0; }

/* --- dashboard --- */
.dash-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.dash-head h1 { margin: 0; }
.month-nav { display: flex; align-items: center; gap: .35rem; }
.month-nav a, .month-nav span.disabled { padding: .3rem .7rem; border: 1px solid var(--line); border-radius: 7px; background: var(--card); }
.month-nav .this { font-size: .9rem; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stat .value.sm { font-size: 1.3rem; }
.section-title { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 1.5rem 0 .6rem; font-weight: 600; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.type-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; }
.type-box .tname { font-weight: 600; font-size: .92rem; }
.type-box .tval { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: .15rem 0; }
.type-box .tsub { font-size: .8rem; color: var(--muted); }
.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .5rem 0; border-bottom: 1px solid var(--line-soft); font-size: .92rem; }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .when { color: var(--muted); font-size: .82rem; display: block; }
.mini-list .amt { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.chart-card { position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.chart-head h2 { margin: 0; }
.chart-key { display: flex; gap: 1rem; font-size: .82rem; color: var(--muted); }
.chart-key .k { display: inline-flex; align-items: center; gap: .4rem; }
.chart-key svg { display: block; }
.chart-wrap { position: relative; margin-top: .75rem; }
svg.balance-chart { width: 100%; height: auto; display: block; overflow: visible; }
svg.balance-chart .grid { stroke: var(--chart-grid); stroke-width: 1; }
svg.balance-chart .axis-label { fill: var(--chart-axis); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.balance-chart .line-actual { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.balance-chart .line-proj { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-dasharray: 5 5; stroke-linecap: round; }
svg.balance-chart .area { fill: var(--chart-area); stroke: none; }
svg.balance-chart .today-line { stroke: var(--chart-today); stroke-width: 1; stroke-dasharray: 2 3; }
svg.balance-chart .today-label { fill: var(--chart-today); font-size: 11px; font-weight: 700; }
svg.balance-chart .zero-line { stroke: var(--chart-zero); stroke-width: 1; }
svg.balance-chart .zero-label { fill: var(--chart-zero); font-size: 11px; font-weight: 600; }
svg.balance-chart .dot { fill: var(--chart-line); stroke: var(--chart-dot-ring); stroke-width: 2; }
svg.balance-chart .crosshair { stroke: var(--chart-axis); stroke-width: 1; }
svg.balance-chart .hover-dot { fill: var(--chart-line); stroke: var(--chart-dot-ring); stroke-width: 2; }
.chart-tip { position: absolute; pointer-events: none; background: var(--tooltip-bg); color: var(--tooltip-ink); border-radius: 6px;
  padding: .35rem .55rem; font-size: .8rem; white-space: nowrap; transform: translate(-50%, -115%); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.chart-tip strong { font-size: .95rem; font-variant-numeric: tabular-nums; display: block; }
.chart-note { font-size: .82rem; color: var(--muted); margin: .5rem 0 0; }
details.table-view { margin-top: .75rem; font-size: .9rem; }
details.table-view summary { cursor: pointer; color: var(--accent); }
details.table-view table { margin-top: .5rem; }
@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } .dash-cols { grid-template-columns: 1fr; } }

/* =====================================================================
   GLASS THEME: translucent "liquid glass" surfaces over a soft, colorful
   backdrop. Follows the device's light/dark setting. Falls back to solid
   surfaces when the device asks for reduced transparency.
   ===================================================================== */
:root[data-theme="glass"] {
  --bg: #eef1fb; --card: rgba(255, 255, 255, .42); --card-2: rgba(255, 255, 255, .55);
  --ink: #1c1c1e; --muted: rgba(60, 60, 67, .68); --faint: rgba(60, 60, 67, .45);
  --line: rgba(255, 255, 255, .6); --line-soft: rgba(60, 60, 67, .09); --code-bg: rgba(255, 255, 255, .5);
  --input-bg: rgba(255, 255, 255, .5); --input-border: rgba(255, 255, 255, .75); --input-disabled: rgba(255, 255, 255, .3);
  --focus-ring: rgba(0, 122, 255, .35);
  --hover: rgba(255, 255, 255, .65); --nav-hover: rgba(255, 255, 255, .45); --nav-on: rgba(255, 255, 255, .72);
  --accent: #0066d6; --accent-btn: #007aff; --accent-btn-hover: #0a84ff; --accent-ink: #ffffff;
  --pos: #1d7a35; --neg: #c4001a;
  --danger-border: rgba(255, 59, 48, .35); --danger-hover: rgba(255, 59, 48, .1);
  --error-bg: rgba(255, 59, 48, .12); --error-border: rgba(255, 59, 48, .3);
  --ok-bg: rgba(52, 199, 89, .16); --ok-border: rgba(52, 199, 89, .35); --ok-ink: #145c2b;
  --warn-bg: rgba(255, 204, 0, .2); --warn-border: rgba(255, 179, 0, .4); --warn-ink: #6b4200; --warn-muted: #8a6420;
  --badge-warn-bg: rgba(255, 149, 0, .18); --badge-warn-ink: #9a4f00; --badge-warn-hover: rgba(255, 149, 0, .3);
  --badge-ok-bg: rgba(52, 199, 89, .2); --badge-ok-ink: #146c33; --badge-ok-hover: rgba(52, 199, 89, .32);
  --badge-grey-bg: rgba(120, 120, 128, .16);
  --needs-bg: rgba(255, 159, 10, .12); --needs-input: rgba(255, 149, 0, .6);
  --est-bg: rgba(0, 122, 255, .1); --est-bar: #007aff; --est-badge-bg: rgba(0, 122, 255, .16); --est-ink: #0055b8;
  --est-btn-border: rgba(0, 122, 255, .3); --est-btn-hover: rgba(0, 122, 255, .18);
  --negbal-bg: rgba(255, 59, 48, .12);
  --alarm-bg: rgba(215, 0, 21, .82); --alarm-shadow: rgba(215, 0, 21, .3);
  --marker-bg: rgba(0, 122, 255, .12); --marker-ink: #0055b8; --marker-line: rgba(0, 122, 255, .35);
  --chart-line: #007aff; --chart-area: transparent; --chart-grid: rgba(60, 60, 67, .12); --chart-axis: rgba(60, 60, 67, .7);
  --chart-today: #1c1c1e; --chart-zero: #d70015; --chart-dot-ring: #ffffff;
  --tooltip-bg: rgba(255, 255, 255, .78); --tooltip-ink: #1c1c1e;
  --past-opacity: .55;
  --radius: 22px;
  /* glass material */
  --g-fill: linear-gradient(135deg, rgba(255, 255, 255, .62), rgba(255, 255, 255, .30));
  --g-fill-strong: linear-gradient(135deg, rgba(255, 255, 255, .80), rgba(255, 255, 255, .55));
  --g-blur: blur(22px) saturate(185%);
  --g-rim: linear-gradient(135deg, rgba(255, 255, 255, .95) 0%, rgba(255, 255, 255, .25) 35%,
             rgba(255, 255, 255, .08) 60%, rgba(255, 255, 255, .7) 100%);
  --g-shadow: inset 0 1px 0 rgba(255, 255, 255, .85), inset 0 -1px 1px rgba(255, 255, 255, .25),
              0 10px 30px rgba(40, 50, 110, .13), 0 1px 3px rgba(40, 50, 110, .08);
  --g-sheen: rgba(255, 255, 255, .55);
  --g-wall-1: #7aa7ff; --g-wall-2: #c79bff; --g-wall-3: #ff9fc4; --g-wall-4: #7fe3d4; --g-wall-5: #ffd38a;
  --g-wall-base: #eef1fb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="glass"] {
    --bg: #0c0e18; --card: rgba(40, 42, 58, .42); --card-2: rgba(44, 46, 64, .6);
    --ink: #f5f5f7; --muted: rgba(235, 235, 245, .65); --faint: rgba(235, 235, 245, .4);
    --line: rgba(255, 255, 255, .16); --line-soft: rgba(255, 255, 255, .07); --code-bg: rgba(255, 255, 255, .1);
    --input-bg: rgba(255, 255, 255, .08); --input-border: rgba(255, 255, 255, .18); --input-disabled: rgba(255, 255, 255, .04);
    --focus-ring: rgba(10, 132, 255, .45);
    --hover: rgba(255, 255, 255, .14); --nav-hover: rgba(255, 255, 255, .1); --nav-on: rgba(255, 255, 255, .18);
    --accent: #4ea3ff; --accent-btn: #0a84ff; --accent-btn-hover: #339bff;
    --pos: #30d158; --neg: #ff6961;
    --danger-border: rgba(255, 69, 58, .45); --danger-hover: rgba(255, 69, 58, .15);
    --error-bg: rgba(255, 69, 58, .16); --error-border: rgba(255, 69, 58, .4);
    --ok-bg: rgba(48, 209, 88, .16); --ok-border: rgba(48, 209, 88, .35); --ok-ink: #7ee29b;
    --warn-bg: rgba(255, 214, 10, .14); --warn-border: rgba(255, 214, 10, .3); --warn-ink: #ffd60a; --warn-muted: #d4b85a;
    --badge-warn-bg: rgba(255, 159, 10, .22); --badge-warn-ink: #ffb340; --badge-warn-hover: rgba(255, 159, 10, .34);
    --badge-ok-bg: rgba(48, 209, 88, .22); --badge-ok-ink: #7ee29b; --badge-ok-hover: rgba(48, 209, 88, .34);
    --badge-grey-bg: rgba(255, 255, 255, .12);
    --needs-bg: rgba(255, 159, 10, .12); --needs-input: rgba(255, 159, 10, .6);
    --est-bg: rgba(10, 132, 255, .16); --est-bar: #0a84ff; --est-badge-bg: rgba(10, 132, 255, .28); --est-ink: #9ccaff;
    --est-btn-border: rgba(10, 132, 255, .45); --est-btn-hover: rgba(10, 132, 255, .28);
    --negbal-bg: rgba(255, 69, 58, .18);
    --alarm-bg: rgba(200, 20, 30, .78); --alarm-shadow: rgba(0, 0, 0, .45);
    --marker-bg: rgba(10, 132, 255, .18); --marker-ink: #9ccaff; --marker-line: rgba(10, 132, 255, .5);
    --chart-line: #0a84ff; --chart-grid: rgba(255, 255, 255, .08); --chart-axis: rgba(235, 235, 245, .6);
    --chart-today: #f5f5f7; --chart-zero: #ff6961; --chart-dot-ring: #1d2030;
    --tooltip-bg: rgba(44, 46, 64, .82); --tooltip-ink: #f5f5f7;
    --g-fill: linear-gradient(135deg, rgba(60, 64, 90, .50), rgba(30, 32, 48, .38));
    --g-fill-strong: linear-gradient(135deg, rgba(70, 74, 100, .72), rgba(40, 42, 60, .62));
    --g-rim: linear-gradient(135deg, rgba(255, 255, 255, .45) 0%, rgba(255, 255, 255, .08) 35%,
               rgba(255, 255, 255, .03) 60%, rgba(255, 255, 255, .28) 100%);
    --g-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), inset 0 -1px 1px rgba(255, 255, 255, .05),
                0 12px 34px rgba(0, 0, 0, .45), 0 1px 3px rgba(0, 0, 0, .3);
    --g-sheen: rgba(255, 255, 255, .18);
    --g-wall-1: #2b4cff; --g-wall-2: #7b2cff; --g-wall-3: #ff2d87; --g-wall-4: #00b3a4; --g-wall-5: #8a3f12;
    --g-wall-base: #0c0e18;
    color-scheme: dark;
  }
}

/* the colorful backdrop the glass sits on */
[data-theme="glass"] body { background: transparent; min-height: 100vh; }
[data-theme="glass"] body::before {
  content: ""; position: fixed; inset: -20vmax; z-index: -1; pointer-events: none;
  background:
    radial-gradient(38vmax 38vmax at 12% 18%, var(--g-wall-1), transparent 62%),
    radial-gradient(34vmax 34vmax at 88% 12%, var(--g-wall-2), transparent 60%),
    radial-gradient(40vmax 40vmax at 78% 82%, var(--g-wall-3), transparent 62%),
    radial-gradient(36vmax 36vmax at 18% 88%, var(--g-wall-4), transparent 60%),
    radial-gradient(28vmax 28vmax at 50% 50%, var(--g-wall-5), transparent 65%),
    var(--g-wall-base);
  filter: saturate(115%);
  opacity: .78;
  animation: glass-drift 38s ease-in-out infinite alternate;
}
@keyframes glass-drift {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  50%  { transform: translate3d(-3vmax, 2vmax, 0) rotate(4deg) scale(1.04); }
  100% { transform: translate3d(2vmax, -2vmax, 0) rotate(-3deg) scale(1.02); }
}

/* the material */
[data-theme="glass"] :is(.topbar, .card, .stat, .table-wrap, .type-box, .attention, .flash, .error,
  .month-nav a, .tabs a.on, .theme-choice label, .chart-tip, details.card) {
  isolation: isolate;
  background: var(--g-fill);
  -webkit-backdrop-filter: var(--g-blur); backdrop-filter: var(--g-blur);
  border: 1px solid transparent;
  box-shadow: var(--g-shadow);
}
[data-theme="glass"] :is(.card, .stat, .table-wrap, .type-box, .attention, .flash, .error,
  .month-nav a, .tabs a.on, .theme-choice label, details.card) { position: relative; }
/* bright rim of light along the edge */
[data-theme="glass"] :is(.topbar, .card, .stat, .table-wrap, .type-box, .attention, .flash, .error,
  .month-nav a, .tabs a.on, .theme-choice label, .chart-tip)::before,
[data-theme="glass"] :is(button:not(.link):not(.badge):not(.amt-show), .button)::before {
  content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
  background: var(--g-rim);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
/* specular highlight that follows the pointer */
[data-theme="glass"] :is(.card, .stat, .type-box, .topbar)::after,
[data-theme="glass"] :is(button:not(.link):not(.badge):not(.amt-show), .button)::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: -1;
  background: radial-gradient(220px circle at var(--mx, 30%) var(--my, -20%), var(--g-sheen), transparent 60%);
  opacity: .55; transition: opacity .35s ease;
}
[data-theme="glass"] :is(.card, .stat, .type-box, .topbar):hover::after { opacity: 1; }

/* floating capsule top bar */
[data-theme="glass"] .topbar {
  position: sticky; top: 12px; margin: 12px auto 0; max-width: 1140px; width: calc(100% - 24px);
  border-radius: 999px; padding: .4rem .55rem .4rem .7rem; gap: .5rem;
}
[data-theme="glass"] .topbar nav { position: relative; }
[data-theme="glass"] .topbar nav a { border-radius: 999px; padding: .4rem .9rem; position: relative; z-index: 1;
  transition: color .2s ease; }
[data-theme="glass"] .topbar nav.has-lens a.on, [data-theme="glass"] .topbar nav.has-lens a:hover { background: transparent; }
[data-theme="glass"] .topbar nav:not(.has-lens) a.on { background: var(--g-fill-strong); }
[data-theme="glass"] .topbar nav a.on { color: var(--ink); font-weight: 600; }
/* the liquid "lens" that glides between nav links */
.nav-lens { position: absolute; top: 0; left: 0; height: 100%; border-radius: 999px; z-index: 0; pointer-events: none;
  background: var(--g-fill-strong); box-shadow: var(--g-shadow);
  transition: transform .5s cubic-bezier(.34, 1.56, .64, 1), width .5s cubic-bezier(.34, 1.56, .64, 1), opacity .25s; }
.nav-lens::before { content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px;
  background: var(--g-rim); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; }
[data-theme="glass"] .topbar .link { padding: .4rem .7rem; }
[data-theme="glass"] .book-switch { border-radius: 999px; }

/* surfaces: rounder, concentric corners */
[data-theme="glass"] .card, [data-theme="glass"] .table-wrap { border-radius: var(--radius); }
[data-theme="glass"] .stat, [data-theme="glass"] .type-box { border-radius: 20px; }
[data-theme="glass"] .attention, [data-theme="glass"] .flash, [data-theme="glass"] .error { border-radius: 16px; }
[data-theme="glass"] .alarm { border-radius: 20px; -webkit-backdrop-filter: var(--g-blur); backdrop-filter: var(--g-blur);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 12px 32px var(--alarm-shadow); }
[data-theme="glass"] main { margin-top: 1.25rem; }

/* controls: capsules that squish when pressed */
[data-theme="glass"] :is(button:not(.link):not(.badge):not(.amt-show), .button) {
  position: relative; isolation: isolate; border-radius: 999px; border-color: transparent;
  background: var(--g-fill); -webkit-backdrop-filter: var(--g-blur); backdrop-filter: var(--g-blur);
  box-shadow: var(--g-shadow);
  transition: transform .45s cubic-bezier(.34, 1.56, .64, 1), box-shadow .3s ease, background .2s ease;
}
[data-theme="glass"] :is(button:not(.link):not(.badge):not(.amt-show), .button):hover { transform: scale(1.035); background: var(--g-fill-strong); }
[data-theme="glass"] :is(button:not(.link):not(.badge):not(.amt-show), .button):active { transform: scale(.94); transition-duration: .12s; }
[data-theme="glass"] button:not(.link):not(.badge):not(.amt-show).primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent-btn) 88%, white), var(--accent-btn));
  color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), inset 0 -1px 2px rgba(0, 0, 0, .12),
  0 6px 18px color-mix(in srgb, var(--accent-btn) 40%, transparent);
}
[data-theme="glass"] button:not(.link):not(.badge):not(.amt-show).primary:hover { background: linear-gradient(180deg, color-mix(in srgb, var(--accent-btn) 75%, white), var(--accent-btn)); }
[data-theme="glass"] button.danger { color: var(--neg); }
[data-theme="glass"] button:not(.link):not(.badge):not(.amt-show).est-btn { background: var(--est-bg); color: var(--est-ink); }
[data-theme="glass"] button:not(.link):not(.badge):not(.amt-show).est-btn:hover { background: var(--est-btn-hover); }
[data-theme="glass"] button.badge { border-radius: 999px; transition: transform .4s cubic-bezier(.34, 1.56, .64, 1); }
[data-theme="glass"] button.badge:active { transform: scale(.92); }
[data-theme="glass"] .badge { border-radius: 999px; padding: 1px 8px; }
[data-theme="glass"] input, [data-theme="glass"] select, [data-theme="glass"] textarea {
  border-radius: 12px; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .06);
}
[data-theme="glass"] input:focus, [data-theme="glass"] select:focus, [data-theme="glass"] textarea:focus {
  outline: 3px solid var(--focus-ring); outline-offset: 0; border-color: var(--accent-btn);
}
[data-theme="glass"] input[type=checkbox], [data-theme="glass"] input[type=radio] { accent-color: var(--accent-btn); }
[data-theme="glass"] .tabs a { border-radius: 999px; }
[data-theme="glass"] .month-nav a { border-radius: 999px; }
[data-theme="glass"] .theme-choice label { border-radius: 999px; }
[data-theme="glass"] .theme-choice label:has(input:checked) { background: var(--g-fill-strong); outline: 2px solid var(--accent-btn); outline-offset: -1px; }

/* tables on glass */
[data-theme="glass"] table.ledger th { background: var(--card-2); -webkit-backdrop-filter: var(--g-blur); backdrop-filter: var(--g-blur); }
[data-theme="glass"] #ledger-wrap table.ledger th:first-child { border-top-left-radius: var(--radius); }
[data-theme="glass"] #ledger-wrap table.ledger th:last-child { border-top-right-radius: var(--radius); }
[data-theme="glass"] table.ledger tbody tr { transition: background .2s ease; }
[data-theme="glass"] table.ledger tbody tr:not(.today-marker):hover td { background: rgba(255, 255, 255, .22); }
[data-theme="glass"] table.ledger tr.today-marker td { -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
[data-theme="glass"] .chart-tip { color: var(--tooltip-ink); border-radius: 12px; }

/* Respect device settings */
@media (prefers-reduced-motion: reduce) {
  [data-theme="glass"] body::before { animation: none; }
  [data-theme="glass"] *, .nav-lens { transition-duration: 0s !important; }
}
@media (prefers-reduced-transparency: reduce) {
  [data-theme="glass"] :is(.topbar, .card, .stat, .table-wrap, .type-box, .attention, .flash, .error, .chart-tip, details.card,
    button:not(.link):not(.badge):not(.amt-show), .button, .nav-lens) {
    background: var(--g-wall-base) !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
  }
  [data-theme="glass"] body::before { opacity: .25; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  [data-theme="glass"] :is(.topbar, .card, .stat, .table-wrap, .type-box, .chart-tip, details.card) { background: var(--g-fill-strong); }
}
@media (max-width: 720px) {
  [data-theme="glass"] .topbar { border-radius: 24px; padding: .4rem; width: calc(100% - 16px); }
  [data-theme="glass"] .topbar nav a { padding: .4rem .6rem; }
}
@media (max-width: 420px) {
  [data-theme="glass"] .topbar nav a { padding: .35rem .5rem; }
}

/* =====================================================================
   MOBILE: phones (up to 760px wide), touch tablets in portrait (up to
   899px), and phones turned sideways. Desktop layout is unaffected.
   ===================================================================== */
.tabbar, .m-only { display: none; }

@media (max-width: 760px), (pointer: coarse) and (max-width: 899px), (pointer: coarse) and (max-height: 500px) {
  html { -webkit-text-size-adjust: 100%; scroll-padding-bottom: calc(84px + env(safe-area-inset-bottom)); scroll-padding-top: 12px; }
  .d-only { display: none !important; }
  .m-only { display: revert; }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  /* header: replaced by the bottom tab bar (kept only for the ledger switcher) */
  .topbar { display: none; }
  .topbar.has-switcher { display: flex; position: static; padding: .5rem .85rem; margin: 0; width: auto; border-radius: 0; }
  .topbar.has-switcher > :not(.book-switch) { display: none; }
  .topbar.has-switcher .book-switch { flex: 1; width: 100%; }

  /* bottom tab bar */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    justify-content: space-around; align-items: stretch;
    padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    background: var(--card); border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .06);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 50px; padding: 4px 0; border-radius: 14px; color: var(--muted); font-size: .68rem; font-weight: 600;
    text-decoration: none; position: relative; z-index: 1; -webkit-tap-highlight-color: transparent; }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a.on { color: var(--accent); }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a.on svg { stroke-width: 2.1; }
  .tabbar .nav-lens { display: none; }

  /* page */
  main, main.narrow { margin: 1rem auto; padding: 0 max(.85rem, env(safe-area-inset-left)) 0 max(.85rem, env(safe-area-inset-right)); }
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.05rem; }
  .card { padding: 1rem; }
  input, select, textarea { font-size: 16px; }          /* keeps iPhone from zooming in on tap */
  input, select { min-height: 44px; }
  input[type=checkbox], input[type=radio] { min-height: 0; width: 20px; height: 20px; }
  button:not(.link):not(.badge):not(.amt-show):not(.small-btn), .button { min-height: 44px; }
  .buttons { flex-wrap: wrap; }
  .flash, .error { font-size: .92rem; }
  .grid-form { grid-template-columns: 1fr; }
  .grid-form .span2, .grid-form .span3 { grid-column: auto; }
  .grid-form .check { margin-top: 0; }
  label.check { min-height: 32px; }

  /* sign in / sign up */
  .auth-brand { display: block; text-align: center; font-weight: 800; font-size: 1.6rem; letter-spacing: -.01em; margin: 2rem 0 1rem; }
  .card.auth { margin-top: 0; padding: 1.25rem; }
  .card.auth h1 { font-size: 1.25rem; }

  /* summary tiles */
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .stat { padding: .75rem .85rem; }
  .stat .label { font-size: .68rem; }
  .stat .value { font-size: 1.2rem; margin: .15rem 0; }
  .stat .sub { font-size: .75rem; }
  .attention { flex-direction: column; gap: .35rem; font-size: .85rem; padding: .6rem .85rem; }
  .alarm { padding: .85rem 1rem; gap: .75rem; }
  .alarm strong { font-size: 1rem; }
  .alarm-icon { width: 1.75rem; height: 1.75rem; font-size: 1rem; }

  /* inline forms: one field per line; a trailing button stretches */
  .row-form > label { flex: 1 1 100%; }
  .row-form > button { flex: 1 1 auto; }
  .add-entry .row-form > label { flex: 1 1 100%; }
  .add-entry .row-form > label.est-check { flex: 0 0 auto; margin: 0; align-self: center; }
  .add-entry .row-form > button { flex: 1 1 auto; }

  /* range tabs */
  .toolbar { gap: .5rem; }
  .tabs a { padding: .35rem .7rem; }

  /* ledger rows become two-line cards:
       Account ............ Amount  ›
       Date ............ Bal $X     ›
       Note (if any)                    */
  #ledger-wrap { overflow: visible; }
  #ledger-wrap table.ledger, #ledger-wrap tbody { display: block; width: 100%; }
  #ledger-wrap thead { display: none; }
  #ledger-wrap tbody tr:not(.today-marker) {
    display: grid; grid-template-columns: minmax(0, 1fr) auto 28px;
    grid-template-areas: "acct amt act" "date bal act" "note note act" "form form form";
    column-gap: .6rem; row-gap: .15rem; align-items: baseline;
    padding: .65rem .75rem; border-bottom: 1px solid var(--line-soft);
  }
  #ledger-wrap tbody tr:last-child { border-bottom: 0; }
  #ledger-wrap td { padding: 0; border: 0; background: none !important; }
  #ledger-wrap td.acct { grid-area: acct; white-space: normal; font-weight: 600; line-height: 1.35; min-width: 0; }
  #ledger-wrap td.acct .acctno { font-weight: 400; }
  #ledger-wrap td.acct .badge, #ledger-wrap td.acct form.inline { white-space: nowrap; }
  #ledger-wrap td.amt { grid-area: amt; min-width: 0; font-weight: 600; }
  #ledger-wrap td.date { grid-area: date; font-size: .8rem; color: var(--muted); }
  #ledger-wrap td.bal { grid-area: bal; font-size: .8rem; font-weight: 600; text-align: right; }
  #ledger-wrap td.bal::before { content: "Bal "; font-weight: 400; color: var(--muted); }
  #ledger-wrap td.note { grid-area: note; display: block; max-width: none; font-size: .8rem; }
  #ledger-wrap td.note:empty { display: none; }
  #ledger-wrap td.act { grid-area: act; grid-row: 1 / span 2; align-self: center; justify-self: end; }
  #ledger-wrap td.act a { display: flex; align-items: center; justify-content: center; width: 28px; height: 44px;
    font-size: 0; color: var(--faint); text-decoration: none; }
  #ledger-wrap td.act a::after { content: "›"; font-size: 1.6rem; line-height: 1; }
  #ledger-wrap td.empty { display: block; }
  /* row tints move from the cells to the whole card */
  #ledger-wrap tr.needs { background: var(--needs-bg); }
  #ledger-wrap tr.estimate { background: var(--est-bg); box-shadow: inset 3px 0 0 var(--est-bar); }
  #ledger-wrap tr.estimate td:first-child { box-shadow: none; }
  #ledger-wrap tr.below-zero td.bal { background: var(--negbal-bg) !important; border-radius: 6px; padding: 0 .35rem; }
  /* amount editing gets its own full-width line */
  #ledger-wrap tr:has(.amt-form.open) td.amt { grid-area: form; margin-top: .45rem; }
  #ledger-wrap .amt-form.open { justify-content: stretch; gap: .4rem; }
  #ledger-wrap .amt-form input { flex: 1 1 auto; width: auto; min-width: 0; text-align: right; }
  #ledger-wrap .amt-form .small-btn { min-height: 44px; padding: 0 .9rem; font-size: .9rem; }
  #ledger-wrap .amt-show { padding: .25rem 0 .25rem .4rem; }
  /* today marker */
  #ledger-wrap tr.today-marker { display: block; }
  #ledger-wrap tr.today-marker td { display: block; padding: .5rem .75rem; font-size: .8rem; background: var(--marker-bg) !important; }
  #ledger-wrap tr.today-marker .tm-inner { flex-wrap: wrap; gap: .25rem 1rem; }

  /* accounts: cards */
  #accounts-wrap table.ledger, #accounts-wrap tbody { display: block; }
  #accounts-wrap thead { display: none; }
  #accounts-wrap tbody tr { display: flex; flex-wrap: wrap; align-items: baseline; position: relative;
    padding: .65rem 2.4rem .65rem .85rem; border-bottom: 1px solid var(--line-soft); column-gap: .7rem; row-gap: .15rem; }
  #accounts-wrap tbody tr:last-child { border-bottom: 0; }
  #accounts-wrap td { padding: 0; border: 0; }
  #accounts-wrap td.c-name { flex: 1 1 60%; font-weight: 600; min-width: 0; }
  #accounts-wrap td.c-def { margin-left: auto; font-weight: 600; }
  #accounts-wrap td.c-def:empty, #accounts-wrap td:empty { display: none; }
  #accounts-wrap td.c-type, #accounts-wrap td.c-dc, #accounts-wrap td.c-day, #accounts-wrap td.c-no { font-size: .8rem; color: var(--muted); text-align: left; }
  #accounts-wrap td.c-type { order: 3; }
  #accounts-wrap td.c-dc { order: 4; }
  #accounts-wrap td.c-day { order: 5; }
  #accounts-wrap td.c-day::before { content: "Day "; }
  #accounts-wrap td.c-no { order: 6; }
  #accounts-wrap tr::after { content: ""; order: 2; flex-basis: 100%; height: 0; }
  #accounts-wrap td.c-note { order: 7; flex-basis: 100%; max-width: none; font-size: .8rem; }
  #accounts-wrap td.c-ent { display: none; }
  #accounts-wrap td.act { position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); }
  #accounts-wrap td.act a { display: flex; align-items: center; justify-content: center; width: 32px; height: 44px; font-size: 0; color: var(--faint); text-decoration: none; }
  #accounts-wrap td.act a::after { content: "›"; font-size: 1.6rem; line-height: 1; }
  #accounts-wrap td.empty { display: block; flex-basis: 100%; }
  .page-head { align-items: center; gap: 1rem; }
  .page-head a { font-size: .9rem; }

  /* admin tables: labelled stacks */
  table.stack, table.stack tbody { display: block; }
  table.stack thead { display: none; }
  table.stack tbody tr { display: block; padding: .7rem .85rem; border-bottom: 1px solid var(--line-soft); }
  table.stack tbody tr:last-child { border-bottom: 0; }
  table.stack td { display: flex; justify-content: space-between; gap: 1rem; padding: .15rem 0; border: 0; text-align: right; font-size: .88rem; }
  table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); text-align: left; }
  table.stack td[data-label]:empty { display: none; }
  table.stack td.s-title { font-weight: 600; font-size: .95rem; text-align: left; justify-content: flex-start; padding-bottom: .3rem; }
  table.stack td.act { justify-content: flex-start; gap: 1.25rem; padding-top: .45rem; }
  table.stack td.act button.link { min-height: 36px; }
  table.stack td.note { max-width: none; }

  /* account types */
  table.types-table, table.types-table tbody { display: block; }
  table.types-table thead { display: none; }
  table.types-table tbody tr { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem; padding: .65rem .85rem; border-bottom: 1px solid var(--line-soft); }
  table.types-table td { padding: 0; border: 0; }
  table.types-table td:first-child { flex: 1 1 100%; }
  table.types-table .type-rename input { max-width: none; flex: 1; }
  table.types-table td.t-count { text-align: left; font-size: .82rem; }
  table.types-table td.act { margin-left: auto; }
  table.types-table td.act button.link { min-height: 36px; }

  /* settings */
  .theme-choice label { flex: 1 1 calc(50% - .5rem); justify-content: flex-start; min-height: 44px; }

  /* dashboard */
  .dash-head { margin-bottom: .75rem; }
  .dash-head h1 { font-size: 1.3rem; }
  .month-nav a { padding: .45rem .75rem; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .stats-grid .stat { padding: .75rem .85rem; }
  .stat .value.sm { font-size: 1.1rem; }
  .chart-head { gap: .5rem; }
  .chart-key { font-size: .75rem; gap: .75rem; }
  svg.balance-chart rect[id^="ch-hit"] { touch-action: pan-y; }
  svg.balance-chart:focus:not(:focus-visible) { outline: none; }
  .section-title { margin-top: 1.25rem; }
  .type-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .type-box { padding: .75rem .85rem; }
  .type-box .tval { font-size: 1.1rem; }
  .dash-cols { grid-template-columns: 1fr; gap: 0; }
  .mini-list li { font-size: .9rem; }

  /* Glass on phones: the tab bar floats as a capsule */
  [data-theme="glass"] .tabbar {
    left: 10px; right: 10px; bottom: calc(8px + env(safe-area-inset-bottom)); padding: 5px;
    border-radius: 30px; border: 1px solid transparent; isolation: isolate;
    background: var(--g-fill); -webkit-backdrop-filter: var(--g-blur); backdrop-filter: var(--g-blur); box-shadow: var(--g-shadow);
  }
  [data-theme="glass"] .tabbar::before { content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
    background: var(--g-rim); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor; mask-composite: exclude; }
  [data-theme="glass"] .tabbar .nav-lens { display: block; }
  [data-theme="glass"] .tabbar { max-width: 560px; margin: 0 auto; }
  [data-theme="glass"] .tabbar a { border-radius: 24px; }
  [data-theme="glass"] .tabbar a.on { color: var(--accent-btn); }
  [data-theme="glass"] body { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
  [data-theme="glass"] .topbar.has-switcher { margin: 10px 10px 0; border-radius: 22px; position: static; }
  [data-theme="glass"] #ledger-wrap tr.estimate td:first-child { box-shadow: none; }
}
@media (max-width: 760px) and (prefers-reduced-transparency: reduce), (pointer: coarse) and (prefers-reduced-transparency: reduce) {
  [data-theme="glass"] .tabbar { background: var(--g-wall-base) !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
}
