/* TD.UI.Components - Shared CSS for reusable components */

/* =============================================================================
   CUSTOM OVERLAY - Alternative to Bootstrap Modal
   Used when opening a picker from within an offcanvas to avoid focus trap conflicts
   ============================================================================= */

/* Backdrop - covers the entire viewport */
.td-overlay-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1070;
}

/* Panel - centered dialog */
.td-overlay-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1080;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

/* Large panel variant - taller for content like flight search */
.td-overlay-panel-lg {
    max-height: 90vh;
    max-width: 600px;
}

/* Extra large panel variant - for rich content */
.td-overlay-panel-xl {
    max-height: 95vh;
    min-height: 600px;
    max-width: 900px;
}

/* Ensure overlay body has enough height for dropdowns */
.td-overlay-panel-xl .td-overlay-body {
    min-height: 450px;
}

/* Content wrapper */
.td-overlay-content {
    background: var(--bs-modal-bg, var(--bs-body-bg, #fff));
    color: var(--bs-modal-color, var(--bs-body-color, #212529));
    border-radius: 0.5rem;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
}

/* Header */
.td-overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--bs-modal-header-border-color, var(--bs-border-color, #dee2e6));
    background: var(--bs-modal-header-bg, transparent);
}

.td-overlay-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--bs-modal-title-color, inherit);
}

/* Body - scrollable */
.td-overlay-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
    background: var(--bs-modal-bg, var(--bs-body-bg, #fff));
}

/* Footer */
.td-overlay-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--bs-modal-footer-border-color, var(--bs-border-color, #dee2e6));
    background: var(--bs-modal-footer-bg, transparent);
}

/* Dark mode support - explicit dark colors when data-bs-theme="dark" is on html */
html[data-bs-theme="dark"] .td-overlay-content,
[data-bs-theme="dark"] .td-overlay-content,
[data-theme="dark"] .td-overlay-content,
.dark .td-overlay-content {
    background: #1e1e2d !important;
    color: #9899ac !important;
}

html[data-bs-theme="dark"] .td-overlay-header,
[data-bs-theme="dark"] .td-overlay-header,
[data-theme="dark"] .td-overlay-header,
.dark .td-overlay-header {
    border-bottom-color: #2b2b40 !important;
    background: #1e1e2d !important;
}

html[data-bs-theme="dark"] .td-overlay-body,
[data-bs-theme="dark"] .td-overlay-body,
[data-theme="dark"] .td-overlay-body,
.dark .td-overlay-body {
    background: #1e1e2d !important;
    color: #9899ac !important;
}

html[data-bs-theme="dark"] .td-overlay-footer,
[data-bs-theme="dark"] .td-overlay-footer,
[data-theme="dark"] .td-overlay-footer,
.dark .td-overlay-footer {
    border-top-color: #2b2b40 !important;
    background: #1e1e2d !important;
}

html[data-bs-theme="dark"] .td-overlay-title,
[data-bs-theme="dark"] .td-overlay-title,
[data-theme="dark"] .td-overlay-title,
.dark .td-overlay-title {
    color: #ffffff !important;
}

/* Dark mode form controls inside overlay */
html[data-bs-theme="dark"] .td-overlay-content .form-control,
html[data-bs-theme="dark"] .td-overlay-content .form-select {
    background-color: #1b1b29 !important;
    border-color: #2b2b40 !important;
    color: #9899ac !important;
}

html[data-bs-theme="dark"] .td-overlay-content .form-label {
    color: #9899ac !important;
}

html[data-bs-theme="dark"] .td-overlay-content .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* =============================================================================
   LEGACY: Bootstrap Modal z-index fixes (kept for backwards compatibility)
   ============================================================================= */

/* Modal that needs to appear above offcanvas */
.modal.td-modal-above-offcanvas,
.modal[data-td-above-offcanvas="true"] {
    z-index: 1080 !important;
}

.modal.td-modal-above-offcanvas .modal-dialog,
.modal[data-td-above-offcanvas="true"] .modal-dialog {
    z-index: 1081 !important;
}

.modal.td-modal-above-offcanvas .modal-content,
.modal[data-td-above-offcanvas="true"] .modal-content {
    position: relative;
    z-index: 1082 !important;
}

body.modal-open .modal-backdrop {
    z-index: 1070 !important;
}

.modal-backdrop.show {
    z-index: 1070 !important;
}

.modal-backdrop.td-backdrop-above-offcanvas {
    z-index: 1070 !important;
}

/* =============================================================================
   SweetAlert2 High Z-Index
   Used when SweetAlert needs to appear above td-overlay-panel (e.g., flight picker)
   ============================================================================= */
.swal-high-z-index {
    z-index: 1100 !important;
}

.swal2-container.swal2-backdrop-show {
    z-index: 1099 !important;
}

/* When swal-high-z-index is used, ensure the container is also elevated */
.swal2-container:has(.swal-high-z-index) {
    z-index: 1099 !important;
}

/* =============================================================================
   CSS Custom Properties
   ============================================================================= */
:root {
    --td-overlay-backdrop-z: 1070;
    --td-overlay-panel-z: 1080;
    --td-swal-high-z: 1100;
}
