:root {
  color-scheme: light;
  --bg: #FFFFFF;
  --surface: #F6F6F8;
  --surface-2: #ECEDF1;
  --text: #111214;
  --muted: #6E7178;
  --line: #E6E7EB;
  --neg: #D0342C;
  --pos: #1D8F5A;
  --neg-soft: rgba(208, 52, 44, .10);
  --pos-soft: rgba(29, 143, 90, .10);
  --btn-bg: #111214;
  --btn-fg: #FFFFFF;
  --focus: #2F6FED;
  --shadow: 0 1px 2px rgba(17, 18, 20, .06), 0 12px 32px -16px rgba(17, 18, 20, .22);
  --backdrop: rgba(17, 18, 20, .40);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  padding-inline: 20px;
  padding-block: 18px 110px;
  min-height: 100vh;
  min-height: 100dvh;
  font-variant-numeric: tabular-nums;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { max-width: 880px; margin: 0 auto; display: grid; gap: 22px; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -.01em; font-size: 17px; }
.mark { width: 22px; height: 22px; display: inline-grid; grid-template-columns: 1fr 1fr; gap: 3px; align-items: end; }
.mark i { display: block; border-radius: 2px; }
.mark i:first-child { background: var(--neg); height: 12px; }
.mark i:last-child { background: var(--pos); height: 22px; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn, .ghost {
  background: transparent; border: 1px solid transparent; border-radius: 999px;
  color: var(--muted); padding: 9px 12px; min-height: 40px; display: inline-flex; align-items: center; gap: 6px;
}
.icon-btn:hover, .ghost:hover { background: var(--surface); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- net hero ---------- */
.net { text-align: center; display: grid; gap: 6px; justify-items: center; padding-block: 14px 6px; }
.net-value {
  font-size: clamp(52px, 11vw, 88px); font-weight: 600; letter-spacing: -.045em; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.net-sub { color: var(--muted); font-size: 13px; }
.net-row { display: grid; gap: 18px; justify-items: center; margin-top: 18px; }
.net-item { display: grid; gap: 6px; justify-items: center; min-width: 0; }
.net-item .eyebrow { text-align: center; letter-spacing: .06em; text-wrap: balance; }
.net-mid {
  font-size: clamp(26px, 4.4vw, 34px); font-weight: 600; letter-spacing: -.035em; line-height: 1;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.eyebrow { text-transform: uppercase; letter-spacing: .09em; font-size: 11px; font-weight: 600; color: var(--muted); }

/* ---------- columns ---------- */
.cols {
  display: grid; gap: 14px; align-items: stretch;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "dep rev" "list .";
}
.tile {
  background: var(--surface); border-radius: 20px;
  padding: 18px 20px 20px;
  display: grid; gap: 12px; grid-template-rows: auto auto 1fr;
  position: relative; overflow: hidden;
}
.tile > :last-child { align-self: end; }
.tile.dep { grid-area: dep; }
.tile.rev { grid-area: rev; }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tile-head .eyebrow { display: inline-flex; align-items: center; gap: 7px; }
.tile-head .eyebrow::before { content: ""; width: 8px; height: 8px; border-radius: 50%; }
.tile.dep .eyebrow::before { background: var(--neg); }
.tile.rev .eyebrow::before { background: var(--pos); }
.chip {
  font-size: 11px; font-weight: 600; letter-spacing: .02em; padding: 4px 9px; border-radius: 999px;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.big {
  font-size: clamp(36px, 5vw, 48px); font-weight: 600; letter-spacing: -.035em; line-height: 1;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.meta { color: var(--muted); font-size: 13px; }
.meta.error { color: var(--neg); }

/* ---------- expense list ---------- */
.list { grid-area: list; background: var(--surface); border-radius: 20px; padding: 6px 8px; }
.list ul { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; min-height: 48px; border-radius: 12px;
}
.list li + li { border-top: 1px solid var(--line); border-radius: 0; }
.list li:hover { background: var(--surface-2); }
.list li.removing { opacity: .4; pointer-events: none; }
.list time { color: var(--muted); font-size: 12px; min-width: 54px; }
.list .label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56%; }
.list .label.empty { color: var(--muted); font-weight: 400; }
.leader { flex: 1; border-bottom: 2px dotted var(--line); height: .62em; min-width: 12px; align-self: baseline; margin-top: .55em; }
.amt { font-weight: 600; color: var(--neg); white-space: nowrap; }
.del {
  background: transparent; border: 0; color: var(--muted); border-radius: 8px;
  width: 34px; height: 34px; line-height: 1; font-size: 20px; display: inline-grid; place-items: center;
  margin-right: -8px;
}
.del:hover { background: var(--neg-soft); color: var(--neg); }
@media (hover: hover) {
  .list .del { opacity: 0; }
  .list li:hover .del, .list .del:focus-visible { opacity: 1; }
}
.empty { margin: 0; padding: 18px 12px; color: var(--muted); font-size: 14px; text-align: center; }

/* ---------- primary buttons ---------- */
.add {
  background: var(--btn-bg); color: var(--btn-fg); border: 0; border-radius: 999px;
  padding: 11px 18px 11px 12px; min-height: 44px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 9px; box-shadow: var(--shadow);
}
.add:hover { background: #2A2C31; }
.add .plus {
  width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--neg); color: #fff; font-size: 17px; line-height: 1;
}
.add-desktop { justify-self: end; margin-top: 4px; }
.add-mobile { display: none; }
.primary {
  background: var(--btn-bg); color: var(--btn-fg); border: 0; border-radius: 999px;
  padding: 11px 20px; min-height: 44px; font-weight: 600;
}
.primary:hover { background: #2A2C31; }

/* ---------- inputs ---------- */
.text-input {
  border: 1px solid transparent; border-radius: 14px; padding: 13px 16px; background: var(--surface);
  outline: 0; width: 100%; min-height: 48px; font-size: 16px;
}
.text-input:focus { border-color: var(--focus); background: var(--bg); }
.text-input::placeholder { color: var(--muted); opacity: .6; }
.form-error { margin: 0; color: var(--neg); font-size: 13px; min-height: 1.2em; }
.form-error:empty { display: none; }

/* ---------- login ---------- */
.login { min-height: calc(100dvh - 128px); display: grid; place-items: center; }
.login-form { width: min(320px, 100%); }
.login-input {
  width: 100%; min-height: 52px; padding: 14px 18px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface); outline: 0;
  font-size: 18px; letter-spacing: .12em; text-align: center;
}
.login-input:focus { border-color: var(--focus); background: var(--bg); }
.login-input.error { border-color: var(--neg); background: var(--neg-soft); }
.login-input.shake { animation: shake .35s ease; }
@keyframes shake {
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}

/* ---------- modal ---------- */
dialog {
  border: 0; border-radius: 22px; padding: 0; background: var(--bg); color: var(--text);
  width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow); margin: auto;
  max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain;
}
body.modal-open { overflow: hidden; }
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(4px); }
dialog form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 22px 22px 20px; }
dialog h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-width: 0; }
.field label { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.field label em { font-style: normal; font-weight: 500; letter-spacing: 0; text-transform: none; opacity: .8; }
.amount-wrap {
  display: flex; align-items: baseline; gap: 8px; border: 1px solid transparent; border-radius: 16px;
  padding: 12px 18px; background: var(--surface); min-width: 0;
}
.amount-wrap:focus-within { border-color: var(--focus); background: var(--bg); }
.amount-wrap input {
  flex: 1; width: 100%; min-width: 0; border: 0; background: transparent; outline: 0;
  font-size: 44px; font-weight: 600; letter-spacing: -.04em; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.amount-wrap input::placeholder { color: var(--muted); opacity: .45; }
.amount-wrap .unit { font-size: 26px; font-weight: 500; color: var(--muted); }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.actions .ghost { padding: 11px 16px; min-height: 44px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--btn-bg); color: var(--btn-fg); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow); z-index: 20; max-width: calc(100vw - 32px);
}

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  body { padding-inline: 16px; padding-block: 12px 100px; }
  .app { gap: 16px; }
  .net { padding-block: 10px 2px; }
  .net-row { gap: 14px; margin-top: 14px; }
  .net-mid { font-size: clamp(24px, 7vw, 30px); }
  .cols { grid-template-areas: "dep rev" "list list"; gap: 10px; }
  .tile { padding: 14px 14px 16px; border-radius: 18px; gap: 10px; }
  .tile-head .chip { display: none; }
  .big { font-size: clamp(24px, 7.6vw, 34px); }
  .meta { font-size: 12px; }
  .list { border-radius: 18px; }
  .list time { min-width: 48px; }
  .list .label { max-width: 50%; }
  .add-desktop { display: none; }
  .add-mobile {
    display: inline-flex; position: fixed; left: 16px; right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    justify-content: center; padding: 15px 18px; font-size: 16px; z-index: 5;
  }
  .toast { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 64px); }
  dialog {
    position: fixed; margin: 0; inset: 10px 10px auto 10px; width: auto; max-width: none;
    max-height: calc(100dvh - 20px); border-radius: 20px;
  }
  dialog form { padding: 16px 16px 14px; gap: 12px; }
  dialog h2 { font-size: 17px; }
  .field { gap: 5px; }
  .amount-wrap { padding: 8px 16px; border-radius: 14px; }
  .amount-wrap input { font-size: 34px; }
  .amount-wrap .unit { font-size: 22px; }
  .text-input { min-height: 46px; padding: 11px 14px; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; margin-top: 0; }
  .actions .ghost { background: var(--surface); justify-content: center; }
  .login { min-height: calc(100dvh - 112px); }
}

@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: pop .18s ease-out; }
  @keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } }
  @media (max-width: 640px) {
    @keyframes pop { from { transform: translateY(-10px); opacity: 0; } }
  }
}
@media (prefers-reduced-motion: reduce) {
  .icon-btn.spinning svg { animation: none; }
  .login-input.shake { animation: none; }
}
