:root {
  --bg: #f5f4ef;
  --panel: #ffffff;
  --ink: #1d2420;
  --muted: #66706a;
  --line: #e2e0d8;
  --brand: #1f4e3d;
  --brand-ink: #ffffff;
  --brand-soft: #e6efe9;
  --accent: #b5832a;
  --ok: #217a4b;   --ok-bg: #e3f3e9;
  --warn: #9a6400; --warn-bg: #fbf0d9;
  --bad: #b3261e;  --bad-bg: #fbe5e3;
  --grey: #5f6560; --grey-bg: #ecebe6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
}
* { 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, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand); }
h1 { font-size: 1.45rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--brand); color: var(--brand-ink); padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 700; font-size: 1.02rem; line-height: 1.2; padding: 0 8px 18px; }
.brand small { display: block; font-weight: 400; opacity: .7; font-size: .78rem; margin-top: 3px; }
.side nav a {
  display: flex; align-items: center; justify-content: space-between;
  color: rgba(255,255,255,.86); text-decoration: none; padding: 8px 10px; border-radius: 7px; margin: 1px 0;
}
.side nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side nav a.on { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.side .who { margin-top: 22px; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.15); font-size: .85rem; opacity: .9; }
.side .who form { display: inline; }
.side .who button, .side .who a { background: none; border: 0; padding: 0; color: rgba(255,255,255,.8); cursor: pointer; font: inherit; text-decoration: underline; }
.close-menu { display: none; float: right; background: rgba(255,255,255,.12); border: 0; color: #fff; padding: 6px 10px; border-radius: 7px; font: inherit; }
.pill-count { background: var(--accent); color: #fff; font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
main { padding: 26px 32px 60px; max-width: 1280px; width: 100%; min-width: 0; }
.topbar { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- panels, cards */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.panel + .panel { margin-top: 16px; }
.panel.flush { padding: 0; overflow: hidden; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { font-size: .82rem; color: var(--muted); }
.kpi.alert { border-color: #e9c98d; background: #fffaf0; }
.bar { height: 6px; background: var(--grey-bg); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #faf9f6; white-space: nowrap; }
tbody tr:hover { background: #fbfaf7; }
tfoot td { font-weight: 700; background: #faf9f6; border-top: 2px solid var(--line); }
td.code { font-weight: 700; white-space: nowrap; }
td.code a { text-decoration: none; }
tr.total td { font-weight: 700; background: #faf9f6; }
.neg { color: var(--ok); }

/* ---------- chips */
.chip { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.chip.Paid, .chip.OK, .chip.matched, .chip.Occupied, .chip.Credit { background: var(--ok-bg); color: var(--ok); }
.chip.Partial, .chip.unmatched, .chip.Check, .chip.No { background: var(--warn-bg); color: var(--warn); }
.chip.Unpaid { background: var(--bad-bg); color: var(--bad); }
.chip.Vacant, .chip.Nothing, .chip.ignored, .chip.Not, .chip.grey { background: var(--grey-bg); color: var(--grey); }
.chip.src { background: var(--brand-soft); color: var(--brand); font-weight: 500; }

/* ---------- forms, buttons */
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfccc2; border-radius: 8px;
  padding: 8px 10px; width: 100%; min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 78, 61, .25); border-color: var(--brand); }
.field { margin-bottom: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; }
.row > .field { flex: 1 1 160px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; min-height: 40px; cursor: pointer;
  background: var(--brand); color: #fff; border: 1px solid var(--brand); text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: #fff; color: var(--brand); border-color: #cfccc2; }
.btn.danger { background: #fff; color: var(--bad); border-color: #e6b8b3; }
.btn.small { padding: 4px 10px; min-height: 30px; font-size: .85rem; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; min-width: 150px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe2cc; }
.flash.error { background: var(--bad-bg); color: var(--bad); border-color: #efc2bd; }
.note { background: #fffaf0; border: 1px solid #f0dcb4; border-radius: 8px; padding: 10px 14px; font-size: .9rem; }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #1f4e3d 0%, #173a2e 55%, #f5f4ef 55.1%); }
.login { width: 100%; max-width: 380px; }
.login .panel { padding: 26px; }
.login .brand-big { color: #fff; margin-bottom: 18px; }
.login .brand-big b { display: block; font-size: 1.3rem; }

/* ---------- meter reader */
.meter-list { display: grid; gap: 8px; }
.meter {
  display: grid; grid-template-columns: 74px 1fr 128px; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
}
.meter.saved { border-color: #a9d8bb; background: #f7fcf9; }
.meter.problem { border-color: #ecc98a; background: #fffaf0; }
.meter .m-code { font-weight: 800; font-size: 1.1rem; }
.meter .m-info { font-size: .85rem; color: var(--muted); line-height: 1.3; }
.meter .m-info b { color: var(--ink); font-variant-numeric: tabular-nums; }
.meter input { font-size: 1.15rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.meter .m-msg { grid-column: 1 / -1; font-size: .85rem; display: none; }
.meter .m-msg.show { display: block; }
.progress-sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0 10px; }

/* ---------- statement / tenant */
.bill-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; box-shadow: var(--shadow); }
.bill-card + .bill-card { margin-top: 18px; }
.bill-card .head { padding: 16px 18px; background: var(--brand); color: #fff; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.bill-card .head .big { font-size: 1.7rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bill-card .body { padding: 16px 18px; }
.lines { width: 100%; }
.lines td { border: 0; padding: 4px 0; }
.lines tr.sum td { border-top: 1px solid var(--line); font-weight: 700; padding-top: 8px; }
.paybox { background: var(--brand-soft); border-radius: 8px; padding: 12px 14px; margin-top: 12px; }
.paybox b { font-size: 1.1rem; }

.print-only { display: none; }
@media print {
  .side, .topbar, .no-print, .filters, .page-head .actions { display: none !important; }
  .shell { display: block; }
  main { padding: 0; }
  .print-only { display: block; }
  body { background: #fff; }
  .panel, .bill-card { box-shadow: none; }
}

/* ---------- small screens */
@media (max-width: 860px) {
  .shell { display: block; }
  .side { display: none; position: fixed; inset: 0; z-index: 30; height: auto; }
  .side.open { display: block; }
  .close-menu { display: block; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    background: var(--brand); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 20;
  }
  .topbar b { font-size: .98rem; }
  .topbar button { background: rgba(255,255,255,.12); border: 0; color: #fff; padding: 7px 12px; border-radius: 7px; font: inherit; }
  main { padding: 16px 16px 50px; }
  .grid2 { grid-template-columns: 1fr; }
  .kpi .value { font-size: 1.3rem; }
  .filters input, .filters select { flex: 1 1 140px; }
  .meter { grid-template-columns: 62px 1fr 112px; }
  .hide-sm { display: none; }
  .progress-sticky { top: 54px; }
}
