:root {
    --sidebar-bg: #0b1a3a;
    --sidebar-active: #2563eb;
    --sidebar-hover: #1a2e5c;
    /* Brightened for higher-contrast readability (was #cbd5e8 / #8896b8). */
    --sidebar-text: #eef2fb;
    --sidebar-text-muted: #a8b4d0;
    --sidebar-text-active: #ffffff;

    --bg: #f5f7fb;
    --card: #ffffff;
    --border: #e5eaf2;
    --border-strong: #d5dbe8;

    --text: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-fg: #ffffff;
    --primary-soft: #eff5ff;
    --primary-icon: #3b82f6;

    --success: #16a34a;
    --success-soft: #dcfce7;

    --danger: #dc2626;
    --danger-soft: #fee2e2;

    --warn: #d97706;
    --warn-soft: #fef3c7;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-modal: 0 10px 30px rgba(15, 23, 42, 0.12);

    --radius-lg: 14px;
    --radius: 10px;
    --radius-sm: 8px;
    --radius-pill: 999px;

    --sidebar-width: 240px;
    --topbar-height: 72px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
    font-family: var(--font);
    /* Base 16px (was 14px) — friendlier for older eyes without forcing them to
       zoom the browser. All rem-based sizes below scale accordingly. */
    font-size: 16px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Safety net: no matter what a page renders, the body never scrolls sideways.
       Individual scroll containers (tables, code blocks) still scroll normally. */
    overflow-x: hidden;
}

/* iOS WKWebView pans the whole document sideways when a stray element widens
   <html> — body-level overflow-x alone doesn't stop it. App Review saw exactly
   that (page shifted, left edges clipped) in the iPad compatibility window,
   so clamp the root too. */
html { overflow-x: hidden; max-width: 100%; }

/* Long words / URLs / emails should soft-wrap instead of blowing out cards.
   Note: NOT applied to .data-table td/th — that broke dates ("9/1/202 6") and
   forced pill text to stack vertically in narrow columns. Table cells rely on
   the card's horizontal scroll instead. */
.card, .action-row, .attention {
    overflow-wrap: anywhere;
}

#app { min-height: 100vh; }

.app-loading {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100vh; gap: 1rem; color: var(--text-muted);
}
.app-loading-spinner {
    width: 42px; height: 42px; border: 3px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#blazor-error-ui {
    background: #fff3cd; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, .1);
    display: none; left: 0; padding: .75rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; top: .75rem; }

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

h1, h2, h3, h4 { color: var(--text); margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.0625rem; }
h4 { font-size: 0.9375rem; }

/* ===== Layout shell ===== */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-width);
    background: var(--sidebar-bg); color: var(--sidebar-text);
    display: flex; flex-direction: column; z-index: 20;
    /* iPhone app: keep the brand/user rows clear of the notch and home bar.
       env() is 0 in desktop browsers, so this is a no-op on the web. */
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sidebar-brand {
    padding: 1.5rem 1.25rem; font-size: 1.125rem; font-weight: 600; color: #fff;
    letter-spacing: -0.01em;
}
/* min-height:0 + overflow-y lets the nav scroll inside the flex column when
   the screen is short, so the user chip stays pinned and nothing clips —
   App Review screenshotted "Sign out" cut off at the bottom of an iPhone. */
.sidebar-nav { flex: 1; min-height: 0; overflow-y: auto; padding: 0.5rem 0.75rem; display: flex; flex-direction: column; gap: 2px; }
/* ===== Add-form disclosure (AddFormCard): desktop shows the form card as
   always, phones collapse it to one tappable "+ Title" row. ===== */
.add-form-toggle { display: none; }
@media (max-width: 720px) {
    .add-form-toggle {
        display: flex; align-items: center; gap: 0.625rem; width: 100%;
        border: none; background: transparent; cursor: pointer;
        padding: 1rem 1.25rem; font-family: inherit; font-size: 1rem;
        font-weight: 600; color: var(--primary); text-align: left;
    }
    .add-form-toggle svg { width: 20px; height: 20px; }
    .add-form-toggle .af-chevron { margin-left: auto; color: var(--text-muted); }
    .add-form:not(.open) .add-form-inner { display: none; }
    /* The toggle already shows the title — drop the duplicate header on phones. */
    .add-form .add-form-inner > .card-header { display: none; }
}

/* The "More" group toggle looks like a nav link; its chevron flips when open. */
.sidebar-nav .nav-group-toggle { border: none; background: transparent; width: 100%; font-family: inherit; font-size: inherit; cursor: pointer; }
.sidebar-nav .nav-group-toggle .grp-chevron { margin-left: auto; transition: transform 0.15s ease; }
.sidebar-nav .nav-group-toggle.open .grp-chevron { transform: rotate(180deg); }
.sidebar-nav .nav-group { display: flex; flex-direction: column; gap: 2px; padding-left: 0.5rem; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.75rem 0.875rem; border-radius: var(--radius-sm);
    color: var(--sidebar-text); text-decoration: none;
    font-weight: 500; font-size: 1rem;
    transition: background 120ms ease, color 120ms ease;
    min-height: 44px;
}
.sidebar-nav .nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--primary); color: #fff; }
.sidebar-nav .nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }

/* Mobile menu button — obvious, tappable, contrasts against the topbar. */
.menu-button {
    background: var(--primary-soft);
    color: var(--primary);
}
.menu-button:hover { background: #dceafe; color: var(--primary-hover); }

.sidebar-user {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.875rem 1rem;
    display: flex; align-items: center; gap: 0.75rem;
}
.sidebar-user .avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 0.8125rem; flex-shrink: 0;
}
.sidebar-user .user-meta { flex: 1; min-width: 0; }
.sidebar-user .user-name { color: #fff; font-weight: 500; font-size: 0.875rem; }
.sidebar-user .user-email {
    color: var(--sidebar-text-muted); font-size: 0.75rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user .chevron { color: var(--sidebar-text-muted); }

.main { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-width: 0; }

.topbar {
    /* iPhone app: the webview runs edge-to-edge, so the bar grows by the
       status-bar height and pushes its content below the clock/notch.
       env() is 0 in desktop browsers — no effect on the web. */
    height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: env(safe-area-inset-top, 0px) 2rem 0;
    position: sticky; top: 0; z-index: 10;
}
.topbar .page-title { font-size: 1.375rem; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }

.page-content {
    padding: 2rem;
    padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px)); /* clear the iPhone home bar */
    max-width: 1400px; width: 100%;
}

/* ===== Buttons ===== */

.btn {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.625rem 1.125rem; border-radius: var(--radius-pill);
    border: 1px solid transparent; background: transparent;
    font-family: inherit; font-size: 1rem; font-weight: 500;
    color: var(--text); cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
    text-decoration: none;
    min-height: 44px; /* Apple HIG touch target */
    /* A button label must never break mid-word ("D-e-l-e-t-e" stacking in a
       narrow table column). If space is tight the column grows or buttons
       wrap as whole units — the label itself stays on one line. */
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 16px; height: 16px; }

.btn-primary {
    background: var(--primary); color: #fff; border-color: var(--primary);
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-primary:disabled { background: var(--border-strong); border-color: var(--border-strong); cursor: not-allowed; box-shadow: none; }

.btn-secondary { background: var(--card); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--bg); border-color: var(--text-faint); }

.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }

.btn-icon {
    width: 40px; height: 40px; padding: 0; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid transparent; color: var(--text-muted);
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon svg { width: 20px; height: 20px; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-link { background: none; border: none; color: var(--primary); padding: 0.25rem 0.5rem; }
.btn-link:hover { text-decoration: underline; }

/* ===== Cards ===== */

.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
}
.card-body { padding: 1.25rem 1.5rem; }
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 1rem; }

/* ===== Stat cards ===== */

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { display: flex; align-items: center; gap: 1rem; padding: 1.25rem 1.5rem; }
.stat-icon {
    width: 52px; height: 52px; border-radius: 14px;
    background: var(--primary-soft); color: var(--primary);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon svg { width: 24px; height: 24px; }
.stat-value { font-size: 1.75rem; font-weight: 600; color: var(--text); line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: 0.875rem; margin-top: 2px; }

/* ===== Two-column dashboard grid ===== */

.dash-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; align-items: start; }
.dash-side > * + * { margin-top: 1.25rem; }

/* ===== Data table ===== */

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    padding: 0.875rem 1.5rem; text-align: left; font-weight: 400; color: var(--text);
}
.data-table thead th {
    color: var(--text-muted); font-size: 0.8125rem; font-weight: 500;
    border-bottom: 1px solid var(--border);
    background: transparent;
    white-space: nowrap; /* short headers like "Ack" were wrapping mid-word */
}

/* Desktop: keep a row's action buttons on ONE line — the column widens to fit.
   (Inline flex-wrap:wrap on these cells is for the mobile stacked layout,
   where the cell spans the full card width; hence the !important.) */
@media (min-width: 721px) {
    .data-table td[data-label="Action"] { white-space: nowrap; }
    .data-table td[data-label="Action"] .row-flex { flex-wrap: nowrap !important; }
}
.data-table tbody tr { border-bottom: 1px solid var(--border); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(37, 99, 235, 0.02); }
.data-table td .cell-with-icon { display: flex; align-items: center; gap: 0.625rem; color: var(--text-muted); white-space: nowrap; }
.data-table td .cell-with-icon svg { width: 16px; height: 16px; color: var(--text-faint); flex-shrink: 0; }

.table-empty { padding: 2.5rem 1.5rem; text-align: center; color: var(--text-muted); }

/* Mobile-only summary snippets inside table cells; hidden on desktop where
   the full columns already show the same info. */
.m-extra { display: none; }
/* Desktop-only counterpart (e.g. the property name on Leases, redundant on
   a phone where every unit is identified by number + tenant). */
.d-only { display: inline; }

/* Money and date columns never wrap mid-value. */
.data-table td[data-label="Rent"], .data-table td[data-label="Amount"],
.data-table td[data-label="Paid on"], .data-table td[data-label="Due day"] { white-space: nowrap; }

/* ===== Owner monthly statement (printable) ===== */
.stmt-stats {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem;
    padding: 1rem 0; margin-bottom: 1.25rem;
    border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.stmt-num { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stmt-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.stmt-table th {
    text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); font-weight: 600; padding: 0.375rem 0.5rem;
    border-bottom: 1px solid var(--border);
}
.stmt-table td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); }
.stmt-table tr:last-child td { border-bottom: none; }
@media (max-width: 720px) {
    .stmt-stats { grid-template-columns: repeat(2, 1fr); }
    .stmt-table { font-size: 0.8125rem; }
}

/* ===== Lease term progress (fixed-term leases) ===== */
.term-bar {
    height: 6px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 999px; margin-top: 5px; overflow: hidden; max-width: 220px;
}
.term-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.term-text { font-size: 0.78rem; color: var(--text-muted); margin-top: 3px; }

/* ===== Filter chips (Reminders and future list pages) ===== */
.filter-chips {
    display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
    padding: 1rem 1.5rem; border-bottom: 1px solid var(--border);
}
.filter-chips .chip {
    border: 1px solid var(--border); background: var(--card);
    color: var(--text-muted); border-radius: 999px;
    padding: 0.375rem 0.875rem; font-size: 0.8125rem; font-weight: 500;
    cursor: pointer; white-space: nowrap;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.filter-chips .chip:hover { border-color: var(--primary); color: var(--primary); }
.filter-chips .chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Segmented control (By tenant / All reminders) ===== */
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-btn { border: none; background: transparent; color: var(--text-muted); font-weight: 600; font-size: 0.875rem; padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; }
.seg-btn.on { background: var(--card); color: var(--primary); box-shadow: 0 1px 2px rgba(15,34,71,.1); }

/* ===== Rent overview: summary strip ===== */
.summary-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem; }
.summary-strip .stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 0.875rem 1rem; }
.summary-strip .stat .n { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
.summary-strip .stat .k { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.summary-strip .stat.red .n { color: var(--danger); }
.summary-strip .stat.amber .n { color: #c2760a; }
.summary-strip .stat.green .n { color: var(--success); }

/* ===== Rent overview: section headers + tenant cards ===== */
.sec { display: flex; align-items: center; gap: 0.5rem; margin: 1.25rem 0.25rem 0.5rem; }
.sec .dot { width: 8px; height: 8px; border-radius: 50%; }
.sec .dot.red { background: var(--danger); } .sec .dot.amber { background: #c2760a; }
.sec .dot.blue { background: var(--primary); } .sec .dot.green { background: var(--success); }
.sec .lbl { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.sec .count { margin-left: auto; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }

.rent-card { background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 14px; margin-bottom: 0.6rem; overflow: hidden; }
.rent-card.red { border-left-color: var(--danger); } .rent-card.amber { border-left-color: #c2760a; }
.rent-card.blue { border-left-color: var(--primary); } .rent-card.green { border-left-color: var(--success); }
.rent-card.open { border-color: var(--primary); box-shadow: 0 4px 16px rgba(37,99,235,.12); }
.rent-head { display: flex; align-items: center; gap: 0.875rem; padding: 0.875rem 1rem; cursor: pointer; }
.rent-head .av { width: 42px; height: 42px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 0.9rem; color: #fff; background: var(--primary); }
.rent-head .av.red { background: #e0575f; } .rent-head .av.amber { background: #d9932f; }
.rent-head .av.blue { background: #4f7ce0; } .rent-head .av.green { background: #3f9e6a; }
.rent-head .who { flex: 1; min-width: 0; }
.rent-head .who .nm { font-weight: 700; font-size: 1rem; letter-spacing: -0.01em; }
.rent-head .who .sub { font-size: 0.8125rem; color: var(--text-muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rent-head .right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex: none; }
.rent-head .amt { font-weight: 700; font-size: 1rem; font-variant-numeric: tabular-nums; }

.rent-thread { padding: 0.5rem 1rem 1rem; border-top: 1px solid var(--border); }
.rent-thread .ev { display: flex; gap: 0.625rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.rent-thread .ev:last-of-type { border-bottom: none; }
.rent-thread .ic { width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 0.8rem; }
.rent-thread .ic.mail { background: var(--primary-soft); color: var(--primary); }
.rent-thread .ic.sms { background: var(--success-soft); color: var(--success); }
.rent-thread .ev-body { flex: 1; min-width: 0; }
.rent-thread .ev-l1 { display: flex; justify-content: space-between; gap: 0.5rem; }
.rent-thread .ev-k { font-weight: 600; font-size: 0.82rem; }
.rent-thread .ev-ts { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }
.rent-thread .ev-msg { font-size: 0.82rem; color: var(--text-muted); line-height: 1.4; margin-top: 2px; }
.rent-actions { display: flex; gap: 0.5rem; padding-top: 0.875rem; }
.rent-actions .btn { flex: 1; justify-content: center; }

/* ===== Help / knowledge base ===== */
.kb ol, .kb ul { padding-left: 1.5rem; line-height: 1.7; }
.kb li { margin-bottom: 0.5rem; }
.kb p { line-height: 1.65; }
.kb code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 0.875em; }

/* ===== Type pills ===== */

.pill {
    display: inline-flex; align-items: center; padding: 0.25rem 0.625rem;
    border-radius: var(--radius-pill); font-size: 0.75rem; font-weight: 500;
    background: var(--bg); color: var(--text-muted); border: 1px solid transparent;
    /* Never break pill labels — "Inspection" must stay on one line even in a
       narrow mobile column. If a pill is too wide for its cell, the table
       card scrolls horizontally instead. */
    white-space: nowrap;
}
.pill-rent      { background: #dcfce7; color: #15803d; }
.pill-overdue   { background: #fee2e2; color: #b91c1c; }
.pill-inspection{ background: #dbeafe; color: #1d4ed8; }
.pill-maintenance{background: #fef3c7; color: #a16207; }
.pill-rule      { background: #ede9fe; color: #6d28d9; }
.pill-cleanliness{background: #ccfbf1; color: #0f766e; }
.pill-renewal   { background: #e0e7ff; color: #4338ca; }
.pill-moveout   { background: #ffe4e6; color: #be123c; }
.pill-general   { background: #e2e8f0; color: #475569; }

.pill-status-scheduled { background: #dbeafe; color: #1d4ed8; }
.pill-status-sent      { background: #dcfce7; color: #15803d; }
.pill-status-cancelled { background: #e2e8f0; color: #475569; }

/* ===== Alert/attention card ===== */

.attention {
    text-align: center; padding: 1.5rem 1.5rem 1.75rem;
}
.attention-badge {
    width: 56px; height: 56px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: 0.75rem;
}
.attention-badge.ok    { background: var(--success-soft); color: var(--success); }
.attention-badge.warn  { background: var(--warn-soft); color: var(--warn); }
.attention-badge.alert { background: var(--danger-soft); color: var(--danger); }
.attention-badge svg   { width: 28px; height: 28px; }
.attention h4 { font-size: 1rem; }
.attention p  { color: var(--text-muted); margin: 0.25rem 0 0; font-size: 0.8125rem; }

.attention-header {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 1rem 1.5rem 0; color: var(--text); font-weight: 500;
}
.attention-header svg { width: 18px; height: 18px; color: var(--warn); }

/* ===== Quick action rows ===== */

.action-list { display: flex; flex-direction: column; }
.action-row {
    display: flex; align-items: center; gap: 0.875rem;
    padding: 0.875rem 1.5rem;
    border: none; background: transparent; text-align: left;
    color: var(--text); cursor: pointer; font-family: inherit; font-size: 0.875rem;
    border-top: 1px solid var(--border); width: 100%;
    text-decoration: none;
}
.action-row:first-child { border-top: none; }
.action-row:hover { background: var(--bg); }
.action-row .icon-puck {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--primary-soft); color: var(--primary);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.action-row .icon-puck svg { width: 18px; height: 18px; }
.action-row .action-label { flex: 1; }
.action-row .action-title { font-weight: 500; }
.action-row .action-sub { color: var(--text-muted); font-size: 0.75rem; }
.action-row .chevron { color: var(--text-faint); }

/* ===== Forms ===== */

.form-row { display: grid; gap: 1rem; grid-template-columns: repeat(12, 1fr); }
.form-field { display: flex; flex-direction: column; gap: 0.375rem; }
.form-field.col-2  { grid-column: span 2; }
.form-field.col-3  { grid-column: span 3; }
.form-field.col-4  { grid-column: span 4; }
.form-field.col-6  { grid-column: span 6; }
.form-field.col-8  { grid-column: span 8; }
.form-field.col-9  { grid-column: span 9; }
.form-field.col-12 { grid-column: span 12; }
.form-label { font-size: 0.8125rem; font-weight: 500; color: var(--text); }
.form-hint  { font-size: 0.75rem; color: var(--text-muted); }
.form-control, .form-select, textarea.form-control {
    width: 100%; padding: 0.625rem 0.875rem; border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); font-family: inherit; font-size: 1rem;
    background: var(--card); color: var(--text); transition: border-color 120ms ease, box-shadow 120ms ease;
    min-height: 44px;
}
.form-control:focus, .form-select:focus, textarea.form-control:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea.form-control { min-height: 90px; resize: vertical; }
.checkbox { display: inline-flex; align-items: center; gap: 0.5rem; }

/* ===== Utilities ===== */

.stack > * + * { margin-top: 1rem; }
.row-flex { display: flex; align-items: center; gap: 0.75rem; }
.row-flex.between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.hidden { display: none; }

/* ===== Print (receipts) ===== */

.print-page { padding: 2rem; background: #fff; color: #0f172a; min-height: 100vh; }
.receipt-actions { display: flex; gap: 0.75rem; margin: 0 auto 1.5rem; max-width: 720px; }
.receipt {
    max-width: 720px; margin: 0 auto; background: #fff; color: #0f172a;
    border: 1px solid #e5eaf2; border-radius: 12px; padding: 2rem 2.25rem;
}
.receipt-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 2rem; padding-bottom: 1.25rem; border-bottom: 2px solid #0f172a;
}
.receipt-header h1 { font-size: 1.75rem; margin: 0; }
.receipt-header .text-muted { color: #64748b; margin: 4px 0 0; }
.receipt-landlord { text-align: right; font-size: 0.9375rem; line-height: 1.5; }
.receipt-parties {
    display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;
    padding: 1.5rem 0; border-bottom: 1px solid #e5eaf2;
}
.receipt-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem 2rem;
    padding: 1.5rem 0; border-bottom: 1px solid #e5eaf2;
}
.receipt-label {
    text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.75rem;
    color: #64748b; font-weight: 600; margin-bottom: 4px;
}
.receipt-value { font-size: 1.0625rem; font-weight: 500; }
.receipt-amount { font-size: 2rem; font-weight: 700; color: #0f172a; letter-spacing: -0.01em; }
.receipt-notes { padding: 1.25rem 0; border-bottom: 1px solid #e5eaf2; }
.receipt-footer {
    display: flex; justify-content: space-between; align-items: flex-end;
    padding-top: 2rem;
}
.receipt-signature { flex: 1; max-width: 260px; }
.receipt-line { border-top: 1px solid #0f172a; margin-bottom: 0.5rem; padding-top: 3rem; }
.receipt-stamp {
    padding: 0.5rem 1rem; border: 2px solid #16a34a; color: #16a34a;
    font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
    border-radius: 6px; transform: rotate(-6deg);
}

.contract-print {
    max-width: 720px; margin: 0 auto; background: #fff; color: #0f172a;
    border: 1px solid #e5eaf2; border-radius: 12px; padding: 2rem 2.25rem;
}
.contract-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 2rem; padding-bottom: 1.25rem; border-bottom: 1px solid #e5eaf2;
    margin-bottom: 1.5rem; font-size: 0.9375rem; line-height: 1.5;
}
.contract-title {
    font-size: 1.5rem; margin: 0 0 1.25rem; text-align: center;
    text-transform: uppercase; letter-spacing: 0.05em;
}
.contract-body {
    font-family: "Georgia", "Times New Roman", serif;
    font-size: 0.9375rem; line-height: 1.65; color: #0f172a;
    white-space: pre-wrap; word-wrap: break-word;
    background: transparent; border: none; padding: 0; margin: 0;
}
.contract-footer { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #e5eaf2; }

@media print {
    body { background: #fff !important; }
    .receipt-actions { display: none !important; }
    .receipt, .contract-print { border: none; padding: 0; max-width: none; }
}

/* ===== Auth pages ===== */

.auth-page {
    min-height: 100vh; background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    padding: 1.5rem;
}
.auth-shell { width: 100%; max-width: 400px; }
.auth-card { box-shadow: 0 10px 40px rgba(15, 23, 42, 0.08); }

/* Show-on-mobile helper (hidden on desktop by default) */
.mobile-only { display: none; }

/* Backdrop shown when off-canvas sidebar is open on mobile */
.sidebar-backdrop {
    display: none; position: fixed; inset: 0; z-index: 15;
    background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(2px);
}

/* Wrap wide data tables so they scroll horizontally instead of blowing out the page */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ===== Responsive tightening ===== */

@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    /* Grid/flex children default to min-width:auto, which lets long unwrapped
       content (big peso figures, dates) push a track wider than the viewport
       on narrow windows — the root cause of the sideways-shifted layout App
       Review screenshotted. Let them shrink and clip instead. */
    .stat-card, .stat-value, .summary-strip .stat, .summary-strip .stat .n,
    .card, .data-table tr, .rent-card, .rent-head .who { min-width: 0; max-width: 100%; }
    .summary-strip { grid-template-columns: repeat(2, 1fr); }
    .summary-strip .stat .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .dash-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .mobile-only { display: inline-flex; }

    /* Off-canvas sidebar: slides in from left, backdrop behind it */
    .sidebar {
        transform: translateX(-100%); transition: transform 200ms ease;
        width: 260px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar.open ~ .sidebar-backdrop,
    .sidebar-backdrop.open { display: block; }

    .main { margin-left: 0; }

    /* Top bar: tighter and taller for touch (still clearing the status bar) */
    .topbar {
        padding: env(safe-area-inset-top, 0px) 0.875rem 0;
        height: calc(60px + env(safe-area-inset-top, 0px));
    }
    .topbar .page-title { font-size: 1.125rem; }

    /* Icon-only Create button on mobile — label lives in the sidebar action anyway */
    .topbar-actions .btn-primary { padding: 0.5rem 0.75rem; }
    .topbar-actions .btn-primary .btn-label { display: none; }

    .page-content { padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px)); }

    /* Cards are edge-to-edge on very small screens */
    .card { border-radius: 12px; }
    .card-body, .card-header { padding: 1rem 1rem; }

    .stat-grid { grid-template-columns: 1fr; gap: 0.75rem; margin-bottom: 1rem; }
    .stat-card { padding: 1rem; }
    .stat-icon { width: 44px; height: 44px; border-radius: 12px; }
    .stat-icon svg { width: 20px; height: 20px; }
    .stat-value { font-size: 1.5rem; }

    /* Forms: single-column, larger inputs for touch (44px = Apple HIG target) */
    .form-field.col-2, .form-field.col-3, .form-field.col-4, .form-field.col-6,
    .form-field.col-8, .form-field.col-9 { grid-column: span 12; }
    .form-control, .form-select, textarea.form-control { padding: 0.625rem 0.75rem; font-size: 1rem; }
    .btn { padding: 0.625rem 1rem; font-size: 0.9375rem; }
    .btn-sm { padding: 0.5rem 0.875rem; font-size: 0.875rem; }
    .btn-icon { width: 44px; height: 44px; }

    /* Responsive table: reflow rows as stacked label:value cards on mobile
       instead of shrinking columns until words break letter-by-letter. Each
       td needs data-label="…" for its label to render. Tables without data-label
       fall back to normal narrow-column rendering + horizontal scroll. */
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr { display: block; width: 100%; }
    .data-table tr {
        border-bottom: 1px solid var(--border);
        padding: 0.5rem 0.25rem;
    }
    .data-table tr:last-child { border-bottom: none; }
    .data-table td {
        display: flex; justify-content: space-between; align-items: baseline;
        gap: 1rem; padding: 0.375rem 1rem; border: none;
        white-space: normal;
    }
    /* ===== Collapsible cards: rows start compact, tap to reveal the rest.
       Collapsed, a card keeps only its identity fields (first cell, Title,
       Status, Amount, Rent, Tenant); everything else — including the action
       buttons — appears when the row gains .expanded (toggled by the tap
       handler in index.html). Detail/editor rows use colspan cells without
       data-label, so these rules never touch them. */
    .data-table tbody tr.collapsible { cursor: pointer; position: relative; }

    /* Collapsed: hide every field cell first… */
    .data-table tbody tr.collapsible:not(.expanded) > td[data-label] { display: none; }
    /* …then reveal just the summary cell: the Title when the row has one,
       otherwise the first cell — as a single truncated line. */
    .data-table tbody tr.collapsible:not(.expanded) > td[data-label="Title"],
    .data-table tbody tr.collapsible:not(.expanded):not(:has(> td[data-label="Title"])) > td:first-child {
        display: block;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        padding: 0.625rem 2.5rem 0.625rem 1rem;   /* tighter rows; right room for chevron */
        font-weight: 600; font-size: 0.9375rem;
    }
    .data-table tbody tr.collapsible:not(.expanded) { padding: 0; }
    /* No "WHEN"/"TITLE" label prefix on the collapsed one-liner. */
    .data-table tbody tr.collapsible:not(.expanded) > td::before { display: none; }
    /* Rules' summary cell holds a title + a body-preview <div>; on the collapsed
       line keep only the title. */
    .data-table tbody tr.collapsible:not(.expanded) > td:first-child > div > div { display: none; }
    .data-table tbody tr.collapsible:not(.expanded) > td .cell-with-icon { display: inline; }

    /* Chevron, always parked at the row's right edge. */
    .data-table tbody tr.collapsible::after {
        content: "▾";
        position: absolute; top: 0.875rem; right: 1rem;
        color: var(--primary); font-weight: 700;
    }
    .data-table tbody tr.collapsible.expanded::after { content: "▴"; }

    /* ===== Blazor-owned accordion (tables tagged .no-auto-collapse, e.g.
       Reminders). Expanded state lives in C# so Cancel/Edit/Delete re-renders
       don't lose it. m-closed = one-line summary; m-open = full stacked card. */
    .data-table.no-auto-collapse tbody tr.m-closed,
    .data-table.no-auto-collapse tbody tr.m-open { position: relative; cursor: pointer; }
    /* The page marks ONE cell per row as .m-summary — that's the collapsed
       one-liner; every other labeled cell hides until the row opens. */
    .data-table.no-auto-collapse tbody tr.m-closed > td[data-label]:not(.m-summary) { display: none; }
    .data-table.no-auto-collapse tbody tr.m-closed > td.m-summary {
        display: block;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
        padding: 0.625rem 2.5rem 0.625rem 1rem;
        font-weight: 600; font-size: 0.9375rem;
    }
    .data-table.no-auto-collapse tbody tr.m-closed > td.m-summary::before { display: none; }
    /* Extra summary text that only exists on the mobile one-liner. */
    .m-extra { display: inline; color: var(--text-muted); font-weight: 500; }
    .d-only { display: none; }
    /* Prominent circular chevron so it's obviously a tap-to-expand control. */
    .data-table.no-auto-collapse tbody tr.m-closed::after,
    .data-table.no-auto-collapse tbody tr.m-open::after {
        content: "▾";
        position: absolute; right: 0.75rem;
        width: 30px; height: 30px; line-height: 30px; text-align: center;
        background: var(--primary); color: #fff;
        border-radius: 50%; font-size: 0.9375rem; font-weight: 700;
        box-shadow: 0 1px 3px rgba(0,0,0,0.18);
    }
    .data-table.no-auto-collapse tbody tr.m-closed::after {
        top: 50%; transform: translateY(-50%);   /* centered on the one-line row */
    }
    .data-table.no-auto-collapse tbody tr.m-open::after {
        content: "▴"; top: 0.75rem;               /* parked at the top of an open card */
    }
    /* Leave room so the chevron never overlaps the summary text. */
    .data-table.no-auto-collapse tbody tr.m-closed > td[data-label="Title"] { padding-right: 3.25rem; }

    /* Multi-select checkbox cell: pinned to the left edge of the row on
       mobile (collapsed and open), with the summary indented to make room. */
    .data-table.no-auto-collapse tbody tr.m-closed > td.sel-cell,
    .data-table.no-auto-collapse tbody tr.m-open > td.sel-cell {
        display: block; position: absolute; left: 0.35rem; top: 0.45rem;
        padding: 0.25rem; border: none; background: transparent; z-index: 1;
    }
    .data-table.no-auto-collapse tbody tr.m-closed > td.sel-cell { top: 50%; transform: translateY(-50%); }
    .data-table.no-auto-collapse tbody tr.m-closed > td.sel-cell::before,
    .data-table.no-auto-collapse tbody tr.m-open > td.sel-cell::before { display: none; }
    .data-table.no-auto-collapse tbody tr.m-closed > td.sel-cell ~ td.m-summary { padding-left: 2.5rem; }
    .data-table.no-auto-collapse tbody tr.m-open > td.sel-cell ~ td[data-label] { padding-left: 2.5rem; }
    .sel-cell input[type="checkbox"] { width: 20px; height: 20px; }

    .data-table td[data-label]::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-weight: 500;
        flex-shrink: 0;
    }
    .data-table td .cell-with-icon { white-space: nowrap; }
    /* Expanded detail rows (delete confirm, unit editor, etc.) span full width */
    .data-table td[colspan] { display: block; }
    .data-table td[colspan]::before { content: none; }

    /* Auth pages never need horizontal scroll — keep them clean. */
    .auth-card { overflow-x: visible; }

    /* Prevent the topbar from getting too cramped: the page-title truncates
       rather than pushing the action buttons off-screen. */
    .topbar .page-title {
        overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
        min-width: 0;
    }
    .topbar > .row-flex { min-width: 0; flex: 1; }
}
