:root {
  --bg: #f3f5f4; --card: #ffffff; --ink: #14201d; --muted: #667570; --line: #dfe5e2;
  --brand: #0f5c4d; --brand-ink: #ffffff; --brand-soft: #e2f1ed;
  --ok: #1b7f4a; --warn: #a35f00; --err: #b3261e; --info: #1d5fb0;
  --radius: 14px; --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1513; --card: #17211e; --ink: #e8efec; --muted: #93a39d; --line: #26332f;
    --brand: #38b29a; --brand-ink: #062119; --brand-soft: #173a33;
    --ok: #55c58a; --warn: #e0a23f; --err: #ff7b72; --info: #6aa6ee;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.has-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 20px 0 8px; }
h3 { font-size: .95rem; margin: 14px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 14px; }
.hide { display: none !important; }

#offline-banner { background: var(--warn); color: #fff; text-align: center; padding: 6px 12px; font-size: .85rem; position: sticky; top: 0; z-index: 50; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { flex: 1; font-size: 1.1rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; opacity: .8; max-width: 30%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn { position: relative; width: 40px; height: 40px; display: grid; place-items: center; color: inherit; border-radius: 50%; }
.iconbtn:active { background: rgba(255,255,255,.18); }
.ic { width: 22px; height: 22px; }
.dot { position: absolute; top: 2px; right: 0; background: #e5483d; color: #fff; font-size: .68rem; font-weight: 700; min-width: 18px; height: 18px; line-height: 18px; border-radius: 9px; text-align: center; padding: 0 4px; }

.wrap { max-width: 720px; margin: 0 auto; padding: 14px 14px 20px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.flash { padding: 11px 14px; border-radius: 12px; margin-bottom: 12px; font-size: .95rem; border: 1px solid transparent; }
.f-ok { background: #e3f4ea; color: #14532d; border-color: #bfe3cd; }
.f-err { background: #fde8e6; color: #7a1712; border-color: #f4c3be; }
.f-info { background: #e5eefb; color: #123a73; border-color: #c3d6f2; }
@media (prefers-color-scheme: dark) {
  .f-ok { background: #123324; color: #bfe9d0; border-color: #1d5a3b; }
  .f-err { background: #3a1613; color: #ffc9c4; border-color: #6b2a25; }
  .f-info { background: #14284a; color: #c6dbf7; border-color: #28497d; }
}

/* Forms */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 0 0 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; }
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox] { display: inline-block; width: 20px; min-height: 20px; height: 20px; margin: 0 8px 0 0; vertical-align: -4px; }
.check { display: flex; align-items: center; font-weight: 500; color: var(--ink); }
.amount { font-size: 1.4rem; font-weight: 700; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: .8rem; color: var(--muted); margin: -6px 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 10px 18px;
  font: inherit; font-weight: 650; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; cursor: pointer; text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { background: transparent; color: var(--err); border-color: var(--err); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.btns .btn { flex: 1; }
button[disabled] { opacity: .5; }

/* Stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .l { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat .v { font-size: 1.25rem; font-weight: 700; margin-top: 2px; word-break: break-word; }
.stat .s { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.stat.hi { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.stat.hi .l, .stat.hi .s { color: inherit; opacity: .85; }
.stat.full { grid-column: 1 / -1; }
.pos { color: var(--ok); } .neg { color: var(--err); }

/* Lists */
.list { padding: 0; margin: 0 0 12px; list-style: none; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.item { display: flex; gap: 10px; align-items: center; padding: 12px 14px; color: inherit; }
a.item:active { background: var(--brand-soft); }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .a { text-align: right; font-weight: 650; white-space: nowrap; }
.item .a small { display: block; font-weight: 500; color: var(--muted); font-size: .76rem; }
.empty { text-align: center; color: var(--muted); padding: 22px 14px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; background: var(--line); color: var(--ink); }
.b-submitted { background: #fff0cf; color: #7a4b00; }
.b-approved { background: #dbeafe; color: #14418a; }
.b-part_paid { background: #e8e1fb; color: #46279a; }
.b-paid { background: #d8f2e2; color: #14532d; }
.b-declined, .b-cancelled { background: #f5dcda; color: #7a1712; }
.b-reversed { background: #f5dcda; color: #7a1712; }
@media (prefers-color-scheme: dark) {
  .b-submitted { background: #4a3708; color: #ffd98a; }
  .b-approved { background: #12305e; color: #b7d2fb; }
  .b-part_paid { background: #31225c; color: #d4c6fa; }
  .b-paid { background: #123a26; color: #aee6c5; }
  .b-declined, .b-cancelled, .b-reversed { background: #4a1d19; color: #ffc4be; }
}

.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; margin: 0 -14px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .chip { flex: none; padding: 7px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--ink); font-size: .88rem; font-weight: 600; display: inline-block; }
.tabs a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip { margin: 2px 4px 2px 0; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; margin: 0; font-size: .93rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }

.tablewrap { overflow-x: auto; margin: 0 -14px 12px; padding: 0 14px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tbl th, .tbl td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg); white-space: nowrap; }
.tbl td.n, .tbl th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 700; background: var(--bg); }
.tbl tr:last-child td { border-bottom: 0; }

.period { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.period .label { flex: 1; text-align: center; font-weight: 650; }
.period a { width: 42px; height: 42px; display: grid; place-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; font-size: 1.2rem; color: var(--ink); }

details.card summary { cursor: pointer; font-weight: 650; }
details.card[open] summary { margin-bottom: 10px; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 15;
  width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.fab .ic { width: 26px; height: 26px; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a { flex: 1; position: relative; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .72rem; font-weight: 600; }
.bottomnav a.on { color: var(--brand); }
.nb { position: absolute; top: 7px; left: 52%; background: #e5483d; color: #fff; font-style: normal; font-size: .66rem; font-weight: 700; min-width: 17px; height: 17px; line-height: 17px; border-radius: 9px; text-align: center; padding: 0 4px; }

.login { max-width: 380px; margin: 0 auto; padding: 36px 6px; }
.login h1 { text-align: center; font-size: 1.5rem; margin-top: 10px; }
.login .logo { text-align: center; }
.login .logo img { border-radius: 18px; }
.login .muted { text-align: center; margin: 4px 0 18px; }

.menu a.item .t { font-weight: 600; }
.pill-note { background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; font-size: .88rem; margin-bottom: 12px; }
.proof { display: flex; gap: 6px; flex-wrap: wrap; }

.noprint-only { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0 !important; }
  .topbar, .bottomnav, .fab, .period a, .noprint, .tabs, #offline-banner, .btns { display: none !important; }
  .noprint-only { display: block; }
  .wrap { max-width: none; padding: 0; }
  .card, .stat, table.tbl { border-color: #bbb; break-inside: avoid; }
}
