/* =============================================================================
   BWPMG Client Management - Design System
   ============================================================================= */

:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-muted: #f1f5f9;
    --border: #e5e7eb;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-2: #334155;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --primary: #10b981;
    --primary-600: #059669;
    --primary-700: #047857;
    --primary-ink: #064e3b;
    --primary-soft: #d1fae5;
    --primary-softer: #ecfdf5;

    --accent: #0ea5e9;
    --warning: #f59e0b;
    --warning-soft: #fef3c7;
    --danger: #ef4444;
    --danger-soft: #fee2e2;

    --gradient-header: linear-gradient(135deg, #0f172a 0%, #1e293b 40%, #064e3b 100%);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.18);

    --radius: 10px;
    --radius-lg: 16px;
    --radius-sm: 6px;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --surface: #111827;
        --surface-2: #0f172a;
        --surface-muted: #1e293b;
        --border: #1f2937;
        --border-strong: #334155;
        --text: #f1f5f9;
        --text-2: #cbd5e1;
        --text-muted: #94a3b8;
        --text-faint: #64748b;
        --primary-softer: rgba(16, 185, 129, 0.12);
        --primary-soft: rgba(16, 185, 129, 0.2);
        --warning-soft: rgba(245, 158, 11, 0.18);
        --danger-soft: rgba(239, 68, 68, 0.18);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
        --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

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

button { font-family: inherit; }

/* ================= Header ================= */
.app-header {
    background: var(--gradient-header);
    color: #fff;
    padding: 18px 28px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    position: sticky;
    top: 0;
    z-index: 30;
    box-shadow: var(--shadow-md);
    transition: transform 0.25s ease;
    will-change: transform;
}
/* Auto-hide on scroll down, reveal on scroll up (toggled from app.js) */
.app-header.is-hidden { transform: translateY(-100%); }
.app-header__row {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}
.app-header__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.3px;
}
.app-header__brand-mark {
    width: 34px; height: 34px; border-radius: 9px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #10b981, #34d399);
    color: #062f21;
    font-weight: 800;
    font-size: 13px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25);
}
.app-header__brand small {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: #94a3b8;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-top: 2px;
}
.app-header__actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
    align-items: center;
}
.app-header__btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: #e2e8f0;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.app-header__btn:hover { background: rgba(255,255,255,0.15); }
.app-header__btn--primary {
    background: var(--primary);
    border-color: var(--primary-600);
    color: #042a1d;
    font-weight: 600;
}
.app-header__btn--primary:hover { background: var(--primary-600); color: #fff; }

/* Hamburger menu: always available; on narrow screens it replaces the tab
   buttons entirely so nothing gets cut off. */
.app-menu { position: relative; }
.app-menu__dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 235px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 60;
}
.app-menu__dropdown.is-open { display: block; }
.app-menu__item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    font-size: 14px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
}
.app-menu__item:hover { background: var(--surface-muted); }
@media (max-width: 900px) {
    .app-header__btn--collapsible { display: none; }
}

.kbd {
    display: inline-block;
    padding: 2px 6px;
    background: rgba(15,23,42,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
}

/* ================= Main Layout ================= */
.main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 24px 80px;
}

/* ================= Stat Cards ================= */
.stats-bar {
    display: flex;
    margin-bottom: 10px;
}
.stats-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    transition: background 0.1s, color 0.1s;
}
.stats-toggle:hover { background: var(--surface-muted); color: var(--text); }
.stats-toggle__chev { transition: transform 0.18s ease; }
.stats-toggle[aria-expanded="false"] .stats-toggle__chev { transform: rotate(-90deg); }
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.stats.is-collapsed { display: none; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.stat-card__label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}
.stat-card__value {
    font-size: 26px;
    font-weight: 700;
    margin-top: 6px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.stat-card__sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}
.stat-card--accent::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--primary);
}

/* Clickable Active/Paused cards -> contact list */
.stat-card--clickable { cursor: pointer; transition: border-color .12s, background .12s; }
.stat-card--clickable:hover { border-color: var(--primary); }
.stat-card--clickable:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stat-card--clickable.is-selected { border-color: var(--primary); background: var(--primary-softer); box-shadow: inset 0 0 0 1px var(--primary); }
.stat-card__cta { font-size: 11px; color: var(--text-muted); margin-top: 6px; }
.stat-card--clickable:hover .stat-card__cta { color: var(--primary-700); }

/* Contact list rows (shown when an Active/Paused card is selected) */
.contact-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.contact-row:hover { background: var(--surface-2); }
.contact-row__name { font-weight: 600; color: var(--text); display: flex; align-items: center; }
.contact-row__lines { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--text-2); }
.contact-line { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.contact-line a { color: var(--primary-600); }
.contact-ic { font-size: 12px; opacity: .8; }

/* Clickable billing-period cards */
.stat-card--period {
    text-align: left;
    font: inherit;
    cursor: pointer;
    border-color: var(--border);
}
.stat-card--period:hover { border-color: var(--primary); background: var(--primary-softer); }
.stat-card--period:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.period-range {
    font-size: 16px;
    font-weight: 700;
    margin-top: 6px;
    color: var(--text);
}
.period-cta { margin-top: 10px; }
.period-hint { display: block; font-size: 11.5px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card--period[aria-expanded="true"] .period-hint { display: none; }
.period-unpaid-btn {
    display: flex;
    width: 100%;
    justify-content: center;
    padding: 7px 10px;
    font-size: 12.5px;
    font-weight: 600;
    border-color: var(--danger);
    color: var(--danger);
    background: var(--surface);
}
.period-unpaid-btn:hover { background: var(--danger-soft); }
.period-unpaid-btn.is-active { background: var(--danger); border-color: var(--danger); color: #fff; }
.period-totals { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.period-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
    color: var(--text-2);
}
.period-row strong { font-size: 15px; font-variant-numeric: tabular-nums; color: var(--text); }
.period-foot { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.stat-card--period.is-selected {
    border-color: var(--primary);
    background: var(--primary-softer);
    box-shadow: inset 0 0 0 1px var(--primary);
}

/* Period filter banner sub-links */
.period-banner__actions { margin-top: 8px; }
.period-subfilter { margin: 0 6px; }
.period-subfilter__link { font-weight: 600; }
.period-subfilter__link.is-active { text-decoration: underline; color: var(--primary-700); }

/* Per-row billing-period detail line (full width, under address) */
.row-period {
    grid-column: 1 / -1;
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.row-period__due { color: var(--danger); }

/* ================= Toolbar ================= */
.toolbar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
}
/* The toolbar scrolls away naturally with the page (not sticky), so it only
   leaves the screen once you've scrolled past it - no pinning or jump. */
.search-wrap {
    position: relative;
    flex: 1 1 280px;
    min-width: 220px;
}
.search-wrap svg {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.search-input {
    width: 100%;
    padding: 10px 14px 10px 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    transition: border-color 0.15s, background 0.15s;
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--primary-softer);
}
.search-hint {
    position: absolute;
    right: 10px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    font-size: 11px;
    pointer-events: none;
}

.pill-group {
    display: inline-flex;
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
    padding: 3px;
    gap: 2px;
}
.pill {
    padding: 6px 12px;
    border-radius: 5px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-2);
    cursor: pointer;
    background: transparent;
    border: none;
    transition: background 0.1s, color 0.1s;
}
.pill:hover { color: var(--text); }
.pill.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.toolbar__spacer { flex: 1; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-muted); }
.btn:active { transform: translateY(1px); }
.btn--primary {
    background: var(--primary);
    border-color: var(--primary-600);
    color: #042a1d;
    font-weight: 600;
}
.btn--primary:hover { background: var(--primary-600); color: #fff; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--surface-muted); }
.btn--danger { color: var(--danger); border-color: var(--border); }
.btn--danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ================= List / Virtual Scroller ================= */
.list-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
/* Row 1: Client | Next cut | Frequency | Price | Actions.
   Row 2: Address spans every column (set on .row-addr). */
.list-header,
.list-row {
    grid-template-columns: 2.2fr 1fr 0.9fr 0.8fr 56px;
}
.list-header {
    display: grid;
    gap: 4px 12px;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.list-scroll {
    position: relative;
    background: var(--surface);
}
/* Footer at the bottom of the list card: result count + pager */
.list-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 16px;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
}
.list-count {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.list-pager {
    display: flex;
    align-items: center;
    gap: 8px;
}
.list-pager__perpage {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}
.list-pager__perpage select {
    width: auto;
    padding: 5px 8px;
    font-size: 12px;
    cursor: pointer;
}
.list-pager__indicator {
    font-size: 12px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
    min-width: 96px;
    text-align: center;
}
.list-row {
    display: grid;
    gap: 2px 12px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    align-items: center;
    cursor: pointer;
    transition: background 0.08s;
}
.list-row:hover { background: var(--surface-2); }
.list-row.is-selected { background: var(--primary-softer); }

/* Clickable, sortable column headers */
.lh-sort {
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.lh-sort:hover { color: var(--text); }
.lh-sort:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }
.sort-caret { font-size: 9px; line-height: 1; opacity: 0.9; }
.lh-sort.sort-asc .sort-caret::after { content: '▲'; }
.lh-sort.sort-desc .sort-caret::after { content: '▼'; }
.lh-sort.is-active { color: var(--primary-700); }

.row-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-name strong { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-name small { color: var(--text-muted); font-size: 11.5px; display: inline-flex; align-items: center; gap: 4px; }
.freq-inline { display: none; }

/* Small, subtle dot before the name: green = active, grey = inactive */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 7px;
    vertical-align: middle;
    flex-shrink: 0;
}
.status-dot--active { background: var(--primary); box-shadow: 0 0 0 2px var(--primary-softer); }
.status-dot--inactive { background: var(--text-faint); }

/* Address occupies its own full-width row under the name */
.row-addr {
    grid-column: 1 / -1;
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Total-owed line, full width, directly under the address */
.row-owed {
    grid-column: 1 / -1;
    font-size: 12px;
    font-weight: 600;
    color: var(--danger);
    font-variant-numeric: tabular-nums;
}
.row-nextcut { font-size: 13px; }
.row-freq { font-size: 12.5px; color: var(--text-2); }
.row-price { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.row-price small { color: var(--text-muted); font-weight: 400; }

.row-actions {
    display: flex; gap: 4px; justify-content: flex-end;
}
.icon-btn {
    width: 28px; height: 28px;
    border: none; background: transparent; color: var(--text-muted);
    border-radius: 5px;
    cursor: pointer;
    display: inline-grid; place-items: center;
    transition: background 0.1s, color 0.1s;
}
.icon-btn:hover { background: var(--surface-muted); color: var(--text); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: var(--surface-muted);
    color: var(--text-2);
}
.badge--active { background: var(--primary-soft); color: var(--primary-700); }
.badge--paused { background: var(--warning-soft); color: #92400e; }
.badge--deleted { background: var(--danger-soft); color: var(--danger); }
.badge--paid { background: var(--primary-soft); color: var(--primary-700); }
.badge--seen { background: #dbeafe; color: #1d4ed8; }
.badge--unpaid { background: var(--danger-soft); color: var(--danger); }
/* Paid/Unpaid badges double as a "send SMS" button */
.badge--send { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
.badge--unpaid.badge--send:hover { background: var(--danger); color: #fff; }
.badge--paid.badge--send:hover { background: var(--primary); color: #fff; }
.badge--send:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }

/* Next-cut countdown cell in the client list */
.row-nextcut { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-2); }
.row-nextcut .nc-overdue { color: var(--danger); font-weight: 600; }
.row-nextcut .nc-due { color: #92400e; font-weight: 600; }
.row-nextcut .nc-soon { color: var(--warning); font-weight: 600; }
.row-nextcut .nc-muted { color: var(--text-faint); }
@media (prefers-color-scheme: dark) {
    .row-nextcut .nc-due { color: #fbbf24; }
}

.empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty strong { display: block; font-size: 16px; color: var(--text); margin-bottom: 4px; }

/* ================= Drawer ================= */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }

.drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 640px;
    max-width: 100vw;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    z-index: 101;
    transform: translateX(100%);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
}
.drawer.is-open { transform: translateX(0); }
.drawer__header {
    padding: 20px 24px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
}
.drawer__close {
    width: 32px; height: 32px; border-radius: 8px;
    border: none; background: var(--surface-muted); color: var(--text-2);
    cursor: pointer;
    display: grid; place-items: center;
    margin-left: auto;
}
.drawer__close:hover { background: var(--border); }
.drawer__title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}
.drawer__tabs {
    display: flex;
    padding: 0 24px;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.drawer__tab {
    background: transparent;
    border: none;
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    font-weight: 500;
}
.drawer__tab:hover { color: var(--text); }
.drawer__tab.is-active {
    color: var(--primary-700);
    border-bottom-color: var(--primary);
}
.drawer__body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}
.drawer__footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    gap: 8px;
    background: var(--surface-2);
}

/* Definition grid for client details */
.kv {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 8px 14px;
    margin-bottom: 16px;
}
.kv dt { color: var(--text-muted); font-size: 12px; font-weight: 500; }
.kv dd { margin: 0; color: var(--text); font-size: 14px; }
.kv dd .muted { color: var(--text-muted); }

.section-title {
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-muted); margin: 0 0 8px; font-weight: 600;
}

/* ================= Forms ================= */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 18px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-2);
    font-weight: 600;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.form-group .hint {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 4px;
}
.form-group .required {
    color: var(--danger);
    margin-left: 3px;
}
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 9px 12px;
    font: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-softer);
}
input[readonly] {
    background: var(--surface-muted);
    color: var(--text-muted);
    cursor: not-allowed;
}
textarea { resize: vertical; min-height: 80px; }
.input-error { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; margin-top: 4px; }

.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface);
}
.segmented button {
    border: none;
    background: transparent;
    padding: 8px 16px;
    font: inherit;
    color: var(--text-2);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
}
.segmented button:not(:last-child) { border-right: 1px solid var(--border); }
.segmented button.is-active {
    background: var(--primary-softer);
    color: var(--primary-700);
    font-weight: 600;
}

/* Duplicate + SMS preview banners */
.banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 13px;
    margin-bottom: 14px;
}
.banner--warning { background: var(--warning-soft); color: #78350f; border-color: #fbbf24; }
.banner--info { background: var(--primary-softer); color: var(--primary-ink); border-color: var(--primary); }
.banner--danger { background: var(--danger-soft); color: #991b1b; border-color: var(--danger); }
.banner a { color: inherit; text-decoration: underline; font-weight: 600; }

.sms-preview {
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text);
    white-space: pre-wrap;
    line-height: 1.5;
}
.sms-preview__meta {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.price-live {
    display: flex; align-items: baseline; gap: 8px;
    padding: 10px 14px;
    background: var(--primary-softer);
    border: 1px solid var(--primary-soft);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}
.price-live strong { font-size: 18px; font-weight: 700; color: var(--primary-ink); }
.price-live small { color: var(--text-muted); font-size: 12px; }

/* ================= Toasts ================= */
.toasts {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    z-index: 200;
    pointer-events: none;
}
.toast {
    min-width: 280px;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: slideIn 0.2s ease;
}
.toast--success { border-left: 3px solid var(--primary); }
.toast--error { border-left: 3px solid var(--danger); }
.toast--warning { border-left: 3px solid var(--warning); }
.toast__msg { flex: 1; font-size: 13px; color: var(--text); }
.toast button {
    background: transparent;
    border: none;
    color: var(--primary-600);
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
}
@keyframes slideIn {
    from { transform: translateY(10px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ================= Command Palette ================= */
.palette-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(3px);
    z-index: 300;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 14vh;
}
.palette-backdrop.is-open { display: flex; }
.palette {
    width: 620px; max-width: 90vw;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex; flex-direction: column;
}
.palette__input {
    width: 100%;
    padding: 14px 18px;
    border: none;
    background: transparent;
    font-size: 15px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    outline: none;
}
.palette__list {
    max-height: 50vh;
    overflow-y: auto;
    padding: 6px 0;
}
.palette-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}
.palette-item:hover, .palette-item.is-active {
    background: var(--surface-muted);
}
.palette-item__name { flex: 1; }
.palette-item__name small { color: var(--text-muted); display: block; font-size: 11px; }
.palette-item__chip {
    font-size: 10px; padding: 2px 6px; border-radius: 4px;
    background: var(--surface-muted); color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600;
}

/* ================= HOA maintenance panel ================= */
.hoa-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(3px);
    z-index: 300;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 16px;
}
.hoa-backdrop.is-open { display: flex; }
.hoa-panel {
    width: 780px; max-width: 100%; max-height: 90vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.hoa-panel__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.hoa-panel__title { margin: 0; font-size: 17px; font-weight: 700; }
.hoa-panel__sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.hoa-tabs {
    display: flex; gap: 4px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.hoa-tab {
    background: none; border: none; cursor: pointer;
    padding: 10px 14px;
    font-size: 13px; font-weight: 600; color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.hoa-tab:hover { color: var(--text-2); }
.hoa-tab.is-active { color: var(--primary-600); border-bottom-color: var(--primary-600); }
.hoa-panel__body { overflow-y: auto; padding: 4px 0; }
.hoa-row__canceled { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.hoa-item { border-bottom: 1px solid var(--border); }
.hoa-item:last-child { border-bottom: none; }
.hoa-row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px;
    flex-wrap: wrap;
}
.hoa-cta-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.hoa-dispute-status { font-size: 12px; font-weight: 600; }
.hoa-dispute-status--none { color: var(--text-muted); }
.hoa-dispute-status--has { color: var(--danger); }
.hoa-history-btn {
    display: inline-block;
    background: none; border: none; padding: 0;
    color: var(--primary-600); font-size: 12px; font-weight: 600; cursor: pointer;
}
.hoa-history-btn:hover { text-decoration: underline; }
.hoa-history-btn.is-open { color: var(--text-2); }

.hoa-detail { padding: 2px 20px 14px; background: var(--surface-2); }
.hoa-detail__sec { margin-top: 10px; }
.hoa-detail__h {
    font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted); font-weight: 700; margin-bottom: 4px;
}
.hoa-line {
    display: flex; align-items: center; gap: 10px;
    font-size: 12.5px; padding: 5px 0;
    border-bottom: 1px solid var(--border);
}
.hoa-line:last-child { border-bottom: none; }
.hoa-line.muted { color: var(--text-muted); border-bottom: none; }
.hoa-line__amt { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 64px; }
.hoa-tag {
    margin-left: auto; font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .03em; padding: 2px 7px; border-radius: 4px;
    background: var(--surface-muted); color: var(--text-2); white-space: nowrap;
}
.hoa-tag--succeeded, .hoa-tag--won, .hoa-tag--paid { background: var(--primary-soft); color: var(--primary-700); }
.hoa-tag--failed, .hoa-tag--lost, .hoa-tag--disputed, .hoa-tag--refunded { background: var(--danger-soft); color: var(--danger); }
.hoa-tag--needs_response, .hoa-tag--warning_needs_response, .hoa-tag--under_review { background: var(--warning-soft); color: #92400e; }
.hoa-row__client { flex: 1 1 220px; min-width: 0; }
.hoa-row__client strong { display: block; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hoa-row__client small { color: var(--text-muted); font-size: 12px; }
.hoa-row__amt { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }
.hoa-row__meta { font-size: 12px; color: var(--text-muted); }
.hoa-row__owed { font-size: 12px; font-weight: 600; color: var(--danger); margin-top: 3px; }
.hoa-row__owed--paid { color: var(--primary-700); }
.hoa-row__actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; margin-left: auto; }
.hoa-all { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.hoa-all input { width: 15px; height: 15px; cursor: pointer; }
.hoa-btns { display: flex; gap: 6px; }
.hoa-row.is-done { opacity: 0.6; }
.hoa-row__status { font-size: 12.5px; font-weight: 600; color: var(--primary-700); margin-left: auto; text-align: right; }
.hoa-row__unmatched { color: var(--warning); }

/* ================= Login ================= */
.login-wrap {
    min-height: 100vh;
    display: grid; place-items: center;
    background: var(--gradient-header);
    padding: 20px;
}
.login-card {
    width: 360px;
    max-width: 100%;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-lg);
}
.login-brand {
    display: flex; align-items: center; gap: 12px; margin-bottom: 22px;
}
.login-brand .app-header__brand-mark { width: 42px; height: 42px; font-size: 15px; }
.login-brand h1 { font-size: 20px; margin: 0; font-weight: 700; }
.login-brand small { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; display: block; }
.login-form label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; display: block; margin-bottom: 6px; }
.login-form input {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px;
    letter-spacing: 0.6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.login-form .btn { width: 100%; justify-content: center; padding: 11px; font-size: 14px; margin-top: 16px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ================= Responsive ================= */
@media (max-width: 640px) {
    /* Drop the dedicated Frequency column; show it inline under the name
       so Weekly/Biweekly stays visible. Address keeps its own full row. */
    .list-header, .list-row {
        grid-template-columns: 1.9fr 0.95fr 0.85fr 48px;
    }
    .list-header__col--freq, .row-freq { display: none; }
    .freq-inline { display: inline-flex; }
    .drawer { width: 100vw; }
}
@media (max-width: 640px) {
    .app-header { padding: 14px 16px 16px; }
    .app-header__actions .kbd, .app-header__btn span:not(.icon) { display: none; }
    .main { padding: 14px; }
    .form-grid { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dt { margin-top: 10px; }
}

.loading {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

.activity-item {
    display: flex; gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.activity-item:last-child { border-bottom: none; }
.activity-item__dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--primary); flex-shrink: 0; margin-top: 5px;
}
.activity-item__body { flex: 1; }
.activity-item__time { color: var(--text-muted); font-size: 11px; }

/* Notes rendered view */
.notes-view {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-size: 13.5px;
    line-height: 1.65;
    color: var(--text);
    white-space: normal;
    word-wrap: break-word;
    max-height: 60vh;
    overflow-y: auto;
}
.notes-view .muted { color: var(--text-muted); font-style: italic; }
.notes-view p { margin: 0 0 10px; }
.notes-view ul, .notes-view ol { margin: 0 0 10px 20px; padding: 0; }
.notes-view li { margin-bottom: 4px; }
.notes-view a { color: var(--primary-600); }

.sms-msg {
    padding: 10px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 13px;
}
.sms-msg__meta {
    display: flex;
    gap: 10px;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 4px;
    font-family: var(--font-mono);
}

/* ================= Billing tab ================= */
.bill-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.bill-summary { font-size: 12.5px; color: var(--text-muted); }
.bill-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.bill-item__body { flex: 1; min-width: 0; }
.bill-item__top { display: flex; align-items: center; gap: 8px; }
.bill-item__amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.bill-item.is-unpaid .bill-item__amt { color: var(--danger); }
.bill-item__meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.bill-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    background: var(--surface-muted);
    color: var(--text-2);
    border-radius: 4px;
    padding: 2px 6px;
}
.bill-item__actions { display: flex; gap: 4px; flex-shrink: 0; align-items: flex-start; }
.bill-check { width: 16px; height: 16px; flex-shrink: 0; cursor: pointer; align-self: center; }
.bill-pay { display: inline-flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.bill-legacy {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}
.bill-legacy input { width: 13px; height: 13px; margin: 0; cursor: pointer; }
.bill-tag--manual { background: #ede9fe; color: #5b21b6; }

/* Bulk select + mark-paid bar */
.bill-selectbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    margin-bottom: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.bill-selectall { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.bill-selectall input { width: 16px; height: 16px; cursor: pointer; }
.bill-selcount { font-size: 12px; color: var(--text-muted); }
.bill-selectbar .btn { margin-left: auto; }
@media (prefers-color-scheme: dark) { .bill-tag--manual { background: rgba(139,92,246,0.2); color: #c4b5fd; } }

.bill-form {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 12px;
}
.bill-form__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
}
.bill-form__grid label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-2);
}
.bill-form__grid label.full { grid-column: 1 / -1; }
.bill-form__hint { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--text-muted); }
.bill-form__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

@media (max-width: 640px) {
    .bill-form__grid { grid-template-columns: 1fr; }
    .bill-item { flex-wrap: wrap; }
    .bill-item__actions { width: 100%; justify-content: flex-end; }
}

/* ================= Service history tab ================= */
.svc-item {
    display: flex;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    align-items: baseline;
}
.svc-item:last-child { border-bottom: none; }
.svc-item__date {
    flex: 0 0 84px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.svc-item__body { flex: 1; min-width: 0; }
.svc-item__title { font-size: 13px; color: var(--text); }
.svc-item__meta { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.svc-rating { color: var(--warning); font-size: 11px; letter-spacing: 1px; }
.svc-paid { color: var(--primary-700); font-weight: 600; }

/* =============================================================================
   AI Assistant bar
   ============================================================================= */

.ai-bar {
    margin: 0 0 14px;
    background: linear-gradient(135deg, var(--primary-softer), transparent 60%), var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.ai-bar::before {
    content: "";
    position: absolute;
    inset: -40% -40% auto auto;
    width: 260px;
    height: 260px;
    background: radial-gradient(closest-side, rgba(16, 185, 129, 0.18), transparent 70%);
    pointer-events: none;
}
.ai-bar__row {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}
.ai-bar__icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}
.ai-bar__input {
    flex: 1;
    min-width: 0;
    border: 1px solid transparent;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 10px 14px;
    font: 500 14px/1.4 var(--font-sans);
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.ai-bar__input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.ai-bar__kbd {
    flex-shrink: 0;
    opacity: .7;
}
.ai-bar__submit { flex-shrink: 0; }
.ai-bar__saved { flex-shrink: 0; }

.ai-bar__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    position: relative;
    z-index: 1;
}
.ai-chip {
    font: 500 12px/1.2 var(--font-sans);
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.ai-chip:hover {
    border-color: var(--primary);
    color: var(--primary-700);
    background: var(--primary-softer);
}

.ai-bar__result {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--primary-soft);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius);
    position: relative;
    z-index: 1;
}
.ai-bar__result-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.ai-bar__badge {
    font: 700 10px/1 var(--font-sans);
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--primary-ink);
    background: var(--primary-soft);
    padding: 4px 7px;
    border-radius: 4px;
    flex-shrink: 0;
}
.ai-bar__badge.is-llm { background: #ddd6fe; color: #5b21b6; }
.ai-bar__badge.is-fallback { background: var(--warning-soft); color: #92400e; }
.ai-bar__summary {
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
    flex: 1;
    min-width: 200px;
}
.ai-bar__count {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.ai-bar__actions {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.ai-bar__saved-panel {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
    z-index: 1;
}
.ai-bar__saved-head {
    font: 700 11px/1.4 var(--font-sans);
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.ai-bar__saved-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.ai-saved-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 6px 4px 10px;
}
.ai-saved-item button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font: inherit;
}
.ai-saved-item__label { color: var(--text); font-weight: 500; }
.ai-saved-item__delete {
    width: 20px; height: 20px;
    border-radius: 4px;
    color: var(--text-muted);
}
.ai-saved-item__delete:hover { background: var(--danger-soft); color: var(--danger); }

/* Past-due and new badges shown in list items when AI mode is active */
.row-badge {
    display: inline-block;
    font: 700 10px/1 var(--font-sans);
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 3px 6px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}
.row-badge--overdue { background: var(--danger-soft); color: var(--danger); }
.row-badge--due-soon { background: var(--warning-soft); color: #92400e; }
.row-badge--new { background: var(--primary-soft); color: var(--primary-ink); }
.row-badge--unpaid { background: #ede9fe; color: #5b21b6; }

@media (prefers-color-scheme: dark) {
    .row-badge--due-soon { color: #fbbf24; }
    .ai-bar__badge.is-llm { background: rgba(139, 92, 246, 0.2); color: #c4b5fd; }
}

/* Responsive: stack AI bar on narrow screens */
@media (max-width: 720px) {
    .ai-bar__row { flex-wrap: wrap; }
    .ai-bar__input { order: 10; flex-basis: 100%; }
    .ai-bar__kbd { display: none; }
    .ai-bar__actions { width: 100%; justify-content: flex-end; }
}
