/**
 * Stream Player Styles - FINAL VERSION 5.0.0
 * Clean rewrite — no duplicates
 */

/* ========================================
   BASE
   ======================================== */
.ms-stream-player-wrapper {
    width: 100%;
    background: #000;
    position: relative;
    display: flex;
    flex-direction: column;
}

.ms-stream-player-wrapper * {
    box-sizing: border-box;
}

/* ========================================
   HIDE UNWANTED ELEMENTS ON STREAM PAGES
   ======================================== */
body.stream-lesson-active #course-compl,
body.stream-lesson-active .stm-lms-course__complete,
body.stream-lesson-active [class*="complete-button"],
body.stream-lesson-active .masterstudy-course-player__complete,
body.stream-lesson-active .masterstudy-course-player-complete,
body.stream-lesson-active button[data-action="complete"],
body.stream-lesson-active .stm-lms-course-player__complete {
    display: none !important;
}

body.stream-lesson-active .stm-lms-course__info,
body.stream-lesson-active .stm-lms-course__stats,
body.stream-lesson-active .stm-lms-course__start-learning,
body.stream-lesson-active .stm-lms-tabs__item:not(:first-child),
body.stream-lesson-active .stm-lms-course-tabs__item:not(:first-child),
body.stream-lesson-active .stm-lms-course-player__navigation,
body.stream-lesson-active .masterstudy-course-player__navigation {
    display: none !important;
}

body.stream-lesson-active .masterstudy-course-player__content,
body.stream-lesson-active .stm-lms-course-player__content {
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}

/* ========================================
   COUNTDOWN (before stream)
   ======================================== */
.ms-stream-countdown-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 5vw, 3rem);
}

.ms-stream-countdown-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.ms-countdown-placeholder {
    text-align: center;
    color: #fff;
}

.ms-countdown-placeholder h2 {
    font-size: clamp(1.2rem, 4vw, 2.5rem);
    font-weight: 300;
    margin: 0;
}

/* ========================================
   CONCLUDED (after stream)
   ======================================== */
.ms-stream-concluded-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
    padding: clamp(1rem, 5vw, 3rem);
}

.ms-concluded-content {
    text-align: center;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.ms-concluded-title {
    font-size: clamp(1.2rem, 4vw, 2rem);
    font-weight: 700;
    color: #10b981;
    margin: 0;
}

/* ========================================
   LIVE STREAM LAYOUT
   ======================================== */
.ms-live-stream-layout {
    width: 100%;
    position: relative;
    background: #000;
}

/* ========================================
   VIDEO PLAYER — 16:9, no extra space
   ======================================== */
.ms-video-player-wrapper {
    width: 100%;
    position: relative;
    background: #000;
}

.ms-video-player {
    width: 100%;
    position: relative;
    background: #000;
    padding-top: 56.25%; /* 16:9 */
    overflow: hidden;
}

.ms-video-player iframe,
.ms-video-player video {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    border: none;
    object-fit: contain;
    display: block;
}

/* HTML5 container */
.ms-html5-video-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    overflow: hidden;
}

.ms-html5-video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: absolute;
    top: 0; left: 0;
    z-index: 1;
    pointer-events: none;
    display: block;
}

/* Transparent blocker — prevents native controls appearing on tap */
.ms-video-blocker {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    background: transparent;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    /* CRITICAL: must not escape the video container */
    overflow: hidden;
}

/* Hide ALL native webkit controls */
.ms-html5-video-container video::-webkit-media-controls,
.ms-html5-video-container video::-webkit-media-controls-enclosure,
.ms-html5-video-container video::-webkit-media-controls-panel,
.ms-html5-video-container video::-webkit-media-controls-play-button,
.ms-html5-video-container video::-webkit-media-controls-start-playback-button,
.ms-html5-video-container video::-webkit-media-controls-timeline,
.ms-html5-video-container video::-webkit-media-controls-current-time-display,
.ms-html5-video-container video::-webkit-media-controls-time-remaining-display,
.ms-html5-video-container video::-webkit-media-controls-fullscreen-button,
.ms-html5-video-container video::-webkit-media-controls-volume-slider,
.ms-html5-video-container video::-webkit-media-controls-mute-button,
.ms-html5-video-container video::-webkit-media-controls-overlay-enclosure,
.ms-html5-video-container video::-webkit-media-controls-overlay-play-button {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.ms-html5-video-container:fullscreen video::-webkit-media-controls,
.ms-html5-video-container:-webkit-full-screen video::-webkit-media-controls,
.ms-html5-video-container:fullscreen video::-webkit-media-controls-enclosure,
.ms-html5-video-container:-webkit-full-screen video::-webkit-media-controls-enclosure,
.ms-html5-video-container:fullscreen video::-webkit-media-controls-panel,
.ms-html5-video-container:-webkit-full-screen video::-webkit-media-controls-panel,
.ms-html5-video-container:fullscreen video::-webkit-media-controls-overlay-enclosure,
.ms-html5-video-container:-webkit-full-screen video::-webkit-media-controls-overlay-enclosure,
.ms-html5-video-container:fullscreen video::-webkit-media-controls-overlay-play-button,
.ms-html5-video-container:-webkit-full-screen video::-webkit-media-controls-overlay-play-button {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* ========================================
   iOS FAKE FULLSCREEN
   Expands video container to fill viewport without using
   webkitEnterFullscreen (which shows native controls on iPhone)
   ======================================== */
.ms-html5-video-container.ms-fake-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 99999 !important;
    background: #000 !important;
    border-radius: 0 !important;
}

.ms-html5-video-container.ms-fake-fullscreen video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
}

/* Lock scroll when fake fullscreen is active */
body.ms-fs-active {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}

/* Keep fullscreen button and blocker visible in fake fullscreen */
.ms-html5-video-container.ms-fake-fullscreen .ms-video-blocker {
    display: block !important;
    pointer-events: auto !important;
}

.ms-html5-video-container.ms-fake-fullscreen .ms-fullscreen-btn {
    display: flex !important;
    z-index: 100000 !important;
}

/* ========================================
   iOS FAKE FULLSCREEN
   Expands video container to fill viewport without
   triggering native iOS player (which shows all controls)
   ======================================== */
.ms-html5-video-container.ms-fake-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 99999 !important;
    background: #000 !important;
    padding-top: 0 !important;
}

.ms-html5-video-container.ms-fake-fullscreen video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    position: absolute !important;
    top: 0 !important; left: 0 !important;
}

.ms-html5-video-container.ms-fake-fullscreen .ms-video-blocker {
    position: fixed !important;
    top: 0 !important; left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 2 !important;
}

.ms-html5-video-container.ms-fake-fullscreen .ms-fullscreen-btn {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 100000 !important;
}

/* Prevent body scroll when iOS fake fullscreen is active */
body.ms-fs-active {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
}
.ms-fullscreen-btn {
    position: absolute !important;
    bottom: 10px !important;
    right: 10px !important;
    z-index: 10 !important;
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(0,0,0,0.72) !important;
    border: 1.5px solid rgba(255,255,255,0.35) !important;
    border-radius: 6px !important;
    cursor: pointer !important;
    padding: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    -webkit-tap-highlight-color: transparent !important;
    transition: background 0.15s ease !important;
}

.ms-fullscreen-btn svg {
    display: block !important;
    width: 20px !important;
    height: 20px !important;
    stroke: #fff !important;
    fill: none !important;
    pointer-events: none !important;
    flex-shrink: 0 !important;
}

.ms-fullscreen-btn:hover,
.ms-fullscreen-btn:focus {
    background: rgba(0,0,0,0.92) !important;
    border-color: rgba(255,255,255,0.7) !important;
    outline: none !important;
}

.ms-fullscreen-btn:active { transform: scale(0.93) !important; }

/* Fullscreen container */
.ms-html5-video-container:fullscreen,
.ms-html5-video-container:-webkit-full-screen,
.ms-html5-video-container:-moz-full-screen,
.ms-html5-video-container:-ms-fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    background: #000 !important;
}

.ms-html5-video-container:fullscreen video,
.ms-html5-video-container:-webkit-full-screen video,
.ms-html5-video-container:-moz-full-screen video,
.ms-html5-video-container:-ms-fullscreen video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
}

.ms-html5-video-container:fullscreen .ms-video-blocker,
.ms-html5-video-container:-webkit-full-screen .ms-video-blocker {
    display: block !important;
    pointer-events: auto !important;
}

/* ========================================
   Q&A PANEL — fixed overlay, right side
   ======================================== */
.ms-qa-panel {
    position: fixed !important;
    top: 0 !important;
    right: -100% !important;
    width: 380px !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    background: #1a1a1a !important;
    z-index: 10000 !important;
    transition: right 0.3s cubic-bezier(0.4,0,0.2,1) !important;
    display: flex !important;
    flex-direction: column !important;
    box-shadow: -4px 0 20px rgba(0,0,0,0.5) !important;
    pointer-events: none !important;
}

.ms-qa-panel.open {
    right: 0 !important;
    pointer-events: auto !important;
}

/* Q&A Toggle — bottom LEFT, away from WhatsApp (bottom-right) */
.ms-qa-toggle-btn {
    position: fixed !important;
    bottom: 80px !important;
    left: 0 !important;
    top: auto !important;
    right: auto !important;
    transform: none !important;
    background: #dc2626 !important;
    border: none !important;
    border-radius: 0 8px 8px 0 !important;
    cursor: pointer !important;
    z-index: 9998 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    color: #fff !important;
    pointer-events: auto !important;
    width: 32px !important;
    min-height: 64px !important;
    padding: 8px 6px !important;
    box-shadow: 2px 2px 8px rgba(0,0,0,0.4) !important;
    -webkit-tap-highlight-color: transparent !important;
}

.ms-qa-toggle-btn .qa-label {
    display: block;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1px;
    color: #fff;
    text-transform: uppercase;
    line-height: 1;
}

.ms-qa-toggle-btn svg {
    width: 14px !important;
    height: 14px !important;
    flex-shrink: 0;
    stroke: #fff;
    fill: none;
}

.ms-qa-toggle-btn:hover { background: #b91c1c !important; }

.ms-qa-panel.open .ms-qa-toggle-btn { display: none !important; }

/* Q&A Content */
.ms-qa-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.ms-qa-header {
    padding: 1rem 1.25rem;
    background: #0f0f0f;
    border-bottom: 1px solid #2a2a2a;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ms-qa-header h4 {
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ms-qa-close-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.ms-qa-close-btn:hover { color: #fff; }

.ms-qa-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    -webkit-overflow-scrolling: touch;
}

.ms-qa-loading,
.ms-qa-empty {
    text-align: center;
    color: #666;
    padding: 2rem 1rem;
    font-size: 0.875rem;
}

.ms-qa-message {
    display: flex;
    gap: 0.6rem;
}

.ms-qa-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
    text-transform: uppercase;
}

.ms-qa-message-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.ms-qa-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
    gap: 0.5rem;
}

.ms-qa-message-header strong {
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
}

.ms-qa-time {
    color: #666;
    font-size: 0.7rem;
    white-space: nowrap;
}

.ms-qa-message-text {
    color: #e0e0e0;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    font-size: 0.875rem;
    background: #0f0f0f;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
}

.ms-qa-answer {
    margin-top: 0.4rem;
    padding: 0.6rem 0.75rem;
    background: #0f0f0f;
    border-left: 3px solid #10b981;
    border-radius: 4px;
    color: #e0e0e0;
    font-size: 0.8rem;
}

.ms-qa-answer strong { color: #10b981; margin-right: 0.4rem; }

.ms-qa-input-wrapper {
    flex-shrink: 0;
    background: #0f0f0f;
    border-top: 1px solid #2a2a2a;
}

.ms-qa-input-container {
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

#qa-message-input {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 20px;
    padding: 0.7rem 1rem;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    transition: border-color 0.2s;
    min-height: 44px;
}

#qa-message-input:focus { outline: none; border-color: #4c6ef5; }
#qa-message-input::placeholder { color: #666; }

.ms-qa-send-btn {
    background: #4c6ef5;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ms-qa-send-btn:hover  { background: #5c7eff; transform: scale(1.05); }
.ms-qa-send-btn:active { transform: scale(0.95); }
.ms-qa-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.ms-qa-messages::-webkit-scrollbar { width: 6px; }
.ms-qa-messages::-webkit-scrollbar-track { background: #1a1a1a; }
.ms-qa-messages::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 3px; }
.ms-qa-messages::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.8); }
    to   { opacity: 1; transform: scale(1); }
}
@keyframes slideInMessage {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 1024px) {
    .ms-qa-panel { width: 340px !important; }
}

@media (max-width: 768px) {
    .ms-qa-panel { width: 100% !important; }
    .ms-qa-toggle-btn { bottom: 70px !important; min-height: 70px !important; }
    .ms-fullscreen-btn { width: 38px !important; height: 38px !important; bottom: 8px !important; right: 8px !important; }
}

@media (max-width: 480px) {
    .ms-qa-header { padding: 0.75rem 1rem; }
    .ms-qa-messages { padding: 0.6rem; }
    .ms-qa-input-container { padding: 0.6rem 0.75rem; gap: 0.5rem; }
    .ms-qa-send-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
}

@media (max-width: 968px) and (orientation: landscape) {
    .ms-qa-panel { width: 55% !important; }
    .ms-qa-toggle-btn { bottom: 50% !important; transform: translateY(50%) !important; }
}

@media (hover: none) and (pointer: coarse) {
    .ms-qa-toggle-btn,
    .ms-qa-close-btn,
    .ms-fullscreen-btn,
    .ms-qa-send-btn {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
}

@media (min-width: 1920px) {
    .ms-qa-panel { width: 420px !important; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

.ms-qa-toggle-btn:focus-visible,
.ms-qa-close-btn:focus-visible,
.ms-fullscreen-btn:focus-visible,
.ms-qa-send-btn:focus-visible,
#qa-message-input:focus-visible {
    outline: 2px solid #4c6ef5;
    outline-offset: 2px;
}
