/* ===== Tokens ===== */
:root {
    --bg: #f5f7f6;
    --surface: #ffffff;
    --surface-2: #f8faf9;
    --surface-3: #eef2f0;
    --text: #14201c;
    --text-2: #4b5a55;
    --muted: #5e6c67;
    --line: #e2e8e5;
    --line-strong: #cfd8d4;

    --primary: #0f766e;
    --primary-hover: #0b5f58;
    --primary-soft: #e6f4f2;
    --primary-ink: #0b4f49;

    --amber: #a16207;
    --amber-soft: #fef6e4;
    --blue: #1d4ed8;
    --blue-soft: #eaf0fd;
    --red: #b42318;
    --red-soft: #fdecea;
    --electric: #ca8a04;
    --water: #0284c7;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(20, 32, 28, 0.05);
    --shadow: 0 1px 2px rgba(20, 32, 28, 0.04), 0 6px 20px rgba(20, 32, 28, 0.06);
    --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 var(--font);
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 28px; line-height: 1.2; font-weight: 700; }
h2 { font-size: 16px; line-height: 1.3; font-weight: 650; display: flex; align-items: center; gap: 8px; }
code { font-family: Consolas, monospace; font-size: 0.9em; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
.icon { flex-shrink: 0; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 13px; margin: 0; }
.text-strong { color: var(--text); }
.warn-text { color: var(--amber); }

/* ===== Sidebar ===== */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 18px 14px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 22px;
    overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--primary); color: #fff;
    display: grid; place-items: center;
}
.brand-text strong { display: block; font-size: 16px; }
.brand-text small { display: block; color: var(--muted); font-size: 12.5px; }

.nav { display: grid; gap: 18px; }
.nav-group { display: grid; gap: 2px; }
.nav-group-label {
    padding: 0 10px 6px;
    font-size: 11.5px; font-weight: 650; letter-spacing: 0.06em;
    text-transform: uppercase; color: var(--muted);
}
.nav-link {
    display: flex; align-items: center; gap: 11px;
    min-height: 40px; padding: 0 10px;
    border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 550;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 650; }
.nav-link.active .icon { color: var(--primary); }

.sidebar-foot { margin-top: auto; display: grid; gap: 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.sidebar-foot .muted { padding: 0 10px; }
.nav-button { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; }

/* Trang đăng nhập / offline */
body.standalone { display: block; }
.auth-wrap {
    min-height: 100vh; display: grid; align-content: center; justify-items: center; gap: 20px;
    padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.auth-card { width: min(400px, 100%); }
.auth-card h1 { font-size: 22px; }

/* Cổng khách thuê */
.portal-bar {
    position: sticky; top: 0; z-index: 10;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: var(--surface); border-bottom: 1px solid var(--line);
}
.portal-bar .brand { padding: 0; max-width: 640px; margin: 0 auto; }
.portal { max-width: 640px; margin: 0 auto; padding: 20px 16px calc(32px + env(safe-area-inset-bottom)); display: grid; gap: 18px; }
.portal .section { margin: 0; }
.portal-hello { font-size: 24px; }
.portal-due { display: grid; text-decoration: none; }
.portal-bills { padding: 0; overflow: hidden; }
.portal-bill-row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto 16px; gap: 12px; align-items: center;
    padding: 14px 16px; border-top: 1px solid var(--line); color: var(--text);
}
.portal-bill-row:first-child { border-top: 0; }
.portal-bill-row:active { background: var(--surface-2); }
.portal-bill-row > .icon { color: var(--muted); }
.portal-bill-month, .portal-bill-amount { display: grid; gap: 2px; }
.portal-bill-month small { display: flex; align-items: center; gap: 4px; font-size: 12.5px; }
.portal-bill-amount { justify-items: end; font-variant-numeric: tabular-nums; }
.portal-hint { margin: 0; }
.portal-foot { text-align: center; }
.portal-contact .card-body { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.portal-contact-actions { display: flex; gap: 8px; }
.portal .invoice-head strong { font-size: 20px; }
.install-tip > summary { padding: 14px 16px; list-style: none; cursor: pointer; }
.install-tip > summary::-webkit-details-marker { display: none; }
.install-tip p { margin: 0 0 8px; }

.mobile-total { display: none; }

.badge {
    display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: auto;
    border-radius: 99px; background: var(--blue); color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
}
.tab .tab-icon { position: relative; display: inline-grid; overflow: visible; max-width: none; }
.tab-icon .badge { position: absolute; top: -5px; right: -11px; margin: 0; border: 2px solid var(--surface); height: 20px; }

.offline-banner {
    position: sticky; top: 0; z-index: 50; padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
    background: var(--amber-soft); color: var(--amber); border-bottom: 1px solid #f4dfae;
    font-size: 13.5px; font-weight: 600; text-align: center; grid-column: 1 / -1;
}

/* Nội dung theo loại thiết bị: chuột (máy tính) / cảm ứng (điện thoại) */
html body .only-touch { display: none; }
@media (pointer: coarse) {
    html body .only-touch { display: grid; }
    html body .only-desktop { display: none; }
}

/* Trang cài lên điện thoại */
.install-grid { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.install-qr { justify-items: center; text-align: center; }
.install-qr img { border-radius: var(--radius-sm); border: 1px solid var(--line); background: #fff; }
.install-url { word-break: break-all; }
.install-steps { margin: 0; padding-left: 20px; display: grid; gap: 10px; }
.install-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.install-checks li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); }
.install-checks li span { display: grid; gap: 2px; }
.install-checks li small { color: var(--text-2); }
.install-checks .ok { background: var(--primary-soft); color: var(--primary-ink); }
.install-checks .todo { background: var(--amber-soft); color: var(--amber); }
@media (max-width: 860px) { .install-grid { grid-template-columns: 1fr; } }

/* Chỉ hiện trên điện thoại */
.appbar, .tabbar, .menu-backdrop { display: none; }

/* ===== Page ===== */
.page { padding: 28px 32px 48px; max-width: 1240px; width: 100%; }

.page-header {
    display: flex; justify-content: space-between; align-items: flex-end;
    gap: 16px 24px; flex-wrap: wrap;
    margin-bottom: 22px;
}
.eyebrow {
    margin: 0 0 4px;
    color: var(--primary); font-size: 12.5px; font-weight: 650;
    text-transform: uppercase; letter-spacing: 0.06em;
}
.back-link {
    display: inline-flex; align-items: center; gap: 6px;
    margin-bottom: 12px; color: var(--muted); font-weight: 550; font-size: 14px;
}
.back-link:hover { color: var(--text); }

.section { margin-bottom: 24px; }
.section-head {
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.link { color: var(--primary); font-weight: 600; display: inline-flex; align-items: center; gap: 2px; font-size: 14px; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.count {
    display: inline-grid; place-items: center; min-width: 24px; height: 22px; padding: 0 7px;
    border-radius: 999px; background: var(--surface-3); color: var(--text-2);
    font-size: 12.5px; font-weight: 650;
}
.stack { display: grid; gap: 10px; }

/* ===== Buttons ===== */
.btn, button {
    font: inherit;
}
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 40px; padding: 0 16px;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    font-weight: 600; font-size: 14.5px; white-space: nowrap;
    cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger-ghost { background: var(--surface); color: var(--red); border-color: #f2c3be; }
.btn-danger-ghost:hover { background: var(--red-soft); }
.btn-sm { min-height: 32px; padding: 0 11px; font-size: 13.5px; }
.btn-lg { min-height: 46px; padding: 0 22px; font-size: 15.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
    width: 38px; height: 38px; display: grid; place-items: center;
    border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
    background: var(--surface); color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

:focus-visible { outline: 3px solid rgba(15, 118, 110, 0.3); outline-offset: 2px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar form { margin: 0; }

/* ===== Month nav ===== */
.month-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.month-nav-picker { display: flex; gap: 6px; margin: 0; }
.month-nav-picker select { width: auto; min-width: 118px; font-weight: 600; }
.month-nav-picker input { width: 88px; font-weight: 600; }
.month-nav-label { min-width: 70px; text-align: center; font-weight: 700; font-size: 17px; }

/* ===== Forms ===== */
input, select, textarea {
    width: 100%;
    font: inherit; color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input, select { min-height: 40px; padding: 0 11px; }
textarea { padding: 9px 11px; resize: vertical; }
input[type="file"] { padding: 7px 10px; }
input:hover, select:hover, textarea:hover { border-color: #b8c4bf; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}
input::placeholder, textarea::placeholder { color: #a3aeaa; }

.field { display: grid; gap: 5px; align-content: start; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-hint { min-height: 17px; font-size: 12.5px; color: var(--muted); }
.field-hint.is-error { color: var(--red); font-weight: 600; }
.field.grow { flex: 1; }
.span-full { grid-column: 1 / -1; }

.form-stack { display: grid; gap: 16px; }
.form-grid-2, .form-grid-3, .form-grid-4 { display: grid; gap: 12px 14px; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px 14px; margin: 0; display: grid; gap: 10px; }
.fieldset legend { padding: 0 6px; font-weight: 650; font-size: 14px; }

.check { display: flex; align-items: center; gap: 10px; font-weight: 550; cursor: pointer; }
.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card.narrow { max-width: 820px; }
.card-head {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.card-head .muted { display: block; font-size: 13.5px; margin-top: 2px; }
.card-head-wrap { flex-wrap: wrap; }
.card-body { padding: 18px 20px; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px; display: grid; gap: 6px; box-shadow: var(--shadow-sm);
}
.stat-label { display: flex; align-items: center; gap: 7px; color: var(--text-2); font-size: 13.5px; font-weight: 600; }
.stat-label .icon { color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 15px; color: var(--muted); font-weight: 550; margin-left: 2px; }
.stat-sub { font-size: 13px; color: var(--muted); }
.stat-accent { background: linear-gradient(135deg, #0f766e, #115e59); border-color: transparent; color: #fff; }
.stat-accent .stat-label, .stat-accent .stat-label .icon, .stat-accent .stat-sub { color: rgba(255, 255, 255, 0.8); }

.progress { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin-top: 4px; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }

/* ===== Callouts & flash ===== */
.callout {
    display: flex; align-items: center; gap: 14px;
    padding: 13px 16px; margin-bottom: 16px;
    border-radius: var(--radius); border: 1px solid;
}
.callout > div { flex: 1; display: grid; gap: 1px; }
.callout > div span { color: var(--text-2); font-size: 14px; }
.callout > .icon { width: 20px; height: 20px; }
.callout-warn { background: var(--amber-soft); border-color: #f4dfae; }
.callout-warn > .icon { color: var(--amber); }
.callout-ok { background: var(--primary-soft); border-color: #bfe2dc; }
.callout-ok > .icon { color: var(--primary); }
.callout-info { background: var(--blue-soft); border-color: #cbd9f7; }
.callout-info > .icon { color: var(--blue); }

.flash-stack { display: grid; gap: 8px; margin-bottom: 18px; }
.flash {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 12px 11px 14px; border-radius: var(--radius-sm);
    background: var(--surface); border: 1px solid var(--line); border-left-width: 4px;
    box-shadow: var(--shadow); animation: flash-in 0.25s ease-out;
}
.flash span { flex: 1; }
.flash-success { border-left-color: var(--primary); }
.flash-success > .icon { color: var(--primary); }
.flash-error { border-left-color: var(--red); background: #fffafa; }
.flash-error > .icon { color: var(--red); }
.flash-close { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; display: grid; }
.flash-close:hover { background: var(--surface-3); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-4px); } }

/* ===== Pills ===== */
.pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 12.5px; font-weight: 650; white-space: nowrap; height: fit-content;
    background: var(--surface-3); color: var(--text-2);
}
.pill-occupied { background: var(--primary-soft); color: var(--primary-ink); }
.pill-reserved { background: var(--amber-soft); color: var(--amber); }
.pill-maintenance, .pill-inactive { background: var(--red-soft); color: var(--red); }

/* ===== Dashboard room tiles ===== */
.room-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.room-tile {
    display: grid; gap: 6px; padding: 15px 16px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.room-tile:hover { border-color: var(--line-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.room-tile.is-pending { border-style: dashed; border-color: var(--line-strong); background: var(--surface-2); }
.room-tile.is-pending:hover { border-color: var(--primary); }
.room-tile-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.room-code { font-size: 20px; font-weight: 750; letter-spacing: -0.01em; }
.room-tenant { color: var(--text-2); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-amount { font-size: 18px; font-variant-numeric: tabular-nums; }
.room-amount.muted { color: var(--muted); font-weight: 600; }
.room-meta { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.room-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; margin: 0 3px; }
.room-meta.cta { color: var(--primary); font-weight: 600; }
.tick { display: inline-flex; align-items: center; gap: 4px; color: var(--primary); font-size: 12.5px; font-weight: 650; }

/* ===== Bill form ===== */
.room-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.room-chip {
    position: relative; display: grid; gap: 1px; padding: 10px 12px;
    background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    transition: border-color 0.15s, background 0.15s;
}
.room-chip strong { font-size: 16px; }
.room-chip span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-chip:hover { border-color: var(--line-strong); background: var(--surface-2); }
.room-chip.is-selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12); }
.chip-tick {
    position: absolute; top: 8px; right: 8px; width: 18px; height: 18px; border-radius: 50%;
    display: grid; place-items: center; background: var(--primary); color: #fff;
}

.bill-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
#bill-form { display: grid; gap: 16px; }
.meter {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px;
    padding: 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line);
}
.meter-title { grid-column: 1 / -1; display: flex; align-items: center; gap: 7px; font-weight: 650; margin-bottom: 4px; }
.meter-title small { margin-left: auto; color: var(--muted); font-weight: 550; font-size: 13px; }
.meter-electric .meter-title .icon { color: var(--electric); }
.meter-water .meter-title .icon { color: var(--water); }
.meter input { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; min-height: 44px; }

.receipt { position: sticky; top: 20px; }
.receipt-body, .invoice-lines { padding: 8px 20px 18px; display: grid; }
.receipt-line {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 10px 0; border-bottom: 1px dashed var(--line);
    font-variant-numeric: tabular-nums;
}
.receipt-line span { color: var(--text-2); }
.receipt-line em { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); }
.receipt-total {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding-top: 14px; font-weight: 650;
}
.receipt-total strong { font-size: 22px; color: var(--primary); font-variant-numeric: tabular-nums; }
.receipt-note { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); }

/* ===== Empty ===== */
.empty-card {
    display: grid; justify-items: center; gap: 8px; text-align: center;
    padding: 40px 20px; color: var(--muted);
    background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius);
}
.empty-card strong { color: var(--text-2); }
.empty-card.flat { border: 0; background: transparent; }

/* ===== Reports ===== */
.month-bars {
    display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px;
    padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.month-bar {
    display: grid; justify-items: center; gap: 5px; padding: 8px 2px;
    border-radius: var(--radius-sm); border: 1.5px solid transparent;
    transition: background 0.15s;
}
.month-bar:hover { background: var(--surface-2); }
.month-bar.is-selected { background: var(--primary-soft); border-color: var(--primary); }
.month-bar-label { font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.month-bar-track {
    width: 100%; max-width: 34px; height: 90px; border-radius: 6px; background: var(--surface-3);
    display: flex; align-items: flex-end; overflow: hidden;
}
.month-bar-track span { width: 100%; background: #5eb3a8; border-radius: 6px 6px 0 0; min-height: 0; }
.month-bar.is-selected .month-bar-track span { background: var(--primary); }
.month-bar strong { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.month-bar strong small { font-size: 11px; color: var(--muted); font-weight: 550; margin-left: 1px; }
.month-bar em { font-style: normal; font-size: 11.5px; color: var(--muted); }
.month-bar.is-empty strong { color: var(--muted); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 760px; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-2); }
.table .num { text-align: right; }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tfoot td { font-weight: 650; background: var(--surface-2); border-bottom: 0; }
.row-link { cursor: pointer; }
.cell-sub { display: block; font-size: 12.5px; color: var(--muted); }
.room-code-sm { font-size: 16px; }

/* ===== Invoice (bill detail) ===== */
.invoice {
    max-width: 920px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.invoice-head {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    padding: 20px 24px; background: linear-gradient(135deg, #0f766e, #115e59); color: #fff;
}
.invoice-head span { display: block; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.8; }
.invoice-head strong { font-size: 24px; }
.invoice-month { font-size: 22px; font-weight: 700; }
.invoice-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 8px; padding: 8px 4px 16px; }
.invoice-body.no-qr { grid-template-columns: 1fr; }
.invoice-month { display: grid; justify-items: end; gap: 6px; }
.invoice-head .paid-chip { display: inline-flex; text-transform: none; opacity: 1; white-space: nowrap; }
.paid-chip {
    display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 99px;
    background: #fff; color: var(--primary-ink); font-size: 12.5px; font-weight: 650; letter-spacing: 0;
}

/* Còn nợ các tháng trước */
.overdue { margin-bottom: 18px; border-color: #f4dfae; overflow: hidden; }
.overdue-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; background: var(--amber-soft); }
.overdue-head h2 { color: var(--amber); }
.overdue-head strong { color: var(--amber); font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.overdue-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 18px; border-top: 1px solid var(--line); }
.overdue-info { display: grid; gap: 1px; min-width: 0; }
.overdue-info span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overdue-amount { font-variant-numeric: tabular-nums; }
.overdue-row .paid-toggle.is-paid { opacity: 0.6; }
.overdue.reported { border-color: #cbd9f7; }
.overdue.reported .overdue-head { background: var(--blue-soft); }
.overdue.reported .overdue-head h2, .overdue.reported .overdue-head strong { color: var(--blue); }
@media (max-width: 560px) {
    .overdue-row { grid-template-columns: minmax(0, 1fr) auto; }
    .overdue-row .paid-toggle { grid-column: 1 / -1; }
    .overdue-row .paid-toggle, .overdue-row .paid-toggle form, .overdue-row .paid-btn { width: 100%; }
}

/* Trạng thái thu tiền */
.paid-toggle { display: inline-flex; }
.paid-btn { background: var(--amber-soft); color: var(--amber); border-color: #f4dfae; }
.paid-btn:hover { background: #fdeccb; }
.paid-toggle.is-paid .paid-btn { background: var(--primary-soft); color: var(--primary-ink); border-color: #bfe2dc; }
.paid-toggle .when-paid, .paid-toggle.is-paid .when-unpaid { display: none; }
.paid-toggle.is-paid .when-paid, .paid-toggle .when-unpaid { display: inline-flex; align-items: center; gap: 6px; }
.pay-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.pay-pill.is-paid { background: var(--primary-soft); color: var(--primary-ink); }
.pay-pill.is-unpaid { background: var(--amber-soft); color: var(--amber); }
.pay-pill.is-reported { background: var(--blue-soft); color: var(--blue); }
.paid-toggle.is-reported:not(.is-paid) .paid-btn { background: var(--blue-soft); color: var(--blue); border-color: #cbd9f7; }
.invoice-tenant { display: grid; gap: 2px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.invoice-tenant span { font-size: 12.5px; color: var(--muted); }
.invoice-tenant strong { font-size: 17px; }
.invoice-tenant small { color: var(--muted); }
.invoice-qr {
    display: grid; justify-items: center; align-content: start; gap: 8px; text-align: center;
    margin: 16px 20px 0 0; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2);
}
.invoice-qr img { width: 230px; max-width: 100%; aspect-ratio: 1; object-fit: contain; border-radius: var(--radius-sm); background: #fff; border: 1px solid var(--line); }
.invoice-qr span { font-size: 13px; color: var(--text-2); white-space: pre-line; }

/* ===== Rooms page ===== */
.room-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.room-card { padding: 16px 18px; display: grid; gap: 12px; }
.room-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.room-card-top .muted { display: block; font-size: 13.5px; }
.price-list { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.price-list div { display: grid; gap: 1px; }
.price-list dt { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.price-list dd { margin: 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.price-list dd small { color: var(--muted); font-weight: 500; }

.portal-link { display: grid; gap: 8px; padding: 10px 0 12px; margin-bottom: 10px; border-bottom: 1px dashed var(--line); }
.portal-link-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; }
.portal-link-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.portal-link-url { min-height: 34px; font-size: 13px; color: var(--muted); background: var(--surface-2); }
.portal-link-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.portal-link p { margin: 0; display: flex; gap: 5px; align-items: center; }
.link-button { border: 0; background: none; padding: 0; cursor: pointer; font-family: inherit; }

.disclosure > summary { list-style: none; cursor: pointer; }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure[open] > summary { margin-bottom: 14px; }
.disclosure-link { display: inline-flex; align-items: center; gap: 6px; color: var(--primary); font-weight: 600; font-size: 14px; }
.disclosure-link:hover { text-decoration: underline; text-underline-offset: 3px; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); display: grid; gap: 10px; }
.timeline li { position: relative; display: grid; gap: 2px; font-size: 13.5px; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--primary); }
.timeline li span { color: var(--muted); font-size: 12.5px; }

/* ===== Tenants ===== */
.add-card { margin-bottom: 22px; }
.add-card-summary {
    list-style: none; cursor: pointer;
    display: flex; align-items: center; gap: 8px;
    padding: 14px 20px; font-weight: 650; color: var(--primary);
}
.add-card-summary::-webkit-details-marker { display: none; }
.add-card[open] > .add-card-summary { border-bottom: 1px solid var(--line); }

.tenant-card { padding: 14px 18px; }
.tenant-card.is-past { background: var(--surface-2); }
.tenant-card .disclosure { margin-top: 8px; padding-left: 54px; }
.tenant-row { display: grid; grid-template-columns: 40px minmax(0, 1.4fr) minmax(0, 1.2fr) auto; align-items: center; gap: 14px; }
.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    display: grid; place-items: center; font-weight: 700;
    background: var(--primary-soft); color: var(--primary-ink);
}
.is-past .avatar { background: var(--surface-3); color: var(--muted); }
.tenant-main { display: grid; min-width: 0; }
.tenant-main strong { font-size: 15.5px; }
.tenant-main .muted { font-size: 13.5px; }
.tenant-contact { display: grid; gap: 2px; font-size: 13.5px; color: var(--text-2); min-width: 0; }
.tenant-contact span { display: flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tenant-price { text-align: right; display: grid; font-variant-numeric: tabular-nums; }

.past-section > summary { list-style: none; cursor: pointer; }
.past-section > summary::-webkit-details-marker { display: none; }

/* ===== Settings ===== */
.settings-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 16px; align-items: start; margin-bottom: 16px; }
.qr-settings { display: grid; gap: 16px; }
.qr-preview { display: grid; justify-items: center; gap: 6px; }
.qr-preview img { width: 200px; aspect-ratio: 1; object-fit: contain; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.qr-placeholder {
    width: 200px; aspect-ratio: 1; border: 2px dashed var(--line-strong); border-radius: var(--radius-sm);
    display: grid; place-content: center; justify-items: center; gap: 6px; color: var(--muted);
}
.inline-test { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--line); }
.danger-zone .add-card-summary { color: var(--text-2); }
.error-text { white-space: pre-wrap; word-break: break-word; font-size: 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; margin: 0; }

/* ===== Properties ===== */
.property-switch { padding: 0 6px; }
.property-switch select { font-weight: 600; background: var(--surface-2); }
.property-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.property-card { padding: 16px 18px; display: grid; gap: 12px; }
.property-card.is-past { background: var(--surface-2); opacity: 0.85; }
.property-top { display: flex; gap: 12px; align-items: flex-start; }
.property-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex-shrink: 0; }
.property-main { display: grid; gap: 1px; flex: 1; min-width: 0; }
.property-main strong { font-size: 16.5px; }
.property-main .muted { font-size: 13.5px; }
.small-line { display: flex; align-items: center; gap: 4px; }
.room-property { font-size: 12.5px; color: var(--primary); font-weight: 600; margin-top: -4px; }
.room-chip small { font-size: 11.5px; color: var(--primary); font-weight: 600; }

/* ===== Zalo ===== */
.btn-zalo.btn-primary { background: #0068ff; }
.btn-zalo.btn-primary:hover { background: #0054cc; }
.zalo-list { display: grid; gap: 10px; }
.zalo-item { display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 12px 16px; transition: background 0.2s, border-color 0.2s; }
.zalo-thumb img { width: 72px; height: 100px; object-fit: cover; object-position: top; border-radius: 6px; border: 1px solid var(--line); display: block; }
.zalo-info { display: grid; gap: 2px; min-width: 0; font-size: 14px; }
.zalo-info .muted { display: flex; align-items: center; gap: 5px; font-size: 13px; }
.zalo-title { display: flex; align-items: center; gap: 8px; }
.zalo-title strong { font-size: 17px; }
.zalo-amount { font-size: 16px; font-variant-numeric: tabular-nums; }
.sent-badge { display: none; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary-ink); font-size: 12px; font-weight: 650; }
.zalo-item.is-sent { background: var(--surface-2); }
.zalo-item.is-sent .sent-badge { display: inline-flex; }
.zalo-item.is-sent .btn-zalo { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.zalo-item.no-zalo { border-style: dashed; }
.zalo-actions { display: grid; gap: 6px; }
.zalo-actions .paid-toggle, .zalo-actions .paid-toggle form, .zalo-actions .paid-btn { width: 100%; }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 50;
    max-width: min(560px, calc(100vw - 32px)); padding: 12px 18px; border-radius: var(--radius-sm);
    background: #14201c; color: #fff; font-weight: 550; box-shadow: var(--shadow);
    opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--amber); }

/* ===== Responsive ===== */
@media (max-width: 1080px) {
    .bill-layout, .settings-grid { grid-template-columns: 1fr; }
    .receipt { position: static; }
    .month-bars { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .tenant-row { grid-template-columns: 40px minmax(0, 1fr) auto; }
    .tenant-contact { grid-column: 2 / -1; grid-row: 2; }
}

@media (max-width: 860px) {
    body { display: block; }

    /* Thanh trên cùng */
    .appbar {
        display: flex; align-items: center; gap: 10px;
        position: sticky; top: 0; z-index: 20;
        padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
        background: var(--surface); border-bottom: 1px solid var(--line);
    }
    .appbar .brand { padding: 0; min-width: 0; flex: 1; }
    .appbar .brand-text { min-width: 0; }
    .appbar .brand-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .appbar-refresh { display: none; }
    .appbar-switch { flex-shrink: 1; min-width: 0; max-width: 46%; }
    .appbar-switch select { width: 100%; min-height: 38px; padding: 0 28px 0 10px; font-size: 16px; font-weight: 600; text-overflow: ellipsis; }
    .appbar:has(.appbar-switch) .brand-text small { display: none; }
    .appbar .brand-mark { width: 32px; height: 32px; border-radius: 9px; }

    /* Menu đầy đủ: trượt ra từ bên phải khi bấm "Thêm" */
    .sidebar {
        position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
        width: min(300px, 86vw); height: auto; border-right: 0; border-left: 1px solid var(--line);
        padding: calc(18px + env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
        transform: translateX(100%); transition: transform 0.22s ease; box-shadow: var(--shadow);
    }
    .menu-open .sidebar { transform: none; }
    .menu-backdrop {
        display: block; position: fixed; inset: 0; z-index: 30; width: 100%; border: 0; padding: 0; margin: 0;
        background: rgba(20, 32, 28, 0.4); opacity: 0; pointer-events: none; transition: opacity 0.2s;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .menu-open .menu-backdrop { opacity: 1; pointer-events: auto; }
    .menu-open { overflow: hidden; }
    .nav-link { min-height: 44px; }

    /* Thanh tab dưới đáy */
    .tabbar {
        display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
        background: var(--surface); border-top: 1px solid var(--line);
    }
    .tab {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
        min-height: 52px; padding: 4px 2px; border: 0; background: none; border-radius: var(--radius-sm);
        color: var(--muted); font: 600 11.5px/1.2 var(--font); cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
    .tab.active { color: var(--primary); }
    .tab.active .icon { stroke-width: 2.4; }
    .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

    /* Form nhập điện nước: tổng tạm tính ngay trên nút Lưu */
    .mobile-total {
        display: flex; justify-content: space-between; align-items: baseline;
        padding: 12px 14px; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary-ink);
    }
    .mobile-total strong { font-size: 20px; font-variant-numeric: tabular-nums; }
    .form-actions .btn-lg { flex: 1; }

    .page { padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); }
    h1 { font-size: 23px; }
    .form-grid-3, .form-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .invoice-body { grid-template-columns: 1fr; }
    .invoice-qr { margin: 8px 16px 0; }
    .tenant-card .disclosure { padding-left: 0; }
    .callout { flex-wrap: wrap; }
}

@media (max-width: 560px) {
    .form-grid-2, .form-grid-3, .form-grid-4, .meter { grid-template-columns: 1fr; }
    /* Biểu đồ 12 tháng: 2 hàng x 6 cột, cột thấp hơn để đỡ chiếm màn hình */
    .month-bars { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; padding: 10px 8px; }
    .month-bar { padding: 6px 0; gap: 3px; }
    .month-bar-track { height: 52px; max-width: 26px; }
    .month-bar strong { font-size: 11.5px; }
    .month-bar strong small { font-size: 9.5px; }
    .month-bar em { display: none; }
    .room-cards { grid-template-columns: 1fr; }
    .tenant-row { grid-template-columns: 40px minmax(0, 1fr); }
    .tenant-price { grid-column: 2; text-align: left; }
    .inline-test { flex-direction: column; align-items: stretch; }
    .stat-value { font-size: 22px; }
    /* 2 cột gọn để thấy nhiều phòng một lúc */
    .room-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .room-tile { padding: 12px; gap: 4px; }
    .room-tile-head { flex-wrap: wrap; gap: 4px 6px; }
    .room-code { font-size: 17px; }
    .room-amount { font-size: 15.5px; }
    .room-tenant, .room-property { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .room-meta { font-size: 12px; gap: 3px; flex-wrap: wrap; }
    .room-meta .dot { margin: 0 1px; }
    .room-tile .pay-pill, .room-tile .pill { font-size: 11px; padding: 1px 7px; }
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stats .stat:nth-child(-n+2) { grid-column: 1 / -1; }
    .stats .stat:nth-child(n+3) .stat-value { font-size: 20px; }
    .zalo-item { grid-template-columns: 56px minmax(0, 1fr); }
    .zalo-actions { grid-column: 1 / -1; }
    .zalo-actions .btn { width: 100%; }
    .room-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .callout > .btn { width: 100%; }
    .page-header .toolbar, .page-header .toolbar .btn { width: 100%; }
    .page-header .toolbar > form, .page-header .toolbar > .paid-toggle, .page-header .toolbar > .paid-toggle form { width: 100%; }
    .portal-link-row { grid-template-columns: 1fr; gap: 4px; }
}

@media (max-width: 860px) {
    input, select, textarea { font-size: 16px; }
}

/* Bảng báo cáo → thẻ trên điện thoại */
@media (max-width: 640px) {
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tfoot { display: block; min-width: 0; }
    .table-cards tr {
        display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
        padding: 14px 16px; border-bottom: 1px solid var(--line);
    }
    .table-cards td { display: block; padding: 0; border: 0; text-align: left; }
    .table-cards tbody td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .table-cards tbody td:nth-child(6) { grid-column: 2; grid-row: 1; text-align: right; font-size: 16px; }
    .table-cards tbody td:nth-child(2) { grid-column: 1 / -1; color: var(--text-2); }
    .table-cards tbody td:nth-child(3), .table-cards tbody td:nth-child(4), .table-cards tbody td:nth-child(5) { display: none; }
    .table-cards tbody td:nth-child(7) { grid-column: 1; margin-top: 6px; }
    .table-cards tbody td:nth-child(8) { grid-column: 2; margin-top: 6px; text-align: right; }
    .table-cards tfoot tr { grid-template-columns: minmax(0, 1fr) auto; border-bottom: 0; }
    .table-cards tfoot td:nth-child(3) { grid-column: 1 / -1; }
}

/* Mở dạng app (đã cài lên màn hình chính): iOS không có kéo-để-tải-lại nên hiện nút tải lại */
@media (display-mode: standalone) and (max-width: 860px) {
    .appbar-refresh { display: grid; }
}
