/**
 * Safari-specific Dark Mode Fixes for iPad
 * These overrides ensure proper dark mode rendering in Safari
 */

@media (prefers-color-scheme: dark) {
    /* Force text colors with higher specificity for Safari */

    /* Fix dark text on dark background issue */
    body * {
        color: #dee2e6 !important;
    }

    /* Specifically target labels and headers that Safari might not be updating */
    h1, h2, h3, h4, h5, h6,
    label,
    .info-group-title,
    .card-title,
    strong, b {
        color: #f8f9fa !important;
        -webkit-text-fill-color: #f8f9fa !important;
    }

    /* Fix for "Patient", "Caller", "Name", "Age" labels */
    .info-compact strong,
    .complaint-compact strong,
    .location-compact strong,
    .assignment-compact strong {
        color: #adb5bd !important;
        -webkit-text-fill-color: #adb5bd !important;
    }

    /* Values should remain white */
    .info-compact span,
    .complaint-compact span,
    .location-compact span,
    .assignment-compact span {
        color: #f8f9fa !important;
        -webkit-text-fill-color: #f8f9fa !important;
    }

    /* Fix the Reason for Call section - make it darker */
    .text-danger {
        color: #dc3545 !important;
        -webkit-text-fill-color: #dc3545 !important;
        filter: brightness(0.7) !important;
    }

    /* Fix bright red box for Reason for Call */
    .card-header.bg-danger,
    .alert-danger {
        background-color: #5a1e28 !important;
        border-color: #842029 !important;
        color: #f8d7da !important;
    }

    /* Fix bright yellow Location box */
    .card-header.bg-warning,
    .alert-warning,
    .text-warning {
        background-color: #664d03 !important;
        border-color: #997404 !important;
        color: #ffda6a !important;
        filter: brightness(0.7) !important;
    }

    /* Fix address boxes at bottom - make backgrounds darker */
    .list-group-item {
        background-color: #1a1d20 !important;
        border-color: #495057 !important;
        color: #dee2e6 !important;
    }

    /* Address boxes specifically */
    .address-item,
    .location-item,
    .list-group-item-action {
        background-color: #212529 !important;
        color: #dee2e6 !important;
    }

    .address-item:hover,
    .location-item:hover,
    .list-group-item-action:hover {
        background-color: #2c3034 !important;
    }

    /* Fix white text on light grey boxes */
    .bg-light {
        background-color: #343a40 !important;
        color: #dee2e6 !important;
    }

    .bg-secondary {
        background-color: #495057 !important;
        color: #f8f9fa !important;
    }

    /* Info groups should have proper contrast */
    .info-group {
        background-color: rgba(33, 37, 41, 0.5) !important;
        border: 1px solid #495057 !important;
        padding: 0.75rem !important;
        border-radius: 0.25rem !important;
    }

    .info-group-title {
        color: #6ea8fe !important;
        -webkit-text-fill-color: #6ea8fe !important;
        border-bottom: 1px solid #495057 !important;
        padding-bottom: 0.5rem !important;
        margin-bottom: 0.5rem !important;
        font-weight: 600 !important;
    }

    /* Fix Call # and Created text */
    .call-number,
    .call-created,
    .badge {
        color: #f8f9fa !important;
        -webkit-text-fill-color: #f8f9fa !important;
    }

    /* Ensure icons maintain proper color */
    .info-group-title i {
        opacity: 0.8 !important;
    }

    .fa-user-injured {
        color: #dc3545 !important;
        filter: brightness(0.7) !important;
    }

    .fa-phone {
        color: #198754 !important;
        filter: brightness(0.7) !important;
    }

    .fa-stethoscope {
        color: #dc3545 !important;
        filter: brightness(0.7) !important;
    }

    .fa-map-marker-alt {
        color: #ffc107 !important;
        filter: brightness(0.7) !important;
    }

    /* Primary colored headers should be darker */
    .card-header.bg-primary {
        background-color: #084298 !important;
        border-color: #084298 !important;
        color: #cfe2ff !important;
    }

    .card-header.bg-success {
        background-color: #0f5132 !important;
        border-color: #0f5132 !important;
        color: #d1e7dd !important;
    }

    /* Ensure all text inputs are properly styled */
    input, select, textarea {
        background-color: #2c3034 !important;
        border-color: #495057 !important;
        color: #dee2e6 !important;
        -webkit-text-fill-color: #dee2e6 !important;
    }

    /* Tables need proper colors */
    .table {
        color: #dee2e6 !important;
    }

    .table td, .table th {
        color: #dee2e6 !important;
        border-color: #495057 !important;
    }

    /* Safari-specific webkit overrides */
    @supports (-webkit-appearance: none) {
        /* Force all text to be light colored */
        * {
            -webkit-text-fill-color: unset;
        }

        body, .card, .card-body, .modal-content {
            color: #dee2e6 !important;
        }

        /* Specific overrides for problem elements */
        label, dt, th {
            color: #adb5bd !important;
        }

        /* Data values should be brighter */
        dd, td, .data-value {
            color: #f8f9fa !important;
        }
    }

    /* Additional Safari mobile specific fixes */
    @supports (-webkit-touch-callout: none) {
        /* iOS Safari specific */
        body {
            -webkit-text-size-adjust: 100%;
        }

        /* Ensure tap highlight is appropriate for dark mode */
        * {
            -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
        }
    }

    /* Fix Bootstrap utility classes that Safari might not override properly */
    .text-primary { color: #6ea8fe !important; }
    .text-secondary { color: #6c757d !important; }
    .text-success { color: #75b798 !important; }
    .text-info { color: #6edff6 !important; }
    .text-warning { color: #ffda6a !important; filter: brightness(0.7) !important; }
    .text-danger { color: #ea868f !important; filter: brightness(0.7) !important; }
    .text-light { color: #f8f9fa !important; }
    .text-dark { color: #dee2e6 !important; }
    .text-body { color: #dee2e6 !important; }
    .text-muted { color: #6c757d !important; }
    .text-black-50 { color: rgba(222, 226, 230, 0.5) !important; }
    .text-white-50 { color: rgba(248, 249, 250, 0.5) !important; }

    /* Override any inline styles that might be causing issues */
    [style*="color: black"],
    [style*="color:#000"],
    [style*="color: #000000"],
    [style*="color:black"],
    [style*="color:rgb(0, 0, 0)"] {
        color: #dee2e6 !important;
    }

    /* Fix any background colors that are too bright */
    [style*="background-color: white"],
    [style*="background-color:#fff"],
    [style*="background-color: #ffffff"],
    [style*="background-color:white"],
    [style*="background:white"],
    [style*="background: white"],
    [style*="background:#fff"],
    [style*="background: #fff"] {
        background-color: #212529 !important;
    }

    /* Ensure proper contrast for all elements */
    .card-body * {
        color: inherit;
    }

    .card-body strong {
        color: #adb5bd !important;
    }

    .card-body span[data-field] {
        color: #f8f9fa !important;
    }
}