:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #14201d; --muted: #66736f; --line: #e3e8e6;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #d9f0ec;
  --warn: #b45309; --warn-soft: #fdf0dc; --bad: #c2410c; --bad-soft: #fde6dc; --ok: #15803d;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --card: #17211e; --ink: #e8efed; --muted: #93a29d; --line: #26332f;
    --brand: #2dd4bf; --brand-ink: #062320; --brand-soft: #123a35;
    --warn: #fbbf24; --warn-soft: #3a2c0c; --bad: #fb923c; --bad-soft: #3d1f12; --ok: #4ade80;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 8px 0 4px; } h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--bad); font-size: 14px; min-height: 1em; margin: 6px 0 0; }

#app { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg); }
.title { font-weight: 700; font-size: 20px; }
main { padding: 0 16px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
  border: 1px solid var(--line); }

input, select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; width: 100%; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.wide { width: 100%; } .btn.big { padding: 15px; font-size: 18px; }
.btn.icon { width: 48px; flex: 0 0 48px; font-size: 20px; padding: 0; }
.row { display: flex; gap: 8px; align-items: center; } .row.end { justify-content: flex-end; flex-wrap: wrap; }
.grow { flex: 1; }

.add { display: grid; gap: 12px; }
.amount-wrap { display: flex; align-items: center; border-bottom: 2px solid var(--line); }
.amount-wrap:focus-within { border-color: var(--brand); }
.amount-wrap input { font-size: 44px; font-weight: 700; border: 0; background: transparent; padding: 4px 0; outline: none;
  font-variant-numeric: tabular-nums; }
.amount-wrap input { flex: 1; }
.amount-wrap select { width: auto; flex: 0 0 auto; border: 0; background: transparent; font-weight: 600; color: var(--muted); }
.amount-wrap.small input { font-size: 28px; }
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chip { font: inherit; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 12px;
  padding: 10px 4px; display: grid; justify-items: center; gap: 2px; cursor: pointer; font-size: 13px; }
.chip i { font-style: normal; font-size: 22px; line-height: 1; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); font-weight: 600; }

.today-head { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 4px; }
.list { list-style: none; margin: 0; padding: 0; }
.list.card { padding: 4px 16px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.item:first-child { border-top: 0; }
.item .ico { width: 36px; height: 36px; border-radius: 10px; background: var(--bg); display: grid; place-items: center;
  font-size: 18px; flex: 0 0 36px; }
.item .what { flex: 1; min-width: 0; }
.item .what small { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sum { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item.deleted .sum, .item.deleted .what b { text-decoration: line-through; color: var(--muted); }
.day-head { font-size: 13px; color: var(--muted); padding: 14px 0 2px; font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }
.tag { font-size: 11px; font-weight: 700; border-radius: 6px; padding: 1px 6px; margin-left: 4px; vertical-align: 1px; }
.tag.pending { background: var(--warn-soft); color: var(--warn); }
.tag.error { background: var(--bad-soft); color: var(--bad); }

.sync { font: inherit; font-size: 13px; font-weight: 600; border: 0; border-radius: 999px; padding: 6px 12px;
  background: var(--brand-soft); color: var(--brand); cursor: pointer; }
.sync.pending { background: var(--warn-soft); color: var(--warn); }
.sync.error, .sync.offline { background: var(--bad-soft); color: var(--bad); }

.period-bar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.period-bar .btn { font-size: 24px; width: 44px; }
.period-name { font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.check input { width: auto; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 3px; }
.seg button { font: inherit; border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

.total { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.bar.warn > i { background: var(--warn); } .bar.over > i { background: var(--bad); }
.cat-row { padding: 10px 0; border-top: 1px solid var(--line); }
.cat-row:first-of-type { border-top: 0; }
.cat-row .row { justify-content: space-between; }
.limit { border-radius: 12px; padding: 10px 12px; margin-top: 8px; background: var(--bg); font-size: 14px; }
.limit.warn { background: var(--warn-soft); } .limit.over { background: var(--bad-soft); }
.limit-form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.tabs button { font: inherit; font-size: 12px; border: 0; background: transparent; color: var(--muted); padding: 8px 0 10px;
  display: grid; justify-items: center; gap: 2px; cursor: pointer; }
.tabs button span { font-size: 20px; line-height: 1.1; }
.tabs button.on { color: var(--brand); font-weight: 600; }

dialog { border: 0; border-radius: var(--radius); background: var(--card); color: var(--ink); padding: 0; width: min(520px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.edit { display: grid; gap: 10px; padding: 18px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 14px; }
.compare > div { background: var(--bg); border-radius: 12px; padding: 10px; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 10px 14px; display: flex; gap: 14px; align-items: center;
  z-index: 20; width: max-content; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast button { font: inherit; font-weight: 700; color: var(--brand); background: none; border: 0; cursor: pointer; }
@media (prefers-color-scheme: dark) { .toast button { color: var(--brand-ink); } .toast { background: var(--brand); color: var(--brand-ink); } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 12px; text-align: center; }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--brand); color: var(--brand-ink); display: grid;
  place-items: center; font-size: 30px; font-weight: 800; margin: 0 auto; }

@media (min-width: 900px) {
  #app { max-width: 980px; }
  #tab-add:not([hidden]) { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
}

.life-toolbar { margin-bottom: 12px; flex-wrap: wrap; }
.life-toolbar > * { flex: 1; }
.edit-fields { display: grid; gap: 10px; }
.edit label { display: grid; gap: 4px; font-size: 14px; }
.compare pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
