/* ============================================================
   MODAL COMPONENT
   Full-screen backdrop, centered dialog container with
   header, body, and footer sections.
   ============================================================ */

/* Overlay wrapper - hidden by default */
#modal-overlay {
    display: none;
}

#modal-overlay.modal-overlay--active {
    display: block;
}

/* Dark backdrop covering the entire viewport */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    animation: modalFadeIn 0.15s ease-out;
}

/* Dialog container */
.modal {
    background: var(--bg-card);
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.2s ease-out;
    outline: none;
}

/* Exit animation class */
.modal-backdrop--closing {
    animation: modalFadeOut 0.15s ease-in forwards;
}

.modal-backdrop--closing .modal {
    animation: modalSlideOut 0.15s ease-in forwards;
}

/* Size variants */
.modal--sm { width: 400px; }
.modal--md { width: 560px; }
.modal--lg { width: 720px; }
.modal--xl { width: 960px; }

/* Header */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
}

.modal-close-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    color: var(--gray-400);
    border-radius: 50%;
    transition: background 0.12s, color 0.12s;
}

.modal-close-btn:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

/* Body */
.modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

/* Footer */
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ----- Animations ----- */
@keyframes modalFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes modalFadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

@keyframes modalSlideOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
}

/* ----- Responsive ----- */
@media (max-width: 640px) {
    .modal--sm,
    .modal--md,
    .modal--lg,
    .modal--xl {
        width: 100%;
    }

    .modal-backdrop {
        padding: 0.5rem;
    }

    .modal-body {
        padding: 0.75rem;
    }

    .modal-footer {
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
    }
}

@media (max-width: 480px) {
    .modal-backdrop {
        padding: 0;
        align-items: flex-end;
    }

    .modal--sm,
    .modal--md,
    .modal--lg,
    .modal--xl {
        width: 100%;
        max-height: 95vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }
}
