:root {
  --bg: #f3f6f8;
  --card: #ffffff;
  --line: #dde5ea;
  --text: #0f1f28;
  --muted: #5d7280;
  --accent: #0e7c86;
  --accent-soft: #d8eef0;
  --on-accent: #ffffff;
  --income: #178a58;
  --income-soft: #dff3ea;
  --expense: #c5443a;
  --expense-soft: #fbe3e1;
  --warn: #b26a00;
  --warn-soft: #fff0d6;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e171c; --card: #172329; --line: #253640; --text: #e9f1f4; --muted: #92a7b2;
    --accent: #37b7c1; --accent-soft: #163a3f; --on-accent: #06181a;
    --income: #4bd291; --income-soft: #15332a; --expense: #ff8078; --expense-soft: #3d1f1d;
    --warn: #f0b457; --warn-soft: #3a2b12;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
code { font-size: 90%; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }
b { font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.warn { color: var(--warn); }

.screen { min-height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-top); }
.screen.center { align-items: center; justify-content: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.narrow { width: 100%; max-width: 420px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; font-weight: 700; }
.brand img { border-radius: 8px; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
.topbar h1 { flex: 1; font-size: 17px; min-width: 0; }
.topbar h1 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 12px; font-weight: 650; padding: 4px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }

.content { padding: 16px; display: flex; flex-direction: column; gap: 12px; flex: 1; padding-bottom: calc(96px + var(--safe-bottom)); max-width: 720px; width: 100%; margin: 0 auto; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 650; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.row > * { flex: 1; }

/* buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 9px 14px; font-size: 15px; font-weight: 600; min-height: 44px; cursor: pointer;
  touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled, .btn.busy { opacity: .6; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.big { min-height: 50px; font-size: 16px; }
.btn.small { min-height: 34px; font-size: 13px; padding: 5px 10px; border-radius: 9px; }
.btn.danger { color: var(--expense); }
.link { appearance: none; background: none; border: 0; color: var(--accent); font-size: 14px; padding: 8px; cursor: pointer; }
.fab {
  position: fixed; right: 18px; bottom: calc(76px + var(--safe-bottom)); width: 58px; height: 58px; border-radius: 50%;
  border: 0; background: var(--accent); color: var(--on-accent); font-size: 32px; line-height: 1; cursor: pointer;
  box-shadow: 0 8px 20px rgba(0,0,0,.25); z-index: 6;
}
.fab:active { transform: scale(.95); }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + var(--safe-bottom)); z-index: 5;
}
.tabbar button { flex: 1; appearance: none; background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; cursor: pointer; }
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar button.active { color: var(--accent); }

/* forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.form h2 { font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], input[type=number], select, textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; min-height: 46px; font-family: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 9px 6px; border-radius: 8px; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.seg input:checked + span { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg input:checked + span.income { color: var(--income); }
.seg input:checked + span.expense { color: var(--expense); }
.opt.toggle { display: flex; justify-content: space-between; align-items: center; min-height: 40px; font-size: 14px; }
.opt.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

/* home */
.monthbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.monthbar strong { font-size: 17px; }
.monthbar .btn { flex: none; width: 44px; padding: 0; font-size: 22px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 .stat:last-child { grid-column: 1 / -1; flex-direction: row; justify-content: space-between; align-items: baseline; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat span, .stat-btn span { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat b, .stat-btn b { font-size: clamp(15px, 4.6vw, 19px); font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat.income b { color: var(--income); }
.stat.expense b { color: var(--expense); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; }
.stat-btn { appearance: none; border: 0; background: var(--bg); border-radius: 10px; padding: 12px; text-align: left; display: flex; flex-direction: column; gap: 4px; color: var(--text); cursor: pointer; font-family: inherit; }
.stat-btn small { font-size: 12px; font-weight: 600; }
.bars { display: flex; gap: 8px; height: 120px; align-items: stretch; }
.bar-col { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.bar-pair { flex: 1; display: flex; gap: 2px; align-items: flex-end; }
.bar { flex: 1; border-radius: 3px 3px 0 0; min-height: 2px; display: block; }
.bar.income { background: var(--income); }
.bar.expense { background: var(--expense); }
.bar-col span { font-size: 11px; color: var(--muted); text-align: center; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 4px; }
.dot.income { background: var(--income); }
.dot.expense { background: var(--expense); }
.cats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cats li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 14px; align-items: center; }
.cats li i { grid-column: 1 / -1; height: 5px; background: var(--accent); border-radius: 3px; display: block; opacity: .8; }
.cats li b { font-variant-numeric: tabular-nums; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 10px; align-items: center; cursor: pointer; }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.item-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-main .muted { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; display: flex; flex-direction: column; gap: 2px; }
.amount small { font-weight: 500; color: var(--muted); font-size: 12px; }
.amount.income { color: var(--income); }
.amount.expense { color: var(--expense); }
.empty { color: var(--muted); text-align: center; padding: 24px 12px; }
.pill { align-self: flex-start; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.pill.overdue { background: var(--expense-soft); color: var(--expense); }
.pill.partial { background: var(--warn-soft); color: var(--warn); }
.pill.paid { background: var(--income-soft); color: var(--income); }
.pill.pending { background: var(--warn-soft); color: var(--warn); }
.pill.admin { background: var(--accent-soft); color: var(--accent); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-row .who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.user-row .who span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.user-row select { width: auto; min-height: 38px; padding: 6px 10px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.chip button { appearance: none; border: 0; background: none; color: var(--muted); font-size: 16px; line-height: 1; cursor: pointer; padding: 0 2px; }

/* bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel {
  position: relative; width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-bottom)); animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); } to { transform: none; } }

.toast { position: fixed; left: 50%; bottom: calc(88px + var(--safe-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 30; max-width: 90vw; text-align: center; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 720px) {
  .tabbar { max-width: 720px; left: 50%; transform: translateX(-50%); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

/* language + signature */
.lang-btn { font-size: 12px; font-weight: 700; letter-spacing: .04em; min-height: 32px; padding: 4px 10px; border-radius: 9px; flex: none; }
.signature { font-size: 13px; color: var(--muted); text-align: center; margin-top: 14px; font-style: italic; }
.screen.center .signature { max-width: 420px; }
.lang-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lang-row .seg { flex: 1; max-width: 220px; }

/* family mark */
.copyright { font-size: 12px; color: var(--muted); text-align: center; margin-top: 4px; letter-spacing: .02em; }
