/* Base tokens. Light first, Apple grays, one thin spectral line as the signature. */
:root {
  --bg: #f5f5f7;
  --page: #ffffff;
  --surface: #ffffff;
  --hover: rgba(0, 0, 0, 0.035);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --line: rgba(0, 0, 0, 0.08);
  --line-2: rgba(0, 0, 0, 0.12);
  --track: rgba(0, 0, 0, 0.07);
  --accent: #0071e3;
  --good: #2fa35a;
  --group: #f2f2f7;
  --card: #ffffff;
  --card-edge: rgba(0, 0, 0, 0.04);
  --fill: rgba(118, 118, 128, 0.1);
  --fill-2: rgba(118, 118, 128, 0.16);
  --good-fill: rgba(52, 199, 89, 0.13);
  --warn-fill: rgba(255, 159, 10, 0.15);
  --bad-fill: rgba(255, 59, 48, 0.12);
  --warn: #b26a00;
  --bad: #d70015;
  --bar-in: #1d1d1f;
  --bar-out: #b0b0b6;
  --scrim: rgba(0, 0, 0, 0.28);
  --glow: rgba(120, 100, 255, 0.35);
  --spectral: linear-gradient(90deg, #5ac8fa, #5856d6 35%, #af52de 60%, #ff375f 85%, #ff9f0a);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --radius: 14px;
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --page: #000000;
    --surface: #1c1c1e;
    --hover: rgba(255, 255, 255, 0.05);
    --text: #f5f5f7;
    --text-2: #a1a1a6;
    --text-3: #8e8e93;
    --line: rgba(255, 255, 255, 0.1);
    --line-2: rgba(255, 255, 255, 0.16);
    --track: rgba(255, 255, 255, 0.12);
    --accent: #2997ff;
    --good: #30d158;
    --group: #000000;
    --card: #1c1c1e;
    --card-edge: rgba(255, 255, 255, 0.06);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(118, 118, 128, 0.32);
    --good-fill: rgba(48, 209, 88, 0.11);
    --warn-fill: rgba(255, 179, 64, 0.16);
    --bad-fill: rgba(255, 69, 58, 0.16);
    --warn: #ffb340;
    --bad: #ff453a;
    --bar-in: #f5f5f7;
    --bar-out: #636366;
    --scrim: rgba(0, 0, 0, 0.6);
    --glow: rgba(140, 120, 255, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}

.wordmark {
  position: relative;
  display: inline-block;
  font: 600 22px/1.1 var(--font-display);
  letter-spacing: -0.02em;
  padding-bottom: 6px;
}
.wordmark .spectral {
  position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: var(--spectral);
  box-shadow: 0 0 6px var(--glow);
}

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: 500 15px/1 var(--font); padding: 13px 16px; border-radius: 12px; cursor: pointer; width: 100%;
}
.btn.primary { background: var(--text); color: var(--bg); border-color: transparent; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.field { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.field input, .field select, .field textarea {
  font: 500 17px/1.2 var(--font); color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%;
}
#code { font-family: var(--mono); letter-spacing: 0.3em; }
.stack { display: grid; gap: 12px; }

body.login { min-height: 100dvh; display: grid; place-items: center; background: var(--page); }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 20px; padding-block: 48px; }
.login-card .wordmark { justify-self: start; }
.login-sub { margin: 0; color: var(--text-2); }
.recovery summary { color: var(--text-2); font-size: 14px; cursor: pointer; margin-bottom: 12px; }
.login-msg { min-height: 1.4em; margin: 0; font-size: 14px; color: var(--text-2); }
.login-msg[data-kind="error"] { color: var(--bad); }
.login-msg[data-kind="ok"] { color: var(--good); }

/* ------------------------------------------------------------------------- */
/* Dashboard                                                                  */
/* ------------------------------------------------------------------------- */

body.app {
  padding: 0;
  background: var(--page);
  font-size: 16px;
  min-height: 100dvh;
}
html.locked, html.locked body { overflow: hidden; }

.num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.good { color: var(--good); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

button { font: inherit; color: inherit; }

/* Top bar: sticky, subtle glass, hairline. */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--page) 78%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 1120px; margin: 0 auto;
  padding: 10px var(--gutter);
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
}
.topbar .wordmark { font-size: 20px; padding-bottom: 5px; }
.fresh {
  flex: 1; min-width: 0; margin: 0 4px 0 0;
  text-align: right; font-size: 13px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fresh.warn { color: var(--warn); }
.fresh.bad { color: var(--bad); font-weight: 500; }

.icon-btn {
  appearance: none; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; display: block; }
.icon-btn[aria-busy="true"] { cursor: progress; }
.icon-btn[aria-busy="true"] svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.wrap {
  max-width: 1120px; margin: 0 auto;
  padding: 0 var(--gutter) env(safe-area-inset-bottom);
}

/* Plain-words status lines above the hero. */
.notices { display: grid; gap: 6px; padding-top: 14px; }
.notices:empty { display: none; }
.notice {
  margin: 0; font-size: 14px; line-height: 1.4; color: var(--text-2);
  padding-left: 14px; position: relative;
}
.notice::before {
  content: ""; position: absolute; left: 0; top: 0.5em;
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.notice.warn { color: var(--warn); }
.notice.bad { color: var(--bad); }
.notice.quiet { color: var(--text-2); }
.notice.quiet::before { background: var(--text-3); }

.main { padding-bottom: 24px; }
.loading, .empty { color: var(--text-3); font-size: 15px; margin: 32px 0; }

.col { min-width: 0; }

/* Sections and rows */
.section { margin-top: 40px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.section-head h2 { margin: 0; font: 600 17px/1.3 var(--font-display); letter-spacing: -0.01em; }
.section-meta { font-size: 13px; color: var(--text-2); text-align: right; }
.section-meta .num { color: var(--text); }
.section-note { margin: 10px 0 0; font-size: 13px; color: var(--text-2); }
.section-note .num { color: var(--text); }

.rows { list-style: none; margin: 0; padding: 0; }
.rows > li + li { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 0; min-height: 60px; width: 100%;
}
.row-btn {
  appearance: none; border: 0; background: none; text-align: left; cursor: pointer;
}
.row-btn:hover .row-title { color: var(--accent); }
.row-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.row-title { font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 14px; color: var(--text-2); }
.row-sub .num { font-size: 13px; }
.row-end { flex: none; display: grid; justify-items: end; gap: 3px; text-align: right; }
.row-end > .num { font-size: 16px; }
.row-note { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.row-end-line { display: flex; align-items: center; gap: 6px; }
.chev { width: 14px; height: 14px; color: var(--text-3); flex: none; }

.row-spend {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
  column-gap: 12px; row-gap: 10px;
}
.bar {
  grid-column: 1 / -1;
  display: block; position: relative; height: 3px; border-radius: 3px;
  background: var(--track); overflow: hidden;
}
.bar-fill { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--text-3); }
.bar-fill.high { background: var(--warn); }

/* Trend chart */
.trend-box { margin-top: 14px; }
.trend-box svg { display: block; width: 100%; height: auto; overflow: visible; }
.trend-box .tick { font: 11px var(--mono); fill: var(--text-3); }
.trend-box .mlabel { font: 500 12px var(--font); fill: var(--text-2); }
.trend-box .mnote { font: 11px var(--font); fill: var(--text-3); }
.trend-box .grid { stroke: var(--line); stroke-width: 1; }
.trend-box .base { stroke: var(--line-2); stroke-width: 1; }
.trend-box .b-in { fill: var(--bar-in); }
.trend-box .b-out { fill: var(--bar-out); }
.trend-box .partial { opacity: 0.38; }
.legend { display: flex; gap: 14px; align-items: center; font-size: 13px; color: var(--text-2); flex-wrap: wrap; justify-content: flex-end; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.sw-in { background: var(--bar-in); }
.sw-out { background: var(--bar-out); }

/* v2 home: grouped surface, white inset cards, one anchor chart. */
body.app { background: var(--group); position: relative; }
body.app::before {
  /* The one soft wash, behind the top card only, fading out within ~280px. */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 340px; z-index: 0; pointer-events: none;
  background:
    radial-gradient(55% 100% at 18% 0%, rgba(90, 200, 250, 0.12), transparent 70%),
    radial-gradient(45% 90% at 58% 0%, rgba(175, 82, 222, 0.09), transparent 70%),
    radial-gradient(40% 80% at 92% 0%, rgba(255, 159, 10, 0.08), transparent 70%);
  -webkit-mask-image: linear-gradient(#000 40%, transparent);
  mask-image: linear-gradient(#000 40%, transparent);
}
.topbar { background: color-mix(in srgb, var(--group) 70%, transparent); border-bottom-color: transparent; }
.topbar.scrolled { border-bottom-color: var(--line); }
.wrap { position: relative; z-index: 1; }
.main { padding-top: 6px; }

.card {
  background: var(--card); border-radius: 18px;
  box-shadow: 0 0 0 0.5px var(--card-edge);
}
.card + .card, .group + .group, .card + .group { margin-top: 12px; }
.group-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin: 28px 16px 8px; font-size: 15px;
}
.group-head h2 { margin: 0; font: 600 15px/1.3 var(--font); color: var(--text-2); letter-spacing: 0; }
.group-meta { color: var(--text-3); font-size: 14px; }
.group-meta .num { color: var(--text-2); }

/* Story card: verdict, the cash path, four chips. */
.story { padding: 20px 18px 16px; }
.hero-stale { display: block; font-size: 14px; margin: 0 0 12px; }
.chip-zone {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 10px;
  font-size: 13px; font-weight: 500; color: var(--text-2);
  padding: 3px 10px 3px 8px; border-radius: 999px; background: var(--fill);
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.dot.good { color: var(--good); } .dot.warn { color: var(--warn); } .dot.bad { color: var(--bad); }
.verdict-line {
  margin: 0; font: 700 30px/1.12 var(--font-display); letter-spacing: -0.025em; text-wrap: balance;
}
.verdict-sub { margin: 8px 0 0; font-size: 15px; color: var(--text-2); text-wrap: pretty; }
.verdict-sub .num { color: var(--text); font-size: 14px; }

.path { position: relative; margin: 18px -4px 0; cursor: pointer; }
.path svg { display: block; width: 100%; height: auto; overflow: visible; }
.path .p-line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.path .p-dash { stroke-dasharray: 5 4; }
.path .p-area { stroke: none; }
.path .p-floor { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 1 4; stroke-linecap: round; fill: none; }
.path .p-zero { stroke: var(--line-2); stroke-width: 1; }
.path .p-axis { font: 12px var(--font); fill: var(--text-3); }
.path .p-floor-label { font: 11px var(--font); fill: var(--text-3); }
.path .p-end { font: 600 13px var(--mono); }
.path .p-start { font: 12px var(--mono); fill: var(--text-2); }
.path .p-dot { stroke: var(--card); stroke-width: 2; }
.s-good { color: var(--good); } .s-tight { color: var(--warn); } .s-short { color: var(--bad); }
.path .tint-good { fill: var(--good-fill); } .path .tint-tight { fill: var(--warn-fill); } .path .tint-short { fill: var(--bad-fill); }
.path .draw { transform-box: fill-box; transform-origin: left center; }
.path.animate .draw { animation: draw 600ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes draw { from { transform: scaleX(0); } }
.path-tip {
  position: absolute; top: 0; transform: translate(-50%, -100%);
  background: var(--text); color: var(--card); font-size: 12px; line-height: 1.3;
  padding: 5px 8px; border-radius: 8px; white-space: nowrap; pointer-events: none;
}
.path-tip[hidden] { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 7px 11px; border-radius: 999px; background: var(--fill);
  font-size: 13px; color: var(--text-2);
}
.chip .num { font-size: 13px; color: var(--text); }
.chip:hover { background: var(--fill-2); }

/* Ad card: one ring, one number. */
.adcard {
  appearance: none; border: 0; width: 100%; text-align: left; cursor: pointer; color: inherit; font: inherit;
  display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 16px; align-items: center;
  padding: 18px;
}
.ring { width: 88px; height: 88px; display: block; position: relative; }
.ring svg { width: 88px; height: 88px; display: block; transform: rotate(-90deg); }
.ring .track { stroke: var(--fill-2); }
.ring .fill { stroke: currentColor; stroke-linecap: round; transition: none; }
.ring.animate .fill { animation: ring 600ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
@keyframes ring { from { stroke-dashoffset: var(--full); } }
.ring-icon { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); }
.ring-icon svg { width: 26px; height: 26px; transform: none; }
.ad-main { display: grid; gap: 2px; min-width: 0; }
.ad-label { font-size: 13px; color: var(--text-2); }
.ad-number { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ad-number .num { font: 500 30px/1.1 var(--mono); letter-spacing: -0.035em; }
.ad-number span:last-child { font-size: 16px; color: var(--text); }
.ad-of { font-size: 15px; color: var(--text-2); }
.ad-of .num { font-size: 14px; color: var(--text-2); }
.ad-if { margin-top: 6px; font-size: 13px; color: var(--text-3); }
.ad-if .num { font-size: 12px; }
.ad-more { margin-top: 8px; font-size: 14px; color: var(--accent); display: inline-flex; align-items: center; gap: 3px; }
.ad-more svg { width: 13px; height: 13px; }

/* Inset list cards with icon tiles (Vesper). */
.list { list-style: none; margin: 0; padding: 0; }
.item-row {
  display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 11px 16px; min-height: 60px; position: relative; width: 100%;
}
button.item-row { appearance: none; border: 0; background: none; text-align: left; cursor: pointer; color: inherit; font: inherit; }
button.item-row:hover { background: var(--hover); }
.list > li:first-child .item-row { border-radius: 18px 18px 0 0; }
.list > li:last-child .item-row { border-radius: 0 0 18px 18px; }
.list > li:only-child .item-row { border-radius: 18px; }
.list > li + li .item-row::before {
  content: ""; position: absolute; top: 0; left: 60px; right: 0; height: 0.5px; background: var(--line-2);
}
.tile {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--fill); color: var(--text-2);
  font: 600 12px/1 var(--font); letter-spacing: 0.01em;
}
.tile svg { width: 17px; height: 17px; }
.tile.t-warn { background: var(--warn-fill); color: var(--warn); }
.tile.t-good { background: var(--good-fill); color: var(--good); }
.item-main { display: grid; gap: 2px; min-width: 0; }
.item-title { font-size: 17px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 14px; line-height: 1.3; color: var(--text-2); }
.item-sub.warn { color: var(--warn); }
.item-end { display: flex; align-items: center; gap: 6px; }
.item-end .num { font-size: 16px; }
.card-note { margin: 8px 16px 0; font-size: 13px; color: var(--text-3); }
.card-note .num { font-size: 12px; color: var(--text-2); }

/* Details: one row, closed by default. */
.details > summary {
  list-style: none; cursor: pointer;
  display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 11px 16px; min-height: 56px; border-radius: 18px;
}
.details > summary::-webkit-details-marker { display: none; }
.details > summary:hover { background: var(--hover); }
.details[open] > summary { border-radius: 18px 18px 0 0; }
.details > summary .chev { transition: transform 160ms ease; }
.details[open] > summary .chev { transform: rotate(90deg); }
.details-body { padding: 4px 16px 18px; border-top: 0.5px solid var(--line-2); }
.sub-sec { margin-top: 20px; }
.sub-sec .section-head { padding-bottom: 6px; }
.sub-sec h3 { margin: 0; font: 600 15px/1.3 var(--font-display); }
.details .rows > li + li { border-top-width: 0.5px; border-top-color: var(--line-2); }

/* Footer */
.foot {
  margin-top: 36px; padding: 18px 4px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13px; color: var(--text-3);
}
.foot p { margin: 0; display: flex; align-items: center; gap: 8px; }
.foot .link-btn { font-size: 14px; }
.lock { width: 13px; height: 13px; }
.link-btn {
  appearance: none; border: 0; background: none; padding: 8px 0; cursor: pointer;
  font-size: 15px; color: var(--accent);
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.link-btn.quiet { color: var(--text-2); }

/* Receipt ledger inside its sheet */
.receipt { list-style: none; margin: 8px 0 0; padding: 0; }
.receipt > li + li { border-top: 1px solid var(--line); }
.receipt-row {
  appearance: none; border: 0; background: none; text-align: left; width: 100%; color: inherit; font: inherit;
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto 14px; gap: 10px; align-items: baseline;
  padding: 12px 0; cursor: pointer;
}
div.receipt-row { cursor: default; }
.receipt-row .op { font-family: var(--mono); color: var(--text-3); text-align: center; }
.receipt-row .lbl { display: grid; gap: 2px; }
.receipt-row .lbl small { font-size: 13px; color: var(--text-2); }
.receipt-row .val .num { font-size: 15px; }
.receipt li.total .receipt-row { font-weight: 600; }
.receipt li.total { border-top-color: var(--line-2); }
.receipt li.short .val { color: var(--bad); }

/* Desktop: story and answer on the left, the lists on the right. */
@media (min-width: 960px) {
  .topbar-in, .wrap { padding-left: 32px; padding-right: 32px; max-width: 1120px; }
  .main.ready { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 0 32px; align-items: start; padding-top: 20px; }
  .col-b > .group:first-child .group-head { margin-top: 2px; }
  .story { padding: 26px 26px 20px; }
  .verdict-line { font-size: 34px; }
  .adcard { padding: 22px 26px; }
  .notices { padding-top: 20px; }
}
@media (min-width: 960px) and (min-height: 820px) {
  .col-a { position: sticky; top: calc(64px + env(safe-area-inset-top)); }
}

/* ------------------------------------------------------------------------- */
/* Sheet: bottom sheet on phone, centered panel on desktop                    */
/* ------------------------------------------------------------------------- */
.sheet {
  border: 0; padding: 0; color: var(--text); background: var(--surface);
  width: 100%; max-width: 100%;
  margin: auto 0 0;
  max-height: calc(100dvh - 40px - env(safe-area-inset-top));
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -1px 0 var(--line);
}
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop { background: var(--scrim); }
.sheet-head {
  flex: none; display: flex; align-items: flex-start; gap: 12px;
  padding: 18px var(--gutter) 12px 20px;
  border-bottom: 1px solid var(--line);
}
.sheet-head > div { flex: 1; min-width: 0; padding-top: 6px; }
.sheet-head h2:focus { outline: none; }
.sheet-head h2 { margin: 0; font: 600 18px/1.3 var(--font-display); letter-spacing: -0.01em; }
.sheet-head p { margin: 2px 0 0; font-size: 14px; color: var(--text-2); }
.sheet-head p:empty { display: none; }
.sheet-head .icon-btn { margin: -2px -6px 0 0; }
.sheet-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 20px calc(24px + env(safe-area-inset-bottom));
}
.sheet-foot {
  flex: none; display: flex; align-items: center; gap: 14px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.sheet-foot[hidden] { display: none; }
.sheet-foot .btn { width: auto; padding-inline: 22px; }
.sheet-foot .save-msg { flex: 1; font-size: 14px; color: var(--text-2); margin: 0; }
.sheet-foot .save-msg.ok { color: var(--good); }
.sheet-foot .save-msg.bad { color: var(--bad); }
.sheet.has-foot .sheet-body { padding-bottom: 24px; }

@media (min-width: 720px) {
  .sheet {
    margin: auto; width: calc(100% - 64px); max-width: 600px;
    max-height: min(780px, calc(100dvh - 96px));
    border-radius: 18px;
    box-shadow: 0 0 0 1px var(--line), 0 24px 64px rgba(0, 0, 0, 0.18);
  }
  .sheet-head { padding: 20px 20px 14px 24px; }
  .sheet-body { padding: 4px 24px 24px; }
  .sheet-foot { padding: 14px 24px; }
}

/* Transactions inside a sheet */
.txns { list-style: none; margin: 0; padding: 0; }
.txn {
  display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 12px; align-items: baseline;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.txn.acct { grid-template-columns: minmax(0, 1fr) auto; }
.txn-date { font-size: 13px; color: var(--text-2); }
.txn-main { display: grid; gap: 2px; min-width: 0; }
.txn-merchant { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-sub { font-size: 13px; color: var(--text-2); display: flex; gap: 8px; align-items: center; min-width: 0; }
.txn-sub > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-amt { font-size: 15px; }
.pending {
  flex: none; font-size: 11px; font-weight: 500; letter-spacing: 0.02em; color: var(--text-2);
  border: 1px solid var(--line-2); border-radius: 4px; padding: 0 5px; line-height: 16px;
}
.total {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 0 0; font-weight: 600;
}
.total .num { font-size: 16px; }
.sheet-lead { margin: 14px 0 6px; color: var(--text-2); font-size: 14px; }

/* "How this is worked out" */
.calc { list-style: none; margin: 8px 0 0; padding: 0; }
.calc li {
  display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; align-items: baseline;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.calc .op { font: 15px var(--mono); color: var(--text-3); text-align: center; }
.calc .lbl { display: grid; gap: 2px; }
.calc .lbl small { font-size: 13px; color: var(--text-2); }
.calc .val { font-size: 15px; }
.calc li.sum { border-bottom-color: var(--line-2); }
.calc li.sum .lbl, .calc li.sum .val { font-weight: 600; }
.calc li.final { border-bottom: 0; padding-top: 14px; }
.calc li.final .val { font-size: 20px; }
.calc-note { margin: 16px 0 0; font-size: 14px; color: var(--text-2); }

/* Settings form */
.settings { display: grid; gap: 0; }
.settings fieldset { border: 0; margin: 0; padding: 20px 0; min-width: 0; border-bottom: 1px solid var(--line); }
.settings fieldset:last-child { border-bottom: 0; }
.settings legend { padding: 0; font: 600 16px/1.3 var(--font-display); margin-bottom: 4px; float: left; width: 100%; }
.settings legend + * { clear: both; }
.settings .help { margin: 0 0 12px; font-size: 13px; color: var(--text-2); clear: both; }
.settings .field { font-size: 13px; }
.settings .field input, .settings .field select, .settings .field textarea { font-size: 16px; padding: 10px 12px; border-radius: 10px; }
.settings .field textarea { font-family: var(--mono); font-size: 14px; line-height: 1.5; resize: vertical; min-height: 120px; }
.settings .field input[type="number"] { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.field-hint { font-size: 12px; color: var(--text-3); }
.field-error { font-size: 13px; color: var(--bad); }
.field-error:empty { display: none; }
.field [aria-invalid="true"] { border-color: var(--bad); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.span2 { grid-column: 1 / -1; }
.item {
  display: grid; gap: 12px; padding: 16px 0;
  border-top: 1px solid var(--line);
}
.item:first-of-type { border-top: 0; padding-top: 8px; }
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.item-head strong { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text); cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.add-btn { justify-self: start; margin-top: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-bottom: 12px; }
.item .checks { margin-bottom: 0; }
.subhead { font-size: 13px; color: var(--text-2); margin: 4px 0 0; }

.grid-client .wide { grid-column: 1 / -1; }
@media (min-width: 520px) {
  .grid-client { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-client .wide { grid-column: span 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
