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

    .main-content {
        padding: 24px;
    }

    .toolbar {
        flex-wrap: wrap;
    }

    .search-box {
        flex-basis: 100%;
        max-width: none;
    }

    .toolbar .form-select,
    .toolbar .btn-outline {
        flex: 0 0 auto;
    }
}

/* Responsive — mobile */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }

    .sidebar {
        position: fixed;
        z-index: 1000;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 72px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

    /* Modal fixes for mobile */
    .modal {
        max-width: 95vw !important;
        margin: 10px auto;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Login card mobile */
    .login-card {
        max-width: 100%;
        margin: 10px;
        padding: 24px;
    }

    /* Page header - stack title and button */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .page-header .btn:not(.btn-compact) {
        width: 100%;
        justify-content: center;
    }

    /* Filter bars - stack vertically */
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
    }

    .filters-bar select,
    .filters-bar input {
        width: 100% !important;
    }

    /* Tables - horizontal scroll with better UX */
    .table-container {
        margin: 0 -16px;
        padding: 0 16px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-container table {
        min-width: 600px;
    }

    /* Contractor header stats - wrap on mobile */
    .contractor-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .contractor-total {
        flex-wrap: wrap;
        gap: 12px;
    }

    /* Billing info grid - single column on mobile */
    .billing-info-grid {
        grid-template-columns: 1fr !important;
    }

    /* Toolbar — stack on mobile */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        max-width: none;
    }

    .toolbar .form-select {
        width: 100%;
    }

    .toolbar .btn-outline {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    /* Stat cards - smaller text */
    .stat-value {
        font-size: 18px;
    }

    /* Page title */
    .page-title {
        font-size: 20px;
    }

    /* Buttons - better touch targets */
    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }

    .btn-icon {
        min-width: 44px;
        min-height: 44px;
    }

    /* Invoice items on mobile */
    .invoice-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .invoice-item .invoice-actions {
        width: 100%;
        display: flex;
        gap: 8px;
    }
}

/* Extra small screens */
@media (max-width: 400px) {
    .main-content {
        padding: 12px;
        padding-top: 60px;
    }

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

    .stat-card {
        padding: 12px;
    }

    .stat-value {
        font-size: 16px;
    }

    .stat-label {
        font-size: 10px;
    }

    .page-title {
        font-size: 18px;
    }

    /* Even smaller table handling */
    .table-container table {
        min-width: 500px;
    }

    table th, table td {
        padding: 8px 10px;
        font-size: 12px;
    }
}

/* Customer List Item with Actions */
.customer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid hsla(220, 15%, 90%, 0.4);
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
    min-height: 44px;
}

.customer-item:last-child {
    border-bottom: none;
}

.customer-item:hover {
    background: var(--bg-tertiary);
}

.customer-item:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
    border-radius: 4px;
}

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

.customer-name {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

.customer-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.customer-actions {
    position: relative;
    flex-shrink: 0;
}

/* Report Filters */
.filters-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* Contractor row in report */
.contractor-section {
    margin-bottom: 8px;
    animation: fadeUpLarge 0.3s ease-out both;
}

.contractor-section:nth-child(1) { animation-delay: 0.1s; }
.contractor-section:nth-child(2) { animation-delay: 0.15s; }
.contractor-section:nth-child(3) { animation-delay: 0.2s; }
.contractor-section:nth-child(4) { animation-delay: 0.25s; }
.contractor-section:nth-child(5) { animation-delay: 0.3s; }

.contractor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid hsl(220, 15%, 90%);
    border-bottom: 1px solid hsla(220, 15%, 90%, 0.3);
    border-radius: 8px 8px 0 0;
}

.contractor-name {
    font-weight: 600;
    font-size: 13px;
}

.contractor-total {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}

.contractor-stat {
    display: flex;
    align-items: baseline;
    gap: 3px;
}

.contractor-stat-value {
    font-weight: 600;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.contractor-stat-label {
    font-size: 10px;
    color: var(--text-primary);
    opacity: 0.45;
}

.contractor-entries {
    border: 1px solid hsl(220, 15%, 90%);
    border-top: none;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}
