:root {
  --bg: #FBF6F1;
  --surface: #FFFFFF;
  --ink: #2C2118;
  --muted: #7A6A5A;
  --line: #E8DDD2;
  --brand: #C45C26;
  --brand-dark: #9A4519;
  --brand-soft: #F4E4D8;
  --good: #1F7A4D;
  --good-bg: #E6F5EC;
  --bad: #B42318;
  --bad-bg: #FDECEC;
  --warn: #B54708;
  --warn-bg: #FEF0C7;
  --blue: #175CD3;
  --blue-bg: #EFF4FF;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(44,33,24,.06);
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; }
body { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 12px); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, #C45C26, #D4783E);
  color: #fff; padding: 14px 16px 12px;
  box-shadow: 0 2px 12px rgba(196,92,38,.25);
}
.app-header h1 { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: .2px; }
.app-header .sub { opacity: .9; font-size: .78rem; margin-top: 2px; }
.header-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.25);
  color: #fff; border-radius: 999px; padding: 4px 10px; font-size: .75rem;
}
.view { display: none; padding: 14px 14px 24px; max-width: 720px; margin: 0 auto; }
.view.active { display: block; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.card h2, .card h3 { margin: 0 0 10px; font-size: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.stat {
  background: var(--brand-soft); border-radius: 12px; padding: 12px;
}
.stat .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 1.05rem; font-weight: 700; margin-top: 4px; word-break: break-word; }
.stat.good { background: var(--good-bg); }
.stat.good .value { color: var(--good); }
.stat.bad { background: var(--bad-bg); }
.stat.bad .value { color: var(--bad); }
.stat.neutral { background: #F3EEE8; }
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  margin: 18px 0 10px; font-weight: 700; font-size: .95rem;
}
.btn {
  appearance: none; border: none; border-radius: 10px; padding: 10px 14px;
  background: var(--brand); color: #fff; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: .8rem; border-radius: 8px; }
.btn.block { width: 100%; }
.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; gap: 10px; align-items: flex-start; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
.row .meta { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.row .amt { font-weight: 700; white-space: nowrap; }
.badge {
  display: inline-block; font-size: .68rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: var(--blue-bg); color: var(--blue); text-transform: uppercase;
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.bottom-nav button {
  border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .65rem; font-weight: 600; padding: 6px 2px;
}
.bottom-nav button.active { color: var(--brand); }
.bottom-nav .ico { font-size: 1.15rem; line-height: 1; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(44,33,24,.45); z-index: 40;
  display: none; align-items: flex-end; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; width: 100%; max-width: 560px; max-height: 90dvh;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b));
  overflow: auto;
}
.modal h3 { margin: 0 0 12px; }
.form-grid { display: grid; gap: 10px; }
label { display: grid; gap: 4px; font-size: .78rem; color: var(--muted); font-weight: 600; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; background: #fff; color: var(--ink);
}
textarea { min-height: 72px; resize: vertical; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.chart-bars .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.chart-bars .bar { width: 100%; max-width: 28px; border-radius: 6px 6px 2px 2px; background: var(--brand); min-height: 2px; }
.chart-bars .bar.exp { background: #E8A17A; }
.chart-bars .lbl { font-size: .62rem; color: var(--muted); margin-top: 4px; }
.cat-bar { display: grid; grid-template-columns: 90px 1fr 70px; gap: 8px; align-items: center; margin-bottom: 6px; font-size: .8rem; }
.cat-bar .track { background: #F0E8E0; border-radius: 999px; height: 8px; overflow: hidden; }
.cat-bar .fill { height: 100%; background: var(--brand); border-radius: 999px; }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; }
.tabs button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 6px 12px; white-space: nowrap; color: var(--muted); font-weight: 600; font-size: .78rem;
}
.tabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + var(--safe-b));
  transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: .85rem; z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.pin-lock {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px;
}
.pin-lock.open { display: flex; }
.pin-lock input { max-width: 220px; text-align: center; letter-spacing: 8px; font-size: 1.4rem; }
.usd { color: var(--muted); font-size: .78rem; font-weight: 500; }
.alert-list .row { border-left: 4px solid var(--warn); }
.alert-list .row.overdue { border-left-color: var(--bad); }
@media print {
  .app-header, .bottom-nav, .header-actions, .no-print { display: none !important; }
  body { padding: 0; background: #fff; }
  .view { display: none !important; }
  .view.print-only, #view-report.active { display: block !important; }
}
