/* ==========================================
   Modal System
   ========================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    animation: fadeIn 0.2s ease;
    padding: var(--spacing-md);
}

.modal-backdrop#history-backdrop {
    background: transparent;
    pointer-events: none;
    backdrop-filter: none;
    z-index: calc(var(--z-sticky) - 1);
}

.modal-backdrop#history-backdrop .history-sidebar {
    pointer-events: auto;
}

.modal-backdrop.hidden {
    display: none;
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: scaleIn 0.2s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

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

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* History Modal - Side Panel Style */
.history-modal {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    max-height: 100vh;
    width: 320px;
    max-width: 90vw;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
    animation: slideInLeft 0.3s ease;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Settings Modal */
.settings-modal {
    max-width: 500px;
}

/* YouTube Modal */
.youtube-modal {
    max-width: 900px;
    width: 100%;
    aspect-ratio: 16/9;
    padding: 0;
    background: #000;
    position: relative;
}

.modal-close-floating {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    color: white;
}

.modal-close-floating:hover {
    background: rgba(0, 0, 0, 0.7);
}

.youtube-container {
    width: 100%;
    height: 100%;
}

.youtube-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* History Sidebar Specific */
.history-sidebar {
    position: fixed;
    top: 60px;
    /* Below the header */
    left: 0;
    height: calc(100vh - 60px);
    width: 360px;
    max-width: 90vw;
    border-radius: 0;
    margin: 0;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-panel-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-glass);
    z-index: calc(var(--z-sticky) - 1);
    /* Lower than header */
}

.modal-backdrop:not(.hidden) .history-sidebar {
    transform: translateX(0);
}

.header-title-container {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.modal-icon-inline svg {
    width: 20px;
    height: 20px;
    color: var(--brand-primary);
}

/* Settings Modal Specific */
.settings-modal {
    max-width: 500px;
    width: 90%;
    border: 1px solid var(--border-glass);
    background: var(--bg-panel-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* Responsive */
@media (max-width: 480px) {
    .modal {
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .history-sidebar {
        width: 100%;
        border-radius: 0;
    }

    .modal-backdrop {
        padding: 0;
    }
}