:root {
  --bg: #f0f8fd; --card: #fff; --ink: #0f2a3d; --muted: #5f7a8c; --line: #dceaf3;
  --brand: #0369a1; --sky: #0ea5e9; --accent: #0284c7; --soft: #e0f2fe; --soft-ink: #075985;
  --good: #15803d; --bad: #dc2626; --warn: #f6c343;
  --radius: 14px; --tabs-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 5; background: linear-gradient(120deg, var(--sky), var(--brand)); color: #fff; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); }
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }
main { max-width: 720px; margin: 0 auto; padding: 14px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(4, 1fr); background: #fff; border-top: 1px solid var(--line); height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs button { background: none; border: 0; font: inherit; font-size: .78rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button span { font-size: 1.3rem; }
.tabs button.active { color: var(--accent); font-weight: 600; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(3,105,161,.08); }
h2 { font-size: 1.05rem; margin: 4px 0 10px; }
h3 { font-size: .95rem; margin: 12px 0 6px; }
.muted { color: var(--muted); font-size: .88rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 11px 14px; font: inherit; font-weight: 600; background: var(--soft); color: var(--soft-ink); cursor: pointer; }
.btn.primary { background: linear-gradient(120deg, var(--sky), var(--accent)); color: #fff; box-shadow: 0 4px 12px rgba(2,132,199,.25); }
.btn.danger { background: #fdeaea; color: var(--bad); }
.btn.big { width: 100%; padding: 18px; font-size: 1.1rem; }
.btn.small { padding: 6px 10px; font-size: .85rem; border-radius: 8px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.stack > * + * { margin-top: 10px; }
label.field { display: block; font-size: .85rem; color: var(--muted); }
label.field input, label.field select, label.field textarea { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 1rem; color: var(--ink); padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
label.field.check input, label.field.check select { border-color: var(--warn); box-shadow: 0 0 0 2px rgba(246,195,67,.35); }
.amount-input { font-size: 1.6rem !important; font-weight: 700; }
.chip { display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.chip.low { background: #fff4d6; color: #8a6300; }
.chip.high { background: #e5f4e7; color: var(--good); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--card); border-radius: 12px; padding: 10px; text-align: center; box-shadow: 0 1px 3px rgba(3,105,161,.08); }
.kpi b { display: block; font-size: 1.05rem; margin-top: 2px; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; min-width: 0; }
.list li .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li .amt { font-weight: 700; white-space: nowrap; }
.list li.tap { cursor: pointer; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; }
.monthnav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.monthnav b { font-size: 1.05rem; }
.chartbox { position: relative; height: 300px; }
.thumb { width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; background: #222; }
.progress { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.banner { background: #fff4d6; color: #5c4300; padding: 10px 16px; font-size: .9rem; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.banner[hidden] { display: none; }
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(92vw, 460px); max-height: 85vh; }
dialog::backdrop { background: rgba(15, 25, 40, .45); }
#dialogForm { padding: 16px; }
#dialogForm .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.tablewrap { overflow-x: auto; }
table.grid { border-collapse: collapse; font-size: .8rem; min-width: 100%; }
table.grid th, table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child { text-align: left; position: sticky; left: 0; background: #fff; }
table.grid tr.main td { font-weight: 700; background: #f0f8fd; }
table.grid tr.main td:first-child { background: #f0f8fd; }
table.grid tr.total td { font-weight: 700; border-top: 2px solid var(--ink); }
details summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
pre.raw { white-space: pre-wrap; font-size: .75rem; background: #f3f5f8; padding: 8px; border-radius: 8px; max-height: 200px; overflow: auto; }
.sub-row { padding-left: 22px !important; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
input[type=color] { width: 36px; height: 30px; border: 0; padding: 0; background: none; }

label.field input:focus, label.field select:focus { outline: none; border-color: var(--sky); box-shadow: 0 0 0 3px rgba(14,165,233,.2); }
