:root {
  --bg: #f4f7f6;
  --card: #ffffff;
  --card2: #eef3f2;
  --text: #17201e;
  --muted: #5d6967;
  --border: #dfe6e4;
  --primary: #00796b;
  --on-primary: #ffffff;
  --primary-c: #cdebe6;
  --on-primary-c: #00201c;
  --weekend: #ffe8c7;
  --notice: #fff4c2;
  --income: #2e7d32;
  --expense: #c62828;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1514;
    --card: #182120;
    --card2: #1f2a29;
    --text: #e3ebe9;
    --muted: #9aa8a5;
    --border: #2a3634;
    --primary: #80cbc4;
    --on-primary: #00332e;
    --primary-c: #00504a;
    --on-primary-c: #cdebe6;
    --weekend: #4a3714;
    --notice: #3f3800;
    --income: #81c784;
    --expense: #ef9a9a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg.i { width: 22px; height: 22px; fill: currentColor; flex: none; }

/* ---------- layout ---------- */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top)) 16px calc(150px + env(safe-area-inset-bottom));
}
.side { display: none; }
.bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottom button {
  flex: 1; border: 0; background: none; padding: 4px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted);
}
.bottom button .pill { padding: 3px 18px; border-radius: 16px; display: flex; }
.bottom button.on { color: var(--text); font-weight: 600; }
.bottom button.on .pill { background: var(--primary-c); color: var(--on-primary-c); }
.fab {
  position: fixed; right: 16px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 11;
  display: flex; align-items: center; gap: 8px;
  border: 0; border-radius: 18px; padding: 16px 22px;
  background: var(--primary); color: var(--on-primary); font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2);
}

@media (min-width: 900px) {
  .bottom, .fab { display: none; }
  .side {
    display: flex; flex-direction: column; gap: 4px;
    position: fixed; top: 0; bottom: 0; left: 0; width: 240px;
    padding: 24px 16px; background: var(--card); border-right: 1px solid var(--border);
  }
  .side .brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; margin: 0 8px 20px; }
  .side .brand img { width: 36px; height: 36px; border-radius: 10px; }
  .side .nav {
    display: flex; align-items: center; gap: 12px; border: 0; background: none;
    padding: 12px 14px; border-radius: 28px; text-align: left; color: var(--muted); font-weight: 500;
  }
  .side .nav:hover { background: var(--card2); }
  .side .nav.on { background: var(--primary-c); color: var(--on-primary-c); font-weight: 600; }
  .side .add { margin-bottom: 16px; justify-content: center; }
  main { margin-left: 240px; padding: 28px 40px 60px; }
}

.cols { display: grid; gap: 14px; align-items: start; }
.stack { display: grid; gap: 14px; }
@media (min-width: 1100px) {
  .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
  .narrow { max-width: 860px; }
}

/* ---------- pieces ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card.hero { background: var(--primary-c); color: var(--on-primary-c); border: 0; padding: 20px; }
.card.notice { background: var(--notice); border: 0; }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -.5px; line-height: 1.15; }
.hero .row2 { display: flex; gap: 16px; margin-top: 14px; }
.hero .row2 > div { flex: 1; }
.label { font-size: 13px; color: var(--muted); }
.hero .label { color: inherit; opacity: .8; }
h2 { font-size: 20px; margin: 6px 0; }
h3 { font-size: 16px; margin: 0; }
.section-title { font-size: 15px; font-weight: 700; color: var(--primary); margin: 18px 2px 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.red { color: var(--expense); }
.green { color: var(--income); }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; }
.bar { height: 8px; border-radius: 4px; background: var(--card2); overflow: hidden; margin: 10px 0 6px; }
.bar > div { height: 100%; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.empty { color: var(--muted); padding: 20px 4px; white-space: pre-line; }

.switcher { display: flex; align-items: center; gap: 4px; margin: 2px 0 10px; }
.switcher .t { flex: 1; text-align: center; }
.switcher .t b { display: block; font-size: 19px; }
.icon-btn { border: 0; background: none; width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center; color: var(--text); }
.icon-btn:hover { background: var(--card2); }

.btn { border: 0; border-radius: 22px; padding: 10px 18px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; justify-content: center; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.tonal { background: var(--primary-c); color: var(--on-primary-c); }
.btn.outline { background: none; border: 1px solid var(--border); color: var(--text); }
.btn.text { background: none; color: var(--primary); padding: 10px 12px; }
.btn.danger { background: none; color: var(--expense); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btns { display: grid; gap: 8px; margin-top: 10px; }

/* entry list */
.entry { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-radius: 10px; cursor: pointer; }
.entry:hover { background: var(--card2); }
.entry .what { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .det { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.entry .amt { font-weight: 600; white-space: nowrap; }
.dayhead { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 6px 2px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.dayhead b { color: var(--primary); font-size: 14px; }

/* week */
.wk-head, .wk-row { display: grid; grid-template-columns: 1fr 104px 96px; align-items: center; gap: 6px; }
.wk-head { font-size: 12px; color: var(--muted); padding: 0 14px 4px; }
.wk-row { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; cursor: pointer; margin-top: 8px; }
.wk-row.today { background: var(--primary-c); color: var(--on-primary-c); border-color: transparent; }
.wk-row.weekend { background: var(--weekend); border-color: transparent; margin-top: 16px; }
.wk-row .n { font-weight: 600; font-size: 17px; text-align: right; }
.wk-items { padding: 4px 4px 4px 8px; }

/* forms */
label.f { display: block; margin-top: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px 4px; }
.in {
  width: 100%; border: 1px solid var(--border); background: var(--card); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; outline: none;
}
.in:focus { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 25%, transparent); }
.in.amount { font-size: 26px; font-weight: 700; }
.with-suffix { position: relative; }
.with-suffix .suf { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: 22px; overflow: hidden; }
.seg label { text-align: center; padding: 10px; cursor: pointer; font-weight: 600; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--primary-c); color: var(--on-primary-c); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; user-select: none; }
.chip input { display: none; }
.chip:has(input:checked) { background: var(--primary-c); color: var(--on-primary-c); border-color: transparent; font-weight: 600; }
.radio { display: flex; align-items: center; gap: 10px; padding: 8px 4px; cursor: pointer; }
.radio input { width: 20px; height: 20px; accent-color: var(--primary); }
.err { color: var(--expense); font-size: 14px; min-height: 0; margin: 8px 4px 0; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--card2); border: 2px solid var(--muted); border-radius: 16px; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 6px; top: 6px; border-radius: 50%; background: var(--muted); transition: .2s; }
.switch input:checked + span { background: var(--primary); border-color: var(--primary); }
.switch input:checked + span::after { left: 26px; top: 4px; width: 20px; height: 20px; background: var(--on-primary); }

.scan { width: 100%; border: 1px dashed var(--primary); background: none; color: var(--primary); border-radius: 12px; padding: 12px; font-weight: 600; display: flex; gap: 8px; justify-content: center; align-items: center; margin-bottom: 12px; }
.ocr { background: var(--card2); border-radius: 12px; padding: 12px; margin-bottom: 12px; font-size: 14px; }
.ocr .chips { margin-top: 8px; }
.ocr pre { white-space: pre-wrap; font-size: 12px; max-height: 160px; overflow: auto; margin: 8px 0 0; }

/* modal */
#modal .back {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .4);
  display: flex; align-items: flex-end; justify-content: center;
}
#modal .sheet {
  background: var(--card); width: 100%; max-height: 94vh; overflow: auto;
  border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
#modal .sheet-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#modal .sheet-head h2 { flex: 1; margin: 0; }
#modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@media (min-width: 700px) {
  #modal .back { align-items: center; }
  #modal .sheet { width: 520px; border-radius: 22px; max-height: 88vh; }
}

#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #2b3230; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw;
}
#toast.show { opacity: 1; }
@media (min-width: 900px) { #toast { bottom: 32px; } }

/* calculator buttons under amount fields */
.calc { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 6px; }
.calc button { border: 1px solid var(--border); background: var(--card2); border-radius: 10px; padding: 8px 0; font-size: 18px; font-weight: 600; color: var(--text); }
.calc button:active { background: var(--primary-c); }
.calc-res { margin: 4px 4px 0; min-height: 1em; font-weight: 600; }
@media (min-width: 900px) { .bottom button { font-size: 12px; } }

/* account balances at the top of every page */
.balbar {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 14px; margin: 0 0 10px; box-shadow: var(--shadow);
}
.balbar > div { display: flex; flex-direction: column; min-width: 0; }
.balbar .label { font-size: 12px; }
.balbar b { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balbar > div + div { border-left: 1px solid var(--border); padding-left: 12px; }
select.in { appearance: auto; }
@media (min-width: 900px) { .balbar { max-width: 640px; } .balbar b { font-size: 22px; } }

/* dashboard */
.cmp { font-size: 40px; font-weight: 800; line-height: 1.1; }
.cmp.good, .badge.good { color: var(--income); }
.cmp.bad, .badge.bad { color: var(--expense); }
.badge { font-weight: 700; font-size: 13px; white-space: nowrap; }
.hist-row { display: grid; grid-template-columns: 1.6fr 1fr 1fr .9fr; gap: 6px; align-items: center; padding: 8px 2px; border-bottom: 1px solid var(--border); font-size: 14px; }
.hist-row.head { font-size: 12px; color: var(--muted); border-bottom: 0; padding-bottom: 2px; }
.hist-row.now { background: var(--primary-c); color: var(--on-primary-c); border-radius: 10px; padding: 8px; border-bottom: 0; }
.wide-btn { width: 100%; border: 1px solid var(--border); background: var(--card); text-align: left; margin: 4px 0; }
.bottom button { font-size: 11px; }
.bottom button .pill { padding: 3px 12px; }
