@font-face { font-family: Inter; font-weight: 400; font-display: swap; src: url(/fonts/inter-400.woff2) format('woff2'); }
@font-face { font-family: Inter; font-weight: 500; font-display: swap; src: url(/fonts/inter-500.woff2) format('woff2'); }
@font-face { font-family: Inter; font-weight: 600; font-display: swap; src: url(/fonts/inter-600.woff2) format('woff2'); }
@font-face { font-family: Inter; font-weight: 700; font-display: swap; src: url(/fonts/inter-700.woff2) format('woff2'); }

:root {
  --bg: #0F1115;
  --card: #181B22;
  --card2: #1D2129;
  --line: #262A33;
  --nav: #13161B;
  --ink: #E8EAF0;
  --quiet: #9AA3B2;
  --teal: #3DD6B5;
  --teal-soft: #1A2A27;
  --blue: #8DB2F5;
  --blue-bar: #5B8DEF;
  --amber: #F3B983;
  --amber-bar: #F0A35E;
  --grey-bar: #6B7280;
  --red: #FF6B6B;
  --red-ink: #FFB3B3;
  --red-bg: #2A1618;
  --red-line: #5A2A2E;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--teal); }
svg { flex: none; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.view {
  padding: calc(16px + var(--safe-t)) 0 calc(96px + var(--safe-b));
  max-width: 560px;
  margin: 0 auto;
  outline: none;
}
.side { display: none; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 8px 8px calc(10px + var(--safe-b));
  background: rgba(19, 22, 27, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 0; min-height: 48px;
  font-size: 11px; color: var(--quiet); text-decoration: none;
}
.tabbar a.on { color: var(--teal); }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); }
  .tabbar { display: none; }
  .side {
    display: flex; flex-direction: column; gap: 2px;
    position: sticky; top: 0; height: 100vh;
    padding: 24px 16px; background: var(--nav); border-right: 1px solid var(--line);
    overflow-y: auto;
  }
  .side .brand { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; padding: 0 12px 20px; }
  .side .brand span { width: 30px; height: 30px; border-radius: 9px; background: var(--teal); color: var(--bg); display: flex; align-items: center; justify-content: center; }
  .side a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; color: var(--quiet); text-decoration: none; font-size: 14px; }
  .side a:hover { background: var(--card); color: var(--ink); }
  .side a.on { background: var(--teal-soft); color: var(--teal); font-weight: 600; }
  .side .label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--quiet); padding: 18px 12px 6px; }
  .view { max-width: 1080px; padding: 32px 40px 48px; margin: 0; }
  .cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 24px; align-items: start; }
}

/* ---------- headers ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 20px 12px; }
.top h1 { margin: 0; font-size: 22px; font-weight: 700; }
.top .center { text-align: center; flex: 1; min-width: 0; }
.top .center h1 { font-size: 18px; font-weight: 600; }
.sub { font-size: 13px; color: var(--quiet); }
.spacer44 { width: 44px; flex: none; }
.ibtn {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.ibtn.acc { background: var(--teal); border-color: var(--teal); color: var(--bg); }
.ibtn:hover { filter: brightness(1.1); }

/* ---------- cards & lists ---------- */
.card { margin: 8px 20px 0; padding: 18px; border-radius: 20px; background: var(--card); border: 1px solid var(--line); }
.card.danger { border-color: var(--red-line); }
.lbl { font-size: 12px; color: var(--quiet); }
.big { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; color: var(--teal); line-height: 1.1; }
.big.neg { color: var(--red); }
.mid { font-size: 30px; font-weight: 700; letter-spacing: -0.01em; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.v { font-size: 15px; font-weight: 600; margin-top: 3px; }
.formula { font-size: 12px; color: var(--quiet); line-height: 1.5; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }

.sec { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 24px 20px 8px; }
.sec h2 { margin: 0; font-size: 15px; font-weight: 600; }

.list { margin: 0 20px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); overflow: hidden; }
.row {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent;
  text-align: left; min-height: 56px;
}
.row:last-child { border-bottom: 0; }
button.row:hover { background: var(--card2); }
.row .t { font-size: 15px; overflow-wrap: anywhere; }
.row .m { font-size: 12px; color: var(--quiet); margin-top: 2px; overflow-wrap: anywhere; }
.row .amt { font-size: 15px; font-weight: 600; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.row .grow { flex: 1; min-width: 0; }
.row.ended .grow, .row.ended .amt { opacity: 0.45; }
.rowbtn { background: none; border: 0; padding: 0; text-align: left; color: inherit; }
.chev { color: var(--quiet); display: inline-flex; }

.chip { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #1F2A2A; color: var(--teal); margin-left: 6px; vertical-align: 1px; white-space: nowrap; }
.chip.o { background: #252831; color: var(--quiet); }
.chip.red { background: var(--red-bg); color: var(--red-ink); }

.del { flex: none; font-size: 13px; color: var(--red); border: 1px solid var(--red-line); background: transparent; border-radius: 10px; padding: 0 12px; height: 36px; }
.del:hover { background: var(--red-bg); }

.bar { height: 8px; border-radius: 4px; background: var(--line); display: flex; overflow: hidden; }
.bar > div { height: 100%; }
.dot { width: 10px; height: 10px; border-radius: 5px; flex: none; }

.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.av { width: 40px; height: 40px; border-radius: 20px; background: var(--teal-soft); color: var(--teal); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.pcard { display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); text-decoration: none; color: inherit; }
.pcard:hover { background: var(--card2); }
.pcard.neg { border-color: var(--red-line); }
.pgrid { display: flex; flex-direction: column; gap: 10px; margin: 0 20px; }
@media (min-width: 900px) { .pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); } }

.chips { display: flex; gap: 8px; padding: 4px 20px 12px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.pill { flex: none; padding: 0 14px; height: 36px; border-radius: 18px; font-size: 13px; background: var(--card); color: var(--quiet); border: 1px solid var(--line); display: inline-flex; align-items: center; text-decoration: none; }
.pill.on { background: var(--teal); color: var(--bg); border-color: var(--teal); font-weight: 600; }

.addrow { margin: 16px 20px 0; padding: 0 16px; min-height: 52px; width: calc(100% - 40px); border-radius: 14px; border: 1px dashed var(--line); background: transparent; display: flex; align-items: center; gap: 10px; color: var(--teal); font-size: 15px; font-weight: 600; }
.addrow:hover { background: var(--card); }

.banner { margin: 8px 20px 0; padding: 14px; border-radius: 14px; background: var(--red-bg); border: 1px solid var(--red-line); display: flex; gap: 10px; font-size: 14px; line-height: 1.45; color: #E8C4C4; }
.banner strong { color: var(--red-ink); display: block; }
.banner svg { color: var(--red); margin-top: 1px; }

.empty { margin: 8px 20px 0; padding: 28px 20px; border-radius: 16px; border: 1px dashed var(--line); text-align: center; color: var(--quiet); line-height: 1.5; }
.empty .btn { margin-top: 14px; }
.loading { padding: 80px 20px; text-align: center; color: var(--quiet); }

/* ---------- buttons & forms ---------- */
.btn { height: 50px; padding: 0 20px; border-radius: 14px; border: 0; font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--teal); color: var(--bg); }
.btn.primary:disabled { background: #2B3038; color: #6B7280; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--quiet); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--red-line); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .field > .lab { font-size: 13px; color: var(--quiet); }
.in {
  width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  padding: 0 14px; font-size: 16px; color: var(--ink); outline: none; -webkit-appearance: none; appearance: none;
}
textarea.in { height: 84px; padding: 12px 14px; resize: vertical; }
select.in { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%239AA3B2' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px; }
input[type=date].in { padding-right: 10px; color-scheme: dark; }
.in:focus { border-color: var(--teal); }
.in.bad { border-color: var(--red); }
.money { position: relative; }
.money span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--quiet); font-size: 16px; }
.money .in { padding-left: 30px; }
.seg { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { height: 44px; border-radius: 10px; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--quiet); }
.seg input:checked + span { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 2px; }
.hint { font-size: 12px; color: var(--quiet); }
.datewrap { display: flex; gap: 8px; }
.datewrap .in { flex: 1; }
.datewrap button { flex: none; height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--quiet); }

/* ---------- sheet (pop-up form) ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.6); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease-out; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0;
  padding: 8px 20px calc(20px + var(--safe-b));
  animation: up .2s ease-out;
}
.sheet .top { padding: 8px 0 14px; }
.sheet .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.sheet .list { margin: 0 0 14px; }
@media (min-width: 900px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 22px; border-bottom: 1px solid var(--line); padding-bottom: 20px; }
  .sheet .actions { flex-direction: row-reverse; }
  .sheet .actions .btn { flex: 1; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 60; max-width: calc(100% - 40px); pointer-events: none; }
#toast div { padding: 12px 16px; border-radius: 12px; background: #2B3038; color: var(--ink); font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: up .2s ease-out; }
#toast div.err { background: var(--red-bg); border: 1px solid var(--red-line); color: var(--red-ink); }
@media (min-width: 900px) { #toast { bottom: 32px; } }

/* ---------- desktop tables ---------- */
.tablewrap { margin: 0 20px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 16px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: 12px; color: var(--quiet); font-weight: 500; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.desk-only { display: none; }
@media (min-width: 900px) { .desk-only { display: block; } .phone-only { display: none; } }
