/* =============================================
   MEDIA PANEL — Panel Multimedia Inteligente
   Mentor de Méritos
   
   Estrategia:
   - PC: sidebar derecho 340px (tipo DevTools)
   - Móvil video: panel inferior 40vh
   - Móvil audio: barra mini 60px
   - Simulacro: botón flotante "Continuar"
   ============================================= */

/* ── CSS Variables ── */
:root {
    --mp-sidebar-w: 340px;
    --mp-mini-h: 64px;
    --mp-bottom-h: 40vh;
    --mp-bg: rgba(15, 23, 42, 0.97);
    --mp-bg-solid: #0f172a;
    --mp-card: rgba(30, 41, 59, 0.9);
    --mp-border: rgba(71, 85, 105, 0.4);
    --mp-accent: #7c3aed;
    --mp-accent-light: rgba(124, 58, 237, 0.15);
    --mp-text: #e2e8f0;
    --mp-text-muted: #94a3b8;
    --mp-radius: 16px;
    --mp-transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Body adjustments when panel active ── */
body.mp-sidebar-active {
    margin-right: var(--mp-sidebar-w) !important;
    transition: margin-right var(--mp-transition);
}
body.mp-mini-active {
    padding-bottom: calc(var(--mp-mini-h) + 8px) !important;
    transition: padding-bottom var(--mp-transition);
}
body.mp-bottom-active {
    padding-bottom: calc(var(--mp-bottom-h) + 8px) !important;
    transition: padding-bottom var(--mp-transition);
}

/* =============================================
   SIDEBAR (PC — right panel like DevTools)
   ============================================= */
.mp-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--mp-sidebar-w);
    height: 100vh;
    background: var(--mp-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--mp-border);
    z-index: 9990;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--mp-transition);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}
.mp-sidebar.mp-visible {
    transform: translateX(0);
}

/* Sidebar header */
.mp-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--mp-border);
    flex-shrink: 0;
}
.mp-sidebar-header h3 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--mp-text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Close button */
.mp-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
}
.mp-close:hover {
    background: #ef4444;
    color: white;
    transform: scale(1.05);
}

/* Media container (video iframe / audio visualizer) */
.mp-media-container {
    padding: 12px;
    flex-shrink: 0;
}
.mp-video-wrap {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    border-radius: 12px;
    background: #000;
}
.mp-video-wrap iframe {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* Audio visualizer placeholder */
.mp-audio-viz {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    border-radius: 12px;
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    position: relative;
    overflow: hidden;
}
.mp-audio-viz::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 30% 50%, rgba(124, 58, 237, 0.3), transparent 60%);
}
.mp-audio-icon {
    font-size: 2.5rem;
    z-index: 1;
    animation: mp-pulse 2s ease-in-out infinite;
}
@keyframes mp-pulse {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* Now playing info */
.mp-now-playing {
    padding: 12px 18px;
    flex-shrink: 0;
}
.mp-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--mp-text);
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mp-description {
    font-size: 0.75rem;
    color: var(--mp-text-muted);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Progress bar */
.mp-progress-wrap {
    padding: 0 18px;
    flex-shrink: 0;
}
.mp-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(100, 116, 139, 0.3);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.mp-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--mp-accent), #a78bfa);
    border-radius: 3px;
    transition: width 0.3s linear;
    width: 0%;
}
.mp-time-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--mp-text-muted);
    margin-top: 6px;
}

/* Controls */
.mp-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 18px;
    flex-shrink: 0;
}
.mp-btn {
    background: none;
    border: none;
    color: var(--mp-text);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mp-btn:hover {
    background: var(--mp-accent-light);
    color: var(--mp-accent);
}
.mp-btn-play {
    width: 48px;
    height: 48px;
    background: var(--mp-accent);
    color: white;
    font-size: 1.4rem;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.4);
}
.mp-btn-play:hover {
    background: #6d28d9;
    color: white;
    transform: scale(1.08);
}

/* Speed control */
.mp-speed {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 4px 18px 12px;
    flex-shrink: 0;
}
.mp-speed-btn {
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--mp-border);
    background: transparent;
    color: var(--mp-text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.mp-speed-btn.active {
    background: var(--mp-accent);
    color: white;
    border-color: var(--mp-accent);
}
.mp-speed-btn:hover:not(.active) {
    border-color: var(--mp-accent);
    color: var(--mp-accent);
}

/* Playlist */
.mp-playlist {
    flex: 1;
    overflow-y: auto;
    border-top: 1px solid var(--mp-border);
    scrollbar-width: thin;
    scrollbar-color: var(--mp-border) transparent;
}
.mp-playlist-header {
    padding: 12px 18px 8px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--mp-text-muted);
}
.mp-playlist-group-header {
    padding: 10px 18px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--mp-accent);
    background: rgba(124, 58, 237, 0.06);
    border-top: 1px solid var(--mp-border);
    border-bottom: 1px solid rgba(51, 65, 85, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 6px;
}
.mp-playlist-group-header::before {
    content: '📚';
    font-size: 0.75rem;
}
.mp-playlist-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}
.mp-playlist-item:hover {
    background: rgba(124, 58, 237, 0.08);
}
.mp-playlist-item.active {
    background: var(--mp-accent-light);
}
.mp-playlist-item-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}
.mp-playlist-item-title {
    font-size: 0.8rem;
    color: var(--mp-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.mp-playlist-item.active .mp-playlist-item-title {
    color: var(--mp-accent);
    font-weight: 600;
}
.mp-playlist-item-check {
    font-size: 0.8rem;
    color: #10b981;
    flex-shrink: 0;
}

/* =============================================
   MINI BAR (móvil audio — bottom bar 64px)
   ============================================= */
.mp-mini {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mp-mini-h);
    background: var(--mp-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--mp-border);
    z-index: 9990;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 10px;
    transform: translateY(100%);
    transition: transform var(--mp-transition);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mp-mini.mp-visible {
    transform: translateY(0);
}

/* Mini progress bar (top of mini bar) */
.mp-mini-progress {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(100, 116, 139, 0.2);
}
.mp-mini-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--mp-accent), #a78bfa);
    transition: width 0.5s linear;
    width: 0%;
}

.mp-mini-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}
.mp-mini-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}
.mp-mini-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--mp-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mp-mini-time {
    font-size: 0.65rem;
    color: var(--mp-text-muted);
}
.mp-mini-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.mp-mini-btn {
    background: none;
    border: none;
    color: var(--mp-text);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: 50%;
    transition: all 0.15s;
}
.mp-mini-btn:hover {
    background: var(--mp-accent-light);
}
.mp-mini-btn-play {
    width: 36px;
    height: 36px;
    background: var(--mp-accent);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* =============================================
   BOTTOM PANEL (móvil video — 40vh)
   ============================================= */
.mp-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mp-bottom-h);
    background: var(--mp-bg-solid);
    border-top: 1px solid var(--mp-border);
    z-index: 9990;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform var(--mp-transition);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mp-bottom.mp-visible {
    transform: translateY(0);
}

.mp-bottom-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--mp-border);
}
.mp-bottom-header h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--mp-text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mp-bottom-media {
    flex: 1;
    min-height: 0;
    padding: 8px;
}
.mp-bottom-media .mp-video-wrap {
    height: 100%;
    padding-bottom: 0;
}
.mp-bottom-media .mp-video-wrap iframe {
    position: relative;
    width: 100%;
    height: 100%;
}

/* =============================================
   SIMULACRO ADAPTATIONS
   ============================================= */

/* Reduce answer spacing when media panel is active on mobile */
@media (max-width: 768px) {
    body.mp-mini-active .space-y-3 > * + *,
    body.mp-mini-active .space-y-4 > * + * {
        margin-top: 0.5rem !important;
    }
    body.mp-bottom-active .space-y-3 > * + *,
    body.mp-bottom-active .space-y-4 > * + * {
        margin-top: 0.5rem !important;
    }
}

/* Floating "Continue" arrow for simulacro — right edge, vertically centered */
.mp-fab-next {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%) translateX(100%);
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    color: white;
    border: none;
    border-radius: 50% 0 0 50%;
    cursor: pointer;
    box-shadow: -3px 0 16px rgba(99, 102, 241, 0.5);
    z-index: 9991;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0 0 2px;
}
.mp-fab-next.mp-visible {
    transform: translateY(-50%) translateX(0);
}
.mp-fab-next:hover {
    width: 52px;
    box-shadow: -5px 0 24px rgba(99, 102, 241, 0.6);
}
.mp-fab-next::after {
    content: '▶';
    font-size: 1.2rem;
}

/* Hidden audio element */
.mp-audio-hidden {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 1024px) {
    /* On tablets and below, sidebar becomes bottom panel */
    body.mp-sidebar-active {
        margin-right: 0 !important;
        padding-bottom: calc(var(--mp-bottom-h) + 8px) !important;
    }
}

/* =============================================
   ANIMATIONS
   ============================================= */
@keyframes mp-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
@keyframes mp-slide-right {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

/* Smooth scrollbar for playlist */
.mp-playlist::-webkit-scrollbar { width: 4px; }
.mp-playlist::-webkit-scrollbar-track { background: transparent; }
.mp-playlist::-webkit-scrollbar-thumb { background: var(--mp-border); border-radius: 2px; }
