/* Light, high-contrast, large touch targets. Built to be read at arm's length
   on a wall-mounted tablet or a phone held one-handed. */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #cbd5e1;
  --line-soft: #e2e8f0;

  --text: #0f172a;
  --muted: #475569;
  --faint: #64748b;

  --on: #15803d;
  --on-bg: #dcfce7;
  --on-line: #86efac;

  --off: #b91c1c;
  --off-bg: #fee2e2;
  --off-line: #fca5a5;

  --warn: #b45309;
  --warn-bg: #fef3c7;
  --warn-line: #fcd34d;

  --accent: #1d4ed8;
  --accent-bg: #dbeafe;

  --radius: 14px;
  --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 4px 12px rgb(15 23 42 / .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px 80px; }

/*------------------------------------------------------------- header ----*/

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.brand small { display: block; font-size: .8rem; font-weight: 500; color: var(--faint); letter-spacing: 0; }

#conn { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; font-weight: 600; color: var(--muted); }
#conn::before { content: ""; width: 11px; height: 11px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
#conn.online::before { background: #22c55e; box-shadow: 0 0 0 4px var(--on-bg); }
#conn.offline::before { background: #ef4444; box-shadow: 0 0 0 4px var(--off-bg); }

/*--------------------------------------------------------------- tabs ----*/

.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 12px 16px 0; max-width: 1080px; margin: 0 auto; }
.tab {
  flex: 0 0 auto; padding: 12px 22px; font-size: 1rem; font-weight: 600;
  border: 1px solid transparent; border-bottom: none; border-radius: 10px 10px 0 0;
  background: transparent; color: var(--muted); cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--accent); border-color: var(--line); }

/*-------------------------------------------------------------- cards ----*/

.card {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
h2 { font-size: 1.2rem; margin: 28px 0 14px; }
h2:first-child { margin-top: 0; }
.section-note { color: var(--muted); font-size: .9rem; margin: -6px 0 16px; }

/*---------------------------------------------------------- flat cards ---*/

.flats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }

.flat {
  background: var(--surface); border: 2px solid var(--line-soft);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column;
}
.flat.is-on  { border-color: var(--on-line); }
.flat.is-off { border-color: var(--off-line); }

.flat-head { padding: 18px 20px 0; }
.flat-name { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.flat-tenant { color: var(--muted); font-size: .95rem; margin-top: 2px; }
.flat-tenant.vacant { color: var(--faint); font-style: italic; }

/* The single most important thing on the card. */
.power {
  margin: 16px 20px; padding: 14px 16px; border-radius: 10px;
  font-size: 1.35rem; font-weight: 800; letter-spacing: .02em;
  display: flex; align-items: center; gap: 10px;
}
.power.on  { background: var(--on-bg);  color: var(--on);  border: 1px solid var(--on-line); }
.power.off { background: var(--off-bg); color: var(--off); border: 1px solid var(--off-line); }
.power-dot { width: 14px; height: 14px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.flat-bill { padding: 0 20px 4px; font-size: 1rem; }
.bill-caption { font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--faint); }
.bill-amount { font-size: 1.9rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; }
.overdue-flag { color: var(--off); font-weight: 800; }
.bill-line { color: var(--muted); font-size: .9rem; margin-top: 2px; }

.flat-actions { margin-top: auto; padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 10px; }

/*------------------------------------------------------------ buttons ----*/

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 12px 18px; min-height: 48px;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-big { font-size: 1.15rem; font-weight: 700; min-height: 60px; width: 100%; }
.btn-on  { background: var(--on);  border-color: var(--on);  color: #fff; }
.btn-on:hover:not(:disabled)  { background: #166534; }
.btn-off { background: var(--off); border-color: var(--off); color: #fff; }
.btn-off:hover:not(:disabled) { background: #991b1b; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1e40af; }
.btn-quiet { background: transparent; border-color: var(--line); color: var(--muted); min-height: 42px; padding: 8px 14px; }
.btn-danger { background: transparent; border-color: transparent; color: var(--off); min-height: 42px; padding: 8px 12px; }
.btn-sm { min-height: 40px; padding: 8px 14px; font-size: .9rem; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/*--------------------------------------------------------------- tags ----*/

.tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 5px 11px; border-radius: 999px; border: 1px solid;
}
.tag.paid    { background: var(--on-bg);   color: var(--on);   border-color: var(--on-line); }
.tag.unpaid  { background: var(--off-bg);  color: var(--off);  border-color: var(--off-line); }
.tag.partial { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.tag.manual  { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.tag.nobill  { background: var(--surface-2); color: var(--faint); border-color: var(--line); }
.tag-row { padding: 0 20px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Warns before enforcement acts, so a cut-off is never a surprise. */
.pending {
  margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px; font-size: .9rem; font-weight: 600;
  background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line);
}

.banner {
  padding: 14px 18px; border-radius: 12px; margin-bottom: 16px;
  font-weight: 600; border: 1px solid;
}
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.banner.info { background: var(--accent-bg); color: var(--accent); border-color: #bfdbfe; }

/*-------------------------------------------------------------- forms ----*/

label.field { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; font-weight: 600; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=tel], select {
  font: inherit; padding: 12px 14px; min-height: 48px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 3px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
.switch-row { display: flex; align-items: center; gap: 12px; font-weight: 600; }

/*------------------------------------------------------------- tables ----*/

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th {
  text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--faint); padding: 10px 12px; border-bottom: 2px solid var(--line); white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.time { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.src { font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.src.button      { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.src.enforcement { background: var(--off-bg);  color: var(--off);  border-color: var(--off-line); }
.src.restore     { background: var(--on-bg);   color: var(--on);   border-color: var(--on-line); }
.src.schedule    { background: var(--accent-bg); color: var(--accent); border-color: #bfdbfe; }

/*-------------------------------------------------------------- login ----*/

#login { max-width: 400px; margin: 12vh auto; padding: 0 16px; }
#login .card { display: flex; flex-direction: column; gap: 16px; }
#login h1 { margin: 0; font-size: 1.6rem; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
  max-width: 460px; width: calc(100% - 32px); background: var(--surface); color: var(--text);
  box-shadow: 0 20px 50px rgb(15 23 42 / .2);
}
dialog::backdrop { background: rgb(15 23 42 / .45); }
dialog h2 { margin-top: 0; }
.dialog-body { display: flex; flex-direction: column; gap: 14px; }

.err { color: var(--off); font-weight: 600; font-size: .9rem; min-height: 1.2em; }
.empty { color: var(--faint); padding: 20px; text-align: center; }
[hidden] { display: none !important; }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days input { position: absolute; opacity: 0; pointer-events: none; }
.days span {
  display: grid; place-items: center; width: 46px; height: 46px; font-size: .8rem; font-weight: 600;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer; user-select: none;
}
.days input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }

@media (max-width: 600px) {
  body { font-size: 16px; }
  .flats { grid-template-columns: 1fr; }
  .tab { padding: 12px 16px; }
}

/*--------------------------------------------------------------- toasts ---*/

.toasts {
  position: fixed; top: 16px; right: 16px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(420px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; border-radius: 12px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgb(15 23 42 / .14);
  animation: toast-in .18s ease-out;
}
.toast.success { background: var(--on-bg);   border-color: var(--on-line);   color: var(--on); }
.toast.error   { background: var(--off-bg);  border-color: var(--off-line);  color: var(--off); }
.toast.info    { background: var(--accent-bg); border-color: #bfdbfe;        color: var(--accent); }
.toast-msg { flex: 1; min-width: 0; }
.toast-close {
  flex-shrink: 0; min-height: 0; padding: 0 6px; line-height: 1.2;
  font-size: 1.3rem; background: none; border: none; color: inherit; opacity: .65;
}
.toast-close:hover { opacity: 1; background: none; }
.toast.leaving { opacity: 0; transform: translateX(12px); transition: opacity .2s, transform .2s; }

@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.confirm-message { margin: 0; font-size: 1.05rem; white-space: pre-line; }

@media (max-width: 600px) {
  .toasts { top: 12px; left: 12px; right: 12px; max-width: none; }
}

/*====================================================== page furniture ====*/

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h2 { margin: 0 0 2px; }
.page-head .section-note { margin: 0; }
.card-title { font-size: 1.05rem; margin: 0 0 4px; }
.card-title + .section-note { margin: 0 0 16px; }

.select-lg { min-width: 190px; font-weight: 600; }

/*---------------------------------------------------------- KPI tiles ----*/

.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }

.kpi {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.kpi-label { font-size: .82rem; font-weight: 600; color: var(--faint); }
/* Proportional figures: tabular-nums makes a standalone display number look loose. */
.kpi-value { font-size: 2rem; font-weight: 700; line-height: 1.15; margin-top: 4px; letter-spacing: -.02em; }
.kpi-foot { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.kpi.good .kpi-value { color: var(--on); }
.kpi.bad  .kpi-value { color: var(--off); }
.kpi.warn .kpi-value { color: var(--warn); }

/*--------------------------------------------------------------- meter ---*/
/* Single ratio against a limit. Track is a lighter step of the fill's own
   ramp so the state reads across the whole bar, not just the filled part. */

.meter-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.meter-label { font-weight: 600; color: var(--muted); font-size: .9rem; }
.meter-value { font-size: 1.15rem; font-weight: 700; }

.meter { height: 14px; border-radius: 999px; overflow: hidden; background: var(--line-soft); }
.meter-fill { height: 100%; border-radius: 999px; transition: width .3s ease; min-width: 2px; }

.meter.good { background: var(--on-bg); }
.meter.good .meter-fill { background: var(--on); }
.meter.warn { background: var(--warn-bg); }
.meter.warn .meter-fill { background: var(--warn); }
.meter.bad  { background: var(--off-bg); }
.meter.bad  .meter-fill { background: var(--off); }

.meter-foot { font-size: .85rem; color: var(--muted); margin-top: 8px; }

/*---------------------------------------------------------- data table ---*/

.data-table td.num, .data-table th.num { text-align: right; }
/* tabular-nums belongs in columns that must align vertically. */
.data-table td.num { font-variant-numeric: tabular-nums; }
.data-table .flat-cell { display: flex; flex-direction: column; gap: 1px; }
.data-table .flat-cell strong { font-size: 1rem; }
.data-table .flat-cell span { font-size: .84rem; color: var(--muted); }
.data-table tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--off); }
.data-table tr.settled td:first-child { box-shadow: inset 3px 0 0 var(--on); }
/* Only the figure that demands action is coloured, not the whole row. */
.data-table tr.overdue td.outstanding { color: var(--off); font-weight: 700; }

.amount-input { display: flex; align-items: center; justify-content: flex-end; gap: 0; max-width: 150px; margin-left: auto; }
.amount-input .prefix {
  padding: 0 8px; height: 46px; display: grid; place-items: center; font-weight: 700; color: var(--muted);
  border: 1px solid var(--line); border-right: 0; border-radius: 10px 0 0 10px; background: var(--surface-2);
}
.amount-input input { border-radius: 0 10px 10px 0; text-align: right; min-height: 46px; }

/*------------------------------------------------------------- filters ---*/

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  padding: 9px 16px; min-height: 42px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .count { opacity: .7; font-weight: 500; margin-left: 4px; }

/*-------------------------------------------------------- activity feed --*/

.day-group { margin-bottom: 18px; }
.day-head {
  font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--faint); padding: 0 4px 8px;
}
.event {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--line-soft); border-bottom: none;
}
.event:first-of-type { border-radius: var(--radius) var(--radius) 0 0; }
.event:last-of-type { border-radius: 0 0 var(--radius) var(--radius); border-bottom: 1px solid var(--line-soft); }
.event:only-of-type { border-radius: var(--radius); }

/* Icon carries state alongside the text label, never colour alone. */
.event-icon {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; font-size: 1.05rem; font-weight: 800;
}
.event-icon.on  { background: var(--on-bg);  color: var(--on);  border: 1px solid var(--on-line); }
.event-icon.off { background: var(--off-bg); color: var(--off); border: 1px solid var(--off-line); }
.event-icon.neutral { background: var(--surface-2); color: var(--faint); border: 1px solid var(--line); }

.event-body { flex: 1; min-width: 0; }
.event-title { font-weight: 600; }
.event-detail { font-size: .87rem; color: var(--muted); margin-top: 1px; word-break: break-word; }
.event-time { flex-shrink: 0; font-size: .85rem; color: var(--faint); font-variant-numeric: tabular-nums; }

/*-------------------------------------------------------- switch card ----*/

.switch-card { border-width: 2px; border-color: var(--on-line); background: var(--on-bg); }
.switch-card.paused { border-color: var(--warn-line); background: var(--warn-bg); }
.switch-card-main { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.switch-card-title { font-size: 1.2rem; font-weight: 700; }
.switch-card-sub { font-size: .9rem; color: var(--muted); margin-top: 2px; max-width: 62ch; }
.switch-card.paused .switch-card-sub { color: var(--warn); font-weight: 600; }

.toggle { position: relative; flex-shrink: 0; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  display: block; width: 68px; height: 38px; border-radius: 999px;
  background: var(--faint); transition: background .15s; position: relative;
}
.toggle-thumb {
  position: absolute; top: 4px; left: 4px; width: 30px; height: 30px;
  background: #fff; border-radius: 50%; transition: transform .15s;
  box-shadow: 0 1px 3px rgb(15 23 42 / .3);
}
.toggle input:checked + .toggle-track { background: var(--on); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(30px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--accent); outline-offset: 3px; }

/*------------------------------------------------------------- fields ----*/

.field-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.rule-preview {
  background: var(--accent-bg); border: 1px solid #bfdbfe; color: #1e3a8a;
  border-radius: 10px; padding: 14px 16px; font-size: .92rem; line-height: 1.6;
}

/*------------------------------------------------------- tenant rows ----*/

.tenant-list { display: flex; flex-direction: column; }
.tenant-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 4px; border-bottom: 1px solid var(--line-soft);
}
.tenant-row:last-child { border-bottom: none; }
.avatar {
  flex-shrink: 0; width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 700; font-size: 1rem;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.avatar.vacant { background: var(--surface); color: var(--faint); font-size: .7rem; }
.tenant-main { flex: 1; min-width: 0; }
.tenant-name { font-weight: 600; }
.tenant-meta { font-size: .85rem; color: var(--muted); }

.sched-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 4px; border-bottom: 1px solid var(--line-soft);
}
.sched-row:last-of-type { border-bottom: none; }
.sched-time { font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-width: 600px) {
  .page-head { align-items: stretch; }
  .kpi-value { font-size: 1.7rem; }
  .switch-card-main { flex-direction: row; }
  .event-time { display: none; }
  .event-body .event-detail::after { content: attr(data-time); display: block; color: var(--faint); margin-top: 2px; }
}

/*--------------------------------------------------------- bill lines ----*/

.bill-lines { display: flex; flex-direction: column; gap: 10px; }

.bill-line {
  display: grid; grid-template-columns: 1fr 150px auto; gap: 10px; align-items: center;
}
.bill-line-label { font-weight: 600; min-width: 0; }
.bill-line-kind { font-size: .75rem; color: var(--faint); font-weight: 500; }
.bill-line input[type=number] { text-align: right; }
.bill-line .amount-input { max-width: 150px; }
.bill-line .note-input { grid-column: 1 / -1; font-size: .85rem; min-height: 40px; }

.bill-total {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 0 0; border-top: 2px solid var(--line); font-size: 1.05rem; font-weight: 600;
}
.bill-total strong { font-size: 1.6rem; }

/* Inline breakdown under a billing row */
.breakdown-toggle {
  background: none; border: none; padding: 0; min-height: 0; font: inherit;
  font-weight: 600; color: var(--accent); cursor: pointer; font-size: .84rem;
}
.breakdown-toggle:hover { background: none; text-decoration: underline; }
.breakdown-row td { padding-top: 0; }
.breakdown {
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 4px;
}
.breakdown-item {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 5px 0; font-size: .9rem; border-bottom: 1px solid var(--line-soft);
}
.breakdown-item:last-child { border-bottom: none; }
.breakdown-item .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.breakdown-note { font-size: .8rem; color: var(--faint); }

@media (max-width: 600px) {
  .bill-line { grid-template-columns: 1fr 120px; }
}


/*--------------------------------------------------------- charge rows ---*/
/* Name, behaviour and remove on one line; they stacked when the inputs
   inherited width:100% inside a plain flex column. */

.charge-row {
  display: grid; grid-template-columns: 1fr 200px auto; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line-soft);
}
.charge-row:last-child { border-bottom: none; }
.charge-row input, .charge-row select { min-height: 46px; }

.charge-add {
  display: grid; grid-template-columns: 1fr 200px auto; gap: 10px; align-items: center;
  margin-top: 16px; padding-top: 16px; border-top: 2px solid var(--line);
}
.charge-add input, .charge-add select { min-height: 46px; }

@media (max-width: 640px) {
  /* Explicit placement: auto-flow pushed the button onto a third row of its
     own once the select spanned both columns. */
  .charge-row, .charge-add { grid-template-columns: 1fr auto; }
  .charge-row > input, .charge-add > input { grid-column: 1; grid-row: 1; }
  .charge-row > button, .charge-add > button { grid-column: 2; grid-row: 1; }
  .charge-row > select, .charge-add > select { grid-column: 1 / -1; grid-row: 2; }
}

/*------------------------------------------------- billing charge matrix -*/

/* Compact enough that five charges plus the money columns fit a laptop screen
   without horizontal scrolling; the wrapper still scrolls on a phone. */
.bill-cell { width: 88px; }
.bill-cell input {
  min-height: 40px; text-align: right; padding: 7px 7px; font-size: .88rem;
  width: 88px;
}
.data-table td.flat-col { min-width: 138px; }
.data-table td.flat-col .flat-cell strong { white-space: nowrap; }
.data-table td.flat-col .flat-cell span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.due-flag { font-size: .75rem; color: var(--off); font-weight: 600; }
/* Header text wraps to the column's own width; without this a long charge name
   like "Electricity (current bill)" alone widened the table past the screen. */
.data-table th.charge-col {
  font-weight: 600; color: var(--muted); width: 90px; white-space: normal;
  line-height: 1.25; vertical-align: bottom;
}
/* The matrix carries many columns, so it runs tighter than other tables. */
.data-table th, .data-table td { padding: 10px 6px; }
.data-table th:first-child, .data-table td:first-child { padding-left: 12px; }
.data-table th.charge-col .kindmark { display: block; font-size: .68rem; color: var(--faint); font-weight: 500; }
.data-table td.total-col { font-size: 1.05rem; font-weight: 700; }
.note-flag {
  display: block; margin-top: 3px; font-size: .72rem; color: var(--accent);
  cursor: help; font-weight: 600;
}
.bill-cell { text-align: right; }
.totals-row td { border-top: 2px solid var(--line); font-weight: 700; background: var(--surface-2); }

/* Row actions stay on one line; wrapping them doubled every row's height. */
.data-table td.actions { white-space: nowrap; width: 1%; }
.data-table td.actions .row { flex-wrap: nowrap; gap: 6px; }
.data-table td.actions button { min-height: 36px; padding: 6px 11px; font-size: .84rem; }
