body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background-color: #1a1a1a;
    color: white;
}

header {
    padding: 15px 40px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header > div:first-child {
    display: flex;
    align-items: center;
    gap: 30px;
}

#main-nav {
    margin-top: 0;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

#main-layout {
    display: grid;
    grid-template-columns: 350px 1fr; /* Matches your previous inline width */
    height: 100vh;
}

#sidebar {
    background: #242424;
    padding: 15px 25px 25px;
    border-right: 1px solid #333;
    overflow-y: auto;
    display: flex;
    vertical-align: top;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    background: #2e2e2e;
    padding: 15px;
    border-radius: 8px;
}

.form-group label {
    display: block;
    font-size: 0.8em;
    color: #888;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

input, select {
    width: 100%;
    padding: 10px;
    margin-bottom: 8px;
    background: #1a1a1a;
    border: 1px solid #444;
    color: white;
    border-radius: 4px;
    box-sizing: border-box;
    min-width: 0; /* Prevents inputs from overflowing grid cells */
}

.datetime-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
}

#content-area {
    padding: 15px 25px 25px;
    overflow-y: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

th {
    text-align: left;
    color: #888;
    padding: 12px;
    border-bottom: 2px solid #333;
}

td {
    padding: 12px;
    border-bottom: 1px solid #333;
}

/* Zebra Striping for Tables */
tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.03);
}

/* Row Hover Effect for all tables */
tbody tr {
    transition: background-color 0.2s;
}

tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.secondary-btn {
    background: #333;
    color: #ccc;
    font-size: 0.8em;
    border: 1px dashed #555;
    padding: 8px;
    cursor: pointer;
    width: 100%;
}

.toggle-row {
    display: flex;
    align-items: center; /* Vertical alignment */
    gap: 10px;           /* Space between box and text */
    margin: 10px 0;
    cursor: pointer;
}

.toggle-row input[type="checkbox"] {
    width: auto;         /* Prevents the checkbox from stretching */
    margin: 0;           /* Removes default margins */
}

#filter-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    background: #2e2e2e;
    padding: 15px;
    border-radius: 8px;
}

#filter-bar input {
    margin-bottom: 0; /* Override default margin */
    flex: 1;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

th.sortable:hover {
    background: #333;
}

.sort-icon {
    font-size: 0.8em;
    margin-left: 5px;
    color: #666;
}

/* 1. THE DARK BACKGROUND - Keep this as is */
#edit-overlay, #agency-overlay, #invoice-overlay, #settings-overlay, #tax-payment-overlay, #bug-report-overlay, #filter-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    display: none; 
    justify-content: center;
    align-items: center;
}

/* Ensure Edit Job modal sits on top of Invoice modal */
#edit-overlay {
    z-index: 2010;
}

#edit-overlay.active { display: flex; }

/* 2. THE MODAL BOX - Updated to be wider (700px) and flexible */
.modal-content {
    background: #1e1e1e;
    width: 95%;
    max-width: 700px; /* Increased from 500px for the grid */
    max-height: 90vh; /* Prevents it from going off-screen */
    border-radius: 12px;
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* 3. NEW SECTIONS - Add these below .modal-content */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 1px solid #333;
    padding-bottom: 15px;
}

.modal-body {
    overflow-y: auto; /* Makes the form scrollable if it gets long */
    margin: 20px 0;
    padding: 5px 15px 5px 5px; /* Padding prevents shadow clipping */
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Creates the two-column look */
    gap: 15px;
    margin-bottom: 15px;
}

.modal-footer {
    border-top: 1px solid #333;
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-actions {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* 4. BUTTONS & ICONS - Keep these */
.close-btn {
    background: none; border: none;
    color: #888; font-size: 2em; cursor: pointer;
}
.close-btn:hover { color: white; }

th.sortable {
    user-select: none;
    transition: background 0.2s;
    white-space: nowrap;
}

th.sortable:hover {
    background: #333;
}

/* Optional: style the arrow specifically */
.sort-arrow {
    margin-left: 8px;
    font-size: 0.8em;
    color: #10b981; /* Matches your green theme */
}

#filter-bar {
    display: flex;
    gap: 15px; /* Space between the two filters */
    margin-bottom: 20px;
    align-items: center; /* Keeps them vertically centered */
    justify-content: flex-start; /* Keeps them on the left, not stretched */
}

#filter-agency {
    width: 220px; /* Specific 'moderate' width */
    padding: 8px;
    background-color: #2a2a2a;
    color: white;
    border: 1px solid #444;
    border-radius: 6px;
}

#filter-consumer {
    width: 220px !important;      /* Forces the width to 220px */
    max-width: 220px !important;  /* Prevents any stretching */
    flex: none !important;        /* Prevents flexbox from growing it */
    display: inline-block;        /* Ensures it respects the width setting */
    padding: 8px;
    background-color: #2a2a2a;
    color: white;
    border: 1px solid #444;
    border-radius: 6px;
}

#filter-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    justify-content: flex-start; /* Aligns them to the left */
    align-items: center;
}

/* Optional: Add a subtle hover effect so it feels like an app */
#filter-agency:hover, #filter-consumer:hover {
    border-color: #10b981;
}

/* The Navigation Pill Buttons */
.nav-btn {
    background-color: transparent;
    color: #059669; /* Same green as calculate button */
    border: 1px solid #059669;
    padding: 8px 20px;
    border-radius: 999px; /* This creates the perfect pill shape */
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background-color: rgba(5, 150, 105, 0.1); /* Subtle green glow on hover */
}

/* The Active Pill */
.nav-btn.active {
    background-color: #059669; /* Solid Emerald Green */
    color: white;
    box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3);
}

/* Admin button styling */
#nav-admin {
    border-color: #ef4444;
    color: #ef4444;
}

#nav-admin:hover {
    background-color: rgba(239, 68, 68, 0.1);
}

/* Admin button active state override */
#nav-admin.active {
    background-color: #ef4444;
    border-color: #ef4444;
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Red variant for delete buttons */
.nav-btn.delete-btn {
    background-color: transparent;
    color: #ef4444; /* Red */
    border-color: #ef4444;
}

.vri-pill {
    background-color: #059669;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: bold;
}

.delete-icon {
    background: none;
    border: none;
    color: #ef4444;
    font-size: 1.5em;
    cursor: pointer;
}

.delete-icon:hover {
    color: #dc2626;
}

.win-row.error-highlight {
    border: 1px solid #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
    border-radius: 4px;
    padding: 5px;
}

/* Fix visibility of calendar/time icons in dark mode */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    cursor: pointer;
}

/* Floating Action Button for Bug Reports */
#fab-bug-report {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #ef4444;
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    cursor: pointer;
    z-index: 3000; /* Higher than normal modals (2000) */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
}

#fab-bug-report:hover {
    transform: scale(1.1);
    background-color: #dc2626;
}

/* Ensure Bug Report modal sits on top of everything, including the FAB */
#bug-report-overlay {
    z-index: 4000;
}

/* Financial Dashboard Rows */
.financial-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 0.95em;
    cursor: pointer;
    transition: background 0.2s;
}
.financial-row:not(.static):hover {
    background-color: rgba(255, 255, 255, 0.1);
}
.financial-row.even { background-color: rgba(255, 255, 255, 0.03); }
.financial-row.static { cursor: default; }

.mobile-only { display: none; }

/* --- MOBILE RESPONSIVENESS --- */
@media (max-width: 768px) {
    header {
        flex-direction: row; /* Keep Title (Left) and Settings (Right) side-by-side */
        align-items: flex-start;
        justify-content: space-between;
        padding: 15px 20px;
        position: relative; /* Anchor for absolute nav */
    }

    .mobile-only { display: block; }

    /* Left Container (Title + Menu) */
    header > div:first-child {
        display: flex;
        flex-direction: column;
        gap: 5px;
        align-items: flex-start;
    }

    #main-nav {
        display: none; /* Hidden by default */
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background-color: #1a1a1a;
        border-bottom: 1px solid #333;
        flex-direction: column;
        padding: 0;
        z-index: 5000;
        box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    }

    #main-nav.open {
        display: flex;
    }

    #main-nav .nav-btn {
        width: 100%;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid #333;
        text-align: left;
        padding: 15px 20px;
        margin: 0;
    }
    
    #mobile-menu-btn {
        display: block !important;
        text-align: left;
    }

    #main-layout {
        display: block !important; /* Force stack layout */
        height: auto !important;
    }

    #sidebar {
        width: 100% !important;
        height: auto !important;
        border-right: none;
        border-bottom: 1px solid #333;
        max-height: 50vh; /* Limit sidebar height on mobile */
    }

    /* --- MOBILE TABLE CARD VIEW --- */
    table, thead, tbody, th, td, tr {
        display: block;
    }

    /* Hide table headers (but keep them accessible for screen readers) */
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr {
        margin-bottom: 15px;
        border: 1px solid #444;
        border-radius: 8px;
        background: #242424;
        padding: 10px;
    }

    /* Reset zebra striping on mobile cards so they look consistent */
    tbody tr:nth-child(even) {
        background-color: #242424;
    }

    td {
        border: none;
        position: relative;
        padding-left: 0;
        padding-top: 5px;
        padding-bottom: 5px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
        border-bottom: 1px solid #333;
    }

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

    /* The Label (generated from data-label attribute) */
    td::before {
        content: attr(data-label);
        font-weight: bold;
        color: #888;
        text-transform: uppercase;
        font-size: 0.75em;
        margin-right: 10px;
        text-align: left;
    }

    /* Fix Date/Time Inputs on Mobile (Add Icons) */
    input[type="date"], input[type="time"] {
        min-height: 40px;
        appearance: none;
        -webkit-appearance: none;
        background-repeat: no-repeat;
        background-position: right 10px center;
        background-size: 20px;
        padding-right: 35px;
    }

    input[type="date"] {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'%3E%3C/rect%3E%3Cline x1='16' y1='2' x2='16' y2='6'%3E%3C/line%3E%3Cline x1='8' y1='2' x2='8' y2='6'%3E%3C/line%3E%3Cline x1='3' y1='10' x2='21' y2='10'%3E%3C/line%3E%3C/svg%3E");
    }

    input[type="time"] {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'%3E%3C/circle%3E%3Cpolyline points='12 6 12 12 16 14'%3E%3C/polyline%3E%3C/svg%3E");
    }

    /* New style to put the setting on the right */
    #mobile-menu-btn {
        margin-top:auto
    }

    /* Stack Modal Grids on Mobile */
    .modal-grid, .agency-grid-3, .agency-grid-4 {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .job-modal-layout {
        flex-direction: column;
        gap: 15px;
    }

    .job-modal-expenses-grid {
        grid-template-columns: 1fr 1fr !important; /* 2 columns for expenses on mobile */
        width: 100%;
    }

    .job-modal-datetime-grid {
        grid-template-columns: 1fr 1fr !important; /* Date | Time side-by-side */
        grid-template-rows: auto auto;
        text-align: left;
    }
    
    .job-modal-datetime-grid span {
        grid-column: auto !important;
        text-align: left !important;
        margin-top: 0 !important;
        margin-bottom: 5px;
    }

    /* Explicitly place items to create Start (Left) vs End (Right) columns */
    .job-modal-datetime-grid span:nth-of-type(1) { grid-row: 1; grid-column: 1; } /* Start Label */
    .job-modal-datetime-grid input:nth-of-type(1) { grid-row: 2; grid-column: 1; } /* Start Date */
    .job-modal-datetime-grid input:nth-of-type(2) { grid-row: 3; grid-column: 1; } /* Start Time */
    
    .job-modal-datetime-grid span:nth-of-type(2) { grid-row: 1; grid-column: 2; } /* End Label */
    .job-modal-datetime-grid input:nth-of-type(3) { grid-row: 2; grid-column: 2; } /* End Date */
    .job-modal-datetime-grid input:nth-of-type(4) { grid-row: 3; grid-column: 2; } /* End Time */

    /* Mobile Modal Footer Actions */
    .modal-actions {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
    .modal-actions > div {
        display: flex;
        width: 100%;
        gap: 10px;
    }
    .modal-actions > div > button {
        flex: 1; /* Calc and Save take equal width */
    }
    #modal-delete-btn {
        width: auto; /* Smaller width */
        align-self: flex-start; /* Align to left */
        order: 2; /* Move Delete to the bottom */
        margin-top: 5px;
    }

    /* Stack View Headers (Title vs Buttons) */
    .view-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 15px;
    }

    .view-header button {
        width: 100%; /* Full width buttons on mobile */
    }

    /* Prevent pagination buttons from taking full width */
    [id$="-pagination-controls-top"] button {
        width: auto;
    }

    .admin-header-group {
        flex-wrap: wrap;
        width: 100%;
    }

    /* Ensure the container of tabs takes full width */
    .admin-header-group > div {
        width: 100%;
    }

    /* Fix Admin Tabs on Mobile to sit side-by-side */
    #admin-tab-bugs, #admin-tab-users {
        width: auto;
        flex: 1;
    }

    /* Filter Modal Styles */
    .mobile-filter-wrapper label {
        display: block; color: #888; font-size: 0.8em; margin-bottom: 5px; text-transform: uppercase;
    }

    /* Hide Date Ranges on Main View (Mobile), Show in Modal */
    #all-jobs-date-range, #invoices-date-range {
        display: none !important;
    }
    #filter-modal-body #all-jobs-date-range, 
    #filter-modal-body #invoices-date-range {
        display: flex !important;
    }
}

/* --- VIEW HEADER UTILITIES --- */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.admin-header-group {
    display: flex; 
    gap: 15px; 
    align-items: center;
}

/* --- MODAL LAYOUT UTILITIES (Desktop Defaults) --- */
.job-modal-layout {
    display: flex;
    gap: 25px;
    align-items: flex-start;
    margin-bottom: 15px;
}

.job-modal-time-col {
    flex: 1.2;
    padding-top: 20px;
}

.job-modal-expenses-grid {
    flex: 1.5;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px 15px;
}

.job-modal-datetime-grid {
    display: grid;
    grid-template-columns: 40px 1fr 1fr;
    gap: 10px;
    align-items: center;
}

.agency-grid-3 {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 15px;
}

.agency-grid-4 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}