﻿/* ========================================
   Modal Styles - Global Modal Components
   Uses theme variables from themes.css
   ======================================== */

/* Modal Backdrop */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1040;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-backdrop.fade {
    opacity: 0;
}

.modal-backdrop.show {
    opacity: 1;
}

/* Modal Container */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1050;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    outline: 0;
}

.modal.fade {
    transition: opacity 0.15s linear;
}

.modal.fade .modal-dialog {
    transition: transform 0.3s ease-out;
    transform: translate(0, -50px);
}

.modal.show .modal-dialog {
    transform: none;
}

/* Modal Dialog Sizes */
.modal-dialog {
    position: relative;
    width: auto;
    margin: 0.5rem auto;
    pointer-events: none;
    max-width: min(500px, calc(100vw - 1rem));
}

.modal-dialog-centered {
    display: flex;
    align-items: center;
    min-height: calc(100% - 1rem);
}

/* On short screens drop the centering so the modal doesn't clip at the top */
@media (max-height: 820px) {
    .modal-dialog-centered {
        align-items: flex-start;
    }
}

.modal-dialog-scrollable {
    height: calc(100% - 1rem);
}

.modal-dialog-scrollable .modal-content {
    max-height: 100%;
    overflow: hidden;
}

.modal-dialog-scrollable .modal-body {
    overflow: auto;
}

/* Modal Size Variants */
.modal-sm {
    max-width: min(300px, calc(100vw - 1rem));
}

.modal-lg {
    max-width: min(800px, calc(100vw - 1rem));
}

.modal-xl {
    max-width: min(1140px, calc(100vw - 1rem));
}

/* Find Client modal - resizable with bottom-right corner handle */
.modal-dialog.find-client-modal-dialog {
    width: min(960px, calc(100vw - 3.5rem));
    max-width: none;
    min-width: min(620px, calc(100vw - 1rem));
}

.modal-dialog.find-client-modal-dialog.find-client-modal-dialog--wide {
    width: min(1120px, calc(100vw - 2rem));
}

.modal-dialog.find-client-modal-dialog.find-client-modal-dialog--xwide {
    width: min(1320px, calc(100vw - 1rem));
}

.modal-dialog.find-client-modal-dialog .modal-content {
    resize: both;
    overflow: hidden;
    min-width: min(620px, calc(100vw - 1rem));
    min-height: 420px;
    max-width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
}

.find-client-search-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.find-client-search-row .input-group {
    flex: 1 1 auto;
}

.find-client-advanced-control {
    position: relative;
    flex: 0 0 auto;
}

.find-client-advanced-button {
    min-width: 2.25rem;
    min-height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.find-client-advanced-popover {
    position: absolute;
    top: calc(100% + 0.4rem);
    right: 0;
    width: min(320px, calc(100vw - 2rem));
    padding: 0.65rem 0.75rem;
    background-color: var(--bg-primary);
    z-index: 6;
}

@media (max-width: 768px) {
    .find-client-search-row {
        gap: 0.4rem;
    }

    .find-client-advanced-popover {
        right: -0.25rem;
        width: min(300px, calc(100vw - 1.25rem));
    }
}

@media (min-width: 576px) {
    .modal-dialog {
        max-width: min(500px, calc(100vw - 3.5rem));
        margin: 1.75rem auto;
    }

    .modal-dialog-centered {
        min-height: calc(100% - 3.5rem);
    }

    .modal-dialog-scrollable {
        height: calc(100% - 3.5rem);
    }

    .modal-sm {
        max-width: min(300px, calc(100vw - 3.5rem));
    }
}

@media (min-width: 992px) {
    .modal-lg,
    .modal-xl {
        max-width: min(800px, calc(100vw - 3.5rem));
    }
}

@media (min-width: 1200px) {
    .modal-xl {
        max-width: min(1140px, calc(100vw - 3.5rem));
    }
}

/* Modal Content */
.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-height: calc(100vh - 1rem);
    overflow: hidden;
    pointer-events: auto;
    background-color: var(--bg-primary);
    background-clip: padding-box;
    border: 1px solid var(--border-color);
    border-radius: var(--bs-border-radius);
    box-shadow: var(--shadow-lg);
    outline: 0;
}

/* Keep header/footer always visible when modal body scrolls */
.modal-content > .modal-header {
    position: sticky;
    top: 0;
    z-index: 2;
}

.modal-content > .modal-footer {
    position: sticky;
    bottom: 0;
    z-index: 2;
}

@media (min-width: 576px) {
    .modal-content {
        max-height: calc(100vh - 3.5rem);
    }
}

/* Modal Header - Global Styles
   All modal headers should use h6 for titles with minimal padding
   and themed background colors from themes.css */
.modal-header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-light);
    background-color: var(--bg-header);
    color: var(--text-header);
    border-top-left-radius: var(--bs-border-radius);
    border-top-right-radius: var(--bs-border-radius);
}

/* Modal title - use h6 for all modal headers */
.modal-header .modal-title,
.modal-header h6.modal-title,
.modal-header h5.modal-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-header);
}

.modal-header .modal-title i {
    margin-right: 0.5rem;
    vertical-align: middle;
}

/* Modal close button (X) - positioned in top right */
.modal-header .btn-close {
    padding: 0.5rem;
    margin: 0;
    margin-left: auto;
    background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ffffff'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center/0.75rem auto no-repeat;
    border: 0;
    opacity: 0.75;
    cursor: pointer;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: var(--bs-border-radius);
    transition: opacity 0.15s ease-in-out;
}

.modal-header .btn-close:hover {
    opacity: 1;
}

.modal-header .btn-close:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
    opacity: 1;
}

/* For light-colored headers, use dark X */
.modal-header.bg-light .btn-close,
.modal-header.bg-white .btn-close {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000000'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e");
}

/* Bootstrap btn-close-white compatibility */
.modal-header .btn-close-white {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23ffffff'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e");
}

/* Modal Body */
.modal-body {
    position: relative;
    flex: 1 1 auto;
    padding: 1.25rem;
    overflow-x: auto;
    overflow-y: auto;
    color: var(--text-primary);
    background-color: var(--bg-primary);
}

/* Tables/grids inside modal bodies scroll horizontally */
.modal-body .data-grid-container {
    overflow-x: auto;
    overflow-y: hidden;
}

.modal-body .data-grid {
    min-width: max-content;
}

.modal-body .alert {
    margin-bottom: 1rem;
}

.modal-body .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Modal Footer */
.modal-footer {
    display: flex;
    flex-wrap: wrap;
    flex-shrink: 0;
    align-items: center;
    justify-content: flex-end;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border-light);
    background-color: var(--bg-secondary);
    border-bottom-right-radius: var(--bs-border-radius);
    border-bottom-left-radius: var(--bs-border-radius);
    gap: 0.5rem;
}

.modal-footer > * {
    margin: 0;
}

/* Tab Navigation in Modals */
.modal-body .nav-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.modal-body .nav-tabs .nav-item {
    flex: 0 0 auto;
    margin-bottom: -2px;
}

.modal-body .nav-tabs .nav-link {
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    padding: 0.75rem 1.25rem;
    background: transparent;
    transition: all 0.2s ease;
}

.modal-body .nav-tabs .nav-link:hover {
    color: var(--bs-primary);
    border-bottom-color: var(--border-color);
}

.modal-body .nav-tabs .nav-link.active {
    color: var(--bs-primary);
    border-bottom-color: var(--bs-primary);
    font-weight: 500;
}

.modal-body .nav-tabs .nav-link i {
    margin-right: 0.5rem;
}

.modal-body .tab-pane-content {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Form Elements in Modals */
.modal-body .form-label {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.modal-body .form-control,
.modal-body .form-select {
    border-color: var(--border-color);
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.modal-body .form-control:focus,
.modal-body .form-select:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.25);
    background-color: var(--bg-primary);
}

.modal-body .form-control::placeholder {
    color: var(--text-muted);
}

.modal-body .form-text {
    color: var(--text-muted);
}

.modal-body .form-check {
    padding-left: 1.75rem;
}

.modal-body .form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0.125rem;
    cursor: pointer;
}

.modal-body .form-check-label {
    cursor: pointer;
    user-select: none;
}

/* Validation Styles */
.modal-body .is-invalid {
    border-color: var(--bs-danger);
}

.modal-body .is-valid {
    border-color: var(--bs-success);
}

.modal-body .invalid-feedback {
    color: var(--bs-danger);
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* Alert Styles in Modals */
.modal-body .alert {
    border-radius: var(--bs-border-radius);
    border: 1px solid transparent;
}

.modal-body .alert-info {
    background-color: rgba(var(--bs-info), 0.1);
    border-color: var(--bs-info);
    color: var(--text-primary);
}

.modal-body .alert-info i {
    color: var(--bs-info);
    margin-right: 0.5rem;
}

/* Responsive Adjustments */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-dialog-centered {
        min-height: calc(100% - 1rem);
    }
    
    .modal-header {
        padding: 0.5rem 0.75rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem 1rem;
    }
    
    .modal-body .nav-tabs .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    .modal-dialog.find-client-modal-dialog {
        width: calc(100vw - 1rem);
        min-width: calc(100vw - 1rem);
    }

    .modal-dialog.find-client-modal-dialog .modal-content {
        resize: none;
        min-width: auto;
        min-height: 360px;
    }
}
