/* zapp finance — modern private banking
   Cool neutral ground · white elevated cards · layered soft shadows
   Indigo = action/brand · Emerald = money-positive · Rose = negative/warning
   Signature: solid deep-navy balance card. System fonts, zero asset requests. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #0f1222;
  --text-2: #5b6070;
  --text-3: #9096a6;
  --line: #e6e8ee;
  --brand: #5b5bd6;
  --brand-strong: #4646c6;
  --brand-soft: #eeeefc;
  --pos: #0f9d6e;
  --pos-soft: #e5f6ef;
  --neg: #d6455b;
  --neg-soft: #fdecef;
  --hero-a: #14162e;
  --r: 14px;
  --r-sm: 10px;
  --shadow-1: 0 1px 2px rgba(15,18,34,.05), 0 1px 3px rgba(15,18,34,.06);
  --shadow-2: 0 2px 4px rgba(15,18,34,.04), 0 8px 24px rgba(15,18,34,.08);
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; }
html { color-scheme: light; scroll-behavior: smooth; }
body {
  overflow-x: clip;
  font: 15px/1.55 var(--sans);
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}

/* ---------------- header: floating glass bar ---------------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.brand em { font-style: normal; color: var(--brand-strong); }
.nav { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; margin-left: auto; }
.nav a {
  color: var(--text-2); text-decoration: none; font-size: 13.5px; font-weight: 500;
  padding: 8px 13px; min-height: 40px; display: inline-flex; align-items: center;
  border-radius: 999px; transition: background .15s, color .15s;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--brand-strong); background: var(--brand-soft); font-weight: 600; }
.logout-form { display: inline; margin-left: 6px; }

main { max-width: 1200px; margin: 0 auto; padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 40px) 96px; }

/* ---------------- typography ---------------- */
h1 { font-size: clamp(24px, 3.4vw, 32px); font-weight: 700; letter-spacing: -0.025em; margin-bottom: 4px; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--text-3); margin: 34px 0 12px; }
section > h2:first-child { margin-top: 0; }
.lede { color: var(--text-2); max-width: 64ch; margin-bottom: 24px; }
.quiet { color: var(--text-2); font-size: 13.5px; }
a { color: var(--brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
.ok { color: var(--pos); } .hot, .warn-text { color: var(--neg); }
small { font-size: 12.5px; }
b, strong { font-weight: 600; }

/* ---------------- cards: the two page panels ---------------- */
.split { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 22px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.split > section {
  min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-1); padding: clamp(18px, 3vw, 28px);
}

/* ---------------- hero: the balance card ---------------- */
.hero-card {
  overflow: clip;
  color: #fff;
  background: var(--hero-a);
  border-radius: var(--r); padding: 26px 26px 22px; margin-bottom: 20px;
  box-shadow: var(--shadow-2);
}
.hero-card .hero-caption { color: rgba(255,255,255,.72); }
.hero-caption { font-size: 12.5px; font-weight: 500; letter-spacing: .01em; color: var(--text-2); }
.hero-number {
  font-size: clamp(30px, 6.5vw, 64px); font-weight: 700; letter-spacing: -0.03em; line-height: 1.08;
  font-variant-numeric: tabular-nums; margin: 4px 0 10px;
}
.hero-card .hero-number.negative { color: #ffb4c0; }
.health-chip { font-size: 13px; color: #7fe0b8; max-width: 60ch; }
.health-chip.warn { color: #ffd27f; }
.health-chip.bad { color: #ffa9b8; }

/* ---------------- stat grid ---------------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 18px 0 6px; }
.stat {
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.stat span { font-size: 12px; color: var(--text-2); order: -1; }
.stat b { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

/* ---------------- period switcher: segmented ---------------- */
.period-bar {
  display: inline-flex; align-items: center; gap: 4px; margin: 6px 0 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px; box-shadow: var(--shadow-1);
}
.period-bar a {
  min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; color: var(--text-2); font-size: 16px;
}
.period-bar a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.period-bar .dates { font-weight: 600; font-size: 13.5px; padding: 0 10px; font-variant-numeric: tabular-nums; }
.badge { font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 4px 11px; margin-right: 6px; text-transform: capitalize; }
.badge.open { background: var(--pos-soft); color: var(--pos); }
.badge.closed { background: var(--neg-soft); color: var(--neg); }

/* ---------------- tables ---------------- */
table.data { width: 100%; border-collapse: separate; border-spacing: 0; display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data thead, table.data tbody { display: table; width: 100%; }
table.data caption {
  /* display:block tables shrink captions to min-content, stacking one word
     per line; force full width so caption text flows horizontally. */
  display: block; width: 100%; box-sizing: border-box;
  text-align: left; font-size: 13px; color: var(--text-2);
  padding-bottom: 10px; caption-side: top; white-space: normal;
}
table.data th {
  text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); padding: 0 12px 8px 0;
}
table.data td { padding: 13px 12px 13px 0; border-top: 1px solid var(--line); vertical-align: top; }
table.data tr:hover td { background: var(--surface-2); }
table.data .num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; padding-right: 0; }
table.data td:last-child, table.data th:last-child { padding-right: 0; }

/* ---------------- bars: animated in ---------------- */
.chart { margin: 4px 0 8px; }
.bar-row { display: grid; grid-template-columns: minmax(84px, 140px) 1fr auto; gap: 12px; align-items: center; padding: 7px 0; }
.bar-label { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: block; height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill {
  display: block; height: 100%; border-radius: 999px;
  background: var(--brand);
  transform-origin: left center; animation: grow .5s cubic-bezier(.2,.7,.2,1);
}
@keyframes grow { from { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .bar-fill { animation: none; } }
.bar-value { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------------- forms ---------------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.field small { color: var(--text-3); }
input, select {
  font: 15px/1.4 var(--sans); color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 10px 13px; min-height: 44px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
  font-variant-numeric: tabular-nums;
}
input:hover, select:hover { border-color: #cdd1dc; }
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input::placeholder { color: var(--text-3); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 49%, var(--text-2) 50%), linear-gradient(-45deg, transparent 49%, var(--text-2) 50%); background-size: 7px 7px; background-position: calc(100% - 18px) 55%, calc(100% - 11px) 55%; background-repeat: no-repeat; padding-right: 36px; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
.stack { max-width: 440px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 18px; max-width: 640px; }

/* ---------------- buttons ---------------- */
button {
  font: 600 14px/1 var(--sans);
  color: #fff; background: var(--brand); border: 0; border-radius: var(--r-sm);
  padding: 0 20px; min-height: 44px; cursor: pointer;
  box-shadow: var(--shadow-1); transition: background .15s, transform .1s;
}
button:hover { background: var(--brand-strong); }
button:active { transform: translateY(1px); }
button.ghost {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  box-shadow: none; font-weight: 500; padding: 0 14px; min-height: 38px; font-size: 13px;
}
button.ghost:hover { background: var(--surface-2); border-color: #cdd1dc; }
button.danger { background: var(--neg); }
button.danger:hover { background: #b93549; }
.logout-form .ghost { border: 0; background: transparent; color: var(--text-2); }
.logout-form .ghost:hover { color: var(--text); background: var(--surface-2); }

/* ---------------- quick actions ---------------- */
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.quick a {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; font-weight: 500; color: var(--text);
}
.quick a:hover { text-decoration: none; border-color: var(--brand); color: var(--brand-strong); background: var(--brand-soft); }

/* ---------------- flashes ---------------- */
.flash {
  border-radius: var(--r-sm); padding: 12px 16px; margin-bottom: 20px; max-width: 76ch;
  font-size: 14px; border: 1px solid;
}
.flash-ok { background: var(--pos-soft); border-color: #bfe8d6; color: #0b6e4e; }
.flash-warn { background: #fff6e6; border-color: #f3dfb5; color: #8a5a00; }
.flash-error { background: var(--neg-soft); border-color: #f5c6cf; color: #a72f43; }

/* ---------------- misc ---------------- */
.a2hs {
  display: none; gap: 14px; align-items: center; justify-content: space-between;
  margin-top: 40px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  color: var(--text-2); font-size: 13.5px; box-shadow: var(--shadow-1);
}
.a2hs.show { display: flex; }
details summary { min-height: 38px; display: inline-flex; align-items: center; color: var(--text-2); }
.skip { position: absolute; left: -9999px; top: 0; background: var(--text); color: #fff; padding: 12px 18px; z-index: 30; border-radius: 0 0 var(--r-sm) 0; }
.skip:focus { left: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------------- login ---------------- */
.login-page {
  max-width: 400px; margin: clamp(16px, 10vh, 120px) auto 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow-2); padding: clamp(24px, 5vw, 40px);
}
.login-brand { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.login-brand em { font-style: normal; color: var(--brand-strong); }
.login-page .lede { font-size: 14px; margin-bottom: 26px; }
.login-page button { width: 100%; margin-top: 6px; }

@media print { .nav, .quick, button, .a2hs, .top { display: none !important; } .split > section {
  min-width: 0; border: 0; box-shadow: none; padding: 0; } body { background: #fff; } }

/* ---------------- semantic money color: green rewards, rose punishes ---------------- */
.pos-amt { color: var(--pos); }
.neg-amt { color: var(--neg); }
.hero-card .pos-amt { color: #6fe0b0; }
.hero-card .neg-amt { color: #ffa9b8; }
.pie-val .pos-amt, .pie-val .neg-amt { color: inherit; } /* legend stays neutral; the swatch is the color */

/* ---------------- nav icons ---------------- */
.nav a, .logout-form .ghost { gap: 7px; }
.nav a svg, .logout-form .ghost svg { flex: none; opacity: .75; }
.nav a[aria-current="page"] svg { opacity: 1; }
.logout-form .ghost { display: inline-flex; align-items: center; }

/* ---------------- donut ---------------- */
.pie { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; margin: 4px 0 8px; }
.pie-disc {
  width: 168px; height: 168px; border-radius: 50%; flex: none;
  -webkit-mask: radial-gradient(circle at 50% 50%, transparent 52px, #000 52.5px);
  mask: radial-gradient(circle at 50% 50%, transparent 52px, #000 52.5px);
}
.pie-legend { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; min-width: 200px; flex: 1; }
.pie-legend li { display: grid; grid-template-columns: 12px 1fr auto; gap: 9px; align-items: center; font-size: 13px; }
.swatch { width: 12px; height: 12px; border-radius: 4px; }
.pie-label { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pie-val { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ---------------- table cell sub-lines wrap; amounts stay aligned ---------------- */
table.data .num small { display: block; white-space: normal; font-weight: 400; color: var(--text-2); margin-top: 2px; }
table.data td small { line-height: 1.5; }

/* ---------------- phone pass ---------------- */
@media (max-width: 760px) {
  .top { padding: 10px 14px; gap: 8px; }
  .nav {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    margin-left: 0; width: 100%; order: 2;
    scrollbar-width: none; padding-bottom: 2px;
    mask: linear-gradient(90deg, #000 92%, transparent);
    -webkit-mask: linear-gradient(90deg, #000 92%, transparent);
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: none; padding: 8px 11px; }
  main { padding-left: 14px; padding-right: 14px; }
  .split > section {
  min-width: 0; padding: 16px; }
  .hero-card { padding: 20px 18px 18px; }
  .hero-number { font-size: clamp(26px, 9.5vw, 44px); }
  .stat-row { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 8px; }
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-label { grid-column: 1 / -1; padding-bottom: 2px; }
  .pie { justify-content: center; }
  .period-bar { width: 100%; justify-content: space-between; }
  .period-bar .dates { font-size: 12.5px; padding: 0 4px; text-align: center; }
  h1 { font-size: 24px; }
  .quick a { flex: 1 1 calc(50% - 8px); justify-content: center; }
}
@media (max-width: 380px) {
  .stat-row { grid-template-columns: 1fr 1fr; }
  .pie-disc { width: 148px; height: 148px; }
}


/* ---------------- confirmation box + error shake ---------------- */
.confirm-box {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 13px 14px; margin: 4px 0 16px; font-size: 13.5px; color: var(--text-2);
  cursor: pointer;
}
.confirm-box input[type="checkbox"] {
  width: 19px; height: 19px; min-height: 0; flex: none; margin-top: 1px;
  accent-color: var(--brand); cursor: pointer;
}
.confirm-box.shake { animation: shake .45s cubic-bezier(.36,.07,.19,.97); border-color: var(--neg); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
@media (prefers-reduced-motion: reduce) { .confirm-box.shake { animation: none; } }

/* ---------------- blocking low-buffer dialog ---------------- */
.scrim { position: fixed; inset: 0; background: rgba(15, 18, 34, .45); z-index: 40; }
dialog.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 41; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-2); padding: 24px; margin: 0;
}
dialog.modal h2 { margin: 0 0 10px; color: var(--neg); text-transform: none; font-size: 16px; letter-spacing: 0; }
dialog.modal p { margin-bottom: 10px; }
.modal-actions { display: flex; gap: 12px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.modal-actions form { display: inline; }
.modal-actions button { background: var(--neg); }
.modal-actions button:hover { background: #b93549; }
.modal-cancel { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; color: var(--text-2); }
body:has(dialog.modal[open]) { overflow: hidden; }

/* ---------------- action cells: uniform compact chips ---------------- */
table.data td.actions { text-align: right; white-space: nowrap; vertical-align: middle; }
td.actions form { display: inline-block; margin: 2px 0 2px 6px; }
td.actions .ghost, td.actions a, td.actions summary {
  display: inline-flex; align-items: center; min-height: 34px; padding: 0 11px;
  font-size: 12.5px; font-weight: 500; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  text-decoration: none; cursor: pointer;
}
td.actions .ghost:hover, td.actions a:hover { color: var(--brand-strong); border-color: var(--brand); background: var(--brand-soft); text-decoration: none; }
td.actions.pay-cell { white-space: normal; min-width: 190px; }
td.actions.pay-cell form { display: block; margin: 0; }
td.actions details { display: inline-block; margin-left: 6px; }
td.actions details form { display: block; margin-top: 8px; text-align: left; }
@media (max-width: 760px) {
  td.actions .ghost, td.actions a { min-height: 40px; padding: 0 12px; }
}

/* ---------------- list rows: main content left, money + actions right ---------------- */
table.data.list td { border-top: 1px solid var(--line); }
table.data.list tr:first-child td { border-top: 0; }
.cell-main { width: 100%; padding-right: 18px; }
.cell-end { text-align: right; vertical-align: top; }
.cell-end .amt {
  display: block; font-weight: 650; font-size: 16.5px;
  font-variant-numeric: tabular-nums; white-space: nowrap; letter-spacing: -0.01em;
}
.cell-end > small { display: block; margin-top: 1px; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; margin-top: 9px; }
.row-actions form { display: inline; margin: 0; }
.row-actions .ghost, .row-actions a {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 10px;
  font-size: 12px; font-weight: 500; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.row-actions .ghost:hover, .row-actions a:hover { color: var(--brand-strong); border-color: var(--brand); background: var(--brand-soft); text-decoration: none; }
.chip {
  display: inline-block; font-size: 11px; font-weight: 600; vertical-align: 1px;
  background: var(--surface-2); color: var(--text-2);
  border-radius: 999px; padding: 2px 9px; margin-left: 4px;
}
.chip-pos { background: var(--pos-soft); color: var(--pos); }
.chip-brand { background: var(--brand-soft); color: var(--brand-strong); }
.scenarios { list-style: none; padding: 4px 0 2px; margin: 0; }
.scenarios li { font-size: 12.5px; color: var(--text-2); padding: 1px 0; }
.pay-form { margin-top: 10px; max-width: 220px; margin-left: auto; text-align: left; }
.pay-form .field { margin-bottom: 8px; }
.pay-form button { width: 100%; justify-content: center; display: inline-flex; align-items: center; min-height: 36px; font-size: 12.5px; color: var(--text-2); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.pay-form button:hover { color: var(--brand-strong); border-color: var(--brand); background: var(--brand-soft); }
@media (max-width: 560px) {
  .cell-end > small { white-space: normal; }
  .row-actions .ghost, .row-actions a { min-height: 38px; }
}

/* ---------------- build badge ---------------- */
.app-footer { max-width: 1200px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 28px; color: var(--text-3); font-size: 11.5px; }

/* ---------------- debt history disclosure ---------------- */
.debt-history { margin-top: 10px; }
.debt-history summary {
  display: inline-flex; align-items: center; min-height: 34px; padding: 0 11px;
  font-size: 12.5px; font-weight: 500; color: var(--brand-strong);
  background: var(--brand-soft); border: 1px solid transparent; border-radius: 8px;
  cursor: pointer; list-style: none;
}
.debt-history summary::-webkit-details-marker { display: none; }
.debt-history summary::before { content: '▸ '; }
.debt-history[open] summary::before { content: '▾ '; }
.history-body { padding: 12px 2px 4px; }
table.data.mini { margin-top: 6px; }
table.data.mini td, table.data.mini th { padding-top: 8px; padding-bottom: 8px; font-size: 13px; }
