:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --surface2: #edf2ef;
  --text: #13201a;
  --muted: #5b6b64;
  --line: #dce4df;
  --brand: #0b7a4b;
  --brand-ink: #ffffff;
  --brand-soft: #e1f2e8;
  --inc: #0b7a4b;
  --exp: #c22f2f;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --danger-soft: #fde7e7;
  --info: #1a5fb4;
  --info-soft: #e3edfb;
  --shadow: 0 1px 2px rgba(16, 40, 28, .05), 0 6px 18px rgba(16, 40, 28, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1311; --surface: #151d1a; --surface2: #1c2622; --text: #e4ede9; --muted: #92a39b;
    --line: #283430; --brand: #35c482; --brand-ink: #04170e; --brand-soft: #12301f;
    --inc: #4cd290; --exp: #ff7d73; --warn: #f2b655; --warn-soft: #3a2b10; --danger-soft: #3a1b1b;
    --info: #8ab4f8; --info-soft: #172a45; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1311; --surface: #151d1a; --surface2: #1c2622; --text: #e4ede9; --muted: #92a39b;
  --line: #283430; --brand: #35c482; --brand-ink: #04170e; --brand-soft: #12301f;
  --inc: #4cd290; --exp: #ff7d73; --warn: #f2b655; --warn-soft: #3a2b10; --danger-soft: #3a1b1b;
  --info: #8ab4f8; --info-soft: #172a45; --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 16px; height: 16px; }
.tnum { font-variant-numeric: tabular-nums; }

.app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px; background: var(--bg);
}
.top h1 { font-size: 20px; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top #backBtn:not([hidden]) + h1 { margin-left: -4px; }
.hdr-act { display: flex; gap: 4px; }
main { padding: 4px 16px calc(120px + env(safe-area-inset-bottom)); outline: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  border: 0; background: transparent; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--surface2); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 112px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; font-size: 11px; color: var(--muted); font-weight: 600;
}
.tabs a.on { color: var(--brand); }
.fab {
  position: fixed; z-index: 31; right: max(16px, calc(50% - 264px)); bottom: calc(76px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 18px rgba(11, 122, 75, .35);
}
.fab .ic { width: 26px; height: 26px; }
.fab[hidden] { display: none; }

/* cards & rows */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.flush { padding: 4px 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-h h2 { font-size: 15px; font-weight: 700; }
.card.flush .card-h { padding: 12px 16px 0; }
.link { color: var(--brand); font-weight: 600; font-size: 13px; background: none; border: 0; cursor: pointer; padding: 4px; }
.section-t { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 18px 4px 8px; }

.hero { background: var(--brand); color: var(--brand-ink); }
.hero .lbl { opacity: .85; font-size: 13px; }
.hero .big { font-size: 30px; font-weight: 800; margin: 2px 0 12px; }
.hero .split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero .split div { background: rgba(255,255,255,.14); border-radius: 12px; padding: 10px 12px; }
:root[data-theme="dark"] .hero .split div { background: rgba(0,0,0,.12); }
.hero .split b { display: block; font-size: 17px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat b { font-size: 16px; overflow-wrap: anywhere; }
.stat.good b { color: var(--inc); } .stat.bad b { color: var(--exp); } .stat.warn b { color: var(--warn); }

.row { display: flex; align-items: center; gap: 12px; padding: 11px 16px; min-height: 56px; cursor: pointer; width: 100%; border: 0; background: none; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.row:hover { background: var(--surface2); }
.row .grow { flex: 1; min-width: 0; }
.t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t2 { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 34px; height: 34px; border-radius: 11px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; }
.amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.amt.income { color: var(--inc); } .amt.expense { color: var(--exp); }
.right { text-align: right; }
.date-h { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 700; color: var(--muted); padding: 14px 6px 6px; }

.bar { height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--brand); }
.bar.over i { background: var(--exp); } .bar.near i { background: var(--warn); }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.chip.paid { background: var(--brand-soft); color: var(--inc); }
.chip.missed, .chip.overdue { background: var(--danger-soft); color: var(--exp); }
.chip.due { background: var(--warn-soft); color: var(--warn); }
.chip.upcoming { background: var(--surface2); color: var(--muted); }
.chip.payout { background: var(--info-soft); color: var(--info); }

.monthbar { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border-radius: 14px; padding: 4px; margin-bottom: 14px; box-shadow: var(--shadow); }
.monthbar .mlabel { border: 0; background: none; font-weight: 700; cursor: pointer; padding: 8px 16px; border-radius: 10px; }

.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }
.note { font-size: 13px; color: var(--muted); padding: 0 4px; }
.alert { display: flex; gap: 10px; align-items: center; background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; font-weight: 600; margin-bottom: 14px; }
.alert a { text-decoration: underline; }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .search input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus, .search input:focus, .amount-field:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12px; color: var(--muted); }
.amount-field { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 6px 16px; }
.amount-field span { font-weight: 700; color: var(--muted); font-size: 20px; }
.amount-field input { border: 0; outline: none; background: none; font-size: 32px; font-weight: 800; width: 100%; min-width: 0; padding: 6px 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; padding: 9px 6px; border-radius: 9px; font-weight: 700; cursor: pointer; color: var(--muted); font-size: 14px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg button.on[data-kind="expense"] { color: var(--exp); } .seg button.on[data-kind="income"] { color: var(--inc); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.btn { flex: 1; min-height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--exp); border-color: color-mix(in srgb, var(--exp) 40%, var(--line)); background: var(--surface); }
.btn.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.btn.sm { min-height: 36px; flex: none; font-size: 13px; padding: 0 12px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.sw input { position: absolute; opacity: 0; pointer-events: none; }
.sw i { display: block; width: 32px; height: 32px; border-radius: 10px; cursor: pointer; border: 3px solid transparent; }
.sw input:checked + i { border-color: var(--text); }
.sw input:focus-visible + i { outline: 2px solid var(--brand); outline-offset: 2px; }
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }
.search { position: relative; }
.search .ic { position: absolute; left: 12px; top: 12px; color: var(--muted); }
.search input { padding-left: 42px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }
.toggle input { width: 22px; height: 22px; accent-color: var(--brand); }

/* attachments */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface2); border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.thumb .pdf { display: grid; place-items: center; height: 100%; font-weight: 800; color: var(--exp); cursor: pointer; }
.thumb .rm { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 99px; border: 0; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; cursor: pointer; }
.thumb .rm .ic { width: 14px; height: 14px; }
.add-file { display: grid; place-items: center; align-content: center; gap: 4px; cursor: pointer; color: var(--brand); font-size: 12px; font-weight: 700; border: 2px dashed var(--line); background: none; }
.add-file input { display: none; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.sheet-panel {
  position: relative; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--bg);
  border-radius: 22px 22px 0 0; padding: 6px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 0 12px; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.sheet-head h2 { font-size: 17px; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: grid; place-items: center; }
.viewer[hidden] { display: none; }
.viewer img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.viewer .icon-btn { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; color: #fff; background: rgba(255,255,255,.15); }

.lock { position: fixed; inset: 0; z-index: 70; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.lock[hidden] { display: none; }
.lock-box { width: 100%; max-width: 320px; text-align: center; display: flex; flex-direction: column; gap: 14px; }
.lock-box .logo { width: 72px; height: 72px; margin: 0 auto; }
.lock-box input { text-align: center; font-size: 24px; letter-spacing: .4em; }

.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 80;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* more grid */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px; min-height: 112px; }
.tile .ic { color: var(--brand); width: 28px; height: 28px; }
.tile b { display: block; } .tile small { color: var(--muted); font-size: 12.5px; }

/* chart */
.chart svg { width: 100%; height: auto; display: block; }
.chart .ax { fill: var(--muted); font-size: 10px; }
.chart .gl { stroke: var(--line); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 8px 6px; text-align: right; border-top: 1px solid var(--line); }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; border-top: 0; }

.sched-row .num { width: 34px; height: 34px; border-radius: 11px; background: var(--surface2); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.sched-row.mine .num { background: var(--info-soft); color: var(--info); }

/* sync status */
#syncBtn { color: var(--muted); }
#syncBtn.sync-ok { color: var(--inc); }
#syncBtn.sync-pending, #syncBtn.sync-offline { color: var(--warn); }
#syncBtn.sync-error { color: var(--exp); }
#syncBtn.sync-syncing .ic { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* kameti day calendar */
details.cal-m summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; cursor: pointer; list-style: none; }
details.cal-m summary::-webkit-details-marker { display: none; }
details.cal-m summary::after { content: '▾'; color: var(--muted); margin-left: 4px; }
details.cal-m[open] summary::after { content: '▴'; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 12px; }
.cal .wd { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); }
.cd { aspect-ratio: 1; min-height: 36px; padding: 0; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; cursor: pointer; }
.cd.paid { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.cd.missed { background: var(--exp); border-color: var(--exp); color: var(--surface); }
.cd.overdue { background: var(--danger-soft); border-color: transparent; color: var(--exp); }
.cd.due { border: 2px solid var(--warn); color: var(--warn); }
.cd.upcoming { color: var(--muted); }
.cd.today { outline: 2px solid var(--text); outline-offset: 1px; }
.cd.mine { box-shadow: inset 0 -4px 0 var(--info); }
.cd { position: relative; }
.cd.draw::after { content: ''; position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 99px; background: var(--info); border: 1.5px solid var(--surface); }

@media (min-width: 600px) {
  main { padding-left: 20px; padding-right: 20px; }
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 22px; max-height: 86vh; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
