/* ═══════════════════════════════════════════════════════════════════
   MODALS — Modal overlay and panel styles
   ═══════════════════════════════════════════════════════════════════
   Purpose: Consistent modal dialogs with animations, all sizes,
   and responsive behavior. No pure white (#FFFFFF), no pure
   black (#000000).
   ═══════════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════════
   MODAL OVERLAY
   ═══════════════════════════════════════════════════════════════════ */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 1000);
    background: var(--bg-overlay, rgba(26, 20, 16, 0.45));
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--lg, 24px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

[data-theme="dark"] .modal-overlay {
    background: rgba(10, 8, 6, 0.65);
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════
   MODAL PANEL
   ═══════════════════════════════════════════════════════════════════ */

.modal {
    background: var(--bg-card, #fcfaf8);
    border-radius: var(--r-xl, 18px);
    border: 1px solid var(--border-light, #e8e0d8);
    box-shadow: var(--shadow-xl, 0 20px 60px rgba(10, 8, 6, 0.20));
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideUp 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: hidden;
}

[data-theme="dark"] .modal {
    background: var(--bg-card, #241d18);
    border-color: rgba(240, 235, 230, 0.06);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.40);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ═══════════════════════════════════════════════════════════════════
   MODAL SIZES
   ═══════════════════════════════════════════════════════════════════ */

.modal-xs {
    max-width: 320px;
}

.modal-sm {
    max-width: 420px;
}

.modal-md {
    max-width: 560px;
}

.modal-lg {
    max-width: 720px;
}

.modal-xl {
    max-width: 920px;
}

.modal-full {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   MODAL HEADER
   ═══════════════════════════════════════════════════════════════════ */

.modal-header {
    padding: var(--lg, 24px) var(--lg, 24px);
    border-bottom: 1px solid var(--border-light, #e8e0d8);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sm, 8px);
    flex-shrink: 0;
}

[data-theme="dark"] .modal-header {
    border-bottom-color: rgba(240, 235, 230, 0.06);
}

.modal-header h2,
.modal-header h3,
.modal-header h4 {
    margin: 0;
    color: var(--text-dark, #1a1410);
    font-family: 'Syne', 'Playfair Display', serif;
    display: flex;
    align-items: center;
    gap: var(--sm, 8px);
}

[data-theme="dark"] .modal-header h2,
[data-theme="dark"] .modal-header h3,
[data-theme="dark"] .modal-header h4 {
    color: var(--text-dark, #f0ebe6);
}

.modal-header .modal-title-icon {
    font-size: 1.2rem;
    color: var(--role-primary, #2d1f3a);
}

[data-theme="dark"] .modal-header .modal-title-icon {
    color: var(--role-primary, #4d2f4a);
}

.modal-header .modal-subtitle {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted, #a8988e);
    margin-left: 4px;
}

[data-theme="dark"] .modal-header .modal-subtitle {
    color: var(--text-muted, #6b5f56);
}

/* ─── Close Button ────────────────────────────────────────────────── */

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-muted, #a8988e);
    transition: all var(--transition-fast, 0.15s ease);
    padding: var(--xs, 4px);
    border-radius: var(--r-sm, 6px);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

[data-theme="dark"] .modal-close {
    color: var(--text-muted, #6b5f56);
}

.modal-close:hover {
    color: var(--text-body, #2c241e);
    background: var(--bg-hover, #f5f0eb);
}

[data-theme="dark"] .modal-close:hover {
    color: var(--text-body, #d4ccc6);
    background: rgba(240, 235, 230, 0.04);
}

.modal-close:active {
    transform: scale(0.92);
}

/* ═══════════════════════════════════════════════════════════════════
   MODAL BODY
   ═══════════════════════════════════════════════════════════════════ */

.modal-body {
    padding: var(--lg, 24px);
    overflow-y: auto;
    flex: 1;
    color: var(--text-body, #2c241e);
}

[data-theme="dark"] .modal-body {
    color: var(--text-body, #d4ccc6);
}

.modal-body p:last-child {
    margin-bottom: 0;
}

/* ─── Scrollbar Styling ───────────────────────────────────────────── */

.modal-body::-webkit-scrollbar {
    width: 4px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-medium, #d4c8be);
    border-radius: var(--r-full, 9999px);
}

[data-theme="dark"] .modal-body::-webkit-scrollbar-thumb {
    background: var(--border-medium, #4a3d35);
}

/* ═══════════════════════════════════════════════════════════════════
   MODAL FOOTER
   ═══════════════════════════════════════════════════════════════════ */

.modal-footer {
    padding: var(--md, 16px) var(--lg, 24px);
    border-top: 1px solid var(--border-light, #e8e0d8);
    display: flex;
    justify-content: flex-end;
    gap: var(--sm, 8px);
    flex-shrink: 0;
    flex-wrap: wrap;
}

[data-theme="dark"] .modal-footer {
    border-top-color: rgba(240, 235, 230, 0.06);
}

.modal-footer .btn {
    min-width: 80px;
}

.modal-footer .btn:last-child {
    margin-left: 0;
}

.modal-footer .btn-ghost {
    color: var(--text-muted, #a8988e);
}

[data-theme="dark"] .modal-footer .btn-ghost {
    color: var(--text-muted, #6b5f56);
}

.modal-footer .btn-ghost:hover {
    color: var(--text-body, #2c241e);
    background: var(--bg-hover, #f5f0eb);
}

[data-theme="dark"] .modal-footer .btn-ghost:hover {
    color: var(--text-body, #d4ccc6);
    background: rgba(240, 235, 230, 0.04);
}

/* ─── Footer with Left Action ────────────────────────────────────── */

.modal-footer.has-left {
    justify-content: space-between;
}

.modal-footer .footer-left {
    display: flex;
    align-items: center;
    gap: var(--sm, 8px);
    color: var(--text-muted, #a8988e);
    font-size: 0.78rem;
}

[data-theme="dark"] .modal-footer .footer-left {
    color: var(--text-muted, #6b5f56);
}

/* ═══════════════════════════════════════════════════════════════════
   MODAL — Full Screen (Mobile)
   ═══════════════════════════════════════════════════════════════════ */

.modal-fullscreen {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    animation: modalFullscreenIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes modalFullscreenIn {
    from {
        opacity: 0;
        transform: scale(0.97);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ═══════════════════════════════════════════════════════════════════
   CONFIRM DIALOG — Special variant for confirm() replacements
   ═══════════════════════════════════════════════════════════════════ */

.modal-confirm .modal-body {
    text-align: center;
    padding: var(--xl, 32px) var(--lg, 24px);
}

.modal-confirm .modal-body .confirm-icon {
    font-size: 3rem;
    margin-bottom: var(--md, 16px);
    display: block;
}

.modal-confirm .modal-body .confirm-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-dark, #1a1410);
    margin-bottom: var(--sm, 8px);
}

[data-theme="dark"] .modal-confirm .modal-body .confirm-title {
    color: var(--text-dark, #f0ebe6);
}

.modal-confirm .modal-body .confirm-message {
    color: var(--text-soft, #6b5f56);
    max-width: 400px;
    margin: 0 auto;
}

[data-theme="dark"] .modal-confirm .modal-body .confirm-message {
    color: var(--text-soft, #9a8e86);
}

.modal-confirm .modal-footer {
    justify-content: center;
    gap: var(--md, 16px);
}

.modal-confirm .modal-footer .btn {
    min-width: 100px;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    .modal-xl {
        max-width: 90vw;
    }
}

@media (max-width: 768px) {
    .modal-overlay {
        padding: var(--md, 16px);
        align-items: flex-end;
    }

    .modal {
        border-radius: var(--r-xl, 18px) var(--r-xl, 18px) 0 0;
        max-height: 85vh;
        animation: modalSlideUpMobile 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    }

    @keyframes modalSlideUpMobile {
        from {
            opacity: 0;
            transform: translateY(30px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .modal-header {
        padding: var(--md, 16px);
    }

    .modal-header h2,
    .modal-header h3 {
        font-size: 1.1rem;
    }

    .modal-body {
        padding: var(--md, 16px);
    }

    .modal-footer {
        padding: var(--sm, 8px) var(--md, 16px);
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: 60px;
        justify-content: center;
    }

    .modal-footer.has-left {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .modal-footer .footer-left {
        justify-content: center;
        padding-top: var(--sm, 8px);
        border-top: 1px solid var(--border-light, #e8e0d8);
    }

    [data-theme="dark"] .modal-footer .footer-left {
        border-top-color: rgba(240, 235, 230, 0.06);
    }

    .modal-xs,
    .modal-sm,
    .modal-md,
    .modal-lg,
    .modal-xl {
        max-width: 100%;
    }

    .modal-confirm .modal-body {
        padding: var(--lg, 24px) var(--md, 16px);
    }

    .modal-confirm .modal-body .confirm-icon {
        font-size: 2.5rem;
    }

    .modal-confirm .modal-body .confirm-title {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .modal {
        max-width: 100%;
        max-height: 92vh;
        border-radius: var(--r-xl, 18px) var(--r-xl, 18px) 0 0;
        margin: 0;
    }

    .modal-full {
        max-height: 100vh;
        border-radius: 0;
    }

    .modal-header {
        padding: var(--sm, 8px) var(--md, 16px);
    }

    .modal-header h2,
    .modal-header h3 {
        font-size: 0.95rem;
    }

    .modal-header .modal-subtitle {
        font-size: 0.65rem;
    }

    .modal-body {
        padding: var(--sm, 8px) var(--md, 16px);
        font-size: 0.875rem;
    }

    .modal-footer {
        padding: var(--xs, 4px) var(--md, 16px);
        gap: var(--xs, 4px);
    }

    .modal-footer .btn {
        font-size: 0.78rem;
        padding: 6px 12px;
        min-height: 32px;
    }

    .modal-close {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }

    .modal-confirm .modal-body .confirm-icon {
        font-size: 2rem;
    }

    .modal-confirm .modal-body .confirm-title {
        font-size: 0.9rem;
    }

    .modal-confirm .modal-body .confirm-message {
        font-size: 0.82rem;
    }

    .modal-confirm .modal-footer .btn {
        min-width: 80px;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    .modal {
        animation: none;
    }

    .modal-fullscreen {
        animation: none;
    }

    .modal-overlay {
        transition: none;
    }
}