:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #17231f;
  --muted: #5b6b66;
  --border: #dbe3e0;
  --brand: #1f6f5c;
  --brand-strong: #17584a;
  --brand-soft: #e3f1ec;
  --good: #1f7a4d;
  --warn: #a35d00;
  --warn-soft: #fdf1e1;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --p1: #2c6fbb;
  --p2: #b5508a;
  --p0: #8a9893;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 28, .06), 0 4px 14px rgba(16, 32, 28, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 64px;
  --on-brand: #ffffff;
  --on-brand-muted: rgba(255,255,255,.85);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1614;
    --surface: #17211e;
    --surface-2: #1f2b27;
    --text: #e6eeeb;
    --muted: #9db0aa;
    --border: #2b3a35;
    --brand: #4fb393;
    --brand-strong: #6cc7a8;
    --brand-soft: #1b3a31;
    --good: #5cc98f;
    --warn: #f0a94a;
    --warn-soft: #3a2c17;
    --bad: #f2877e;
    --bad-soft: #3d1f1c;
    --p1: #6ea8e8;
    --p2: #e08bbb;
    --p0: #6f807a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
    --on-brand: #0b1512;
    --on-brand-muted: rgba(0,0,0,.7);
  }
}
:root[data-theme="dark"] {
    --bg: #0f1614;
  --surface: #17211e;
  --surface-2: #1f2b27;
  --text: #e6eeeb;
  --muted: #9db0aa;
  --border: #2b3a35;
  --brand: #4fb393;
  --brand-strong: #6cc7a8;
  --brand-soft: #1b3a31;
  --good: #5cc98f;
  --warn: #f0a94a;
  --warn-soft: #3a2c17;
  --bad: #f2877e;
  --bad-soft: #3d1f1c;
  --p1: #6ea8e8;
  --p2: #e08bbb;
  --p0: #6f807a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
  --on-brand: #0b1512;
  --on-brand-muted: rgba(0,0,0,.7);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .78rem; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-strong); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .chip:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 600; cursor: pointer; text-decoration: underline; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
label.field > small { display: block; color: var(--muted); font-size: .8rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[inputmode], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 16px;
}
textarea { min-height: 80px; resize: vertical; }
.field.invalid input, .field.invalid select { border-color: var(--bad); }
.field .err { color: var(--bad); font-size: .85rem; margin-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }
.form-error { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: .92rem; }
.form-note { background: var(--brand-soft); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: .92rem; }

/* ---------- Public pages ---------- */
.public { max-width: 1040px; margin: 0 auto; padding: 0 16px 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand img { width: 34px; height: 34px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .72rem; }
.hero { padding: 40px 0 28px; display: grid; gap: 28px; grid-template-columns: 1.1fr .9fr; align-items: center; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -.02em; }
.hero .lead { font-size: 1.15rem; color: var(--muted); max-width: 34em; }
.hero .cta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.hero-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.hero-card .k { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.hero-card .k:last-child { border: 0; font-weight: 700; font-size: 1.15rem; }
.section { padding: 34px 0 8px; }
.section > h2 { font-size: 1.5rem; margin-bottom: 18px; }
.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.feature { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.feature h3 { margin-bottom: 6px; }
.feature p { color: var(--muted); margin: 0; font-size: .95rem; }
.feature .ico { width: 36px; height: 36px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 800; margin-bottom: 10px; }
.pricing { display: grid; grid-template-columns: repeat(2, minmax(0, 300px)); gap: 14px; }
.price { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.price.best { border: 2px solid var(--brand); }
.price .amt { font-size: 2rem; font-weight: 800; }
.footer { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.auth-wrap { max-width: 420px; margin: 0 auto; padding: 0 16px 48px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 550; }
.side nav a:hover { background: var(--surface-2); }
.side nav a.active { background: var(--brand-soft); color: var(--brand); }
.side nav .sep { height: 1px; background: var(--border); margin: 10px 8px; }
.badge { margin-left: auto; background: var(--bad); color: var(--surface); border-radius: 999px; font-size: .72rem; padding: 1px 7px; font-weight: 700; }
.main { min-width: 0; }
.appbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding: 10px 20px; display: flex; align-items: center; gap: 10px; }
.appbar .title { font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.monthnav { display: flex; align-items: center; gap: 4px; }
.monthnav button { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 1.1rem; }
.monthnav .m { min-width: 120px; text-align: center; font-weight: 650; }
.bell { position: relative; width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; text-decoration: none; color: var(--text); }
.bell .dot { position: absolute; top: -4px; right: -4px; background: var(--bad); color: var(--surface); border-radius: 999px; font-size: .7rem; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }
.content { padding: 20px; max-width: 1080px; }
.bottomnav { display: none; }
.readonly-banner { background: var(--warn-soft); color: var(--warn); padding: 10px 20px; font-weight: 600; font-size: .92rem; }
.readonly-banner a { color: inherit; }

/* ---------- Cards & lists ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-h h2 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .l { color: var(--muted); font-size: .85rem; font-weight: 600; }
.stat .v { font-size: 1.5rem; font-weight: 750; margin-top: 2px; }
.stat.lead-stat { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.stat.lead-stat .l { color: var(--on-brand-muted); }
.stat.neg { background: var(--bad); border-color: var(--bad); }
.stat .s { font-size: .8rem; margin-top: 4px; opacity: .9; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.plan-row { padding: 12px 4px; border-bottom: 1px solid var(--border); }
.plan-row:last-child { border-bottom: 0; }
.plan-row .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.plan-row .top input { max-width: 120px; text-align: right; min-height: 40px; }
.plan-row .nums { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.quick .btn { min-height: 52px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { color: var(--muted); font-size: .84rem; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.item .amt { font-weight: 700; white-space: nowrap; }
.item.clickable { cursor: pointer; border-radius: 8px; }
.item.clickable:hover { background: var(--surface-2); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: .74rem; font-weight: 650; background: var(--surface-2); color: var(--muted); }
.pill.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.p1 { background: color-mix(in srgb, var(--p1) 15%, transparent); color: var(--p1); }
.pill.p2 { background: color-mix(in srgb, var(--p2) 15%, transparent); color: var(--p2); }
.paybtn { min-width: 92px; }
.empty { text-align: center; padding: 26px 10px; color: var(--muted); }
.empty .btn { margin-top: 10px; }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar.over > i { background: var(--bad); }
.split { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin: 8px 0 10px; }
.split > i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--c); vertical-align: -1px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-weight: 600; cursor: pointer; font-size: .9rem; }
.chip.on { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }
.receipt-full { width: 100%; border-radius: 10px; border: 1px solid var(--border); }
.alert-item.unread .name::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-right: 8px; vertical-align: 2px; }
.pref-row { display: grid; grid-template-columns: 1fr 64px 64px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 8px; }
.pref-row input { width: 22px; height: 22px; justify-self: center; accent-color: var(--brand); }
.pref-row.h { font-weight: 700; font-size: .85rem; color: var(--muted); }
.pref-row.h span:not(:first-child) { text-align: center; }

/* ---------- Sheet (modal) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 16, 14, .45); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s ease-out; }
.sheet { background: var(--surface); border-radius: 18px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.sheet-h { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.sheet-h h2 { margin: 0; }
.sheet-b { padding: 18px; }
.sheet-f { display: flex; gap: 10px; padding: 0 18px 18px; flex-wrap: wrap; }
.sheet-f .spacer { flex: 1; }
.x { width: 40px; height: 40px; border: 0; background: var(--surface-2); border-radius: 10px; cursor: pointer; font-size: 1.2rem; }
.photo-box { border: 2px dashed var(--border); border-radius: 12px; padding: 14px; text-align: center; margin-bottom: 14px; }
.photo-box img { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; margin: 0 auto 10px; }
.photo-box .btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#toast .t { background: #17231f; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow); animation: fade .15s; max-width: 90vw; }
#toast .t.err { background: var(--bad); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .features { grid-template-columns: 1fr 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; padding-top: 16px; }
}
@media (max-width: 760px) {
  .shell { display: block; }
  .side { display: none; }
  .appbar { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  .appbar .title { font-size: .95rem; }
  .monthnav .m { min-width: 92px; font-size: .92rem; }
  .monthnav button { width: 36px; height: 36px; }
  .content { padding: 14px 12px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
  .bottomnav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); z-index: 20; padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; justify-content: center; height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 650; gap: 2px; }
  .bottomnav a svg { width: 22px; height: 22px; }
  .bottomnav a.active { color: var(--brand); }
  .stat .v { font-size: 1.25rem; }
  .quick { grid-template-columns: 1fr 1fr; }
  .stats.three { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .stats.three .stat { padding: 10px; }
  .stats.three .v { font-size: 1rem; }
  .stats.three .l { font-size: .74rem; }
  .item { flex-wrap: wrap; }
  .item .grow { flex-basis: 50%; }
  .overlay { align-items: flex-end; padding: 0; }
  .sheet { border-radius: 18px 18px 0 0; max-height: 92vh; }
  .sheet-f { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  .features { grid-template-columns: 1fr; }
  .pricing { grid-template-columns: 1fr; }
  #toast { bottom: calc(var(--nav-h) + 16px); }
}
@media (max-width: 380px) {
  .row2 { grid-template-columns: 1fr; }
  .stat .v { font-size: 1.1rem; }
}
