:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
  --primary: #38bdf8;
  --primary-ink: #0b2233;
  --pos: #34d399;
  --neg: #f87171;
  --danger: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

.container { max-width: 640px; margin: 0 auto; padding: 16px; padding-bottom: 48px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: max(12px, env(safe-area-inset-top));
}
.topbar-title { font-weight: 700; font-size: 1.15rem; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions form { margin: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-size: 0.95rem; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-small { padding: 6px 10px; font-size: 0.85rem; }
.btn-danger { color: var(--neg); border-color: var(--neg); background: transparent; }

/* sections */
.section-title { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 22px 0 10px; }

/* balances */
.balance-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-left-width: 4px; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px;
}
.balance-cur { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 48px; }
.balance-row.pos { border-left-color: var(--pos); }
.balance-row.neg { border-left-color: var(--neg); }
.balance-row.zero { border-left-color: var(--border); }
.pos .balance-text, .tx-running.pos span:last-child { color: var(--pos); }
.neg .balance-text, .tx-running.neg span:last-child { color: var(--neg); }

/* register */
.tx-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.tx-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.tx-name { font-weight: 700; }
.tx-meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.tx-actions { display: flex; gap: 6px; }
.tx-actions form { margin: 0; }
.tx-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.tx-col { display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem;
  font-variant-numeric: tabular-nums; background: var(--surface-2);
  border-radius: 8px; padding: 8px; }
.tx-col .who { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.tx-running span:last-child { font-weight: 700; }
.tx-desc { margin-top: 10px; color: var(--muted); font-size: 0.88rem; }

/* forms */
label { display: block; margin: 14px 0; font-weight: 600; font-size: 0.95rem; }
input, select, textarea {
  width: 100%; margin-top: 6px; padding: 11px 12px; font-size: 1rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
textarea { resize: vertical; }

.card { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; }

.form-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg); padding: 10px 0; margin-bottom: 4px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.form-title { font-weight: 700; }

.side-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin: 18px 0; background: var(--surface);
}
.side-card legend { font-weight: 700; padding: 0 6px; font-size: 0.9rem;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.cur-readonly { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }

/* segmented control */
.seg { display: flex; gap: 0; margin: 12px 0; border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; }
.seg-btn { flex: 1; margin: 0; }
.seg-btn input { position: absolute; opacity: 0; pointer-events: none; }
.seg-btn span {
  display: block; text-align: center; padding: 9px 4px; font-size: 0.9rem;
  background: var(--surface); cursor: pointer; border-right: 1px solid var(--border);
}
.seg-btn:last-child span { border-right: none; }
.seg-btn input:checked + span { background: var(--primary); color: var(--primary-ink); font-weight: 700; }

.split-row { display: grid; grid-template-columns: 90px 1fr auto; align-items: center;
  gap: 10px; margin: 8px 0; }
.split-name { font-weight: 600; font-size: 0.9rem; }
.split-in { margin: 0; }
.derived { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; min-width: 56px; }

.reconcile { margin-top: 10px; font-size: 0.9rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.reconcile.ok { color: var(--pos); }
.reconcile.ok::before { content: "OK "; }
.reconcile.bad { color: var(--neg); }

/* banners + errors */
.banner { border-radius: 10px; padding: 12px 14px; margin: 12px 0; font-size: 0.92rem; }
.banner-error { background: rgba(239,68,68,0.12); border: 1px solid var(--neg); color: #fecaca; }
.banner-error ul { margin: 6px 0 0; padding-left: 18px; }
.field-error { display: block; color: var(--neg); font-size: 0.83rem; margin-top: 5px; font-weight: 600; }

/* login */
.login-wrap { max-width: 360px; margin: 12vh auto 0; }
.brand { text-align: center; font-size: 2rem; margin-bottom: 18px; }
.cur-label, .cur-other { display: inline-block; width: auto; min-width: 140px; }
