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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f7fa;
    color: #333;
    line-height: 1.6;
}

.hidden { display: none !important; }

/* Login Screen */
.login-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-container {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}

.login-container h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #333;
}

.login-container input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 1rem;
}

.login-container button {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.login-container button:hover {
    background: #5a6fd8;
}

.error-message {
    color: #e74c3c;
    text-align: center;
    margin-top: 1rem;
    font-size: 14px;
}

/* Dashboard Layout */
.dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    color: #333;
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.last-updated {
    color: #666;
    font-size: 0.9rem;
}

.refresh-btn, .logout-btn, .retry-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.refresh-btn {
    background: #3498db;
    color: white;
}

.refresh-btn:hover {
    background: #2980b9;
}

.logout-btn {
    background: #e74c3c;
    color: white;
}

.logout-btn:hover {
    background: #c0392b;
}

/* Loading and Error States */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.error {
    text-align: center;
    padding: 4rem;
}

.error h3 {
    color: #e74c3c;
    margin-bottom: 1rem;
}

.retry-btn {
    background: #3498db;
    color: white;
    margin-top: 1rem;
}

/* Content Layout */
.content {
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Date Range Filter */
.date-filter-section {
    background: white;
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.date-filter-section h3 {
    margin: 0;
    color: #333;
}

.date-inputs {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.date-inputs input {
    padding: 8px 12px;
    border: 2px solid #e1e5e9;
    border-radius: 6px;
    font-size: 14px;
}

.filter-btn {
    padding: 8px 16px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.filter-btn:hover {
    background: #2980b9;
}

/* Overview Cards */
.overview-section {
    margin-bottom: 2rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.overview-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s;
}

.overview-card:hover {
    transform: translateY(-2px);
}

.card-icon {
    font-size: 2rem;
}

.card-content h3 {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
}

.card-value {
    font-size: 1.8rem;
    font-weight: bold;
    color: #333;
}

.overview-card.success .card-value { color: #27ae60; }
.overview-card.danger .card-value { color: #e74c3c; }
.overview-card.warning .card-value { color: #f39c12; }
.overview-card.info .card-value { color: #3498db; }
.overview-card.alert .card-value { color: #e67e22; }

/* Charts - OPTIMIZED FOR PERFORMANCE */
.charts-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.chart-container {
    background: white;
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    height: 300px; /* Fixed height for better performance */
}

.chart-container h3 {
    margin-bottom: 0.5rem;
    color: #333;
    font-size: 1rem;
}

.chart-container canvas {
    max-height: 250px !important; /* Smaller charts for better performance */
    will-change: transform; /* GPU acceleration */
}

/* Alerts */
.alerts-section {
    margin-bottom: 2rem;
}

.alerts-section h3 {
    margin-bottom: 1rem;
    color: #333;
}

.alerts-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
}

.alert-item {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid #e74c3c;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.alert-item.warning {
    border-left-color: #f39c12;
}

.alert-item.critical {
    border-left-color: #e74c3c;
}

.alert-message {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.alert-timestamp {
    font-size: 0.8rem;
    color: #666;
}

/* Business Table */
.business-section h3 {
    margin-bottom: 1rem;
    color: #333;
}

.table-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.search-input, .sort-select {
    padding: 8px 12px;
    border: 2px solid #e1e5e9;
    border-radius: 6px;
    font-size: 14px;
}

.search-input {
    flex: 1;
}

.table-container {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    max-height: 600px;
    overflow-y: auto;
}

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

.business-table th {
    background: #f8f9fa;
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #e1e5e9;
    position: sticky;
    top: 0;
    z-index: 10;
}

.business-table td {
    padding: 1rem;
    border-bottom: 1px solid #e1e5e9;
}

.business-table tr:hover {
    background: #f8f9fa;
    cursor: pointer;
}

.business-name-cell {
    color: #3498db;
    text-decoration: underline;
    cursor: pointer;
}

.business-name-cell:hover {
    color: #2980b9;
}

.status-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.status-indicator.success { background: #27ae60; }
.status-indicator.alert { background: #e74c3c; }

.percentage {
    font-weight: 500;
}

.percentage.success { color: #27ae60; }
.percentage.danger { color: #e74c3c; }

/* Business Detail Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    margin: 2rem;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #e1e5e9;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
}

.modal-close:hover {
    color: #333;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.detail-card {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.detail-card h4 {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.detail-card .value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
}

/* Import Alerts */
.import-section h3 {
    margin-bottom: 1rem;
    color: #333;
}

.import-alerts {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.import-alert {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid #f39c12;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.import-alert-title {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.import-alert-details {
    font-size: 0.9rem;
    color: #666;
}

/* Performance Optimizations */
.business-table tbody {
    transform: translateZ(0); /* Force GPU acceleration */
}

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .content {
        padding: 1rem;
    }

    .card-grid {
        grid-template-columns: 1fr;
    }

    .charts-section {
        grid-template-columns: 1fr;
    }

    .chart-container {
        height: 250px;
    }

    .table-controls {
        flex-direction: column;
    }

    .date-filter-section {
        flex-direction: column;
        align-items: flex-start;
    }

    .date-inputs {
        width: 100%;
        justify-content: space-between;
    }

    .business-table {
        font-size: 0.9rem;
    }

    .business-table th,
    .business-table td {
        padding: 0.5rem;
    }

    .modal-content {
        margin: 1rem;
        max-height: 90vh;
    }
}

/* Progress Section */
.progress-section {
    margin-bottom: 20px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
    color: #666;
}

.progress-bar-container {
    width: 100%;
    background-color: #e5e7eb;
    border-radius: 4px;
    height: 8px;
}

.progress-bar {
    background-color: #3b82f6;
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Results Section */
.results-section {
    margin-top: 20px;
}

.results-header {
    margin-bottom: 15px;
}

.download-btn {
    background-color: #10b981;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.download-btn:hover:not(:disabled) {
    background-color: #059669;
}

.download-btn:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
}

/* Failure Table */
.failure-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.failure-table th,
.failure-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.failure-table th {
    background-color: #f9fafb;
    font-weight: 600;
    color: #374151;
}

.failure-table tr:hover {
    background-color: #f9fafb;
}

.failure-table a {
    color: #3b82f6;
    text-decoration: underline;
}

.failure-table a:hover {
    color: #1d4ed8;
}
/* Navigation Tabs */
.nav-tabs {
    display: flex;
    background: #2c3e50;
    border-bottom: 2px solid #34495e;
    margin-bottom: 20px;
}

.nav-tab {
    background: none;
    border: none;
    color: #bdc3c7;
    padding: 15px 25px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.nav-tab:hover {
    background: #34495e;
    color: #ecf0f1;
}

.nav-tab.active {
    color: #3498db;
    border-bottom-color: #3498db;
    background: #34495e;
}

.tab-content {
    display: block;
}

.tab-content.hidden {
    display: none;
}

/* Responsive tabs */
@media (max-width: 768px) {
    .nav-tabs {
        flex-direction: column;
    }
    
    .nav-tab {
        text-align: left;
        border-bottom: 1px solid #34495e;
        border-right: none;
    }
    
    .nav-tab.active {
        border-bottom-color: #34495e;
        border-left: 3px solid #3498db;
    }
}
/* Expandable import rows */
.customer-row {
    cursor: pointer;
}

.customer-row:hover {
    background-color: #f9fafb;
}

.import-toggle {
    text-align: center;
    font-weight: 500;
}

.toggle-icon {
    margin-right: 5px;
    transition: transform 0.2s;
}

.imports-row {
    background-color: #f8fafc;
}

.imports-row.hidden {
    display: none;
}

.imports-container {
    padding: 15px;
    border-left: 3px solid #e5e7eb;
}

.import-detail {
    background: white;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    border-left: 4px solid #e5e7eb;
}

.import-detail.healthy {
    border-left-color: #10b981;
    background-color: #f0fdf4;
}

.import-detail.warning {
    border-left-color: #f59e0b;
    background-color: #fffbeb;
}

.import-detail.critical {
    border-left-color: #ef4444;
    background-color: #fef2f2;
}

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

.import-name {
    font-weight: 600;
    font-size: 1.1em;
}

.import-status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.7em;
    font-weight: 600;
    text-transform: uppercase;
}

.import-status-badge.healthy {
    background-color: #dcfce7;
    color: #166534;
}

.import-status-badge.warning {
    background-color: #fef3c7;
    color: #92400e;
}

.import-status-badge.critical {
    background-color: #fee2e2;
    color: #991b1b;
}

.import-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    font-size: 0.9em;
    color: #6b7280;
}

.import-info span {
    display: flex;
    flex-direction: column;
}

.import-info span::before {
    content: attr(class);
    font-size: 0.8em;
    font-weight: 500;
    color: #374151;
    margin-bottom: 2px;
    text-transform: capitalize;
}

.import-id::before { content: "Import ID"; }
.import-jobs::before { content: "Total Jobs"; }
.import-last-job::before { content: "Last Job"; }
.import-last-import::before { content: "Last Import"; }
.import-days::before { content: "Status"; }

.import-id {
    font-family: monospace;
    font-size: 0.8em;
}

.no-imports {
    text-align: center;
    color: #9ca3af;
    font-style: italic;
    padding: 20px;
}

/* Stale Pending Jobs Section */
.stale-pending-section {
    margin-bottom: 2rem;
}

.stale-pending-alert {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-left: 4px solid #faad14;
}

.stale-pending-alert.critical {
    border-left-color: #ff4d4f;
    background: #fff2f0;
}

.stale-pending-alert.warning {
    border-left-color: #faad14;
    background: #fffbe6;
}

.alert-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.alert-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.alert-icon {
    font-size: 1.5rem;
}

.alert-title h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #333;
}

.toggle-btn {
    background: #f0f0f0;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.toggle-btn:hover {
    background: #e0e0e0;
}

.alert-message {
    margin-bottom: 0.75rem;
    font-size: 1rem;
    color: #666;
}

.alert-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.age-tag {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.age-tag.critical {
    background: #ff4d4f;
    color: white;
}

.age-tag.high {
    background: #ff7a45;
    color: white;
}

.age-tag.medium {
    background: #faad14;
    color: white;
}

.alert-oldest {
    font-size: 0.85rem;
    color: #999;
    margin-top: 0.5rem;
}

.stale-pending-details {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e8e8e8;
}

.stale-pending-details h4 {
    margin-bottom: 1rem;
    color: #333;
}

.stale-pending-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

.stale-pending-table thead {
    background: #fafafa;
}

.stale-pending-table th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #e8e8e8;
}

.stale-pending-table td {
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.stale-pending-table tbody tr:hover {
    background: #fafafa;
}

.business-link {
    color: #1890ff;
    text-decoration: none;
    cursor: pointer;
}

.business-link:hover {
    text-decoration: underline;
}

.pending-count-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
}

.pending-count-badge.high {
    background: #ff4d4f;
    color: white;
}

.pending-count-badge.medium {
    background: #ff7a45;
    color: white;
}

.pending-count-badge.low {
    background: #1890ff;
    color: white;
}

.days-overdue-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.9rem;
}

.days-overdue-badge.critical {
    background: #ff4d4f;
    color: white;
}

.days-overdue-badge.high {
    background: #ff7a45;
    color: white;
}

.days-overdue-badge.medium {
    background: #faad14;
    color: white;
}

/* Severity-based card styling */
#stalePendingCard.severity-none {
    border-left: 4px solid #52c41a;
}

#stalePendingCard.severity-warning {
    border-left: 4px solid #faad14;
}

#stalePendingCard.severity-critical {
    border-left: 4px solid #ff4d4f;
}

#stalePendingCard.severity-none .card-value {
    color: #52c41a;
}

#stalePendingCard.severity-warning .card-value {
    color: #faad14;
}

#stalePendingCard.severity-critical .card-value {
    color: #ff4d4f;
}
