:root {
  --bg: #f3f6f8; --card: #ffffff; --line: #e2e8f0; --txt: #0f172a; --mut: #64748b;
  --acc: #0f766e; --acc2: #14b8a6; --accSoft: #ccfbf1; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --badSoft: #fee2e2; --warnSoft: #fef3c7; --okSoft: #dcfce7; --shadow: 0 1px 3px rgba(15,23,42,.08);
}
:root[data-theme="dark"] {
  --bg: #0b1220; --card: #131c2e; --line: #243049; --txt: #e6edf7; --mut: #93a1b8;
  --acc: #2dd4bf; --acc2: #14b8a6; --accSoft: #0f2f33; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
  --badSoft: #3b1620; --warnSoft: #3a2e12; --okSoft: #10301e; --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #131c2e; --line: #243049; --txt: #e6edf7; --mut: #93a1b8;
    --acc: #2dd4bf; --acc2: #14b8a6; --accSoft: #0f2f33; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
    --badSoft: #3b1620; --warnSoft: #3a2e12; --okSoft: #10301e; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--txt); font: 16px/1.4 system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  padding-top: calc(56px + env(safe-area-inset-top)); padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 10; height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0; display: flex; align-items: center; justify-content: space-between;
  background: var(--acc); color: #fff;
}
:root[data-theme="dark"] .top { background: #0f2f33; }
.top h1 { margin: 0; font-size: 19px; }
main { max-width: 720px; margin: 0 auto; padding: 14px 14px 24px; display: grid; gap: 14px; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
}
.tabs a { flex: 1; max-width: 140px; text-align: center; font-size: 11px; color: var(--mut); text-decoration: none; padding: 4px 0; }
.tabs a span { display: block; font-size: 21px; line-height: 1.2; }
.tabs a.on { color: var(--acc); font-weight: 700; }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 11; width: 56px; height: 56px;
  border: 0; border-radius: 50%; background: var(--acc2); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); cursor: pointer;
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 10px; font-size: 15px; color: var(--mut); font-weight: 600; letter-spacing: .02em; }
.hero { background: linear-gradient(135deg, #0f766e, #0d9488); color: #fff; border: 0; }
.hero small, .hero .lbl { color: rgba(255,255,255,.8); }
.big { font-size: 32px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0 6px; }
.lbl { font-size: 13px; color: var(--mut); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi b { display: block; font-size: 18px; }
.neg { color: var(--bad); } .pos { color: var(--ok); }

.bar { height: 8px; border-radius: 99px; background: rgba(148,163,184,.3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--acc2); border-radius: 99px; }
.hero .bar { background: rgba(255,255,255,.25); } .hero .bar > i { background: #fff; }

.row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .grow b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row small, small { color: var(--mut); font-size: 12px; }
.chip {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; flex: none;
  background: color-mix(in srgb, var(--c, #64748b) 18%, transparent);
}
.amt { font-weight: 700; white-space: nowrap; }
.row.overdue .amt { color: var(--bad); }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 99px; font-weight: 700; }
.tag.overdue { background: var(--badSoft); color: var(--bad); }
.tag.upcoming { background: var(--warnSoft); color: var(--warn); }
.tag.paid { background: var(--okSoft); color: var(--ok); }
.tag.off { background: var(--line); color: var(--mut); }

.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--txt);
  border-radius: 12px; padding: 9px 14px; cursor: pointer;
}
.btn.pri { background: var(--acc); border-color: var(--acc); color: #fff; }
:root[data-theme="dark"] .btn.pri { color: #04201d; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.small { padding: 5px 11px; font-size: 13px; border-radius: 10px; }
.top .btn { background: rgba(255,255,255,.18); color: #fff; border-color: transparent; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 10px; font: inherit; font-weight: 600; color: var(--mut); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--txt); box-shadow: var(--shadow); }
.monthnav { display: flex; align-items: center; justify-content: space-between; }
.monthnav b { font-size: 17px; }
.monthnav button { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--txt); font-size: 18px; cursor: pointer; }

.day { font-size: 12px; font-weight: 700; color: var(--mut); text-transform: uppercase; letter-spacing: .04em; margin: 8px 0 0; }
.empty { text-align: center; color: var(--mut); padding: 22px 10px; }
.empty .ico { font-size: 40px; }

.catrow { margin: 10px 0; }
.catrow .t { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }

.acc { display: grid; gap: 8px; }
.acc .head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.acc svg { width: 100%; height: 44px; }

dialog {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 24px); overflow: auto; border: 0; border-radius: 20px;
  padding: 18px; background: var(--card); color: var(--txt); box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
dialog::backdrop { background: rgba(2,6,23,.55); }
dialog h3 { margin: 0 0 12px; }
form { display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--mut); font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--txt); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%;
}
input[type="checkbox"] { width: auto; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--txt); font-weight: 500; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.formbtns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; flex-wrap: wrap; }
.formbtns .left { margin-right: auto; }
.hint { font-size: 12px; color: var(--mut); }

#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: .25s; z-index: 30; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters input { grid-column: 1 / -1; }

@media (min-width: 760px) {
  body { padding-bottom: 90px; }
  main { padding-top: 22px; }
}
