/* Additional Dark Mode Fixes */
/* This file provides comprehensive fixes for any remaining white backgrounds in dark mode */

/* Force all potentially white elements to use theme colors */
@media (prefers-color-scheme: dark) {
    /* Generic fixes for common white background patterns */
    * {
        transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
    }
    
    /* Bootstrap and common white background classes */
    .bg-white,
    .bg-body,
    .bg-body-secondary,
    .bg-light {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
    }
    
    /* Card components */
    .card,
    .card-body,
    .card-header,
    .card-footer {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    /* Modal components */
    .modal-content,
    .modal-header,
    .modal-body,
    .modal-footer {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    /* Tables */
    .table {
        color: var(--text-primary) !important;
    }
    
    .table > :not(caption) > * > * {
        background-color: transparent !important;
        border-bottom-color: var(--border-color) !important;
        color: var(--text-primary) !important;
    }
    
    .table-striped > tbody > tr:nth-of-type(odd) > * {
        background-color: rgba(255, 255, 255, 0.05) !important;
    }
    
    /* Forms */
    .form-control,
    .form-select,
    .form-check-input {
        background-color: var(--bg-secondary) !important;
        border-color: var(--border-color) !important;
        color: var(--text-primary) !important;
    }
    
    .form-control:focus,
    .form-select:focus {
        background-color: var(--bg-primary) !important;
        border-color: var(--primary) !important;
        color: var(--text-primary) !important;
    }
    
    /* Dropdowns */
    .dropdown-menu {
        background-color: var(--bg-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    .dropdown-item {
        color: var(--text-primary) !important;
    }
    
    .dropdown-item:hover,
    .dropdown-item:focus {
        background-color: var(--bg-secondary) !important;
        color: var(--text-primary) !important;
    }
    
    /* Alerts */
    .alert {
        border-color: var(--border-color) !important;
    }
    
    .alert-light {
        background-color: var(--bg-secondary) !important;
        border-color: var(--border-color) !important;
        color: var(--text-primary) !important;
    }
    
    /* List groups */
    .list-group-item {
        background-color: var(--bg-primary) !important;
        border-color: var(--border-color) !important;
        color: var(--text-primary) !important;
    }
    
    /* Pagination */
    .page-link {
        background-color: var(--bg-primary) !important;
        border-color: var(--border-color) !important;
        color: var(--text-primary) !important;
    }
    
    .page-link:hover {
        background-color: var(--bg-secondary) !important;
        border-color: var(--border-color) !important;
        color: var(--text-primary) !important;
    }
    
    /* Breadcrumb */
    .breadcrumb {
        background-color: var(--bg-secondary) !important;
    }
    
    .breadcrumb-item a {
        color: var(--text-secondary) !important;
    }
    
    /* Nav tabs/pills */
    .nav-tabs .nav-link {
        background-color: transparent !important;
        border-color: var(--border-color) !important;
        color: var(--text-secondary) !important;
    }
    
    .nav-tabs .nav-link.active {
        background-color: var(--bg-primary) !important;
        border-color: var(--border-color) !important;
        color: var(--text-primary) !important;
    }
    
    /* Progress bars */
    .progress {
        background-color: var(--bg-secondary) !important;
    }
    
    /* Accordion */
    .accordion-item {
        background-color: var(--bg-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    .accordion-header button {
        background-color: var(--bg-secondary) !important;
        color: var(--text-primary) !important;
    }
    
    .accordion-body {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
    }
}

/* Explicit data-theme="dark" overrides */
[data-theme="dark"] .bg-white,
[data-theme="dark"] .bg-body,
[data-theme="dark"] .bg-body-secondary,
[data-theme="dark"] .bg-light {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .card,
[data-theme="dark"] .card-body,
[data-theme="dark"] .card-header,
[data-theme="dark"] .card-footer {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .modal-content,
[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-body,
[data-theme="dark"] .modal-footer {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .table {
    color: var(--text-primary) !important;
}

[data-theme="dark"] .table > :not(caption) > * > * {
    background-color: transparent !important;
    border-bottom-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-check-input {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

/* Specific fixes for content areas that might still be white */
[data-theme="dark"] .content,
[data-theme="dark"] .main-content,
[data-theme="dark"] .report-content,
[data-theme="dark"] .analysis-content,
[data-theme="dark"] .summary-content {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

/* Force override for any remaining white backgrounds via important declarations */
@media (prefers-color-scheme: dark) {
    div[style*="background-color: white"],
    div[style*="background: white"],
    div[style*="background-color: #fff"],
    div[style*="background: #fff"],
    section[style*="background-color: white"],
    section[style*="background: white"] {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
    }
}

[data-theme="dark"] div[style*="background-color: white"],
[data-theme="dark"] div[style*="background: white"],
[data-theme="dark"] div[style*="background-color: #fff"],
[data-theme="dark"] div[style*="background: #fff"],
[data-theme="dark"] section[style*="background-color: white"],
[data-theme="dark"] section[style*="background: white"] {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

/* Additional specific fixes for progress bars and data tables */
@media (prefers-color-scheme: dark) {
    /* Progress bars and loading areas */
    .progress,
    .progress-bar,
    .loading-area,
    .analysis-progress,
    .compliance-progress,
    .ai-progress {
        background-color: var(--bg-secondary) !important;
        color: var(--text-primary) !important;
    }
    
    .progress-bar {
        background-color: var(--primary) !important;
    }
    
    /* Data tables and inspection summaries */
    .inspection-summary,
    .device-summary,
    .compliance-table,
    .data-table,
    .summary-table,
    .device-table {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    /* Table headers and cells - more specific */
    .table-header,
    .summary-header,
    .device-header,
    .inspection-header,
    thead th,
    tbody td {
        background-color: var(--bg-secondary) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    /* Blue badge/button elements that show as light blue */
    .badge,
    .badge-primary,
    .badge-info,
    .badge-light,
    .btn-info,
    .btn-light,
    .tag,
    .label,
    .chip {
        background-color: var(--primary) !important;
        color: white !important;
        border-color: var(--primary) !important;
    }
    
    /* Status indicators and small text elements */
    .status,
    .device-status,
    .inspection-status,
    .compliance-status {
        background-color: var(--bg-secondary) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    /* Any remaining light colored text on dark backgrounds */
    .light-text,
    .muted-text,
    .secondary-text {
        color: var(--text-secondary) !important;
    }
    
    /* Force override any remaining white or very light backgrounds */
    *[style*="background-color: #f"],
    *[style*="background: #f"],
    *[class*="bg-light"],
    *[class*="light"] {
        background-color: var(--bg-secondary) !important;
        color: var(--text-primary) !important;
    }
}

/* Explicit data-theme dark mode fixes */
[data-theme="dark"] .progress,
[data-theme="dark"] .progress-bar,
[data-theme="dark"] .loading-area,
[data-theme="dark"] .analysis-progress,
[data-theme="dark"] .compliance-progress,
[data-theme="dark"] .ai-progress {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] .progress-bar {
    background-color: var(--primary) !important;
}

[data-theme="dark"] .inspection-summary,
[data-theme="dark"] .device-summary,
[data-theme="dark"] .compliance-table,
[data-theme="dark"] .data-table,
[data-theme="dark"] .summary-table,
[data-theme="dark"] .device-table {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .table-header,
[data-theme="dark"] .summary-header,
[data-theme="dark"] .device-header,
[data-theme="dark"] .inspection-header,
[data-theme="dark"] thead th,
[data-theme="dark"] tbody td {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-color) !important;
}

[data-theme="dark"] .badge,
[data-theme="dark"] .badge-primary,
[data-theme="dark"] .badge-info,
[data-theme="dark"] .badge-light,
[data-theme="dark"] .btn-info,
[data-theme="dark"] .btn-light,
[data-theme="dark"] .tag,
[data-theme="dark"] .label,
[data-theme="dark"] .chip {
    background-color: var(--primary) !important;
    color: white !important;
    border-color: var(--primary) !important;
}

[data-theme="dark"] *[style*="background-color: #f"],
[data-theme="dark"] *[style*="background: #f"],
[data-theme="dark"] *[class*="bg-light"],
[data-theme="dark"] *[class*="light"] {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* Ultra-aggressive fixes for any remaining white backgrounds */
@media (prefers-color-scheme: dark) {
    /* Catch any dynamically created elements */
    *:not(.fa):not(.fas):not(.far):not(.fab):not(.fal) {
        transition: background-color 0.3s ease, color 0.3s ease !important;
    }
    
    /* Force any element with computed white background */
    *[style*="255, 255, 255"],
    *[style*="rgb(255,255,255)"],
    *[style*="rgba(255,255,255"],
    *[style*="hsl(0,0%,100%)"] {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
    }
    
    /* Fix any remaining light gray backgrounds */
    *[style*="#f0f0f0"],
    *[style*="#f5f5f5"],
    *[style*="#f8f9fa"],
    *[style*="#e9ecef"] {
        background-color: var(--bg-secondary) !important;
        color: var(--text-primary) !important;
    }
    
    /* Extremely aggressive white background detection */
    * {
        /* Force override any white or near-white backgrounds */
    }
    
    /* Target specific compliance data elements visible in screenshot */
    .device-summary,
    .device-table,
    .device-records,
    .compliance-data,
    .data-grid,
    .equipment-details,
    .device-info,
    .inspection-data,
    .equipment-grid .equipment-card,
    .summary-card,
    .data-card,
    /* Any div that might contain tabular data */
    div[class*="device"],
    div[class*="summary"],
    div[class*="table"],
    div[class*="grid"],
    div[class*="data"],
    /* Target by common background colors */
    div[style*="background-color: #fff"],
    div[style*="background: #fff"],
    div[style*="background-color: white"],
    div[style*="background: white"],
    div[style*="background-color: #ffffff"],
    div[style*="background: #ffffff"],
    /* Light blues and grays that appear white-ish */
    div[style*="background-color: #f1f5f9"],
    div[style*="background-color: #f8fafc"],
    div[style*="background-color: #e2e8f0"],
    /* Any element with these classes that commonly have white backgrounds */
    .bg-white,
    .bg-light,
    .bg-body,
    .bg-body-secondary,
    .bg-body-tertiary,
    .table-light,
    .list-group-item-light {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    /* Nuclear option: catch all white backgrounds with wildcard */
    *[style*="background"][style*="white"],
    *[style*="background"][style*="#fff"],
    *[style*="background"][style*="255, 255, 255"],
    *[style*="background"][style*="rgb(255"],
    *[style*="background"][style*="rgba(255, 255, 255"] {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    /* ULTIMATE NUCLEAR OPTION: Force ALL elements to respect dark mode */
    * {
        /* Apply to all elements except media */
    }
    
    /* Blanket override for all potentially problematic elements */
    div:not([class*="icon"]):not([class*="logo"]):not([class*="image"]),
    section, article, main, aside, 
    table, tbody, thead, tfoot, tr, td, th,
    ul, ol, li, dl, dt, dd, p, span, h1, h2, h3, h4, h5, h6 {
        background-color: transparent !important;
    }
    
    /* Specific override for containers that commonly have white backgrounds */
    .container, .row, .col, .card, .panel, .box, .widget,
    [class*="table"], [class*="grid"], [class*="data"], [class*="list"],
    [class*="summary"], [class*="detail"], [class*="info"], [class*="content"],
    [class*="permit"], [class*="record"], [class*="item"], [class*="entry"],
    [id*="table"], [id*="grid"], [id*="data"], [id*="list"],
    [id*="summary"], [id*="detail"], [id*="info"], [id*="content"],
    [id*="permit"], [id*="record"] {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
        border-color: var(--border-color) !important;
    }
    
    /* Force any remaining table-like structures */
    [style*="display: table"], 
    [style*="display: table-row"],
    [style*="display: table-cell"],
    [style*="display: grid"],
    [style*="display: flex"] {
        background-color: var(--bg-primary) !important;
        color: var(--text-primary) !important;
    }
}

[data-theme="dark"] *[style*="255, 255, 255"],
[data-theme="dark"] *[style*="rgb(255,255,255)"],
[data-theme="dark"] *[style*="rgba(255,255,255"],
[data-theme="dark"] *[style*="hsl(0,0%,100%)"] {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

[data-theme="dark"] *[style*="#f0f0f0"],
[data-theme="dark"] *[style*="#f5f5f5"],
[data-theme="dark"] *[style*="#f8f9fa"],
[data-theme="dark"] *[style*="#e9ecef"] {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}