/**
 * TXL Gen4 Design System - Modals
 * 
 * Composants de dialogues et overlays
 */

/* ============================================
   MODAL BASE
   ============================================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-4);
    overflow-x: hidden;
    overflow-y: auto;
}

.modal.is-active {
    display: flex;
}

/* ============================================
   MODAL BACKDROP
   ============================================ */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: modal-backdrop-fade-in var(--transition-base);
}

@keyframes modal-backdrop-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal.is-closing .modal-backdrop {
    animation: modal-backdrop-fade-out var(--transition-base);
}

@keyframes modal-backdrop-fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* ============================================
   MODAL DIALOG
   ============================================ */

.modal-dialog {
    position: relative;
    width: 100%;
    max-width: 32rem;
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2xl);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - var(--spacing-8));
    animation: modal-dialog-scale-in var(--transition-base);
    z-index: 1;
}

@keyframes modal-dialog-scale-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-2rem);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal.is-closing .modal-dialog {
    animation: modal-dialog-scale-out var(--transition-base);
}

@keyframes modal-dialog-scale-out {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.95) translateY(-2rem);
    }
}

/* ============================================
   MODAL SECTIONS
   ============================================ */

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-6);
    border-bottom: 1px solid var(--color-border);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
}

.modal-title {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.modal-body {
    flex: 1;
    padding: var(--spacing-6);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--spacing-3);
    padding: var(--spacing-6);
    border-top: 1px solid var(--color-border);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

/* ============================================
   MODAL CLOSE BUTTON
   ============================================ */

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    background: none;
    border: none;
    border-radius: var(--radius-base);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background-color: var(--color-neutral-100);
    color: var(--color-text-primary);
}

.modal-close:focus-visible {
    outline: 2px solid var(--color-primary-500);
    outline-offset: 2px;
}

.modal-close-icon {
    width: 1.25rem;
    height: 1.25rem;
}

/* ============================================
   MODAL SIZES
   ============================================ */

.modal-sm .modal-dialog {
    max-width: 24rem;
}

.modal-md .modal-dialog {
    max-width: 32rem;
}

.modal-lg .modal-dialog {
    max-width: 48rem;
}

.modal-xl .modal-dialog {
    max-width: 64rem;
}

.modal-fullscreen .modal-dialog {
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
    height: 100vh;
}

/* ============================================
   MODAL SCROLLABLE
   ============================================ */

.modal-scrollable .modal-dialog {
    max-height: calc(100vh - var(--spacing-8));
}

.modal-scrollable .modal-body {
    overflow-y: auto;
}

/* ============================================
   MODAL CENTERED
   ============================================ */

.modal-centered {
    align-items: center;
}

.modal-centered .modal-dialog {
    margin: auto;
}

/* ============================================
   MODAL COLORS
   ============================================ */

.modal-primary .modal-header {
    background-color: var(--color-primary-500);
    color: var(--color-neutral-0);
    border-bottom-color: var(--color-primary-600);
}

.modal-primary .modal-title {
    color: var(--color-neutral-0);
}

.modal-primary .modal-close {
    color: var(--color-neutral-0);
}

.modal-primary .modal-close:hover {
    background-color: var(--color-primary-600);
}

.modal-success .modal-header {
    background-color: var(--color-success-500);
    color: var(--color-neutral-0);
    border-bottom-color: var(--color-success-600);
}

.modal-success .modal-title {
    color: var(--color-neutral-0);
}

.modal-success .modal-close {
    color: var(--color-neutral-0);
}

.modal-success .modal-close:hover {
    background-color: var(--color-success-600);
}

.modal-warning .modal-header {
    background-color: var(--color-warning-500);
    color: var(--color-neutral-900);
    border-bottom-color: var(--color-warning-600);
}

.modal-warning .modal-title {
    color: var(--color-neutral-900);
}

.modal-warning .modal-close {
    color: var(--color-neutral-900);
}

.modal-warning .modal-close:hover {
    background-color: var(--color-warning-600);
}

.modal-error .modal-header {
    background-color: var(--color-error-500);
    color: var(--color-neutral-0);
    border-bottom-color: var(--color-error-600);
}

.modal-error .modal-title {
    color: var(--color-neutral-0);
}

.modal-error .modal-close {
    color: var(--color-neutral-0);
}

.modal-error .modal-close:hover {
    background-color: var(--color-error-600);
}

/* ============================================
   MODAL CONFIRMATION
   ============================================ */

.modal-confirm .modal-body {
    text-align: center;
    padding: var(--spacing-8);
}

.modal-confirm-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    margin-bottom: var(--spacing-4);
    border-radius: var(--radius-full);
    font-size: var(--font-size-2xl);
}

.modal-confirm-icon.icon-success {
    background-color: var(--color-success-100);
    color: var(--color-success-600);
}

.modal-confirm-icon.icon-warning {
    background-color: var(--color-warning-100);
    color: var(--color-warning-600);
}

.modal-confirm-icon.icon-error {
    background-color: var(--color-error-100);
    color: var(--color-error-600);
}

.modal-confirm-icon.icon-info {
    background-color: var(--color-info-100);
    color: var(--color-info-600);
}

.modal-confirm-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--spacing-2);
}

.modal-confirm-message {
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-6);
}

/* ============================================
   MODAL LOADING
   ============================================ */

.modal-loading .modal-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-8);
    min-height: 10rem;
}

.modal-loading-spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid var(--color-neutral-200);
    border-top-color: var(--color-primary-500);
    border-radius: var(--radius-full);
    animation: modal-loading-spin 0.8s linear infinite;
}

@keyframes modal-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

.modal-loading-text {
    margin-top: var(--spacing-4);
    color: var(--color-text-secondary);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 767px) {
    .modal {
        padding: 0;
    }
    
    .modal-dialog {
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        max-height: 100vh;
    }
    
    .modal-sm .modal-dialog,
    .modal-md .modal-dialog,
    .modal-lg .modal-dialog,
    .modal-xl .modal-dialog {
        max-width: 100%;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: var(--spacing-4);
    }
}
