:root {
  --bg: #f4f6f5; --card: #fff; --ink: #1b2623; --muted: #6b7874; --line: #e2e8e6;
  --brand: #0f5c4d; --brand-2: #e7f2ef; --late: #b3261e; --late-bg: #fdecea; --warn: #9a6700;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111615; --card: #1a2120; --ink: #e6ecea; --muted: #93a19d; --line: #2a3432;
    --brand: #4fb39c; --brand-2: #1d2e2a; --late: #ff8a80; --late-bg: #3a1f1d; --shadow: none; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; }
h2 { font-size: 1.3rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.wrap { max-width: 980px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 520px; }

/* header + nav */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand); color: #fff; }
.brand { color: #fff; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.nav-desktop { display: none; gap: 6px; align-items: center; }
.nav-desktop a { color: #dfeee9; padding: 6px 10px; border-radius: 8px; }
.nav-desktop a.on, .nav-desktop a:hover { background: rgba(255,255,255,.14); color: #fff; }
.nav-desktop a.btn { background: #fff; color: #0f5c4d; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px;
  color: var(--muted); font-size: .75rem; }
.tabbar a span { font-size: 1.25rem; line-height: 1; }
.tabbar a.on { color: var(--brand); font-weight: 600; }
.tabbar a.add span { background: var(--brand); color: #fff; width: 34px; height: 26px; border-radius: 13px;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem; }
@media (min-width: 760px) {
  .nav-desktop { display: flex; } .tabbar { display: none; } body { padding-bottom: 24px; }
}

/* buttons, forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; cursor: pointer;
  background: var(--brand); color: #fff; font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; }
.btn.small { padding: 7px 12px; font-size: .9rem; }
.btn.tiny { padding: 4px 9px; font-size: .78rem; border-radius: 8px; }
.btn.ghost { background: transparent; color: var(--brand); box-shadow: inset 0 0 0 1.5px var(--brand); }
.btn.danger { background: transparent; color: var(--late); box-shadow: inset 0 0 0 1.5px var(--late); }
.btn.full { width: 100%; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--card);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 11px; margin-top: 4px; min-height: 42px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
input[type=checkbox] { width: auto; min-height: 0; margin: 0 6px 0 0; }
input[type=file] { padding: 7px; }
label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 12px; }
label.check { display: flex; align-items: center; font-weight: 400; }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-weight: 700; font-size: 1rem; margin-bottom: 10px; padding: 0; }
.cols { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .cols { grid-template-columns: 1fr 1fr; } }
.form fieldset + fieldset { border-top: 1px solid var(--line); padding-top: 14px; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.inline { display: inline; } .inline select { width: auto; margin: 0; }
pre { background: var(--card); padding: 10px; border-radius: 8px; overflow-x: auto; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  margin-bottom: 14px; border: 1px solid var(--line); }
.card.list { padding: 0; overflow: hidden; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; background: var(--brand-2); color: var(--brand); font-weight: 600; }
.flash.error { background: var(--late-bg); color: var(--late); }
.empty { text-align: center; padding: 28px 16px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 18px 0 10px; flex-wrap: wrap; }
.row-head h2 { margin: 0; }

/* stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat small { display: block; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.stat b { display: block; font-size: 1.35rem; margin: 2px 0; font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--muted); }
.stat.alert { background: var(--late-bg); border-color: transparent; }
.stat.alert b, .stat.alert small { color: var(--late); }

/* month list */
.month-head { display: flex; justify-content: space-between; align-items: baseline; margin: 16px 2px 8px; }
.month-head h3 { margin: 0; }
.month-head span { color: var(--muted); font-size: .9rem; }
.month.overdue .month-head h3 { color: var(--late); }
.due { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.due:first-child { border-top: 0; }
.due.late { background: var(--late-bg); }
.due-date { width: 44px; text-align: center; flex: none; background: var(--brand-2); border-radius: 10px; padding: 4px 0; }
.due-date b { display: block; font-size: 1.15rem; line-height: 1.1; color: var(--brand); }
.due-date small { font-size: .7rem; text-transform: uppercase; color: var(--muted); }
.due.late .due-date { background: var(--card); } .due.late .due-date b { color: var(--late); }
.due-main { flex: 1; min-width: 0; color: var(--ink); }
.due-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.due-sub { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.due-amt { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-variant-numeric: tabular-nums; }

/* badges */
.badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 6px; vertical-align: 1px;
  background: #eef0f0; color: #4b5553; }
.cat-vehicle { background: #e3effd; color: #1b5fae; }
.cat-shop { background: #fff1dc; color: #8a5300; }
.cat-life { background: #efe7fb; color: #6a3fb5; }
.cat-medical { background: #e2f5ea; color: #1d7a45; }
.badge.grey { background: #e9ecec; color: #5d6664; }
@media (prefers-color-scheme: dark) { .badge { filter: brightness(.9) saturate(1.1); } }
.member { font-weight: 600; font-size: .85rem; margin-left: 4px; }
.late-txt { color: var(--late); font-weight: 700; }

/* policy grid */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; }
.filters input { grid-column: 1 / -1; }
.filters input, .filters select { margin: 0; }
@media (min-width: 760px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr; } .filters input { grid-column: auto; } }
.grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .grid { grid-template-columns: 1fr 1fr; } }
.pcard { display: block; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); }
.pcard:hover { border-color: var(--brand); }
.pcard-title { font-weight: 700; font-size: 1.05rem; margin-top: 6px; }
.pcard-foot { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: .9rem; }

/* policy view */
.back { display: inline-block; margin-bottom: 10px; font-size: .9rem; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.view-head h2 { margin: 6px 0 0; }
.due-box { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.due-box small { display: block; color: var(--muted); font-size: .78rem; text-transform: uppercase; }
.due-box b { display: block; font-size: 1.3rem; }
.due-box.late { background: var(--late-bg); border-color: transparent; }
.paid-form { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.paid-form label:nth-child(4) { grid-column: 1 / -1; }
.paid-form .btn { grid-column: 1 / -1; }
@media (min-width: 760px) { .paid-form { grid-template-columns: 1fr 1fr 2fr auto; align-items: end; }
  .paid-form label:nth-child(4), .paid-form .btn { grid-column: auto; } .paid-form .btn { margin-bottom: 12px; } }
.details { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; }
.details dt { color: var(--muted); } .details dd { margin: 0; font-weight: 500; word-break: break-word; }
.notes { margin-top: 12px; padding: 10px 12px; background: var(--bg); border-radius: 10px; white-space: pre-wrap; }
.doc { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.doc > a:first-child { flex: 1; display: flex; gap: 10px; align-items: center; color: var(--ink); min-width: 0; }
.doc > a:first-child span:last-child { min-width: 0; overflow: hidden; }
.doc b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc small { display: block; font-size: .78rem; }
.doc-ico { font-size: 1.5rem; }
.upload { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 12px; }
.upload input { margin: 0; }
@media (min-width: 640px) { .upload { grid-template-columns: 1fr 1.4fr auto; } }
.pay { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.danger-zone { text-align: right; margin: 20px 0; }
.chip { display: inline-block; background: var(--brand-2); padding: 5px 12px; border-radius: 20px; margin: 0 6px 8px 0; font-weight: 600; }
.chip small { color: var(--muted); margin-left: 4px; }

/* login */
.login { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 12px; }
.login form { text-align: left; margin-top: 16px; }

/* ---- policies: view-by switch and groups ---- */
.seg { display: flex; align-items: center; gap: 4px; margin: 0 0 10px; flex-wrap: wrap; }
.seg-label { font-size: .82rem; color: var(--muted); margin-right: 4px; }
.seg a { padding: 6px 14px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  color: var(--brand); box-shadow: inset 0 0 0 1.5px var(--line); background: var(--card); }
.seg a.on { background: var(--brand); color: #fff; box-shadow: none; }
.pgroup { margin-top: 18px; }
.pgroup-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  margin: 0 2px 8px; padding-bottom: 6px; border-bottom: 2px solid var(--line); }
.pgroup-head h3 { margin: 0; font-size: 1.1rem; }
.pgroup-head h3 .badge { font-size: .85rem; padding: 3px 9px; }
.pgroup-head span { color: var(--muted); font-size: .88rem; white-space: nowrap; }
.psub-head { margin: 12px 2px 6px; }
