/* ========================================
   MB Related Videos - Frontend Styles
   Enhanced with flexible aspect ratios
   ======================================== */

/* Collapsible Section */
.mb-rv {
  margin: 1rem 0;
}

.mb-rv__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  padding: 0.75rem 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #f8f8f8;
  font-weight: 600;
  transition: background-color 0.2s ease;
}

.mb-rv__toggle:hover {
  background: #eeeeee;
}

.mb-rv__toggle:focus {
  outline: 2px solid #5b9dd9;
  outline-offset: 2px;
}

.mb-rv__chev {
  transition: transform 0.2s ease;
  font-size: 1.2em;
}

.mb-rv.is-open .mb-rv__chev {
  transform: rotate(90deg);
}

.mb-rv__panel {
  display: none;
  border: 1px solid #eee;
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 0.5rem 1rem;
  background: #fff;
}

.mb-rv.is-open .mb-rv__panel {
  display: block;
}

/* Related Videos List */
.mb-related-videos__head {
  font-weight: 600;
  display: flex;
  gap: 1rem;
  border-bottom: 1px solid #ddd;
  padding: 0.5rem 0;
  margin-top: 0.25rem;
}

.mb-related-videos__row {
  display: flex;
  gap: 1rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid #eee;
}

.mb-related-videos__date {
  width: 12rem;
  flex: 0 0 12rem;
}

/* ========================================
   Inline Video Embeds (Featured Image Replacement)
   Multiple aspect ratio options
   ======================================== */

.mb-rv-inline-embed {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer; /* Indicate clickability for fullscreen modal */
}

/* Default: 4:3 aspect ratio (less wide, more traditional) */
.mb-rv-inline-embed {
  aspect-ratio: 4 / 3;
}

/* Alternative aspect ratios - add these classes in PHP if needed */
.mb-rv-inline-embed.mb-rv-ratio-16x9 {
  aspect-ratio: 16 / 9;
}

.mb-rv-inline-embed.mb-rv-ratio-1x1 {
  aspect-ratio: 1 / 1;
}

.mb-rv-inline-embed.mb-rv-ratio-3x4 {
  aspect-ratio: 3 / 4; /* Portrait */
}

/* Fallback for older browsers without aspect-ratio support */
@supports not (aspect-ratio: 1/1) {
  .mb-rv-inline-embed {
    padding-bottom: 75%; /* 4:3 default */
  }
  .mb-rv-inline-embed.mb-rv-ratio-16x9 {
    padding-bottom: 56.25%;
  }
  .mb-rv-inline-embed.mb-rv-ratio-1x1 {
    padding-bottom: 100%;
  }
  .mb-rv-inline-embed.mb-rv-ratio-3x4 {
    padding-bottom: 133.33%;
  }
}

.mb-rv-inline-embed iframe,
.mb-rv-inline-embed video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.mb-rv-inline-embed video {
  object-fit: cover;
}

/* Loading state for inline embeds */
.mb-rv-inline-embed::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: mb-rv-spin 0.8s linear infinite;
  z-index: 1;
}

.mb-rv-inline-embed.initialized::before {
  display: none;
}

@keyframes mb-rv-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Frozen state overlay */
.mb-rv-inline-embed.is-frozen::after {
  content: '▶';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: white;
  pointer-events: none;
  z-index: 10;
  backdrop-filter: blur(2px);
}

/* Fullscreen hint overlay */
.mb-rv-inline-embed:hover::after {
  content: '⛶'; /* Fullscreen icon */
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 18px;
  z-index: 20;
  pointer-events: none;
}

.mb-rv-inline-embed.is-frozen:hover::after {
  content: '▶ Click to replay'; /* Override for frozen state */
  font-size: 14px;
  bottom: auto;
  right: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 80px);
}

/* Modal Video Player */
.mb-rv-modal__overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999999;
  animation: mb-rv-fade-in 0.2s ease;
  padding: 20px; /* Add padding to prevent edge-to-edge */
}

@keyframes mb-rv-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.mb-rv-modal {
  background: #000;
  border-radius: 8px;
  /* Fixed dimensions - cannot expand */
  width: 50vw !important;
  min-width: 400px !important;
  max-width: 50vw !important;
  height: calc(50vw * 9 / 16) !important;
  max-height: 50vh !important;
  /* Force contained sizing */
  position: relative;
  flex-shrink: 0;
  flex-grow: 0;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  animation: mb-rv-scale-in 0.25s ease;
  /* Ensure it cannot be resized */
  resize: none !important;
}

@keyframes mb-rv-scale-in {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.mb-rv-modal iframe,
.mb-rv-modal video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
  border: 0;
  display: block;
  border-radius: 8px;
  background: #000;
  object-fit: contain;
}

.mb-rv-modal__close {
  position: absolute;
  top: -60px;
  right: 0;
  background: #fff;
  color: #111;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  transition: all 0.2s ease;
  z-index: 10;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mb-rv-modal__close::before {
  content: '✕';
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  color: #d32f2f;
}

.mb-rv-modal__close:hover {
  background: #f8f8f8;
  border-color: #d32f2f;
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(211, 47, 47, 0.4);
}

.mb-rv-modal__close:active {
  transform: translateY(-1px);
  box-shadow: 0 3px 12px rgba(211, 47, 47, 0.3);
}

/* Helper text for modal */
.mb-rv-modal__helper {
  position: absolute;
  top: -60px;
  left: 0;
  background: rgba(255, 255, 255, 0.98);
  color: #111;
  padding: 10px 18px;
  border-radius: 6px;
  border: 2px solid #e0e0e0;
  font-size: 14px;
  font-weight: 600;
  opacity: 1;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  animation: mb-rv-helper-fade 6s ease forwards;
}

.mb-rv-modal__helper::before {
  content: 'ℹ️';
  margin-right: 8px;
  font-size: 16px;
}

@keyframes mb-rv-helper-fade {
  0%, 75% { opacity: 1; }
  100% { opacity: 0; }
}

/* Responsive Styles */
@media (max-width: 1400px) {
  .mb-rv-modal {
    width: 60vw !important; /* Slightly larger on smaller desktops */
    height: calc(60vw * 9 / 16) !important;
    max-height: 55vh !important;
  }
}

@media (max-width: 768px) {
  .mb-rv-modal {
    width: 85vw !important; /* Almost full width on mobile */
    height: calc(85vw * 9 / 16) !important;
    max-height: 60vh !important;
  }

  .mb-rv-modal__close {
    top: -54px;
    font-size: 15px;
    padding: 10px 18px;
  }
  
  .mb-rv-modal__helper {
    top: -54px;
    font-size: 12px;
    padding: 8px 14px;
  }

  .mb-related-videos__row {
    flex-direction: column;
    gap: 0.25rem;
  }

  .mb-related-videos__dur {
    text-align: left !important;
  }
  
  .mb-rv-inline-embed:hover::after {
    display: none; /* Hide hint on mobile */
  }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .mb-rv__chev,
  .mb-rv-modal__overlay,
  .mb-rv-modal,
  .mb-rv-modal__close {
    animation: none;
    transition: none;
  }
}