/* Custom minimal CSS on top of Tailwind */
html, body { height: 100%; }
/* Hint browser to render native form controls in dark mode */
html { color-scheme: dark; }
#countries::-webkit-scrollbar, #channels::-webkit-scrollbar { width: 10px; height: 10px; }
#countries::-webkit-scrollbar-thumb, #channels::-webkit-scrollbar-thumb { background-color: rgba(148,163,184,0.3); border-radius: 9999px; }
#countries::-webkit-scrollbar-track, #channels::-webkit-scrollbar-track { background-color: transparent; }

.card-hover { transition: transform .2s ease, box-shadow .2s ease; }
.card-hover:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(2,132,199,.25); }

/* Lazy sections below the fold */
.lazy-section { content-visibility: auto; contain-intrinsic-size: 1000px 800px; }

/* Globe tooltip */
.globe-tooltip {
  position: absolute;
  top: 0; left: 0;
  transform: translate(-50%, -120%);
  background: rgba(15, 23, 42, 0.95);
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1;
  padding: 6px 8px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(2,132,199,0.25);
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .12s ease;
  z-index: 20;
}
.globe-tooltip[data-show="true"] { opacity: 1; }

/* Center selector for mobile */
.center-selector {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 15;
}
#center-dot {
  width: 10px; /* smaller dot */
  height: 10px;
  border-radius: 9999px;
  background: #7F1D1D; /* dark red */
  box-shadow: 0 0 0 3px rgba(127, 29, 29, 0.35), 0 0 14px rgba(127, 29, 29, 0.55);
  opacity: .9;
}
.center-label {
  position: absolute;
  top: calc(50% - 18px);
  transform: translateY(-100%);
  background: rgba(15, 23, 42, 0.95);
  color: #e2e8f0;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(2,132,199,0.25);
  display: none;
}
.center-label[data-show="true"] { display: inline-block; }

/* Video.js error screen nicer look */
.vjs-error-display .vjs-modal-dialog-content {
  display: grid;
  place-items: center;
  text-align: center;
  color: #e2e8f0;
}
.vjs-error-display .vjs-modal-dialog-content::before {
  content: '';
  display: block;
  width: 56px; height: 56px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f43f5e, #ef4444);
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white"><path d="M12 2a10 10 0 100 20 10 10 0 000-20zm1 11H11V7h2v6zm0 4H11v-2h2v2z"/></svg>') center/28px 28px no-repeat;
          mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white"><path d="M12 2a10 10 0 100 20 10 10 0 000-20zm1 11H11V7h2v6zm0 4H11v-2h2v2z"/></svg>') center/28px 28px no-repeat;
}
.vjs-error-display .vjs-modal-dialog-content { font-size: 14px; }

/* Hide center selector on >=640px (desktop/tablet) */
@media (min-width: 640px) {
  .center-selector { display: none !important; }
} 

/* Force dark styling for dropdown selects so text is readable */
#filter-region,
#filter-category,
#filter-category-inline,
select {
  color: #e2e8f0;
  background-color: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
}

/* Options list background/text when the native menu is open */
select option {
  color: #e2e8f0;
  background-color: #0b1220; /* site bg */
}

select optgroup {
  color: #94a3b8;
  background-color: #0b1220;
}

/* Focus ring consistent with brand color */
#filter-region:focus,
#filter-category:focus,
#filter-category-inline:focus,
select:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.4);
  border-color: rgba(6, 182, 212, 0.6);
}

/* Ensure portrait (vertical) videos fit inside horizontal player */
#player-container video,
#player-container .vjs-tech {
  object-fit: contain !important;
  object-position: center center !important;
  background-color: #000;
}

/* Ensure Video.js fill mode respects container and not overflow */
.video-js.vjs-fill,
.video-js.vjs-fill .vjs-tech {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
}

/* Fullscreen handling for contain-fit as well */
.video-js.vjs-fullscreen .vjs-tech,
#player-container :fullscreen video,
#player-container :-webkit-full-screen video,
#player-container :-moz-full-screen video {
  object-fit: contain !important;
  object-position: center center !important;
}

/* Reduce spacing between main content and footer on desktop */
@media (min-width: 1024px) {
  /* Force the app container to not use full height */
  #app {
    min-height: auto !important;
  }
  
  /* Make main content not expand to fill space */
  main {
    flex: none !important;
  }
  
  /* Reduce padding on main grid */
  #app-main-grid {
    padding-top: 1rem !important;
    padding-bottom: 0.5rem !important; /* small space before footer */
  }
  
  /* Reduce footer padding */
  footer {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
  }
}

/* Multi-view: ensure players stay in viewport and don't overlap */
#multi-view-modal {
  overflow: hidden !important;
  max-height: 100vh !important;
  max-width: 100vw !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
}

/* Container flex pentru modal - p-4 = 16px padding, gap-4 = 16px gap */
#multi-view-modal > div.relative {
  overflow: hidden !important;
  max-height: 100vh !important;
  max-width: 100vw !important;
  height: 100vh !important;
  width: 100vw !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 1rem !important; /* p-4 = 16px */
  gap: 1rem !important; /* gap-4 = 16px */
  box-sizing: border-box !important;
}

/* Header takes ~56px (h-10 button = 40px + padding) */
#multi-view-modal > div.relative > div:first-child {
  flex-shrink: 0 !important;
  min-height: 3.5rem !important; /* ~56px */
}

#multi-view-grid {
  width: 100% !important;
  max-width: 100% !important;
  flex: 1 1 0 !important; /* Respect flex-1 from HTML */
  min-height: 0 !important; /* Allow shrinking */
  min-width: 0 !important; /* Allow shrinking */
  overflow-y: auto !important; /* Allow scrolling on mobile when content doesn't fit */
  overflow-x: hidden !important;
  box-sizing: border-box !important;
  display: grid !important;
  grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
  gap: 0.75rem !important; /* gap-3 = 12px */
  align-content: start !important;
  padding: 0 !important;
  margin: 0 !important;
  /* Calculate available height: 100vh - padding top (16px) - padding bottom (16px) - gap (16px) - header (~56px) */
  max-height: calc(100vh - 1rem - 1rem - 1rem - 3.5rem) !important;
  -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
  touch-action: pan-y !important; /* Allow vertical scrolling */
}

/* Tablet and desktop: 2 columns */
@media (min-width: 640px) {
  #multi-view-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

.multi-view-slot {
  width: 100% !important;
  max-width: 100% !important;
  overflow: hidden !important;
  position: relative !important;
  box-sizing: border-box !important;
  min-width: 0 !important;
  min-height: 0 !important;
  contain: layout style paint !important;
  isolation: isolate !important;
}

/* Default aspect ratio for slots */
.multi-view-slot {
  aspect-ratio: 16 / 9 !important;
  height: auto !important;
}

.multi-view-slot .mv-container {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

.multi-view-slot .mv-container iframe,
.multi-view-slot .mv-container video,
.multi-view-slot .mv-container .video-js {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain !important;
  box-sizing: border-box !important;
  display: block !important;
  margin: 0 !important;
  padding: 0 !important;
}

/* Multi-view: make 2-up layout taller on desktop */
@media (min-width: 640px) {
  #multi-view-grid.mv-layout-two {
    /* 2 slots: 1 row, no row gap needed */
    grid-auto-rows: 1fr !important;
    grid-template-rows: 1fr !important;
    height: 100% !important;
  }
  #multi-view-grid.mv-layout-two .multi-view-slot {
    aspect-ratio: auto !important;
    height: 100% !important;
    max-height: 100% !important;
  }
}

/* Ensure 3-4 slot layouts also fit properly */
#multi-view-grid:not(.mv-layout-two) {
  /* 3-4 slots: 2 rows, 1 gap between rows (12px) */
  grid-auto-rows: minmax(0, auto) !important;
  max-height: 100% !important;
}

/* For 3-4 slots: calculate max height per slot considering:
   - Available grid height (calculated above)
   - 2 rows
   - 1 gap between rows (12px = 0.75rem)
   Each slot max height = (available height - gap) / 2 */
#multi-view-grid:not(.mv-layout-two) .multi-view-slot {
  aspect-ratio: 16 / 9 !important;
  height: auto !important;
  /* Available height = calc(100vh - 1rem - 1rem - 1rem - 3.5rem) = calc(100vh - 5.5rem)
     Per slot = (available - 0.75rem gap) / 2 */
  max-height: calc((100vh - 5.5rem - 0.75rem) / 2) !important;
}

/* On mobile, single column - all slots stack vertically */
@media (max-width: 639px) {
  #multi-view-grid:not(.mv-layout-two) .multi-view-slot {
    /* On mobile, slots stack, so each can be smaller */
    max-height: calc((100vh - 5.5rem - 0.75rem) / 4) !important; /* Worst case: 4 slots */
  }
}

/* Multi-view: enable touch interaction with YouTube iframes on mobile */
.multi-view-slot .mv-container {
  position: relative;
}

.multi-view-slot .mv-container iframe {
  pointer-events: auto;
  touch-action: manipulation;
  position: relative;
  z-index: 1;
}

/* YouTube overlay for touch interaction */
.mv-youtube-overlay {
  pointer-events: none;
  z-index: 5;
}

/* Ensure control buttons work but don't block iframe touch on mobile */
@media (max-width: 639px) {
  /* Multi-view slot should create a stacking context */
  .multi-view-slot {
    position: relative;
    z-index: 0;
  }
  
  /* Buttons container (div with absolute positioning) should be above iframe and Video.js */
  .multi-view-slot > div.absolute:has(.mv-btn) {
    z-index: 9999 !important; /* Very high z-index to ensure buttons container is above everything, including YouTube controls */
    position: absolute !important;
    pointer-events: none !important; /* Allow clicks to pass through container to buttons */
    isolation: isolate; /* Create new stacking context */
  }
  
  /* Buttons are positioned absolutely in the slot, need high z-index */
  .multi-view-slot .mv-btn {
    pointer-events: auto !important; /* Buttons should always be clickable */
    z-index: 10000 !important; /* Very high z-index to ensure buttons are above YouTube iframe, controls, and Video.js */
    position: relative !important;
    isolation: isolate; /* Create new stacking context */
    transform: translateZ(0); /* Force hardware acceleration and new stacking context */
  }
  
  /* Add channel button (.mv-empty) needs same treatment as control buttons */
  .multi-view-slot .mv-empty {
    pointer-events: auto !important; /* Button should always be clickable */
    z-index: 10000 !important; /* Very high z-index to ensure button is above YouTube iframe, controls, and Video.js */
    position: absolute !important;
    isolation: isolate; /* Create new stacking context */
    transform: translateZ(0); /* Force hardware acceleration and new stacking context */
  }
  
  /* Ensure iframe can receive touch events when buttons are not being touched */
  .multi-view-slot .mv-container iframe {
    pointer-events: auto !important;
    z-index: 1 !important;
    position: relative;
  }
  
  /* Ensure container doesn't block touch events */
  .multi-view-slot .mv-container {
    touch-action: manipulation;
    position: relative;
    z-index: 1;
  }
  
  /* Only disable pointer-events for overlays, NOT for Video.js or video elements */
  .multi-view-slot .mv-youtube-overlay {
    pointer-events: none;
  }
  
  /* Ensure Video.js and video elements can receive touch events */
  .multi-view-slot .mv-container .video-js,
  .multi-view-slot .mv-container video {
    pointer-events: auto !important;
    z-index: 10 !important;
    position: relative;
  }
  
  /* Video.js controls should be clickable */
  .multi-view-slot .mv-container .vjs-control-bar,
  .multi-view-slot .mv-container .vjs-control,
  .multi-view-slot .mv-container .vjs-big-play-button,
  .multi-view-slot .mv-container .vjs-control-bar * {
    pointer-events: auto !important;
    z-index: 15 !important;
  }
}

/* Ensure player-multiview button is visible and properly styled on mobile */
#player-multiview {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  align-items: center !important;
  justify-content: center !important;
}

@media (max-width: 639px) {
  #player-multiview {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}