/* ============================================
   Overlays — Modal, Lightbox, Toast, Loading, Live Player
   ============================================ */

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-loading);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.loading-overlay:not(.hidden) {
    opacity: 1;
}

.loading-content {
    background: var(--surface);
    padding: var(--space-8);
    border-radius: var(--radius-xl);
    text-align: center;
    box-shadow: var(--shadow-xl);
    transform: scale(0.95);
    transition: transform var(--transition-base);
}

.loading-overlay:not(.hidden) .loading-content {
    transform: scale(1);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto var(--space-4);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-weight: 500;
    font-size: var(--text-base);
    color: var(--text);
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: var(--z-toast);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-sm);
    font-weight: 500;
    transform: translateX(120%);
    transition: transform var(--transition-slow);
}

.toast.show {
    transform: translateX(0);
}

.toast svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.success svg { color: var(--success); }

.toast.error { border-left: 3px solid var(--error); }
.toast.error svg { color: var(--error); }

.toast-message {
    color: var(--text);
}

/* --- History Modal --- */
.history-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-history);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.history-modal:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.history-backdrop {
    position: absolute;
    inset: 0;
    background: transparent;
}

.history-content {
    position: relative;
    width: 90vw;
    max-width: 560px;
    max-height: 70vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    transform: scale(0.95) translateY(10px);
    transition: transform var(--transition-base);
}

.history-modal:not(.hidden) .history-content {
    transform: scale(1) translateY(0);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.history-header h3 {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text);
}

.history-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.history-clear-btn {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    background: var(--error-light);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--error);
    font-size: var(--text-xs);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
}

.history-clear-btn:hover {
    background: var(--error);
    color: white;
}

.history-clear-btn svg {
    width: 14px;
    height: 14px;
}

.history-close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
}

.history-close-btn:hover {
    background: var(--border);
}

.history-close-btn svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.history-list {
    max-height: calc(70vh - 72px);
    overflow-y: auto;
    padding: var(--space-3);
}

.history-empty {
    text-align: center;
    color: var(--text-tertiary);
    padding: var(--space-8);
    font-size: var(--text-sm);
}

.history-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--surface-hover);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    margin-bottom: var(--space-2);
}

.history-item:hover {
    background: var(--border);
}

.history-cover {
    width: 72px;
    height: 54px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--border);
    position: relative;
    flex-shrink: 0;
}

.history-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-no-cover {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
}

.history-no-cover svg {
    width: 20px;
    height: 20px;
}

.history-badge {
    position: absolute;
    bottom: 3px;
    left: 3px;
    padding: 1px 5px;
    background: var(--primary);
    color: white;
    font-size: 10px;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

.history-info {
    flex: 1;
    min-width: 0;
}

.history-title {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: 2px;
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.history-platform {
    padding: 1px 6px;
    background: var(--primary-alpha);
    color: var(--primary);
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.history-author {
    color: var(--text-secondary);
}

/* --- Lightbox --- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: var(--z-lightbox);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.lightbox.active {
    opacity: 1;
    visibility: visible;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.lightbox-content {
    position: relative;
    width: 90vw;
    max-width: 900px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform var(--transition-base);
}

.lightbox.active .lightbox-content {
    transform: scale(1);
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    color: white;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-close svg {
    width: 18px;
    height: 18px;
}

.lightbox-prev,
.lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    color: white;
}

.lightbox-prev { left: -60px; }
.lightbox-next { right: -60px; }

.lightbox-prev:hover,
.lightbox-next:hover {
    background: rgba(255, 255, 255, 0.2);
}

.lightbox-prev svg,
.lightbox-next svg {
    width: 22px;
    height: 22px;
}

.lightbox-image-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.lightbox-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.lightbox-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    margin-top: var(--space-3);
}

.lightbox-counter {
    font-size: var(--text-sm);
    color: rgba(255, 255, 255, 0.8);
    font-weight: 500;
}

.lightbox-download {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    background: var(--primary);
    color: white;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: all var(--transition-base);
}

.lightbox-download:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

.lightbox-download svg {
    width: 14px;
    height: 14px;
}

/* --- Live Player Modal --- */
.live-player-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-live-player);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-base);
}

.live-player-modal.active {
    opacity: 1;
}

.live-player-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
}

.live-player-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: scale(0.95);
    transition: transform var(--transition-base);
}

.live-player-modal.active .live-player-content {
    transform: scale(1);
}

.live-player-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: all var(--transition-base);
}

.live-player-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.live-player-close svg {
    width: 18px;
    height: 18px;
}

.live-video {
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--radius-lg);
    background: #000;
}

.live-player-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: var(--space-3);
    background: linear-gradient(135deg, #FF6B6B, #FF8E53);
    color: white;
    padding: 5px 12px;
    border-radius: var(--radius-md);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* --- Responsive Overlays --- */
@media (max-width: 768px) {
    .live-player-content {
        width: 95vw;
    }

    .live-video {
        max-height: 70vh;
    }

    .lightbox-prev,
    .lightbox-next {
        width: 36px;
        height: 36px;
    }

    .lightbox-prev { left: 10px; }
    .lightbox-next { right: 10px; }

    .lightbox-content {
        width: 95vw;
        height: 90vh;
    }

    .lightbox-info {
        flex-direction: column;
        gap: var(--space-2);
    }

    .toast-container {
        bottom: var(--space-3);
        right: var(--space-3);
        left: var(--space-3);
    }

    .toast {
        width: 100%;
    }
}
