/*
 * modal.css
 * ─────────────────────────────────────────────────────────────────────────────
 * Complete modal styles for Bootstrap 4.6.2
 * Fixes:
 *   - Modal always centered in viewport regardless of scroll position
 *   - Footer never hidden behind overlay
 *   - No horizontal scrollbar in body
 *   - Vertical scroll only when content exceeds body height
 *   - Minimum 800px on large/medium screens
 *   - Full screen on tablets and mobile
 *   - Dark mode aware
 *
 * Deploy to : /include/styles/modal.css
 * Include in: /views/layout/page_foot.inc
 * ─────────────────────────────────────────────────────────────────────────────
 */


/* ══════════════════════════════════════════════════════════════
   MODAL OVERLAY — fixed to viewport, not document
   ══════════════════════════════════════════════════════════════ */

#myModal,
#fullModal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1050 !important;
    overflow: hidden !important;
}


/* ══════════════════════════════════════════════════════════════
   BACKDROP — fixed to viewport
   ══════════════════════════════════════════════════════════════ */

.modal-backdrop {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
}


/* ══════════════════════════════════════════════════════════════
   MODAL DIALOG — centered in viewport via transform
   ══════════════════════════════════════════════════════════════ */

#myModal .modal-dialog {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    margin: 0 !important;
    /* Fixed 700px on large and medium screens */
    width: 700px !important;
    min-width: 700px !important;
    max-width: 700px !important;
    /* Height */
    max-height: 90vh !important;
    /* Flex column so header/footer stay fixed and body scrolls */
    display: flex !important;
    flex-direction: column !important;
}


/* ══════════════════════════════════════════════════════════════
   MODAL CONTENT — flex column, fills dialog
   ══════════════════════════════════════════════════════════════ */

#myModal .modal-content {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    max-height: 90vh !important;
    overflow: hidden !important;
    border-radius: 8px !important;
    border: none !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35) !important;
}


/* ══════════════════════════════════════════════════════════════
   MODAL HEADER — fixed, never scrolls
   ══════════════════════════════════════════════════════════════ */

#myModal .modal-header {
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 10px 16px !important;
    border-bottom: none !important;
    border-radius: 8px 8px 0 0 !important;
}

    #myModal .modal-header .modal-title,
    #myModal .modal-header h3 {
        margin: 0 !important;
        font-size: 1rem !important;
        font-weight: 600 !important;
        color: #fff !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: calc(100% - 40px) !important;
    }

    #myModal .modal-header .close {
        color: #fff !important;
        opacity: 1 !important;
        font-size: 1.4rem !important;
        padding: 0 4px !important;
        margin: 0 !important;
        line-height: 1 !important;
        flex-shrink: 0 !important;
    }

        #myModal .modal-header .close:hover {
            opacity: 0.75 !important;
        }


/* ══════════════════════════════════════════════════════════════
   MODAL BODY — scrolls vertically when needed, no horizontal scroll
   ══════════════════════════════════════════════════════════════ */

#myModal .modal-body {
    flex: 1 1 auto !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 0 !important;
    height: auto !important;
    min-height: 200px !important;
    background: #f8f9fa !important;
    /* Scrollbar styling — thin and subtle */
    scrollbar-width: thin !important;
}

    #myModal .modal-body::-webkit-scrollbar {
        width: 5px;
    }

    #myModal .modal-body::-webkit-scrollbar-track {
        background: transparent;
    }

    #myModal .modal-body::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 3px;
    }

    /* Iframe inside body */
    #myModal .modal-body iframe {
        width: 100% !important;
        height: 100% !important;
        min-height: 420px !important;
        border: none !important;
        display: block !important;
    }


/* ══════════════════════════════════════════════════════════════
   MODAL FOOTER — fixed at bottom, always visible
   ══════════════════════════════════════════════════════════════ */

#myModal .modal-footer {
    flex-shrink: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
    padding: 10px 16px !important;
    border-top: 1px solid #dee2e6 !important;
    background: #fff !important;
    border-radius: 0 0 8px 8px !important;
    z-index: 1 !important;
}

    #myModal .modal-footer .btn {
        min-width: 80px !important;
    }


/* ══════════════════════════════════════════════════════════════
   FULL MODAL — full screen variant
   ══════════════════════════════════════════════════════════════ */

#fullModal .modal-dialog {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
    margin: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    display: flex !important;
    flex-direction: column !important;
}

#fullModal .modal-content {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
}

#fullModal .modal-header {
    flex-shrink: 0 !important;
    padding: 8px 16px !important;
}

#fullModal .modal-body {
    flex: 1 1 auto !important;
    overflow: hidden !important;
    padding: 0 !important;
}

    #fullModal .modal-body iframe {
        width: 100% !important;
        height: 100% !important;
        border: none !important;
        display: block !important;
    }


/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — tablet (768px–991px) and mobile (<768px)
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 991px) {
    #myModal .modal-dialog {
        width: 95vw !important;
        min-width: unset !important;
        max-width: 95vw !important;
        height: auto !important;
        max-height: 92vh !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
    }

    #myModal .modal-content {
        height: auto !important;
        max-height: 92vh !important;
        border-radius: 6px !important;
    }

    #myModal .modal-body {
        height: auto !important;
        max-height: calc(92vh - 110px) !important;
    }
}

@media (max-width: 767px) {
    #myModal .modal-dialog {
        width: 100vw !important;
        min-width: unset !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
    }

    #myModal .modal-content {
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }

    #myModal .modal-body {
        height: calc(100vh - 110px) !important;
        max-height: calc(100vh - 110px) !important;
    }

    #myModal .modal-header .modal-title,
    #myModal .modal-header h3 {
        font-size: .9rem !important;
    }

    #myModal .modal-footer {
        border-radius: 0 !important;
    }
}


/* ══════════════════════════════════════════════════════════════
   DARK MODE
   ══════════════════════════════════════════════════════════════ */

html.dark-mode #myModal .modal-content,
html.dark-mode #fullModal .modal-content {
    background: var(--dm-surface, #181c27) !important;
    box-shadow: 0 10px 40px rgba(0,0,0,.6) !important;
}

html.dark-mode #myModal .modal-body {
    background: var(--dm-surface, #181c27) !important;
}

    html.dark-mode #myModal .modal-body::-webkit-scrollbar-thumb {
        background: var(--dm-border, #272d3d);
    }

html.dark-mode #myModal .modal-footer {
    background: var(--dm-surface2, #1e2435) !important;
    border-color: var(--dm-border, #272d3d) !important;
}

    html.dark-mode #myModal .modal-footer .btn-default {
        background: var(--dm-surface2, #272d3d) !important;
        color: var(--dm-text, #e2e8f0) !important;
        border-color: var(--dm-border, #3a4257) !important;
    }

        html.dark-mode #myModal .modal-footer .btn-default:hover {
            background: var(--dm-surface, #181c27) !important;
        }


/* ══════════════════════════════════════════════════════════════
   ANIMATION
   ══════════════════════════════════════════════════════════════ */

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, calc(-50% - 20px));
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

/* Only animate on large screens where transform centering is active */
@media (min-width: 992px) {
    #myModal.show .modal-dialog {
        animation: modalSlideIn .2s ease;
    }
}

@keyframes modalSlideInFull {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#fullModal.show .modal-dialog {
    animation: modalSlideInFull .2s ease;
}
