:root {
  --c-urgent:    #dc2626;
  --c-urgent-bg: #fee2e2;
  --c-warn:      #d97706;
  --c-warn-bg:   #fef3c7;
  --c-ok:        #16a34a;
  --c-ok-bg:     #dcfce7;
  --c-accent:    #0369a1; /* sky-700 — used for address to anchor the eye */
  --c-bg:        #f8fafc;
  --c-card:      #ffffff;
  --c-text:      #0f172a;
  --c-muted:     #475569;
  --c-border:    #e2e8f0;
}

* {
  box-sizing: border-box;
  /* Disable double-tap-to-zoom across the app. Pinch-zoom is still allowed
     by the browser so accessibility users keep their option to enlarge text. */
  touch-action: manipulation;
}
html, body {
  margin: 0; padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 14px;
  padding-bottom: 60px;
}

/* ===== Header (3 fixed rows: title+tools / date-nav / status) ===== */
.header-top {
  display: flex; align-items: center; gap: 8px;
  position: sticky; top: 0; z-index: 100;
  background: var(--c-bg);
  /* cancel #app's 14px gutter so the bar bg spans edge-to-edge when pinned */
  margin: 0 -14px 10px; padding: 8px 14px;
  border-bottom: 1px solid var(--c-border);
}
/* index.html title lives in .header-top (sticky); report.html title stays in .header */
.header-top h1, .header h1 {
  font-size: 22px; font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
  flex: 1; min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-tools {
  display: flex; gap: 6px;
  flex-shrink: 0;
}

#btnRefresh, #btnMenu {
  min-width: 40px; min-height: 40px;
  border: 1px solid var(--c-border); border-radius: 10px;
  background: var(--c-card); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 10px;
  text-decoration: none; color: inherit;
  transition: background 120ms ease, transform 80ms ease;
}
#btnRefresh:active, #btnMenu:active { background: var(--c-bg); transform: scale(0.96); }
#btnRefresh .icon, #btnMenu .icon {
  display: inline-block;
  font-size: 20px; line-height: 1;
  font-weight: 700;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
#btnRefresh.spinning .icon {
  animation: spin 0.8s linear infinite;
}

.header-date {
  display: flex; align-items: center; gap: 6px;
  margin: 0 0 8px;
}
.date-nav-btn {
  min-width: 36px; min-height: 36px;
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-card);
  color: var(--c-text);
  font-size: 22px; line-height: 1; font-weight: 700;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.date-nav-btn:active { background: var(--c-bg); transform: scale(0.95); }
.date-nav-btn:disabled {
  opacity: 0.3; cursor: not-allowed;
}
.date-nav-btn.hidden { display: none; }
.date-nav-label {
  flex: 1;
  text-align: center;
  color: var(--c-text);
  font-size: 17px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.date-nav-today {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--c-accent);
  border-radius: 999px;
  background: var(--c-card);
  color: var(--c-accent);
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.date-nav-today.hidden { display: none; }
.date-nav-today:active { background: var(--c-bg); }

.header-status {
  display: flex; align-items: center; gap: 8px;
  color: var(--c-muted);
  font-size: 13px; font-weight: 500;
  font-variant-numeric: tabular-nums;
  min-height: 22px;
}
.sep { opacity: 0.5; }
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
#btnRefresh.spinning .icon {
  animation: spin 0.8s linear infinite;
}

/* Badge (unseen-changes count) — now rides on the ☰ menu button */
.badge {
  display: inline-block; min-width: 22px; height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--c-urgent); color: white;
  font-size: 13px; font-weight: 700; line-height: 22px; text-align: center;
}
.badge.hidden { display: none; }
.hidden { display: none; }

/* ===== Menu button (☰) carries the unseen-changes badge ===== */
#btnMenu { position: relative; }
#btnMenu .badge {
  position: absolute;
  top: -6px; right: -6px;
  pointer-events: none;
}

/* ===== Right drawer nav (Thay đổi / Thiết lập / Báo cáo overlay) ===== */
.drawer-backdrop {
  position: fixed; inset: 0;
  z-index: 900;
  background: rgba(15, 23, 42, 0.55);
}
.drawer-backdrop.hidden { display: none; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 901;
  width: min(85%, 420px);
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.2);
  transform: translateX(100%);
  transition: transform 220ms ease;
}
.drawer.open { transform: none; }
.drawer.hidden { display: none; }
@media (max-width: 360px) {
  .drawer { width: 100%; }
}
body.drawer-open { overflow: hidden; }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--c-border);
}
.drawer-cleaner {
  font-size: 16px; font-weight: 700;
  color: var(--c-text);
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.drawer-cleaner::before { content: '👤 '; }
.drawer-close {
  min-width: 40px; min-height: 40px;
  border: 1px solid var(--c-border); border-radius: 10px;
  background: var(--c-card); color: var(--c-text);
  font-size: 18px; font-weight: 700; line-height: 1;
  cursor: pointer; flex-shrink: 0;
}
.drawer-close:active { background: var(--c-bg); transform: scale(0.96); }

.segmented {
  display: flex; gap: 6px;
  padding: 12px 14px;
}
.segmented button {
  flex: 1; min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--c-border); border-radius: 10px;
  background: var(--c-card); color: var(--c-text);
  font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.segmented button.active {
  background: var(--c-text); color: var(--c-bg);
  border-color: var(--c-text);
}
.segmented button:disabled { opacity: 0.4; cursor: not-allowed; }

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 14px 14px;
}
.drawer-body.frame-mode { padding: 0; overflow: hidden; }

#panel-bao-cao { height: 100%; }
.report-frame { width: 100%; height: 100%; border: 0; display: block; }

/* Summary chips — sit on a single row on phones; wrap only if a 4th appears. */
.summary {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 4px 0 12px;
}
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  background: var(--c-card); border: 1px solid var(--c-border);
  white-space: nowrap;
}
.chip b { font-weight: 800; }
.chip.urgent { background: var(--c-urgent-bg); color: var(--c-urgent); border-color: transparent; }
.chip.warn   { background: var(--c-warn-bg);   color: var(--c-warn);   border-color: transparent; }
.chip.ok     { background: var(--c-ok-bg);     color: var(--c-ok);     border-color: transparent; }

/* Hourly group header above its cluster of cards */
.slot-head {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-muted);
}
.slot-head:first-of-type { margin-top: 6px; }

/* Task card — fixed two-row layout. Severity shows only via the left border
   color and the trailing pill. No row tints, no flex-wrap surprises. */
.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-left: 6px solid var(--c-border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}
.card.sev-urgent { border-left-color: var(--c-urgent); }
.card.sev-warn   { border-left-color: var(--c-warn); }
.card.sev-ok     { border-left-color: var(--c-ok); }
.card.vacant     { border-left-color: var(--c-border); background: #fafafa; }

.card-line { display: flex; align-items: baseline; gap: 10px; }
.card-line.bottom { justify-content: flex-end; align-items: center; }

/* Row 1: <outAt> | <addr> <roomNum> */
.t-out {
  font-size: 22px; font-weight: 800;
  color: var(--c-text);
  line-height: 1.1;
}
.t-sep { color: var(--c-muted); opacity: 0.4; font-weight: 600; }
.t-addr {
  font-size: 20px; font-weight: 700;
  color: var(--c-accent);
  letter-spacing: 0.01em;
  line-height: 1.1;
}
.t-room {
  font-size: 20px; font-weight: 800;
  color: var(--c-text);
  line-height: 1.1;
}

/* Row 2: → Vào tiếp <inAt> [pill] (right-aligned) */
.t-arrow {
  color: var(--c-muted);
  font-weight: 700;
  font-size: 16px;
}
.t-in-label {
  color: var(--c-muted);
  font-size: 14px;
  font-weight: 600;
}
.t-in {
  font-size: 18px; font-weight: 700;
  color: var(--c-text);
  line-height: 1.1;
}

.day-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  background: var(--c-warn-bg);
  color: var(--c-warn);
  vertical-align: 2px;
}

.pill {
  flex-shrink: 0;
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 15px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pill.urgent { background: var(--c-urgent-bg); color: var(--c-urgent); }
.pill.warn   { background: var(--c-warn-bg);   color: var(--c-warn); }
.pill.ok     { background: #f1f5f9;            color: #94a3b8; }
.pill.vacant { background: #f1f5f9; color: var(--c-muted); }

/* Changelog day groups (Hôm nay / past dates) */
.change-group { margin-bottom: 14px; }
.change-group-head {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-card);
  color: var(--c-text);
  font-size: 16px; font-weight: 700;
  cursor: pointer; text-align: left;
}
.change-group-head:active { background: var(--c-bg); }
.cg-caret {
  display: inline-block;
  transition: transform 160ms ease;
  color: var(--c-muted);
  font-size: 14px;
}
.change-group.collapsed .cg-caret { transform: rotate(-90deg); }
.change-group-body {
  margin-top: 8px;
  overflow: hidden;
}
.change-group.collapsed .change-group-body { display: none; }

/* Changelog entry */
.change {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.change-head {
  font-size: 14px; color: var(--c-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.change-body { margin-top: 4px; font-size: 16px; }
.change.urgent     { border-left-color: var(--c-urgent); }
.change.warn       { border-left-color: var(--c-warn); }
.change.ok         { border-left-color: var(--c-ok); }
/* Cleaner-centric change types */
.change.new         { border-left-color: var(--c-ok); }
.change.urgent_up   { border-left-color: var(--c-urgent); }
.change.out_changed { border-left-color: var(--c-warn); }
.change.cancelled   { border-left-color: var(--c-border); opacity: 0.55; }

/* Empty + footer */
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--c-muted);
  font-size: 16px;
}
.footer {
  text-align: center;
  font-size: 12px;
  color: var(--c-muted);
  margin-top: 20px;
  min-height: 18px;
}

/* Inline cleaner identity badge inside .header-status */
.cleaner-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  font-size: 13px; font-weight: 600;
  color: var(--c-text);
}
.cleaner-badge.hidden { display: none; }
.cleaner-badge::before {
  content: '👤';
  font-size: 12px;
}

/* "Đổi cleaner" footer link — low-prominence per UX (rarely used) */
.footer-link {
  display: inline-block;
  margin-left: 8px;
  background: transparent;
  border: 0;
  color: var(--c-muted);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 6px;
}
.footer-link:active { color: var(--c-text); }

/* Tới hiện tại button (manual scroll trigger) — inline pill in the summary row */
.scroll-now {
  margin-left: auto;            /* push to the right edge of the flex row */
  padding: 5px 12px;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  background: var(--c-card);
  font-size: 13px; font-weight: 600;
  color: var(--c-accent);
  cursor: pointer;
  min-height: 32px;
  white-space: nowrap;
}
.scroll-now:active { background: var(--c-bg); }

/* Scroll-to-top FAB (fixed bottom-right, revealed past one viewport) */
.scroll-top {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  width: 48px; height: 48px;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  background: var(--c-card);
  color: var(--c-text);
  font-size: 22px; font-weight: 700; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.scroll-top:active { transform: scale(0.94); background: var(--c-bg); }
/* Beats .scroll-top's own display:flex — global .hidden ties on specificity and
   loses on source order, so the toggle needs this 2-class rule (cf. .badge.hidden). */
.scroll-top.hidden { display: none; }
body.drawer-open .scroll-top { display: none; }

/* Done state for cards (overrides past dim with stronger opacity) */
.pill.done {
  background: #dcfce7;
  color: #16a34a;
  border: 1px solid #86efac;
}
.card.done {
  background: #f0fdf4;
  opacity: 0.85;
}
.card.done .t-out,
.card.done .t-room,
.card.done .t-addr,
.card.done .t-in {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--c-muted);
}

/* Past dim (Google Calendar-style) */
.card.past { opacity: 0.5; }
.card.done.past { opacity: 0.85; }  /* done overrides past */

/* All schedule cards are tappable (mark/undo). */
.card { cursor: pointer; }
.card:active { transform: scale(0.99); }

/* Modal */
.modal {
  position: fixed; inset: 0;
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.55);
}
.modal-content {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--c-card);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.modal-title {
  margin: 0 0 10px;
  font-size: 20px; font-weight: 800;
}
.modal-hint {
  margin: 0 0 12px;
  color: var(--c-muted);
  font-size: 15px;
}
.modal-body p { margin: 4px 0 12px; font-size: 17px; line-height: 1.4; }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 16px;
}
.modal-btn {
  min-height: 48px; padding: 0 18px;
  border-radius: 10px;
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text);
}
.modal-btn.btn-primary {
  background: var(--c-ok);
  color: white;
  border-color: var(--c-ok);
}
.modal-btn.btn-secondary {
  background: var(--c-card);
}
.modal-btn.btn-danger {
  background: var(--c-urgent);
  color: white;
  border-color: var(--c-urgent);
}
.modal-btn:active { transform: scale(0.97); }

/* Identity buttons inside modal */
.identity-btn {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  margin-bottom: 8px;
  border-radius: 12px;
  border: 1px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text);
  font-size: 18px; font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.identity-btn:active { background: var(--c-bg); transform: scale(0.99); }

/* ===== Báo cáo page ===== */
.back-link {
  color: var(--c-accent);
  text-decoration: none;
  font-weight: 600;
  min-height: 36px;
  display: inline-flex; align-items: center;
}
.back-link:active { opacity: 0.7; }

.report-filters {
  display: flex; flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin: 12px 0 16px;
}
.report-field {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 14px; font-weight: 600;
  color: var(--c-muted);
  flex: 1; min-width: 130px;
}
.report-field input[type="date"] {
  min-height: 44px;
  padding: 0 12px;
  font-size: 16px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-card);
  color: var(--c-text);
  font-variant-numeric: tabular-nums;
}
#btnLoad {
  min-height: 44px; padding: 0 22px;
  border: 1px solid var(--c-text);
  border-radius: 10px;
  background: var(--c-text); color: var(--c-bg);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
}
#btnLoad:active { opacity: 0.85; transform: scale(0.98); }

.report-summary-banner {
  padding: 14px 16px;
  margin: 0 0 14px;
  background: var(--c-ok-bg);
  color: var(--c-ok);
  border-radius: 12px;
  font-size: 17px; font-weight: 600;
}
.report-summary-banner b { font-weight: 800; font-size: 22px; }
.report-summary-empty {
  padding: 30px 16px;
  text-align: center;
  color: var(--c-muted);
}

.report-day {
  margin-bottom: 14px;
}
.report-day-head {
  margin: 0 0 8px;
  font-size: 17px; font-weight: 700;
  color: var(--c-text);
  padding: 8px 12px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 10px;
}
.report-day-head b { font-weight: 800; color: var(--c-accent); }
.report-item-list {
  list-style: none;
  margin: 0; padding: 0;
}
.report-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--c-card);
  border-left: 4px solid var(--c-ok);
  border-radius: 8px;
  margin-bottom: 4px;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.report-item-room { font-weight: 700; flex: 1; min-width: 0; }
.report-item-sep { color: var(--c-muted); }
.report-item-time { color: var(--c-muted); }

/* ---- Settings Tab ---- */
.settings-section {
  padding: 1rem;
  border-bottom: 1px solid var(--c-border);
}
.settings-section:last-child { border-bottom: none; }
.settings-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-muted);
  margin: 0 0 0.75rem;
}
.settings-cleaner-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.settings-cleaner-name { font-weight: 600; font-size: 1rem; }
.settings-change-btn {
  font-size: 0.85rem;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: var(--c-card);
  cursor: pointer;
  color: var(--c-text);
}
.settings-change-btn:active { opacity: 0.7; }
.address-list { display: flex; flex-direction: column; gap: 0.6rem; }
.address-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
}
.address-item input[type="checkbox"] { width: 1.1rem; height: 1.1rem; cursor: pointer; flex-shrink: 0; }
.settings-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
}
.settings-toggle-row input[type="checkbox"] { width: 1.1rem; height: 1.1rem; cursor: pointer; flex-shrink: 0; }
.settings-empty { color: var(--c-muted); font-size: 0.9rem; margin: 0; }
.settings-field-row {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 0.95rem; font-weight: 600;
}
.settings-field-row input[type="date"] {
  min-height: 44px; padding: 0 12px;
  font-size: 16px;
  border: 1px solid var(--c-border); border-radius: 10px;
  background: var(--c-card); color: var(--c-text);
  font-variant-numeric: tabular-nums;
}
.settings-hint { color: var(--c-muted); font-size: 0.85rem; margin: 6px 0 0; }
