/* =====================================================
   GLOBAL MODAL FIX - Tüm Modal Sorunlarını Çözer
   Bootstrap 5 ile uyumlu, minimal müdahale
   EN SON YÜKLENEN CSS - TÜM ÇAKIŞMALARI OVERRIDE EDER
   ===================================================== */

/* PERFORMANS OPTİMİZASYONU - Animasyonları TAMAMEN KALDIR (Instant açılış) */
/* Bootstrap'ın tüm fade animasyonlarını devre dışı bırak */
/* Varsayılan olarak TÜM modallar gizli olmalı */
.modal,
.modal.fade {
    transition: none !important;
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -o-transition: none !important;
    opacity: 0 !important;
    display: none !important;
}

/* Sadece show class'ı varsa görünür */
.modal.fade.show,
.modal.show {
    transition: none !important;
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -o-transition: none !important;
    opacity: 1 !important;
    display: block !important;
}

.modal-dialog,
.modal.fade .modal-dialog,
.modal.fade.show .modal-dialog,
.modal.show .modal-dialog {
    transition: none !important;
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -o-transition: none !important;
    transform: none !important;
    -webkit-transform: none !important;
    -moz-transform: none !important;
    -o-transform: none !important;
}

.modal-backdrop,
.modal-backdrop.fade,
.modal-backdrop.fade.show,
.modal-backdrop.show {
    transition: none !important;
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -o-transition: none !important;
    opacity: 0.5 !important;
}

/* Tüm modal elemanları için animasyon kaldır - Ama butonları etkileme */
.modal input,
.modal select,
.modal textarea,
.modal label,
.modal .form-control,
.modal .form-select,
.modal.show input,
.modal.show select,
.modal.show textarea,
.modal.show label,
.modal.show .form-control,
.modal.show .form-select,
.modal.fade input,
.modal.fade select,
.modal.fade textarea,
.modal.fade.show input,
.modal.fade.show select,
.modal.fade.show textarea {
    transition: none !important;
    -webkit-transition: none !important;
    -moz-transition: none !important;
    -o-transition: none !important;
    animation: none !important;
    -webkit-animation: none !important;
    -moz-animation: none !important;
    -o-animation: none !important;
}

/* CRITICAL: Bootstrap'ın .modal-dialog { pointer-events: none; } kuralını override et */
/* Bootstrap'ın amacı: backdrop'a tıklanınca modal kapansın */
/* Bizim amacımız: Modal içindeki elemanlar tıklanabilir olsun */

/* Z-INDEX DÜZELTMESİ - En önemli düzeltme */
/* Backdrop backdrop'un altında kalmalı, modal üstte olmalı */
.modal-backdrop {
    z-index: 1050 !important;
    opacity: 0 !important; /* Başlangıçta görünmez */
    background-color: rgba(0, 0, 0, 0.5) !important; /* CSS variable override */
    --bs-backdrop-opacity: 0.5 !important; /* Bootstrap variable override */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    pointer-events: auto !important; /* Backdrop tıklamaları almalı */
}

.modal-backdrop.show {
    opacity: 0.5 !important; /* Kesin olarak 0.5 */
    z-index: 1050 !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    --bs-backdrop-opacity: 0.5 !important;
    pointer-events: auto !important; /* Backdrop tıklamaları almalı */
}

.modal-backdrop.fade {
    opacity: 0 !important;
}

.modal-backdrop.fade.show {
    opacity: 0.5 !important;
    z-index: 1050 !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    --bs-backdrop-opacity: 0.5 !important;
    pointer-events: auto !important; /* Backdrop tıklamaları almalı */
}

/* Modal container backdrop'dan yüksek olmalı */
.modal {
    z-index: 1055 !important;
    pointer-events: none !important; /* Backdrop tıklamalarını almak için */
    position: fixed !important; /* Z-index'in çalışması için */
}

.modal.show {
    z-index: 1055 !important;
    display: block !important;
    opacity: 1 !important;
    pointer-events: none !important; /* Backdrop tıklamalarını almak için */
    position: fixed !important;
}

/* Modal dialog ve content - Bootstrap'ın pointer-events: none'unu override et */
.modal-dialog {
    z-index: 1055 !important;
    pointer-events: auto !important; /* Bootstrap'ın none'unu override et */
    position: relative !important; /* Z-index'in çalışması için */
}

.modal.show .modal-dialog {
    pointer-events: auto !important;
    z-index: 1055 !important;
    position: relative !important;
    /* GPU acceleration - z-index'i güçlendirir */
    transform: translateZ(0) !important;
    will-change: transform !important;
}

.modal-content {
    z-index: 1055 !important;
    pointer-events: auto !important;
    position: relative !important; /* Z-index'in çalışması için */
    background-color: #fff !important;
    /* Modal content backdrop'un üstünde olmalı */
    transform: translateZ(0) !important; /* GPU acceleration - z-index'i güçlendirir */
    will-change: transform !important;
    isolation: isolate !important; /* Yeni stacking context oluştur */
}

/* Sidebar overlay modal açıldığında gizlenmeli */
body.modal-open .sidebar-overlay,
body.modal-open #sidebarOverlay {
    display: none !important;
    z-index: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Sidebar modal açıldığında modal'ın altında kalmalı */
body.modal-open .sidebar,
body.modal-open #sidebar {
    z-index: 1030 !important;
}

/* Header modal açıldığında modal'ın altında kalmalı */
body.modal-open header {
    z-index: 1040 !important;
}

/* Body scroll lock - Bootstrap'ın modal-open class'ını kullan */
body.modal-open {
    overflow: hidden !important;
}

/* Modal Dialog - Pointer events düzeltmesi */
.modal.show .modal-dialog {
    pointer-events: auto !important;
}

/* Modal Content - Opacity ve background düzeltmesi */
.modal.show .modal-content {
    opacity: 1 !important;
    background-color: #fff !important;
    pointer-events: auto !important;
}

/* Modal Header, Body, Footer - Renkleri koru */
.modal-header {
    pointer-events: auto !important;
    opacity: 1 !important;
    /* Background color'ı koru - bg-primary, bg-warning gibi class'lar çalışmalı */
}

.modal-body {
    pointer-events: auto !important;
    opacity: 1 !important;
    background-color: #fff !important; /* Body beyaz olmalı */
    color: inherit !important; /* Text rengini koru */
}

.modal-footer {
    pointer-events: auto !important;
    opacity: 1 !important;
    /* Background color'ı koru */
}

/* Form Elemanları - Sadece show durumunda aktif et */
.modal.show input:not(:disabled),
.modal.show select:not(:disabled),
.modal.show textarea:not(:disabled),
.modal.show button:not(:disabled),
.modal.show .form-control:not(:disabled),
.modal.show .form-select:not(:disabled),
.modal.show .form-check-input:not(:disabled),
.modal.show .btn:not(:disabled) {
    pointer-events: auto !important;
    opacity: 1 !important;
}

/* Sadece form input'ları için background ve color - Header/Footer/Button'ları etkilemesin */
.modal.show input:not(:disabled):not([type="button"]):not([type="submit"]):not([type="reset"]),
.modal.show select:not(:disabled),
.modal.show textarea:not(:disabled) {
    background-color: #fff !important;
    color: #212529 !important;
}

/* Butonlar için renkleri koru */
.modal.show button:not(:disabled),
.modal.show .btn:not(:disabled) {
    /* Buton renklerini koru - background-color ve color override etme */
    opacity: 1 !important;
}

/* Modal header içindeki elemanlar için renkleri koru */
.modal.show .modal-header {
    /* Header background color'ı koru - bg-primary, bg-warning gibi class'lar çalışmalı */
    opacity: 1 !important;
    pointer-events: auto !important;
}

.modal.show .modal-header * {
    /* Header içindeki tüm elemanların renklerini koru */
    opacity: 1 !important;
    pointer-events: auto !important;
}

.modal.show .modal-header .modal-title {
    /* Title rengini koru - text-white gibi class'lar çalışmalı */
    opacity: 1 !important;
    pointer-events: auto !important;
    /* Color override etme */
}

.modal.show .modal-header .btn-close,
.modal.show .modal-header .btn-close-white {
    /* Close button rengini koru */
    opacity: 0.5 !important;
    pointer-events: auto !important;
}

.modal.show .modal-header .btn-close:hover,
.modal.show .modal-header .btn-close-white:hover {
    opacity: 1 !important;
}

/* Modal footer içindeki elemanlar için renkleri koru */
.modal.show .modal-footer {
    /* Footer background color'ı koru */
    opacity: 1 !important;
    pointer-events: auto !important;
}

.modal.show .modal-footer * {
    /* Footer içindeki tüm elemanların renklerini koru */
    opacity: 1 !important;
    pointer-events: auto !important;
}

.modal.show .modal-footer .btn {
    /* Footer butonlarının renklerini koru - btn-primary, btn-secondary gibi */
    opacity: 1 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    /* Background-color ve color override etme */
}

/* Tab Navigation - Show durumunda aktif */
.modal.show .nav-tabs .nav-link {
    pointer-events: auto !important;
    opacity: 1 !important;
}

/* Close Button */
.modal.show .btn-close {
    pointer-events: auto !important;
    opacity: 0.5 !important;
}

.modal.show .btn-close:hover {
    opacity: 1 !important;
}

/* Dropdown Menüler - Z-index düzeltmesi */
.modal.show .dropdown-menu {
    z-index: 1060 !important;
}

/* Modal dialog ve content aktif olmalı - Bootstrap varsayılanı zaten bunu yapıyor ama emin olmak için */
.modal.show .modal-dialog {
    pointer-events: auto !important;
}

.modal.show .modal-content {
    pointer-events: auto !important;
}

/* Modal içindeki tüm elemanlar aktif olmalı - EN SPESİFİK SELECTOR */
/* Ama renkleri koru - sadece pointer-events ve opacity */
.modal.show .modal-content,
.modal.show .modal-dialog,
.modal.show .modal-header,
.modal.show .modal-body,
.modal.show .modal-footer,
.modal.show .nav-link,
.modal.show .tab-content,
.modal.show .tab-pane,
.modal.show label,
.modal.show a,
.modal.show .nav-tabs,
.modal.show .nav-tabs .nav-link,
.modal.show .tab-pane.active,
.modal.show .form-label,
.modal.show .alert,
.modal.show .card,
.modal.show .card-body,
.modal.show .row,
.modal.show .col,
.modal.show .col-md-4,
.modal.show .col-md-6,
.modal.show .col-md-12 {
    pointer-events: auto !important;
    opacity: 1 !important;
    cursor: auto !important;
    /* Renkleri override etme - inherit kullan */
}

/* Butonlar için özel kural - Text color'ı koru */
.modal.show button,
.modal.show .btn {
    pointer-events: auto !important;
    opacity: 1 !important;
    cursor: pointer !important;
    /* Color override etme - Bootstrap buton renklerini koru */
    color: inherit !important;
}

/* Buton içindeki icon ve text için - Beyaz yap */
.modal.show button *,
.modal.show .btn *,
.modal.show .btn i,
.modal.show button i,
.modal.show .btn span,
.modal.show button span,
.modal.show .btn::before,
.modal.show button::before,
.modal.show .btn::after,
.modal.show button::after {
    /* Renkli butonlar için beyaz text */
    color: #fff !important;
    opacity: 1 !important;
}

/* Özel buton tipleri için text rengi */
.modal.show .btn-primary,
.modal.show .btn-primary *,
.modal.show .btn-primary i,
.modal.show .btn-primary span,
.modal.show .btn-danger,
.modal.show .btn-danger *,
.modal.show .btn-danger i,
.modal.show .btn-danger span,
.modal.show .btn-success,
.modal.show .btn-success *,
.modal.show .btn-success i,
.modal.show .btn-success span,
.modal.show .btn-info,
.modal.show .btn-info *,
.modal.show .btn-info i,
.modal.show .btn-info span,
.modal.show .btn-warning,
.modal.show .btn-warning *,
.modal.show .btn-warning i,
.modal.show .btn-warning span {
    color: #fff !important;
}

/* Outline butonlar için siyah text */
.modal.show .btn-outline-primary,
.modal.show .btn-outline-primary *,
.modal.show .btn-outline-danger,
.modal.show .btn-outline-danger *,
.modal.show .btn-outline-secondary,
.modal.show .btn-outline-secondary *,
.modal.show .btn-outline-success,
.modal.show .btn-outline-success *,
.modal.show .btn-outline-info,
.modal.show .btn-outline-info *,
.modal.show .btn-outline-warning,
.modal.show .btn-outline-warning * {
    color: inherit !important; /* Outline butonlar için inherit */
}

/* Form elemanları için özel kurallar */
.modal.show input:not([type="button"]):not([type="submit"]):not([type="reset"]):not(:disabled),
.modal.show select:not(:disabled),
.modal.show textarea:not(:disabled),
.modal.show .form-control:not(:disabled),
.modal.show .form-select:not(:disabled) {
    pointer-events: auto !important;
    opacity: 1 !important;
    background-color: #fff !important;
    color: #212529 !important;
    cursor: text !important;
}

/* Butonlar için - renkleri koru */
.modal.show button:not(:disabled),
.modal.show .btn:not(:disabled) {
    pointer-events: auto !important;
    opacity: 1 !important;
    cursor: pointer !important;
    /* Background-color koru - Text color için özel kurallar var */
}

/* Renkli butonlar için beyaz text */
.modal.show button:not(:disabled):not(.btn-outline-primary):not(.btn-outline-danger):not(.btn-outline-secondary):not(.btn-outline-success):not(.btn-outline-info):not(.btn-outline-warning) *,
.modal.show .btn:not(:disabled):not(.btn-outline-primary):not(.btn-outline-danger):not(.btn-outline-secondary):not(.btn-outline-success):not(.btn-outline-info):not(.btn-outline-warning) * {
    color: #fff !important; /* Renkli butonlar için beyaz text */
    opacity: 1 !important;
}

/* Outline butonlar için inherit */
.modal.show .btn-outline-primary:not(:disabled) *,
.modal.show .btn-outline-danger:not(:disabled) *,
.modal.show .btn-outline-secondary:not(:disabled) *,
.modal.show .btn-outline-success:not(:disabled) *,
.modal.show .btn-outline-info:not(:disabled) *,
.modal.show .btn-outline-warning:not(:disabled) * {
    color: inherit !important; /* Outline butonlar için inherit */
    opacity: 1 !important;
}

/* Input ve select'ler için özel cursor - Sadece form input'ları */
.modal.show input:not([type="hidden"]):not([type="button"]):not([type="submit"]):not([type="reset"]),
.modal.show select,
.modal.show textarea {
    cursor: text !important;
}

/* Butonlar için pointer cursor - Renkleri koru */
.modal.show button:not(:disabled),
.modal.show .btn:not(:disabled),
.modal.show .nav-link,
.modal.show a {
    cursor: pointer !important;
    /* Background-color ve color override etme - Bootstrap buton renklerini koru */
}

/* Modal container'ın kendisi de aktif olmalı */
.modal.show {
    pointer-events: auto !important;
}

/* Özel modal ID'leri için */
#editModal.show,
#musteriEkleModal.show,
#viewModal.show,
#yeniKontratModal.show,
#addKiraciModal.show,
[id*="Modal"].show {
    pointer-events: auto !important;
}

#editModal.show *,
#musteriEkleModal.show *,
#viewModal.show *,
#yeniKontratModal.show *,
#addKiraciModal.show *,
[id*="Modal"].show * {
    pointer-events: auto !important;
    opacity: 1 !important;
}

/* TÜM SAYFALARDAKİ MODAL CSS'LERİNİ OVERRIDE ET */
/* Sayfa içindeki inline CSS'ler modal-fix.css'den sonra yüklendiği için !important kullanıyoruz */

/* Tüm modal backdrop'ları için - CSS Variable Override */
.modal-backdrop,
.modal-backdrop.show,
.modal-backdrop.fade,
.modal-backdrop.fade.show {
    z-index: 1050 !important;
    opacity: 0.5 !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    --bs-backdrop-opacity: 0.5 !important; /* Bootstrap variable override */
    --bs-backdrop-bg: rgba(0, 0, 0, 0.5) !important;
}

/* Tüm modal container'ları için */
.modal,
.modal.show,
.modal.fade,
.modal.fade.show {
    z-index: 1055 !important;
    pointer-events: auto !important;
}

/* Tüm modal dialog ve content'ler için - Bootstrap'ı override et */
.modal-dialog,
.modal.show .modal-dialog,
.modal.fade .modal-dialog,
.modal.fade.show .modal-dialog {
    z-index: 1055 !important;
    pointer-events: auto !important; /* Bootstrap'ın none'unu override et */
    position: relative !important;
    transform: translateZ(0) !important; /* GPU acceleration */
    will-change: transform !important;
    isolation: isolate !important; /* Yeni stacking context */
}

.modal-content,
.modal.show .modal-content,
.modal.fade .modal-content,
.modal.fade.show .modal-content {
    z-index: 1055 !important;
    pointer-events: auto !important;
    position: relative !important;
    background-color: #fff !important;
    transform: translateZ(0) !important; /* GPU acceleration */
    will-change: transform !important;
    isolation: isolate !important; /* Yeni stacking context */
}

/* Özel modal ID'leri için de aynı z-index */
#editModal,
#musteriEkleModal,
#yeniKontratModal,
#addKiraciModal,
#portfoyEkleModal,
#portfoyDuzenleModal,
#portfoyGoruntuleModal,
[id*="Modal"],
[id*="modal"] {
    z-index: 1055 !important;
    pointer-events: auto !important;
}

#editModal.show,
#musteriEkleModal.show,
#yeniKontratModal.show,
#addKiraciModal.show,
#portfoyEkleModal.show,
#portfoyDuzenleModal.show,
#portfoyGoruntuleModal.show {
    z-index: 1055 !important;
    pointer-events: auto !important;
}

#editModal.show *,
#musteriEkleModal.show *,
#yeniKontratModal.show *,
#addKiraciModal.show *,
#portfoyEkleModal.show *,
#portfoyDuzenleModal.show *,
#portfoyGoruntuleModal.show * {
    pointer-events: auto !important;
    opacity: 1 !important;
}

/* Print Media Query - Modal'ları yazdırırken gizle */
@media print {
    .modal,
    .modal-backdrop {
        display: none !important;
    }
}
