:root {
  --bg: #f4f6f5; --card: #ffffff; --text: #14201b; --muted: #6b7a73; --line: #e2e7e4;
  --accent: #107854; --accent-2: #16a36e; --danger: #d33f49; --ok: #1f9d5b; --chip: #e6efea;
  --sheet: #ffffff; --shadow: 0 8px 30px rgba(0,0,0,.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --card: #182019; --text: #e9efec; --muted: #8b998f; --line: #26312a;
    --accent: #2fbf86; --accent-2: #3ad39a; --danger: #ff6b6b; --ok: #3ad39a; --chip: #223028;
    --sheet: #182019; --shadow: 0 8px 30px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; overscroll-behavior-y: none; }
body { padding-top: env(safe-area-inset-top); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
#view { padding: 12px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.tabs button { flex: 1; background: none; border: 0; padding: 8px 0 6px; color: var(--muted); font-size: 10px; white-space: nowrap; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button .ico { font-size: 19px; line-height: 1; }
.tabs button { padding-left: 2px; padding-right: 2px; overflow: hidden; }
.tabs button.active { color: var(--accent); }
#fab { position: fixed; right: 20px; bottom: calc(72px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 30px; line-height: 1; box-shadow: var(--shadow); z-index: 21; }

.hero { padding: 16px 0 8px; }
.hero .label { color: var(--muted); font-size: 13px; }
.hero .total { font-size: 36px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 0; background: var(--chip); color: var(--text); padding: 6px 12px; border-radius: 999px; font-size: 13px; }
.chip.active { background: var(--accent); color: #fff; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; margin: 12px 0; }
.card h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; display: flex; justify-content: space-between; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row.click { cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { text-align: right; font-variant-numeric: tabular-nums; }
.row .amt .eq { color: var(--muted); font-size: 12px; }
.pos { color: var(--ok); } .neg { color: var(--danger); }
.bar { height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent-2); }
.badge { display: inline-block; width: 38px; height: 38px; border-radius: 12px; background: var(--chip); color: var(--accent); font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.empty b { display: block; color: var(--text); margin-bottom: 6px; font-size: 18px; }

.btn { display: block; width: 100%; padding: 13px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; font-weight: 600; margin-top: 8px; }
.btn.sec { background: var(--chip); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); }
.btn:disabled { opacity: .5; }
.btnrow { display: flex; gap: 8px; } .btnrow .btn { margin-top: 8px; }
label.f { display: block; margin: 12px 0 0; font-size: 13px; color: var(--muted); }
label.f input, label.f select, label.f textarea { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 17px; }
label.f input:focus, label.f select:focus { outline: 2px solid var(--accent); border-color: transparent; }
.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; margin-top: 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }

#sheet-root .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; animation: fade .15s; }
#sheet-root .sheet { position: fixed; left: 0; right: 0; bottom: 0; background: var(--sheet); border-radius: 20px 20px 0 0; padding: 12px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; z-index: 31; max-width: 640px; margin: 0 auto; animation: up .2s; }
#sheet-root .sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
.sheet h2 { margin: 6px 0 4px; font-size: 20px; }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; background: none; border: 0; border-top: 1px solid var(--line); padding: 14px 4px; text-align: left; font-size: 17px; }
.menu button:first-child { border-top: 0; }
.menu button .ico { width: 30px; text-align: center; font-size: 20px; color: var(--accent); }
.menu button.danger { color: var(--danger); } .menu button.danger .ico { color: var(--danger); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#auth { position: fixed; inset: 0; background: var(--bg); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 24px; }
#auth .box { width: 100%; max-width: 360px; }
#auth img { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 12px; }
#auth h1 { text-align: center; margin: 0 0 4px; font-size: 22px; }
#auth p { text-align: center; color: var(--muted); margin: 0 0 8px; font-size: 14px; }
.err { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 18px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.show { opacity: 1; pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent-2); font-weight: 600; margin-left: 10px; }

.chart { width: 100%; height: 160px; display: block; margin-top: 8px; }
.chart .line { fill: none; stroke: var(--accent-2); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: var(--accent-2); opacity: .12; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.stat { display: flex; justify-content: space-between; align-items: baseline; }
.stat .big { font-size: 22px; font-weight: 700; }
.day { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; margin: 16px 0 4px; letter-spacing: .4px; }
.sync { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: 12px; font-size: 11px; color: var(--muted); background: var(--card); border: 1px solid var(--line); padding: 3px 8px; border-radius: 999px; z-index: 22; }
.sync.off { color: var(--danger); }
.small { font-size: 13px; color: var(--muted); }
.rate-row input { width: 110px; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); font-size: 15px; }
.kv:first-of-type { border-top: 0; }

.kvs { margin-top: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 2px 12px; }
.kvs .kv { font-size: 14px; } .kvs .kv b { font-weight: 600; font-variant-numeric: tabular-nums; }
.hero .total.neg { color: var(--danger); }
.bar i.warn { background: var(--danger); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.grid2 label.f { margin-top: 12px; }
.f-out { padding: 11px 0 12px; font-weight: 600; font-size: 15px; }
.chk { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; color: var(--muted); }
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.row.paused { opacity: .5; }
.chart .grid.zero { stroke: var(--danger); stroke-dasharray: 4 4; }
.badge.cal { flex-direction: column; line-height: 1; gap: 2px; }
.badge.cal b { font-size: 15px; } .badge.cal i { font-style: normal; font-size: 9px; color: var(--muted); text-transform: uppercase; }
.chart.tall { height: 190px; }
.chart .marker { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 3; opacity: .7; }
.chart .dot { fill: var(--accent-2); stroke: var(--card); stroke-width: 2; }
.chart .bar-inc, .legend .bar-inc { fill: var(--accent-2); background: var(--accent-2); }
.chart .bar-exp, .legend .bar-exp { fill: var(--danger); background: var(--danger); opacity: .85; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
input[type=range] { width: 100%; margin: 6px 0 0; accent-color: var(--accent); }
#scrub-svg { touch-action: none; cursor: crosshair; }
