:root {
    --primary: #D50000;
    --primary-dark: #9B0000;
    --bg-page: #F5F4F2;
    --bg-card: #FFFFFF;
    --sidebar-bg: #000000;
    --sidebar-text: #E0DED9;
    --sidebar-active: #D50000;
    --text-primary: #1C1B19;
    --text-secondary: #6B6860;
    --border: #E2E0DC;
    --success: #2D7A4F;
    --danger: #D50000;
    --table-header: #F0EEE9;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 10px;
    --sidebar-width: 240px;
    --topnav-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-page);
    color: var(--text-primary);
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    z-index: 1000;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    height: var(--topnav-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header .logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background-color: rgba(255,255,255,0.05);
}

.nav-item.active {
    background-color: rgba(213, 0, 0, 0.1);
    color: white;
    border-left-color: var(--sidebar-active);
}

.nav-item i {
    width: 20px;
    margin-right: 12px;
    display: flex;
    justify-content: center;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Topnav */
.topnav {
    position: fixed;
    top: 0;
    right: 0;
    left: var(--sidebar-width);
    height: var(--topnav-height);
    background-color: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 900;
}

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

.page-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.topnav-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.admin-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.logout-btn {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: #f8f8f8;
    color: var(--danger);
    border-color: var(--danger);
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    padding: calc(var(--topnav-height) + 24px) 24px 24px;
    min-height: 100vh;
}

/* Grid System */
.grid-5 {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.kpi-card {
    position: relative;
    border-bottom: 3px solid var(--primary);
}

.kpi-icon {
    position: absolute;
    top: 20px;
    right: 20px;
    color: var(--text-secondary);
    opacity: 0.5;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.kpi-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Customer card hover state (clickable) */
.customer-card {
    transition: box-shadow 0.18s, transform 0.18s;
}
.customer-card:hover {
    box-shadow: 0 4px 20px rgba(213,0,0,0.13);
    transform: translateY(-2px);
}

/* Report preview styles (shared) */
.report-preview {
    font-family: 'Outfit', sans-serif;
    font-size: 0.88rem;
    color: #1C1B19;
    padding: 10px 0;
}
.report-preview h2 {
    font-size: 1.1rem;
    border-bottom: 2px solid #D50000;
    padding-bottom: 6px;
    margin-bottom: 10px;
}
.report-preview h3 {
    font-size: 0.95rem;
    margin-top: 16px;
    margin-bottom: 6px;
}
.report-preview table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.report-preview th {
    background: #D50000;
    color: #fff;
    padding: 6px 10px;
    text-align: left;
}
.report-preview td {
    padding: 5px 10px;
    border-bottom: 1px solid #f0ede8;
}
.report-preview tr:nth-child(even) td {
    background: #faf9f7;
}

/* Analytics toolbar responsive */
@media (max-width: 600px) {
    .preset-group {
        flex-wrap: wrap;
        gap: 6px;
    }
    #analyticsFromDate, #analyticsToDate {
        max-width: 130px !important;
        font-size: 0.78rem !important;
    }
}

/* Tables */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    margin-top: 32px;
}

.table-container {
    overflow-x: auto;
}

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

th {
    background: var(--table-header);
    text-align: left;
    padding: 12px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

tr:last-child td {
    border-bottom: none;
}

/* Form Elements */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 600;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-control:focus {
    border-color: var(--primary);
}

.form-control[readonly] {
    background: #f8f8f8;
    cursor: not-allowed;
}

.btn {
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    white-space: nowrap;
}

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

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: #f8f8f8;
}

/* Modal */
.modal-overlay {
    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: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-container {
    background: white;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: all 0.3s;
}

.modal-overlay.active .modal-container {
    transform: translateY(0);
}

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

.modal-tabs {
    display: flex;
    gap: 10px;
}

.modal-tab {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    background: #f0f0f0;
}

.modal-tab.active {
    background: var(--primary);
    color: white;
}

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

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

/* Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: white;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-left: 4px solid var(--success);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 280px;
    animation: slideIn 0.3s forwards;
}

.toast.danger {
    border-left-color: var(--danger);
}

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

/* Responsive */
@media (max-width: 1024px) {
    .grid-5 {
        grid-template-columns: repeat(3, 1fr);
    }
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    /* sidebar opened via JS (body.sidebar-open) */
    body.sidebar-open .sidebar {
        transform: translateX(0) !important;
    }

    .topnav {
        left: 0;
        padding: 0 12px;
    }

    .admin-name {
        display: none;
    }

    .main-content {
        margin-left: 0;
    }

    .grid-4, .grid-2, .grid-3 {
        grid-template-columns: 1fr;
    }
    
    .grid-5 {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .kpi-value {
        font-size: 1.35rem;
    }
    
    .kpi-label {
        font-size: 0.75rem;
    }

    .hamburger-btn {
        display: inline-flex;
    }

    .tab-switcher {
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        flex-wrap: nowrap;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
    }

    .tab-switcher::-webkit-scrollbar {
        display: none;
    }

    .tab-switcher .tab-btn {
        flex-shrink: 0;
        width: auto;
    }

    .sub-tab-switcher {
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .sub-tab-switcher::-webkit-scrollbar {
        display: none;
    }

    .sub-tab-switcher .sub-tab-btn {
        flex-shrink: 0;
    }

    .toolbar-left, .toolbar-right {
        width: 100%;
        flex-wrap: wrap;
        gap: 10px;
    }

    .toolbar-left .form-control, .search-input, .filter-select {
        flex: 1 1 100%;
        max-width: none !important;
        min-width: 0 !important;
        margin: 0;
    }

    .toolbar-left .btn, .toolbar-right .btn {
        flex: 1 1 calc(50% - 10px);
        min-width: 120px;
        margin: 0;
        text-align: center;
        justify-content: center;
    }
}

/* Search & Filter Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 200px;
    flex-wrap: wrap;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.search-input {
    padding: 10px 14px 10px 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    background: white url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236B6860' viewBox='0 0 24 24'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E") 10px center no-repeat;
    min-width: 240px;
}

.search-input:focus {
    border-color: var(--primary);
}

.filter-select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    background: white;
    cursor: pointer;
}

/* Agent Card Grid */
.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.agent-card {
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
}

.agent-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

.agent-card .agent-name {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.agent-card .agent-contact {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.agent-card .agent-badges {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.agent-card .agent-balance {
    font-size: 1.4rem;
    font-weight: 700;
}

.balance-positive { color: var(--success); }
.balance-negative { color: var(--danger); }

/* Credentials Toggle */
.cred-cell {
    font-family: monospace;
    font-size: 0.82rem;
}

.cred-hidden {
    letter-spacing: 2px;
    color: var(--text-secondary);
}

.eye-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
}

.eye-btn:hover {
    background: #f0f0f0;
}

.copy-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
}

.copy-btn:hover {
    background: #f0f0f0;
}

/* Tab Switcher */
.tab-switcher {
    display: flex;
    gap: 0;
    background: var(--table-header);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 20px;
    width: fit-content;
    max-width: 100%;
    flex-wrap: wrap;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.tab-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

.sub-tab-switcher {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    max-width: 100%;
    flex-wrap: wrap;
}

.sub-tab-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    background: transparent;
    font-weight: 500;
    font-size: 0.82rem;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.sub-tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Agent Profile Header */
.profile-header {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.profile-info h2 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.profile-info .profile-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.profile-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.balance-badge {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 700;
}

.balance-badge.positive {
    background: rgba(45, 122, 79, 0.1);
    color: var(--success);
}

.balance-badge.negative {
    background: rgba(213, 0, 0, 0.1);
    color: var(--danger);
}

/* Chart Containers */
.chart-wrap {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.chart-wrap canvas {
    width: 100% !important;
    max-height: 300px;
}

/* Report Preview */
.report-preview {
    background: white;
    padding: 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    max-height: 60vh;
    overflow-y: auto;
}

.report-preview h2 {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    padding-bottom: 8px;
    margin-bottom: 16px;
}

.report-preview table {
    font-size: 0.8rem;
}

.report-preview table th {
    background: var(--primary);
    color: white;
    padding: 8px 10px;
}

.report-preview table td {
    padding: 6px 10px;
}

/* Badge colors */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-success { background: rgba(45, 122, 79, 0.1); color: var(--success); }
.badge-danger { background: rgba(213, 0, 0, 0.1); color: var(--danger); }
.badge-primary { background: rgba(213, 0, 0, 0.1); color: var(--primary); }
.badge-info { background: rgba(1, 87, 155, 0.1); color: #01579B; }
.badge-muted { background: var(--table-header); color: var(--text-secondary); }

code {
    background: var(--table-header);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-muted { color: var(--text-secondary); }

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.85rem;
    line-height: 1.4;
    border: 1px solid transparent;
}
.alert-info { background: #E1F5FE; color: #01579B; border-color: #B3E5FC; }
.alert-success { background: #E8F5E9; color: #2E7D32; border-color: #C8E6C9; }
.alert-warning { background: #FFFDE7; color: #F57F17; border-color: #FFF9C4; }
.alert-danger { background: #FFEBEE; color: #C62828; border-color: #FFCDD2; }

/* Spinners */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(0,0,0,0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner-sm {
    width: 14px;
    height: 14px;
    border-width: 1.5px;
}

/* Validation */
.border-success { border-color: var(--success) !important; }
.border-warning { border-color: #FBC02D !important; }

/* Utility */
.hidden { display: none !important; }
.d-flex { display: flex; }
.align-items-center { display: flex; align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.flex-shrink-0 { flex-shrink: 0; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.gap-4 { gap: 24px; }
.w-100 { width: 100%; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.text-center { text-align: center; }

/* Preset Filter Buttons */
.preset-group {
    display: flex;
    gap: 0;
    background: var(--table-header);
    border-radius: 8px;
    padding: 3px;
}

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

.preset-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow);
}

.preset-btn:hover:not(.active) {
    background: rgba(0,0,0,0.04);
}

/* Heatmap */
.heatmap-tooltip {
    position: absolute;
    background: var(--sidebar-bg);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Renewal Rows */
.renewal-urgent { background: rgba(193, 51, 21, 0.06); }
.renewal-warn { background: rgba(184, 115, 51, 0.06); }

.days-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-block;
}

.days-badge.urgent {
    background: rgba(193, 51, 21, 0.12);
    color: var(--danger);
}

.days-badge.warn {
    background: rgba(184, 115, 51, 0.12);
    color: #B87333;
}

.days-badge.normal {
    background: var(--table-header);
    color: var(--text-secondary);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
}

/* Responsive - Agent cards & toolbar */
@media (max-width: 1024px) {
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .grid-3 { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; gap: 12px; }
    .toolbar-left, .toolbar-right { width: 100%; flex-wrap: wrap; gap: 10px; }
    .search-input { min-width: unset; width: 100%; }
    .profile-header { flex-direction: column; align-items: stretch; gap: 20px; }
    .profile-actions { width: 100%; flex-direction: column; align-items: stretch; gap: 10px; }
    .profile-actions .balance-badge { text-align: center; margin-bottom: 4px; }
    .profile-actions .btn { width: 100%; justify-content: center; }
    
    .preset-group {
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        display: flex;
    }
    .preset-group::-webkit-scrollbar { display: none; }
    .preset-btn {
        flex: 0 0 auto;
        padding: 8px 12px;
        font-size: 0.8rem;
    }
}

/* ============================================
   PART 4 — FINAL POLISH
   ============================================ */

/* Hamburger Button */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    margin-right: 8px;
}

.hamburger-btn svg { width: 22px; height: 22px; fill: var(--text-primary); }

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

body.sidebar-open .sidebar-overlay { display: block; }
body.sidebar-open .sidebar { transform: translateX(0) !important; }

@media (max-width: 768px) {
    .hamburger-btn { display: inline-flex; }
}

/* Back Button */
.back-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    margin-right: 10px;
    transition: all 0.2s;
}

.back-btn:hover { background: #f0f0f0; }
.back-btn svg { width: 18px; height: 18px; fill: var(--text-primary); }


.section-loader {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 60px 20px;
    flex-direction: column;
    gap: 12px;
}

.section-loader .spinner { width: 28px; height: 28px; }

/* Form Validation */
.form-control.error {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 2px rgba(193, 51, 21, 0.1);
}

.field-error {
    color: var(--danger);
    font-size: 0.75rem;
    margin-top: 4px;
    display: block;
}

/* Table Row Hover */
tr:hover td { background: rgba(0,0,0,0.015); }

/* Card Hover (generic) */
.card { transition: box-shadow 0.2s, transform 0.2s; }

/* Button States */
.btn:active { transform: scale(0.97); }
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary:active { background: var(--primary-dark); }
.btn-outline:active { background: #eee; }

/* Focus States (accessibility) */
.btn:focus-visible,
.form-control:focus-visible,
.search-input:focus-visible,
.filter-select:focus-visible,
.nav-item:focus-visible,
.tab-btn:focus-visible,
.preset-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Empty States */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    color: var(--text-secondary);
    text-align: center;
}

.empty-state svg {
    width: 48px;
    height: 48px;
    fill: none;
    stroke: var(--border);
    stroke-width: 1.5;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 0.9rem;
    margin: 0;
}

/* Nav item spacing for SVGs */
.nav-item span { margin-left: 12px; }

/* Print Styles */
@media print {
    .sidebar, .topnav, .toast-container, .modal-overlay,
    .hamburger-btn, .sidebar-overlay, .toolbar, .btn { display: none !important; }
    .main-content { margin-left: 0 !important; padding-top: 0 !important; }
    .report-preview { max-height: none; overflow: visible; border: none; padding: 0; }
    body { background: white; }
}

/* ========== SITE TOPBAR (public pages + customer) ========== */
.site-topbar {
    position: sticky;
    top: 0;
    z-index: 900;
    background: #ffffff;
    padding: 10px 28px 0;
    height: 70px;
}
.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 100%;
    gap: 28px;
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--primary, #D50000);
    flex-shrink: 0;
}
.topbar-brand svg { stroke: var(--primary, #D50000); }
.topbar-logo-img {
    height: 50px;
    width: auto;
    object-fit: contain;
}
.topbar-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
}
.topbar-link {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: .88rem;
    font-weight: 500;
    color: #555;
    text-decoration: none;
    transition: background .2s, color .2s;
}
.topbar-link:hover { background: rgba(0,0,0,.04); color: #111; }
.topbar-link.active { background: var(--primary, #D50000); color: #fff; }
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}
.topbar-login-btn {
    padding: 7px 18px;
    border-radius: 8px;
    background: var(--primary, #D50000);
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: .85rem;
    transition: opacity .2s;
}
.topbar-login-btn:hover { opacity: .9; color: #fff; }
.topbar-hamburger {
    display: none;
    background: none;
    border: none;
    color: #333;
    cursor: pointer;
    padding: 4px;
}

/* Profile Pill (shared between topbar and admin) */
.profile-dropdown-wrap { position: relative; }
.profile-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    padding: 4px 12px 4px 4px;
    border-radius: 24px;
    box-shadow: 0 1px 6px rgba(0,0,0,.05);
    cursor: pointer;
    transition: box-shadow .2s;
}
.profile-pill:hover { box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.profile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(213,0,0,.08);
    color: var(--primary, #D50000);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.profile-name {
    font-weight: 600;
    font-size: .85rem;
    color: #111;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.profile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0,0,0,.1);
    min-width: 200px;
    z-index: 999;
    overflow: hidden;
    border: 1px solid #f0f0f0;
}
.profile-dropdown.open { display: block; }
.profile-dropdown-header {
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.profile-dropdown-name {
    font-weight: 700;
    font-size: .9rem;
    color: #111;
}
.profile-dropdown-role {
    font-size: .72rem;
    color: #999;
    text-transform: capitalize;
}
.profile-dropdown-divider {
    height: 1px;
    background: #f0f0f0;
}
.profile-dropdown button {
    width: 100%;
    padding: 11px 18px;
    border: none;
    background: none;
    text-align: left;
    font-size: .85rem;
    font-weight: 500;
    color: #444;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Outfit', sans-serif;
    transition: background .15s;
}
.profile-dropdown button:hover { background: #f8f8f8; color: var(--primary, #D50000); }
.profile-dropdown button svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Topbar responsive */
@media (max-width: 768px) {
    .site-topbar { padding: 0 16px; }
    .topbar-nav {
        display: none;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: #fff;
        flex-direction: column;
        padding: 12px 16px;
        box-shadow: 0 4px 16px rgba(0,0,0,.08);
        gap: 4px;
    }
    .topbar-nav.mobile-open { display: flex; }
    .topbar-link { padding: 10px 14px; width: 100%; }
    .topbar-hamburger { display: block; }
    .profile-name { display: none; }
    .profile-pill { padding: 3px; border-radius: 50%; }
}

/* Public and Customer pages background */
body.bg-public {
    background: url('images/website-bg.png') center/cover no-repeat fixed !important;
}
