/* =====================================================================
   ISP Tracker — Design tokens
   Theme: "Network Operations" — a light, calm ops console with a dark
   sidebar and a signal-bar motif used throughout as the status signature.
   ===================================================================== */
:root {
    --bg: #F3F6FA;
    --surface: #FFFFFF;
    --surface-2: #F8FAFC;
    --border: #E2E8F0;

    --sidebar-start: #101828;
    --sidebar-end: #1D2939;
    --sidebar-text: #CBD5E1;
    --sidebar-text-active: #FFFFFF;

    --text: #101828;
    --text-muted: #64748B;

    --accent: #0D9488;
    --accent-dark: #0B7A70;
    --accent-soft: #CCFBF1;

    --ok: #16A34A;
    --ok-soft: #DCFCE7;
    --warn: #D97706;
    --warn-soft: #FEF3C7;
    --danger: #DC2626;
    --danger-soft: #FEE2E2;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.10);

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

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ---------------- Layout ---------------- */
.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: linear-gradient(180deg, var(--sidebar-start), var(--sidebar-end));
    color: var(--sidebar-text);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 10px 26px;
    color: #fff;
    letter-spacing: -0.01em;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, .92);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(45, 212, 191, .28), 0 7px 18px rgba(0, 0, 0, .28);
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.38); }
.brand-copy { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.brand-copy strong { font-size: 14px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; }
.brand-copy small { margin-top: 4px; color: #9EACBE; font-size: 10px; font-weight: 600; letter-spacing: .055em; text-transform: uppercase; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    color: var(--sidebar-text);
    text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: rgba(13,148,136,0.18); color: #fff; }
.nav-item.active svg { color: var(--accent); }

.sidebar-footer {
    margin-top: auto;
    font-size: 12px;
    color: #8B98AA;
    padding: 10px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-footer span { color: #B9C5D4; font-size: 10.5px; }

.main {
    padding: 28px 32px 60px;
    max-width: 1280px;
    width: 100%;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.topbar h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 2px;
}
.topbar p { margin: 0; color: var(--text-muted); font-size: 14px; }
.mobile-company-brand { display: none; }

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    min-width: 260px;
}
.search-box input {
    border: none;
    outline: none;
    font-size: 14px;
    width: 100%;
    font-family: var(--font-ui);
    background: transparent;
}
.search-box svg { color: var(--text-muted); flex-shrink: 0; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: transform .05s ease, box-shadow .15s ease, background .15s ease;
}
.btn:disabled { cursor: wait; opacity: .65; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); padding: 6px 8px; }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.btn-danger-ghost { background: transparent; color: var(--danger); padding: 6px 8px; }
.btn-danger-ghost:hover { background: var(--danger-soft); }

/* ---------------- Stat cards ---------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .stat-label {
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.stat-card .stat-value {
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.stat-card.total .stat-value { color: var(--text); }
.stat-card.active .stat-value { color: var(--ok); }
.stat-card.soon .stat-value { color: var(--warn); }
.stat-card.expired .stat-value { color: var(--danger); }

/* ---------------- AI Insights panel ---------------- */
.ai-panel {
    background: linear-gradient(135deg, #101828, #0B4F49);
    border-radius: var(--radius);
    padding: 18px 22px;
    color: #E6FFFB;
    margin-bottom: 24px;
    box-shadow: var(--shadow-md);
}
.ai-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 12px;
    color: #fff;
}
.ai-panel-header svg { color: var(--accent-soft); }
.ai-insight-list { display: flex; flex-direction: column; gap: 8px; }
.ai-insight {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
    line-height: 1.5;
    background: rgba(255,255,255,0.06);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}
.ai-insight .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.ai-insight.critical .dot { background: #F87171; }
.ai-insight.warning .dot { background: #FBBF24; }
.ai-insight.success .dot { background: #4ADE80; }
.ai-insight.info .dot { background: #5EEAD4; }
.ai-insight.ai .dot { background: #C4B5FD; }

/* ---------------- Filter chips ---------------- */
.filter-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
}
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }
.chip:hover:not(.active) { border-color: #CBD5E1; color: var(--text); }

/* ---------------- Table ---------------- */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.mobile-nav, .mobile-menu-overlay { display: none; }
table { width: 100%; border-collapse: collapse; }
thead th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 700;
    padding: 12px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

.isp-name { font-weight: 600; }
.isp-package { font-size: 12.5px; color: var(--text-muted); }
.mono { font-family: var(--font-mono); font-size: 13px; }
.contact-name { font-weight: 500; }
.contact-phone { font-size: 12.5px; color: var(--text-muted); font-family: var(--font-mono); }

/* Signal-bar status indicator — the page's signature element */
.signal-status { display: flex; align-items: center; gap: 8px; }
.signal-bars { display: flex; align-items: flex-end; gap: 2px; height: 16px; }
.signal-bars i { width: 4px; border-radius: 2px; background: var(--border); display: block; }
.signal-bars i:nth-child(1) { height: 35%; }
.signal-bars i:nth-child(2) { height: 55%; }
.signal-bars i:nth-child(3) { height: 75%; }
.signal-bars i:nth-child(4) { height: 100%; }

.signal-status.active .signal-bars i { background: var(--ok); }
.signal-status.expiring_soon .signal-bars i:nth-child(1),
.signal-status.expiring_soon .signal-bars i:nth-child(2) { background: var(--warn); }
.signal-status.expiring_soon .signal-bars i:nth-child(3),
.signal-status.expiring_soon .signal-bars i:nth-child(4) { background: var(--border); }
.signal-status.expired .signal-bars i:nth-child(1) { background: var(--danger); }
.signal-status.expired .signal-bars i:nth-child(2),
.signal-status.expired .signal-bars i:nth-child(3),
.signal-status.expired .signal-bars i:nth-child(4) { background: var(--border); }

.status-text { font-size: 12.5px; font-weight: 700; }
.status-text.active { color: var(--ok); }
.status-text.expiring_soon { color: var(--warn); }
.status-text.expired { color: var(--danger); }
.status-sub { font-size: 11.5px; color: var(--text-muted); font-family: var(--font-mono); }

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
}
.badge.active { background: var(--ok-soft); color: #14532D; }
.badge.expiring_soon { background: var(--warn-soft); color: #78350F; }
.badge.expired { background: var(--danger-soft); color: #7F1D1D; }
.badge.paid { background: var(--ok-soft); color: #14532D; }
.badge.unpaid { background: var(--warn-soft); color: #78350F; }
.badge.overdue { background: var(--danger-soft); color: #7F1D1D; }

.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ---------------- Invoices ---------------- */
.invoice-btn { position: relative; }
.invoice-count {
    position: absolute; top: -2px; right: -2px;
    background: var(--accent); color: #fff;
    font-size: 10px; font-weight: 700; line-height: 1;
    min-width: 15px; height: 15px; border-radius: 999px;
    display: none; align-items: center; justify-content: center;
    font-family: var(--font-mono); padding: 0 3px;
}
.invoice-count.show { display: flex; }

.invoice-modal-body { padding: 0 20px 20px; }
.invoice-modal { max-width: 580px; }
.invoice-tabs {
    display: flex; gap: 4px; border-bottom: 1px solid var(--border);
    margin: 0 -20px 20px; padding: 0 20px;
}
.invoice-tab {
    appearance: none; border: 0; border-bottom: 2px solid transparent;
    padding: 11px 10px 9px; background: transparent; color: var(--text-muted);
    font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.invoice-tab:hover { color: var(--text); }
.invoice-tab.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.invoice-section-heading { margin-bottom: 14px; }
.invoice-section-heading h3 { margin: 0 0 3px; font-size: 16px; }
.invoice-section-heading p { margin: 0; color: var(--text-muted); font-size: 13px; }
.invoice-panel[hidden] { display: none; }

.invoice-upload-box {
    max-width: 540px;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    background: linear-gradient(135deg, var(--surface-2), #F1FAF8);
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
.invoice-upload-box h4 { margin: 0 0 12px; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.invoice-upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px 12px; margin-bottom: 14px; }
.invoice-upload-grid .full { grid-column: 1 / -1; }
.invoice-upload-box .field label { margin-bottom: 5px; font-size: 12px; }
.invoice-upload-box .field input, .invoice-upload-box .field select { padding: 8px 10px; font-size: 13px; }
.invoice-upload-box .btn-primary { min-height: 38px; padding: 8px 14px; }
.file-input-row {
    display: flex; align-items: center; gap: 10px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 8px 10px; background: var(--surface); font-size: 13px; color: var(--text-muted);
}
.file-input-row input[type=file] { font-size: 13px; font-family: var(--font-ui); }
.file-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

.invoice-list { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.invoice-item {
    display: flex; align-items: center; gap: 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 10px 12px; background: var(--surface);
}
.invoice-icon {
    width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
    background: var(--accent-soft); color: var(--accent-dark);
    display: flex; align-items: center; justify-content: center;
}
.invoice-info { flex: 1; min-width: 0; }
.invoice-filename { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.invoice-meta { font-size: 11.5px; color: var(--text-muted); font-family: var(--font-mono); }
.invoice-isp-tag { font-size: 11px; font-weight: 700; color: var(--accent-dark); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; display: inline-block; margin-right: 6px; }
.invoice-actions { display: flex; gap: 2px; flex-shrink: 0; }
.invoice-download { gap: 5px; }
.invoice-empty { text-align: center; padding: 30px 10px; color: var(--text-muted); font-size: 13.5px; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; color: var(--border); }
.empty-state h3 { color: var(--text); margin: 0 0 6px; }

/* ---------------- Modal ---------------- */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(16, 24, 40, 0.5);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
    overflow-y: auto;
    z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 560px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}
.invoice-modal .modal-header { padding: 16px 20px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-body { padding: 22px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-body .full { grid-column: 1 / -1; }
.modal-footer {
    padding: 16px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: var(--surface-2);
}

.field label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.field input, .field select, .field textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    font-size: 14px;
    font-family: var(--font-ui);
    outline: none;
    background: var(--surface);
    color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 60px; }

/* Electricity facility, meter and consumption views */
.electricity-modal { max-width: 760px; }
.electricity-modal [data-close-modal="electricity-modal"] { display: none; }
.invoice-modal [data-close-modal="payment-invoices-modal"] { display: none; }
.back-button {
    font-size: 27px;
    font-weight: 800;
    line-height: 1;
}
.electricity-body { min-height: 390px; }
.electricity-breadcrumb { display: flex; align-items: center; gap: 7px; min-height: 34px; margin-bottom: 12px; color: var(--text-muted); font-size: 12px; }
.electricity-breadcrumb button { border: 0; padding: 3px 0; background: transparent; color: var(--accent-dark); font: 600 12px var(--font-ui); cursor: pointer; }
.electricity-breadcrumb button:disabled { color: var(--text-muted); cursor: default; }
.facility-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.facility-card, .meter-card { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); text-align: left; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
.facility-card:hover, .meter-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.facility-card { min-height: 94px; padding: 16px; display: flex; flex-direction: column; justify-content: space-between; }
.facility-card strong { font-size: 15px; }
.facility-card span { display: flex; justify-content: space-between; color: var(--text-muted); font-size: 12px; }
.facility-card b, .meter-next { color: var(--accent-dark); font-size: 19px; line-height: 12px; }
.meter-list { display: grid; gap: 8px; }
.meter-card { display: grid; grid-template-columns: 108px 1fr auto; align-items: center; gap: 10px; padding: 13px 15px; }
.meter-number { color: var(--accent-dark); font-weight: 700; font-size: 13px; }
.meter-area { font-size: 14px; }
.usage-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin: 12px 0; }
.usage-stat { border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; }
.usage-stat span { display: block; color: var(--text-muted); font-size: 11px; font-weight: 600; margin-bottom: 5px; }
.usage-stat strong { font-size: 18px; }
.usage-stat small { font-size: 10px; color: var(--text-muted); font-weight: 500; }
.usage-analysis { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; border-radius: var(--radius-sm); background: #effaf5; border-left: 3px solid var(--ok); font-size: 13px; margin-bottom: 13px; }
.usage-analysis.increased { background: #fff6e7; border-color: #d97706; }
.usage-analysis.no_data { background: var(--surface-2); border-color: var(--text-muted); }
.usage-analysis span { color: var(--text-muted); }
.usage-report-controls { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; margin: 13px 0 9px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.usage-report-controls .field label { margin-bottom: 4px; font-size: 11px; }
.usage-report-actions { display: flex; gap: 7px; }
.usage-report-actions .btn { min-height: 38px; white-space: nowrap; }
.usage-report-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-bottom: 13px; }
.usage-report-summary > div { padding: 11px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); border: 1px solid #99F6E4; }
.usage-report-summary span { display: block; color: var(--text-muted); font-size: 11px; font-weight: 600; margin-bottom: 4px; }
.usage-report-summary strong { font-size: 17px; }
.usage-periods { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 13px 0; }
.usage-period { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.usage-period h4 { margin: 0; padding: 11px 13px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 13px; }
.usage-period-list { max-height: 190px; overflow-y: auto; }
.usage-period-list > div { display: flex; justify-content: space-between; gap: 10px; padding: 9px 13px; border-bottom: 1px solid var(--border); font-size: 12px; }
.usage-period-list > div:last-child { border-bottom: 0; }
.usage-period-list span { color: var(--text-muted); }
.usage-period-list small { font-size: 10px; color: var(--text-muted); font-weight: 500; }
.usage-period-list p { padding: 9px 13px; margin: 0; color: var(--text-muted); font-size: 12px; }
.meter-reading-help { margin: 10px 0; color: var(--text-muted); font-size: 12px; line-height: 1.45; }
.usage-history-heading { margin-top: 18px; }
.usage-history { display: grid; gap: 7px; }
.usage-row { display: grid; grid-template-columns: 1.1fr 1fr 1.35fr auto; gap: 12px; align-items: center; padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 12px; }
.usage-row div { display: flex; flex-direction: column; gap: 2px; }
.usage-row small { color: var(--text-muted); }
.usage-row b { font-weight: 700; }
.usage-delete { min-width: 34px; min-height: 34px; padding: 7px; color: var(--danger); }
.purchase-history { display: grid; gap: 7px; margin: 10px 0 14px; }
.purchase-history-heading { color: var(--text-muted); font-size: 12px; font-weight: 700; }
.purchase-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 12px; }
.purchase-row strong { color: var(--ok); }

.toast-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}
.toast {
    background: var(--text);
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    box-shadow: var(--shadow-md);
    animation: slideIn .2s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--ok); }
@keyframes slideIn { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: translateY(0); } }

@media (max-width: 860px) {
    body { padding-bottom: 78px; }
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .main { padding: 22px 16px 24px; }
    .topbar { align-items: stretch; margin-bottom: 20px; }
    .topbar h1 { font-size: 24px; line-height: 1.15; }
    .topbar p { font-size: 13px; line-height: 1.5; margin-top: 6px; }
    .mobile-company-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; }
    .mobile-company-brand .brand-mark { width: 38px; height: 38px; flex-basis: 38px; }
    .mobile-company-brand > span:last-child { display: flex; flex-direction: column; line-height: 1.1; }
    .mobile-company-brand strong { font-size: 13px; letter-spacing: -.01em; }
    .mobile-company-brand small { margin-top: 3px; color: var(--text-muted); font-size: 9.5px; font-weight: 700; letter-spacing: .055em; text-transform: uppercase; }
    .topbar > div:last-child { width: 100%; display: grid !important; grid-template-columns: 1fr auto; gap: 10px !important; }
    .search-box { min-width: 0; padding: 11px 12px; border-radius: 10px; }
    .btn { min-height: 42px; padding: 10px 13px; }
    .btn-primary { box-shadow: 0 6px 14px rgba(13,148,136,.20); }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
    .stat-card { padding: 14px; border-radius: 14px; }
    .stat-card .stat-label { font-size: 10.5px; margin-bottom: 6px; }
    .stat-card .stat-value { font-size: 25px; }
    .ai-panel { padding: 16px; margin-bottom: 18px; border-radius: 14px; }
    .ai-insight { font-size: 13px; padding: 9px 10px; }
    .filter-row { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; margin-right: -16px; padding-right: 16px; }
    .chip { white-space: nowrap; padding: 8px 13px; }
    .table-wrap { border: 0; background: transparent; box-shadow: none; overflow: visible; }
    table, tbody, tr, td { display: block; width: 100%; }
    thead { display: none; }
    tbody { display: grid; gap: 12px; }
    tbody tr { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
    tbody td { border: 0; padding: 7px 0; min-height: 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
    tbody td:first-child { display: block; padding: 0 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 5px; }
    tbody td:not(:first-child)::before { content: attr(data-label); color: var(--text-muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-family: var(--font-ui); }
    tbody tr:hover { background: var(--surface); }
    .isp-name { font-size: 15px; }
    .contact-name, .mono { text-align: right; }
    .signal-status { justify-content: flex-end; }
    .actions-cell { padding-top: 12px !important; margin-top: 4px; border-top: 1px solid var(--border) !important; }
    .actions-cell::before { display: none; }
    .row-actions { width: 100%; justify-content: flex-end; gap: 7px; }
    .row-actions .btn { min-width: 40px; min-height: 40px; justify-content: center; }
    .empty-state { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 42px 20px; }
    /* Keep every mobile dialog fully above the fixed bottom navigation. */
    .modal-overlay { align-items: flex-end; padding: 0 0 calc(68px + env(safe-area-inset-bottom)); background: rgba(16,24,40,.58); }
    .modal { max-width: none; max-height: min(92dvh, calc(100dvh - 68px - env(safe-area-inset-bottom))); border-radius: 20px 20px 0 0; overflow-y: auto; }
    .modal-header { position: sticky; top: 0; z-index: 1; background: var(--surface); padding: 16px 18px; }
    .modal-body { grid-template-columns: 1fr; padding: 18px; gap: 14px; }
    .modal-footer { position: sticky; bottom: 0; padding: 13px 18px; }
    .modal-footer .btn { flex: 1; justify-content: center; }
    .field input, .field select, .field textarea { min-height: 44px; font-size: 16px; }
    .invoice-upload-grid { grid-template-columns: 1fr; }
    .invoice-upload-grid .full { grid-column: auto; }
    .invoice-modal-body { padding: 0 16px 18px; }
    .invoice-tabs { margin: 0 -16px 18px; padding: 0 16px; }
    .invoice-upload-box { padding: 14px; }
    .invoice-item { align-items: flex-start; padding: 12px; }
    .invoice-actions .btn { min-height: 38px; }
    .invoice-actions .btn-danger-ghost { min-width: 38px; }
    .facility-grid, .usage-stats { grid-template-columns: 1fr 1fr; }
    .usage-periods { grid-template-columns: 1fr; }
    .usage-report-controls { grid-template-columns: 1fr 1fr; }
    .usage-report-actions { grid-column: 1 / -1; }
    .usage-report-actions .btn { flex: 1; justify-content: center; }
    .usage-report-summary { grid-template-columns: 1fr 1fr; }
    .usage-row { grid-template-columns: 1fr; gap: 5px; }
    .toast-wrap { left: 16px; right: 16px; bottom: 88px; }
    .toast { text-align: center; }
    .mobile-nav { position: fixed; z-index: 60; left: 0; right: 0; bottom: 0; height: 68px; display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; background: rgba(255,255,255,.96); border-top: 1px solid var(--border); box-shadow: 0 -6px 18px rgba(16,24,40,.08); backdrop-filter: blur(12px); padding: 5px 6px env(safe-area-inset-bottom); }
    .mobile-nav-item { appearance: none; border: 0; background: transparent; color: var(--text-muted); min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font: 600 10px var(--font-ui); cursor: pointer; }
    .mobile-nav-item.active { color: var(--accent-dark); }
    .mobile-add-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 24px; line-height: 1; box-shadow: 0 4px 10px rgba(13,148,136,.25); }
    .mobile-menu-overlay { position: fixed; inset: 0; z-index: 70; align-items: flex-end; background: rgba(16,24,40,.44); }
    .mobile-menu-overlay.open { display: flex; }
    .mobile-menu-panel { width: 100%; padding: 18px 16px calc(80px + env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; background: var(--surface); box-shadow: 0 -12px 36px rgba(16,24,40,.18); }
    .mobile-menu-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-size: 16px; }
    .mobile-menu-heading button { border: 0; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); color: var(--text); font-size: 24px; line-height: 1; cursor: pointer; }
    .mobile-menu-item { width: 100%; display: flex; flex-direction: column; gap: 3px; padding: 14px 12px; border: 0; border-top: 1px solid var(--border); background: transparent; text-align: left; color: var(--text); font: 600 14px var(--font-ui); cursor: pointer; }
    .mobile-menu-item small { color: var(--text-muted); font-size: 12px; font-weight: 400; }
}

@media (min-width: 861px) {
    .main { min-width: 0; }
    .topbar > div:last-child { display: flex; }
    #isp-modal .modal { max-width: 490px; }
    .invoice-modal { max-width: 490px; }
    .electricity-modal { max-width: 690px; }
    #isp-modal .modal-header, .invoice-modal .modal-header { padding: 11px 16px; }
    #isp-modal .modal-header h2, .invoice-modal .modal-header h2 { font-size: 15px; }
    #isp-modal .modal-body { padding: 11px 16px; gap: 7px 10px; }
    #isp-modal .modal-footer { padding: 8px 16px; }
    #isp-modal .modal-footer .btn { min-height: 34px; padding: 7px 12px; }
    #isp-modal .field label, .invoice-upload-box .field label { margin-bottom: 2px; font-size: 11px; }
    #isp-modal .field input, #isp-modal .field select, #isp-modal .field textarea,
    .invoice-upload-box .field input, .invoice-upload-box .field select { padding: 6px 9px; font-size: 13px; }
    #isp-modal .field textarea { min-height: 48px; }
    .invoice-modal-body { padding: 0 16px 12px; }
    .invoice-tabs { margin: 0 -16px 11px; padding: 0 16px; }
    .invoice-tab { padding: 7px 8px 6px; font-size: 12px; }
    .invoice-section-heading { margin-bottom: 7px; }
    .invoice-section-heading h3 { font-size: 15px; }
    .invoice-section-heading p { font-size: 12px; }
    .invoice-upload-box { max-width: 455px; padding: 9px 11px; }
    .invoice-upload-grid { gap: 6px 8px; margin-bottom: 8px; }
    .file-input-row { padding: 5px 8px; }
    .file-hint { font-size: 10.5px; }
    .invoice-upload-box .btn-primary { min-height: 34px; padding: 6px 12px; }
}

@media (max-width: 420px) {
    .topbar > div:last-child { grid-template-columns: 1fr; }
    .topbar > div:last-child .btn-primary { justify-content: center; }
    .stats-grid { gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-card .stat-value { font-size: 23px; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
