/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent horizontal scroll globally */
html {
    overflow-x: hidden;
    width: 100%;
}

body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* CSS Variables for Light and Dark Mode */
:root {
    /* Light mode colors */
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f5f5f7;
    --text-primary: #333333;
    --text-secondary: #86868b;
    --text-tertiary: #1d1d1f;
    --border-color: #e5e5e7;
    --border-input: #d2d2d7;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.15);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.1);
    --overlay-bg: rgba(0, 0, 0, 0.3);
    --hover-bg: #e5e5e7;
    --accent-blue: #FF3B30;
    --accent-blue-dark: #CC2E24;
    --accent-green: #34C759;
    --accent-red: #FF3B30;
    --accent-orange: #FF9500;
    /* Star rating gold, and the lime used in report rating bands. */
    --star-gold: #E8A400;
    --accent-lime: #7CB342;
    /* Status notices (GMB admin panels). Tinted surfaces need their own
       tokens: the original pastels were unreadable on a dark ground. */
    --notice-info-bg: #E3F2FD;   --notice-info-border: #2196F3;
    --notice-warn-bg: #FFF9E6;   --notice-warn-border: #FFC107;
    --notice-ok-bg:   #E8F5E9;   --notice-ok-border:   #4CAF50;  --notice-ok-text: #2E7D32;
}

body.dark-mode {
    /* Dark mode colors */
    --bg-primary: #000000;
    --bg-secondary: #1c1c1e;
    --bg-tertiary: #2c2c2e;
    --text-primary: #f5f5f7;
    --text-secondary: #98989d;
    --text-tertiary: #ffffff;
    --border-color: #38383a;
    --border-input: #48484a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.5);
    --overlay-bg: rgba(0, 0, 0, 0.7);
    --hover-bg: #2c2c2e;
    --accent-blue: #0A84FF;
    --accent-blue-dark: #0066CC;
    --accent-green: #30D158;
    --star-gold: #FFD60A;
    --accent-lime: #A8D65C;
    --notice-info-bg: #10263A;   --notice-info-border: #4DA3FF;
    --notice-warn-bg: #332A10;   --notice-warn-border: #E0A800;
    --notice-ok-bg:   #12301A;   --notice-ok-border:   #45C463;  --notice-ok-text: #7FE0A0;
    --accent-red: #FF453A;
    --accent-orange: #FF9F0A;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Mobile-specific styles */
@media (max-width: 768px) {
    body {
        font-size: 16px; /* Prevents iOS zoom on input focus */
    }
}

/* Screen Management */
.screen {
    min-height: 100vh;
}

/* Login Screen */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-header {
    text-align: center;
    margin-bottom: 24px;
}

.login-form {
    background: var(--bg-secondary);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
}

.login-header h1 {
    color: var(--text-tertiary);
    font-size: 28px;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 16px;
}

/* Logo Styles */
.app-logo {
    width: 120px;
    height: 120px;
    margin-bottom: 1rem;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.header-logo {
    width: 40px;
    height: 40px;
    margin-right: 0.75rem;
    border-radius: 8px;
    vertical-align: middle;
}

.header-left {
    display: flex;
    align-items: center;
}

/* Dashboard Header */
.dashboard-header {
    background: var(--bg-secondary);
    padding: 20px 32px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dashboard-header h1 {
    font-size: 24px;
    color: var(--text-tertiary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

#user-name {
    font-weight: 500;
    color: var(--text-primary);
}

/* Mobile User Info (only in mobile menu) */
.mobile-user-info {
    display: none;
    padding: 20px 16px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
}

.mobile-user-info #mobile-user-name {
    display: block;
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.mobile-menu-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.mobile-menu-actions .btn {
    flex: 1;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
    background: var(--bg-secondary);
    border: none;
    padding: 12px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    width: 48px;
    height: 48px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
}

.mobile-menu-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-primary);
    transition: all 0.3s ease;
    border-radius: 2px;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Navigation Tabs */
.tab-nav {
    background: var(--bg-secondary);
    padding: 0 32px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 32px;
}

.tab-btn {
    padding: 16px 0;
    background: none;
    border: none;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
}

/* Tab Content */
.tab-content {
    display: none;
    padding: 32px;
}

.tab-content.active {
    display: block;
}

.content-container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.card h2 {
    margin-bottom: 24px;
    color: var(--text-tertiary);
    font-size: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.filters {
    display: flex;
    gap: 12px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Checkboxes and radios are excluded: they are widgets, not text fields.
   Giving them padding, a border, a background and an 8px radius turned
   every one of them into an empty rounded box with the native control
   squeezed to nothing inside it - a radio rendered as a square, and no
   tick was ever visible. */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
select,
textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s, background-color 0.3s;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: var(--ring);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: var(--brand);
    color: white;
}

.btn-primary:hover {
    background: var(--brand-dark);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-input);
}

.btn-secondary:hover {
    background: var(--hover-bg);
}

.btn-success {
    background: var(--accent-green);
    color: white;
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Dark Mode Toggle Button */
.btn-icon {
    background: none;
    border: none;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    color: var(--text-primary);
}

.btn-icon:hover {
    background: var(--hover-bg);
}

.btn-icon svg {
    width: 24px;
    height: 24px;
}

/* Google Sign-in Button */
.google-signin-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: 20px;
}

.divider {
    text-align: center;
    margin: 20px 0;
    position: relative;
}

.divider span {
    background: var(--bg-secondary);
    padding: 0 10px;
    color: var(--text-secondary);
    font-size: 14px;
    position: relative;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border-color);
}

/* Message Preview */
.message-preview {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.message-preview h4 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.preview-content {
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Form Actions */
.form-actions {
    margin-top: 24px;
    text-align: center;
}

/* Result Messages */
.result-message {
    margin-top: 16px;
    padding: 12px;
    border-radius: 8px;
}

.result-message.success {
    background: #d4f4dd;
    color: #1d4d1f;
    border: 1px solid #34C759;
}

.result-message.error {
    background: #ffebea;
    color: #d70015;
    border: 1px solid #FF3B30;
}

.error-message {
    color: var(--accent-red);
    margin-top: 8px;
    font-size: 14px;
}

/* Statistics */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.stat-card h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-value {
    font-size: 32px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.stat-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Desktop/Mobile Visibility */
.desktop-only {
    display: block !important;
}

.requests-table.desktop-only {
    display: table !important;
    width: 100%;
}

.mobile-only {
    display: none !important;
}

/* Ensure desktop table is always displayed as table */
.requests-table.desktop-only table {
    display: table;
    width: 100%;
}

/* Tables */
.requests-table {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

td {
    font-size: 14px;
}

tr:hover {
    background: var(--bg-tertiary);
}

.loading-row td {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Mobile Request Cards */
.requests-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.request-card {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid var(--border-color);
}

.request-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.request-customer {
    flex: 1;
}

.request-customer-name {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.request-customer-phone {
    font-size: 13px;
    color: var(--text-secondary);
}

.request-location {
    text-align: right;
    font-size: 13px;
    color: var(--text-secondary);
}

.request-card-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.request-info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.request-info-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.request-info-value {
    font-size: 14px;
    color: var(--text-tertiary);
}

.request-card-footer {
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.request-card-footer .btn {
    width: 100%;
}

.loading-card {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

/* Status Badges */
.status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
}

.status-sent {
    background: #d4f4dd;
    color: #1d4d1f;
}

.status-failed {
    background: #ffebea;
    color: #d70015;
}

.status-clicked {
    background: #dff4ff;
    color: #0066cc;
}

.status-completed {
    background: #f0e6ff;
    color: #5856d6;
}

.status-pending {
    background: var(--bg-tertiary);
    color: #888;
}

/* Loading Spinner */
.spinner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

.spinner-circle {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--brand);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.toast {
    background: var(--bg-secondary);
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    margin-bottom: 12px;
    min-width: 300px;
    border-left: 4px solid var(--brand);
    animation: slideIn 0.3s ease-out;
}

.toast.success {
    border-left-color: #34C759;
}

.toast.error {
    border-left-color: #FF3B30;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Location Stats */
.location-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.location-stat {
    padding: 20px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tertiary);
}

.location-stat h4 {
    margin-bottom: 12px;
    color: var(--text-primary);
}

.location-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    text-align: center;
}

.location-metric {
    font-size: 14px;
}

.location-metric .value {
    display: block;
    font-size: 20px;
    font-weight: 600;
    color: var(--brand);
}

.location-metric .label {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Mobile Button Styles */
@media (max-width: 768px) {
    .btn {
        padding: 16px 20px;
        font-size: 16px;
        width: 100%;
        max-width: 100%;
        margin-bottom: 10px;
        white-space: normal;
        word-wrap: break-word;
    }

    .btn-sm {
        padding: 10px 16px;
        font-size: 14px;
    }

    input[type="tel"],
    input[type="text"],
    input[type="email"],
    input[type="date"],
    input[type="url"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden;
        width: 100vw;
    }

    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: flex;
    }

    .dashboard-header {
        padding: 16px 20px;
        padding-right: 70px; /* Space for hamburger button */
        max-width: 100vw;
        overflow-x: hidden;
    }

    .dashboard-header h1 {
        font-size: 20px;
    }

    /* Hide user name and logout button on mobile header */
    .header-right #user-name,
    .header-right #logout-btn {
        display: none !important;
    }

    /* Keep dark mode toggle visible in header on mobile */
    .header-right {
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    /* Show mobile user info in hamburger menu */
    .mobile-user-info {
        display: block !important;
    }

    /* Mobile navigation */
    .tab-nav {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        height: 100vh;
        background: var(--bg-secondary);
        padding: 80px 20px 20px 20px;
        flex-direction: column;
        gap: 0;
        box-shadow: -4px 0 20px rgba(0,0,0,0.15);
        transition: right 0.3s ease;
        z-index: 1000;
        overflow-y: auto;
        border-bottom: none;
    }

    .tab-nav.mobile-open {
        right: 0;
    }

    .tab-btn {
        width: 100%;
        text-align: left;
        padding: 16px 12px;
        border-bottom: 1px solid var(--border-color);
        border-left: 3px solid transparent;
    }

    .tab-btn.active {
        border-bottom-color: var(--border-color);
        border-left-color: var(--brand);
        background: var(--bg-tertiary);
    }

    /* Mobile overlay */
    .mobile-nav-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }

    .mobile-nav-overlay.active {
        display: block;
    }

    .tab-content {
        padding: 16px;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .content-container {
        max-width: 100vw;
        overflow-x: hidden;
    }

    .card {
        padding: 20px 16px;
        margin-bottom: 16px;
        max-width: 100%;
        overflow-x: hidden;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .form-group {
        margin-bottom: 16px;
        max-width: 100%;
        width: 100%;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .form-actions {
        margin-top: 20px;
        width: 100%;
    }

    .form-actions .btn {
        width: 100%;
        box-sizing: border-box;
    }

    /* Fix toast notifications on mobile */
    .toast {
        min-width: unset;
        width: calc(100% - 32px);
        max-width: 100%;
        left: 16px;
        right: 16px;
    }

    /* Fix location stats grid on mobile */
    .location-stats {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    /* Ensure all inputs and selects don't overflow */
    input, select, textarea, button {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Fix message preview on mobile */
    .message-preview {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        padding: 12px;
        overflow-wrap: break-word;
        word-wrap: break-word;
    }

    .preview-content {
        width: 100%;
        max-width: 100%;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Fix filters on mobile */
    .filters select {
        width: 100%;
        max-width: 100%;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .card-header h2 {
        font-size: 18px;
        margin-bottom: 0;
    }

    .filters {
        flex-direction: column;
        width: 100%;
        gap: 12px;
    }

    .filter-select {
        width: 100%;
    }

    /* Hide table on mobile, show cards */
    .desktop-only {
        display: none !important;
    }

    .requests-table.desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: block !important;
    }

    /* Ensure tables don't cause horizontal scroll */
    .requests-table {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        width: 100%;
        max-width: 100%;
    }

    /* Fix request cards on mobile */
    .request-card {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        margin-bottom: 12px;
    }

    /* Fix any fixed-width elements */
    .btn, button, .btn-primary, .btn-secondary {
        max-width: 100%;
        white-space: normal;
        word-wrap: break-word;
    }

    /* Table responsiveness (if we need it later) */
    .requests-table:not(.desktop-only) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        display: block;
    }

    .requests-table table {
        min-width: 600px;
        font-size: 13px;
    }

    th, td {
        padding: 10px 8px;
        font-size: 12px;
        white-space: nowrap;
    }

    /* Message preview on mobile */
    .message-preview {
        margin-bottom: 20px;
        padding: 12px;
        overflow-wrap: break-word;
        word-wrap: break-word;
    }

    .preview-content {
        font-size: 14px;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Result messages */
    .result-message {
        margin-top: 16px;
        padding: 12px;
        font-size: 14px;
        word-break: break-word;
    }
}
/* ============================================
   GMB ADMIN & REVIEWS UI STYLES
   ============================================ */

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 0;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 24px 24px 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-tertiary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--hover-bg);
    color: var(--text-tertiary);
}

.modal-content form {
    padding: 24px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

/* Review Card Styles */
.reviews-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.review-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    border: 1px solid transparent;
}

.review-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--brand);
}

.review-card-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.reviewer-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
}

.reviewer-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.review-card-info {
    flex: 1;
    min-width: 0;
}

.reviewer-name {
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.review-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.review-stars {
    color: var(--accent-red) !important;
    font-size: 16px;
    letter-spacing: 2px;
}

body.dark-mode .review-stars {
    color: #FF453A !important;
}

.review-location {
    display: flex;
    align-items: center;
    gap: 4px;
}

.review-date {
    font-size: 13px;
}

.review-comment {
    margin: 16px 0;
    line-height: 1.6;
    color: var(--text-tertiary);
}

.review-match-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin: 16px 0;
    font-size: 14px;
}

.match-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.match-badge.high {
    background: #E8F5E9;
    color: #2E7D32;
}

.match-badge.medium {
    background: #FFF3E0;
    color: #F57C00;
}

.match-badge.low {
    background: #FFEBEE;
    color: #C62828;
}

.match-badge.manual {
    background: #E3F2FD;
    color: #1976D2;
}

.match-badge.unmatched {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.review-reply {
    margin-top: 16px;
    padding: 16px;
    background: var(--brand-tint);
    border-left: 3px solid var(--brand);
    border-radius: 8px;
}

.reply-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--brand);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.reply-text {
    color: var(--text-tertiary);
    line-height: 1.6;
}

.review-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 14px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* GMB Locations List */
.gmb-locations-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gmb-location-card {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    transition: all 0.2s;
}

.gmb-location-card:hover {
    background: var(--hover-bg);
}

.gmb-location-info {
    flex: 1;
}

.gmb-location-name {
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.gmb-location-id {
    font-size: 13px;
    color: var(--text-secondary);
    font-family: 'SF Mono', Monaco, monospace;
}

.gmb-location-stats {
    display: flex;
    gap: 20px;
    margin-top: 12px;
}

.gmb-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.gmb-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.gmb-stat-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-tertiary);
}

.gmb-location-status {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.status-badge {
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.active {
    background: #E8F5E9;
    color: #2E7D32;
}

.status-badge.disabled {
    background: #FFEBEE;
    color: #C62828;
}

.status-badge.error {
    background: #FFF3E0;
    color: #F57C00;
}

.gmb-location-actions {
    display: flex;
    gap: 8px;
}

/* Sync Logs */
.sync-logs-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sync-log-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 14px;
}

.sync-log-time {
    color: var(--text-secondary);
    min-width: 180px;
}

.sync-log-stats {
    display: flex;
    gap: 20px;
    flex: 1;
    justify-content: center;
}

.sync-log-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sync-log-stat-value {
    font-weight: 600;
    color: var(--text-tertiary);
}

.sync-log-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.sync-status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    min-width: 90px;
    text-align: center;
}

.sync-status-badge.completed {
    background: #E8F5E9;
    color: #2E7D32;
}

.sync-status-badge.running {
    background: #E3F2FD;
    color: #1976D2;
}

.sync-status-badge.failed {
    background: #FFEBEE;
    color: #C62828;
}

.sync-status-badge.partial {
    background: #FFF3E0;
    color: #F57C00;
}

/* Review Preview in Modals */
.review-preview {
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin-bottom: 20px;
}

.review-preview-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.review-preview-stars {
    color: var(--accent-red) !important;
    font-size: 18px;
}

body.dark-mode .review-preview-stars {
    color: #FF453A !important;
}

.review-preview-comment {
    line-height: 1.6;
    color: var(--text-tertiary);
}

/* Response Templates */
.response-templates {
    margin: 16px 0;
}

.response-templates label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.template-buttons {
    display: flex;
    gap: 8px;
}

/* Match Candidates */
.match-candidates {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 16px;
}

.match-candidate {
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.match-candidate:hover {
    background: var(--hover-bg);
    border-color: var(--brand);
}

.match-candidate-name {
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.match-candidate-meta {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    gap: 12px;
}

.match-score {
    display: inline-block;
    padding: 2px 8px;
    background: var(--brand);
    color: white;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

/* Filter Select Styling */
.filter-select {
    padding: 10px 14px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-tertiary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 160px;
}

.filter-select:hover {
    border-color: var(--brand);
}

.filter-select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: var(--ring);
}

/* Loading States */
.loading-text {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.empty-state-text {
    color: var(--text-secondary);
    font-size: 14px;
    max-width: 400px;
    margin: 0 auto 24px;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .review-card-header {
        flex-direction: column;
    }
    
    .review-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    
    .gmb-location-card {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .gmb-location-status {
        align-items: flex-start;
        width: 100%;
    }
    
    .sync-log-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .sync-log-stats {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    
    .modal-content {
        width: 95%;
        max-height: 95vh;
    }
    
    .filters {
        grid-template-columns: 1fr;
    }
}

/* Character Counter */
#reply-char-count {
    font-weight: 600;
    color: var(--brand);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.review-card,
.gmb-location-card,
.sync-log-item {
    animation: fadeIn 0.3s ease-out;
}

/* Notification Badge */
.notification-badge {
    display: inline-block;
    background: var(--brand);
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}


/* Leaderboard Styles */
.leaderboard-table {
    overflow-x: auto;
    margin-top: 20px;
}

.leaderboard-table table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
}

.leaderboard-table thead {
    background: var(--bg-tertiary);
}

.leaderboard-table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-tertiary);
    border-bottom: 2px solid var(--border-color);
}

.leaderboard-table td {
    padding: 16px 12px;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-table tbody tr {
    transition: background 0.2s;
}

.leaderboard-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.leaderboard-table tbody tr.highlight-row {
    background: linear-gradient(90deg, #fff9e6 0%, #ffffff 100%);
}

.leaderboard-table tbody tr.highlight-row:hover {
    background: linear-gradient(90deg, #fff4cc 0%, #f8f9fa 100%);
}

/* Performance summary cards */
#performance-summary.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

#performance-summary .stat-card {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    text-align: center;
}

#performance-summary .stat-card h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

#performance-summary .stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-tertiary);
    margin: 8px 0;
}

#performance-summary .stat-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Mobile responsiveness for leaderboard */
@media (max-width: 768px) {
    .leaderboard-table {
        font-size: 14px;
    }

    .leaderboard-table th,
    .leaderboard-table td {
        padding: 8px 6px;
    }

    #performance-summary.stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 12px;
    }

    #performance-summary .stat-card {
        padding: 16px;
    }

    #performance-summary .stat-value {
        font-size: 24px;
    }
}

/* ============================================================
   Users Management
   ============================================================ */

.users-container {
    background: var(--bg-secondary);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table thead {
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
}

.users-table th {
    padding: 16px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

.users-table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.users-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.requests-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.requests-table-wrapper .requests-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.requests-table-wrapper .requests-table th,
.requests-table-wrapper .requests-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color, #f0f0f0);
    font-size: 13px;
    white-space: nowrap;
}

.requests-table-wrapper .requests-table thead {
    background: var(--bg-tertiary, #f8f9fa);
}

.requests-table-wrapper .requests-table th {
    font-weight: 600;
    color: var(--text-secondary, #666);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.requests-table-wrapper .requests-table tbody tr:hover {
    background: var(--hover-bg, #f8f9fa);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 16px;
}

/* Role badges */
.role-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.role-admin {
    background: #ffebee;
    color: #c62828;
}

.role-manager {
    background: #e3f2fd;
    color: #1565c0;
}

.role-tech {
    background: #f3e5f5;
    color: #6a1b9a;
}

/* Status badges in users table */
.status-active {
    background: #e8f5e9;
    color: #2e7d32;
}

.status-inactive {
    background: #f5f5f5;
    color: #757575;
}

/* Location checkboxes in modal */
.locations-checkboxes {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    background: var(--bg-tertiary);
}

.location-checkbox {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
    gap: 10px;
    min-height: 32px;
}

.location-checkbox:hover {
    background: var(--hover-bg);
}

.location-checkbox input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    accent-color: var(--accent-red);
}

.location-checkbox span {
    font-size: 14px;
    line-height: 1.4;
    flex: 1;
}

/* Switch container for active toggle */
.switch-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-input);
    transition: .3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--brand);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 2px;
}

.user-email {
    font-size: 13px;
    color: var(--text-secondary);
}

.user-role-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    text-transform: capitalize;
}

.user-role-badge.admin {
    background: #ffebee;
    color: #d32f2f;
}

.user-role-badge.manager {
    background: #fff3e0;
    color: #f57c00;
}

.user-role-badge.technician {
    background: #e8f5e9;
    color: #388e3c;
}

.user-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.user-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.user-status-dot.active {
    background: #34c759;
}

.user-status-dot.inactive {
    background: #ff3b30;
}

.user-locations-count {
    font-size: 14px;
    color: var(--text-tertiary);
}

.user-actions {
    display: flex;
    gap: 8px;
}

.btn-edit-user {
    padding: 8px 16px;
    background: var(--brand);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-edit-user:hover {
    background: var(--brand-dark);
}

/* Edit User Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    position: sticky;
    bottom: 0;
    z-index: 10;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-tertiary);
}

/* Was a full re-statement of the base field styling at specificity (0,1,1),
   which outranked the bare `select` rule that draws the dropdown chevron - and
   its `background:` SHORTHAND reset background-image to none, so in light mode
   every select in a form had no arrow at all. Dark mode escaped it only
   because `body.dark-mode select` is (0,2,1). Everything this set is already
   covered by the shared input/select/textarea rules. */

.locations-checklist {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    padding: 16px;
}

.location-checkbox {
    display: flex;
    align-items: center;
    padding: 8px 0;
}

.location-checkbox input {
    margin-right: 10px;
}

.location-checkbox label {
    font-weight: normal !important;
    margin: 0 !important;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 24px;
    border-top: 1px solid var(--border-color);
}

.btn-secondary {
    padding: 12px 24px;
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--hover-bg);
}

@media (max-width: 768px) {
    .users-table {
        font-size: 13px;
    }
    
    .users-table th,
    .users-table td {
        padding: 12px 8px;
    }
    
    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .modal-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* User Management Specific Styles */
.user-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    transition: box-shadow 0.2s;
}

.user-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.user-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
}

.user-details h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 4px;
}

.user-details p {
    font-size: 14px;
    color: var(--text-secondary);
}

.user-actions {
    display: flex;
    gap: 8px;
}

.user-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.user-meta-item {
    display: flex;
    flex-direction: column;
}

.user-meta-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.user-meta-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.role-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.role-badge.admin {
    background: #fee;
    color: #c00;
}

.role-badge.manager {
    background: #fef3e0;
    color: #f59e0b;
}

.role-badge.technician {
    background: #e0f2fe;
    color: #0284c7;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.active {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.inactive {
    background: #fee;
    color: #991b1b;
}

/* Locations Checkboxes */
.locations-checkboxes {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    background: var(--bg-tertiary);
}

.location-checkbox-item {
    display: flex;
    align-items: center;
    padding: 8px;
    margin-bottom: 4px;
    border-radius: 6px;
    transition: background 0.2s;
}

.location-checkbox-item:hover {
    background: var(--bg-secondary);
}

.location-checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 12px;
    cursor: pointer;
}

.location-checkbox-item label {
    flex: 1;
    cursor: pointer;
    font-size: 14px;
    margin: 0;
}

/* Toggle Switch */
.switch-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-input);
    transition: 0.3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--brand);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

/* Mobile responsive for users */
@media (max-width: 768px) {
    .user-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .user-actions {
        width: 100%;
    }

    .user-actions .btn {
        flex: 1;
    }

    .user-meta {
        grid-template-columns: 1fr;
    }
}

/* ===================================================================
   DARK MODE SPECIFIC OVERRIDES
   ================================================================ */

body.dark-mode {
    /* Tables */
    table {
        border-color: var(--border-color) !important;
    }

    table thead {
        background: var(--bg-tertiary) !important;
    }

    th {
        background: var(--bg-tertiary) !important;
        color: var(--text-primary) !important;
        border-bottom-color: var(--border-color) !important;
    }

    td {
        border-bottom-color: var(--border-color) !important;
    }

    table tbody tr {
        background: var(--bg-secondary) !important;
        border-bottom-color: var(--border-color) !important;
    }

    table tbody tr:hover {
        background: var(--bg-tertiary) !important;
    }

    /* Specific table fixes */
    .requests-table th,
    .leaderboard-table th,
    .users-table th {
        background: var(--bg-tertiary) !important;
        color: var(--text-primary) !important;
        border-bottom-color: var(--border-color) !important;
    }

    .requests-table thead,
    .leaderboard-table thead,
    .users-table thead {
        background: var(--bg-tertiary) !important;
    }

    /* Review cards */
    .review-card {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }

    .review-card-header {
        border-bottom-color: var(--border-color);
    }

    /* GMB location cards */
    .gmb-location-card {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }

    /* Sync log entries */
    .sync-log-entry {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }

    /* User cards */
    .user-card {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }

    /* Loading and empty states */
    .loading-text, .empty-message {
        color: var(--text-secondary);
    }

    /* Request cards (mobile) */
    .request-card {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }

    /* Stats value */
    .stat-value {
        color: var(--text-tertiary);
    }

    /* Location stats */
    .location-stat-item {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }

    /* Match candidates */
    .match-candidate {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }

    .match-candidate:hover {
        background: var(--bg-tertiary);
    }

    /* Filters */
    .filter-select {
        background: var(--bg-secondary);
        border-color: var(--border-input);
        color: var(--text-primary);
    }

    /* Toast notifications - keep high contrast */
    .toast {
        background: var(--bg-tertiary);
        color: var(--text-primary);
        box-shadow: var(--shadow-lg);
    }

    /* Mobile nav overlay */
    .mobile-nav-overlay {
        background: var(--overlay-bg);
    }

    /* Fieldsets */
    fieldset {
        border-color: var(--border-color);
    }

    legend {
        color: var(--text-primary);
    }

    /* Small text */
    small {
        color: var(--text-secondary);
    }

    /* HR dividers */
    hr {
        border-color: var(--border-color);
    }

    /* Placeholder text */
    ::placeholder {
        color: var(--text-secondary) !important;
        opacity: 0.7 !important;
    }

    input::placeholder,
    textarea::placeholder {
        color: var(--text-secondary) !important;
        opacity: 0.7 !important;
    }

    input::-webkit-input-placeholder,
    textarea::-webkit-input-placeholder {
        color: var(--text-secondary) !important;
        opacity: 0.7 !important;
    }

    input::-moz-placeholder,
    textarea::-moz-placeholder {
        color: var(--text-secondary) !important;
        opacity: 0.7 !important;
    }

    /* Scrollbar styling for dark mode (webkit browsers) */
    ::-webkit-scrollbar {
        width: 12px;
        height: 12px;
    }

    ::-webkit-scrollbar-track {
        background: var(--bg-primary);
    }

    ::-webkit-scrollbar-thumb {
        background: var(--border-input);
        border-radius: 6px;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: var(--text-secondary);
    }

    /* Fix all hard-coded text colors for dark mode */
    h1, h2, h3, h4, h5, h6 {
        color: var(--text-tertiary) !important;
    }

    /* Stat card labels */
    .stat-card h3,
    .stat-card .stat-subtitle {
        color: var(--text-secondary) !important;
    }

    .stat-value {
        color: var(--text-tertiary) !important;
    }

    /* Review card text */
    .review-card h3,
    .review-card-header h3,
    .review-card-title {
        color: var(--text-tertiary) !important;
    }

    .review-card p,
    .review-text,
    .review-comment {
        color: var(--text-primary) !important;
    }

    .review-meta,
    .review-date {
        color: var(--text-secondary) !important;
    }

    /* Table text */
    table th {
        color: var(--text-primary) !important;
    }

    table td {
        color: var(--text-primary) !important;
    }

    /* Location stat text */
    .location-stat-name {
        color: var(--text-tertiary) !important;
    }

    .location-stat-label {
        color: var(--text-secondary) !important;
    }

    .location-stat-value {
        color: var(--text-primary) !important;
    }

    /* Leaderboard text */
    .tech-name {
        color: var(--text-tertiary) !important;
    }

    /* User card text */
    .user-name {
        color: var(--text-tertiary) !important;
    }

    .user-email,
    .user-meta span {
        color: var(--text-secondary) !important;
    }

    /* GMB location text */
    .gmb-location-name {
        color: var(--text-tertiary) !important;
    }

    .gmb-location-info {
        color: var(--text-secondary) !important;
    }

    /* Sync log text */
    .sync-log-time,
    .sync-log-status {
        color: var(--text-secondary) !important;
    }

    /* Message preview background fix */
    .message-preview {
        background: var(--bg-tertiary);
        border-color: var(--border-color);
    }

    /* Result message adjustments for dark mode */
    .result-message.success {
        background: rgba(52, 199, 89, 0.2);
        color: var(--accent-green);
        border-color: var(--accent-green);
    }

    .result-message.error {
        background: rgba(255, 59, 48, 0.2);
        color: var(--accent-red);
        border-color: var(--accent-red);
    }

    /* Fix all form inputs and selects.
       Checkboxes and radios are excluded. Stripping their appearance leaves
       nothing for the browser to paint - no tick, no dot, just a 16px hole -
       and because this sits inside body.dark-mode it outranks the widget rule
       further down, so the controls vanished in dark mode only. */
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        color: var(--text-primary) !important;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }

    /* Fix select dropdown arrow */
    select {
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgb(245, 245, 247)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 12px center;
        background-size: 16px;
        padding-right: 40px;
    }

    /* Fix dropdown option colors */
    option {
        background: var(--bg-secondary) !important;
        color: var(--text-primary) !important;
    }

    /* Fix labels */
    label {
        color: var(--text-primary) !important;
    }

    .form-group label,
    .form-row label {
        color: var(--text-primary) !important;
    }

    /* Date input fix */
    input[type="date"]::-webkit-calendar-picker-indicator {
        filter: invert(1);
    }

    /* Performance summary stat cards */
    #performance-summary .stat-card {
        background: var(--bg-secondary) !important;
    }

    #performance-summary .stat-card h3 {
        color: var(--text-secondary) !important;
    }

    #performance-summary .stat-value {
        color: var(--text-tertiary) !important;
    }

    #performance-summary .stat-subtitle {
        color: var(--text-secondary) !important;
    }

    /* Review dashboard specific */
    .review-info,
    .reviewer-name {
        color: var(--text-tertiary) !important;
    }

    .review-location {
        color: var(--text-secondary) !important;
    }

    /* Additional table and list fixes */
    .requests-table tbody td,
    .leaderboard-table tbody td,
    .users-table tbody td {
        color: var(--text-primary) !important;
    }

    /* Fix any remaining borders */
    .card-header {
        border-bottom-color: var(--border-color) !important;
    }

    /* Location stats specific */
    .location-stats {
        color: var(--text-primary);
    }

    .location-stat h4 {
        color: var(--text-tertiary) !important;
    }

    .location-stat-item h4 {
        color: var(--text-tertiary) !important;
    }

    .location-metric .label {
        color: var(--text-secondary) !important;
    }

    /* GMB Settings page fixes */
    .gmb-locations-list,
    .sync-logs-list {
        color: var(--text-primary);
    }

    .oauth-status-container {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }

    /* Modal dark mode fixes */
    .modal-content {
        background: var(--bg-secondary) !important;
        color: var(--text-primary);
    }

    .modal-header {
        background: var(--bg-secondary);
        border-bottom-color: var(--border-color);
    }

    .modal-header h2 {
        color: var(--text-tertiary) !important;
    }

    .modal-body {
        background: var(--bg-secondary);
        color: var(--text-primary);
    }

    .modal-footer {
        background: var(--bg-secondary) !important;
        border-top-color: var(--border-color) !important;
    }

    .modal-content input:not([type="checkbox"]):not([type="radio"])[readonly] {
        background: var(--bg-primary) !important;
        color: var(--text-secondary) !important;
    }

    .locations-checkboxes {
        background: var(--bg-tertiary) !important;
        border-color: var(--border-color) !important;
    }

    .location-checkbox:hover {
        background: var(--hover-bg) !important;
    }

    .location-checkbox span {
        color: var(--text-primary) !important;
    }

    .location-checkbox input[type="checkbox"] {
        accent-color: var(--accent-red) !important;
        border: 2px solid var(--border-input);
        background: var(--bg-tertiary);
    }

    /* Ensure checkboxes are visible in dark mode */
    input[type="checkbox"] {
        accent-color: var(--accent-red);
    }

    /* Ensure all white backgrounds become dark */
    .stats-grid,
    .leaderboard-table,
    .users-table,
    .requests-table {
        background: transparent;
    }

    /* Mobile navigation dark mode */
    @media (max-width: 768px) {
        .tab-nav {
            background: var(--bg-secondary) !important;
        }

        .tab-btn {
            border-bottom-color: var(--border-color) !important;
        }

        .tab-btn.active {
            background: var(--bg-tertiary) !important;
            border-bottom-color: var(--border-color) !important;
        }

        .mobile-user-info {
            border-bottom-color: var(--border-color) !important;
        }
    }
}

/* ========================================
   Enhanced Reviews Page Styling
   ======================================== */

/* Filter Bar */
.reviews-filter-bar {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
}

.filter-row-top {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 16px;
    align-items: start;
}

.search-input-wrapper {
    position: relative;
    flex: 0 0 280px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
}

.search-input:focus {
    outline: none;
    border-color: var(--brand);
}

.filter-badge-group {
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    gap: 12px;
    align-items: center;
}

.filter-badge-group .date-range-picker {
    grid-column: 1 / -1;
}

.filter-badge-group #review-tech-filter {
    grid-column: 1 / -1;
}

.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.filter-badge:hover {
    background: var(--bg-tertiary);
    border-color: var(--brand);
}

.filter-badge.active {
    background: var(--brand-tint);
    border-color: var(--brand);
    color: var(--brand);
}

.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--brand);
    color: white;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
}

.filter-select-minimal {
    padding: 6px 28px 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.filter-select-minimal:focus {
    outline: none;
    border-color: var(--brand);
}

.date-range-picker {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-input {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
}

.date-input:focus {
    outline: none;
    border-color: var(--brand);
}

/* Reviews Section Header */
.reviews-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.reviews-section-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.btn-outline-secondary {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-outline-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--brand);
    color: var(--brand);
}

/* Modern Reviews Container */
.reviews-container-modern {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Modern Review Card */
.review-card-modern {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    transition: all 0.2s;
}

.review-card-modern:hover {
    border-color: var(--brand);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.review-location-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.review-location-icon {
    color: var(--text-secondary);
}

.review-location-name {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.review-header-modern {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.reviewer-avatar-modern {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.reviewer-avatar-modern.initials {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: white;
    font-weight: 600;
    font-size: 18px;
}

.review-header-info {
    flex: 1;
}

.reviewer-name-modern {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.review-meta-modern {
    font-size: 13px;
    color: var(--text-secondary);
}

.review-meta-modern a {
    color: var(--brand);
    text-decoration: none;
}

.review-meta-modern a:hover {
    text-decoration: underline;
}

.review-stars-modern {
    display: inline-flex;
    gap: 2px;
    margin-bottom: 16px;
}

.star-filled {
    color: var(--accent-red) !important;
    font-size: 18px;
}

.star-empty {
    color: #666666 !important;
    font-size: 18px;
}

/* Dark mode specific star colors */
body.dark-mode .star-filled {
    color: #FF453A !important;
}

body.dark-mode .star-empty {
    color: #666666 !important;
}

.review-comment-modern {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.review-match-info-modern {
    background: rgba(52, 199, 89, 0.1);
    border: 1px solid rgba(52, 199, 89, 0.3);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.review-match-info-modern.no-invite {
    background: rgba(128, 128, 128, 0.1);
    border-color: rgba(128, 128, 128, 0.3);
}

.review-match-info-modern .match-label {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.review-reply-section-modern {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.review-reply-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.review-reply-text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
}

.review-quick-replies {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.quick-reply-btn {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.quick-reply-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--brand);
}

.review-reply-input-wrapper {
    position: relative;
    margin-bottom: 12px;
}

.review-reply-input {
    width: 100%;
    min-height: 80px;
    padding: 12px 40px 12px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}

.review-reply-input:focus {
    outline: none;
    border-color: var(--brand);
}

.emoji-picker-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
}

.review-actions-modern {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.ai-assistant-banner {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    margin-top: 12px;
}

/* Checkbox Labels */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
    .filter-row-top {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .search-input-wrapper {
        width: 100%;
    }

    .filter-badge-group {
        grid-template-columns: 1fr;
    }

    .reviews-section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

/* ============================================ */
/* PWA Install Banner */
/* ============================================ */

.install-banner {
    position: fixed;
    /* Clears the bottom tab bar. At bottom:0 with z-index:10000 this drawer
       covered the primary navigation, so the app's own nav was unreachable
       while it was open. */
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    left: 10px;
    right: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-3);
    z-index: 95;
    animation: slideUp 0.3s ease-out;
    padding: 14px;
}

/* It offers to add the app to a home screen, which only means something on a
   phone; the JS gate is the real fix, this is the belt. */
@media (min-width: 769px) {
    .install-banner { display: none !important; }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.install-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

.install-banner-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.install-banner-text {
    flex: 1;
    min-width: 0;
}

.install-banner-text strong {
    display: block;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
}

.install-banner-text p {
    color: var(--text-secondary);
    font-size: 13px;
    margin: 0;
}

.install-banner #install-button {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 600;
}

.install-close {
    /* Was top:-8px right:-8px, i.e. outside its own container, so the banner
       clipped it - worst on mobile, where the padding is tightest. It is a
       row item now, aligned with everything else in the row. */
    position: static;
    flex-shrink: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.install-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .install-banner {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .install-banner-content {
        gap: 10px;
    }

    .install-banner-icon {
        font-size: 28px;
    }

    .install-banner-text strong {
        font-size: 14px;
    }

    .install-banner-text p {
        font-size: 12px;
    }

    .install-banner #install-button {
        padding: 6px 12px;
        font-size: 13px;
    }

    .install-close {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
}

/* ============================================ */
/* Reports Page Styles */
/* ============================================ */

.reports-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

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

.reports-sub-nav {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
}

.reports-sub-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.reports-sub-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.reports-sub-btn.active {
    background: var(--brand);
    color: white;
    font-weight: 600;
}

.reports-filters {
    display: flex;
    gap: 12px;
    align-items: center;
}

.reports-filters select {
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
}

.reports-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 16px;
}

.reports-error {
    text-align: center;
    padding: 60px 20px;
    color: var(--accent-red);
    font-size: 16px;
}

.reports-grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Report Table */
.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.report-table thead {
    background: var(--bg-tertiary);
}

.report-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.report-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.report-table tbody tr:hover {
    background: var(--bg-tertiary);
}

/* Rate badges */
.rate-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 13px;
}

.rate-good {
    background: rgba(52, 199, 89, 0.15);
    color: #34C759;
}

.rate-ok {
    background: rgba(255, 149, 0, 0.15);
    color: #FF9500;
}

.rate-low {
    background: rgba(255, 59, 48, 0.15);
    color: #FF3B30;
}

/* Star distribution bars */
.star-distribution {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0;
}

.star-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.star-bar-label {
    width: 50px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.star-bar-track {
    flex: 1;
    height: 20px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.star-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
    min-width: 2px;
}

.star-bar-count {
    width: 80px;
    text-align: right;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
}

/* Match stats */
.match-stats-visual {
    padding: 16px 0;
}

.match-donut-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.match-stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.match-stat-row strong {
    margin-left: auto;
}

.match-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* SMS breakdown */
.sms-breakdown {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sms-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
}

.sms-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sms-status-label {
    flex: 1;
    font-size: 14px;
    text-transform: capitalize;
}

.sms-status-count {
    font-weight: 600;
    font-size: 14px;
    min-width: 30px;
    text-align: right;
}

.sms-status-pct {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: right;
}

/* Sync health grid */
.sync-health-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.sync-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.sync-stat-value {
    font-size: 24px;
    font-weight: 700;
}

.sync-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Trend chart */
.trend-chart {
    padding: 16px 0;
}

.trend-bar:hover {
    opacity: 0.8;
}

/* Mobile responsive for reports */
@media (max-width: 768px) {
    .reports-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .reports-sub-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .reports-filters {
        flex-wrap: wrap;
    }

    .reports-grid-2col {
        grid-template-columns: 1fr;
    }

    .report-table {
        font-size: 12px;
    }

    .report-table th,
    .report-table td {
        padding: 8px 6px;
    }

    .reports-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .sync-health-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Dark mode overrides for reports */
body.dark-mode .report-table thead {
    background: var(--bg-tertiary) !important;
}

body.dark-mode .report-table th {
    color: var(--text-secondary) !important;
}

body.dark-mode .report-table td {
    color: var(--text-primary) !important;
    border-bottom-color: var(--border-color) !important;
}

body.dark-mode .report-table tbody tr:hover {
    background: var(--bg-tertiary) !important;
}

body.dark-mode .star-bar-track {
    background: var(--bg-secondary);
}

body.dark-mode .sync-stat {
    background: var(--bg-secondary);
}

/* ==========================================================================
   Messages - customer SMS conversations
   Uses the existing :root / body.dark-mode custom properties throughout so
   dark mode needs no separate overrides.
   ========================================================================== */

.msg-nav-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    margin-left: 6px;
    border-radius: 9px;
    background: var(--accent-red);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}

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

.msg-title { margin: 0; font-size: 24px; font-weight: 600; color: var(--text-tertiary); }

.msg-sub-nav { display: flex; gap: 4px; }

.msg-sub-btn {
    padding: 7px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.msg-sub-btn:hover { background: var(--hover-bg); }
.msg-sub-btn.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

/* ----- two-pane layout ----- */
.msg-layout {
    display: flex;
    gap: 16px;
    height: calc(100vh - 230px);
    min-height: 420px;
}

.msg-list-pane {
    flex: 0 0 320px;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

.msg-list-controls {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
}

.msg-filter-row { display: flex; gap: 8px; align-items: center; }
.msg-filter-row select { flex: 1; min-width: 0; }

.msg-filter-chip {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}
.msg-filter-chip.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.msg-conversation-list { flex: 1; overflow-y: auto; }

.msg-convo {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    padding: 12px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease;
}
.msg-convo:hover { background: var(--hover-bg); }
.msg-convo.active { background: var(--bg-tertiary); }
.msg-convo.unread .msg-convo-name { font-weight: 700; }
.msg-convo.unread .msg-convo-preview { color: var(--text-primary); font-weight: 500; }

.msg-convo-avatar {
    flex: 0 0 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.msg-convo-body { flex: 1; min-width: 0; }

.msg-convo-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.msg-convo-name {
    font-size: 14px; color: var(--text-primary); font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-convo-time { font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }

.msg-convo-preview {
    font-size: 13px; color: var(--text-secondary); margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.msg-convo-meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.msg-convo-location { font-size: 11px; color: var(--text-secondary); }

.msg-convo-badge {
    flex-shrink: 0;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px;
    background: var(--brand);
    color: #fff; font-size: 11px; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
}

.msg-tag {
    display: inline-block; padding: 1px 6px; border-radius: 4px;
    font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.msg-tag-optout { background: var(--accent-red); color: #fff; }

/* ----- thread ----- */
.msg-thread-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

.msg-thread-header {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    min-height: 56px;
}

.msg-back-btn {
    display: none;
    border: none; background: transparent;
    color: var(--brand); font-size: 20px; cursor: pointer; padding: 0 4px;
}

.msg-thread-identity { flex: 1; min-width: 0; }
.msg-thread-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.msg-thread-sub { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }

.msg-thread {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-primary);
}

.msg-day-divider {
    text-align: center;
    margin: 12px 0 6px;
}
.msg-day-divider span {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
}

.msg-row { display: flex; }
.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }

.msg-bubble {
    max-width: 72%;
    padding: 9px 13px;
    border-radius: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}
.msg-row.out .msg-bubble {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.msg-row.out .msg-bubble.auto {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
    border-style: dashed;
}
.msg-bubble.failed { border-color: var(--accent-red); }

.msg-text { font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }

.msg-media-note { font-size: 12px; opacity: 0.8; margin-top: 4px; font-style: italic; }

.msg-bubble-meta {
    display: flex; align-items: center; gap: 6px;
    margin-top: 4px; font-size: 10px; opacity: 0.75;
}
.msg-row.out .msg-bubble-meta { justify-content: flex-end; }
.msg-status.failed { color: #ffd5d2; font-weight: 600; }
.msg-row.out .msg-bubble.auto .msg-status.failed { color: var(--accent-red); }

/* ----- composer ----- */
.msg-composer { border-top: 1px solid var(--border-color); padding: 10px 12px; background: var(--bg-secondary); }

.msg-composer-notice {
    padding: 8px 10px; margin-bottom: 8px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--accent-red);
    font-size: 12px;
}

.msg-composer-form { display: flex; gap: 8px; align-items: flex-end; }

.msg-composer-input {
    flex: 1;
    resize: none;
    padding: 9px 12px;
    border: 1px solid var(--border-input);
    border-radius: 18px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
}
.msg-composer-input:disabled { opacity: 0.55; cursor: not-allowed; }

.msg-char-count { font-size: 11px; color: var(--text-secondary); text-align: right; margin-top: 4px; min-height: 14px; }
.msg-char-count.warn { color: var(--accent-orange); }

/* ----- auto-reply settings ----- */
.msg-autoreply-intro {
    color: var(--text-secondary); font-size: 13px; line-height: 1.6;
    margin: 0 0 16px; max-width: 70ch;
}

.msg-autoreply-list { display: flex; flex-direction: column; gap: 14px; }

.msg-autoreply-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
}

.msg-autoreply-head {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 12px; margin-bottom: 12px;
}
.msg-autoreply-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.msg-autoreply-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.msg-switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-primary); cursor: pointer; }

.msg-autoreply-hint { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

.msg-autoreply-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.ar-result { font-size: 12px; color: var(--text-secondary); }
.ar-result.ok { color: var(--accent-green); }
.ar-result.err { color: var(--accent-red); }

/* ----- mobile ----- */
@media (max-width: 768px) {
    .msg-layout { height: calc(100vh - 200px); position: relative; }

    .msg-list-pane { flex: 1 1 auto; width: 100%; }
    .msg-list-pane.mobile-hidden { display: none; }

    .msg-thread-pane { display: none; }
    .msg-thread-pane.mobile-active { display: flex; width: 100%; }

    .msg-back-btn { display: block; }

    .msg-bubble { max-width: 85%; }
}

.msg-sender { font-weight: 600; }
.msg-time { white-space: nowrap; }

/* ==========================================================================
   Service Picker — searchable combobox replacing the Service Type <select>
   A native select on iOS opens a wheel with no search, which is unusable for
   a ~105 item catalog on a phone.
   ========================================================================== */

.sp-wrap { position: relative; }

.sp-input {
    width: 100%;
    padding: 10px 34px 10px 12px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 16px;               /* 16px stops iOS Safari zooming on focus */
    font-family: inherit;
}
.sp-input:focus {
    outline: none;
    border-color: var(--brand);
}

.sp-clear {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.sp-clear:hover { background: var(--hover-bg); color: var(--text-primary); }

.sp-options {
    display: none;
    position: absolute;
    z-index: 60;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    -webkit-overflow-scrolling: touch;
}

.sp-group {
    padding: 8px 12px 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    position: sticky;
    top: 0;
}

.sp-option {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    /* 44px minimum touch target - techs use this one-handed in the field */
    min-height: 44px;
    padding: 10px 12px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    font-size: 15px;
    cursor: pointer;
}
.sp-option:last-child { border-bottom: none; }
.sp-option:hover,
.sp-option.active { background: var(--hover-bg); }

.sp-option-name { flex: 1; min-width: 0; }
.sp-option-meta {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-secondary);
}

.sp-empty {
    padding: 14px 12px;
    color: var(--text-secondary);
    font-size: 14px;
}

@media (max-width: 768px) {
    .sp-options { max-height: 45vh; }
}

/* ==========================================================================
   App shell — stage 1 of the UI restructure

   Phones get a fixed bottom tab bar plus a More sheet. Desktop is unchanged
   and keeps the top tab bar. Everything below 768px that used the hamburger
   drawer is superseded here.
   ========================================================================== */

/* Hidden by default: desktop keeps the existing top nav. */
.bottom-nav { display: none; }
.more-sheet { display: none; }
.sheet-backdrop { display: none; }

@media (max-width: 768px) {

    /* ---- retire the hamburger drawer ------------------------------------ */
    /* The drawer put primary actions two taps deep. The bottom bar replaces
       it, so the toggle, the slide-out panel and its overlay all go away. */
    .mobile-menu-toggle { display: none !important; }
    .mobile-nav-overlay { display: none !important; }
    .tab-nav { display: none !important; }

    /* Header slims down; the account controls now live in the More sheet. */
    .dashboard-header {
        padding: 12px 16px !important;
        position: sticky;
        top: 0;
        z-index: 40;
    }
    .dashboard-header h1 { font-size: 18px; }
    .header-right #user-name,
    .header-right #logout-btn { display: none !important; }

    /* Content must clear the fixed bar, including the iPhone home indicator. */
    .tab-content {
        padding: 16px 14px calc(76px + env(safe-area-inset-bottom, 0px));
    }

    /* ---- bottom tab bar -------------------------------------------------- */
    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 90;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        /* Translucent so content scrolling underneath reads as continuous. */
        backdrop-filter: saturate(180%) blur(16px);
        -webkit-backdrop-filter: saturate(180%) blur(16px);
    }

    .bnav-item {
        position: relative;
        flex: 1 1 0;
        min-height: 52px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 7px 4px 6px;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        font-size: 11px;
        font-weight: 500;
        font-family: inherit;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.15s ease;
    }

    .bnav-item svg {
        width: 23px;
        height: 23px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .bnav-item.active { color: var(--brand); }
    .bnav-item:active { opacity: 0.6; }

    .bnav-badge {
        position: absolute;
        top: 4px;
        left: 50%;
        margin-left: 4px;
        min-width: 17px;
        height: 17px;
        padding: 0 4px;
        border-radius: 9px;
        background: var(--accent-red);
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ---- More sheet ------------------------------------------------------ */
    .sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 95;
        background: var(--overlay-bg);
        opacity: 0;
        transition: opacity 0.2s ease;
    }
    .sheet-backdrop.open { opacity: 1; }

    .more-sheet {
        display: block;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 96;
        max-height: 80vh;
        overflow-y: auto;
        background: var(--bg-secondary);
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -8px 30px rgba(0,0,0,0.25);
        padding: 8px 16px calc(20px + env(safe-area-inset-bottom, 0px));
        transform: translateY(100%);
        transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
        -webkit-overflow-scrolling: touch;
    }
    .more-sheet.open { transform: translateY(0); }

    .sheet-grip {
        width: 36px;
        height: 4px;
        margin: 6px auto 10px;
        border-radius: 2px;
        background: var(--border-input);
    }

    .sheet-head {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--border-color);
    }
    .sheet-name { font-size: 16px; font-weight: 600; color: var(--text-primary); }
    .sheet-role { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

    .sheet-close {
        border: none;
        background: transparent;
        color: var(--text-secondary);
        font-size: 26px;
        line-height: 1;
        padding: 0 4px;
        cursor: pointer;
    }

    .sheet-links { padding: 6px 0; }

    .sheet-link {
        display: flex;
        flex-direction: column;
        gap: 2px;
        width: 100%;
        min-height: 56px;          /* comfortable one-handed target */
        padding: 12px 4px;
        border: none;
        border-bottom: 1px solid var(--border-color);
        background: transparent;
        text-align: left;
        cursor: pointer;
    }
    .sheet-link:last-child { border-bottom: none; }
    .sheet-link:active { background: var(--hover-bg); }
    .sheet-link-label { font-size: 16px; color: var(--text-primary); font-weight: 500; }
    .sheet-link-desc { font-size: 12px; color: var(--text-secondary); }

    .sheet-empty { padding: 20px 4px; color: var(--text-secondary); font-size: 14px; }

    .sheet-actions {
        display: flex;
        gap: 10px;
        padding-top: 14px;
        border-top: 1px solid var(--border-color);
    }
    .sheet-actions .btn { flex: 1; margin-bottom: 0; }

    /* The Messages inbox is full-height; it must sit above the bar, not under it. */
    .msg-layout { height: calc(100vh - 210px); }
}

/* Very small phones: keep four labels legible rather than truncating. */
@media (max-width: 360px) {
    .bnav-item { font-size: 10px; }
    .bnav-item svg { width: 21px; height: 21px; }
}

/* ==========================================================================
   My Requests — stage 2
   Request cards show the funnel (texted -> clicked -> reviewed) rather than
   four separate Yes/No fields. All colours are tokens so dark mode works; the
   previous cards hardcoded #86868b and stayed light grey on a dark background.
   ========================================================================== */

.req-search {
    padding: 8px 12px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    min-width: 190px;
}
.req-search:focus { outline: none; border-color: var(--brand); }

.request-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
}
.request-card.stage-reviewed { border-left-color: var(--accent-green); }
.request-card.stage-updated  { border-left-color: var(--info, #175CD3); }
.request-card.stage-clicked  { border-left-color: var(--accent-orange); }
.request-card.stage-failed   { border-left-color: var(--accent-red); }

.request-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.request-customer-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}
.request-customer-phone {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.req-stage-badge {
    flex-shrink: 0;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}
.req-stage-reviewed { background: var(--accent-green); color: #fff; }
.req-stage-updated  { background: var(--info, #175CD3); color: #fff; }
.req-stage-clicked  { background: var(--accent-orange); color: #fff; }
.req-stage-failed   { background: var(--accent-red); color: #fff; }

/* ---- funnel ---- */
.req-funnel {
    display: flex;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 10px;
}

.req-step {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    position: relative;
    text-align: center;
}

/* connector between steps */
.req-step:not(:first-child)::before {
    content: '';
    position: absolute;
    top: 5px;
    right: 50%;
    width: 100%;
    height: 2px;
    background: var(--border-color);
}
.req-step.reached:not(:first-child)::before { background: var(--accent-green); }

.req-step-dot {
    position: relative;
    z-index: 1;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 2px solid var(--border-input);
}
.req-step.reached .req-step-dot {
    background: var(--accent-green);
    border-color: var(--accent-green);
}

.req-step-label {
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.req-step.reached .req-step-label { color: var(--text-primary); font-weight: 500; }

.req-step-time {
    font-size: 10px;
    color: var(--text-secondary);
    min-height: 12px;
}

.req-meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.request-card-footer { margin-top: 10px; }
.request-card-footer .btn { width: 100%; margin-bottom: 0; }

@media (max-width: 768px) {
    /* Cards are the only view on a phone; the table is desktop-only. */
    .filters {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }
    .filters .req-search,
    .filters select { width: 100%; min-width: 0; }

    .card-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
}

/* ==========================================================================
   Shell fixes — click-blocking overlay and login-screen leakage
   ==========================================================================

   BUG 1 (critical): the More sheet and its backdrop are marked hidden in the
   HTML, but the mobile block above sets `display: block` on them. The
   `[hidden] { display: none }` rule that makes the attribute work lives in the
   USER-AGENT stylesheet, and ANY author declaration beats a user-agent one no
   matter how specific. So the backdrop stayed in the layout permanently:
   position:fixed, inset:0, z-index:95, opacity:0 — an invisible sheet of glass
   over the whole viewport that swallowed every click, including Sign in.

   Restore the attribute's meaning explicitly. !important so it cannot be
   defeated again by a later rule.

   BUG 2: the bottom bar, sheet and backdrop live outside #dashboard, so they
   rendered on the login screen too. Gate them on body.logged-in.
   ========================================================================== */

.more-sheet[hidden],
.sheet-backdrop[hidden] {
    display: none !important;
}

/* Belt and braces: even if something re-enables display, a closed backdrop
   must not intercept pointer events. */
.sheet-backdrop:not(.open) {
    pointer-events: none;
}
.sheet-backdrop.open {
    pointer-events: auto;
}

/* Nothing in the mobile shell should exist before sign-in. */
.bottom-nav,
.more-sheet,
.sheet-backdrop {
    display: none !important;
}

@media (max-width: 768px) {
    body.logged-in .bottom-nav {
        display: flex !important;
    }
    body.logged-in .more-sheet:not([hidden]) {
        display: block !important;
    }
    body.logged-in .sheet-backdrop:not([hidden]) {
        display: block !important;
    }
}

/* ==========================================================================
   Stage 3 — manager screens (Leaderboard, Reports, Statistics)

   Leaderboard and Reports were desktop tables with no mobile fallback: seven
   and eight columns respectively, rendered at 390px. Leaderboard now has a
   ranked-card view below 768px; Reports keeps its tables but scrolls them
   horizontally inside their own container so the page body never does.
   ========================================================================== */

.lb-cards { display: none; }

.lb-empty {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}
.lb-error { color: var(--accent-red); }

.lb-gold { color: var(--star-gold); font-weight: 700; }

/* Desktop table: let it scroll rather than blow out the layout on a narrow
   laptop window. */
.lb-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- mobile ranked cards ---- */
.lb-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
}
.lb-card-top { border-color: var(--star-gold); }

.lb-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.lb-rank {
    flex-shrink: 0;
    min-width: 28px;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    color: var(--text-secondary);
}

.lb-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}
.lb-avatar-initial {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
}

.lb-identity { flex: 1; min-width: 0; }
.lb-name {
    font-size: 15px; font-weight: 600; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lb-email {
    font-size: 12px; color: var(--text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.lb-metrics {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.lb-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
}
.lb-metric-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}
.lb-metric-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
}

/* ---- reports: keep wide tables inside their own scroller ---- */
.report-table { width: 100%; border-collapse: collapse; }
.report-table-wrap,
#reports-content .report-table {
    /* A wide table must scroll itself; the page body must never scroll
       sideways. */
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
}

/* ---- statistics: location breakdown ---- */
.location-stat {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
}
.location-stat h4 {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.location-metrics { display: flex; gap: 16px; }
.location-metric { display: flex; flex-direction: column; gap: 2px; }
.location-metric .value { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.location-metric .label { font-size: 11px; color: var(--text-secondary); }

@media (max-width: 768px) {
    .lb-cards { display: block; }

    /* Filter rows stack so the selects are full width and tappable. */
    .reports-controls,
    .reports-filters,
    .leaderboard-filters {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }
    .reports-filters select,
    .leaderboard-filters select { width: 100%; }

    .reports-sub-nav {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
    .reports-sub-btn { flex-shrink: 0; }

    /* Summary tiles: two per row rather than one long column. */
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .location-metrics { justify-content: space-between; gap: 8px; }
}

@media (max-width: 360px) {
    .lb-metrics { grid-template-columns: repeat(3, 1fr); row-gap: 10px; }
}

/* ==========================================================================
   Stage 4 — admin screens
   Users was a seven-column table with no mobile fallback; below 768px the
   same records render as cards.
   ========================================================================== */

.user-cards { display: none; }

.users-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.user-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
}
.user-card-inactive { opacity: 0.6; }

.user-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.user-card-identity { flex: 1; min-width: 0; }
.user-card-name {
    font-size: 15px; font-weight: 600; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-card-email {
    font-size: 12px; color: var(--text-secondary); margin-top: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-card-facts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 10px 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}
.user-fact { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.user-fact-value {
    font-size: 14px; font-weight: 700; color: var(--text-primary);
    text-align: center; line-height: 1.2;
}
.user-fact-label { font-size: 10px; color: var(--text-secondary); }
.user-active { color: var(--accent-green); }
.user-inactive { color: var(--text-secondary); }

.user-card-actions { display: flex; gap: 8px; margin-top: 12px; }
.user-card-actions .btn { flex: 1; margin-bottom: 0; }

/* Status notice panels in GMB admin now use tokens for both themes. */
.gmb-notice-info { background: var(--notice-info-bg); border-left: 4px solid var(--notice-info-border); }
.gmb-notice-warn { background: var(--notice-warn-bg); border-left: 4px solid var(--notice-warn-border); }
.gmb-notice-ok   { background: var(--notice-ok-bg);   border-left: 4px solid var(--notice-ok-border); color: var(--notice-ok-text); }

@media (max-width: 768px) {
    .user-cards { display: block; }

    /* GMB location cards stack rather than sitting in a cramped grid. */
    .gmb-locations-list { display: flex; flex-direction: column; gap: 10px; }
    .gmb-location-card { width: 100%; }
    .gmb-location-stats { flex-wrap: wrap; gap: 10px; }
    .gmb-location-actions { display: flex; gap: 8px; flex-wrap: wrap; }
    .gmb-location-actions .btn { flex: 1; min-width: 120px; margin-bottom: 0; }
}

/* ==========================================================================
   GMB Settings

   The old page stacked three always-open cards with 27 expanded location
   cards between them, so finding one office meant scrolling past all of them.
   Status strip first, then one panel at a time, with dense rows.
   ========================================================================== */

.gs-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 16px;
    margin-bottom: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.gs-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 92px;
    padding-right: 14px;
    border-right: 1px solid var(--border-color);
}
.gs-stat:nth-of-type(4) { border-right: none; }
.gs-stat-value { font-size: 20px; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.gs-stat-label { font-size: 11px; color: var(--text-secondary); }

.gs-strip-actions { margin-left: auto; display: flex; gap: 8px; }
.gs-strip-actions .btn { margin-bottom: 0; width: auto; }

.gs-alert {
    padding: 10px 14px;
    margin-bottom: 12px;
    border-radius: 10px;
    font-size: 13px;
    background: var(--notice-info-bg);
    border-left: 4px solid var(--notice-info-border);
    color: var(--text-primary);
}
.gs-alert-warn { background: var(--notice-warn-bg); border-left-color: var(--notice-warn-border); }
.gs-alert-error { background: var(--notice-warn-bg); border-left-color: var(--accent-red); }

/* ---- sub navigation ---- */
.gs-subnav {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.gs-subbtn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
}
.gs-subbtn:hover { background: var(--hover-bg); }
.gs-subbtn.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.gs-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px;
    background: var(--accent-red);
    color: #fff; font-size: 11px; font-weight: 700;
}
.gs-subbtn.active .gs-badge { background: rgba(255,255,255,0.28); }

/* ---- panels ---- */
.gs-panel { display: none; }
.gs-panel.active { display: block; }

.gs-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.gs-toolbar .btn { margin-bottom: 0; width: auto; }
/* The global `input, select, textarea { width: 100% }` would otherwise put
   every control on its own row. */
.gs-toolbar select {
    flex: 0 0 auto;
    width: auto;
    min-width: 150px;
    font-size: 14px;
    padding: 8px 30px 8px 12px;
}

.gs-search {
    flex: 1 1 200px;
    width: auto;
    min-width: 160px;
    padding: 8px 12px;
    border: 1px solid var(--border-input);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
}
.gs-search:focus { outline: none; border-color: var(--brand); }

.gs-cache-note { font-size: 12px; color: var(--text-secondary); margin-left: auto; }

.gs-help {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0 0 12px;
    max-width: 72ch;
}

/* ---- dense rows ---- */
.gs-rows {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    /* Long lists scroll inside the panel rather than the page. */
    max-height: calc(100vh - 340px);
    min-height: 160px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.gs-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border-color);
}
.gs-row:last-child { border-bottom: none; }
.gs-row:hover { background: var(--hover-bg); }

.gs-row-main { flex: 1; min-width: 0; }
.gs-row-title {
    display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
    font-size: 14px; font-weight: 600; color: var(--text-primary);
}
.gs-row-sub {
    font-size: 12px; color: var(--text-secondary); margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis;
}
.gs-muted { color: var(--text-secondary); }

.gs-row-meta { display: flex; gap: 16px; flex-shrink: 0; align-items: center; }
.gs-row-metric { display: flex; flex-direction: column; align-items: flex-end; }
.gs-row-metric span { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.gs-row-metric small { font-size: 10px; color: var(--text-secondary); }

.gs-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.gs-row-actions .btn { margin-bottom: 0; width: auto; }

.gs-chip {
    padding: 1px 7px; border-radius: 999px;
    background: var(--bg-tertiary); color: var(--text-secondary);
    font-size: 11px; font-weight: 600;
}
.gs-chip-hvac { background: var(--notice-info-bg); color: var(--notice-info-border); }
.gs-chip-pest { background: var(--notice-ok-bg); color: var(--notice-ok-text); }

.gs-flags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.gs-flag {
    padding: 1px 7px; border-radius: 4px;
    background: var(--bg-tertiary); color: var(--text-secondary);
    font-size: 10px; font-weight: 600;
}
.gs-flag-warn { background: var(--notice-warn-bg); color: var(--text-primary); }
.gs-flag-err  { background: var(--accent-red); color: #fff; }
.gs-flag-ok   { background: var(--notice-ok-bg); color: var(--notice-ok-text); }

.gs-conf {
    padding: 1px 7px; border-radius: 4px;
    font-size: 10px; font-weight: 700; text-transform: uppercase;
}
.gs-conf-exact  { background: var(--accent-green); color: #fff; }
.gs-conf-high   { background: var(--accent-green); color: #fff; }
.gs-conf-manual { background: var(--brand); color: #fff; }
.gs-conf-medium { background: var(--accent-orange); color: #fff; }
.gs-conf-none,
.gs-conf-low    { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ---- activity panel ---- */
.gs-block {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
}
.gs-block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.gs-h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); margin: 0 0 10px; }
.gs-block-head .gs-h3, .gs-legacy .gs-h3 { margin: 0; }
.gs-legacy summary { cursor: pointer; }
.gs-legacy .gmb-locations-list { margin-top: 12px; }

@media (max-width: 768px) {
    .gs-strip { gap: 8px; padding: 12px; }
    .gs-stat { min-width: 68px; padding-right: 8px; }
    .gs-stat-value { font-size: 17px; }
    .gs-strip-actions { margin-left: 0; width: 100%; }
    .gs-strip-actions .btn { flex: 1; }

    .gs-toolbar { flex-direction: column; align-items: stretch; }
    .gs-toolbar .gs-search,
    .gs-toolbar select,
    .gs-toolbar .btn { width: 100%; }
    .gs-cache-note { margin-left: 0; }

    .gs-rows { max-height: none; }

    /* Rows stack so nothing is cut off on a narrow screen. */
    .gs-row { flex-direction: column; align-items: stretch; gap: 8px; }
    .gs-row-meta { justify-content: flex-start; gap: 20px; }
    .gs-row-metric { align-items: flex-start; }
    .gs-row-actions .btn { flex: 1; }
}

/* ==========================================================================
   Desktop shell: sidebar + content

   The old desktop screen was a header, a row of text tabs under it, and the
   page below - so nine destinations competed for one horizontal strip, and
   every screen started a third of the way down the viewport. A sidebar gives
   the destinations room to have icons and stay readable, puts the account
   controls somewhere permanent, and hands the whole right-hand side to the
   content.

   Everything below 769px is untouched: that band has its own bottom bar and
   More sheet, and this entire block is gated behind the media query.

   Colours come from the existing tokens. What is new here is depth - surfaces,
   borders and shadows - not hue.
   ========================================================================== */

:root {
    --side-w: 244px;
    --topbar-h: 64px;

    /* Layered shadows read as depth rather than a grey halo. */
    --elev-1: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
    --elev-2: 0 2px 4px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.08);
    --elev-3: 0 8px 16px rgba(0,0,0,0.08), 0 18px 40px rgba(0,0,0,0.12);

    /* The brand accent, named for what it is.
       --accent-blue is #FF3B30 in light mode and #0A84FF in dark, so anything
       painted with it changes hue when the theme flips. That was invisible
       while it only tinted text and a 3px underline; as a filled sidebar row
       it turns the navigation blue at night. This token is Go-Forth red in
       both themes, and nothing already using --accent-blue is affected. */
    --brand: #FF3B30;
    --brand-dark: #CC2E24;
    --brand-contrast: #ffffff;

    --ring: 0 0 0 3px rgba(255, 59, 48, 0.20);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

body.dark-mode {
    --elev-1: 0 1px 2px rgba(0,0,0,0.4), 0 1px 3px rgba(0,0,0,0.5);
    --elev-2: 0 2px 4px rgba(0,0,0,0.4), 0 4px 14px rgba(0,0,0,0.55);
    --elev-3: 0 8px 18px rgba(0,0,0,0.55), 0 22px 48px rgba(0,0,0,0.65);

    --brand: #FF453A;
    --brand-dark: #D9342A;
    --ring: 0 0 0 3px rgba(255, 69, 58, 0.30);
}

/* The sidebar's own surface. A hair off --bg-primary so the content area
   reads as the page and the rail reads as chrome, in both themes. */
:root      { --side-bg: #ffffff; --side-hover: #f2f2f4; }
body.dark-mode { --side-bg: #141416; --side-hover: #232326; }

@media (min-width: 769px) {

    /* ---- the grid ------------------------------------------------------- */
    /* #dashboard carries an inline display from showDashboard(), so that
       function sets display:'' and the value is decided here instead. */
    body.logged-in #dashboard {
        display: grid;
        grid-template-columns: var(--side-w) minmax(0, 1fr);
        grid-template-rows: var(--topbar-h) minmax(0, 1fr);
        grid-template-areas:
            "sidebar topbar"
            "sidebar main";
        min-height: 100vh;
    }

    .side-nav { grid-area: sidebar; }
    .dashboard-header { grid-area: topbar; }
    /* Every panel shares the one content cell; only .active is displayed. */
    .tab-content { grid-area: main; }

    .mobile-menu-toggle { display: none; }
    .mobile-user-info   { display: none; }

    /* ---- sidebar -------------------------------------------------------- */
    .side-nav {
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding: 0;
        background: var(--side-bg);
        border-right: 1px solid var(--border-color);
        border-bottom: none;
        position: sticky;
        top: 0;
        height: 100vh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .side-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        height: var(--topbar-h);
        padding: 0 18px;
        flex-shrink: 0;
    }
    .side-brand .header-logo {
        width: 30px; height: 30px; margin: 0;
        border-radius: var(--radius-sm);
        box-shadow: var(--elev-1);
    }
    .side-brand-name {
        font-size: 16px;
        font-weight: 650;
        letter-spacing: -0.01em;
        color: var(--text-tertiary);
    }

    .side-links {
        display: flex;
        flex-direction: column;
        gap: 2px;
        padding: 10px;
        flex: 1;
        min-height: 0;
    }

    /* The tab buttons keep their class so app.js keeps working; everything
       about how they look is replaced. */
    .side-links .tab-btn {
        display: flex;
        align-items: center;
        gap: 11px;
        width: 100%;
        padding: 9px 11px;
        border: none;
        border-radius: var(--radius-sm);
        background: none;
        color: var(--text-secondary);
        font-size: 14.5px;
        font-weight: 500;
        font-family: inherit;
        text-align: left;
        cursor: pointer;
        position: relative;
        transition: background-color .15s ease, color .15s ease;
    }
    .side-links .tab-btn .nav-ico {
        width: 18px; height: 18px;
        flex-shrink: 0;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.9;
        stroke-linecap: round;
        stroke-linejoin: round;
        opacity: .85;
    }
    .side-links .tab-btn:hover {
        background: var(--side-hover);
        color: var(--text-primary);
    }
    .side-links .tab-btn.active {
        background: var(--brand);
        color: var(--brand-contrast);
        box-shadow: var(--elev-1);
    }
    .side-links .tab-btn.active .nav-ico { opacity: 1; }
    .side-links .tab-btn:focus-visible {
        outline: none;
        box-shadow: var(--ring);
    }

    /* Unread count sits at the far end of the row, not next to the label. */
    .side-links .tab-btn .msg-nav-badge {
        margin-left: auto;
    }
    .side-links .tab-btn.active .msg-nav-badge {
        background: rgba(255,255,255,0.3);
        color: #fff;
    }

    /* ---- account block -------------------------------------------------- */
    .side-account {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "avatar name  theme"
            "logout logout logout";
        align-items: center;
        gap: 8px 10px;
        padding: 12px;
        margin-top: auto;
        border-top: 1px solid var(--border-color);
        flex-shrink: 0;
    }
    .side-avatar {
        grid-area: avatar;
        width: 30px; height: 30px;
        border-radius: 50%;
        display: grid;
        place-items: center;
        background: var(--brand);
        color: var(--brand-contrast);
        font-size: 12px;
        font-weight: 700;
        letter-spacing: .02em;
    }
    .side-account #user-name {
        grid-area: name;
        font-size: 13.5px;
        font-weight: 600;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .side-account #dark-mode-toggle {
        grid-area: theme;
        width: 32px; height: 32px;
        display: grid;
        place-items: center;
        border-radius: var(--radius-sm);
        color: var(--text-secondary);
    }
    .side-account #dark-mode-toggle:hover {
        background: var(--side-hover);
        color: var(--text-primary);
    }
    .side-account #logout-btn {
        grid-area: logout;
        width: 100%;
        margin: 0;
    }

    /* ---- top bar -------------------------------------------------------- */
    .dashboard-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        padding: 0 28px;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 30;
    }
    /* The brand lives in the sidebar up here; the top bar just names the page. */
    .dashboard-header .topbar-logo { display: none; }
    .dashboard-header .header-left { gap: 0; }
    .dashboard-header h1 {
        font-size: 19px;
        font-weight: 650;
        letter-spacing: -0.01em;
        color: var(--text-tertiary);
        margin: 0;
    }
    .header-right { gap: 12px; }

    /* ---- content -------------------------------------------------------- */
    .tab-content {
        padding: 26px 28px 56px;
        min-width: 0;
    }
    .content-container {
        max-width: 1180px;
        margin: 0 auto;
    }
}

/* Wider rails on a large screen, but the content column stops growing so
   lines of text stay readable. */
@media (min-width: 1600px) {
    :root { --side-w: 264px; }
    .tab-content { padding-left: 40px; padding-right: 40px; }
}

/* ==========================================================================
   Surfaces, forms, buttons, modals

   Same palette, different depth. Everything here is a refinement of shapes
   already in the markup, so no screen needs new classes to pick it up.
   ========================================================================== */

/* ---- cards -------------------------------------------------------------- */
.card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-1);
    padding: 22px 24px;
}

.card h2 {
    font-size: 17px;
    font-weight: 650;
    letter-spacing: -0.01em;
    margin-bottom: 20px;
}

.card-header {
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}
.card-header h2 { margin-bottom: 0; }

/* ---- forms -------------------------------------------------------------- */
label {
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
select,
textarea {
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    border-radius: var(--radius-sm);
    border-color: var(--border-input);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .3s ease;
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
    border-color: var(--text-secondary);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--brand);
    /* The old ring was hard-coded iOS blue while the accent is Go-Forth red,
       so focus never matched the rest of the interface. */
    box-shadow: var(--ring);
}

input::placeholder, textarea::placeholder {
    color: var(--text-secondary);
    opacity: .7;
}

/* Widgets excluded for the same reason as above: a background erases them. */
input:not([type="checkbox"]):not([type="radio"]):disabled,
select:disabled, textarea:disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
}
input[type="checkbox"]:disabled,
input[type="radio"]:disabled { opacity: .5; cursor: not-allowed; }

/* A form's actions belong at its trailing edge, next to where the eye lands
   after the last field, rather than centred under the whole card. */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    text-align: left;
}
.form-actions .btn { min-width: 160px; }

@media (max-width: 768px) {
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; min-width: 0; }
}

/* ---- buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 18px;
    font-size: 14.5px;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.005em;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: background-color .15s ease, border-color .15s ease,
                box-shadow .15s ease, transform .08s ease;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.btn-primary {
    box-shadow: var(--elev-1);
}
.btn-primary:hover:not(:disabled) {
    box-shadow: var(--elev-2);
}

.btn-secondary {
    border-color: var(--border-input);
    box-shadow: var(--elev-1);
}

.btn-success, .btn-danger { box-shadow: var(--elev-1); }
.btn-success:hover:not(:disabled),
.btn-danger:hover:not(:disabled) { filter: brightness(1.06); box-shadow: var(--elev-2); }

.btn:disabled { box-shadow: none; transform: none; }

.btn-icon:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---- modals ------------------------------------------------------------- */
.modal {
    background: var(--overlay-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 24px;
    /* A tall modal should scroll the overlay, not get clipped by it. */
    overflow-y: auto;
    align-items: flex-start;
}

.modal-content {
    /* The radius was 0, which read as a dialog dropped in from another app. */
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--elev-3);
    max-width: 720px;
    width: 100%;
    max-height: calc(100vh - 48px);
    /* Centred vertically, but free to grow downward past the midpoint. */
    margin: auto;
    animation: modalIn .18s cubic-bezier(.2, .8, .3, 1);
    overflow: hidden;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .modal-content { animation: none; }
}

.modal-header {
    padding: 20px 22px;
    background: var(--bg-secondary);
}
.modal-header h2 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }

.modal-body { padding: 22px; overflow-y: auto; }

.modal-footer,
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 22px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.modal-close {
    font-size: 22px;
    line-height: 1;
}

/* ---- tables ------------------------------------------------------------- */
.requests-table,
.report-table {
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: var(--elev-1);
}

.requests-table th,
.report-table th {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
}

.requests-table tbody tr,
.report-table tbody tr {
    transition: background-color .12s ease;
}

/* ---- empty states ------------------------------------------------------- */
.empty-state {
    padding: 40px 24px;
    text-align: center;
}
.empty-state-title {
    font-size: 15px;
    font-weight: 650;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.empty-state-text { font-size: 13.5px; color: var(--text-secondary); }

/* The top bar names the screen, so a panel that also carried its own name in
   an <h1> was saying it twice, twenty pixels apart. The headings stay in the
   markup for anything that reads the document without the stylesheet. */
.page-heading {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
/* Their rows were space-between with the heading holding the left edge. */
.msg-header,
.reports-header { justify-content: flex-end; }

/* ---- GMB settings: the pick-one chooser --------------------------------- */
.gs-chooser-box { max-width: 560px; }

.gs-chooser-search { width: 100%; margin-bottom: 12px; }

.gs-chooser-list {
    max-height: min(46vh, 380px);
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
}

.gs-choice {
    display: block;
    width: 100%;
    padding: 10px 13px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: none;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color .12s ease;
}
.gs-choice:last-child { border-bottom: none; }
.gs-choice:hover { background: var(--hover-bg); }

.gs-choice.selected {
    background: var(--brand);
}
.gs-choice.selected .gs-choice-title,
.gs-choice.selected .gs-choice-sub { color: var(--brand-contrast); }

.gs-choice-title {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.gs-choice-sub {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.gs-chooser .gs-help { margin-bottom: 12px; }

/* ==========================================================================
   VISUAL REDESIGN — design layer
   ==========================================================================

   Everything above this line is the app's accumulated stylesheet: the shell,
   the mobile bottom bar, the screen-specific layouts. Everything below is the
   look. It is one layer, ordered from tokens outward - tokens, type, shell,
   shared components, then each screen, then the phone - so a question like
   "why is that badge green" has one place to be answered.

   Rules the layer keeps:
   - Go-Forth red is the only accent. Green / orange / blue / violet appear
     solely as status semantics (sent, clicked, completed, failed) and were
     already in the palette; they never decorate.
   - Every colour is a token, and every token has a dark value, so a component
     that looks right in one theme looks right in the other for free.
   - Depth is layered shadow plus a hairline, never a heavy grey halo. In dark
     mode shadows vanish against near-black, so surfaces get a 1px inner
     highlight on their top edge instead - that is what reads as "raised".
   ========================================================================== */

/* ---- tokens ------------------------------------------------------------- */
:root {
    /* Neutrals. A touch cooler than the originals so white cards separate
       from the page without needing a heavy shadow. */
    --bg-primary: #f3f3f6;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f4f4f7;
    --text-primary: #2a2a30;
    --text-secondary: #74747d;
    --text-tertiary: #131317;
    --border-color: #e6e6eb;
    --border-input: #d2d2d9;
    --border-strong: #b4b4bd;
    --hover-bg: #ededf1;
    --overlay-bg: rgba(18, 18, 22, 0.42);

    /* Brand derivatives: a tint for selected states, a gradient for the
       primary action, a red-tinted shadow that makes red things glow instead
       of casting a grey shadow. */
    --brand-tint: rgba(255, 59, 48, 0.08);
    --brand-tint-strong: rgba(255, 59, 48, 0.16);
    --brand-line: rgba(255, 59, 48, 0.32);
    --brand-grad: linear-gradient(135deg, #FF5C51 0%, #FF3B30 56%, #E52A1F 100%);
    --brand-glow: 0 6px 18px -6px rgba(255, 59, 48, 0.55);
    --brand-glow-lg: 0 10px 26px -8px rgba(255, 59, 48, 0.62);

    /* Status semantics: a text-safe strong value and a wash for its chip. */
    --ok:      #1E8E48;  --ok-tint:      rgba(52, 199, 89, 0.13);
    --warn:    #B36600;  --warn-tint:    rgba(255, 149, 0, 0.14);
    --bad:     #CC2419;  --bad-tint:     rgba(255, 59, 48, 0.11);
    --info:    #0A62BD;  --info-tint:    rgba(10, 132, 255, 0.12);
    --done:    #4F4DCF;  --done-tint:    rgba(94, 92, 230, 0.13);
    --neutral: #5f5f68;  --neutral-tint: rgba(120, 120, 128, 0.13);

    --surface-glass: rgba(255, 255, 255, 0.74);
    --side-bg: #ffffff;
    --side-hover: #f2f2f5;

    --radius-xl: 20px;
    --side-w: 248px;
    --topbar-h: 64px;

    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI Variable Text', 'Segoe UI',
            Inter, Roboto, 'Helvetica Neue', Arial, sans-serif;
    --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

body.dark-mode {
    /* Not pure black: near-black lets a card one step lighter still read as a
       card, and keeps the brand red from vibrating against the ground. */
    --bg-primary: #0b0b0d;
    --bg-secondary: #17171a;
    --bg-tertiary: #212125;
    --text-primary: #ececf1;
    --text-secondary: #9a9aa4;
    --text-tertiary: #ffffff;
    --border-color: #2a2a30;
    --border-input: #3a3a43;
    --border-strong: #55555f;
    --hover-bg: #26262b;
    --overlay-bg: rgba(0, 0, 0, 0.62);

    --brand-tint: rgba(255, 69, 58, 0.14);
    --brand-tint-strong: rgba(255, 69, 58, 0.24);
    --brand-line: rgba(255, 69, 58, 0.42);
    --brand-grad: linear-gradient(135deg, #FF6459 0%, #FF453A 56%, #E7352B 100%);
    --brand-glow: 0 8px 22px -6px rgba(255, 69, 58, 0.55);
    --brand-glow-lg: 0 12px 30px -8px rgba(255, 69, 58, 0.62);

    --ok:      #4ADE80;  --ok-tint:      rgba(48, 209, 88, 0.17);
    --warn:    #FFB340;  --warn-tint:    rgba(255, 159, 10, 0.17);
    --bad:     #FF6B62;  --bad-tint:     rgba(255, 69, 58, 0.17);
    --info:    #62AEFF;  --info-tint:    rgba(10, 132, 255, 0.2);
    --done:    #A4A2FF;  --done-tint:    rgba(94, 92, 230, 0.22);
    --neutral: #a9a9b3;  --neutral-tint: rgba(150, 150, 160, 0.17);

    --surface-glass: rgba(23, 23, 26, 0.74);
    --side-bg: #111113;
    --side-hover: #1f1f23;
}

/* ---- base --------------------------------------------------------------- */
body {
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { letter-spacing: -0.012em; line-height: 1.25; }

::selection { background: var(--brand-tint-strong); }

/* Thin, theme-aware scrollbars in place of the wide grey default. */
* { scrollbar-width: thin; scrollbar-color: var(--border-input) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-input);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--border-strong); }
body.dark-mode ::-webkit-scrollbar-track { background: transparent; }

/* ---- desktop shell ------------------------------------------------------ */
@media (min-width: 769px) {

    /* A faint red wash at the top-left corner of the page gives the content
       area a horizon; the eye reads it as light rather than as a colour. */
    .tab-content {
        background:
            radial-gradient(900px 360px at 8% -10%, var(--brand-tint) 0%, transparent 60%),
            var(--bg-primary);
        padding: 28px 32px 64px;
    }
    .content-container { max-width: 1160px; }

    /* sidebar */
    .side-nav {
        background: var(--side-bg);
        border-right: 1px solid var(--border-color);
    }
    .side-brand {
        height: var(--topbar-h);
        padding: 0 16px 0 20px;
        gap: 11px;
    }
    .side-brand .header-logo {
        width: 32px; height: 32px;
        border-radius: 9px;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.14);
    }
    .side-brand-name {
        font-size: 16.5px;
        font-weight: 700;
        letter-spacing: -0.02em;
    }

    .side-links { padding: 10px 12px 12px; gap: 3px; }

    .side-links .tab-btn {
        min-height: 40px;
        padding: 0 12px;
        gap: 12px;
        border-radius: 10px;
        font-size: 14px;
        font-weight: 500;
        color: var(--text-secondary);
        transition: background-color .15s ease, color .15s ease,
                    box-shadow .15s ease;
    }
    .side-links .tab-btn .nav-ico {
        width: 19px; height: 19px;
        stroke-width: 1.8;
        opacity: .8;
        transition: opacity .15s ease;
    }
    .side-links .tab-btn:hover {
        background: var(--side-hover);
        color: var(--text-primary);
    }
    .side-links .tab-btn:hover .nav-ico { opacity: 1; }

    /* The one filled element in the rail: brand gradient, a red glow instead
       of a grey shadow, and a 1px highlight on its top edge so it reads as a
       solid object rather than a painted row. */
    .side-links .tab-btn.active {
        background: var(--brand-grad);
        color: #fff;
        font-weight: 600;
        box-shadow: var(--brand-glow), inset 0 1px 0 rgba(255, 255, 255, 0.18);
    }
    .side-links .tab-btn.active .nav-ico { opacity: 1; stroke-width: 2; }
    .side-links .tab-btn.active .msg-nav-badge {
        background: rgba(255, 255, 255, 0.28);
        color: #fff;
    }

    .side-account {
        padding: 14px 12px 16px;
        gap: 10px 10px;
        border-top: 1px solid var(--border-color);
    }
    .side-avatar {
        width: 34px; height: 34px;
        font-size: 12.5px;
        background: var(--brand-grad);
        box-shadow: 0 0 0 2px var(--side-bg), 0 0 0 3.5px var(--brand-tint-strong);
    }
    .side-account #user-name { font-size: 13.5px; font-weight: 600; }
    .side-account #dark-mode-toggle {
        width: 34px; height: 34px;
        border-radius: 9px;
    }
    .side-account #dark-mode-toggle:hover { background: var(--side-hover); }

    /* top bar: translucent so content scrolling under it stays legible */
    .dashboard-header {
        padding: 0 32px;
        background: var(--surface-glass);
        -webkit-backdrop-filter: saturate(160%) blur(14px);
        backdrop-filter: saturate(160%) blur(14px);
        border-bottom: 1px solid var(--border-color);
    }
    .dashboard-header h1 {
        font-size: 20px;
        font-weight: 700;
        letter-spacing: -0.02em;
    }

    /* The requests table wrapper was forced to display:table, which disables
       its own horizontal scrolling. */
    .requests-table.desktop-only { display: block !important; }
}

/* ==========================================================================
   Shared components
   ========================================================================== */

/* ---- cards -------------------------------------------------------------- */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-1);
    padding: 24px 26px;
    margin-bottom: 20px;
}
body.dark-mode .card {
    border-color: rgba(255, 255, 255, 0.07);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), var(--elev-1);
}

.card h2 {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--text-tertiary);
    margin-bottom: 18px;
}
/* A one-line description under a card title (Users). */
.card > p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: -10px 0 18px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding-bottom: 16px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
}
.card-header h2 { margin: 0; }

.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filters select,
.filters input { width: auto; min-width: 150px; }

/* ---- forms -------------------------------------------------------------- */
label,
.form-group label,
.form-row label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--text-primary);
    margin-bottom: 7px;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
select,
textarea,
.form-control,
.sp-input,
.msg-search,
.req-search,
.gs-search,
.search-input,
.date-input,
.filter-select,
.filter-select-minimal,
.reports-filters select,
.gs-toolbar select,
.gs-chooser-search {
    font-family: inherit;
    font-size: 15px;
    line-height: 1.35;
    min-height: 42px;
    padding: 9px 13px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-input);
    border-radius: 10px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
    transition: border-color .15s ease, box-shadow .15s ease, background-color .2s ease;
}
body.dark-mode input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
body.dark-mode select,
body.dark-mode textarea { box-shadow: none; }

input:hover:not(:disabled):not(:focus),
select:hover:not(:disabled):not(:focus),
textarea:hover:not(:disabled):not(:focus) { border-color: var(--border-strong); }

input:focus, select:focus, textarea:focus,
.sp-input:focus, .msg-search:focus, .req-search:focus, .gs-search:focus,
.search-input:focus, .date-input:focus, .filter-select-minimal:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 4px var(--brand-tint-strong);
}

input::placeholder, textarea::placeholder { color: var(--text-secondary); opacity: .75; }

/* Checkbox and radio excluded: a background erases the widget, so a disabled
   one would render as an empty square instead of a greyed-out control. The
   default-template checkbox is disabled for managers, which is where this
   would have shown. */
input:not([type="checkbox"]):not([type="radio"]):disabled,
select:disabled, textarea:disabled,
input:not([type="checkbox"]):not([type="radio"])[readonly] {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: default;
}

textarea { min-height: 96px; line-height: 1.5; resize: vertical; }

/* One chevron for both themes; the old one only existed in dark mode.
   The :not(#\9) raises specificity to (1,0,1) without matching anything extra,
   so a stray descendant rule cannot strip the arrow again. */
select:not(#\9),
.filter-select-minimal:not(#\9),
.reports-filters select:not(#\9),
.gs-toolbar select:not(#\9) {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2374747d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    cursor: pointer;
}
body.dark-mode select:not(#\9),
body.dark-mode .filter-select-minimal:not(#\9),
body.dark-mode .reports-filters select:not(#\9),
body.dark-mode .gs-toolbar select:not(#\9) {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239a9aa4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 38px;
}

/* Native widgets, drawn by the browser and tinted with the brand colour.
   Everything a text-field rule applied is rolled back with `revert`, not
   zeroed: Chrome stops painting the native control the moment an author sets
   its background or border AT ALL, so `border: none; background: none` does
   not restore the checkbox - it erases it. `revert` hands the property back
   to the browser's own stylesheet, which is the only way to get the tick and
   the round radio back. */
input[type="checkbox"], input[type="radio"] {
    appearance: revert;
    -webkit-appearance: revert;
    padding: revert;
    border: revert;
    background: revert;
    border-radius: revert;
    box-shadow: none;
    width: 18px;
    height: 18px;
    min-height: 0;
    flex-shrink: 0;
    margin: 0;
    accent-color: var(--brand);
    cursor: pointer;
}

/* A ring on every click is noise; keyboard focus still gets one. */
input[type="checkbox"]:focus, input[type="radio"]:focus { box-shadow: none; }
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
input[type="date"] { min-width: 0; }
input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .6; }
body.dark-mode input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: .6; }

.form-row { gap: 18px 20px; }
.form-group { margin-bottom: 18px; }
.form-group small { display: block; margin-top: 6px; font-size: 12.5px; color: var(--text-secondary); }
label small { font-weight: 500; color: var(--text-secondary); }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-secondary);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}
.checkbox-label:hover { border-color: var(--border-strong); background: var(--bg-tertiary); }
.checkbox-label:has(input:checked) { border-color: var(--brand-line); background: var(--brand-tint); }
.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-section-label { margin-bottom: 10px; }
.date-pair { display: flex; align-items: center; gap: 10px; }
.date-pair span, .date-sep { color: var(--text-secondary); font-size: 13px; }

.form-fieldset {
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 16px 18px 2px;
    margin-bottom: 18px;
    min-width: 0;
}
.form-legend {
    padding: 0 8px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.hint-brand { color: var(--brand); font-weight: 500; }

/* Toggle switch */
.switch { width: 48px; height: 28px; }
.slider {
    background-color: var(--border-input);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.04);
    transition: background-color .2s ease;
}
.slider:before {
    width: 22px; height: 22px;
    left: 3px; bottom: 3px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform .2s cubic-bezier(.2, .8, .3, 1);
}
input:checked + .slider { background-color: var(--brand); }
input:checked + .slider:before { transform: translateX(20px); }
.switch-container { gap: 12px; font-size: 14px; font-weight: 500; }

/* The SMS preview reads as the text message it will become. */
.message-preview {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 16px 18px 18px;
    margin: 6px 0 22px;
}
.message-preview h4 {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 10px;
}
.preview-content {
    display: inline-block;
    max-width: min(100%, 520px);
    padding: 11px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px 16px 16px 5px;
    box-shadow: var(--elev-1);
    font-style: normal;
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--text-primary);
}
body.dark-mode .preview-content { background: var(--bg-primary); }

.form-actions {
    margin-top: 8px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.result-message {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
}
.result-message.success { background: var(--ok-tint); color: var(--ok); border-color: rgba(52, 199, 89, 0.3); }
.result-message.error   { background: var(--bad-tint); color: var(--bad); border-color: rgba(255, 59, 48, 0.3); }
.error-message { color: var(--bad); font-size: 13.5px; }

/* ---- buttons ------------------------------------------------------------ */
.btn,
.btn-outline-secondary,
.btn-edit-user {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 18px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: .005em;
    line-height: 1.2;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease,
                box-shadow .15s ease, transform .1s ease, filter .15s ease;
}
.btn:active:not(:disabled),
.btn-outline-secondary:active { transform: translateY(1px); }

.btn-primary {
    background: var(--brand-grad);
    color: #fff;
    border-color: transparent;
    box-shadow: var(--brand-glow), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.btn-primary:hover:not(:disabled) {
    background: var(--brand-grad);
    filter: brightness(1.06);
    box-shadow: var(--brand-glow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.btn-secondary,
.btn-outline-secondary,
.btn-edit-user {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-input);
    box-shadow: var(--elev-1);
}
.btn-secondary:hover:not(:disabled),
.btn-outline-secondary:hover,
.btn-edit-user:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-strong);
    color: var(--text-tertiary);
    box-shadow: var(--elev-1);
}
body.dark-mode .btn-secondary,
body.dark-mode .btn-outline-secondary,
body.dark-mode .btn-edit-user { background: var(--bg-tertiary); border-color: var(--border-input); }
body.dark-mode .btn-secondary:hover:not(:disabled),
body.dark-mode .btn-outline-secondary:hover,
body.dark-mode .btn-edit-user:hover { background: var(--hover-bg); border-color: var(--border-strong); }

.btn-success { background: var(--accent-green); color: #fff; box-shadow: var(--elev-1); }
.btn-success:hover:not(:disabled) { filter: brightness(1.06); }

/* Danger is a red outline, not a red fill: the primary action is already red,
   and "Delete user" must not look like "Save". */
.btn-danger {
    background: var(--bad-tint);
    color: var(--bad);
    border-color: rgba(255, 59, 48, 0.35);
    box-shadow: none;
}
.btn-danger:hover:not(:disabled) { background: var(--accent-red); color: #fff; border-color: transparent; filter: none; }

.btn-sm,
.btn.btn-sm { min-height: 34px; padding: 5px 13px; font-size: 13px; border-radius: 9px; }

.btn:disabled,
.btn-outline-secondary:disabled {
    opacity: .55;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    filter: none;
}

.btn:focus-visible,
.btn-outline-secondary:focus-visible,
.btn-edit-user:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--brand-tint-strong); }

/* Icon-only buttons (theme toggle). The second .btn-icon definition in the
   legacy block turned it into an inline-flex with a gap for review actions;
   both uses want a square, quiet target. */
.btn-icon {
    width: 36px; height: 36px;
    padding: 0;
    border-radius: 10px;
    color: var(--text-secondary);
    background: transparent;
    border: none;
}
.btn-icon:hover { background: var(--hover-bg); color: var(--text-primary); }
.btn-icon svg { width: 20px; height: 20px; }

/* ---- badges & chips ----------------------------------------------------- */
.status-badge, .role-badge, .user-role-badge, .match-badge, .sync-status-badge,
.rate-badge, .req-stage-badge, .gs-conf, .gs-chip, .gs-flag, .msg-tag,
.match-score, .badge-count, .notification-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 22px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .01em;
    line-height: 1.2;
    white-space: nowrap;
    vertical-align: middle;
    text-transform: none;
    background: var(--neutral-tint);
    color: var(--neutral);
    border: 1px solid transparent;
    min-width: 0;
}
.gs-conf, .msg-tag, .gs-flag { font-size: 10.5px; min-height: 20px; padding: 1px 7px; letter-spacing: .04em; text-transform: uppercase; }
.gs-chip { font-size: 11px; min-height: 20px; padding: 1px 8px; }

/* Status chips carry a dot so state is readable without relying on hue. */
.status-badge::before, .sync-status-badge::before, .req-stage-badge::before, .rate-badge::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

/* semantic variants */
.status-sent, .status-delivered, .status-badge.active, .status-active,
.match-badge.high, .sync-status-badge.completed, .rate-good, .req-stage-reviewed,
.gs-conf-exact, .gs-conf-high, .gs-flag-ok, .gs-chip-pest, .role-tech, .role-badge.technician, .user-role-badge.technician {
    background: var(--ok-tint); color: var(--ok);
}
.status-clicked, .match-badge.manual, .sync-status-badge.running, .gs-chip-hvac,
.role-manager, .role-badge.manager, .user-role-badge.manager,
.status-updated, .req-stage-updated {
    background: var(--info-tint); color: var(--info);
}

/* A sentence under a card heading, when the heading shares its row with
   a search box or a filter. */
.card-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-secondary);
}

/* How many users the search is showing, above the list. */
.users-count {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.status-completed {
    background: var(--done-tint); color: var(--done);
}
.status-failed, .status-undelivered, .status-badge.inactive, .status-badge.disabled, .status-inactive,
.match-badge.low, .sync-status-badge.failed, .rate-low, .req-stage-failed, .gs-flag-err, .msg-tag-optout {
    background: var(--bad-tint); color: var(--bad);
}
.status-badge.error, .match-badge.medium, .sync-status-badge.partial, .rate-ok,
.req-stage-clicked, .gs-conf-medium, .gs-flag-warn {
    background: var(--warn-tint); color: var(--warn);
}
.status-pending, .status-queued, .status-generated, .match-badge.unmatched,
.gs-conf-none, .gs-conf-low {
    background: var(--neutral-tint); color: var(--neutral);
}
.role-admin, .role-badge.admin, .user-role-badge.admin, .gs-conf-manual {
    background: var(--brand-tint); color: var(--brand);
}
/* Solid counters */
.match-score, .badge-count, .notification-badge, .msg-nav-badge, .gs-badge, .msg-convo-badge, .bnav-badge {
    background: var(--brand);
    color: #fff;
    border: none;
    font-weight: 700;
}
.badge-count { min-width: 20px; height: 20px; min-height: 20px; padding: 0 6px; font-size: 11.5px; justify-content: center; }
.lb-gold { color: var(--star-gold); }

.user-status { font-size: 13px; font-weight: 500; }
.user-status-dot { width: 8px; height: 8px; box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04); }
.user-status-dot.active { background: var(--accent-green); }
.user-status-dot.inactive { background: var(--text-secondary); }

/* ---- tables ------------------------------------------------------------- */
.requests-table,
.lb-table-wrap,
.users-container,
.requests-table-wrapper,
.report-table-wrap {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: var(--elev-1);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}
body.dark-mode .requests-table,
body.dark-mode .lb-table-wrap,
body.dark-mode .users-container,
body.dark-mode .requests-table-wrapper,
body.dark-mode .report-table-wrap { border-color: rgba(255, 255, 255, 0.07); }

/* A table that sits inside a card doesn't need its own shadow as well. */
.card .requests-table,
.card .lb-table-wrap,
.card .users-container { box-shadow: none; }

table { width: 100%; border-collapse: collapse; }

th,
.users-table th,
.leaderboard-table th,
.report-table th,
.requests-table th,
.requests-table-wrapper .requests-table th {
    padding: 11px 16px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    text-align: left;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
td,
.users-table td,
.leaderboard-table td,
.report-table td,
.requests-table-wrapper .requests-table td {
    padding: 13px 16px;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color .12s ease; }
tbody tr:hover,
.users-table tbody tr:hover,
.leaderboard-table tbody tr:hover,
.report-table tbody tr:hover,
.requests-table-wrapper .requests-table tbody tr:hover { background: var(--bg-tertiary); }
thead tr:hover { background: transparent; }
td .btn, td .btn-sm { vertical-align: middle; }

/* Top-three rows on the leaderboard: a gold wash that fades out. */
.leaderboard-table tbody tr.highlight-row,
body.dark-mode .leaderboard-table tbody tr.highlight-row {
    background: linear-gradient(90deg, rgba(232, 164, 0, 0.12), transparent 60%) !important;
}
.leaderboard-table tbody tr.highlight-row:hover,
body.dark-mode .leaderboard-table tbody tr.highlight-row:hover {
    background: linear-gradient(90deg, rgba(232, 164, 0, 0.18), var(--bg-tertiary) 60%) !important;
}

/* Report tables. The legacy rule made the <table> itself display:block so it
   could scroll; a block table's rows then shrink-wrap, leaving the frame wider
   than the header. reports.js always puts the table straight inside a .card,
   so the card is the scroller and the table is a table again. */
#reports-content .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#reports-content .report-table {
    display: table;
    width: 100%;
    min-width: 640px;
    overflow: visible;
    white-space: normal;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: none;
    background: var(--bg-secondary);
}
#reports-content .report-table th,
#reports-content .report-table td { white-space: nowrap; }

/* ---- stat tiles --------------------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat-card,
#performance-summary .stat-card {
    position: relative;
    overflow: hidden;
    text-align: left;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-1);
    padding: 20px 22px 18px;
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
body.dark-mode .stat-card,
body.dark-mode #performance-summary .stat-card {
    border-color: rgba(255, 255, 255, 0.07);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), var(--elev-1);
}
/* A soft brand glow in one corner, under the number. */
.stat-card::after {
    content: '';
    position: absolute;
    right: -70px; top: -80px;
    width: 190px; height: 190px;
    border-radius: 50%;
    background: radial-gradient(closest-side, var(--brand-tint), transparent);
    pointer-events: none;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--elev-2); }
body.dark-mode .stat-card:hover { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), var(--elev-2); }

.stat-card h3,
#performance-summary .stat-card h3 {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.stat-value,
#performance-summary .stat-value {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    margin: 0 0 10px;
}
.stat-subtitle,
#performance-summary .stat-subtitle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-secondary);
}
.stat-subtitle::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--brand);
    opacity: .75;
}
/* Tiles nested inside a card become flat tiles on the card's surface. */
.card .stat-card,
.card #performance-summary .stat-card {
    background: var(--bg-tertiary);
    border-color: transparent;
    box-shadow: none;
}
.card .stat-card:hover { transform: none; box-shadow: none; border-color: var(--border-color); }
.card .stats-grid { margin-bottom: 0; }
body.dark-mode .card .stat-card { background: var(--bg-tertiary); box-shadow: none; }

/* ---- loading, empty, error states -------------------------------------- */
.loading-text,
.loading-card,
.loading-row td,
.lb-empty,
.reports-empty,
.reports-error {
    padding: 44px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
}
.lb-error, .reports-error { color: var(--bad); }

/* Only the placeholders that are unambiguously "loading" get a spinner:
   .loading-text is reused by scripts for errors and empty results. */
.loading-row td,
.loading-text.is-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.loading-row td { display: table-cell; }
.loading-row td::before,
.loading-text.is-loading::before {
    content: '';
    display: inline-block;
    width: 16px; height: 16px;
    margin-right: 10px;
    vertical-align: -3px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    border-top-color: var(--brand);
    animation: spin .8s linear infinite;
}
.loading-text.is-loading::before { margin-right: 0; }

.empty-state { padding: 56px 24px; text-align: center; }
.empty-state-icon {
    width: 64px; height: 64px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    background: var(--bg-tertiary);
    box-shadow: inset 0 0 0 1px var(--border-color);
    font-size: 28px;
    line-height: 1;
    opacity: 1;
}
.empty-state-title { font-size: 16px; font-weight: 700; color: var(--text-tertiary); margin-bottom: 4px; }
.empty-state-text { font-size: 13.5px; color: var(--text-secondary); max-width: 360px; margin: 0 auto; }

.spinner-circle {
    width: 36px; height: 36px;
    border-width: 3px;
    border-color: var(--border-color);
    border-top-color: var(--brand);
}

/* ---- toasts ------------------------------------------------------------- */
.toast-container {
    top: 18px; right: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10001;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 280px;
    max-width: 400px;
    margin: 0;
    padding: 12px 16px 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--brand);
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: var(--elev-3);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    pointer-events: auto;
    animation: toastIn .28s cubic-bezier(.2, .8, .3, 1);
}
body.dark-mode .toast { background: var(--bg-tertiary); border-color: rgba(255, 255, 255, 0.08); }
.toast::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--brand);
    flex-shrink: 0;
}
.toast.success { border-left-color: var(--accent-green); }
.toast.success::before { background: var(--accent-green); }
.toast.error { border-left-color: var(--accent-red); }
.toast.error::before { background: var(--accent-red); }
.toast.warning { border-left-color: var(--accent-orange); }
.toast.warning::before { background: var(--accent-orange); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-8px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

/* ---- modals ------------------------------------------------------------- */
.modal {
    background: var(--overlay-bg);
    -webkit-backdrop-filter: blur(10px) saturate(120%);
    backdrop-filter: blur(10px) saturate(120%);
    padding: 24px;
}
.modal-content {
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--elev-3);
    background: var(--bg-secondary);
    overflow: hidden;
}
body.dark-mode .modal-content {
    border-color: rgba(255, 255, 255, 0.09);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), var(--elev-3);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 24px 18px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}
.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.015em;
    margin: 0;
}
.modal-close {
    width: 34px; height: 34px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 20px;
    flex-shrink: 0;
}
.modal-close:hover { background: var(--hover-bg); color: var(--text-tertiary); }

.modal-body { padding: 24px; }
.modal-content form { padding: 24px; }
.modal-content > .review-preview { margin: 20px 24px 0; }
.modal-intro { color: var(--text-secondary); font-size: 14px; line-height: 1.55; margin: 0 0 22px; }

.modal-footer,
.modal-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    margin: 0;
}
/* Actions inside a padded form extend to the modal's edges like a footer. */
.modal-content form .modal-actions { margin: 24px -24px -24px; }
.modal-footer-split { justify-content: space-between; }
.modal-footer-group { display: flex; gap: 10px; }
.modal-footer .btn, .modal-actions .btn { margin: 0; }

.review-preview {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 0;
}
.review-preview-header { gap: 12px; margin-bottom: 8px; font-weight: 600; }
.review-preview-comment { font-size: 14px; line-height: 1.6; color: var(--text-primary); }
.response-templates { margin: 14px 0 4px; }
.response-templates label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-secondary); }
.template-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.locations-checkboxes {
    max-height: 280px;
    padding: 6px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
}
.location-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 38px;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color .12s ease;
}
.location-checkbox:hover { background: var(--bg-secondary); }
.location-checkbox span { font-size: 14px; }

/* Add-GMB modal helper panels (were inline iOS-blue styles). */
.gs-discover-box {
    padding: 16px;
    margin-bottom: 20px;
    background: var(--brand-tint);
    border: 1px solid var(--brand-line);
    border-radius: 14px;
}
.gs-discover-box small { display: block; margin-top: 8px; text-align: center; font-size: 12.5px; color: var(--text-secondary); }
.gs-discovery-results {
    margin-bottom: 20px;
    max-height: 300px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-primary);
}

/* ---- PWA install banner -------------------------------------------------- */
.install-banner {
    border-radius: 16px;
    background: var(--surface-glass);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    backdrop-filter: blur(16px) saturate(160%);
}
.install-banner-icon { font-size: 30px; }
.install-close { width: 30px; height: 30px; }

/* ==========================================================================
   Screens
   ========================================================================== */

/* ---- login -------------------------------------------------------------- */
/* Two soft red glows and a faint dot grid: enough atmosphere that the page
   feels designed, quiet enough that the card is still the only thing to do. */
#login-screen {
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}
#login-screen::before,
#login-screen::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    /* No filter: blur() here. Two 640px blurred layers made every repaint of
       the page expensive; the gradient's own falloff is soft enough. */
}
#login-screen::before {
    width: 640px; height: 640px;
    left: -200px; top: -240px;
    background: radial-gradient(closest-side, rgba(255, 59, 48, 0.22), transparent);
}
#login-screen::after {
    width: 560px; height: 560px;
    right: -180px; bottom: -220px;
    background: radial-gradient(closest-side, rgba(255, 59, 48, 0.14), transparent);
}
body.dark-mode #login-screen::before { background: radial-gradient(closest-side, rgba(255, 69, 58, 0.26), transparent); }
body.dark-mode #login-screen::after  { background: radial-gradient(closest-side, rgba(255, 69, 58, 0.18), transparent); }

.login-container { position: relative; z-index: 1; padding: 40px 20px; }
.login-container::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image: radial-gradient(var(--border-input) 1px, transparent 1.3px);
    background-size: 26px 26px;
    -webkit-mask-image: radial-gradient(ellipse 60% 55% at 50% 45%, #000 10%, transparent 72%);
            mask-image: radial-gradient(ellipse 60% 55% at 50% 45%, #000 10%, transparent 72%);
    opacity: .7;
}
.login-header, .login-form { position: relative; z-index: 1; }

.login-header { margin-bottom: 22px; }
.app-logo {
    width: 92px; height: 92px;
    margin-bottom: 18px;
    border-radius: 24px;
    box-shadow: 0 16px 36px -12px rgba(255, 59, 48, 0.55), 0 2px 6px rgba(0, 0, 0, 0.12);
}
.login-header h1 {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-tertiary);
    margin-bottom: 6px;
}
.login-header p { font-size: 15px; color: var(--text-secondary); }

.login-form {
    max-width: 400px;
    padding: 26px;
    background: var(--surface-glass);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
    backdrop-filter: blur(18px) saturate(150%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    box-shadow: var(--elev-3);
}
body.dark-mode .login-form {
    border-color: rgba(255, 255, 255, 0.09);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), var(--elev-3);
}
.google-signin-btn { min-height: 48px; font-size: 15px; margin-bottom: 0; }
/* The multicolour G sits on a white disc so it stays legible on red. */
.google-signin-btn svg {
    width: 26px !important;
    height: 26px !important;
    padding: 4px;
    margin-right: 6px !important;
    box-sizing: border-box;
    background: #fff;
    border-radius: 50%;
}
.login-form .error-message { margin-top: 14px; text-align: center; }

/* ---- send request ------------------------------------------------------- */
/* A two-column form at 1160px has fields a foot wide; cap it. */
#send-request-tab .content-container { max-width: 880px; }

.sp-clear { width: 26px; height: 26px; right: 10px; font-size: 18px; }
.sp-options {
    border-radius: 12px;
    border-color: var(--border-color);
    box-shadow: var(--elev-3);
    overflow: hidden;
}
body.dark-mode .sp-options { border-color: rgba(255, 255, 255, 0.09); }
.sp-group {
    padding: 8px 12px 5px;
    font-size: 10.5px;
    letter-spacing: .06em;
    background: var(--bg-tertiary);
}
.sp-option { padding: 10px 13px; font-size: 14.5px; }
.sp-option:hover,
.sp-option.active { background: var(--brand-tint); color: var(--text-tertiary); }
.sp-option-meta { font-size: 11px; }

/* ---- my requests -------------------------------------------------------- */
.req-search,
.msg-search,
.gs-search,
.search-input {
    padding-left: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2374747d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 16px;
}
body.dark-mode .req-search,
body.dark-mode .msg-search,
body.dark-mode .gs-search,
body.dark-mode .search-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239a9aa4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M21 21l-4.3-4.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    background-size: 16px;
}
.req-search,
.filters .req-search { min-width: 240px; flex: 1 1 240px; max-width: 320px; }

.request-card { border-radius: 14px; box-shadow: var(--elev-1); }
.request-customer-name { font-size: 15.5px; color: var(--text-tertiary); }
.req-step.reached .req-step-dot { box-shadow: 0 0 0 3px var(--ok-tint); }
.req-meta { font-weight: 500; }

/* ---- segmented controls (Messages, Reports, GMB) ------------------------ */
/* Neutral track, white pill, brand-coloured label: brand marks the choice
   without a second red block competing with the primary button. */
.msg-sub-nav,
.reports-sub-nav,
.gs-subnav {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}
.gs-subnav { margin-bottom: 14px; }

.msg-sub-btn,
.reports-sub-btn,
.gs-subbtn {
    min-height: 34px;
    padding: 6px 14px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.msg-sub-btn:hover,
.reports-sub-btn:hover,
.gs-subbtn:hover { color: var(--text-primary); background: rgba(0, 0, 0, 0.04); }
body.dark-mode .msg-sub-btn:hover,
body.dark-mode .reports-sub-btn:hover,
body.dark-mode .gs-subbtn:hover { background: rgba(255, 255, 255, 0.05); }

.msg-sub-btn.active,
.reports-sub-btn.active,
.gs-subbtn.active {
    background: var(--bg-secondary);
    color: var(--brand);
    box-shadow: var(--elev-1);
}
body.dark-mode .msg-sub-btn.active,
body.dark-mode .reports-sub-btn.active,
body.dark-mode .gs-subbtn.active { background: #2c2c32; }
.gs-subbtn.active .gs-badge { background: var(--brand); color: #fff; }

/* ---- messages ----------------------------------------------------------- */
.msg-header { justify-content: flex-start; margin-bottom: 16px; }

.msg-layout { height: calc(100vh - 212px); min-height: 480px; gap: 16px; }

.msg-list-pane,
.msg-thread-pane {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--elev-1);
}
body.dark-mode .msg-list-pane,
body.dark-mode .msg-thread-pane { border-color: rgba(255, 255, 255, 0.07); }
.msg-list-pane { flex-basis: 340px; }

.msg-list-controls { padding: 12px; gap: 8px; }
.msg-search { min-height: 40px; font-size: 14px; }
.msg-filter-row select {
    min-height: 36px;
    font-size: 13px;
    padding: 5px 30px 5px 10px;
    background-position: right 10px center;
}
.msg-filter-chip {
    min-height: 36px;
    padding: 0 13px;
    border-radius: 999px;
    border: 1px solid var(--border-input);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.msg-filter-chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.msg-filter-chip.active {
    background: var(--brand-tint);
    border-color: var(--brand-line);
    color: var(--brand);
}

.msg-convo {
    position: relative;
    padding: 12px 14px;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}
.msg-convo:hover { background: var(--bg-tertiary); }
.msg-convo.active { background: var(--brand-tint); }
.msg-convo.active::before {
    content: '';
    position: absolute;
    left: 0; top: 10px; bottom: 10px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
}
.msg-convo-avatar {
    flex-basis: 40px;
    height: 40px;
    background: var(--brand-grad);
    font-size: 13.5px;
    box-shadow: var(--elev-1);
}
.msg-convo-name { font-size: 14.5px; font-weight: 600; }
.msg-convo.unread .msg-convo-name { font-weight: 700; color: var(--text-tertiary); }
.msg-convo-time { font-size: 11.5px; }
.msg-convo-preview { font-size: 13px; margin-top: 3px; }
.msg-convo-location {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.msg-thread-header { padding: 12px 18px; min-height: 60px; }
.msg-thread-name { font-size: 15px; font-weight: 700; color: var(--text-tertiary); }
.msg-thread { padding: 18px; gap: 6px; background: var(--bg-primary); }
body.dark-mode .msg-thread { background: #101012; }
.msg-day-divider span {
    padding: 4px 11px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.msg-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 18px;
    box-shadow: var(--elev-1);
}
.msg-row.in .msg-bubble { border-bottom-left-radius: 6px; background: var(--bg-secondary); }
.msg-row.out .msg-bubble {
    border-bottom-right-radius: 6px;
    background: var(--brand-grad);
    border-color: transparent;
    color: #fff;
    box-shadow: var(--brand-glow);
}
.msg-row.out .msg-bubble.auto {
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-input);
    color: var(--text-primary);
    box-shadow: none;
}
.msg-bubble.failed { border: 1px solid var(--accent-red); }
.msg-text { font-size: 14.5px; }
.msg-bubble-meta { margin-top: 5px; font-size: 10.5px; }

.msg-composer { padding: 12px 14px; }
.msg-composer-form { gap: 10px; }
.msg-composer-form .msg-composer-input {
    min-height: 42px;
    max-height: 140px;
    padding: 10px 16px;
    border-radius: 21px;
    background: var(--bg-primary);
    font-size: 14.5px;
    line-height: 1.4;
    box-shadow: none;
    resize: none;
}
.msg-composer-form .btn { min-height: 42px; padding: 8px 20px; border-radius: 21px; margin: 0; }
.msg-char-count { font-size: 11px; margin-top: 5px; }
.msg-composer-notice {
    padding: 8px 12px;
    border-radius: 10px;
    background: var(--bad-tint);
    color: var(--bad);
    font-size: 12.5px;
    font-weight: 500;
}

.msg-autoreply-card { border-radius: 16px; padding: 18px 20px; box-shadow: var(--elev-1); }
body.dark-mode .msg-autoreply-card { border-color: rgba(255, 255, 255, 0.07); }
.msg-autoreply-name { font-size: 15px; font-weight: 700; color: var(--text-tertiary); }
.msg-switch { font-weight: 500; }

/* ---- statistics --------------------------------------------------------- */
.location-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
}
.location-stats > .loading-text,
.location-stats > .empty-state { grid-column: 1 / -1; }
.location-stat {
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: 14px;
    padding: 14px 16px;
    margin: 0;
    transition: border-color .15s ease;
}
.location-stat:hover { border-color: var(--border-color); }
.location-stat h4 { font-size: 14px; font-weight: 700; color: var(--text-tertiary); margin-bottom: 10px; }
.location-metrics { display: flex; gap: 18px; }
.location-metric .value {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--text-tertiary);
}
.location-metric .label {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

/* ---- leaderboard -------------------------------------------------------- */
.leaderboard-table { margin-top: 0; }
#performance-summary.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
}
.leaderboard-table td:first-child { font-weight: 700; }
body.dark-mode .leaderboard-table tbody td.lb-error { color: var(--bad) !important; }
.lb-card { border-radius: 14px; box-shadow: var(--elev-1); }
.lb-card-top {
    border-color: rgba(232, 164, 0, 0.5);
    background: linear-gradient(180deg, rgba(232, 164, 0, 0.08), transparent 60%), var(--bg-secondary);
}
.lb-avatar-initial { background: var(--brand-grad); }
.lb-name { color: var(--text-tertiary); }
.lb-metric-value { font-variant-numeric: tabular-nums; }

/* ---- reviews ------------------------------------------------------------ */
.reviews-filter-bar {
    padding: 16px 18px;
    border-radius: 16px;
    box-shadow: var(--elev-1);
    margin-bottom: 20px;
}
body.dark-mode .reviews-filter-bar { border-color: rgba(255, 255, 255, 0.07); }

/* The filters were a 280px column beside an odd three-column grid; a wrapping
   row lets each control take the width it needs. */
.filter-row-top { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.search-input-wrapper { flex: 1 1 260px; max-width: 340px; }
.search-icon { display: none; }
.search-input { min-height: 40px; font-size: 14px; }
.filter-badge-group { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; flex: 1 1 auto; }
.filter-badge-group .date-range-picker,
.filter-badge-group #review-tech-filter { grid-column: auto; }
/* The global `select { width: 100% }` would give each filter its own row. */
.filter-badge-group select,
.filter-badge-group .date-input { width: auto; min-width: 150px; flex: 0 1 auto; }
.filter-badge-group .date-range-picker { display: inline-flex; }

.filter-badge {
    min-height: 40px;
    padding: 0 14px;
    gap: 8px;
    border-radius: 10px;
    border: 1px solid var(--border-input);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.filter-badge:hover { border-color: var(--border-strong); background: var(--bg-tertiary); }
.filter-badge.active {
    background: var(--brand-tint);
    border-color: var(--brand-line);
    color: var(--brand);
}
.filter-select-minimal { min-height: 40px; font-size: 14px; }
.date-input { min-height: 40px; font-size: 14px; }
.date-range-picker { gap: 2px; }

.reviews-section-header { margin: 4px 0 14px; gap: 12px; flex-wrap: wrap; }
.reviews-section-header h2 {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.015em;
    color: var(--text-tertiary);
}
.reviews-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.review-card-modern {
    padding: 20px 22px;
    border-radius: 16px;
    box-shadow: var(--elev-1);
    transition: box-shadow .18s ease, border-color .18s ease;
}
body.dark-mode .review-card-modern { border-color: rgba(255, 255, 255, 0.07); }
.review-card-modern:hover { border-color: var(--brand-line); box-shadow: var(--elev-2); }
.review-location-header { margin-bottom: 14px; padding-bottom: 12px; }
.review-location-name {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.reviewer-avatar-modern { width: 44px; height: 44px; }
.reviewer-avatar-modern.initials { background: var(--brand-grad); font-size: 16px; box-shadow: var(--elev-1); }
.reviewer-name-modern { font-size: 15px; font-weight: 700; color: var(--text-tertiary); }
.review-meta-modern { font-size: 13px; }
.review-stars-modern { gap: 1px; margin-bottom: 12px; }
.star-filled, .star-empty { font-size: 17px; }
.star-empty,
body.dark-mode .star-empty { color: var(--border-input) !important; }
.review-comment-modern { font-size: 15px; line-height: 1.65; }
.review-match-info-modern {
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--ok-tint);
    border-color: rgba(52, 199, 89, 0.28);
}
.review-match-info-modern.no-invite { background: var(--neutral-tint); border-color: transparent; }
.review-match-info-modern .match-label { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.review-reply-section-modern {
    padding: 12px 14px;
    border-radius: 12px;
    border-left: 3px solid var(--brand);
    background: var(--bg-tertiary);
}
.review-reply-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--brand);
}
.review-reply-text { font-size: 14px; line-height: 1.55; }
.quick-reply-btn {
    min-height: 32px;
    padding: 5px 13px;
    border-radius: 999px;
    border: 1px solid var(--border-input);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.quick-reply-btn:hover { background: var(--brand-tint); border-color: var(--brand-line); color: var(--brand); }
.review-reply-input { min-height: 90px; padding: 12px 44px 12px 14px; border-radius: 12px; background: var(--bg-secondary); }
.emoji-picker-btn {
    right: 8px; bottom: 8px;
    width: 32px; height: 32px;
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 8px;
    font-size: 18px;
}
.emoji-picker-btn:hover { background: var(--hover-bg); }
.review-actions-modern { gap: 8px; }
.ai-assistant-banner { border-radius: 12px; font-weight: 500; box-shadow: var(--brand-glow); }

/* legacy review cards (gmb-admin.js) */
.review-card { border: 1px solid var(--border-color); border-radius: 16px; box-shadow: var(--elev-1); }
.review-card:hover { border-color: var(--brand-line); box-shadow: var(--elev-2); }
.reviewer-avatar { background: var(--brand-grad); }
.reviewer-name { color: var(--text-tertiary); }
.review-match-info { border-radius: 12px; }
.review-reply { border-radius: 12px; background: var(--bg-tertiary); }

/* ---- users -------------------------------------------------------------- */
.users-container { margin-top: 4px; }
.user-info { gap: 12px; }
.user-avatar {
    width: 38px; height: 38px;
    flex-shrink: 0;
    font-size: 14px;
    background: var(--brand-grad);
    box-shadow: var(--elev-1);
}
.user-name { font-size: 14.5px; font-weight: 600; color: var(--text-tertiary); }
.user-email { font-size: 12.5px; }
.user-locations-count { font-weight: 500; font-variant-numeric: tabular-nums; }
.user-actions { gap: 8px; }
.btn-edit-user { min-height: 34px; padding: 5px 13px; font-size: 13px; border-radius: 9px; }
.user-card { border-radius: 14px; box-shadow: var(--elev-1); }
.user-card-name { color: var(--text-tertiary); }
.user-fact-value { font-variant-numeric: tabular-nums; }
.user-fact-label { letter-spacing: .04em; text-transform: uppercase; }

/* ---- GMB settings ------------------------------------------------------- */
.gs-strip {
    padding: 16px 20px;
    gap: 14px;
    margin-bottom: 14px;
    border-radius: 16px;
    box-shadow: var(--elev-1);
}
body.dark-mode .gs-strip { border-color: rgba(255, 255, 255, 0.07); }
.gs-stat { min-width: 104px; padding-right: 18px; gap: 3px; }
.gs-stat-value {
    font-size: 24px;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--text-tertiary);
}
.gs-stat-label {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.gs-alert {
    padding: 11px 14px 11px 16px;
    border-radius: 12px;
    border: 1px solid transparent;
    border-left-width: 4px;
    font-weight: 500;
}
.gs-alert-warn  { background: var(--warn-tint); border-left-color: var(--accent-orange); }
.gs-alert-error { background: var(--bad-tint);  border-left-color: var(--accent-red); }

.gs-toolbar { gap: 8px; margin-bottom: 12px; }
.gs-toolbar .btn { min-height: 40px; }
.gs-search { min-height: 40px; font-size: 14px; }
.gs-toolbar select { min-height: 40px; font-size: 14px; padding: 6px 34px 6px 12px; }
.gs-cache-note { font-size: 12px; }
.gs-help { font-size: 13.5px; margin-bottom: 14px; }

.gs-rows { border-radius: 14px; box-shadow: var(--elev-1); }
body.dark-mode .gs-rows { border-color: rgba(255, 255, 255, 0.07); }
.gs-row { padding: 12px 16px; gap: 14px; transition: background-color .12s ease; }
.gs-row:hover { background: var(--bg-tertiary); }
.gs-row-title { font-size: 14.5px; font-weight: 600; color: var(--text-tertiary); }
.gs-row-sub { font-size: 12.5px; }
.gs-row-metric span { font-size: 14px; font-variant-numeric: tabular-nums; }
.gs-row-metric small { font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; }

.gs-block { padding: 18px 20px; border-radius: 16px; box-shadow: var(--elev-1); }
body.dark-mode .gs-block { border-color: rgba(255, 255, 255, 0.07); }
.gs-h3 { font-size: 15px; font-weight: 700; color: var(--text-tertiary); }
.gs-legacy summary { font-size: 14px; font-weight: 600; color: var(--text-secondary); }

.gs-chooser-list { border-radius: 12px; }
.gs-choice.selected { background: var(--brand-grad); }

/* GMB admin (legacy renderer) */
.gmb-location-card {
    background: var(--bg-tertiary);
    border: 1px solid transparent;
    border-radius: 14px;
    transition: border-color .15s ease;
}
.gmb-location-card:hover { background: var(--bg-tertiary); border-color: var(--border-color); }
.gmb-location-name { font-weight: 700; color: var(--text-tertiary); }
.gmb-location-id { font-family: var(--mono); font-size: 12px; }
.gmb-stat-value { font-size: 18px; font-variant-numeric: tabular-nums; }
.sync-log-item { padding: 12px 16px; border-radius: 12px; background: var(--bg-tertiary); }
.sync-log-stat-value { font-variant-numeric: tabular-nums; }
.gmb-notice-info, .gmb-notice-warn, .gmb-notice-ok { border-radius: 12px; }

/* ---- reports ------------------------------------------------------------ */
/* The markup puts "Export CSV" in its own row above the report chooser. One
   row reads better: chooser, filters, then the export button at the far end.
   Flex order does it without touching the markup; the visually-hidden <h1>
   still comes first for screen readers. */
#reports-tab .content-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px 12px;
}
.reports-header { order: 2; flex: 0 0 auto; margin: 0; }
.reports-controls { order: 1; flex: 1 1 auto; margin: 0; gap: 12px; }
#reports-content { order: 3; flex: 1 1 100%; min-width: 0; }
.reports-filters select {
    min-height: 40px;
    min-width: 150px;
    font-size: 14px;
    padding: 6px 34px 6px 12px;
}
.reports-grid-2col { gap: 16px; }

.star-bar-track, body.dark-mode .star-bar-track { height: 14px; border-radius: 7px; background: var(--bg-tertiary); }
.star-bar-fill { border-radius: 7px; }
.star-bar-label { font-weight: 600; }
.star-bar-count { font-variant-numeric: tabular-nums; }

.sync-stat, body.dark-mode .sync-stat { padding: 14px; border-radius: 12px; background: var(--bg-tertiary); }
.sync-stat-value { font-size: 26px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sync-stat-label {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
}
.match-stat-row, .sms-status-row { font-size: 14px; }
.match-dot, .sms-status-dot { box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04); }
.sms-status-count { font-variant-numeric: tabular-nums; }
.trend-bar { transition: opacity .12s ease; }

/* ==========================================================================
   Phone
   The shell (bottom bar, More sheet) is unchanged in behaviour; this is how it
   looks, plus how every component above reflows under 769px.
   ========================================================================== */
@media (max-width: 768px) {

    .tab-content {
        padding: 16px 16px calc(92px + env(safe-area-inset-bottom, 0px));
        background:
            radial-gradient(520px 260px at 0% -6%, var(--brand-tint) 0%, transparent 62%),
            var(--bg-primary);
    }

    /* header */
    .dashboard-header {
        display: flex;
        align-items: center;
        min-height: 56px;
        padding: 0 16px !important;
        background: var(--surface-glass);
        -webkit-backdrop-filter: saturate(160%) blur(14px);
        backdrop-filter: saturate(160%) blur(14px);
        border-bottom: 1px solid var(--border-color);
    }
    .dashboard-header h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
    .header-logo {
        width: 28px; height: 28px;
        margin-right: 10px;
        border-radius: 8px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
    }

    /* cards */
    .card { padding: 18px 16px; border-radius: 16px; margin-bottom: 14px; }
    .card h2 { font-size: 16px; margin-bottom: 14px; }
    /* Header stacks: title on top, controls under it, all left-aligned.
       (align-items:center would centre the title in a column flexbox.) */
    .card-header {
        flex-direction: column;
        align-items: stretch;
        padding-bottom: 12px;
        margin-bottom: 14px;
    }
    .card-header h2 { text-align: left; }
    .filters { flex-direction: column; align-items: stretch; }
    .filters select,
    .filters input,
    .filters .req-search { width: 100%; min-width: 0; max-width: none; }
    /* In a column flexbox the desktop flex-basis would become a height. */
    .filters .req-search { flex: 0 0 auto; }

    /* Leaderboard summary: the id-scoped desktop grid would fall to one
       column at phone width. */
    #performance-summary.stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

    /* Buttons. The legacy rule stretched every button to full width and put
       10px under it, which broke any row of buttons. Full width is now opted
       into per container instead. */
    .btn { width: auto; margin-bottom: 0; min-height: 46px; font-size: 15px; padding: 8px 18px; }
    .btn-sm, .btn.btn-sm { min-height: 38px; font-size: 13.5px; padding: 5px 13px; }
    .form-actions .btn,
    .request-card-footer .btn,
    .reports-header .btn,
    .mobile-menu-actions .btn { width: 100%; }
    .gs-strip-actions .btn,
    .gs-toolbar .btn,
    .sheet-actions .btn,
    .user-card-actions .btn,
    .gmb-location-actions .btn { flex: 1 1 auto; }

    /* stat tiles: two per row, smaller number */
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .stat-card, #performance-summary .stat-card { padding: 14px 15px 13px; border-radius: 14px; }
    .stat-card h3, #performance-summary .stat-card h3 { font-size: 10.5px; margin-bottom: 8px; }
    .stat-value, #performance-summary .stat-value { font-size: 26px; margin-bottom: 6px; }
    .stat-subtitle { font-size: 11.5px; }
    .stat-card:hover { transform: none; box-shadow: var(--elev-1); }

    /* ---- bottom bar ---- */
    .bottom-nav {
        background: var(--surface-glass);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.06);
        padding: 4px 6px env(safe-area-inset-bottom, 0px);
    }
    body.dark-mode .bottom-nav { box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45); }

    .bnav-item {
        min-height: 54px;
        gap: 4px;
        padding: 6px 4px 5px;
        border-radius: 12px;
        font-size: 10.5px;
        font-weight: 600;
    }
    .bnav-item svg { width: 24px; height: 24px; position: relative; z-index: 1; stroke-width: 1.9; transition: transform .12s ease; }
    /* The label only: the unread badge is also a <span> and must stay
       absolutely positioned. */
    .bnav-item > span:not(.bnav-badge) { position: relative; z-index: 1; }
    .bnav-item .bnav-badge { position: absolute; }
    /* A tinted pill grows in behind the active icon. */
    .bnav-item::before {
        content: '';
        position: absolute;
        top: 4px; left: 50%;
        width: 54px; height: 30px;
        border-radius: 15px;
        background: var(--brand-tint-strong);
        transform: translateX(-50%) scaleX(.55);
        opacity: 0;
        transition: transform .22s cubic-bezier(.2, .8, .3, 1), opacity .18s ease;
    }
    .bnav-item.active { color: var(--brand); }
    .bnav-item.active::before { opacity: 1; transform: translateX(-50%) scaleX(1); }
    .bnav-item.active svg { stroke-width: 2.2; }
    .bnav-item:active { opacity: 1; }
    .bnav-item:active svg { transform: scale(.9); }
    .bnav-badge {
        top: 2px;
        left: calc(50% + 4px);
        margin-left: 0;
        z-index: 2;
        box-shadow: 0 0 0 2px var(--bg-secondary);
    }

    /* ---- More sheet ---- */
    .more-sheet {
        padding: 6px 18px calc(18px + env(safe-area-inset-bottom, 0px));
        border-radius: 22px 22px 0 0;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.22);
    }
    body.dark-mode .more-sheet {
        border-top-color: rgba(255, 255, 255, 0.08);
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.6);
    }
    .sheet-grip { width: 40px; height: 5px; border-radius: 3px; margin: 8px auto 12px; }
    .sheet-head { padding-bottom: 14px; align-items: center; }
    .sheet-name { font-size: 17px; font-weight: 700; letter-spacing: -0.015em; }
    .sheet-role { font-size: 12.5px; text-transform: capitalize; }
    .sheet-close {
        width: 34px; height: 34px;
        padding: 0;
        display: grid;
        place-items: center;
        border-radius: 10px;
        background: var(--bg-tertiary);
        color: var(--text-secondary);
        font-size: 22px;
    }
    .sheet-links { padding: 4px 0; }
    .sheet-link {
        position: relative;
        min-height: 58px;
        padding: 12px 34px 12px 6px;
        border-radius: 10px;
    }
    .sheet-link::after {
        content: '';
        position: absolute;
        right: 14px; top: 50%;
        width: 9px; height: 9px;
        border-right: 2px solid var(--text-secondary);
        border-bottom: 2px solid var(--text-secondary);
        transform: translateY(-50%) rotate(-45deg);
        opacity: .7;
    }
    .sheet-link:active { background: var(--brand-tint); }
    .sheet-link-label { font-size: 16px; font-weight: 600; }
    .sheet-link-desc { font-size: 12.5px; }
    .sheet-actions { padding-top: 14px; gap: 10px; }
    .sheet-actions .btn { min-height: 44px; font-size: 14px; }

    /* ---- modals become bottom sheets ---- */
    .modal { padding: 0; align-items: flex-end; }
    .modal-content {
        width: 100%;
        max-width: none;
        max-height: 92vh;
        max-height: 92dvh;
        margin: auto 0 0;
        border-radius: 22px 22px 0 0;
        border-bottom: none;
        animation: sheetIn .26s cubic-bezier(.32, .72, 0, 1);
    }
    .modal-content::before {
        content: '';
        display: block;
        width: 38px; height: 5px;
        margin: 8px auto 0;
        border-radius: 3px;
        background: var(--border-input);
    }
    .modal-header { padding: 12px 18px 14px; }
    .modal-body, .modal-content form { padding: 18px; }
    .modal-content > .review-preview { margin: 16px 18px 0; }
    .modal-content form .modal-actions { margin: 18px -18px -18px; }
    .modal-footer, .modal-actions {
        flex-wrap: wrap;
        padding: 14px 18px calc(14px + env(safe-area-inset-bottom, 0px));
    }
    .modal-footer .btn, .modal-actions .btn { flex: 1 1 auto; }
    .modal-footer-group { flex: 1 1 100%; }
    .modal-footer-split #delete-user-btn { flex: 1 1 100%; order: 2; }
    .checkbox-grid { grid-template-columns: 1fr; }
    .date-pair { flex-wrap: wrap; }

    /* toasts span the top */
    .toast-container { top: calc(10px + env(safe-area-inset-top, 0px)); left: 12px; right: 12px; }
    .toast { width: 100%; min-width: 0; max-width: none; }

    /* forms */
    .form-row { gap: 14px; }
    .form-group { margin-bottom: 14px; }
    .message-preview { padding: 14px; }
    .preview-content { max-width: 100%; }

    /* segmented controls scroll sideways rather than wrapping */
    .msg-sub-nav, .reports-sub-nav, .gs-subnav {
        display: flex;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .msg-sub-nav::-webkit-scrollbar,
    .reports-sub-nav::-webkit-scrollbar,
    .gs-subnav::-webkit-scrollbar { display: none; }
    .msg-sub-btn, .reports-sub-btn, .gs-subbtn { flex: 1 0 auto; }

    /* messages fill the space between header and bar */
    .msg-layout { height: calc(100vh - 210px); height: calc(100dvh - 210px); min-height: 380px; }
    .msg-composer-form .btn { width: auto; }
    .msg-bubble { max-width: 84%; }
    .msg-back-btn {
        width: 36px; height: 36px;
        display: grid;
        place-items: center;
        border-radius: 10px;
    }
    .msg-back-btn:active { background: var(--brand-tint); }

    /* reports: chooser, filters and export stack */
    .reports-header, .reports-controls { flex: 1 1 100%; }
    #reports-tab .content-container { gap: 12px; }

    /* GMB */
    /* The toolbar stacks on phones; a desktop flex-basis would become a
       height here (the search box grew to 200px tall). */
    .gs-toolbar > * { flex: 0 0 auto; }
    .gs-strip { padding: 14px; border-radius: 14px; }
    .gs-stat { min-width: 0; flex: 1 1 40%; }
    .gs-stat-value { font-size: 20px; }
    .gs-row { padding: 12px 14px; }

    /* reviews */
    .reviews-filter-bar { padding: 14px; border-radius: 14px; }
    .search-input-wrapper { max-width: none; flex-basis: 100%; }
    .filter-badge-group > * { flex: 1 1 100%; }
    /* Site and rating pair up on one row; the tech filter gets its own. */
    .filter-badge-group select { flex: 1 1 40%; width: auto; min-width: 0; }
    .filter-badge-group #review-tech-filter { flex-basis: 100%; }
    .filter-badge { justify-content: center; }
    .date-range-picker { display: flex; }
    .date-range-picker .date-input { flex: 1; min-width: 0; }
    .review-card-modern { padding: 16px; border-radius: 14px; }
    .reviews-actions { width: 100%; }
    .reviews-actions .btn-outline-secondary { flex: 1; }

    /* login */
    .app-logo { width: 80px; height: 80px; border-radius: 22px; }
    .login-header h1 { font-size: 26px; }
    .login-form { padding: 20px; }
    #login-screen::before { width: 420px; height: 420px; left: -160px; top: -180px; }
    #login-screen::after  { width: 380px; height: 380px; right: -140px; bottom: -160px; }

    /* Any table that survives on a phone scrolls inside its own box. */
    th, td { padding: 10px 12px; font-size: 13px; white-space: nowrap; }
    .report-table th, .report-table td { padding: 9px 10px; font-size: 12.5px; }
}

@keyframes sheetIn {
    from { transform: translateY(24px); opacity: .6; }
    to   { transform: none; opacity: 1; }
}

@media (max-width: 380px) {
    .stats-grid { gap: 8px; }
    .stat-value, #performance-summary .stat-value { font-size: 23px; }
    .bnav-item { font-size: 10px; }
}

/* ---- motion ------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
    .stat-card:hover { transform: none; }
}

/* ==========================================================================
   Templates

   List on the left, editor on the right, so a manager can compare wording
   against the other templates while writing. Below 1100px the editor drops
   under the list rather than squeezing both.
   ========================================================================== */

.tpl-layout {
    display: grid;
    /* One column until the editor opens, so the list is not stranded at half
       width next to empty space. */
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}
.tpl-layout.editing { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }

@media (max-width: 1100px) {
    .tpl-layout.editing { grid-template-columns: minmax(0, 1fr); }
}

.tpl-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.tpl-toolbar .gs-search { flex: 1 1 auto; min-width: 0; }

.tpl-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    cursor: pointer;
}
.tpl-toggle input { width: 16px; height: 16px; margin: 0; }

.tpl-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 300px);
    min-height: 140px;
    overflow-y: auto;
}
@media (max-width: 1100px) { .tpl-rows { max-height: 420px; } }

.tpl-row {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 100%;
    padding: 12px 14px;
    text-align: left;
    font-family: inherit;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}
.tpl-row:hover { background: var(--hover-bg); }
.tpl-row.selected {
    border-color: var(--brand);
    box-shadow: var(--ring);
}

.tpl-row-title { font-size: 14.5px; font-weight: 650; color: var(--text-primary); }
.tpl-row-msg {
    font-size: 12.5px;
    color: var(--text-secondary);
    line-height: 1.45;
    /* Two lines is enough to recognise a template without the row growing. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tpl-row-foot { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---- editor ------------------------------------------------------------- */

.tpl-meta-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}
.tpl-count { font-size: 12px; color: var(--text-secondary); }

.tpl-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.tpl-chip {
    padding: 5px 11px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 550;
    cursor: pointer;
    transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}
.tpl-chip:hover {
    background: var(--brand);
    border-color: var(--brand);
    color: var(--brand-contrast);
}

/* The preview is a message bubble because that is what it becomes. */
.tpl-preview-wrap {
    padding: 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}
.tpl-preview-bubble {
    max-width: min(460px, 100%);
    padding: 10px 14px;
    border-radius: 18px 18px 18px 5px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    box-shadow: var(--elev-1);
    font-size: 14px;
    line-height: 1.45;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.tpl-scope { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

.tpl-radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 9px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
}
.tpl-radio input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }
.tpl-radio:has(input:checked) {
    border-color: var(--brand);
    background: var(--brand-tint, var(--hover-bg));
}

.tpl-locations {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}
.tpl-locations-head {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}
.tpl-locations-head .gs-search { flex: 1 1 auto; min-width: 0; }
.tpl-locations-head .btn { flex-shrink: 0; }

.tpl-loc-list { max-height: 240px; overflow-y: auto; }

.tpl-loc {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 400;
    cursor: pointer;
}
.tpl-loc:last-child { border-bottom: none; }
.tpl-loc:hover { background: var(--hover-bg); }
.tpl-loc input { width: 16px; height: 16px; margin: 0; flex-shrink: 0; accent-color: var(--brand); }
.tpl-loc-name { flex: 1; font-size: 13.5px; color: var(--text-primary); }
.tpl-loc-code { font-size: 11px; color: var(--text-secondary); }

.tpl-loc-count {
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    font-size: 12px;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .tpl-toolbar { flex-direction: column; align-items: stretch; }
    .tpl-locations-head { flex-wrap: wrap; }
    .tpl-locations-head .btn { flex: 1; }
    .tpl-rows { max-height: none; }
}

/* ==========================================================================
   The hidden attribute wins

   [hidden] is a user-agent rule, so ANY author declaration that sets display
   defeats it - and the design layer sets display on a lot of things. A chip
   styled `display: flex` stays on screen with hidden set, which is how a
   "no review link yet" warning appeared on a template that had one, and how
   an invisible full-viewport backdrop once swallowed every click on the page.

   One global rule is stronger than remembering a guard per selector.
   Toggle visibility with el.hidden and this holds everywhere.
   ========================================================================== */
[hidden] { display: none !important; }

/* ==========================================================================
   Private feedback

   Each row is a person waiting for a call back, so the phone number is a
   tap target rather than text, and an unresolved negative carries a red edge
   that survives a quick scan down the page.
   ========================================================================== */

.fb-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.fb-stat {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 16px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-1);
}
.fb-stat-value { font-size: 28px; font-weight: 700; line-height: 1.05; color: var(--text-primary); }
.fb-stat-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.fb-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.fb-toolbar select { width: auto; min-width: 150px; }

.fb-segment {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}
.fb-seg-btn {
    padding: 7px 14px;
    border: none;
    border-radius: 6px;
    background: none;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
}
.fb-seg-btn.active {
    background: var(--bg-secondary);
    color: var(--brand);
    box-shadow: var(--elev-1);
}

.fb-rows { display: flex; flex-direction: column; gap: 12px; }

.fb-card {
    padding: 16px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--elev-1);
}
/* The ones somebody has to act on read differently at a glance. */
.fb-card.negative { border-left: 3px solid var(--accent-red); }

.fb-card-head { display: flex; align-items: flex-start; gap: 12px; }
.fb-face { font-size: 22px; line-height: 1.2; flex-shrink: 0; }
.fb-who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.fb-name { font-size: 15px; font-weight: 650; color: var(--text-primary); }
.fb-where { font-size: 12.5px; color: var(--text-secondary); }
.fb-when { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.fb-time { font-size: 11.5px; color: var(--text-secondary); }

.fb-comment {
    margin: 12px 0 0;
    padding: 12px 14px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.fb-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 12px;
}
.fb-contact { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.fb-phone {
    font-size: 14px;
    font-weight: 650;
    color: var(--brand);
    text-decoration: none;
    padding: 4px 0;
}
.fb-phone:hover { text-decoration: underline; }

.fb-actions { display: flex; gap: 8px; flex-shrink: 0; }
.fb-actions .btn { margin-bottom: 0; width: auto; }

.fb-resolution {
    margin: 12px 0 0;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .fb-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .fb-stat { padding: 13px 14px; }
    .fb-stat-value { font-size: 23px; }

    .fb-toolbar { flex-direction: column; align-items: stretch; }
    .fb-toolbar select { width: 100%; }
    .fb-segment { justify-content: space-between; }
    .fb-seg-btn { flex: 1; }

    .fb-card-foot { flex-direction: column; align-items: stretch; }
    .fb-actions { width: 100%; }
    .fb-actions .btn { flex: 1; }
}

/* ==========================================================================
   Nebula design system

   The CRM (Go-Forth-Nebula, frontend/src/app/globals.css) and this app are two
   halves of the same product, and they did not look like it. This adopts the
   CRM's tokens wholesale so a person moving between them is not crossing a
   border.

   It is deliberately a remapping of the token VALUES rather than a rewrite of
   the component CSS: every panel, badge and table in this app already draws
   from these names, so pointing them at the CRM's palette retones the whole
   interface without touching a single component rule. The CRM is Tailwind and
   stores colours as "R G B" triples for rgb(var(--x) / a); the same values are
   written here as hex because nothing in this stylesheet needs the alpha form.

   Notes carried over from the CRM, because they explain the values:
     - neutrals carry a slight blue cast; a screen built from #f2f2f2/#949494
       reads as untouched browser defaults, the same layout in tinted neutrals
       reads as chosen. The tint should be felt, not seen.
     - borders are a HAIRLINE, not a drawn line. Separation comes from
       elevation; the border only keeps the edge crisp.
     - elevation is four stacked layers, not one drop. A tight contact shadow
       anchors the element, then progressively wider, weaker ambient layers.
       Each is nearly invisible alone - the depth is the stack.
     - dark mode is not pure black. #000 forces every surface above it lighter,
       flattening the stack to two levels.
   ========================================================================== */

/* Self-hosted rather than linked from Google. The CSP here allows fonts from
   'self' only, and widening it for a typeface would be the wrong trade on an
   app technicians open in the field - this also keeps it working offline in
   the installed PWA. One variable file covers 400-700. */
@font-face {
    font-family: 'Host Grotesk';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('/fonts/host-grotesk-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                   U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                   U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Host Grotesk';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('/fonts/host-grotesk-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
                   U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
                   U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
    --font: 'Host Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    /* — Brand & semantic — */
    --brand:            #DC2626;
    --brand-dark:       #B42318;
    --brand-contrast:   #FFFFFF;
    --accent-green:     #15803D;
    --accent-orange:    #D97706;
    --accent-red:       #D92D20;

    /* --accent-blue is this app's older name for the primary action colour.
       It has never been blue in light mode; it stays an alias of the brand. */
    --accent-blue:      #DC2626;
    --accent-blue-dark: #B42318;

    /* — Surfaces & text — */
    --bg-primary:    #E8ECF3;   /* the page ground */
    --bg-secondary:  #FFFFFF;   /* a card */
    --bg-tertiary:   #F1F4F8;   /* a band inside a card */
    --hover-bg:      #EAEFF5;

    --text-primary:   #101828;
    --text-secondary: #5B6776;
    --text-tertiary:  #101828;

    --border-color:  #E2E8F0;
    --border-strong: #CBD5E1;
    --border-input:  #CBD5E1;

    --overlay-bg:    rgb(16 24 40 / 0.45);
    --surface-glass: rgb(255 255 255 / 0.82);

    /* — App chrome —
       The sidebar is not a card. Painting it --bg-secondary made the fixed
       furniture the same white as the panels floating inside it. It sits a
       step behind the content so cards visibly float on top. */
    --side-bg:    #F8FAFC;
    --side-hover: #EAEFF5;

    /* — Tints — */
    --brand-tint:        rgb(220 38 38 / 0.08);
    --brand-tint-strong: rgb(220 38 38 / 0.16);
    --brand-line:        rgb(220 38 38 / 0.28);
    --brand-grad:        linear-gradient(135deg, #DC2626 0%, #B42318 100%);
    --brand-glow:        0 1px 2px rgb(16 24 40 / 0.05), inset 0 1px 0 rgb(255 255 255 / 0.16);
    --brand-glow-lg:     0 2px 4px rgb(16 24 40 / 0.06), 0 12px 24px -6px rgb(220 38 38 / 0.28);

    /* — Status ramp — */
    --ok:      #15803D;  --ok-tint:      rgb(21 128 61 / 0.10);
    --warn:    #D97706;  --warn-tint:    rgb(217 119 6 / 0.12);
    --bad:     #D92D20;  --bad-tint:     rgb(217 45 32 / 0.10);
    --info:    #175CD3;  --info-tint:    rgb(23 92 211 / 0.10);
    --done:    #15803D;  --done-tint:    rgb(21 128 61 / 0.10);
    --neutral: #5B6776;  --neutral-tint: rgb(91 103 118 / 0.10);

    --notice-ok-bg:      rgb(21 128 61 / 0.10);
    --notice-ok-border:  #15803D;
    --notice-ok-text:    #15803D;
    --notice-warn-bg:    rgb(217 119 6 / 0.12);
    --notice-warn-border:#D97706;
    --notice-info-bg:    rgb(23 92 211 / 0.10);
    --notice-info-border:#175CD3;

    /* Report rating bands. Not in the CRM's palette; pulled onto the same
       tinted ramp so they do not read as imports from another app. */
    --star-gold:   #D97706;
    --accent-lime: #669F2A;

    /* — Elevation — */
    --elev-1: 0 1px 2px rgb(16 24 40 / 0.05);
    --elev-2:
        0 1px 1px rgb(16 24 40 / 0.06),
        0 2px 5px -1px rgb(16 24 40 / 0.08),
        0 10px 18px -4px rgb(16 24 40 / 0.11),
        0 24px 40px -12px rgb(16 24 40 / 0.15);
    --elev-3:
        0 2px 4px rgb(16 24 40 / 0.06),
        0 12px 24px -6px rgb(16 24 40 / 0.12),
        0 32px 56px -16px rgb(16 24 40 / 0.18);

    /* Legacy names, still referenced by older rules in this file. */
    --shadow-sm: var(--elev-1);
    --shadow-md: var(--elev-2);
    --shadow-lg: var(--elev-3);

    /* Focus is a soft 3px halo rather than a hard ring - the field lights up
       instead of being outlined. */
    --ring: 0 0 0 3px rgb(220 38 38 / 0.28);

    /* — Radius scale —
       One radius for everything reads mechanical. Three steps, each with a
       job: controls, cards, and the overlay layer. */
    --radius-sm: 0.375rem;   /* 6px  - controls */
    --radius-md: 0.75rem;    /* 12px - cards */
    --radius-lg: 0.875rem;   /* 14px - overlays */
    --radius-xl: 1rem;
}

body.dark-mode {
    --brand:            #EF4444;
    --brand-dark:       #B91C1C;
    --brand-contrast:   #FFFFFF;
    --accent-green:     #34C77B;
    --accent-orange:    #F59E0B;
    --accent-red:       #F85C5C;
    --accent-blue:      #EF4444;
    --accent-blue-dark: #B91C1C;

    --bg-primary:    #0A0B0D;
    --bg-secondary:  #15171B;
    --bg-tertiary:   #1C1F24;
    --hover-bg:      #24282F;

    --text-primary:   #F2F4F7;
    --text-secondary: #98A2B3;
    --text-tertiary:  #F2F4F7;

    --border-color:  #272B33;
    --border-strong: #383D47;
    --border-input:  #383D47;

    --overlay-bg:    rgb(0 0 0 / 0.66);
    --surface-glass: rgb(21 23 27 / 0.84);

    /* Dark mode inverts the relationship: chrome sits BELOW the page. */
    --side-bg:    #0F1114;
    --side-hover: #24282F;

    --brand-tint:        rgb(239 68 68 / 0.12);
    --brand-tint-strong: rgb(239 68 68 / 0.22);
    --brand-line:        rgb(239 68 68 / 0.34);
    --brand-grad:        linear-gradient(135deg, #EF4444 0%, #B91C1C 100%);
    --brand-glow:        0 1px 2px rgb(0 0 0 / 0.5), inset 0 1px 0 rgb(255 255 255 / 0.10);
    --brand-glow-lg:     0 2px 6px rgb(0 0 0 / 0.5), 0 14px 28px -8px rgb(239 68 68 / 0.34);

    --ok:      #34C77B;  --ok-tint:      rgb(52 199 123 / 0.14);
    --warn:    #F59E0B;  --warn-tint:    rgb(245 158 11 / 0.16);
    --bad:     #F85C5C;  --bad-tint:     rgb(248 92 92 / 0.14);
    --info:    #6BA5FF;  --info-tint:    rgb(107 165 255 / 0.14);
    --done:    #34C77B;  --done-tint:    rgb(52 199 123 / 0.14);
    --neutral: #98A2B3;  --neutral-tint: rgb(152 162 179 / 0.14);

    --notice-ok-bg:      rgb(52 199 123 / 0.14);
    --notice-ok-border:  #34C77B;
    --notice-ok-text:    #7FE0A0;
    --notice-warn-bg:    rgb(245 158 11 / 0.16);
    --notice-warn-border:#F59E0B;
    --notice-info-bg:    rgb(107 165 255 / 0.14);
    --notice-info-border:#6BA5FF;

    --star-gold:   #F59E0B;
    --accent-lime: #A8D65C;

    /* Deeper and wider than light mode: on a dark page a shadow has to travel
       further before it is perceptible at all. */
    --elev-1: 0 1px 2px rgb(0 0 0 / 0.5);
    --elev-2:
        0 1px 1px rgb(0 0 0 / 0.4),
        0 2px 6px -1px rgb(0 0 0 / 0.45),
        0 10px 20px -6px rgb(0 0 0 / 0.5),
        0 24px 40px -16px rgb(0 0 0 / 0.55);
    --elev-3:
        0 2px 6px rgb(0 0 0 / 0.5),
        0 14px 28px -8px rgb(0 0 0 / 0.6),
        0 36px 60px -20px rgb(0 0 0 / 0.7);

    --ring: 0 0 0 3px rgb(239 68 68 / 0.34);
}

/* --------------------------------------------------------------------------
   Base, matched to the CRM
   -------------------------------------------------------------------------- */

body {
    font-family: var(--font);
    /* Host Grotesk's alternates: a '1' with a foot and an unambiguous 'l',
       worth having in an app full of phone numbers and office codes. tnum
       keeps figures the same width so numeric columns stack. */
    font-feature-settings: 'cv05' 1, 'cv09' 1, 'cv11' 1, 'ss01' 1;
    letter-spacing: -0.01em;
    /* Tints native checkbox / radio / range with the brand colour, so every
       control picks it up without a per-component rule. */
    accent-color: var(--brand);
}

/* Figures line up in tables and stat tiles. */
.fb-stat-value, .gs-stat-value, .stat-value, .tpl-count,
table td, table th, .req-table, .report-table {
    font-variant-numeric: tabular-nums;
}

/* A default blue highlight in a red-branded app reads as nobody having
   looked. */
::selection {
    background-color: var(--brand-tint-strong);
    color: var(--text-primary);
}

/* Cards get the CRM's top-edge highlight. In light mode it is nearly
   nothing; in dark mode it is what actually separates a raised surface from
   the one behind it, because shadows do not read on black. */
.card, .fb-card, .modal-content, .gs-rows, .tpl-rows {
    box-shadow: var(--elev-2), inset 0 1px 0 rgb(255 255 255 / 0.9);
}
body.dark-mode .card,
body.dark-mode .fb-card,
body.dark-mode .modal-content,
body.dark-mode .gs-rows,
body.dark-mode .tpl-rows {
    box-shadow: var(--elev-2), inset 0 1px 0 rgb(255 255 255 / 0.06);
}

/* Controls are 40px in the CRM; matching the height is most of what makes
   two apps feel like one. */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
select,
textarea,
.btn {
    min-height: 2.5rem;
}
.btn-sm { min-height: 2rem; }

/* A field should read as a well cut into the card, not a grey rectangle
   sitting on top of it. */
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
select,
textarea {
    box-shadow: inset 0 1px 2px rgb(16 24 40 / 0.05);
}
body.dark-mode input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]),
body.dark-mode select,
body.dark-mode textarea {
    box-shadow: none;
}

/* Primary buttons carry the CRM's inner top light. */
.btn-primary {
    box-shadow: var(--elev-1), inset 0 1px 0 rgb(255 255 255 / 0.16);
}
.btn-secondary {
    box-shadow: var(--elev-1), inset 0 1px 0 rgb(255 255 255 / 0.9);
}
body.dark-mode .btn-secondary {
    box-shadow: var(--elev-1), inset 0 1px 0 rgb(255 255 255 / 0.06);
}

/* ---- template picker in the chat composer ------------------------------- */
.msg-template-bar {
    position: relative;
    padding: 0 14px 8px;
}

.msg-template-menu {
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: calc(100% - 2px);
    z-index: 40;
    max-height: min(52vh, 420px);
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--elev-3);
}

.msg-template-item {
    display: block;
    width: 100%;
    padding: 11px 14px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: none;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color .12s ease;
}
.msg-template-item:last-child { border-bottom: none; }
.msg-template-item:hover:not([disabled]) { background: var(--hover-bg); }

/* Shown rather than hidden: a template that cannot be used right now is
   usually the one someone is looking for, and silently dropping it reads as
   the template having gone missing. */
.msg-template-item.blocked { cursor: not-allowed; opacity: .6; }

.msg-template-name {
    display: block;
    font-size: 13.5px;
    font-weight: 650;
    color: var(--text-primary);
    margin-bottom: 3px;
}
.msg-template-body {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--text-secondary);
}
.msg-template-blocked {
    display: block;
    margin-top: 5px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--accent-red);
}

@media (max-width: 768px) {
    .msg-template-menu { max-height: 46vh; }
}

/* ---------------------------------------------------------------------------
   My Requests: the reminder button
   --------------------------------------------------------------------------- */

/* Desktop table. Two short buttons on one line, wrapping rather than
   stretching the column when the labels grow ("Send reminder (2 sent)"). */
.req-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.req-row-actions .btn {
    white-space: nowrap;
}

/* Cards. The existing rule makes every footer button full width, which is
   right on a phone - they just need room between them when there are two. */
.request-card-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* A blocked reminder still says why in its tooltip, so it reads as
   "not yet" rather than broken. */
.remind-btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

/* The reason a reminder is not available, on a phone card. A tooltip would
   never be read there, so it is said out loud instead. */
.req-remind-note {
    margin: 0;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--text-secondary);
}

/* ==========================================================================
   Reports: the controls hold still, the report scrolls
   ==========================================================================

   The tech performance report is one row per technician, and there are 174
   of them. Scrolling to the bottom used to carry the sub-report buttons,
   the office and timeframe pickers and the column headings off the top of
   the screen, so reading a number meant scrolling back up to remember which
   column it was in and what timeframe it covered.

   So the tab becomes a column the height of the viewport: the controls stay
   where they are, #reports-content does the scrolling, and each table's
   heading row sticks to the top of it.

   The container above keeps the arrangement it already had - chooser and
   filters on the left, Export CSV at the far end, the report across the
   full width below - but as an explicit two-row grid rather than a wrapping
   flex row. Wrapped flex lines share the container's height between them,
   so a tall container stretched the controls row to half the screen; grid
   lets the second row take the space that is left and nothing else.

   Below 769px this is all off. A scrolling panel inside a scrolling page is
   worse on a phone than a long page is - the inner region swallows the
   flick that was meant for the page, and the viewport is too short to spare
   the room. */

@media (min-width: 769px) {

    #reports-tab.active {
        display: flex;
        flex-direction: column;
        height: calc(100vh - var(--topbar-h));
        overflow: hidden;
    }

    #reports-tab .content-container {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        /* The report takes whatever the controls leave. minmax(0, 1fr)
           rather than 1fr so the row may be shorter than its contents -
           which is the whole point, since its contents are 174 rows. */
        grid-template-rows: auto minmax(0, 1fr);
        align-items: center;
        gap: 20px 12px;
        flex: 1;
        min-height: 0;
    }

    .reports-controls { grid-column: 1; grid-row: 1; }
    .reports-header   { grid-column: 2; grid-row: 1; }

    #reports-content {
        grid-column: 1 / -1;
        grid-row: 2;
        align-self: stretch;
        min-height: 0;
        overflow-y: auto;
        /* Keeps the scrollbar off the table's right edge. */
        padding-right: 6px;
    }

    /* A card clips its own overflow, which makes it the nearest scrolling
       box and quietly steals the heading row below: a sticky cell sticks
       to the card, the card does not scroll, and the heading scrolls away
       with everything else. Cards in here hand that job up to the panel.
       Nothing is clipped as a result - a table too wide for the column
       scrolls the panel sideways instead, because an element with one axis
       scrollable gets the other automatically. Phones keep the card's own
       overflow, since none of this block applies to them. */
    #reports-content .card {
        overflow: visible;
    }

    /* The column headings belong to the rows under them, so they travel
       with the scroll container.

       Sticky goes on the cells rather than the thead: with border-collapse
       the thead's own box is not painted, so a sticky thead slides over the
       rows transparently. For the same reason the underline is a shadow - a
       collapsed border is not drawn by the cell that declares it. */
    #reports-content .report-table th {
        position: sticky;
        top: 0;
        z-index: 2;
        background: var(--bg-tertiary);
        box-shadow: inset 0 -2px 0 var(--border-color);
    }
}

/* ==========================================================================
   The leaderboard scrolls the same way
   ==========================================================================

   Same 174 technicians, same problem: the ranking is the point of the tab,
   and reading row 120 used to mean losing the office and timeframe pickers,
   the summary figures and the column headings off the top of the screen.

   The shape is different from Reports, though. Everything here lives in one
   card, and the table already sits in .lb-table-wrap - a wrapper that
   scrolls sideways for its seven columns. So the card becomes the column
   that stops growing, the heading, filters and summary figures keep their
   height at the top of it, and that existing wrapper takes the rest and
   scrolls down as well as across. Being the element directly around the
   table, it is also the right thing for the headings to stick to.

   Below 769px none of it applies: the table is hidden there and the same
   standings render as ranked cards, which belong on a page that scrolls. */

@media (min-width: 769px) {

    #leaderboard-tab.active {
        display: flex;
        flex-direction: column;
        height: calc(100vh - var(--topbar-h));
        overflow: hidden;
    }

    #leaderboard-tab .content-container {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    /* The card is the whole tab here, so it is the thing that has to stop
       growing. Its bottom margin would otherwise push its own last row
       past the edge of a window it is not allowed to overflow. */
    #leaderboard-tab .card {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        margin-bottom: 0;
    }

    /* The top section: heading, the two pickers, and the summary figures.
       They keep their own height and hold still. */
    #leaderboard-tab .card-header,
    #leaderboard-tab #performance-summary {
        flex: 0 0 auto;
    }

    #leaderboard-tab .leaderboard-table {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    /* The one thing on the tab that scrolls. */
    #leaderboard-tab .lb-table-wrap {
        flex: 1;
        min-height: 0;
        overflow: auto;
    }

    /* Sticky on the cells rather than the thead: with border-collapse the
       thead's own box is not painted, so a sticky thead slides over the
       rows transparently, and a collapsed border is not drawn by the cell
       that declares it - hence the shadow for the underline. */
    #leaderboard-tab .leaderboard-table th {
        position: sticky;
        top: 0;
        z-index: 2;
        background: var(--bg-tertiary);
        box-shadow: inset 0 -2px 0 var(--border-color);
    }
}

/* ==========================================================================
   Custom date range

   A pair of date inputs that sits beside a timeframe picker and stays out
   of the way until "Custom Range" is chosen.

   Layout only, deliberately. The inputs are painted by the shared input
   rule further up - the same one the picker beside them answers to, which
   outranks anything scoped like this - and that rule's neighbours already
   invert the calendar icon for dark mode. Repeating any of it here would
   only be a second opinion for the cascade to settle.

   The hiding is the `hidden` attribute, through the global [hidden] rule,
   which is why there is no display:none here for the flex to fight with.
   ========================================================================== */
.date-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

@media (max-width: 768px) {
    /* The filters stack on a phone, so the pair takes the width it is given
       and shares it, rather than pushing the card sideways. */
    .date-range {
        width: 100%;
    }

    .date-range input[type="date"] {
        flex: 1;
        min-width: 0;
    }
}

/* ==========================================================================
   Send-by channel chooser

   Three radios on the Send Review Request form, deciding whether the link
   goes out as a text, an email, or both.

   Radios rather than a dropdown because this is the one control on the form
   that changes what the customer receives, and it should be readable without
   a tap. The radio dots are left visible on purpose: :has() paints the
   selected box, but a browser without it still shows the state, and a
   segmented control whose selection is invisible is worse than a plain group.

   Specificity note: `.form-group label` upstream is (0,2,0) and sets
   display:block plus a bottom margin, which would stack these vertically and
   space them oddly. `label.channel-option` is (0,2,1), so it wins outright
   rather than relying on which rule comes last in the file.
   ========================================================================== */
.channel-choice {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.channel-choice label.channel-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    /* Measured off a rendered input rather than copied from the shared input
       rule, which declares 42px and is overridden to 40px further down the
       file. Two pixels is visible when these sit directly under the fields. */
    min-height: 40px;
    margin-bottom: 0;
    padding: 0 16px;
    border: 1px solid var(--border-input);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.channel-choice label.channel-option:hover {
    border-color: var(--text-secondary);
}

.channel-choice .channel-option input {
    margin: 0;
    cursor: pointer;
}

/* The chosen one. Scoped to :has() so nothing here depends on it: without
   support the box simply stays plain and the radio dot carries the state. */
.channel-choice label.channel-option:has(input:checked) {
    border-color: var(--accent-blue);
    box-shadow: inset 0 0 0 1px var(--accent-blue);
}

.channel-choice .channel-option input:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.channel-hint {
    margin: 8px 0 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-secondary);
}

@media (max-width: 480px) {
    /* Three across is tight on a small phone, so they share the row evenly
       instead of the third wrapping on its own. */
    .channel-choice label.channel-option {
        flex: 1;
        justify-content: center;
        padding: 0 10px;
    }
}

/* Half of a two-channel send worked.
   Neither green nor red is honest about that, and the stylesheet already
   carries a warn pair for exactly this kind of answer. */
.result-message.warn {
    background: var(--warn-tint);
    color: var(--warn);
    border-color: rgba(255, 149, 0, 0.3);
}
