/* Ledgerly: a hand-drawn paper look.
   Cream paper with faint ruled lines, thick ink outlines with slightly uneven
   corners, hard offset shadows in pastel tints, dashed rules between rows. */

@font-face { font-family: 'Caprasimo'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/static/fonts/caprasimo-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Figtree'; font-style: normal; font-weight: 300 900; font-display: swap;
  src: url(/static/fonts/figtree-latin-wght-normal.woff2) format('woff2'); }
@font-face { font-family: 'Rubik'; font-style: normal; font-weight: 300 900; font-display: swap;
  src: url(/static/fonts/rubik-latin-wght-normal.woff2) format('woff2'); }

:root {
  --paper: #f6eedd;
  --rule: rgba(31, 29, 27, .055);
  --card: #fffbf1;
  --ink: #1f1d1b;
  --ink-soft: #4a443a;
  --muted: #7d7464;
  --hairline: #dcd2bf;

  --terracotta: #c4683a;
  --sage: #8a9d6e;
  --sand: #dcb078;
  --clay: #a56a57;
  --danger: #bf5f55;
  --income: #5c8560;

  --sh-terracotta: #ffc9a8;
  --sh-sage: #cddbb4;
  --sh-hair: #dcd2bf;
  --tint-terracotta: #ffe3d3;
  --tint-sage: #e3eecf;
  --tint-sand: #f7e9cf;
  --tint-income: #dcebd8;

  /* Corners that are not quite equal, like a hand-drawn box. */
  --r-lg: 20px 13px 18px 15px / 14px 19px 12px 20px;
  --r-md: 16px 12px 15px 13px / 12px 15px 11px 16px;
  --r-sm: 12px 8px 11px 9px / 8px 11px 7px 10px;
  --r-blob: 52% 48% 51% 49% / 49% 52% 48% 51%;

  --display: 'Caprasimo', Georgia, serif;
  --body: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --num: 'Rubik', 'Figtree', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background: var(--paper); color: var(--ink);
  font: 400 16px/1.45 var(--body);
}
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: repeating-linear-gradient(180deg, transparent 0 31px, var(--rule) 31px 32px);
}
button, a, [role="button"], summary, label.chip { touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--terracotta); outline-offset: 2px; }
a { color: var(--clay); font-weight: 600; }
h1, h2, h3 { margin: 0; }

/* ---------- page frame ---------- */
.page {
  width: 100%; max-width: 640px; margin: 0 auto;
  padding: calc(26px + env(safe-area-inset-top, 0px)) 20px calc(140px + env(safe-area-inset-bottom, 0px));
}
.page-head { margin-bottom: 20px; }
.page-head h1 { font: 400 34px/1.05 var(--display); letter-spacing: -.01em; }
.page-head .sub { margin-top: 10px; font-size: 13px; color: var(--muted); }

/* ---------- boxes ---------- */
.box {
  margin: 0 5px 18px 0; padding: 20px 22px 22px;
  background: var(--card); border: 2.5px solid var(--ink);
  border-radius: var(--r-lg); box-shadow: 5px 6px 0 var(--sh-hair);
}
.box.total { box-shadow: 5px 6px 0 var(--sh-terracotta); }
.box.sage { background: var(--tint-sage); box-shadow: 5px 5px 0 var(--sh-sage); }
.box.danger { box-shadow: 5px 6px 0 var(--danger); }
.box h2 { font: 400 21px/1.15 var(--display); margin-bottom: 14px; }
.box h3 { font: 700 14px/1.2 var(--body); margin: 18px 0 8px; }
.note { margin: 0; font-size: 13.5px; color: var(--muted); }
.empty { margin: 4px 0 0; color: var(--muted); font-size: 14.5px; }

/* ---------- buttons ---------- */
.btn, .tab {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; font: 600 14px var(--body); color: var(--ink-soft); text-decoration: none; cursor: pointer;
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-sm);
  white-space: nowrap;
}
.btn:active, .tab:active { transform: translate(1px, 1px); }
.btn.primary, .tab.active {
  color: var(--card); background: var(--terracotta); box-shadow: 2px 3px 0 var(--ink);
}
.btn.danger { color: #fff; background: var(--danger); box-shadow: 2px 3px 0 var(--ink); }
.btn.block { width: 100%; padding: 13px 16px; font-size: 16px; }
.btn:disabled, .tab:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 5px 11px; font-size: 13px; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs .tab { flex: 1 1 auto; padding: 8px 10px; }

/* ---------- period navigator ---------- */
.range {
  display: flex; align-items: stretch; margin-bottom: 20px; overflow: hidden;
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-md);
  box-shadow: 2px 2px 0 var(--sh-hair);
}
.range .name { flex: 1; min-width: 0; padding: 10px 8px; text-align: center; font: 600 14px var(--body); letter-spacing: .02em; }
.range button {
  flex: 0 0 48px; border: 0; background: none; cursor: pointer; font: 700 20px/1 var(--body); color: var(--ink);
}
.range button:first-child { border-right: 1.5px dashed var(--hairline); }
.range button:last-child { border-left: 1.5px dashed var(--hairline); }
.range button:disabled { color: var(--hairline); cursor: default; }

/* ---------- total ---------- */
.total .label { margin: 0; font-size: 14px; color: var(--muted); font-weight: 600; }
.total .figure { margin: 6px 0 4px; font: 600 44px/1.05 var(--num); letter-spacing: -.02em; word-break: break-word; }
.total .sub { margin: 0; font-size: 14px; color: var(--ink-soft); }
.compare { display: flex; align-items: flex-start; gap: 8px; margin-top: 12px; font-size: 13.5px; color: var(--muted); }
.compare b { color: var(--ink); font-weight: 700; }
.compare .arrow { flex: none; width: 22px; height: 22px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: var(--r-blob); font-size: 12px; font-weight: 800; }
.compare .arrow.down { background: var(--tint-income); }
.compare .arrow.up { background: var(--tint-terracotta); }

/* ---------- goals ---------- */
.goal + .goal { margin-top: 16px; }
.goal .line { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; margin-bottom: 6px; }
.goal .line span:last-child { font-family: var(--num); font-weight: 500; }
.track { height: 16px; overflow: hidden; background: var(--paper); border: 2px solid var(--ink); border-radius: 9px 6px 8px 7px / 7px 9px 6px 8px; }
.fill { height: 100%; background: var(--sand); border-right: 2px solid var(--ink); }
.fill.over { background: var(--danger); }
.fill.good { background: var(--sage); }
.fill.empty, .fill.full { border-right: 0; }

/* ---------- rows: accounts, entries, highlights ---------- */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li { border-bottom: 1.5px dashed var(--hairline); }
.rows > li:last-child { border-bottom: 0; }

.account { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto auto 26px; gap: 6px 10px; align-items: center; padding: 11px 2px; font-size: 14.5px; }
.account.tappable { cursor: pointer; border-radius: var(--r-sm); }
.account .name-btn { min-width: 0; padding: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; cursor: pointer; color: inherit; font: 600 15px var(--body); background: none; border: 0; }
.account .name-btn:focus-visible { outline-offset: 4px; }
.account .spent { min-width: 66px; text-align: right; color: var(--muted); font: 400 13.5px var(--num); }
.account .balance { min-width: 86px; text-align: right; font: 600 14.5px var(--num); }
.account .balance.unset { font: 500 12.5px var(--body); color: var(--muted); }
.acc-icon { display: grid; place-items: center; width: 24px; height: 24px; font-size: 17px; line-height: 1; }
.acc-icon svg { width: 22px; height: 22px; fill: color-mix(in srgb, var(--c, #dcb078) 24%, transparent); stroke: var(--c, #a39a88); stroke: color-mix(in srgb, var(--c, #a39a88) 80%, #1f1d1b); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.account-head { padding: 0 2px 4px; font: 600 11px var(--body); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.account-head .c-name { grid-column: 1 / 3; }
.account-head .c-spent { grid-column: 3; text-align: right; }
.account-head .c-balance { grid-column: 4 / 6; text-align: right; }
.q-slot { display: grid; place-items: center; }
.qmark { flex: none; width: 24px; height: 24px; padding: 0; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); font: 600 12.5px var(--body); background: none; border: 1.5px solid var(--muted); border-radius: 50%; }
.qmark:hover { color: var(--ink); border-color: var(--ink); }
.head-left { display: flex; align-items: center; gap: 10px; }
.help { margin: 0 0 14px; padding: 11px 13px; font-size: 13.5px; line-height: 1.5; background: var(--tint-sand); border: 1.5px solid var(--hairline); border-radius: var(--r-sm); }
.box.accounts-card { box-shadow: 5px 6px 0 var(--sh-sage); }
@media (max-width: 440px) { .account .spent .cur, .account .balance .cur { display: none; } .account .spent { min-width: 54px; } }
.overall { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 12px; border-top: 2px solid var(--ink); font-weight: 700; }
.overall span:last-child { font-family: var(--num); }

.entry { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 2px; cursor: pointer; border-radius: var(--r-sm); }
.entry:hover, .account.tappable:hover { background: rgba(220, 176, 120, .14); }
.entry .badge { width: 38px; height: 38px; display: grid; place-items: center; font-size: 18px; background: var(--tint-sand); border: 2px solid var(--ink); border-radius: var(--r-blob); }
.entry .what { min-width: 0; }
.entry .what b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.entry .what small { color: var(--muted); font-size: 12.5px; }
.entry .amount { font: 600 15.5px var(--num); white-space: nowrap; text-align: right; }
.entry .amount.income { color: var(--income); }

.sorter { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.sorter h2 { margin: 0; }
.sorter .tabs { margin: 0; flex-wrap: nowrap; }
.sorter .tab { padding: 5px 10px; font-size: 12.5px; flex: none; }

.facts li { display: flex; justify-content: space-between; gap: 14px; padding: 11px 2px; font-size: 14px; }
.facts li span:first-child { color: var(--muted); }
.facts li b { text-align: right; font-weight: 700; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font: 500 10px var(--num); fill: var(--muted); }
.chart .grid { stroke: var(--hairline); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .bar { fill: #ffd6ba; stroke: var(--ink); stroke-width: 2.5; }
.chart .slice { stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.legend { list-style: none; margin: 16px 0 0; padding: 0; }
.legend li { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 7px 0; font-size: 14px; border-bottom: 1.5px dashed var(--hairline); }
.legend li:last-child { border-bottom: 0; }
.legend .dot { width: 14px; height: 14px; border: 2px solid var(--ink); border-radius: var(--r-blob); }
.legend .pct { color: var(--muted); font-size: 13px; }
.legend .amt { font-family: var(--num); font-weight: 500; }

/* ---------- forms ---------- */
label { display: block; margin: 14px 0 6px; font-weight: 700; font-size: 14px; }
.opt { font-weight: 400; color: var(--muted); }
input, select {
  width: 100%; padding: 11px 13px; font: 500 16px var(--body); color: var(--ink);
  background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-sm);
}
input::placeholder { color: #b0a692; }
input:focus, select:focus { outline: none; box-shadow: 3px 3px 0 var(--sh-terracotta); }
.hint { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.error {
  margin: 0 0 14px; padding: 10px 13px; color: #7d2f28; background: #fbe4e0;
  border: 2px solid var(--danger); border-radius: var(--r-sm); font-size: 14.5px;
}
.notice {
  margin: 0 0 14px; padding: 10px 13px; background: var(--tint-sage);
  border: 2px solid var(--ink); border-radius: var(--r-sm); font-size: 14.5px; font-weight: 600;
}
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-actions .btn { flex: 1; padding: 12px; font-size: 15px; }

/* ---------- auth pages ---------- */
.auth { width: 100%; max-width: 420px; margin: 0 auto; padding: calc(40px + env(safe-area-inset-top, 0px)) 22px 40px; }
.wordmark { font: 400 40px/1 var(--display); letter-spacing: -.01em; margin: 0; }
.wordmark span { display: block; width: 74px; height: 6px; margin-top: 12px; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
.lede { margin: 18px 0 22px; color: var(--ink-soft); }
.alt { margin: 22px 0 0; color: var(--muted); font-size: 14.5px; }

/* ---------- settings folds ---------- */
.fold { margin: 0 5px 16px 0; background: var(--card); border: 2.5px solid var(--ink); border-radius: var(--r-md); box-shadow: 4px 5px 0 var(--sh-hair); }
.fold > summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; cursor: pointer; list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: '▾'; color: var(--muted); font-size: 14px; transition: transform .15s ease; }
.fold[open] > summary::after { transform: rotate(180deg); }
.fold .title { font: 400 19px/1.1 var(--display); }
.fold .peek { color: var(--muted); font-size: 13px; margin-left: auto; margin-right: 4px; }
.fold .inner { padding: 4px 18px 20px; border-top: 1.5px dashed var(--hairline); }
.person { display: flex; align-items: center; gap: 14px; min-width: 0; }
.avatar { flex: none; width: 48px; height: 48px; display: grid; place-items: center; font: 400 22px var(--display); color: var(--card); background: var(--terracotta); border: 2.5px solid var(--ink); border-radius: var(--r-blob); box-shadow: 2px 3px 0 var(--ink); }
.person b { display: block; font-size: 17px; overflow: hidden; text-overflow: ellipsis; }
.person small { display: block; color: var(--muted); font-size: 12.5px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; text-align: center; }
.stats div { padding: 10px 4px; background: var(--tint-sand); border: 2px solid var(--ink); border-radius: var(--r-sm); }
.stats b { display: block; font: 600 20px var(--num); }
.stats small { font-size: 12px; color: var(--ink-soft); }

/* ---------- chips (category / account picker) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; margin: 0; font-weight: 600; font-size: 14px; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-sm); }
.chip input:checked + span { background: var(--tint-terracotta); box-shadow: 2px 3px 0 var(--ink); }
.chip input:focus-visible + span { outline: 3px solid var(--terracotta); outline-offset: 2px; }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; align-items: flex-start; justify-content: space-around;
  padding: 12px max(6px, calc((100% - 640px) / 2)) max(22px, calc(8px + env(safe-area-inset-bottom, 0px)));
  background: rgba(255, 251, 241, .9); border-top: 2.5px solid var(--ink);
  -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%);
}
.tabbar > * { max-width: 120px; }
.tabbar .item {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 5px 2px 3px; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer;
  font: 600 10px var(--body); letter-spacing: .07em; text-transform: uppercase;
}
.tabbar .item svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar .item.current { color: var(--ink); }
.tabbar .item.current::after { content: ''; width: 18px; height: 3px; margin-top: 1px; background: var(--terracotta); border-radius: 2px; }
.tabbar .plus {
  flex: 0 0 auto; width: 60px; height: 60px; margin-top: -24px; display: grid; place-items: center;
  color: var(--card); background: var(--terracotta); border: 2.5px solid var(--ink); border-radius: var(--r-blob);
  box-shadow: 3px 4px 0 var(--ink); text-decoration: none; cursor: pointer;
}
.tabbar .plus svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.tabbar .plus:active { transform: translate(2px, 2px); box-shadow: 1px 2px 0 var(--ink); }

/* ---------- dialogs and the new-entry sheet ---------- */
dialog { padding: 0; color: var(--ink); background: transparent; border: 0; max-width: none; max-height: none; }
dialog::backdrop { background: rgba(31, 29, 27, .45); }
.dlg { width: min(370px, calc(100vw - 40px)); padding: 24px 24px 22px; background: var(--card); border: 2.5px solid var(--ink); border-radius: var(--r-lg); box-shadow: 6px 7px 0 var(--danger); }
.dlg.neutral { box-shadow: 6px 7px 0 var(--sh-sage); }
.dlg h3 { font: 400 21px/1.15 var(--display); margin: 0 0 8px; }
.dlg p { margin: 0 0 18px; color: var(--ink-soft); font-size: 15px; }
.dlg .form-actions { margin-top: 0; }

dialog.sheet { margin: auto auto 0; width: 100%; max-width: 560px; }
dialog.sheet .panel {
  max-height: 92dvh; overflow-y: auto; padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--card); border: 2.5px solid var(--ink); border-bottom: 0; border-radius: 22px 22px 0 0 / 18px 18px 0 0;
  box-shadow: 0 -5px 0 var(--sh-terracotta);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-head h2 { font: 400 24px/1 var(--display); }
.sheet-head .close { width: 36px; height: 36px; font-size: 22px; line-height: 1; cursor: pointer; background: none; border: 2px solid var(--ink); border-radius: var(--r-blob); color: var(--ink); }
.kind-switch { display: flex; gap: 8px; margin: 14px 0 4px; }
.kind-switch .tab { flex: 1; }
.amount-input { font: 600 34px var(--num); padding: 10px 14px; letter-spacing: -.01em; }

@media (min-width: 700px) {
  dialog.sheet { margin: auto; }
  dialog.sheet .panel { border-bottom: 2.5px solid var(--ink); border-radius: var(--r-lg); box-shadow: 6px 7px 0 var(--sh-terracotta); }
}
@media (max-width: 380px) {
  .page { padding-left: 14px; padding-right: 14px; }
  .total .figure { font-size: 38px; }
}
@media (prefers-reduced-motion: no-preference) {
  .view { animation: in .22s ease; }
  @keyframes in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

/* ---------- extras: settings, labels page, recurring cards, key box ---------- */
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.fold.link { display: flex; align-items: center; gap: 12px; padding: 16px 18px; color: inherit; text-decoration: none; font-weight: 400; }
.fold.link::after { content: '›'; color: var(--muted); font-size: 22px; line-height: 1; }
.fold.link:active { transform: translate(1px, 1px); }
.fold .inner h3 { font: 700 14px/1.2 var(--body); margin: 18px 0 6px; }
.fold .inner h3:first-child { margin-top: 14px; }
.fold .inner .note { margin-top: 6px; }
.fold .inner .form-actions .btn { flex: 0 1 auto; }
.error-title { margin: 0; font-weight: 700; }
.error-list { margin: 8px 0 0; padding-left: 20px; font-size: 14px; }
input.file { padding: 10px 12px; font-size: 14px; background: var(--paper); border-style: dashed; margin-top: 10px; }
.code { margin: 8px 0 0; padding: 12px 14px; overflow-x: auto; white-space: pre; background: var(--paper); border: 2px dashed var(--hairline); border-radius: var(--r-sm); font: 500 12.5px/1.55 ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }
code { font: 500 .92em ui-monospace, 'SF Mono', Menlo, Consolas, monospace; background: var(--tint-sand); padding: 1px 5px; border-radius: 5px; }
.notice .key-title { margin: 0 0 8px; }
.notice .key { display: block; margin-bottom: 10px; padding: 9px 10px; overflow-wrap: anywhere; font-size: 13px; background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-sm); user-select: all; }

/* categories and accounts */
.label-row { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 8px 12px; align-items: center; width: 100%; padding: 12px 2px; text-align: left; cursor: pointer; background: none; border: 0; border-radius: var(--r-sm); color: inherit; font: inherit; }
.label-row:hover { background: rgba(220, 176, 120, .14); }
.label-row .dot { width: 14px; height: 14px; border: 2px solid var(--ink); border-radius: var(--r-blob); }
.label-row .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.label-row small { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; }
.label-row .side { font: 600 14px var(--num); text-align: right; }
.label-row.archived .name, .label-row.archived .dot { opacity: .5; }
.pill { display: inline-block; margin-left: 6px; padding: 0 8px; font: 700 10.5px/18px var(--body); letter-spacing: .05em; text-transform: uppercase; vertical-align: 1px; background: var(--tint-sand); border: 1.5px solid var(--ink); border-radius: 999px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { position: relative; width: 34px; height: 34px; margin: 0; cursor: pointer; }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.swatch span { display: block; width: 100%; height: 100%; border: 2px solid var(--ink); border-radius: var(--r-blob); }
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--ink); }
.swatch input:focus-visible + span { outline: 3px solid var(--terracotta); outline-offset: 4px; }

/* recurring cards */
.auto { margin: 0 5px 14px 0; padding: 15px 16px; background: var(--card); border: 2.5px solid var(--ink); border-radius: var(--r-md); box-shadow: 4px 5px 0 var(--sh-hair); }
.auto.paused { background: transparent; border-style: dashed; box-shadow: none; }
.auto.paused .auto-top, .auto.paused .auto-when { opacity: .55; }
.auto-top { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.auto-top .badge { width: 38px; height: 38px; display: grid; place-items: center; font-size: 18px; background: var(--tint-sand); border: 2px solid var(--ink); border-radius: var(--r-blob); }
.auto-top b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auto-top small { color: var(--muted); font-size: 12.5px; }
.auto-top .amount { font: 600 16px var(--num); }
.auto-top .amount.income { color: var(--income); }
.auto-when { margin: 10px 0 0; font-size: 13.5px; color: var(--ink-soft); }
.auto-actions { display: flex; gap: 8px; margin-top: 12px; }

.sheet .form-actions { flex-wrap: wrap; }

/* ---------- round 3: shortcut banner, search, account detail, transfers, profile ---------- */
.box.alert { background: #f8e6df; box-shadow: 5px 6px 0 #ebbfae; }
.box.alert h2 { font-size: 18px; margin-bottom: 8px; }
.box.alert .form-actions { margin-top: 14px; }
.box.alert .form-actions .btn { flex: 0 0 auto; text-decoration: none; }
.search { margin: 2px 0 8px; padding: 9px 12px; font-size: 15px; }
.rows.scroll { max-height: 460px; overflow-y: auto; padding-right: 4px; }
.account .balance.unset { font: 500 12.5px var(--body); color: var(--muted); }
.entry .amount.transfer { color: var(--ink-soft); }
.dlg.wide { width: min(480px, calc(100vw - 32px)); }
.dlg .sheet-head h3 { margin: 0; }
.dlg .sheet-head { margin-bottom: 10px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 4px 0 14px; padding-bottom: 12px; border-bottom: 1.5px dashed var(--hairline); }
.pair small { display: block; font: 600 11.5px var(--body); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pair b { display: block; margin-top: 2px; font: 600 22px var(--num); }
.chart .hole { fill: var(--card); stroke: var(--ink); stroke-width: 2.5; }
.kind-switch .tab { padding: 8px 6px; }
.pill.shortcut { background: var(--tint-terracotta); }
.edit-profile { margin-top: 16px; }
.edit-profile > summary { list-style: none; width: max-content; }
.edit-profile > summary::-webkit-details-marker { display: none; }
.edit-profile[open] > summary { background: var(--tint-sand); }
.edit-profile form { margin-top: 6px; padding-top: 4px; border-top: 1.5px dashed var(--hairline); }

/* ---------- round 4: install banner, entry detail, guide ---------- */
.install { display: flex; gap: 14px; align-items: flex-start; }
.install img { flex: none; border: 2.5px solid var(--ink); border-radius: 12px 9px 11px 10px / 10px 12px 9px 11px; box-shadow: 2px 3px 0 var(--ink); }
.install h2 { font-size: 18px; margin-bottom: 4px; }
.install .form-actions { margin-top: 12px; }
.install .form-actions .btn { flex: 0 0 auto; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; margin: 4px 0 18px; }
.detail-grid dt { font: 600 11.5px var(--body); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.detail-grid dd { margin: 3px 0 0; font: 600 16px var(--body); overflow-wrap: anywhere; }
.detail-grid #ed-amount { font: 600 24px var(--num); }
.dlg .form-actions .btn.danger { flex: 1 1 auto; }
ol.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; }
ol.steps > li { counter-increment: step; position: relative; padding-left: 62px; }
ol.steps > li::before { content: counter(step); position: absolute; left: 16px; top: 18px; width: 34px; height: 34px; display: grid; place-items: center; font: 400 18px var(--display); color: var(--card); background: var(--terracotta); border: 2.5px solid var(--ink); border-radius: var(--r-blob); box-shadow: 2px 3px 0 var(--ink); }
ol.steps h2 { margin-bottom: 8px; }
ol.actions { margin: 10px 0 0; padding-left: 20px; }
ol.actions > li { margin-bottom: 14px; font-size: 14.5px; line-height: 1.55; }
ol.actions .code { margin: 6px 0; }
ol.steps .code { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- round 5: payment methods / categories pop-up ---------- */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.icon-btn { flex: none; width: 34px; height: 34px; display: grid; place-items: center; padding: 0; cursor: pointer; color: var(--ink); background: var(--card); border: 2px solid var(--ink); border-radius: var(--r-sm); }
.icon-btn:active { transform: translate(1px, 1px); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.glyph { flex: none; width: 32px; height: 32px; display: grid; place-items: center; font-size: 15px; line-height: 1; border: 2px solid var(--ink); border-radius: var(--r-blob); background: var(--tint-sand); background: color-mix(in srgb, var(--c, #dcb078) 38%, var(--card)); }
.glyph svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dlg.manager { width: min(460px, calc(100vw - 28px)); max-height: 90dvh; overflow-y: auto; padding: 22px 20px 20px; box-shadow: 6px 7px 0 var(--sh-terracotta); }
.dlg.manager .sheet-head h3 { font-size: 26px; }
.dlg.manager .note { margin: 0 0 16px; }
.manager-row { display: flex; align-items: center; gap: 12px; width: 100%; margin: 0 0 12px; padding: 12px 14px; text-align: left; cursor: pointer; color: inherit; font: 600 16px var(--body); background: var(--card); border: 2.5px solid var(--ink); border-radius: var(--r-md); box-shadow: 2px 3px 0 var(--sh-hair); }
.manager-row:active { transform: translate(1px, 1px); }
.manager-row .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manager-row .count { margin-left: auto; padding-left: 8px; font: 500 13.5px var(--num); color: var(--muted); }
.manager-row.archived { border-style: dashed; box-shadow: none; }
.manager-row.archived .name, .manager-row.archived .glyph { opacity: .55; }
.add-dashed { display: block; width: 100%; margin: 4px 0 12px; padding: 14px; text-align: center; cursor: pointer; color: var(--ink); font: 600 14.5px var(--body); background: var(--tint-sand); border: 2.5px dashed var(--ink); border-radius: var(--r-md); }
.btn.block.done { margin-top: 0; background: var(--tint-sage); color: var(--ink); border-width: 2.5px; box-shadow: 2px 3px 0 var(--sh-sage); }

/* the name shortens ("Fab Isl…") but its tags never get clipped */
.manager-row .name, .label-row .name { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: clip; }
.name-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manager-row .pill, .label-row .pill { flex: none; margin-left: 0; }
/* when name + tag don't fit side by side, the tag wraps under the name instead of eating it */
.manager-row .name, .label-row .name { flex-wrap: wrap; row-gap: 4px; overflow: visible; }
.manager-row .name-text, .label-row .name-text { max-width: 100%; }

/* ---------- dashboard cards: small-caps labels instead of big headings (like the original) ---------- */
[data-page="home"] .box:not(.alert):not(.install) > h2,
[data-page="home"] .box:not(.alert):not(.install) .card-head h2,
[data-page="home"] .box:not(.alert):not(.install) .sorter h2 { font: 600 11.5px/1.2 var(--body); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
[data-page="home"] .box > h2 { margin-bottom: 14px; }

/* tags drop to a second line instead of squeezing a name */
.manager-row .name, .label-row .name { flex-wrap: wrap; row-gap: 4px; overflow: visible; }
.manager-row .name-text, .label-row .name-text { max-width: 100%; }

/* One set of columns for the header and every row, so amounts line up whatever their length.
   (Browsers without subgrid keep the simpler per-row layout above.) */
.account-table { display: grid; grid-template-columns: 24px minmax(0, 1fr) max-content max-content 26px; column-gap: 8px; }
@supports (grid-template-columns: subgrid) {
  .account-table > .account, .account-table > ul, .account-table > ul > li, .account-table > ul > li > .account {
    display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; }
  .account-table .account { padding-left: 0; padding-right: 0; }
  .account-table .account .spent, .account-table .account .balance { min-width: 0; }
}

/* =====================================================================================
   AUTO WIDTH. One column on a phone, two on a laptop or desktop, a top bar on wide screens.
   Nothing below depends on a device name: columns appear when there is room for them.
   ===================================================================================== */
:root { --gutter: clamp(14px, 3.4vw, 36px); --content: 1240px; }
@media (min-width: 1700px) { :root { --content: 1420px; } }

/* Windows: dark mode must not darken form controls, and classic scrollbars must not shift the layout. */
html { color-scheme: light; scrollbar-gutter: stable; scrollbar-width: thin; scrollbar-color: #cdbf9f transparent; }
* { scrollbar-width: thin; scrollbar-color: #cdbf9f transparent; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: #cdbf9f; background-clip: padding-box; border: 3px solid transparent; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background-color: #b8a883; }
::-webkit-scrollbar-track { background: transparent; }

.page { max-width: var(--content); padding-left: var(--gutter); padding-right: var(--gutter); }
.page[data-page="settings"], .page[data-page="labels"] { max-width: 780px; }
.page[data-page="guide"] { max-width: 860px; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 24px; }
.page-head .sub { margin-top: 0; }

/* the columns: as many 420px+ columns as fit, never fewer than one */
.dash { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); column-gap: clamp(20px, 3vw, 40px); align-items: start; }
.dash > .col { min-width: 0; }

/* period tabs and the previous/next bar share a row when there is room */
#period-controls { display: flex; flex-wrap: wrap; gap: 0 20px; align-items: center; }
#period-controls .tabs { flex: 1 1 360px; margin: 0 0 18px; }
#period-controls .range { flex: 1 1 300px; margin: 0 5px 18px 0; }

#recurring-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); column-gap: 20px; align-items: start; }
.rows.scroll { max-height: min(62vh, 640px); }
.chart { max-height: 420px; }
.search { font-size: 16px; }                         /* 16px: iPhones zoom into smaller fields */
.plus-label { display: none; }

/* ---------- wide screens: the tab bar moves to the top ---------- */
@media (min-width: 900px) {
  .page { padding-top: 96px; padding-bottom: 56px; }
  .tabbar { top: 0; bottom: auto; justify-content: flex-start; align-items: center; gap: 6px;
    padding: 10px max(var(--gutter), calc((100% - var(--content)) / 2 + var(--gutter)));
    border-top: 0; border-bottom: 2.5px solid var(--ink); }
  .tabbar > * { max-width: none; }
  .tabbar .item { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 9px 14px; font-size: 12px; border: 2px solid transparent; border-radius: var(--r-sm); }
  .tabbar .item svg { width: 20px; height: 20px; }
  .tabbar .item.current { background: var(--tint-terracotta); border-color: var(--ink); }
  .tabbar .item.current::after { display: none; }
  .tabbar .plus { order: 10; margin: 0 0 0 auto; width: auto; height: 44px; padding: 0 18px 0 14px; gap: 8px; border-radius: var(--r-md); display: inline-flex; flex-direction: row; align-items: center; justify-content: center; }
  .tabbar .plus svg { width: 20px; height: 20px; }
  .plus-label { display: inline; font: 700 14px var(--body); letter-spacing: .01em; }
  .auth { padding-top: 12vh; }
}

/* ---------- mouse and keyboard (Windows, Mac, Linux) ---------- */
@media (hover: hover) {
  .btn:hover:not(:disabled), .tab:hover:not(.active) { background: #fff3da; }
  .btn.primary:hover, .tab.active:hover, .btn.danger:hover { filter: brightness(1.07); }
  .manager-row:hover, .label-row:hover { background: #fff3da; }
  .icon-btn:hover, .close:hover { background: #fff3da; }
  .tabbar .item:hover { color: var(--ink); }
  .chip:hover span { background: #fff3da; }
}

/* ---------- touch screens: fingers need bigger targets ---------- */
@media (pointer: coarse) {
  .tab, .btn.small { min-height: 44px; }
  .icon-btn, .close { min-width: 44px; min-height: 44px; }
  .qmark { position: relative; }
  .qmark::after { content: ''; position: absolute; inset: -10px; }
  .chip span { padding: 11px 14px; }
  .entry { padding-top: 14px; padding-bottom: 14px; }
  .account { padding-top: 13px; padding-bottom: 13px; }
  .manager-row, .label-row { min-height: 56px; }
  .swatch { width: 40px; height: 40px; }
  .range button { flex-basis: 56px; min-height: 46px; }
  input, select { min-height: 46px; }
}

/* ---------- very small phones ---------- */
@media (max-width: 360px) {
  .total .figure { font-size: 34px; }
  .tabs .tab { padding: 8px 4px; font-size: 13px; }
  .tabbar .item { font-size: 9px; letter-spacing: .03em; }
  .box { padding: 16px 16px 18px; }
}

/* ---------- phones held sideways: the bottom bar must not eat the screen ---------- */
@media (max-height: 500px) and (max-width: 899px) {
  .tabbar { padding-top: 6px; padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
  .tabbar .plus { width: 48px; height: 48px; margin-top: -14px; }
  .page { padding-bottom: 96px; }
}
