/* --- Dark mode for native dropdowns in modals --- */
[data-bs-theme="dark"] .modal select.form-select,
[data-bs-theme="dark"] .modal select.form-control {
    background-color: rgba(255, 255, 255, 0.05) !important;
    color: #fff !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

[data-bs-theme="dark"] .modal select.form-select:focus,
[data-bs-theme="dark"] .modal select.form-control:focus {
    background-color: rgba(255, 255, 255, 0.08) !important;
    color: #fff !important;
    border-color: #0d6efd !important;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25) !important;
}

/* Option text in dropdowns */
[data-bs-theme="dark"] .modal select.form-select option,
[data-bs-theme="dark"] .modal select.form-control option {
    background: var(--bs-dark) !important;
    color: #fff !important;
}

/* ─── Modal Styling ─── */
.modal {
    display: block;
    position: fixed;
    z-index: 1055;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

/* Hide scrollbars inside modals specifically (keeps scroll behavior) */
.modal,
.modal-content,
.modal-body,
.modal-dialog {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE 10+ */
}

.modal::-webkit-scrollbar,
.modal-content::-webkit-scrollbar,
.modal-body::-webkit-scrollbar,
.modal-dialog::-webkit-scrollbar {
    display: none; /* WebKit */
    width: 0px;
    height: 0px;
}

.modal-content {
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    margin: 3% auto;
    padding: 0;
    width: 95%;
    max-width: 900px;
    border: none;
    border-radius: 12px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    background: transparent;
    color: var(--bs-body-color);
    padding: 2.5rem 1.5rem 2.5rem 1.5rem;
    min-height: 80px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(var(--bs-primary-rgb), 0.1);
    border-radius: 12px 12px 0 0;
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.05), rgba(var(--bs-primary-rgb), 0.02));
}

.modal-header h4,
.modal-header h5 {
    margin: 0;
    font-weight: 600;
    font-size: 1.2rem;
}

.modal-title {
    font-weight: 600;
    color: var(--bs-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(var(--bs-primary-rgb), 0.1);
    background: rgba(var(--bs-secondary-bg), 0.3);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    border-radius: 0 0 12px 12px;
}

/* Close button styling */
.modal .close,
.modal-header .btn-close {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    font-size: 1.5rem;
    color: rgba(255, 71, 87, 0.8);
    cursor: pointer;
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal .close:hover,
.modal-header .btn-close:hover {
    color: #ff4757;
    background: rgba(255, 71, 87, 0.1);
}

/* Form styling in modals */
.modal .form-control {
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 0.65rem 0.9rem;
    transition: border-color 0.2s ease;
}

.modal .form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.1);
}

.modal .form-label {
    font-weight: 600;
    color: var(--bs-gray-700);
    margin-bottom: 0.4rem;
}

/* Dark mode modal */
[data-bs-theme="dark"] .modal-content {
    background: #08151d !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .modal .accordion,
[data-bs-theme="dark"] .modal .accordion-item {
    background: #08151d !important;
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .modal .accordion-header {
    background: #08151d !important;
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .modal .accordion-button {
    background: #08151d !important;
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] .modal-header {
    background: #08151d !important;
    color: #ffffff !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

/* [data-bs-theme="dark"] .modal-footer {
    background: #08151d !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #ffffff !important;
} */

[data-bs-theme="dark"] .modal .form-control {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .modal .form-control:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: #0d6efd;
}



/* --- Modal title visibility fix for light mode --- */
[data-bs-theme="light"] .modal-header,
[data-bs-theme="light"] .modal-title,
[data-bs-theme="light"] .modal-header .modal-title {
    color: #212529 !important;
}

[data-bs-theme="light"] .modal-header.bg-primary,
[data-bs-theme="light"] .modal-header.bg-info,
[data-bs-theme="light"] .modal-header.bg-success,
[data-bs-theme="light"] .modal-header.bg-danger {
    color: #fff !important;
}

[data-bs-theme="light"] .modal-header.bg-primary .modal-title,
[data-bs-theme="light"] .modal-header.bg-info .modal-title,
[data-bs-theme="light"] .modal-header.bg-success .modal-title,
[data-bs-theme="light"] .modal-header.bg-danger .modal-title {
    color: #fff !important;
}

/* ─── COMPREHENSIVE MODAL DARK MODE STYLES ─── */
/* Ensure all modal text is visible in dark mode */
[data-bs-theme="dark"] .modal-content {
    background: var(--bs-dark) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .modal-header {
    color: #ffffff !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .modal-title {
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal-body {
    color: #ffffff !important;
    background: #08151d !important;
}

[data-bs-theme="dark"] .modal-footer {
    background: #08151d !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #ffffff !important;
}

/* Modal form elements in dark mode */
[data-bs-theme="dark"] .modal .form-label {
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .form-control,
[data-bs-theme="dark"] .modal .form-select,
[data-bs-theme="dark"] .modal textarea.form-control {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .form-control:focus,
[data-bs-theme="dark"] .modal .form-select:focus,
[data-bs-theme="dark"] .modal textarea.form-control:focus {
    background-color: rgba(255, 255, 255, 0.08) !important;
    border-color: #0d6efd !important;
    color: #ffffff !important;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25) !important;
}

[data-bs-theme="dark"] .modal .form-control::placeholder,
[data-bs-theme="dark"] .modal textarea.form-control::placeholder {
    color: rgba(255, 255, 255, 0.6) !important;
}

/* Alert messages in modals */
[data-bs-theme="dark"] .modal .alert {
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .alert-danger {
    background-color: rgba(220, 53, 69, 0.2) !important;
    border-color: rgba(220, 53, 69, 0.4) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .alert-success {
    background-color: rgba(25, 135, 84, 0.2) !important;
    border-color: rgba(25, 135, 84, 0.4) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .alert-warning {
    background-color: rgba(255, 193, 7, 0.2) !important;
    border-color: rgba(255, 193, 7, 0.4) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .alert-info {
    background-color: rgba(13, 202, 240, 0.2) !important;
    border-color: rgba(13, 202, 240, 0.4) !important;
    color: #ffffff !important;
}

/* Close button in dark mode */
[data-bs-theme="dark"] .modal .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Text elements that might have custom colors */
[data-bs-theme="dark"] .modal h1,
[data-bs-theme="dark"] .modal h2,
[data-bs-theme="dark"] .modal h3,
[data-bs-theme="dark"] .modal h4,
[data-bs-theme="dark"] .modal h5,
[data-bs-theme="dark"] .modal h6,
[data-bs-theme="dark"] .modal p,
[data-bs-theme="dark"] .modal span,
[data-bs-theme="dark"] .modal div,
[data-bs-theme="dark"] .modal li,
[data-bs-theme="dark"] .modal td,
[data-bs-theme="dark"] .modal th {
    color: #ffffff !important;
}

/* Specific overrides for text that might be inheriting wrong colors */
[data-bs-theme="dark"] .modal .text-muted {
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .text-primary {
    color: #6ea8fe !important;
}

[data-bs-theme="dark"] .modal .text-secondary {
    color: #6c757d !important;
}

/* Select2 in modals - dark mode */
[data-bs-theme="dark"] .modal .select2-container--default .select2-selection--single {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
}

/* Select2 (theme: bootstrap-5) in modals - dark mode */
[data-bs-theme="dark"] .modal .select2-container--bootstrap-5 .select2-selection--single {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .select2-container--bootstrap-5 .select2-selection--multiple {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .select2-container--bootstrap-5 .select2-selection__placeholder {
    color: rgba(255, 255, 255, 0.45) !important;
}

[data-bs-theme="dark"] .modal .select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow b {
    border-color: rgba(255, 255, 255, 0.65) transparent transparent transparent !important;
}

[data-bs-theme="dark"] .modal .select2-selection__rendered {
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .select2-dropdown {
    background-color: var(--bs-dark) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .select2-results__option {
    background-color: var(--bs-dark) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .modal .select2-results__option--highlighted {
    background-color: rgba(13, 110, 253, 0.2) !important;
    color: #ffffff !important;
}

/* --- Modal overlay fixes for stacking and background interaction --- */
.modal {
    z-index: 20000 !important;
    pointer-events: auto !important;
}

body.modal-open .card,
body.modal-open .table,
body.modal-open .actions-col {
    filter: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transition: none !important;
}

/* Allow buttons to maintain their normal styling when modal is open */
body.modal-open .btn {
    pointer-events: auto !important;
}

/* Prevent background table/buttons from changing size or color when modal is open */
/* Removed problematic CSS that was overriding button styles - buttons should maintain their appearance */

/* ─── Autocomplete Dropdown Styling ─── */
#hospital-suggestions.autocomplete-suggestions,
#hospital-country-suggestions.autocomplete-suggestions,
#country-suggestions.autocomplete-suggestions,
#country-suggestions-edit.autocomplete-suggestions,
#country-suggestions-reg.autocomplete-suggestions,
#country-suggestions-branch.autocomplete-suggestions,
#country-suggestions-branch-edit.autocomplete-suggestions {
  position: absolute;
  z-index: 1000000;
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: 0.375rem;
  border-top: none;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  color: var(--bs-body-color);
}

#hospital-suggestions .suggestion,
#hospital-country-suggestions .suggestion,
#country-suggestions .suggestion,
#country-suggestions-edit .suggestion,
#country-suggestions-reg .suggestion,
#country-suggestions-branch .suggestion,
#country-suggestions-branch-edit .suggestion {
  padding: 10px 12px;
  cursor: pointer;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  border: none;
  border-bottom: 1px solid rgba(var(--bs-border-color-rgb), 0.2);
  display: flex;
  align-items: center;
  font-size: 0.95rem;
}

#hospital-suggestions .suggestion:last-child,
#hospital-country-suggestions .suggestion:last-child,
#country-suggestions .suggestion:last-child,
#country-suggestions-edit .suggestion:last-child,
#country-suggestions-reg .suggestion:last-child,
#country-suggestions-branch .suggestion:last-child,
#country-suggestions-branch-edit .suggestion:last-child {
  border-bottom: none;
}

#hospital-suggestions .suggestion:hover, 
#hospital-suggestions .suggestion.active,
#hospital-country-suggestions .suggestion:hover, 
#hospital-country-suggestions .suggestion.active,
#country-suggestions .suggestion:hover, 
#country-suggestions .suggestion.active,
#country-suggestions-edit .suggestion:hover, 
#country-suggestions-edit .suggestion.active,
#country-suggestions-reg .suggestion:hover, 
#country-suggestions-reg .suggestion.active,
#country-suggestions-branch .suggestion:hover, 
#country-suggestions-branch .suggestion.active,
#country-suggestions-branch-edit .suggestion:hover, 
#country-suggestions-branch-edit .suggestion.active {
  background: var(--bs-primary);
  color: white;
}

/* Dark mode autocomplete */
[data-bs-theme="dark"] #hospital-suggestions.autocomplete-suggestions,
[data-bs-theme="dark"] #hospital-country-suggestions.autocomplete-suggestions,
[data-bs-theme="dark"] #country-suggestions.autocomplete-suggestions,
[data-bs-theme="dark"] #country-suggestions-edit.autocomplete-suggestions,
[data-bs-theme="dark"] #country-suggestions-reg.autocomplete-suggestions,
[data-bs-theme="dark"] #country-suggestions-branch.autocomplete-suggestions,
[data-bs-theme="dark"] #country-suggestions-branch-edit.autocomplete-suggestions {
  background: #1a1d29 !important;
  border-color: #444c56 !important;
  color: #f1f3f4 !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-bs-theme="dark"] #hospital-suggestions .suggestion,
[data-bs-theme="dark"] #hospital-country-suggestions .suggestion,
[data-bs-theme="dark"] #country-suggestions .suggestion,
[data-bs-theme="dark"] #country-suggestions-edit .suggestion,
[data-bs-theme="dark"] #country-suggestions-reg .suggestion,
[data-bs-theme="dark"] #country-suggestions-branch .suggestion,
[data-bs-theme="dark"] #country-suggestions-branch-edit .suggestion {
  background: #1a1d29 !important;
  color: #f1f3f4 !important;
  border-bottom-color: rgba(255, 255, 255, 0.1) !important;
}

[data-bs-theme="dark"] #hospital-suggestions .suggestion:hover, 
[data-bs-theme="dark"] #hospital-suggestions .suggestion.active,
[data-bs-theme="dark"] #hospital-country-suggestions .suggestion:hover, 
[data-bs-theme="dark"] #hospital-country-suggestions .suggestion.active,
[data-bs-theme="dark"] #country-suggestions .suggestion:hover, 
[data-bs-theme="dark"] #country-suggestions .suggestion.active {
  background: #0d6efd !important;
  color: #ffffff !important;
}