:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #14201c;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f766e;
  --brand-dark: #0b5b54;
  --brand-ink: #ffffff;
  --danger: #dc2626;
  --ok: #15803d;
  --warn: #b45309;
  --water: #2563eb;
  --elec: #d97706;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", system-ui,
    -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  font-size: 16px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--brand);
  color: var(--brand-ink);
  padding: 0.55rem 0.9rem;
  box-shadow: var(--shadow);
}
.topbar .brand {
  color: var(--brand-ink);
  font-weight: 700;
  font-size: 1.2rem;
  display: inline-block;
  margin-bottom: 0.35rem;
}
.topbar nav { display: flex; gap: 0.2rem; flex-wrap: wrap; }
.topbar nav a {
  color: var(--brand-ink);
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  font-size: 0.95rem;
  white-space: nowrap;
}
.topbar nav a:hover { background: rgba(255, 255, 255, 0.16); text-decoration: none; }

/* ---------- layout ---------- */
.container { max-width: 1000px; margin: 1rem auto 3rem; padding: 0 0.9rem; }

h1 { font-size: 1.4rem; margin: 0.25rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 0.6rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  overflow-x: auto; /* wide tables scroll inside the card instead of off-screen */
}

.cards { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.cards .card { flex: 1 1 150px; margin-bottom: 0; }
.metric { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
.metric.ok { color: var(--ok); }
.metric.warn { color: var(--warn); }
.label { color: var(--muted); font-size: 0.82rem; margin-bottom: 0.15rem; }

/* ---------- tables ---------- */
table { width: 100%; min-width: 460px; border-collapse: collapse; }
th, td { padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- forms ---------- */
input, select, button, textarea {
  font: inherit;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.2rem; }

.field { margin-bottom: 0.75rem; }
.row { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 140px; margin-bottom: 0.4rem; }
.toolbar { display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .field { margin-bottom: 0; }

/* ---------- buttons ---------- */
button, .btn {
  background: var(--brand);
  color: #fff;
  border: 1px solid transparent;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  line-height: 1.1;
}
button:hover, .btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.secondary, button.secondary { background: #eef2f6; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover, button.secondary:hover { background: #e2e8f0; }
.btn.danger, button.danger { background: var(--danger); }
.btn.danger:hover, button.danger:hover { background: #b91c1c; }
.btn.small, button.small { padding: 0.3rem 0.6rem; font-size: 0.85rem; min-height: 34px; }

/* ---------- pills ---------- */
.pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}
.pill.unpaid { background: #fee2e2; color: var(--danger); }
.pill.partial { background: #fef3c7; color: var(--warn); }
.pill.paid { background: #dcfce7; color: var(--ok); }
.pill.occupied { background: #dcfce7; color: var(--ok); }
.pill.vacant { background: #e2e8f0; color: var(--muted); }

/* ---------- misc ---------- */
.flash { padding: 0.65rem 0.9rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 600; }
.flash.ok { background: #dcfce7; color: var(--ok); }
.flash.info { background: #e0f2fe; color: #075985; }
.muted { color: var(--muted); }
.right { text-align: right; }
.inline { display: inline; }

/* ---------- meter recording ---------- */
.meter-progress {
  position: sticky;
  top: 3rem;
  z-index: 10;
  background: #ecfdf5;
  color: var(--brand-dark);
  border: 1px solid #a7f3d0;
  border-radius: 10px;
  padding: 0.5rem 0.85rem;
  margin-bottom: 0.9rem;
  font-size: 0.95rem;
}
.meter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
}
.meter-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.9rem;
  box-shadow: var(--shadow);
}
.meter-card.is-vacant { opacity: 0.72; }
.meter-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.meter-card-head .room-no { font-size: 1.15rem; font-weight: 700; }

.meter-line { padding: 0.5rem 0 0.5rem 0.7rem; border-left: 4px solid var(--line); }
.meter-line + .meter-line { margin-top: 0.5rem; }
.meter-line.water { border-left-color: var(--water); }
.meter-line.elec { border-left-color: var(--elec); }
.meter-line-label { font-weight: 700; margin-bottom: 0.35rem; }
.meter-line-label .rate { font-weight: 400; color: var(--muted); font-size: 0.82rem; margin-left: 0.25rem; }

.meter-line-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.6rem;
  align-items: end;
}
.meter-line-controls .prev { font-size: 0.95rem; }
.meter-line-controls .prev .cap { display: block; font-size: 0.72rem; color: var(--muted); }
.meter-line-controls .cur label { margin-bottom: 0.15rem; }
.meter-line-controls .cur input { width: 100%; text-align: right; font-size: 1.05rem; }
.meter-line-controls .result { text-align: right; min-width: 4.5rem; }
.meter-line-controls .result .u { display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.meter-line-controls .result .c { display: block; font-size: 0.8rem; color: var(--muted); }

.meter-warn { font-size: 0.82rem; font-weight: 600; margin: 0.35rem 0 0; }
.meter-warn.low { color: var(--danger); }
.meter-warn.high { color: var(--warn); }
input.input-warn { border-color: var(--danger); background: #fef2f2; }
input.input-high { border-color: var(--warn); background: #fffbeb; }

/* ---------- sticky save bar ---------- */
.save-bar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  background: #ffffff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.08);
  padding: 0.7rem 0.4rem;
  margin: 0.4rem -0.9rem 0;
}
.save-bar-actions { display: flex; gap: 0.5rem; }
.save-bar .btn { min-height: 46px; }

/* ---------- larger screens ---------- */
@media (min-width: 700px) {
  body { font-size: 16px; }
  .topbar { display: flex; align-items: center; gap: 1.25rem; padding: 0.6rem 1.25rem; }
  .topbar .brand { margin-bottom: 0; }
  h1 { font-size: 1.6rem; }
  .meter-grid { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  .meter-progress { top: 0; }
  .save-bar { border-radius: 0 0 12px 12px; }
}
