/*
 * Video.js Custom Theme
 *
 * Custom styling for Video.js player to match the platform's dark theme.
 * This file should be loaded after the base video-js.css from CDN.
 */

/* CSS Custom Properties for theming */
:root {
  --vjs-primary-color: #dc2626; /* red-600 - matches platform accent */
  --vjs-secondary-color: #1f2937; /* gray-800 */
  --vjs-text-color: #ffffff;
  --vjs-control-bg: rgba(0, 0, 0, 0.7);
}

/* Player container */
.video-js {
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #000;
  border-radius: 0.5rem;
  overflow: hidden;
  font-family: inherit;
}

/* Portrait video player — 9:16 aspect ratio, capped to viewport height */
.video-js.vjs-portrait {
  aspect-ratio: 9 / 16;
  max-height: 80vh;
  max-height: 80dvh;
  width: auto;
}

/* Override vjs-fluid padding-top: use aspect-ratio instead so max-height works */
.video-js.vjs-portrait.vjs-fluid {
  padding-top: 0;
  height: auto;
}

/* Portrait player container — center the narrower player */
.video-player-container--portrait {
  display: flex;
  justify-content: center;
}

/* Remove default focus outline, add custom */
.video-js *:focus {
  outline: none;
}

.video-js *:focus-visible {
  outline: 2px solid var(--vjs-primary-color);
  outline-offset: 2px;
}

/* No focus ring or color change on control bar controls —
   avoids red box/stuck highlight on mobile tap */
.video-js .vjs-control-bar .vjs-control:focus,
.video-js .vjs-control-bar .vjs-control:focus-visible {
  outline: none;
  color: inherit;
}

/* Big play button */
.video-js .vjs-big-play-button {
  background-color: var(--vjs-primary-color);
  border: none;
  border-radius: 50%;
  width: 80px;
  height: 80px;
  line-height: 80px;
  font-size: 3rem;
  top: 50%;
  left: 50%;
  margin-top: -40px;
  margin-left: -40px;
  transition: transform 0.2s ease, background-color 0.2s ease, opacity 0.2s ease;
}

.video-js .vjs-big-play-button:hover,
.video-js .vjs-big-play-button:focus {
  background-color: #b91c1c; /* red-700 */
  transform: scale(1.1);
}

.video-js:hover .vjs-big-play-button {
  opacity: 1;
}

/* Hide big play button when playing */
.video-js.vjs-playing .vjs-big-play-button,
.video-js.vjs-has-started .vjs-big-play-button {
  display: none;
}

/* Control bar */
.video-js .vjs-control-bar {
  background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.6) 50%, transparent 100%);
  height: 48px;
  padding: 0 8px;
  display: flex;
  align-items: center;
}

/* Control bar buttons */
.video-js .vjs-button > .vjs-icon-placeholder:before {
  font-size: 1.5rem;
  line-height: 48px;
}

.video-js .vjs-control:focus:before,
.video-js .vjs-control:hover:before,
.video-js .vjs-control:focus {
  text-shadow: none;
}

.video-js .vjs-control {
  width: 3em;
  transition: color 0.2s ease;
}

.video-js .vjs-control:hover {
  color: var(--vjs-primary-color);
}

/* Play/Pause button */
.video-js .vjs-play-control {
  font-size: 1.1em;
}

/* Progress bar - positioned above control bar */
.video-js .vjs-progress-control {
  position: absolute;
  bottom: 44px;
  left: 0;
  right: 0;
  width: 100%;
  height: 8px;
  padding: 0 8px;
}

.video-js .vjs-progress-holder {
  height: 4px;
  margin: 0;
  border-radius: 2px;
  transition: height 0.15s ease;
  background-color: rgba(255, 255, 255, 0.2);
}

.video-js .vjs-progress-control:hover .vjs-progress-holder,
.video-js .vjs-progress-holder:focus {
  height: 8px;
}

/* Progress bar colors */
.video-js .vjs-play-progress {
  background-color: var(--vjs-primary-color);
  border-radius: 2px;
}

.video-js .vjs-play-progress:before {
  display: none; /* Hide the time tooltip circle */
}

.video-js .vjs-play-progress .vjs-time-tooltip {
  display: none !important; /* Hide the duplicate time tooltip on the play head */
}

.video-js .vjs-load-progress {
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

.video-js .vjs-load-progress div {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Seek handle */
.video-js .vjs-slider-handle {
  background-color: var(--vjs-primary-color);
}

/* Time tooltip */
.video-js .vjs-time-tooltip {
  background-color: var(--vjs-secondary-color);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
}

/* When sprite thumbnails are loaded, hide the built-in time tooltips to
   prevent flickering and duplicate time displays. Videos without sprites
   keep the default Video.js time tooltip behavior. */
.video-js.vjs-has-sprites .vjs-mouse-display .vjs-time-tooltip,
.video-js.vjs-has-sprites .vjs-play-progress .vjs-time-tooltip,
.video-js.vjs-has-sprites .vjs-mouse-display {
  display: none !important;
}

/* Expand the progress bar hover target when sprites are available.
   Since the control is position: absolute with bottom: 44px, extra height
   grows upward — the visible bar stays put, but the hover zone is larger. */
.video-js.vjs-has-sprites .vjs-progress-control {
  height: 28px;
}

/* Volume panel */
.video-js .vjs-volume-panel {
  width: 6em;
  transition: width 0.2s ease;
}

.video-js .vjs-volume-panel.vjs-hover,
.video-js .vjs-volume-panel:active,
.video-js .vjs-volume-panel.vjs-slider-active {
  width: 9em;
}

.video-js .vjs-volume-bar {
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  margin: 1.35em 0.45em;
}

.video-js .vjs-volume-level {
  background-color: var(--vjs-primary-color);
  border-radius: 2px;
}

/* Time display — YouTube-style pill: "2:34 / 5:20" */
.video-js .vjs-time-control {
  display: block !important; /* Override Video.js default display: none */
  font-size: 12px;
  font-weight: 500;
  padding: 0;
  min-width: auto;
  line-height: 48px;
}

.video-js .vjs-current-time {
  padding-left: 8px;
}

.video-js .vjs-time-divider {
  padding: 0 2px;
  min-width: auto;
}

.video-js .vjs-duration {
  padding-right: 8px;
}

/* Remaining time - hide, we show current/duration instead */
.video-js .vjs-remaining-time {
  display: none !important;
}

/* Playback rate menu */
.video-js .vjs-playback-rate {
  font-size: 12px;
}

.video-js .vjs-playback-rate .vjs-playback-rate-value {
  font-size: 12px;
  line-height: 48px;
}

/* Menu styling */
.video-js .vjs-menu {
  z-index: 10;
}

.video-js .vjs-menu-content {
  border-radius: 4px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  scrollbar-width: none; /* Firefox */
}

/* Override Video.js default transparent menu background for all popup menus */
.video-js .vjs-menu-button-popup .vjs-menu .vjs-menu-content {
  background-color: rgba(0, 0, 0, 0.9);
}

.video-js .vjs-menu-content::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Edge */
}

.video-js .vjs-menu li {
  padding: 8px 16px;
  font-size: 13px;
  text-transform: none;
}

.video-js .vjs-menu li:hover,
.video-js .vjs-menu li:focus {
  background-color: rgba(255, 255, 255, 0.1);
}

.video-js .vjs-menu li.vjs-selected,
.video-js .vjs-menu li.vjs-selected:hover,
.video-js .vjs-menu li.vjs-selected:focus {
  background-color: var(--vjs-primary-color);
  color: white;
}

/* Quality selector styles */
.video-js .vjs-quality-selector {
  cursor: pointer;
  order: 98; /* Before PiP (99) and fullscreen (100) */
}

.video-js .vjs-quality-selector .vjs-icon-placeholder:before {
  font-family: "VideoJS";
  content: "\f114"; /* cog/gear icon */
  font-size: 1.4rem;
  line-height: 48px;
}

.video-js .vjs-quality-selector .vjs-menu .vjs-menu-content {
  min-width: 120px;
  max-height: 300px;
  overflow-y: auto;
  bottom: 1.5em;
  padding: 4px 0;
}

.video-js .vjs-quality-selector .vjs-menu li {
  padding: 8px 16px;
  font-size: 13px;
  text-transform: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.video-js .vjs-quality-selector .vjs-menu li:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.video-js .vjs-quality-selector .vjs-menu li.vjs-selected {
  background-color: transparent;
  color: var(--vjs-primary-color);
  font-weight: 600;
}

.video-js .vjs-quality-selector .vjs-menu li.vjs-selected:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Captions/subtitles */
.video-js .vjs-text-track-display {
  bottom: 56px;
}

.video-js .vjs-text-track-cue > div {
  background-color: rgba(0, 0, 0, 0.8) !important;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 1.1em;
}

/* Loading spinner */
.video-js .vjs-loading-spinner {
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--vjs-primary-color);
  border-radius: 50%;
}

.video-js .vjs-loading-spinner:before,
.video-js .vjs-loading-spinner:after {
  display: none;
}

/* Error display */
.video-js .vjs-error-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.video-js .vjs-error-display:before {
  content: none;
}

.video-js .vjs-error-display .vjs-modal-dialog-content {
  font-size: 14px;
  padding: 24px;
  text-align: center;
  max-width: 400px;
}

/* Poster image styling */
.video-js .vjs-poster {
  background-size: cover;
  background-position: center;
  background-color: #000;
}

/* Fullscreen button */
.video-js .vjs-fullscreen-control {
  order: 100; /* Push to the end */
}

/* Picture-in-picture button */
.video-js .vjs-picture-in-picture-control {
  order: 99;
}

/* Custom spacer — pushes right-side controls to the far right.
   Must override Video.js defaults: display: none, width: 3em, flex: none */
.video-js .vjs-custom-control-spacer {
  display: block !important;
  flex: 1 1 auto !important;
  width: auto !important;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .video-js .vjs-big-play-button {
    width: 60px;
    height: 60px;
    line-height: 60px;
    font-size: 2.25rem;
    margin-top: -30px;
    margin-left: -30px;
  }

  .video-js .vjs-control-bar {
    height: 40px;
    padding: 0 4px;
  }

  .video-js .vjs-button > .vjs-icon-placeholder:before {
    line-height: 40px;
    font-size: 1.25rem;
  }

  .video-js .vjs-time-control {
    line-height: 40px;
    font-size: 11px;
  }

  .video-js .vjs-progress-control {
    display: flex !important; /* Override Video.js responsive hiding at narrow widths */
    bottom: 36px;
    padding: 0 4px;
  }

  .video-js .vjs-text-track-display {
    bottom: 44px;
  }

  /* Hide some controls on mobile */
  .video-js .vjs-playback-rate {
    display: none;
  }

  .video-js .vjs-quality-selector .vjs-icon-placeholder:before {
    line-height: 40px;
    font-size: 1.2rem;
  }
}

/* Fluid mode - maintains aspect ratio */
.video-js.vjs-fluid,
.video-js.vjs-16-9,
.video-js.vjs-4-3 {
  width: 100%;
  max-width: 100%;
  height: 0;
}

.video-js.vjs-fluid {
  padding-top: 56.25%; /* 16:9 default */
}

.video-js.vjs-16-9 {
  padding-top: 56.25%;
}

.video-js.vjs-4-3 {
  padding-top: 75%;
}

/* Fill mode - fills container */
.video-js.vjs-fill {
  width: 100%;
  height: 100%;
}

/* Audio-only mode */
.video-js.vjs-audio {
  min-height: 48px;
  aspect-ratio: auto;
}

.video-js.vjs-audio .vjs-big-play-button {
  display: none;
}

/* Ads placeholder (for Phase 05) */
.video-js .vjs-ad-loading {
  background-color: rgba(0, 0, 0, 0.8);
}

.video-js .vjs-ad-playing .vjs-progress-control {
  pointer-events: none;
  opacity: 0.5;
}

/* Skeleton loading state */
.video-player-skeleton {
  aspect-ratio: 16 / 9;
  background-color: #1f2937;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.video-player-skeleton-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: #374151;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-player-skeleton-icon svg {
  width: 32px;
  height: 32px;
  color: #6b7280;
}

/* Processing state */
.video-player-processing {
  aspect-ratio: 16 / 9;
  background-color: #1f2937;
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
}

.video-player-processing-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--vjs-primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.video-player-processing-text {
  color: #9ca3af;
  font-size: 14px;
  text-align: center;
}

/* Error state */
.video-player-error {
  aspect-ratio: 16 / 9;
  background-color: #1f2937;
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
}

.video-player-error-icon {
  width: 64px;
  height: 64px;
  color: #ef4444;
}

.video-player-error-text {
  color: #9ca3af;
  font-size: 14px;
  text-align: center;
  max-width: 300px;
}

.video-player-error-retry {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background-color: var(--vjs-primary-color);
  color: white;
  border: none;
  border-radius: 0.375rem;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.video-player-error-retry:hover {
  background-color: #b91c1c;
}

/* Portrait variants for processing, skeleton, and error states */
.video-player-processing.video-player--portrait,
.video-player-skeleton.video-player--portrait {
  aspect-ratio: 9 / 16;
  max-height: 80vh;
  max-height: 80dvh;
  margin-inline: auto;
  width: auto;
}

/* ===================== */
/* Video Show Layout     */
/* ===================== */

/* Surround for immersive player area — transparent so page background shows through */
.video-player-surround {
  background-color: transparent;
  padding: 0.5rem 0;
}

@media (min-width: 992px) {
  .video-player-surround {
    padding: 1rem 0;
  }
}

/* Centered container shared by player row and content row */
.video-show-layout {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1rem;
}

@media (max-width: 640px) {
  .video-show-layout {
    padding: 0 0.25rem;
  }
}

/* Unified two-column layout: left col (player + info) and right col (Up Next) */
.video-show-two-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 992px) {
  .video-show-two-col {
    flex-direction: row;
    gap: 1.5rem;
    align-items: flex-start;
  }
}

/* Left column: player + content stacked vertically */
.video-show-left-col {
  flex: 1;
  min-width: 0;
}

/* Content area below the player */
.video-show-content {
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
}

/* Legacy layout classes (used by live_streams/show) */
.video-show-player-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 992px) {
  .video-show-player-row {
    flex-direction: row;
    gap: 1.5rem;
  }
}

.video-show-player-col {
  flex: 1;
  min-width: 0;
}

.video-show-content-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
}

@media (min-width: 992px) {
  .video-show-content-row {
    flex-direction: row;
    gap: 1.5rem;
  }
}

.video-show-main {
  flex: 1;
  min-width: 0;
}

.video-show-sidebar-spacer {
  width: 400px;
  flex-shrink: 0;
}

/* Sidebar: fixed width on desktop */
.video-show-sidebar {
  min-width: 0;
  width: 100%;
}

@media (min-width: 992px) {
  .video-show-sidebar {
    width: 400px;
    flex-shrink: 0;
  }
}

/* ===================== */
/* Up-Next Sidebar       */
/* ===================== */

.up-next-sidebar {
  border-radius: 0.75rem;
  padding: 1rem;
  overflow-x: hidden;
}

/* Dark theme: semi-transparent dark background */
.dark .up-next-sidebar {
  background: rgba(31, 31, 31, 0.9);
}

/* Light theme: card surface */
:not(.dark) .up-next-sidebar {
  background: var(--color-card, #ffffff);
  border: 1px solid var(--color-border, rgba(0, 0, 0, 0.1));
}

/* Sticky wrapper on desktop */
.up-next-sticky {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.up-next-sticky .up-next-sidebar {
  display: flex;
  flex-direction: column;
  max-height: 100%;
  overflow: hidden;
}

.up-next-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  flex-shrink: 0;
}

.dark .up-next-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

:not(.dark) .up-next-header {
  border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.1));
}

/* Autoplay toggle switch */
.autoplay-toggle {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.autoplay-toggle-track {
  display: inline-block;
  width: 2.25rem;
  height: 1.25rem;
  border-radius: 9999px;
  position: relative;
  transition: background-color 0.2s ease;
}

.dark .autoplay-toggle-track {
  background: rgba(255, 255, 255, 0.2);
}

:not(.dark) .autoplay-toggle-track {
  background: rgba(0, 0, 0, 0.15);
}

.autoplay-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

:not(.dark) .autoplay-toggle-track::after {
  background: white;
}

.peer:checked ~ .autoplay-toggle-track {
  background-color: var(--color-primary, #ec1c24);
}

.peer:checked ~ .autoplay-toggle-track::after {
  transform: translateX(1rem);
}

/* Compact card list (desktop — vertical) */
.up-next-list {
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  scrollbar-width: none; /* Firefox — hide scrollbar */
}

.up-next-list::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Edge — hide scrollbar */
}

/* Mobile horizontal scroll row */
.up-next-scroll-row {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem;
  scrollbar-width: none; /* Firefox */
}

.up-next-scroll-row::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Edge */
}

.up-next-scroll-item {
  flex-shrink: 0;
  width: 200px;
  scroll-snap-align: start;
}

@media (min-width: 576px) {
  .up-next-scroll-item {
    width: 220px;
  }
}

/* ============================== */
/* Playlist Current Item Highlight */
/* ============================== */

.playlist-current-item {
  border-radius: 0.5rem;
  position: relative;
}

.dark .playlist-current-item {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1.5px var(--color-primary, #ec1c24);
}

:not(.dark) .playlist-current-item {
  background: var(--color-primary, #ec1c24) / 0.06;
  background: color-mix(in srgb, var(--color-primary, #ec1c24) 6%, transparent);
  box-shadow: inset 0 0 0 1.5px var(--color-primary, #ec1c24);
}

/* ===================== */
/* Autoplay Countdown    */
/* ===================== */

.autoplay-countdown-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 20;
  border-radius: 0.5rem;
  backdrop-filter: blur(4px);
}

.autoplay-countdown-overlay:not(.hidden) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.countdown-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.countdown-ring-container {
  position: relative;
  width: 120px;
  height: 120px;
}

.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring-circle {
  stroke-dasharray: 283; /* 2 * PI * 45 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}

.countdown-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.5rem;
  font-weight: 700;
  color: white;
  line-height: 1;
}

.next-video-info {
  margin-top: 1.5rem;
  max-width: 280px;
}

.cancel-autoplay-button {
  margin-top: 1.25rem;
  padding: 0.5rem 2rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 9999px;
  color: white;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cancel-autoplay-button:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

.cancel-autoplay-button:focus-visible {
  outline: 2px solid var(--color-primary, #ec1c24);
  outline-offset: 2px;
}

/* Mobile adjustments for countdown overlay */
@media (max-width: 640px) {
  .countdown-ring-container {
    width: 80px;
    height: 80px;
  }

  .countdown-ring-container svg {
    width: 100%;
    height: 100%;
  }

  .countdown-number {
    font-size: 1.75rem;
  }

  .next-video-info {
    max-width: 200px;
  }

  .next-video-info h4 {
    font-size: 0.875rem;
  }
}
