/* ==========================================================================
   MODAL DIALOG - UNIVERSAL RESPONSIVE DIALOG SYSTEM
   Modern, uniform, glassmorphic confirmation, alert, and choice modals
   ========================================================================== */

/* Main Container & Backdrop */
.app-dialog-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 1.25rem;
    box-sizing: border-box;
}

.app-dialog-modal.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Glassmorphic Backdrop Overlay */
.app-dialog-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 15, 29, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
}

[data-theme="dark"] .app-dialog-overlay {
    background: rgba(5, 8, 18, 0.8);
}

/* Modal Card */
.app-dialog-card {
    position: relative;
    background: var(--surface, #1e293b);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
    border-radius: 22px;
    padding: 2.25rem 2rem 2rem 2rem;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.5),
                0 0 0 1px rgba(255, 255, 255, 0.06);
    transform: scale(0.92) translateY(12px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.3s ease;
    z-index: 1;
    overflow: hidden;
    box-sizing: border-box;
}

/* Colored top accent bar (brand/type indicator) */
.app-dialog-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3.5px;
    background: linear-gradient(90deg, #6366f1, #4f46e5);
    border-radius: 22px 22px 0 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.app-dialog-modal.active .app-dialog-card::before {
    opacity: 1;
}

/* Type-specific accent colors */
.app-dialog-modal:has(.app-dialog-icon-danger) .app-dialog-card::before {
    background: linear-gradient(90deg, #ef4444, #dc2626);
}
.app-dialog-modal:has(.app-dialog-icon-warning) .app-dialog-card::before {
    background: linear-gradient(90deg, #f59e0b, #d97706);
}
.app-dialog-modal:has(.app-dialog-icon-success) .app-dialog-card::before {
    background: linear-gradient(90deg, #10b981, #059669);
}
.app-dialog-modal:has(.app-dialog-icon-info) .app-dialog-card::before {
    background: linear-gradient(90deg, #6366f1, #0ea5e9);
}


/* Light Mode Overrides */
:root:not([data-theme="dark"]) .app-dialog-card,
[data-theme="light"] .app-dialog-card {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.08);
    box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

:root:not([data-theme="dark"]) .app-dialog-title,
[data-theme="light"] .app-dialog-title {
    color: #0f172a;
}

:root:not([data-theme="dark"]) .app-dialog-description,
[data-theme="light"] .app-dialog-description {
    color: #475569;
}

:root:not([data-theme="dark"]) .app-dialog-btn-cancel,
[data-theme="light"] .app-dialog-btn-cancel {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}

:root:not([data-theme="dark"]) .app-dialog-btn-cancel:hover,
[data-theme="light"] .app-dialog-btn-cancel:hover {
    background: #e2e8f0;
    color: #0f172a;
}

:root:not([data-theme="dark"]) .app-dialog-choice-btn,
[data-theme="light"] .app-dialog-choice-btn {
    background: #f8fafc;
    border-color: #e2e8f0;
}

:root:not([data-theme="dark"]) .app-dialog-choice-title,
[data-theme="light"] .app-dialog-choice-title {
    color: #0f172a;
}

:root:not([data-theme="dark"]) .app-dialog-choice-desc,
[data-theme="light"] .app-dialog-choice-desc {
    color: #64748b;
}

:root:not([data-theme="dark"]) .app-dialog-choice-btn:hover,
[data-theme="light"] .app-dialog-choice-btn:hover {
    background: rgba(99, 102, 241, 0.06);
    border-color: #6366f1;
}

:root:not([data-theme="dark"]) .app-dialog-input,
[data-theme="light"] .app-dialog-input {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #0f172a;
}

:root:not([data-theme="dark"]) .app-dialog-close-btn,
[data-theme="light"] .app-dialog-close-btn {
    color: #64748b;
}

:root:not([data-theme="dark"]) .app-dialog-close-btn:hover,
[data-theme="light"] .app-dialog-close-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #0f172a;
}

.app-dialog-card.wide {
    max-width: 540px;
}

.app-dialog-modal.active .app-dialog-card {
    transform: scale(1) translateY(0);
}

/* Header & Icon */
.app-dialog-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.app-dialog-icon-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    margin-bottom: 1.25rem;
    position: relative;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.app-dialog-modal.active .app-dialog-icon-wrapper {
    transform: scale(1);
    animation: dialogIconPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes dialogIconPop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.app-dialog-icon-wrapper svg {
    width: 32px;
    height: 32px;
    stroke-width: 2.25;
}

/* Icon Color Variants */
.app-dialog-icon-danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(220, 38, 38, 0.08));
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
}
.app-dialog-icon-danger svg { stroke: #ef4444; }

.app-dialog-icon-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.08));
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: #f59e0b;
}
.app-dialog-icon-warning svg { stroke: #f59e0b; }

.app-dialog-icon-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.08));
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #10b981;
}
.app-dialog-icon-success svg { stroke: #10b981; }

.app-dialog-icon-info {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(14, 165, 233, 0.08));
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: #6366f1;
}
.app-dialog-icon-info svg { stroke: #6366f1; }

/* Title & Description */
.app-dialog-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary, #ffffff);
    margin: 0 0 0.65rem 0;
    letter-spacing: -0.015em;
    line-height: 1.3;
}

.app-dialog-description {
    font-size: 0.925rem;
    color: var(--text-secondary, #94a3b8);
    line-height: 1.6;
    margin: 0;
    white-space: pre-line;
    word-break: break-word;
}

/* Choices List (for option selection like CSV vs JSON) */
.app-dialog-choices {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1.5rem 0;
}

.app-dialog-choice-btn {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--background, rgba(0, 0, 0, 0.15));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 14px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: inherit;
    width: 100%;
    box-sizing: border-box;
}

.app-dialog-choice-btn:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color, #6366f1);
    background: rgba(99, 102, 241, 0.08);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}

.app-dialog-choice-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-color, #6366f1);
    flex-shrink: 0;
}

.app-dialog-choice-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
}

.app-dialog-choice-info {
    flex: 1;
    min-width: 0;
}

.app-dialog-choice-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary, #ffffff);
    margin-bottom: 0.2rem;
}

.app-dialog-choice-desc {
    font-size: 0.8rem;
    color: var(--text-secondary, #94a3b8);
}

/* Prompt Input */
.app-dialog-input-group {
    margin: 1.25rem 0;
}

.app-dialog-input {
    width: 100%;
    padding: 0.85rem 1rem;
    background: var(--background, #0f172a);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.15));
    border-radius: 12px;
    font-size: 0.95rem;
    color: var(--text-primary, #ffffff);
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

.app-dialog-input:focus {
    border-color: var(--primary-color, #6366f1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Actions Footer */
.app-dialog-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.75rem;
}

.app-dialog-btn {
    flex: 1;
    padding: 0.85rem 1.35rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    min-height: 46px;
    font-family: inherit;
}

.app-dialog-btn:focus-visible {
    outline: 2px solid var(--primary-color, #6366f1);
    outline-offset: 2px;
}

/* Button Variants */
.app-dialog-btn-cancel {
    background: var(--background, rgba(0, 0, 0, 0.2));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.15));
    color: var(--text-secondary, #94a3b8);
}

.app-dialog-btn-cancel:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary, #ffffff);
    border-color: rgba(255, 255, 255, 0.25);
}

.app-dialog-btn-primary {
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.app-dialog-btn-primary:hover {
    transform: translateY(-1.5px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.app-dialog-btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.3);
}

.app-dialog-btn-danger:hover {
    transform: translateY(-1.5px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.45);
}

/* Close Button (X in top right) */
.app-dialog-close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    padding: 0.45rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0.6;
}

.app-dialog-close-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary, #ffffff);
}

.app-dialog-close-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}

/* Prevent Background Scrolling */
body.dialog-open {
    overflow: hidden !important;
}

/* Responsive Breakpoints */
@media (max-width: 640px) {
    .app-dialog-card {
        padding: 1.75rem 1.25rem 1.5rem 1.25rem;
        border-radius: 18px;
    }
    
    .app-dialog-title {
        font-size: 1.2rem;
    }
    
    .app-dialog-actions {
        flex-direction: column-reverse;
        gap: 0.6rem;
    }
    
    .app-dialog-btn {
        width: 100%;
    }
}
