/* Hallmark · shape: app screen · genre: modern-minimal · theme: Dose (deal 1/3, seed calm-professional-back-office-tool-2ba2·7e98e1bf·2026-11-24·r0)
 * nav: top bar (wordmark, dorm selector, menu, account) that hands the menu to a bottom bar under 768px · signature: the dorm selector, the one control every screen answers to · states: boot loading, boot error, route error, not-ready placeholder, form field errors · dose: night
 * axes: light/grotesk-sans/chromatic-green · posture: committed · contrast: pass · v2.0.0 */
/* Hallmark · pre-emit critique: P4 H4 E4 S3 R5 V3 · weakest: S, a shell has little of its own yet; made the dorm selector the moulded control every screen answers to and kept everything else quiet */
/* Task 10 (plan, room): status is a chip with icon + text (occupied = filled tint, vacant = outline,
 * disabled = grey) plus a card top rule; overdue / rent-unset are badges; every label truncates with an ellipsis. */
@import url("./tokens.css");

/* ---- base ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { overflow-x: clip; }
html { scrollbar-color: var(--color-muted) var(--color-paper); scroll-padding-top: calc(var(--topbar-h) + var(--space-md)); }
body {
  margin: 0; min-height: 100dvh;
  background: var(--color-paper); color: var(--color-ink);
  font-family: var(--font-body); font-size: var(--text-md); line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased; caret-color: var(--color-accent);
}
::selection { background: color-mix(in oklab, var(--color-accent) 24%, transparent); color: var(--color-ink); }
:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 700; line-height: var(--leading-head); overflow-wrap: break-word; min-width: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
svg { display: block; flex: none; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: var(--gutter); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- controls ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-xs);
  min-height: var(--control-h); padding: 0 var(--space-md);
  border: var(--rule-hair) solid var(--color-rule-strong); border-radius: var(--radius-input);
  background: var(--color-surface); color: var(--color-ink);
  font-weight: 500; font-size: var(--text-md); line-height: 1.2; cursor: pointer;
  box-shadow: inset 0 1px 0 var(--glint), 0 2px 0 var(--color-rule);
  transition: transform var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out), box-shadow var(--dur-micro) var(--ease-out);
  position: relative;
}
.btn::after { content: ""; position: absolute; inset: -3px 0; } /* 44px hit target on 40px controls */
.btn:hover { background: var(--color-paper-2); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 var(--glint), 0 0 0 var(--color-rule); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn--primary {
  border-color: var(--color-accent-deep);
  background: var(--color-accent); color: var(--color-accent-ink);
  box-shadow: inset 0 1px 0 color-mix(in oklab, var(--glint) 35%, transparent), 0 2px 0 var(--color-accent-deep);
}
.btn--primary:hover { background: var(--color-accent-deep); }
.btn--primary:active { box-shadow: 0 0 0 var(--color-accent-deep); }
.btn--block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: var(--hit); height: var(--hit); padding: 0;
  border: 0; border-radius: var(--radius-input); background: transparent; color: var(--color-ink-2);
  cursor: pointer; transition: background-color var(--dur-micro) var(--ease-out);
}
.icon-btn:hover { background: var(--color-paper-3); color: var(--color-ink); }

.field { display: grid; gap: var(--space-2xs); min-width: 0; }
.field__label { font-weight: 500; font-size: var(--text-sm); color: var(--color-ink-2); }
.input {
  width: 100%; min-height: 44px; padding: 0 var(--space-sm);
  border: var(--rule-hair) solid var(--color-rule-strong); border-radius: var(--radius-input);
  background: var(--color-surface); font-size: var(--text-md);
  transition: border-color var(--dur-micro) var(--ease-out);
}
.input:hover { border-color: var(--color-muted); }
.input:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -1px; }
.input:disabled { opacity: 0.55; cursor: not-allowed; }
.field__msg { display: flex; align-items: center; gap: var(--space-2xs); min-height: 1lh; font-size: var(--text-sm); color: var(--color-muted); }
.field--error .input { border-color: var(--color-error); }
.field--error .field__msg { color: var(--color-error); }

.form { display: grid; gap: var(--space-sm); }
.form__actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); padding-top: var(--space-xs); }
.form__error {
  display: flex; align-items: flex-start; gap: var(--space-xs);
  padding: var(--space-sm); border-radius: var(--radius-input);
  border: var(--rule-hair) solid var(--color-error); background: var(--color-error-soft); color: var(--color-error);
  font-size: var(--text-sm);
}
.form__error .icon { margin-top: 0.15em; }
.form__note { margin-top: var(--space-md); color: var(--color-muted); font-size: var(--text-sm); }

/* ---- shell: top bar ------------------------------------------------------ */
.skip-link {
  position: absolute; left: var(--space-sm); top: var(--space-sm); z-index: var(--z-toast);
  padding: var(--space-xs) var(--space-sm); border-radius: var(--radius-input);
  background: var(--color-ink); color: var(--color-paper); transform: translateY(-200%);
}
.skip-link:focus-visible { transform: none; }

.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: color-mix(in oklab, var(--color-paper) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: var(--rule-hair) solid var(--color-rule);
}
.topbar__inner { display: flex; align-items: center; gap: var(--space-md); min-height: var(--topbar-h); }
.wordmark {
  flex: none; font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg);
  letter-spacing: -0.015em; text-decoration: none; color: var(--color-ink); white-space: nowrap;
}
a.wordmark:hover { color: var(--color-accent-deep); }

/* the dorm selector: the moulded control every screen answers to */
.dorm-picker { position: relative; flex: 0 1 220px; min-width: 140px; }
.dorm-picker__select {
  appearance: none; width: 100%; min-height: var(--control-h);
  padding: 0 36px 0 var(--space-sm);
  border: var(--rule-hair) solid var(--color-rule-strong); border-radius: var(--radius-input);
  background: var(--color-paper-2); font-weight: 500; cursor: pointer;
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
  box-shadow: inset 0 1px 0 var(--glint), 0 2px 0 var(--color-rule);
  transition: background-color var(--dur-micro) var(--ease-out);
}
.dorm-picker__select:hover { background: var(--color-paper-3); }
.dorm-picker__select:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.dorm-picker .icon { position: absolute; right: var(--space-sm); top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--color-muted); }

.mainnav { display: flex; gap: var(--space-2xs); margin-left: var(--space-xs); }
.mainnav__link {
  position: relative; display: inline-flex; align-items: center; gap: var(--space-xs);
  min-height: var(--hit); padding: 0 var(--space-sm); border-radius: var(--radius-input);
  color: var(--color-ink-2); text-decoration: none; font-weight: 500; white-space: nowrap;
  transition: background-color var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out);
}
.mainnav__link .icon { width: 20px; height: 20px; }
.mainnav__link:hover { background: var(--color-paper-3); color: var(--color-ink); }
/* current page: tinted background, accent colour and a bar under it, never colour alone */
.mainnav__link[aria-current="page"] { background: var(--color-accent-soft); color: var(--color-accent-deep); }
.mainnav__link[aria-current="page"]::after {
  content: ""; position: absolute; left: var(--space-sm); right: var(--space-sm); bottom: -10px;
  height: 3px; border-radius: 3px 3px 0 0; background: var(--color-accent);
}

/* the phone "เพิ่มเติม" button and its sheet exist only in the bottom bar */
.morenav { display: none; }
.mainnav__more { border: 0; background: transparent; cursor: pointer; width: 100%; }
.more-sheet {
  position: absolute; right: var(--space-xs); bottom: calc(100% + var(--space-xs)); z-index: var(--z-dropdown);
  width: min(260px, calc(100vw - 2 * var(--space-xs)));
  padding: var(--space-xs); border-radius: var(--radius-card);
  border: var(--rule-hair) solid var(--color-rule); background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-pop);
}
.more-sheet__title { padding: var(--space-2xs) var(--space-sm) var(--space-xs); font-size: var(--text-sm); font-weight: 500; color: var(--color-muted); }
.more-sheet__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3xs); }
.more-sheet__link {
  display: flex; align-items: center; gap: var(--space-sm); min-height: 48px; padding: 0 var(--space-sm);
  border-radius: var(--radius-input); color: var(--color-ink); text-decoration: none; font-weight: 500;
}
.more-sheet__link .icon { color: var(--color-muted); }
.more-sheet__link:hover { background: var(--color-paper-2); }
/* current page inside the sheet: tint, bold and a bar on the left, never colour alone */
.more-sheet__link[aria-current="page"] { background: var(--color-accent-soft); color: var(--color-accent-deep); font-weight: 700; box-shadow: inset 3px 0 0 var(--color-accent); }
.more-sheet__link[aria-current="page"] .icon { color: currentColor; }

.topbar__tools { display: flex; align-items: center; gap: var(--space-2xs); margin-left: auto; }

.account { position: relative; }
.account__button {
  display: inline-flex; align-items: center; gap: var(--space-xs);
  min-height: var(--hit); padding: 0 var(--space-xs) 0 var(--space-2xs);
  border: 0; border-radius: var(--radius-pill); background: transparent; cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out);
}
.account__button:hover, .account__button[aria-expanded="true"] { background: var(--color-paper-3); }
.account__avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--color-ink); color: var(--color-paper); font-weight: 500; font-size: var(--text-sm);
}
.account__name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.account__button .icon { color: var(--color-muted); }
.account__panel {
  position: absolute; right: 0; top: calc(100% + var(--space-xs)); z-index: var(--z-dropdown);
  width: 260px;
  padding: var(--space-xs); border-radius: var(--radius-card);
  border: var(--rule-hair) solid var(--color-rule); background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-pop);
}
.account__who { display: grid; padding: var(--space-xs) var(--space-sm) var(--space-sm); border-bottom: var(--rule-hair) solid var(--color-rule); margin-bottom: var(--space-2xs); }
.account__who-name { font-weight: 500; overflow-wrap: anywhere; }
.account__who-user { font-size: var(--text-sm); color: var(--color-muted); overflow-wrap: anywhere; }
.account__item {
  display: flex; align-items: center; gap: var(--space-sm); width: 100%; min-height: var(--hit);
  padding: 0 var(--space-sm); border: 0; border-radius: var(--radius-input); background: transparent;
  color: var(--color-ink); text-decoration: none; text-align: left; font-size: var(--text-md); cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out);
}
.account__item:hover { background: var(--color-paper-2); }
.account__item .icon { color: var(--color-muted); }

/* ---- main ---------------------------------------------------------------- */
.main { padding-top: var(--space-xl); padding-bottom: var(--space-2xl); outline: none; }
.main:focus-visible { outline: none; }
.page-title { display: flex; align-items: center; gap: var(--space-xs); font-size: var(--text-2xl); margin-bottom: var(--space-lg); }

.state { display: grid; justify-items: start; gap: var(--space-sm); max-width: 52ch; padding: var(--space-xl) 0; }
.state .page-title { margin-bottom: 0; }
.state__text { color: var(--color-muted); }
.state[role="alert"] .page-title .icon { color: var(--color-error); }

.boot { display: grid; place-content: center; justify-items: center; gap: var(--space-sm); min-height: 100dvh; padding: var(--space-lg); text-align: center; }
.boot__mark { font-family: var(--font-display); font-weight: 700; font-size: var(--text-xl); letter-spacing: -0.015em; }
.boot__text { display: flex; align-items: center; gap: var(--space-xs); color: var(--color-muted); }
.boot[role="alert"] .boot__text { color: var(--color-error); }

/* panels: one white surface per section, never nested */
.account-page { display: grid; gap: var(--space-lg); max-width: 640px; }
.panel {
  display: grid; gap: var(--space-md); padding: var(--space-lg);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
  background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-card);
}
.panel__title { font-size: var(--text-lg); }
.panel__text { color: var(--color-muted); max-width: 60ch; }
.panel .form { max-width: 400px; }
.facts { display: grid; gap: 0; margin: 0; }
.facts__row { display: grid; grid-template-columns: minmax(0, 10rem) minmax(0, 1fr); gap: var(--space-md); padding: var(--space-sm) 0; border-top: var(--rule-hair) solid var(--color-rule); }
.facts__row:first-child { border-top: 0; padding-top: 0; }
.facts dt { font-weight: 500; color: var(--color-ink-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

/* ---- toast & dialog -------------------------------------------------------- */
.toasts {
  position: fixed; left: 50%; bottom: var(--space-lg); z-index: var(--z-toast);
  display: grid; gap: var(--space-xs); width: 100%; max-width: 440px;
  padding-inline: var(--gutter); transform: translateX(-50%); pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md); border-radius: var(--radius-input);
  background: var(--color-ink); color: var(--color-paper); box-shadow: var(--shadow-pop);
  pointer-events: auto; animation: toast-in var(--dur-short) var(--ease-out);
}
.toast .icon { margin-top: 0.15em; }
.toast--success .icon { color: var(--color-accent-soft); }
.toast--error { background: var(--color-error); color: var(--color-accent-ink); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.dialog {
  width: 100%; max-width: min(420px, calc(100% - 2 * var(--gutter))); padding: var(--space-lg);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
  background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: var(--color-backdrop); }
.dialog__text { margin-bottom: var(--space-lg); }
.dialog__actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--space-sm); }

/* ---- status chips and badges: icon + text, colour only supports them ------ */
.status, .badge {
  display: inline-flex; align-items: center; gap: var(--space-2xs); max-width: 100%;
  min-height: 24px; padding: 0 var(--space-xs); border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 500; line-height: 1.35;
}
.status > span, .badge > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status--occupied { background: var(--color-accent-soft); color: var(--color-accent-deep); }
.status--vacant { background: transparent; color: var(--color-ink-2); box-shadow: inset 0 0 0 1px var(--color-rule-strong); }
.status--disabled, .status--storage { background: var(--color-paper-3); color: var(--color-muted); }
.badge--alert { background: var(--color-error-soft); color: var(--color-error); }
.badge--note { background: var(--color-paper-3); color: var(--color-ink-2); }
.badges { display: flex; flex-wrap: wrap; gap: var(--space-2xs); min-width: 0; }

.notice {
  display: flex; align-items: flex-start; gap: var(--space-sm); margin-bottom: var(--space-lg);
  padding: var(--space-sm) var(--space-md); border-radius: var(--radius-input);
  border: var(--rule-hair) solid var(--color-rule-strong); background: var(--color-paper-2); color: var(--color-ink);
}
.notice > .icon { margin-top: 0.2em; color: var(--color-error); }
.notice__text { min-width: 0; overflow-wrap: anywhere; }
.notice__link { font-weight: 500; color: var(--color-accent-deep); white-space: nowrap; }

/* ---- room plan ------------------------------------------------------------ */
.plan-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2xs) var(--space-sm); margin-bottom: var(--space-lg); }
.plan-head__title { margin-bottom: 0; }
.plan-head__scope { color: var(--color-muted); font-weight: 500; overflow-wrap: anywhere; min-width: 0; }

.stats { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, 1fr)); gap: var(--space-sm); margin: 0 0 var(--space-lg); }
.stat {
  display: grid; align-content: start; gap: var(--space-2xs); min-width: 0;
  padding: var(--space-md); border-radius: var(--radius-card);
  border: var(--rule-hair) solid var(--color-rule); background: var(--color-surface); box-shadow: var(--shadow-card);
}
.stat__label { font-size: var(--text-sm); font-weight: 500; color: var(--color-ink-2); }
.stat__value { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2xs) var(--space-xs); min-width: 0; }
.stat__num { font-family: var(--font-display); font-weight: 700; font-size: var(--text-2xl); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat__note { font-size: var(--text-sm); color: var(--color-muted); min-width: 0; }
.stat--lead { border-color: color-mix(in oklab, var(--color-accent) 40%, var(--color-rule)); }
.stat--lead .stat__num { color: var(--color-accent-deep); }
.stat--alert .stat__num { color: var(--color-error); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-sm); }
.toolbar__search { position: relative; flex: 1 1 260px; min-width: 0; }
.toolbar__search > .icon { position: absolute; left: var(--space-sm); top: 50%; transform: translateY(-50%); color: var(--color-muted); pointer-events: none; }
.toolbar__search-input { padding-left: 40px; }
.toolbar__filter { position: relative; flex: 0 1 200px; min-width: 0; }
.toolbar__select { appearance: none; padding-right: 36px; cursor: pointer; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
.toolbar__filter > .icon { position: absolute; right: var(--space-sm); top: 50%; transform: translateY(-50%); color: var(--color-muted); pointer-events: none; }
.segmented { display: inline-flex; padding: 2px; border-radius: var(--radius-input); border: var(--rule-hair) solid var(--color-rule-strong); background: var(--color-paper-2); }
.segmented__btn {
  display: inline-grid; place-items: center; width: 40px; height: 38px; border: 0; border-radius: 8px;
  background: transparent; color: var(--color-muted); cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out);
}
.segmented__btn:hover { color: var(--color-ink); }
.segmented__btn[aria-pressed="true"] { background: var(--color-surface); color: var(--color-accent-deep); box-shadow: inset 0 0 0 1px var(--color-rule-strong), 0 1px 0 var(--color-rule); }
.plan-count { margin-bottom: var(--space-md); font-size: var(--text-sm); color: var(--color-muted); }

.dorm-group { display: grid; gap: var(--space-lg); min-width: 0; }
.dorm-group--multi + .dorm-group--multi { margin-top: var(--space-xl); padding-top: var(--space-lg); border-top: 2px solid var(--color-rule); }
.dorm-group__title { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-xs); font-size: var(--text-xl); }
.dorm-group__name { min-width: 0; overflow-wrap: anywhere; }
.dorm-group__count, .floor__count { font-family: var(--font-body); font-size: var(--text-sm); font-weight: 400; color: var(--color-muted); }
.floor { display: grid; gap: var(--space-sm); min-width: 0; }
.floor__title { display: flex; align-items: baseline; gap: var(--space-xs); font-size: var(--text-md); color: var(--color-ink-2); }

.room-grid, .room-list { list-style: none; margin: 0; padding: 0; min-width: 0; }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 168px), 1fr)); gap: var(--space-sm); }
.room-grid__item, .room-list__item { min-width: 0; }
.room-card {
  display: grid; align-content: start; justify-items: start; gap: var(--space-2xs);
  height: 100%; min-width: 0; padding: var(--space-sm) var(--space-sm) var(--space-md);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
  background: var(--color-surface); color: var(--color-ink); text-decoration: none;
  box-shadow: 0 1px 0 var(--color-rule);
  transition: border-color var(--dur-micro) var(--ease-out), transform var(--dur-micro) var(--ease-out), box-shadow var(--dur-micro) var(--ease-out);
}
.room-card > * { max-width: 100%; }
.room-card:hover { border-color: var(--color-rule-strong); transform: translateY(-1px); box-shadow: var(--shadow-card); }
.room-card--occupied { border-top: 3px solid var(--color-accent); }
.room-card--vacant { background: var(--color-paper-2); }
.room-card--disabled, .room-card--storage { background: var(--color-paper); color: var(--color-muted); }
.room-card--overdue { border-color: color-mix(in oklab, var(--color-error) 45%, var(--color-rule)); border-top-color: var(--color-error); }
.room-card__number {
  display: block; width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); line-height: 1.3;
}
.room-card__type, .room-card__tenant { display: block; width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-card__type { font-size: var(--text-xs); color: var(--color-muted); }
.room-card__tenant { font-size: var(--text-sm); font-weight: 500; margin-top: var(--space-2xs); }
.room-card__tenant.is-empty, .room-row__tenant.is-empty { color: var(--color-muted); font-weight: 400; }

.room-list { display: grid; border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-surface); overflow: hidden; }
.room-list__item + .room-list__item { border-top: var(--rule-hair) solid var(--color-rule); }
.room-row {
  display: grid; grid-template-columns: minmax(0, 7rem) minmax(0, 6rem) minmax(0, 8rem) minmax(0, 1fr) auto 18px;
  align-items: center; gap: var(--space-sm); min-height: 52px; padding: var(--space-xs) var(--space-md);
  color: var(--color-ink); text-decoration: none; transition: background-color var(--dur-micro) var(--ease-out);
}
.room-row:hover { background: var(--color-paper-2); }
.room-row > .icon { color: var(--color-muted); }
.room-row__number { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; font-family: var(--font-display); }
.room-row__type, .room-row__tenant { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-row__type { font-size: var(--text-sm); color: var(--color-muted); }
.room-row__status { min-width: 0; display: flex; }
.room-row--overdue { box-shadow: inset 3px 0 0 var(--color-error); }

/* ---- room page ------------------------------------------------------------ */
.backlink {
  display: inline-flex; align-items: center; gap: var(--space-2xs); min-height: var(--hit);
  margin: calc(-1 * var(--space-sm)) 0 var(--space-xs) calc(-1 * var(--space-2xs)); padding: 0 var(--space-xs) 0 var(--space-2xs);
  border-radius: var(--radius-input); color: var(--color-ink-2); text-decoration: none; font-weight: 500;
}
.backlink:hover { background: var(--color-paper-3); color: var(--color-ink); }
.room-head { display: grid; justify-items: start; gap: var(--space-2xs); margin-bottom: var(--space-lg); min-width: 0; }
.room-head__eyebrow { color: var(--color-muted); font-size: var(--text-sm); font-weight: 500; overflow-wrap: anywhere; max-width: 100%; }
.room-head__title { margin-bottom: 0; max-width: 100%; }
.room-head__number { min-width: 0; overflow-wrap: anywhere; }
.room-head__status { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-top: var(--space-2xs); }

.tabs {
  display: flex; gap: var(--space-2xs); margin-bottom: var(--space-lg);
  border-bottom: var(--rule-hair) solid var(--color-rule);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs__tab {
  position: relative; flex: none; min-height: var(--hit); padding: 0 var(--space-md);
  border: 0; border-radius: var(--radius-input) var(--radius-input) 0 0; background: transparent;
  color: var(--color-ink-2); font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out), color var(--dur-micro) var(--ease-out);
}
.tabs__tab:hover { background: var(--color-paper-3); color: var(--color-ink); }
.tabs__tab:focus-visible { outline-offset: -2px; }
/* selected tab: accent text, bold weight and a bar under it, never colour alone */
.tabs__tab[aria-selected="true"] { color: var(--color-accent-deep); font-weight: 700; }
.tabs__tab[aria-selected="true"]::after { content: ""; position: absolute; left: var(--space-sm); right: var(--space-sm); bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--color-accent); }
.tabpanel { outline: none; min-width: 0; }
.tabpanel:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 4px; border-radius: var(--radius-card); }
.tabpanel__stack { display: grid; gap: var(--space-lg); max-width: 760px; }
.panel__subtitle { font-size: var(--text-md); padding-top: var(--space-xs); border-top: var(--rule-hair) solid var(--color-rule); }

.person-link {
  display: flex; align-items: center; gap: var(--space-sm); min-width: 0; padding: var(--space-sm);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-input);
  background: var(--color-paper-2); color: var(--color-ink); text-decoration: none;
  transition: border-color var(--dur-micro) var(--ease-out);
}
.person-link:hover { border-color: var(--color-rule-strong); }
.person-link__avatar { display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--color-accent-soft); color: var(--color-accent-deep); }
.person-link__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.person-link__more { flex: none; font-size: var(--text-sm); color: var(--color-accent-deep); }
.person-link > .icon { color: var(--color-muted); }
.inline-with-badge { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); }

.rate { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); }
.rate__value { font-weight: 500; font-variant-numeric: tabular-nums; }
.source { display: inline-flex; align-items: center; min-height: 22px; padding: 0 var(--space-xs); border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 500; }
.source--room { background: var(--color-accent-soft); color: var(--color-accent-deep); }
.source--dorm { background: var(--color-paper-3); color: var(--color-ink-2); }
.source--none { box-shadow: inset 0 0 0 1px var(--color-rule-strong); color: var(--color-muted); }
.form--rates { max-width: none; }
.panel .form--rates { max-width: none; }
.form__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--space-sm) var(--space-md); }

.contract-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-md); }
.contract-list__item { display: grid; gap: var(--space-xs); padding-top: var(--space-md); border-top: var(--rule-hair) solid var(--color-rule); }
.contract-list__item:first-child { padding-top: 0; border-top: 0; }
.contract-list__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2xs) var(--space-sm); }
.contract-list__name { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.contract-list__period { font-size: var(--text-sm); color: var(--color-muted); }

.history { list-style: none; margin: 0; padding: 0; display: grid; }
.history__item { display: grid; gap: var(--space-2xs); padding: var(--space-sm) 0 var(--space-sm) var(--space-md); border-left: 2px solid var(--color-rule); position: relative; }
.history__item::before { content: ""; position: absolute; left: -6px; top: calc(var(--space-sm) + 0.45em); width: 10px; height: 10px; border-radius: 50%; background: var(--color-surface); border: 2px solid var(--color-accent); }
.history__meta { display: flex; flex-wrap: wrap; gap: var(--space-2xs) var(--space-sm); font-size: var(--text-sm); color: var(--color-muted); }
.history__title { font-weight: 500; }
.history__details { margin: 0; padding-left: 1.1em; font-size: var(--text-sm); color: var(--color-ink-2); overflow-wrap: anywhere; }

/* ---- Task 11: shared form pieces ----------------------------------------- */
.btn--small { min-height: 36px; padding: 0 var(--space-sm); font-size: var(--text-sm); }
.field__req { font-weight: 400; color: var(--color-muted); }
.field--wide { grid-column: 1 / -1; }
.input--area { min-height: 88px; padding: var(--space-xs) var(--space-sm); resize: vertical; line-height: var(--leading-body); }
.select-wrap { position: relative; min-width: 0; }
.input--select { appearance: none; padding-right: 36px; cursor: pointer; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
.select-wrap > .icon { position: absolute; right: var(--space-sm); top: 50%; transform: translateY(-50%); color: var(--color-muted); pointer-events: none; }
.panel .form--wide { max-width: none; }
.form__section { display: grid; gap: var(--space-sm); min-width: 0; }
.form__heading { font-size: var(--text-md); color: var(--color-ink-2); padding-top: var(--space-xs); }
.form__error-body { display: grid; justify-items: start; gap: var(--space-xs); min-width: 0; overflow-wrap: anywhere; }
.form__actions--status { align-items: center; }
.form__status { display: inline-flex; align-items: center; gap: var(--space-2xs); font-size: var(--text-sm); color: var(--color-ink-2); }
.expander { display: grid; gap: var(--space-md); min-width: 0; padding-top: var(--space-xs); border-top: var(--rule-hair) solid var(--color-rule); }
.expander .panel__subtitle { border-top: 0; padding-top: 0; }
.muted { color: var(--color-muted); }

.choices { display: grid; gap: var(--space-2xs); margin: 0; padding: 0; border: 0; min-width: 0; }
.choices__row { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.choice {
  display: inline-flex; align-items: center; gap: var(--space-xs); min-height: var(--hit);
  padding: 0 var(--space-md) 0 var(--space-sm); border: var(--rule-hair) solid var(--color-rule-strong);
  border-radius: var(--radius-input); background: var(--color-surface); cursor: pointer; font-weight: 500;
}
.choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--color-accent); }
.choice:has(input:checked) { border-color: var(--color-accent); background: var(--color-accent-soft); color: var(--color-accent-deep); }
.choice:has(input:focus-visible) { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.picker { display: grid; gap: var(--space-xs); min-width: 0; }
.picker__status { font-size: var(--text-sm); color: var(--color-muted); min-height: 1lh; }
.picker__results { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2xs); }
.picker__results:empty { display: none; }
.picker__item {
  display: grid; gap: 2px; width: 100%; min-height: var(--hit); padding: var(--space-xs) var(--space-sm);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-input);
  background: var(--color-paper-2); text-align: left; cursor: pointer;
  transition: border-color var(--dur-micro) var(--ease-out);
}
.picker__item:hover { border-color: var(--color-accent); }
.picker__name { font-weight: 500; overflow-wrap: anywhere; }
.picker__meta { font-size: var(--text-sm); color: var(--color-muted); overflow-wrap: anywhere; }
.chosen {
  display: flex; align-items: center; gap: var(--space-sm); min-width: 0; padding: var(--space-sm);
  border: var(--rule-hair) solid var(--color-accent); border-radius: var(--radius-input); background: var(--color-accent-soft);
}
.chosen__text { display: grid; flex: 1 1 auto; min-width: 0; }
.chosen__name { font-weight: 500; overflow-wrap: anywhere; }
.chosen__note { font-size: var(--text-sm); color: var(--color-ink-2); overflow-wrap: anywhere; }
.chosen__warn { display: flex; align-items: flex-start; gap: var(--space-2xs); margin-top: var(--space-2xs); font-size: var(--text-sm); font-weight: 500; color: var(--color-ink); }
.chosen__warn .icon { margin-top: 0.2em; color: var(--color-accent-deep); }
.picker__nick { font-weight: 400; color: var(--color-muted); }
.form__hint { color: var(--color-ink); }

.notice--inline { margin-bottom: 0; }
.notice--inline > .icon { color: var(--color-accent-deep); }
.notice > .btn { flex: none; margin-left: auto; }

/* ---- tenant register -------------------------------------------------------- */
.toolbar__filter--wide { flex-basis: 260px; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-bottom: var(--space-sm); }
.chip-btn {
  display: inline-flex; align-items: center; gap: var(--space-2xs); min-height: var(--hit);
  padding: 0 var(--space-sm); border: var(--rule-hair) solid var(--color-rule-strong); border-radius: var(--radius-pill);
  background: var(--color-surface); color: var(--color-ink-2); font-weight: 500; font-size: var(--text-sm); cursor: pointer;
  transition: background-color var(--dur-micro) var(--ease-out), border-color var(--dur-micro) var(--ease-out);
}
.chip-btn:hover { background: var(--color-paper-2); }
.chip-btn .icon { color: var(--color-muted); }
/* selected filter: tint, accent border, bold count, never colour alone (aria-pressed + weight) */
.chip-btn[aria-pressed="true"] { border-color: var(--color-accent); background: var(--color-accent-soft); color: var(--color-accent-deep); font-weight: 700; }
.chip-btn[aria-pressed="true"] .icon { color: currentColor; }
.chip-btn__count { min-width: 1.6em; padding: 0 6px; border-radius: var(--radius-pill); background: var(--color-paper-3); text-align: center; font-variant-numeric: tabular-nums; }
.chip-btn[aria-pressed="true"] .chip-btn__count { background: var(--color-surface); }
.badge--soon { background: var(--color-paper-3); color: var(--color-ink); box-shadow: inset 0 0 0 1px var(--color-rule-strong); }

.tenant-results { min-width: 0; }
.tenant-results[aria-busy="true"] { opacity: 0.6; transition: opacity var(--dur-short) var(--ease-out); }
.tenant-table {
  width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-surface); overflow: hidden;
}
.tenant-table th {
  padding: var(--space-sm) var(--space-md); text-align: left; font-size: var(--text-sm); font-weight: 500;
  color: var(--color-ink-2); background: var(--color-paper-2); border-bottom: var(--rule-hair) solid var(--color-rule);
}
.tenant-table th:nth-child(1) { width: 28%; }
.tenant-table th:nth-child(2) { width: 18%; }
.tenant-table th:nth-child(3) { width: 16%; }
.tenant-table th:nth-child(5) { width: 14%; }
.tenant-table td { padding: var(--space-sm) var(--space-md); vertical-align: top; border-top: var(--rule-hair) solid var(--color-rule); min-width: 0; overflow-wrap: anywhere; }
.tenant-table tbody tr:first-child td { border-top: 0; }
.tenant-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.tenant-row:hover td { background: var(--color-paper-2); }
.tenant-row--overdue td:first-child { box-shadow: inset 3px 0 0 var(--color-error); }
.tenant-row__link { font-weight: 500; color: var(--color-ink); }
.tenant-row__link:hover { color: var(--color-accent-deep); }
.tenant-row__nick { display: block; font-size: var(--text-sm); color: var(--color-muted); }
.tenant-row__roomlink { display: grid; color: inherit; text-decoration: none; }
.tenant-row__roomno { font-weight: 500; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
.tenant-row__dorm { font-size: var(--text-sm); color: var(--color-muted); }
.tenant-row__phone { font-variant-numeric: tabular-nums; white-space: nowrap; }

.contract-list__room { font-weight: 500; color: var(--color-ink); min-width: 0; overflow-wrap: anywhere; }
.contract-list__room:hover { color: var(--color-accent-deep); }

/* ---- dorm settings --------------------------------------------------------- */
.settings { display: grid; gap: var(--space-lg); max-width: 960px; min-width: 0; }
.settings__panel { min-width: 0; scroll-margin-top: calc(var(--topbar-h) + var(--space-md)); }
.settings__panel:focus { outline: none; }
.settings__head { margin-bottom: var(--space-sm); }
.settings__head .plan-head__scope { color: var(--color-ink); font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; }
.settings__nav { margin-bottom: var(--space-lg); }
.settings__lead { color: var(--color-muted); margin-bottom: var(--space-md); }
.settings__bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-sm); }
.settings__floors { display: grid; gap: var(--space-lg); min-width: 0; }
.settings__floor { display: grid; gap: var(--space-xs); min-width: 0; }
.settings__overrides { min-width: 0; }
.panel .form--inline { max-width: 560px; }
.notice--warn > .icon { color: var(--color-error); }

.btn--danger { background: var(--color-error); border-color: var(--color-error); color: var(--color-accent-ink); }
.btn--danger:hover { background: color-mix(in oklab, var(--color-error) 85%, var(--color-ink)); }
.btn--quiet-danger { color: var(--color-error); }
a.btn { text-decoration: none; }

.dialog--form { max-width: min(520px, calc(100% - 2 * var(--gutter))); max-height: calc(100dvh - 2 * var(--space-lg)); overflow-y: auto; }
.dialog__form { gap: var(--space-md); }
.dialog__title { font-size: var(--text-lg); overflow-wrap: anywhere; }
.dialog__text--tight { margin-bottom: 0; color: var(--color-ink-2); }
.form__grid--dialog { grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }

.dorm-choices { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-sm); max-width: 640px; }
.dorm-choice {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 18px; grid-template-areas: "name badge go" "meta badge go";
  align-items: center; gap: var(--space-3xs) var(--space-sm); width: 100%; padding: var(--space-sm) var(--space-md);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
  background: var(--color-surface); color: var(--color-ink); text-align: left; cursor: pointer; box-shadow: 0 1px 0 var(--color-rule);
}
.dorm-choice:hover { border-color: var(--color-rule-strong); }
.dorm-choice__name { grid-area: name; font-family: var(--font-display); font-weight: 700; font-size: var(--text-md); overflow-wrap: anywhere; }
.dorm-choice__meta { grid-area: meta; font-size: var(--text-sm); color: var(--color-muted); }
.dorm-choice > .status, .dorm-choice > .badge { grid-area: badge; }
.dorm-choice > .icon { grid-area: go; color: var(--color-muted); }

.floor-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.floor-list__item {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2xs) var(--space-xs); min-width: 0;
  padding: var(--space-xs) var(--space-sm); border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-input); background: var(--color-paper-2);
}
.floor-list__name { font-weight: 700; }
.floor-list__label { color: var(--color-ink-2); overflow-wrap: anywhere; }
.floor-list__count { font-size: var(--text-sm); color: var(--color-muted); }

.settings-table {
  width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-surface); overflow: hidden;
}
.settings-table th {
  padding: var(--space-xs) var(--space-md); text-align: left; font-size: var(--text-sm); font-weight: 500;
  color: var(--color-ink-2); background: var(--color-paper-2); border-bottom: var(--rule-hair) solid var(--color-rule);
}
.settings-table td { padding: var(--space-xs) var(--space-md); vertical-align: middle; border-top: var(--rule-hair) solid var(--color-rule); min-width: 0; overflow-wrap: anywhere; }
.settings-table tbody tr:first-child td { border-top: 0; }
.settings-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.settings-row:hover td { background: var(--color-paper-2); }
.settings-row__title, .settings-row__sub { display: block; }
.settings-row__title { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.settings-row__sub { font-size: var(--text-sm); color: var(--color-muted); }
.settings-row__link { color: var(--color-ink); }
.settings-row__link:hover { color: var(--color-accent-deep); }
.settings-table td.settings-row__actions { text-align: right; }
.settings-row__actions > .btn { margin: 2px 0 2px var(--space-2xs); }
.settings-table th:last-child { text-align: right; }
.settings-table--rooms th:nth-child(1) { width: 22%; }
.settings-table--rooms th:nth-child(3) { width: 22%; }
.settings-table--rooms th:nth-child(4) { width: 34%; }
.settings-table--types th:nth-child(1) { width: 26%; }
.settings-table--types th:nth-child(5) { width: 16%; }
.settings-table--overrides th:nth-child(5) { width: 22%; }

/* ---- meter readings (#/meters) ---------------------------------------------- */
/* One meter at a time (a น้ำ / ไฟ switch), one short row per room: the table is capped so the
 * eye does not travel, rows stay ~47px (a 40px input), and anything longer than a word (a
 * failed save, units typed by hand) opens on a line under its row. */
.meter-head { margin-bottom: var(--space-sm); }
.meter-head .meter-head__dorm { color: var(--color-ink); font-family: var(--font-display); font-size: var(--text-lg); font-weight: 700; }
.meter-period {
  display: flex; align-items: center; gap: var(--space-xs); max-width: 640px; margin-bottom: var(--space-md);
  padding: var(--space-2xs); border: var(--rule-hair) solid var(--color-rule-strong); border-radius: var(--radius-card);
  background: var(--color-paper-2);
}
.meter-notice { max-width: 640px; margin-bottom: var(--space-md); align-items: center; border-color: var(--color-error); background: var(--color-error-soft); }
.meter-notice .notice__text { font-weight: 500; }
.meter-period__step { flex: none; color: var(--color-ink); }
.meter-period__step:disabled { opacity: 0.4; cursor: not-allowed; background: transparent; }
.meter-period__label { display: grid; flex: 1 1 auto; min-width: 0; text-align: center; }
.meter-period__name { font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); }
.meter-period__note { font-size: var(--text-sm); color: var(--color-muted); overflow-wrap: anywhere; }

/* the switch and how far along both meters are */
.meter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm) var(--space-lg); margin-bottom: var(--space-xs); }
.meter-switch { flex: none; }
.meter-switch .segmented__btn { width: auto; min-width: 88px; height: 40px; padding: 0 var(--space-md); font-weight: 500; font-size: var(--text-md); }
.meter-switch .segmented__btn[aria-pressed="true"] { font-weight: 700; }
.meter-progress { display: grid; gap: var(--space-2xs); flex: 1 1 240px; max-width: 420px; min-width: 0; }
.meter-progress__text { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs) var(--space-xs); font-variant-numeric: tabular-nums; }
.meter-progress__main { font-weight: 700; }
.meter-progress__other { font-size: var(--text-sm); color: var(--color-muted); }
.meter-progress__other--todo { color: var(--color-ink-2); font-weight: 500; }
.meter-progress--complete .meter-progress__text .icon { color: var(--color-accent-deep); }
.meter-progress__track { display: block; height: 6px; border-radius: var(--radius-pill); background: var(--color-paper-3); overflow: hidden; }
.meter-progress__fill { display: block; height: 100%; border-radius: inherit; background: var(--color-accent); transition: width var(--dur-short) var(--ease-out); }

/* each meter carries its own colour: water blue, electricity soft red */
.meter-body[data-meter="water"] { --meter: var(--color-water); --meter-deep: var(--color-water-deep); --meter-soft: var(--color-water-soft); }
.meter-body[data-meter="elec"] { --meter: var(--color-elec); --meter-deep: var(--color-elec-deep); --meter-soft: var(--color-elec-soft); }
.meter-switch .segmented__btn[data-meter="water"][aria-pressed="true"] { background: var(--color-water-soft); color: var(--color-water-deep); box-shadow: inset 0 0 0 1.5px var(--color-water); }
.meter-switch .segmented__btn[data-meter="elec"][aria-pressed="true"] { background: var(--color-elec-soft); color: var(--color-elec-deep); box-shadow: inset 0 0 0 1.5px var(--color-elec); }
.meter-body[data-meter] .meter-progress__main { color: var(--meter-deep); }
.meter-body[data-meter] .meter-progress__track { background: var(--meter-soft); }
.meter-body[data-meter] .meter-progress__fill { background: var(--meter); }
.meter-table.meter-table--water { border-top: 3px solid var(--color-water); }
.meter-table.meter-table--elec { border-top: 3px solid var(--color-elec); }
.meter-table.meter-table--water thead th { background: var(--color-water-soft); }
.meter-table.meter-table--elec thead th { background: var(--color-elec-soft); }
.meter-table.meter-table--water input:focus-visible { border-color: var(--color-water); }
.meter-table.meter-table--elec input:focus-visible { border-color: var(--color-elec); }
.meter-hint { margin-bottom: var(--space-sm); font-size: var(--text-sm); color: var(--color-muted); }

/* the table */
.meter-table {
  width: 100%; max-width: 58rem; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-surface);
}
.meter-col--room { width: 11%; }
.meter-col--status { width: 15%; }
.meter-col--prev { width: 19%; }
.meter-col--input { width: 22%; }
.meter-col--units { width: 25%; }
.meter-col--more { width: 56px; }
.meter-table thead th {
  position: sticky; top: var(--topbar-h); z-index: 1;
  padding: var(--space-2xs) var(--space-sm); text-align: left; vertical-align: bottom; font-size: var(--text-sm); font-weight: 500; line-height: 1.3;
  color: var(--color-ink-2); background: var(--color-paper-2); border-bottom: var(--rule-hair) solid var(--color-rule);
}
.meter-table thead th:first-child { border-top-left-radius: var(--radius-card); }
.meter-table thead th:last-child { border-top-right-radius: var(--radius-card); }
.meter-table thead th.meter-th--num { text-align: right; }
.meter-th__sub { display: block; font-size: var(--text-xs); font-weight: 400; color: var(--color-muted); white-space: nowrap; }
.meter-floor th {
  padding: var(--space-sm) var(--space-sm) var(--space-2xs); text-align: left; font-family: var(--font-display); font-size: var(--text-sm);
  font-weight: 700; color: var(--color-ink-2); border-top: var(--rule-hair) solid var(--color-rule-strong);
}
tbody:first-of-type .meter-floor th { border-top: 0; }
.meter-row > th, .meter-row > td { padding: 3px var(--space-sm); vertical-align: middle; border-top: var(--rule-hair) solid var(--color-rule); min-width: 0; }
.meter-row:hover > th, .meter-row:hover > td { background: var(--color-paper-2); }
.meter-row__room { text-align: left; font-weight: 400; }
.meter-row__num { font-family: var(--font-display); font-weight: 700; font-size: var(--text-md); overflow-wrap: anywhere; }
.meter-row__status .status { padding-inline: var(--space-2xs) var(--space-xs); }

.meter-cell--prev, .meter-cell--units { font-variant-numeric: tabular-nums; }
.meter-cell--prev { text-align: right; }
.meter-cell--prev > *, .meter-cell--units > * { vertical-align: middle; }
.meter-cell__value { font-weight: 500; }
.meter-cell--prev.is-empty { color: var(--color-muted); }
.meter-cell--prev .meter-tag { margin-right: var(--space-2xs); }
.meter-entry { display: flex; align-items: center; gap: var(--space-2xs); min-width: 0; }
.meter-input {
  flex: 1 1 auto; min-width: 0; min-height: var(--control-h); padding: 0 var(--space-xs);
  font-variant-numeric: tabular-nums; text-align: right; scroll-margin: calc(var(--space-2xl) + var(--space-md)) 0 var(--space-2xl);
}
.meter-input--error { border-color: var(--color-error); }
/* save state: an icon (words for screen readers) beside the input */
.meter-save { display: inline-flex; flex: none; align-items: center; gap: var(--space-2xs); min-width: 16px; color: var(--color-muted); }
.meter-save[data-state="saved"] { color: var(--color-accent-deep); }
.meter-save[data-state="error"], .meter-save[data-state="invalid"] { color: var(--color-error); font-weight: 500; }
.meter-save--wordy { font-size: var(--text-sm); }
.meter-save--wordy:empty { display: none; }
.meter-units { font-weight: 500; margin-right: var(--space-2xs); }
.meter-tags { display: inline-flex; flex-wrap: wrap; gap: var(--space-3xs); vertical-align: middle; }
.meter-tags:empty { display: none; }
.meter-tag {
  display: inline-flex; align-items: center; gap: var(--space-3xs); min-height: 20px; padding: 0 6px;
  border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 500; line-height: 1.3; white-space: nowrap;
  background: var(--color-paper-3); color: var(--color-ink-2);
}
.meter-tag--manual { background: transparent; color: var(--color-ink); box-shadow: inset 0 0 0 1px var(--color-rule-strong); }
.meter-tag--alert { background: var(--color-error-soft); color: var(--color-error); }
.meter-cell--more { text-align: right; padding-inline: 0 var(--space-2xs) !important; }
.meter-more { position: relative; width: 40px; height: 40px; }
.meter-more::after { content: ""; position: absolute; inset: -2px 0; } /* 44px hit target */
.meter-more[aria-expanded="true"] { background: var(--color-paper-3); color: var(--color-ink); }

/* the line under a row: a failed or refused value, and units typed by hand */
.meter-sub > td { padding: var(--space-2xs) var(--space-sm) var(--space-sm); background: var(--color-paper-2); }
.meter-row--open > th, .meter-row--open > td { background: var(--color-paper-2); }
.meter-sub__inner { display: grid; gap: var(--space-xs); min-width: 0; padding-left: var(--space-sm); border-left: 2px solid var(--color-rule-strong); }
.meter-issue { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs) var(--space-xs); font-size: var(--text-sm); font-weight: 500; color: var(--color-error); overflow-wrap: anywhere; }
.meter-issue__text { min-width: 0; flex: 0 1 auto; }
.meter-issue .btn { color: var(--color-ink); }
.meter-manual { display: grid; gap: var(--space-2xs); min-width: 0; }
.meter-manual__label { font-size: var(--text-sm); font-weight: 500; color: var(--color-ink-2); overflow-wrap: anywhere; }
.meter-manual__controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); min-width: 0; }
.meter-entry--manual { flex: 0 1 12rem; }
.meter-manual__unit { flex: none; font-size: var(--text-sm); color: var(--color-ink-2); }
.meter-manual__msg { font-size: var(--text-sm); font-weight: 500; color: var(--color-error); overflow-wrap: anywhere; }
.meter-manual__why { font-size: var(--text-sm); color: var(--color-ink-2); overflow-wrap: anywhere; }

/* phones: still one row per room. The status shrinks to its icon (its word stays for screen
 * readers), cells tighten, the input keeps a 44px touch height, tags sit under their number. */
@media (max-width: 47.99rem) {
  .meter-bar { gap: var(--space-xs) var(--space-md); }
  .meter-switch { flex: 1 1 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .meter-switch .segmented__btn { min-width: 0; height: 42px; }
  .meter-progress { flex-basis: 100%; max-width: none; }
  .meter-table { max-width: none; }
  .meter-col--room { width: 15%; }
  .meter-col--status { width: 34px; }
  .meter-col--prev { width: 19%; }
  .meter-col--input { width: 27%; }
  .meter-col--units { width: 19%; }
  .meter-col--more { width: 40px; }
  .meter-table thead th { top: var(--topbar-h); padding-inline: var(--space-2xs); font-size: var(--text-xs); }
  .meter-table thead th:first-child { padding-left: var(--space-xs); }
  .meter-th__sub { display: none; }
  .meter-th--status > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .meter-floor th { padding-inline: var(--space-xs); }
  .meter-row > th, .meter-row > td { padding: 3px var(--space-2xs); }
  .meter-row > th:first-child { padding-left: var(--space-xs); }
  .meter-row__num { font-size: var(--text-sm); }
  .meter-row__status .status { padding: 0; width: 24px; justify-content: center; }
  .meter-row__status .status > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .meter-cell--prev, .meter-cell--units { font-size: var(--text-sm); overflow-wrap: anywhere; line-height: 1.25; }
  .meter-cell--prev .meter-tag, .meter-units { display: block; margin: 0; }
  .meter-cell--prev .meter-tag { display: table; margin: 0 0 2px auto; }
  .meter-tags { display: flex; }
  .meter-tag { min-height: 18px; padding: 0 4px; font-size: 0.75rem; }
  .meter-tag .icon { display: none; }
  .meter-input { min-height: 44px; padding: 0 6px; scroll-margin-bottom: calc(var(--bottomnav-h) + var(--space-md)); }
  .meter-entry { gap: 2px; }
  .meter-save { min-width: 14px; }
  .meter-save .icon { width: 14px; height: 14px; }
  .meter-cell--more { padding-inline: 0 !important; }
  .meter-more { width: 36px; height: 44px; }
  .meter-more::after { inset: 0 -4px; }
  .meter-sub > td { padding-inline: var(--space-xs); }
  .meter-sub__inner { padding-left: var(--space-xs); }
}

/* ---- bills (#/bills, #/bill/:id) -------------------------------------------- */
/* bill status chips: icon + text, the tint only supports them */
.status--bill-none { background: transparent; color: var(--color-muted); box-shadow: inset 0 0 0 1px var(--color-rule-strong); }
.status--bill-draft { background: var(--color-paper-3); color: var(--color-ink-2); }
.status--bill-issued { background: transparent; color: var(--color-accent-deep); box-shadow: inset 0 0 0 1px var(--color-accent); }
.status--bill-paid { background: var(--color-accent-soft); color: var(--color-accent-deep); }
.status--bill-void { background: var(--color-paper-3); color: var(--color-muted); text-decoration: line-through; }
.badge--manual { background: var(--color-paper-3); color: var(--color-ink); box-shadow: inset 0 0 0 1px var(--color-rule-strong); }

.stats--four { grid-template-columns: minmax(0, 1fr) repeat(3, minmax(0, 1.25fr)); }
.bill-actions { margin-bottom: var(--space-lg); gap: var(--space-sm); }
.bill-actions .notice { margin-bottom: 0; }
.bill-actions__buttons { padding-top: 0; }
.bill-outcome:empty { display: none; }
.bill-result { display: grid; gap: var(--space-xs); padding: var(--space-sm) var(--space-md); border-radius: var(--radius-input); border: var(--rule-hair) solid var(--color-rule-strong); background: var(--color-paper-2); }
.bill-result__head { display: flex; align-items: center; gap: var(--space-xs); font-weight: 700; }
.bill-result__head .icon { color: var(--color-accent-deep); }
.bill-result__sub { font-weight: 500; color: var(--color-ink-2); }
.bill-result__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2xs); }
.bill-result__list li { display: grid; grid-template-columns: minmax(0, 6rem) minmax(0, 1fr); gap: var(--space-sm); font-size: var(--text-sm); overflow-wrap: anywhere; }
.bill-result__room { font-weight: 700; }
.bill-list__title { font-size: var(--text-lg); margin-bottom: var(--space-sm); }

.bill-results { min-width: 0; }
.bill-results[aria-busy="true"] { opacity: 0.6; transition: opacity var(--dur-short) var(--ease-out); }
.bill-table {
  width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-surface); overflow: hidden;
}
.bill-table th {
  padding: var(--space-sm) var(--space-md); text-align: left; font-size: var(--text-sm); font-weight: 500;
  color: var(--color-ink-2); background: var(--color-paper-2); border-bottom: var(--rule-hair) solid var(--color-rule);
}
.bill-table th:nth-child(1) { width: 13%; }
.bill-table th:nth-child(2) { width: 22%; }
.bill-table th:nth-child(4) { width: 14%; }
.bill-table th:nth-child(5) { width: 15%; }
.bill-table td { padding: var(--space-sm) var(--space-md); vertical-align: top; border-top: var(--rule-hair) solid var(--color-rule); min-width: 0; overflow-wrap: anywhere; }
.bill-table tbody tr:first-child td { border-top: 0; }
.bill-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.bill-row:hover td { background: var(--color-paper-2); }
.bill-row__link { display: inline-flex; align-items: center; gap: var(--space-3xs); min-height: 28px; color: var(--color-ink); font-weight: 700; }
.bill-row__link:hover { color: var(--color-accent-deep); }
.bill-row__link .icon { color: var(--color-muted); }
.bill-row__roomno { font-family: var(--font-display); font-weight: 700; }
.bill-row__floor { display: block; font-size: var(--text-xs); color: var(--color-muted); }
.bill-row__status { display: grid; justify-items: start; gap: var(--space-2xs); }
.bill-row__no { font-size: var(--text-xs); color: var(--color-ink-2); font-variant-numeric: tabular-nums; }
.bill-row__status .badge { white-space: normal; height: auto; padding-block: 2px; }
.bill-row__status .badge > span { white-space: normal; }
.bill-row__total { font-weight: 500; }
.bill-row--none td { color: var(--color-muted); }

/* one bill */
.bill-page { display: grid; gap: var(--space-lg); max-width: 860px; min-width: 0; }
.bill-page > .room-head { margin-bottom: 0; }
.bill-head__no { font-size: var(--text-sm); font-weight: 500; color: var(--color-ink-2); font-variant-numeric: tabular-nums; align-self: center; }
.bill-notice { margin-bottom: 0; align-items: flex-start; }
.bill-notice .notice__text { display: grid; gap: var(--space-2xs); }
.bill-notice__title { font-weight: 700; }
.bill-notice__list { margin: 0; padding-left: 1.2em; }
.bill-notice__hint { font-size: var(--text-sm); color: var(--color-ink-2); }
.notice > .btn[data-action] { align-self: center; }

.bill-items { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.bill-item { display: grid; gap: var(--space-2xs); padding: var(--space-sm) 0; border-top: var(--rule-hair) solid var(--color-rule); min-width: 0; }
.bill-item:first-child { border-top: 0; padding-top: 0; }
.bill-item__head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs) var(--space-xs); min-height: 28px; }
.bill-item__kind { font-weight: 700; font-size: var(--text-sm); color: var(--color-ink-2); }
.bill-item__remove { margin-left: auto; min-height: 32px; }
.bill-item__fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 11rem); gap: var(--space-xs) var(--space-sm); }
.bill-item__fields .field__msg:empty { min-height: 0; }
.bill-item__money-wrap { display: flex; align-items: center; gap: var(--space-2xs); }
.bill-item__money { text-align: right; font-variant-numeric: tabular-nums; }
.bill-item__sign { flex: none; font-size: var(--text-sm); font-weight: 700; color: var(--color-ink-2); }
.bill-item__meter, .bill-item__follows { font-size: var(--text-sm); color: var(--color-muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.bill-item__follows { color: var(--color-ink-2); }
.bill-item__blocked { display: flex; align-items: flex-start; gap: var(--space-2xs); font-size: var(--text-sm); color: var(--color-error); overflow-wrap: anywhere; }
.bill-item__blocked .icon { margin-top: 0.2em; }
.bill-item--discount .bill-item__money { color: var(--color-accent-deep); }
.bill-item__line { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2xs) var(--space-md); }
.bill-item__text { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2xs) var(--space-xs); min-width: 0; }
.bill-item__name { overflow-wrap: anywhere; }
.bill-item__value { font-weight: 500; font-variant-numeric: tabular-nums; margin-left: auto; }
.bill-items__add { display: flex; flex-wrap: wrap; gap: var(--space-xs); }
.bill-total {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2xs) var(--space-sm);
  padding-top: var(--space-sm); border-top: 2px solid var(--color-rule-strong);
}
.bill-total__label { font-weight: 700; }
.bill-total__num { font-family: var(--font-display); font-weight: 700; font-size: var(--text-xl); font-variant-numeric: tabular-nums; margin-right: auto; }
.bill-total__warn { flex-basis: 100%; font-size: var(--text-sm); color: var(--color-error); }
.bill-total--negative .bill-total__num { color: var(--color-error); }
.bill-note-read { display: grid; gap: var(--space-2xs); }
.bill-note-read__text { white-space: pre-wrap; overflow-wrap: anywhere; }
.bill-actions-bar { display: grid; gap: var(--space-xs); padding-top: var(--space-sm); border-top: var(--rule-hair) solid var(--color-rule); }
.bill-actions-bar .form__actions { padding-top: 0; }
.bill-actions__why { font-size: var(--text-sm); color: var(--color-ink-2); overflow-wrap: anywhere; }
.bill-pay .form__grid { max-width: 560px; }
.bill-pay .panel__title { display: flex; align-items: center; gap: var(--space-xs); }
.bill-pay .panel__title .icon { color: var(--color-accent-deep); }
.choices.field--error .choice { border-color: var(--color-error); }
.choices .field__msg { color: var(--color-error); }
.bill-pay .field__msg:empty { min-height: 0; }
.bill-pay .choices .field__msg:empty { display: none; }
.bill-link__fallback { display: grid; gap: var(--space-2xs); max-width: 640px; }

@media (max-width: 47.99rem) {
  .stats--four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats--four .stat--lead { grid-column: auto; }
  /* bill list: each row becomes a card (room and status on top, labelled facts under it) */
  .bill-table, .bill-table tbody, .bill-table tr, .bill-table td { display: block; width: auto; }
  .bill-table { border: 0; background: transparent; overflow: visible; }
  .bill-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .bill-table tbody { display: grid; gap: var(--space-xs); }
  .bill-table .bill-row {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-2xs) var(--space-sm);
    padding: var(--space-sm) var(--space-md); border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
    background: var(--color-surface); box-shadow: 0 1px 0 var(--color-rule);
  }
  .bill-row:hover td { background: transparent; }
  .bill-table td { padding: 0; border: 0; }
  .bill-table .num { text-align: left; }
  .bill-table td.bill-row__room { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-sm); }
  .bill-row__link, .bill-row__room > .bill-row__roomno { font-size: var(--text-md); min-height: var(--hit); }
  .bill-table td.bill-row__status { grid-column: 1 / -1; display: grid; }
  .bill-row__tenant { grid-column: 1 / -1; }
  .bill-row td[data-label]::before { content: attr(data-label); display: block; font-size: var(--text-xs); color: var(--color-muted); }
  .bill-item__fields { grid-template-columns: minmax(0, 1fr); }
  .bill-result__list li { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

.bill-bank-notice { max-width: 640px; margin-bottom: var(--space-md); align-items: center; }

/* ---- monthly report (#/reports) --------------------------------------------- */
/* Every dorm at once: metrics down the side and one column per dorm, the total column tinted
 * and bold (never colour alone). Phones get one card per dorm instead; print keeps the table. */
.report-scope { margin: calc(-1 * var(--space-xs)) 0 var(--space-sm); font-size: var(--text-sm); color: var(--color-muted); }
.report-body { display: grid; gap: var(--space-lg); min-width: 0; max-width: 960px; }
.report-body[aria-busy="true"] > :not(.state) { opacity: 0.6; transition: opacity var(--dur-short) var(--ease-out); }
.report-body > .stats { margin-bottom: 0; }
.report-basis { display: flex; align-items: flex-start; gap: var(--space-xs); margin-top: calc(-1 * var(--space-sm)); font-size: var(--text-sm); color: var(--color-ink-2); }
.report-basis .icon { margin-top: 0.25em; color: var(--color-accent-deep); }
.report-actions { padding-top: 0; }
.report-section { display: grid; gap: var(--space-sm); min-width: 0; }
.report-section__title { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2xs) var(--space-sm); font-size: var(--text-lg); }
.report-section__count { font-family: var(--font-body); font-size: var(--text-sm); font-weight: 400; color: var(--color-muted); }
.report-section__lead { font-size: var(--text-sm); color: var(--color-muted); max-width: 64ch; }
.report-empty { grid-auto-flow: column; justify-content: start; align-items: center; padding: var(--space-sm) 0; }
.report-empty .icon { color: var(--color-accent-deep); }

.report-table {
  width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-surface); overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.report-table thead th {
  padding: var(--space-sm) var(--space-md); text-align: left; vertical-align: bottom; font-size: var(--text-sm); font-weight: 700;
  color: var(--color-ink); background: var(--color-paper-2); border-bottom: var(--rule-hair) solid var(--color-rule-strong);
  overflow-wrap: anywhere;
}
.report-table thead th:first-child { width: 24%; font-weight: 500; color: var(--color-ink-2); }
.report-table .num { text-align: right; }
.report-table tbody th, .report-table tbody td { padding: var(--space-2xs) var(--space-md); border-top: var(--rule-hair) solid var(--color-rule); min-width: 0; }
.report-table tbody th { text-align: left; font-weight: 400; color: var(--color-ink-2); }
.report-table tbody:first-of-type tr:first-child > * { border-top: 0; }
.report-table__group th {
  padding-top: var(--space-sm); font-family: var(--font-display); font-size: var(--text-sm); font-weight: 700 !important;
  color: var(--color-ink) !important; border-top: var(--rule-hair) solid var(--color-rule-strong) !important;
}
.report-table__row:hover > * { background: var(--color-paper-2); }
.report-table__total { background: color-mix(in oklab, var(--color-accent-soft) 45%, var(--color-surface)); font-weight: 700; }
.report-table thead .report-table__total { background: var(--color-accent-soft); color: var(--color-accent-deep); }
.report-table__row--strong > * { font-weight: 700; color: var(--color-ink) !important; }
.report-table__row--strong > td { font-size: var(--text-md); }

.report-cards { display: none; list-style: none; margin: 0; padding: 0; gap: var(--space-xs); }
.report-card {
  display: grid; gap: var(--space-xs); min-width: 0; padding: var(--space-sm) var(--space-md);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-surface); box-shadow: 0 1px 0 var(--color-rule);
}
.report-card--total { border-color: color-mix(in oklab, var(--color-accent) 40%, var(--color-rule)); border-top: 3px solid var(--color-accent); }
.report-card__title { font-size: var(--text-md); overflow-wrap: anywhere; }
.report-card__facts { display: grid; margin: 0; font-variant-numeric: tabular-nums; }
.report-card__fact { display: flex; justify-content: space-between; gap: var(--space-sm); padding: 3px 0; border-top: var(--rule-hair) solid var(--color-rule); font-size: var(--text-sm); }
.report-card__fact:first-child { border-top: 0; }
.report-card__fact dt { color: var(--color-ink-2); min-width: 0; }
.report-card__fact dd { margin: 0; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.report-card__fact--strong { font-weight: 700; font-size: var(--text-md); }
.report-card__fact--strong dt { color: var(--color-ink); }

.report-out {
  width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card); background: var(--color-surface); overflow: hidden;
}
.report-out th {
  padding: var(--space-xs) var(--space-md); text-align: left; font-size: var(--text-sm); font-weight: 500;
  color: var(--color-ink-2); background: var(--color-paper-2); border-bottom: var(--rule-hair) solid var(--color-rule);
}
.report-out th:nth-child(1) { width: 17%; }
.report-out th:nth-child(3) { width: 15%; }
.report-out th:nth-child(4) { width: 14%; }
.report-out th:nth-child(5) { width: 14%; }
.report-out th:nth-child(6) { width: 17%; }
.report-out td { padding: var(--space-xs) var(--space-md); vertical-align: top; border-top: var(--rule-hair) solid var(--color-rule); min-width: 0; overflow-wrap: anywhere; }
.report-out tbody tr:first-child td { border-top: 0; }
.report-out .num { text-align: right; font-variant-numeric: tabular-nums; }
.report-out__row:hover td { background: var(--color-paper-2); }
.report-out__row--late td:first-child { box-shadow: inset 3px 0 0 var(--color-error); }
.report-out__dorm { display: block; font-size: var(--text-xs); color: var(--color-muted); }
.report-out__no { font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.report-out__total { font-weight: 500; }
.report-out__late .badge { white-space: normal; }

/* bank accounts in the dorm settings */
.settings-table--bank th:nth-child(1) { width: 20%; }
.settings-table--bank th:nth-child(3) { width: 17%; }
.settings-table--bank th:nth-child(4) { width: 14%; }
.settings-table--bank th:nth-child(5) { width: 13%; }
.settings-table--bank th:nth-child(6) { width: 22%; }
.bank-row__number { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bank-row--default td:first-child { box-shadow: inset 3px 0 0 var(--color-accent); }
.bank-default { justify-self: start; }

@media screen and (max-width: 47.99rem) {
  .report-table { display: none; }
  .report-cards { display: grid; }
  .report-basis { margin-top: calc(-1 * var(--space-xs)); }
  /* unpaid bills: each row becomes a card (room and dorm on top, labelled facts under it) */
  .report-out, .report-out tbody, .report-out tr, .report-out td { display: block; width: auto; }
  .report-out { border: 0; background: transparent; overflow: visible; }
  .report-out thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .report-out tbody { display: grid; gap: var(--space-xs); }
  .report-out .report-out__row {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-2xs) var(--space-sm);
    padding: var(--space-sm) var(--space-md); border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
    background: var(--color-surface); box-shadow: 0 1px 0 var(--color-rule);
  }
  .report-out__row--late { border-left: 3px solid var(--color-error) !important; }
  .report-out__row--late td:first-child { box-shadow: none; }
  .report-out__row:hover td { background: transparent; }
  .report-out td { padding: 0; border: 0; }
  .report-out .num { text-align: left; }
  .report-out td.report-out__room { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 var(--space-sm); }
  .report-out__room .bill-row__link { font-size: var(--text-md); min-height: var(--hit); }
  .report-out__room .report-out__dorm { display: inline; font-size: var(--text-sm); }
  .report-out__tenant { grid-column: 1 / -1; }
  .report-out td[data-label]::before { content: attr(data-label); display: block; font-size: var(--text-xs); color: var(--color-muted); }
  .report-out td.report-out__late::before { margin-bottom: 2px; }
  .settings-table .settings-row.bank-row--default { border-left: 3px solid var(--color-accent); }
  .bank-row--default td:first-child { box-shadow: none; }
}

/* print: the report on paper, no menu, no buttons, the table (never the phone cards) */
@media print {
  /* Paper is white whatever the screen theme: re-declare the light colour tokens with selectors as
   * specific as the dark ones in tokens.css (this file comes after it, so these win). */
  :root, :root[data-theme], :root:not([data-theme="light"]) {
    color-scheme: light;
    --color-paper: oklch(97.6% 0.011 88);
    --color-paper-2: oklch(96.5% 0.02 160);
    --color-paper-3: oklch(93% 0.036 160);
    --color-surface: oklch(99.6% 0.004 88);
    --color-ink: oklch(21% 0.025 170);
    --color-ink-2: oklch(31% 0.02 170);
    --color-muted: oklch(47% 0.024 165);
    --color-rule: oklch(86.5% 0.022 140);
    --color-rule-strong: oklch(70% 0.024 165);
    --color-accent: oklch(50% 0.13 160);
    --color-accent-deep: oklch(42% 0.11 162);
    --color-accent-soft: oklch(91% 0.06 160);
    --color-accent-ink: oklch(99% 0.006 160);
    --color-focus: oklch(45% 0.14 160);
    --color-error: oklch(50% 0.18 27);
    --color-error-soft: oklch(95% 0.03 27);
    --color-success: oklch(46% 0.12 150);
    --color-water: oklch(58% 0.13 240);
    --color-water-deep: oklch(45% 0.12 245);
    --color-water-soft: oklch(94.5% 0.03 235);
    --color-elec: oklch(64% 0.14 25);
    --color-elec-deep: oklch(49% 0.15 25);
    --color-elec-soft: oklch(95% 0.028 22);
    --glint: oklch(100% 0 0);
  }
  /* keep the total column's tint on paper (it is also bold, so it reads without it) */
  .report-table__total { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .topbar, .skip-link, .toasts, .report-actions, .report-period .meter-period__step, .report-scope { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .main { padding: 0 !important; max-width: none; }
  .report-body { max-width: none; gap: 14pt; }
  .report-period { border: 0; padding: 0; background: none; max-width: none; }
  .report-period .meter-period__label { text-align: left; }
  /* an A4 page is narrower than 768px, so the phone rules apply on paper: undo the ones that matter */
  .stats.stats--four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stats.stats--four .stat--lead { grid-column: auto; }
  .stat, .report-table, .report-out { box-shadow: none; }
  .report-table { display: table !important; }
  .report-cards { display: none !important; }
  .report-table tr, .report-out tr { break-inside: avoid; }
  .report-section { break-inside: auto; }
  .report-table tbody th, .report-table tbody td, .report-out td { padding-block: 2pt; }
  a { text-decoration: none; }
  .bill-row__link .icon { display: none; }
}

/* ---- login --------------------------------------------------------------- */
.login { display: grid; align-content: start; gap: var(--space-xl); width: min(440px, 100%); margin-inline: auto; padding: var(--space-lg) var(--gutter) var(--space-2xl); min-height: 100dvh; }
.login__top { display: flex; align-items: center; justify-content: space-between; }
.login__card {
  display: grid; gap: var(--space-xs); padding: var(--space-xl) var(--space-lg);
  border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
  background: var(--color-surface); color: var(--color-ink); box-shadow: var(--shadow-card);
  margin-top: var(--space-xl);
}
.login__title { font-size: var(--text-2xl); }
.login__lead { color: var(--color-muted); margin-bottom: var(--space-md); }
.login .btn--block { margin-top: var(--space-xs); min-height: 44px; }

/* ---- under 60rem: the account shows as its icon only ---------------------- */
@media (max-width: 60rem) {
  .account__name, .account__button > .icon { display: none; }
  .account__button { padding: 0 var(--space-2xs); }
}

/* ---- six menu items on narrower desktops and tablets ------------------------ */
/* 64–75rem: labels only, so the six items fit beside the selector and account */
@media (min-width: 64.01rem) and (max-width: 75rem) {
  .mainnav__link > .icon { display: none; }
}
/* 48–64rem: the menu takes its own row under the wordmark, selector and account */
@media (min-width: 48rem) and (max-width: 64rem) {
  .topbar__inner { flex-wrap: wrap; row-gap: 0; }
  .mainnav { order: 3; flex: 1 0 100%; margin: 0 0 var(--space-xs); justify-content: space-between; }
  .mainnav__link { padding: 0 var(--space-xs); }
  .mainnav__link[aria-current="page"]::after { bottom: -8px; }
  html { scroll-padding-top: calc(var(--topbar-h) + var(--hit) + var(--space-lg)); }
  .settings__panel { scroll-margin-top: calc(var(--topbar-h) + var(--hit) + var(--space-lg)); }
  /* meter table: the two-row top bar has no fixed height, so the header does not stick here */
  .meter-table thead th { position: static; }
}

/* ---- under 768px: the menu becomes a bottom bar -------------------------- */
@media (max-width: 47.99rem) {
  /* backdrop-filter would make the topbar the containing block of the fixed bottom bar */
  .topbar { backdrop-filter: none; background: var(--color-paper); }
  .topbar__inner { gap: var(--space-xs); }
  .wordmark { font-size: var(--text-md); }
  .dorm-picker { flex: 1 1 auto; min-width: 0; }

  .mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky);
    margin: 0; gap: 0; padding: 0 0 env(safe-area-inset-bottom);
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    background: var(--color-surface); border-top: var(--rule-hair) solid var(--color-rule);
  }
  /* four items in the bar; the rest live in the "เพิ่มเติม" sheet */
  .mainnav__link--extra { display: none; }
  .morenav { display: grid; min-width: 0; }
  .mainnav__more[aria-expanded="true"] { background: var(--color-paper-3); color: var(--color-ink); }
  .mainnav__more[data-current] { background: var(--color-accent-soft); color: var(--color-accent-deep); font-weight: 700; }
  .mainnav__more[data-current]::after {
    content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px;
    border-radius: 0 0 3px 3px; background: var(--color-accent);
  }
  .mainnav__label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .mainnav__link {
    flex-direction: column; justify-content: center; gap: var(--space-3xs);
    min-height: var(--bottomnav-h); padding: var(--space-2xs); border-radius: 0;
    font-size: var(--text-xs);
  }
  .mainnav__link .icon { width: 22px; height: 22px; }
  .mainnav__link[aria-current="page"] { background: var(--color-accent-soft); }
  .mainnav__link[aria-current="page"]::after { top: 0; bottom: auto; left: 25%; right: 25%; border-radius: 0 0 3px 3px; }

  .main { padding-top: var(--space-lg); padding-bottom: calc(var(--bottomnav-h) + var(--space-xl) + env(safe-area-inset-bottom)); }
  .page-title { font-size: var(--text-xl); }
  .toasts { bottom: calc(var(--bottomnav-h) + var(--space-sm) + env(safe-area-inset-bottom)); }
  .panel { padding: var(--space-md); }
  .facts__row { grid-template-columns: minmax(0, 1fr); gap: 0; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat--lead { grid-column: 1 / -1; }
  .stat { padding: var(--space-sm) var(--space-md); }
  .room-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-xs); }
  .toolbar__search { flex-basis: 100%; }
  .toolbar__filter { flex: 1 1 auto; }
  .room-row {
    grid-template-columns: minmax(0, 1fr) auto 18px;
    grid-template-areas: "num status go" "tenant tenant go" "badges badges go";
    gap: var(--space-2xs) var(--space-sm); padding: var(--space-sm) var(--space-md);
  }
  .room-row__number { grid-area: num; }
  .room-row__type { display: none; }
  .room-row__status { grid-area: status; }
  .room-row__tenant { grid-area: tenant; font-size: var(--text-sm); }
  .room-row > .badges { grid-area: badges; }
  .room-row > .icon { grid-area: go; }

  /* tenant register: each row becomes a card (name on top, labelled facts under it) */
  .tenant-table, .tenant-table tbody, .tenant-table tr, .tenant-table td { display: block; width: auto; }
  .tenant-table { border: 0; background: transparent; overflow: visible; }
  .tenant-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .tenant-table tbody { display: grid; gap: var(--space-xs); }
  .tenant-table .tenant-row {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-2xs) var(--space-sm);
    padding: var(--space-sm) var(--space-md); border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
    background: var(--color-surface); box-shadow: 0 1px 0 var(--color-rule);
  }
  .tenant-row--overdue { border-left: 3px solid var(--color-error); }
  .tenant-row--overdue td:first-child { box-shadow: none; }
  .tenant-row:hover td { background: transparent; }
  .tenant-table td { padding: 0; border: 0; }
  .tenant-table .num { text-align: left; }
  .tenant-row__name { grid-column: 1 / -1; font-size: var(--text-md); }
  .tenant-row__nick { display: inline; margin-left: var(--space-2xs); }
  .tenant-row td[data-label]::before { content: attr(data-label); display: block; font-size: var(--text-xs); color: var(--color-muted); }
  .notice { flex-wrap: wrap; }

  /* settings tables: each row becomes a card (title on top, labelled facts, actions last) */
  .settings-table, .settings-table tbody, .settings-table tr, .settings-table td { display: block; width: auto; }
  .settings-table { border: 0; background: transparent; overflow: visible; }
  .settings-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .settings-table tbody { display: grid; gap: var(--space-xs); }
  .settings-table .settings-row {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-2xs) var(--space-sm);
    padding: var(--space-sm) var(--space-md); border: var(--rule-hair) solid var(--color-rule); border-radius: var(--radius-card);
    background: var(--color-surface); box-shadow: 0 1px 0 var(--color-rule);
  }
  .settings-row:hover td { background: transparent; }
  .settings-table td { padding: 0; border: 0; }
  .settings-table .num { text-align: left; }
  .settings-table td.settings-row__main { grid-column: 1 / -1; }
  .settings-table td.settings-row__actions { grid-column: 1 / -1; text-align: left; padding-top: var(--space-2xs); }
  .settings-row__actions > .btn { margin: 0 var(--space-2xs) 0 0; }
  .settings-row td[data-label]::before { content: attr(data-label); display: block; font-size: var(--text-xs); color: var(--color-muted); }
  .dorm-choice { grid-template-columns: minmax(0, 1fr) 18px; grid-template-areas: "name go" "meta go" "badge go"; }
  .dorm-choice > .status, .dorm-choice > .badge { justify-self: start; margin-top: var(--space-2xs); }
}

/* ---- phones: the four room tabs sit in two rows so none hides off-screen -- */
@media (max-width: 40rem) {
  .tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; overflow: visible; }
  .tabs__tab { padding: 0 var(--space-xs); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
}

@media (pointer: coarse) {
  :root { --control-h: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
