/* =====================================================
   MODULE: MODALS
   Modal overlays, drawers, dialogs, dropdowns, tooltips.
   Per-theme overrides for all 5 themes.
   Toggle: modules.modals in theme-config.json
   ===================================================== */

/* ============= MODAL OVERLAY ============= */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay-bg);
    z-index: 5000;
    align-items: center;
    justify-content: center;
    animation: modal-fade-in 0.2s ease;
}
.modal-overlay.show { display: flex; }

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

/* ============= MODAL ============= */
.modal {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl, 1rem);
    padding: 1.5rem;
    max-width: 520px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    border: 2px solid var(--border-primary);
    box-shadow: var(--shadow-lg);
    animation: modal-scale-in 0.25s ease;
    position: relative;
}
.modal-accent { border-color: var(--accent); }

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

/* ============= MODAL HEADER ============= */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-primary);
}
.modal-title { font-size: var(--font-size-xl, 1.25rem); font-weight: 700; color: var(--text-primary); }
.modal-subtitle { font-size: var(--font-size-sm, 0.875rem); color: var(--text-tertiary); margin-top: 0.25rem; }
.modal-close {
    background: none; border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 1.5rem;
    padding: 0; line-height: 1;
    transition: color 0.2s ease;
}
.modal-close:hover { color: var(--text-primary); }

/* ============= MODAL BODY ============= */
.modal-body {
    margin-bottom: 1rem;
    color: var(--text-secondary);
    font-size: var(--font-size-sm, 0.875rem);
    line-height: 1.6;
}

/* ============= MODAL FOOTER ============= */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-primary);
}

/* ============= MODAL SIZES ============= */
.modal-sm { max-width: 380px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }
.modal-full { max-width: 95vw; max-height: 95vh; }

/* ============= COLOR PICKER MODAL ============= */
.modal-colors {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.625rem;
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
}
.modal-color {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm, 0.25rem);
    border: none;
    cursor: pointer;
    background: var(--bg-elevated);
    color: var(--text-primary);
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
    font-size: var(--font-size-xs, 0.75rem);
    font-weight: 700;
}
.modal-color:hover { transform: scale(1.05); box-shadow: var(--shadow-md); }
.modal-color.selected { box-shadow: var(--shadow-md), 0 0 0 3px var(--accent); }
.modal-color .color-swatch {
    width: 1rem; height: 1rem;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

/* ============= DRAWER (slide-in panel) ============= */
.drawer-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay-bg);
    z-index: 5000;
}
.drawer-overlay.show { display: block; }

.drawer {
    position: fixed;
    top: 0; right: -400px;
    width: 400px; height: 100vh;
    background: var(--bg-elevated);
    border-left: 1px solid var(--border-primary);
    box-shadow: var(--shadow-lg);
    z-index: 5001;
    padding: 1.5rem;
    overflow-y: auto;
    transition: right 0.3s ease;
}
.drawer.open { right: 0; }
.drawer-left { left: -400px; right: auto; border-left: none; border-right: 1px solid var(--border-primary); }
.drawer-left.open { left: 0; }

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-primary);
}

/* ============= CONFIRM DIALOG ============= */
.dialog { text-align: center; max-width: 400px; }
.dialog-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.dialog-message { font-size: var(--font-size-base, 1rem); color: var(--text-secondary); margin-bottom: 1.5rem; }
.dialog-actions { display: flex; gap: 0.75rem; justify-content: center; }

/* ============= POPUP (small floating) ============= */
.popup {
    position: absolute;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg, 0.75rem);
    box-shadow: var(--shadow-lg);
    padding: 0.75rem;
    z-index: 4000;
    min-width: 200px;
    animation: popup-in 0.15s ease;
}
@keyframes popup-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============= DROPDOWN MENU ============= */
.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg, 0.75rem);
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    padding: 0.375rem;
    display: none;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: var(--font-size-sm, 0.875rem);
    color: var(--text-secondary);
    border-radius: var(--radius-md, 0.5rem);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item.active { background: var(--bg-accent-subtle); color: var(--accent); }
.dropdown-divider { height: 1px; background: var(--border-primary); margin: 0.25rem 0; }

/* ============= TOOLTIP ============= */
.tooltip {
    position: absolute;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md, 0.5rem);
    padding: 0.375rem 0.625rem;
    font-size: var(--font-size-xs, 0.75rem);
    box-shadow: var(--shadow-md);
    z-index: 6000;
    white-space: nowrap;
    pointer-events: none;
    animation: popup-in 0.15s ease;
}

/* ============= LIGHT THEME ============= */
[data-theme="white-glass"] .modal {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}
[data-theme="white-glass"] .drawer { background: #ffffff; box-shadow: -4px 0 16px rgba(0, 0, 0, 0.1); }
[data-theme="white-glass"] .dropdown-menu { background: #ffffff; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); }
[data-theme="white-glass"] .tooltip { background: #1a1a1a; color: #ffffff; border: none; }
[data-theme="white-glass"] .modal-overlay { background: rgba(0, 0, 0, 0.3); }

/* ============= GLASS THEME — frosted modals ============= */
[data-theme="black-glass"] .modal {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="black-glass"] .drawer {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(16px) saturate(1.6);
    -webkit-backdrop-filter: blur(16px) saturate(1.6);
}
[data-theme="black-glass"] .dropdown-menu {
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* ============= RETRO THEME — 3D windows ============= */
[data-theme="retro"] .modal {
    background: #c0c0c0;
    border: none;
    border-radius: 0 !important;
    box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #ffffff, inset -2px -2px #808080, inset 2px 2px #dfdfdf;
    color: #000;
}
[data-theme="retro"] .modal-header {
    background: linear-gradient(90deg, #000080, #1084d0);
    color: #fff;
    padding: 0.25rem 0.5rem;
    margin: -1.5rem -1.5rem 1rem;
    border-bottom: none;
}
[data-theme="retro"] .modal-title { color: #fff; font-size: 0.875rem; }
[data-theme="retro"] .modal-close { color: #fff; }
[data-theme="retro"] .modal-body { color: #000; }
[data-theme="retro"] .drawer {
    background: #c0c0c0;
    border-radius: 0 !important;
    box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #ffffff;
}
[data-theme="retro"] .dropdown-menu {
    background: #c0c0c0;
    border-radius: 0 !important;
    box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #ffffff, inset -2px -2px #808080, inset 2px 2px #dfdfdf;
}
[data-theme="retro"] .dropdown-item { border-radius: 0 !important; }
[data-theme="retro"] .dropdown-item.active { background: #000080; color: #fff; }
[data-theme="retro"] .popup { border-radius: 0 !important; background: #c0c0c0; }
[data-theme="retro"] .tooltip { border-radius: 0 !important; background: #ffffe1; color: #000; border: 1px solid #000; }

/* ============= HOMEBREW THEME — terminal modals ============= */
[data-theme="homebrew"] .modal {
    background: rgba(10, 15, 20, 0.95);
    border: 1px solid rgba(0, 255, 0, 0.2);
    border-radius: 0 !important;
    box-shadow: 0 0 20px rgba(0, 255, 0, 0.1);
    color: #00ff00;
}
[data-theme="homebrew"] .modal-title { color: #00ff00; }
[data-theme="homebrew"] .modal-body { color: rgba(0, 255, 0, 0.7); }
[data-theme="homebrew"] .modal-close { color: rgba(0, 255, 0, 0.5); }
[data-theme="homebrew"] .modal-close:hover { color: #00ff00; }
[data-theme="homebrew"] .drawer {
    background: rgba(10, 15, 20, 0.95);
    border-color: rgba(0, 255, 0, 0.15);
    border-radius: 0 !important;
}
[data-theme="homebrew"] .dropdown-menu {
    background: rgba(10, 15, 20, 0.95);
    border: 1px solid rgba(0, 255, 0, 0.2);
    border-radius: 0 !important;
}
[data-theme="homebrew"] .dropdown-item { border-radius: 0 !important; color: rgba(0, 255, 0, 0.6); }
[data-theme="homebrew"] .dropdown-item:hover { color: #00ff00; background: rgba(0, 255, 0, 0.04); }
[data-theme="homebrew"] .dropdown-item.active { color: #00ff00; background: rgba(0, 255, 0, 0.08); }
[data-theme="homebrew"] .popup { background: rgba(10, 15, 20, 0.95); border: 1px solid rgba(0, 255, 0, 0.2); border-radius: 0 !important; }
[data-theme="homebrew"] .tooltip { background: rgba(0, 0, 0, 0.9); color: #00ff00; border: 1px solid rgba(0, 255, 0, 0.3); border-radius: 0 !important; }

/* ============= SKEUOMORPHIC THEME — raised modals ============= */
[data-theme="skeuomorphic"] .modal-content {
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2), 0 2px 8px rgba(0,0,0,0.1), inset 0 1px 0 rgba(255,255,255,0.8);
    backdrop-filter: none;
}
[data-theme="skeuomorphic"] .modal-header {
    background: linear-gradient(to bottom, #f5f0e8, #ece7df);
    border-bottom: 1px solid rgba(0,0,0,0.1);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
}
