:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1c1d1f;
  --muted: #6a6d72;
  --line: #e2dfd7;
  --accent: #2f6f5e;
  --accent-soft: #dcebe5;
  --accent-text: #ffffff;
  --warn: #a25b12;
  --warn-soft: #f8ead9;
  --bad: #b3372f;
  --bad-soft: #f7dfdc;
  --good: #2f6f5e;
  --bar: #2f6f5e;
  --bar-over: #b3372f;
  --track: #e9e6de;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181a;
    --surface: #1f2225;
    --surface-2: #272a2e;
    --text: #ecebe8;
    --muted: #9b9ea3;
    --line: #33373b;
    --accent: #6fbfa5;
    --accent-soft: #23372f;
    --accent-text: #0e1513;
    --warn: #e5a35c;
    --warn-soft: #3a2c1c;
    --bad: #ef7d73;
    --bad-soft: #3d2321;
    --good: #6fbfa5;
    --bar: #6fbfa5;
    --bar-over: #ef7d73;
    --track: #2c3034;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181a; --surface: #1f2225; --surface-2: #272a2e; --text: #ecebe8; --muted: #9b9ea3;
  --line: #33373b; --accent: #6fbfa5; --accent-soft: #23372f; --accent-text: #0e1513;
  --warn: #e5a35c; --warn-soft: #3a2c1c; --bad: #ef7d73; --bad-soft: #3d2321; --good: #6fbfa5;
  --bar: #6fbfa5; --bar-over: #ef7d73; --track: #2c3034; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .8rem; margin: 1.2rem 0 .4rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.hidden { display: none !important; }

/* ---------- layout */
.shell { min-height: 100vh; }
.main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; min-height: 40px; }
.topbar .actions { display: flex; gap: 8px; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
nav.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 500; position: relative;
}
nav.tabs a.active { color: var(--accent); }
nav.tabs svg { width: 24px; height: 24px; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: .7rem; line-height: 18px; text-align: center; font-weight: 600;
}
.brand { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 220px 1fr; }
  nav.tabs {
    position: sticky; top: 0; height: 100vh; flex-direction: column; justify-content: flex-start;
    gap: 4px; padding: 24px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  nav.tabs a { flex: 0; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: .95rem; }
  nav.tabs a.active { background: var(--accent-soft); }
  nav.tabs .badge { position: static; margin-left: auto; }
  .brand { display: block; font-weight: 700; font-size: 1.1rem; padding: 0 12px 16px; }
  .main { padding-bottom: 48px; padding-top: 32px; }
}

/* ---------- surfaces */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px; margin-bottom: 12px;
}
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left;
}
.row:first-child { border-top: 0; }
button.row { cursor: pointer; }
button.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-head { padding: 8px 14px; background: var(--surface-2); color: var(--muted); font-size: .8rem; font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { color: var(--muted); font-size: .78rem; }
.tile .value { font-size: 1.15rem; font-weight: 650; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .tile .value { font-size: 1rem; } }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn.small { height: 32px; padding: 0 12px; font-size: .85rem; }
.btn.icon { width: 40px; padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); outline: none;
}
textarea { height: auto; min-height: 70px; padding: 10px 12px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: .88rem; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.month { display: flex; align-items: center; gap: 4px; }
.month .label { min-width: 120px; text-align: center; font-weight: 600; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: .8rem; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.chip.suggest { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- inbox */
.review { padding: 14px; }
.review .head { display: flex; gap: 12px; align-items: flex-start; }
.review .desc { font-weight: 600; word-break: break-word; }
.review .amount { margin-left: auto; font-weight: 650; }
.review .meta { color: var(--muted); font-size: .82rem; margin-top: 2px; }
.review .note { font-size: .85rem; margin-top: 4px; font-style: italic; }
.review .act { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.review .act .suggestion { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.confidence { font-size: .75rem; color: var(--muted); white-space: nowrap; }
@media (max-width: 600px) {
  .review .act { justify-content: flex-end; }
  .review .act .suggestion { flex-basis: 100%; }
}
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty .big { font-size: 2.2rem; margin-bottom: 8px; }

/* ---------- bars & charts */
.bar-row { padding: 10px 14px; border-top: 1px solid var(--line); }
.bar-row:first-child { border-top: 0; }
.bar-row .line { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; }
.bar-row .line .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track { height: 6px; background: var(--track); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.fill { height: 100%; background: var(--bar); border-radius: 3px; }
.fill.over { background: var(--bar-over); }
.trend { width: 100%; height: 160px; display: block; }
.trend text { fill: var(--muted); font-size: 10px; }
.trend .spent { fill: var(--bar); }
.trend .current { fill: var(--accent); }
.trend .income-line { stroke: var(--muted); stroke-width: 1.5; fill: none; stroke-dasharray: 3 3; }

/* ---------- sheet */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b));
}
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 18px; max-height: 80vh; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; position: sticky; top: -16px; background: var(--bg); padding: 4px 0; z-index: 1; }
.sheet-head h2 { margin: 0; }
.cat-option { cursor: pointer; }
.cat-option.selected { background: var(--accent-soft); }

/* ---------- import table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; margin: 8px 0 12px; }
table.preview { border-collapse: collapse; font-size: .8rem; min-width: 100%; }
table.preview th, table.preview td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.preview th { background: var(--surface-2); }
table.preview select { height: 30px; font-size: .78rem; padding: 0 4px; min-width: 110px; }

/* ---------- login */
.login { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
.login .logo { width: 56px; height: 56px; margin-bottom: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.notice { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: .92rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.good { background: var(--accent-soft); color: var(--accent); }
.more-grid { display: grid; grid-template-columns: 1fr; gap: 0; }
