/*
 * Modal Fixes - Tüm Bootstrap modallar için
 * - Mobilde ekranı taşımama (üst/alt boşluk, max-height)
 * - İçerik uzunsa scroll (modal-body)
 * - Sticky header (z-index 9999) üstünde görünsün
 * - Hesabım: Yeni adres / Fatura adresi modalları dahil
 */

/* ========== Z-index: Sticky header üstünde ========== */
/* Sticky header .sticky-bar.sticky = 9999; modal her zaman onun üstünde olmalı */
.modal-backdrop {
    z-index: 10040 !important;
}
.modal {
    z-index: 10050 !important;
}

/* ========== Genel: Tüm modallar ========== */
.modal {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.modal-dialog {
    margin: 1rem auto;
    max-width: calc(100% - 2rem);
}

.modal-content {
    max-height: none; /* Alt kuralda sınırlanacak */
}

.modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: none;
}

/* ========== Mobil / Küçük ekran ========== */
@media (max-width: 991px) {
    /* Modal tam ekran overlay: sticky header dahil üstte kalır (z-index yukarıda) */
    /* Modal ekrandan taşmasın: üst-alt boşluk + max-height */
    .modal {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
        padding-top: max(0.5rem, env(safe-area-inset-top)) !important;
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom)) !important;
        align-items: flex-start;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        /* Dokunmatik cihazlarda kaydırma */
        touch-action: pan-y;
    }

    .modal.show .modal-dialog {
        margin-top: 0.5rem;
        margin-bottom: 0.5rem;
        margin-top: max(0.5rem, env(safe-area-inset-top));
        margin-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }

    /* custom-modal: masaüstündeki ortalamayı kaldır, mobilde üstten hizala */
    .custom-modal .modal-dialog {
        top: auto !important;
        -webkit-transform: none !important;
        transform: none !important;
    }

    /* Dialog yüksekliği viewport'u aşmasın; içerik scroll olsun */
    .modal-dialog {
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - 2rem);
        max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem);
        display: flex;
        flex-direction: column;
        margin-left: 0.5rem;
        margin-right: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-content {
        max-height: 100%;
        display: flex;
        flex-direction: column;
        border-radius: 16px;
        overflow: hidden;
    }

    .modal-header {
        flex-shrink: 0;
    }

    .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
    }

    .modal-footer {
        flex-shrink: 0;
    }
}

/* ========== Çok küçük ekran (telefon) ========== */
@media (max-width: 576px) {
    .modal {
        padding-top: 0.25rem !important;
        padding-bottom: 0.25rem !important;
        padding-top: max(0.25rem, env(safe-area-inset-top)) !important;
        padding-bottom: max(0.25rem, env(safe-area-inset-bottom)) !important;
    }

    .modal-dialog {
        max-height: calc(100vh - 0.5rem);
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 0.5rem);
        margin-left: 0.25rem;
        margin-right: 0.25rem;
        max-width: calc(100% - 0.5rem);
    }

    /* custom-modal (adres, yorum, stok vb.) içerik padding mobilde */
    .custom-modal .modal-dialog .modal-content {
        padding: 1rem !important;
    }

    .custom-modal .modal-dialog .btn-close {
        right: 1rem !important;
        top: 1rem !important;
    }
}

/* ========== Hesabım: Adres / Fatura adresi modalları ========== */
.addres-update-modal .modal-dialog,
.addres-invoice-update-modal .modal-dialog {
    max-width: 520px;
}

@media (max-width: 991px) {
    .addres-update-modal .modal-body,
    .addres-invoice-update-modal .modal-body {
        padding: 1rem;
    }

    .addres-update-modal .modal_addres_body .form-group,
    .addres-invoice-update-modal .modal_invoice_addres_body .form-group {
        margin-bottom: 0.75rem;
    }
}

/* ========== KVKK / Gizlilik (uzun metin) ========== */
#kvkkModal .modal-dialog,
#privacyModal .modal-dialog {
    max-width: 600px;
}

@media (max-width: 991px) {
    #kvkkModal .modal-body,
    #privacyModal .modal-body {
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========== Yorumlar modal ========== */
#commentsModal .modal-body,
#modalCommentsContent {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 991px) {
    #commentsModal .modal-dialog {
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem);
    }
}

/* ========== Sipariş takip modal ========== */
#trackingModal .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 991px) {
    #trackingModal .modal-dialog {
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem);
    }
}

/* ========== 3D / Ürün modal ========== */
#div-3d .modal-dialog {
    max-width: 95vw;
}

@media (max-width: 991px) {
    #div-3d .modal-dialog {
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem);
    }

    #div-3d .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========== SMS / Mail doğrulama modalları ========== */
#smsModal .modal-body,
#mailModal .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ========== İptal / İade modal (Hesabım) ========== */
#cancelOrderModal .modal-body,
#orderInfoModal .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 991px) {
    #cancelOrderModal .modal-dialog,
    #orderInfoModal .modal-dialog {
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem);
    }
}

/* ========== Stok modal (ürün kutusu) ========== */
.product-stock-modal .modal-dialog {
    max-width: 90%;
}

/* ========== Fiyat alarmı modal ========== */
#priceAlertModal .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 991px) {
    #priceAlertModal .modal-dialog {
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem);
    }
}

/* ========== Cookie modal (zaten özel yapı) ========== */
#cookie-modal {
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 576px) {
    #cookie-modal {
        max-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 1rem);
    }
}
