﻿
/* =========================================================
   Bootstrap 3 Modal — Fixed Layout, Drag, Resize, Scrollable
   Requires: Bootstrap 3, jQuery, jQuery UI (draggable/resizable)
   ========================================================= */
/* The dialog is the thing that moves/resizes */
#modal-container .modal-dialog {
    position: fixed; /* relative to viewport */
    top: 10%; /* initial placement */
    left: 50%;
    margin: 0 !important; /* kill BS3 auto-centering */
    max-width: none !important; /* remove theme caps */
    min-width: 600px;
    box-sizing: border-box;
}

/* Center only while NOT dragging/floating/maximized */
#modal-container .modal-dialog:not(.is-maximized):not(.is-floating):not(.is-dragging) {
    transform: translateX(-50%);
}

/* Kill BS3's animated transform so it doesn't fight our rules */
#modal-container.modal.fade .modal-dialog,
#modal-container.modal.in .modal-dialog {
    -webkit-transition: none !important;
    transition: none !important;
    -webkit-transform: none !important;
    transform: none !important;
}
    /* Then re-apply our X-centering only when appropriate */
    #modal-container.modal.fade .modal-dialog:not(.is-maximized):not(.is-floating):not(.is-dragging),
    #modal-container.modal.in .modal-dialog:not(.is-maximized):not(.is-floating):not(.is-dragging) {
        -webkit-transform: translateX(-50%) !important;
        transform: translateX(-50%) !important;
    }

/* Opt-out classes once user starts dragging */
#modal-container .modal-dialog.is-floating,
#modal-container .modal-dialog.is-dragging {
    transform: none !important;
}

/* Maximized state (toggle .is-maximized on .modal-dialog) */
#modal-container .modal-dialog.is-maximized {
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    transform: none !important;
    margin: 0 !important;
}

/* ===== Panel uses flex so header/body/footer behave ===== */
#modal-container .modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100% !important;
    max-width: none !important;
    height: auto; /* dialog controls overall height */
    max-height: calc(100vh - 20px); /* safety cap when no explicit height */
    overflow: hidden; /* keep the resize handle inside */
    border-radius: 4px;
    box-sizing: border-box;
}

/* Body grows & scrolls */
#modal-container .modal-body {
    flex: 1 1 auto;
    min-height: 0; /* CRITICAL for scrolling in flex child */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    /* Neutralize inline height:100% used by some dialogs */
    height: auto !important;
}

/* Footer participates in flow */
#modal-container .modal-footer {
    flex: 0 0 auto;
    position: static;
    width: 100%;
    margin-top: 0;
    background-color: #fff;
    z-index: 1;
}

/* Header gets a grab cursor for drag handle */
#modal-container .modal-header {
    cursor: grab;
}

/* ===== jQuery-UI resize handle: keep it inside the panel ===== */
#modal-container .modal-content .ui-resizable-se {
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 16px;
    height: 16px;
    z-index: 2000;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, #bdbdbd 50%) no-repeat;
    background-size: 100% 100%;
    opacity: .85;
    pointer-events: auto;
}

/* Make sure other UI handles sit above table content if you add them */
.ui-resizable-handle {
    z-index: 2000;
}

/* ===== Support dialogs that wrap content in a <form> ===== */
/* Make the direct form inside modal-content a flex column so nested header/body/footer still lay out correctly */
#modal-container .modal-content > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    max-height: inherit;
    width: 100%;
    align-items: stretch;
    box-sizing: border-box;
}

    /* Ensure nested modal sections inside the form participate in the flex layout */
    #modal-container .modal-content > form > .modal-header {
        flex: 0 0 auto;
    }

    #modal-container .modal-content > form > .modal-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        height: auto !important; /* neutralize inline height on nested bodies too */
    }

    #modal-container .modal-content > form > .modal-footer {
        flex: 0 0 auto;
        position: static;
        width: 100%;
    }
