/* Ultra-Modern Dark Theme UI Design */
.hidden {
  display: none !important;
}

label {
  margin-bottom: 10px;
  display: block;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: #0a0a0a;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  overflow-x: hidden;
  overflow-y: hidden;
  color: #e5e5e5;
  position: relative;
  /* Prevent layout shift from scrollbar */
  width: 100vw;
}

/* Animated background particles effect - slower animation */
.bg-particles {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image:
    radial-gradient(at 15% 15%, rgba(220, 38, 38, 0.08) 0%, transparent 50%),
    radial-gradient(at 85% 20%, rgba(120, 120, 120, 0.04) 0%, transparent 40%),
    radial-gradient(at 50% 80%, rgba(220, 38, 38, 0.06) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
  animation: particleFloat 60s ease-in-out infinite;
}

@keyframes particleFloat {
  0%, 100% {
    transform: translateY(0) scale(1);
    opacity: 0.6;
  }
  50% {
    transform: translateY(-20px) scale(1.05);
    opacity: 1;
  }
}

/* Red gradient background spanning from header to footer */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(ellipse at center, rgba(220, 38, 38, 0.12) 0%, rgba(220, 38, 38, 0.06) 30%, rgba(0, 0, 0, 0) 60%);
  pointer-events: none;
  z-index: 1;
}

/* Modern header with compact height - flex layout */
.header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 2rem;
  background: rgba(15, 15, 15, 0.98);
  backdrop-filter: blur(40px) saturate(200%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.3),
    0 8px 40px rgba(0, 0, 0, 0.6),
    0 0 80px rgba(220, 38, 38, 0.03);
  z-index: 100;
  flex-shrink: 0;
  min-height: 70px;
  max-height: 70px;
  flex-wrap: wrap;
}

/* Animated accent line with much slower gradient shimmer */
.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(220, 38, 38, 0.2) 10%,
    rgba(220, 38, 38, 0.5) 30%,
    rgba(220, 38, 38, 0.8) 50%,
    rgba(220, 38, 38, 0.5) 70%,
    rgba(220, 38, 38, 0.2) 90%,
    transparent 100%);
  background-size: 200% 100%;
  animation: shimmerMove 12s linear infinite;
}

@keyframes shimmerMove {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Header sections with flex layout */
.header-left {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex: 0 0 auto;
  z-index: 2;
}

.header-center {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  pointer-events: none;
}

.header-center p-heading {
  pointer-events: auto;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 0 0 auto;
  z-index: 2;
  flex-wrap: wrap;
}

.header-logo {
  width: 100%;
  max-width: 180px;
  max-height: 50px; /* Constrain height to prevent overflow */
  height: auto;
  object-fit: contain; /* Maintain aspect ratio */
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.4));
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  /* Make SVG background transparent by removing mix-blend-mode and adding background transparency */
  background: transparent;
  display: block;
}

.header-logo:hover {
  filter: drop-shadow(0 4px 12px rgba(220, 38, 38, 0.25));
  transform: scale(1.02);
}

.header-title {
  text-align: center;
  margin: 0;
  padding: 0;
}

.header-title p-heading {
  letter-spacing: -0.02em;
  font-weight: 600;
}

/* Username in header */
.text-username {
  justify-self: end;
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.08), rgba(220, 38, 38, 0.04));
  border-radius: 8px;
  border: 1px solid rgba(220, 38, 38, 0.15);
  font-weight: 500;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  white-space: nowrap;
  color: #e5e5e5;
  font-size: 0.875rem;
  line-height: 1.5;
}

.text-username:hover {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.12), rgba(220, 38, 38, 0.06));
  border-color: rgba(220, 38, 38, 0.25);
}

/* Custom buttons matching username style */
.custom-button {
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.08), rgba(220, 38, 38, 0.04));
  border-radius: 8px;
  border: 1px solid rgba(220, 38, 38, 0.15);
  font-weight: 500;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  white-space: nowrap;
  color: #e5e5e5;
  font-size: 0.875rem;
  line-height: 1.5;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  min-width: 120px;
}

.custom-button:hover {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.12), rgba(220, 38, 38, 0.06));
  border-color: rgba(220, 38, 38, 0.25);
}

.custom-button:active {
  transform: translateY(1px);
}

/* Custom select dropdown matching username style */
.custom-select {
  padding: 0.5rem 2.5rem 0.5rem 1rem;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.08), rgba(220, 38, 38, 0.04));
  border-radius: 8px;
  border: 1px solid rgba(220, 38, 38, 0.15);
  font-weight: 500;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  color: #e5e5e5;
  font-size: 0.875rem;
  line-height: 1.5;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  min-width: 220px;
  max-width: 280px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: linear-gradient(135deg, rgba(220, 38, 38, 0.08), rgba(220, 38, 38, 0.04)),
    url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(229, 229, 229, 0.8)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat, no-repeat;
  background-position: right 0.7rem center;
  background-size: auto, 1.2rem;
}

.custom-select:hover {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.12), rgba(220, 38, 38, 0.06)),
    url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(229, 229, 229, 0.8)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat, no-repeat;
  background-position: right 0.7rem center;
  background-size: auto, 1.2rem;
  border-color: rgba(220, 38, 38, 0.25);
}

.custom-select:focus {
  outline: none;
  border-color: rgba(220, 38, 38, 0.4);
  box-shadow: 0 2px 12px rgba(220, 38, 38, 0.2);
}

.custom-select option {
  background: #1a1a1a;
  color: #e5e5e5;
  padding: 0.5rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
  font-weight: 500 !important;
}

.login-button,
.logout-button {
  justify-self: end;
}

/* Hero section for login state */
.hero-section {
  position: relative;
  z-index: 10;
}

.centered-content-headline {
  width: 90%;
  max-width: 900px;
  margin: 3rem auto 1.5rem;
  padding: 0 1.5rem;
  text-shadow: 0 4px 32px rgba(220, 38, 38, 0.3);
  letter-spacing: -0.03em;
  font-weight: 700;
}

.centered-content-text {
  width: 90%;
  max-width: 750px;
  margin: 0 auto 2rem;
  padding: 0 1.5rem;
  line-height: 1.7;
  opacity: 0.8;
  font-size: 1rem;
  font-weight: 400;
}

/* Premium dropdown styling */
p-select {
  align-self: center;
  min-width: 320px;
  flex: 0 1 auto;
}

/* Premium video container with compact spacing */
.video-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  max-width: 1700px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  z-index: 10;
  box-sizing: border-box;
}

/* Content area wrapper - contains both single and quad views */
.content-area {
  position: relative;
  width: 100%;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding-bottom: 70px; /* Reserve space for fixed footer */
  display: flex;
  flex-direction: column; /* Stack items vertically */
  align-items: center; /* Center video players horizontally */
  justify-content: flex-start; /* Align to top */
  box-sizing: border-box;
  /* Calculate width to account for potential scrollbar */
  scrollbar-gutter: stable both-edges;
}

/* Slower pulsing ambient glow */
.video-container::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 85%;
  height: 85%;
  background: radial-gradient(ellipse at center, rgba(220, 38, 38, 0.08) 0%, rgba(220, 38, 38, 0.03) 40%, transparent 70%);
  filter: blur(80px);
  pointer-events: none;
  z-index: -1;
  animation: ambientPulse 15s ease-in-out infinite;
}

@keyframes ambientPulse {
  0%, 100% {
    opacity: 0.5;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1);
  }
}

.video-wrapper {
  position: relative;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  /* Ensure wrapper maintains aspect ratio for proper layout */
  aspect-ratio: 16 / 9;
  box-sizing: border-box;
}

.video-wrapper::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 18px;
  background: linear-gradient(135deg,
    rgba(220, 38, 38, 0.15) 0%,
    rgba(220, 38, 38, 0.05) 25%,
    transparent 50%,
    rgba(120, 120, 120, 0.05) 75%,
    rgba(220, 38, 38, 0.15) 100%);
  background-size: 300% 300%;
  animation: gradientShift 24s ease infinite;
  opacity: 0;
  transition: opacity 0.4s ease;
  z-index: -1;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.video-wrapper:hover::before {
  opacity: 1;
}

video {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  min-height: 200px; /* Prevent video from becoming too small */
  background: transparent !important;
  background-color: transparent !important;
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 24px 72px rgba(0, 0, 0, 0.8),
    0 36px 96px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  position: relative;
  display: block;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  object-fit: contain; /* Ensure video content fits properly */
}

/* Videos are transparent by default - background only shows for placeholder */
video {
  background: transparent !important;
}

video:hover {
  box-shadow:
    0 0 0 1px rgba(220, 38, 38, 0.2),
    0 28px 84px rgba(0, 0, 0, 0.9),
    0 42px 108px rgba(220, 38, 38, 0.12),
    inset 0 1px 0 rgba(220, 38, 38, 0.1);
  transform: translateY(-3px) scale(1.005);
}

.video-overlay {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.03) 0%, transparent 40%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

video:hover + .video-overlay {
  opacity: 1;
}

/* Enhanced control panel with fixed compact height */
.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: rgba(12, 12, 12, 0.98);
  backdrop-filter: blur(40px) saturate(200%);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow:
    0 -1px 3px rgba(0, 0, 0, 0.3),
    0 -12px 40px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.02);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  height: 70px;
  flex-shrink: 0;
  flex-wrap: nowrap;
  overflow: hidden;
}

.controls::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 50%;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(220, 38, 38, 0.3) 30%,
    rgba(220, 38, 38, 0.5) 50%,
    rgba(220, 38, 38, 0.3) 70%,
    transparent 100%);
}


/* Medium screens - prevent early wrapping */
@media (max-width: 1200px) and (min-width: 769px) {
  .header {
    gap: 1rem;
    padding: 0.75rem 1.5rem;
  }

  .header-right {
    gap: 0.75rem;
  }

  .view-mode-button {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    min-width: auto;
  }

  .text-username {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
  }

  .custom-button {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    min-width: 100px;
  }

  .custom-select {
    min-width: 180px;
    max-width: 240px;
    font-size: 0.8125rem;
  }
}

/* Force header wrapping at 1600px to prevent elements from overlapping with title */
@media (max-width: 1600px) and (min-width: 1025px) {
  .header {
    align-items: center; /* Keep items vertically centered */
    padding: 0.75rem 2rem;
    gap: 1rem;
  }

  .header-center {
    position: static; /* Take center out of absolute positioning */
    transform: none;
    order: 2; /* Move title to second position (between logo and right elements) */
    width: auto; /* Only take needed width */
    flex: 1; /* Take remaining space */
    margin: 0;
    text-align: center; /* Center the text */
  }

  .header-center p-heading {
    font-size: 1.25rem; /* Slightly smaller title */
  }

  .header-left {
    order: 1;
    flex-shrink: 0;
  }

  .header-right {
    order: 3; /* Buttons go last, on the right side */
    width: auto; /* Only take needed width */
    flex-shrink: 0;
    justify-content: flex-end; /* Keep buttons on the right */
    gap: 0.75rem; /* Reduced gap between buttons */
  }

  .view-mode-button {
    padding: 0.45rem 0.85rem;
    font-size: 0.8125rem;
  }

  .text-username {
    padding: 0.4rem 0.75rem;
    font-size: 0.8125rem;
  }

  .logout-button {
    padding: 0.45rem 0.85rem;
    font-size: 0.8125rem;
  }

  .header-logo {
    max-width: 160px;
    max-height: 45px;
  }
}

/* Tablet and smaller desktop screens */
@media (max-width: 768px) {
  /* Removed duplicate - see main mobile section below at line ~1100 */
}

/* Mobile phones - Removed duplicate section, see consolidated mobile styles below */
@media (max-width: 500px) {
  /* See consolidated mobile section at end of file */
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  color: #ffffff;
  padding: 1rem 1.5rem;
  border-radius: 12px;
  font-size: 0.9375rem;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.toast.toast-success {
  background: linear-gradient(135deg, rgba(34, 139, 34, 0.9), rgba(46, 125, 50, 0.9));
  border: 1px solid rgba(34, 139, 34, 0.4);
  box-shadow:
    0 0 0 1px rgba(34, 139, 34, 0.2),
    0 12px 32px rgba(0, 0, 0, 0.7),
    0 18px 48px rgba(34, 139, 34, 0.15);
}

.toast.toast-error {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.95), rgba(180, 30, 30, 0.95));
  border: 1px solid rgba(220, 38, 38, 0.3);
  box-shadow:
    0 0 0 1px rgba(220, 38, 38, 0.2),
    0 12px 32px rgba(0, 0, 0, 0.7),
    0 18px 48px rgba(220, 38, 38, 0.15);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* View Mode Selector in Header */
.view-mode-selector {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
  position: relative;
}

.view-mode-button {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.06), rgba(220, 38, 38, 0.03));
  border-radius: 8px;
  border: 1px solid rgba(220, 38, 38, 0.1);
  font-weight: 500;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: rgba(229, 229, 229, 0.7);
  font-size: 0.8125rem;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  min-width: auto;
  justify-content: center;
  white-space: nowrap;
}

.view-mode-button:hover {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.1), rgba(220, 38, 38, 0.05));
  border-color: rgba(220, 38, 38, 0.2);
  color: rgba(229, 229, 229, 0.9);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.15);
}

.view-mode-button.active {
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.15), rgba(220, 38, 38, 0.08));
  border-color: rgba(220, 38, 38, 0.3);
  color: #e5e5e5;
  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.4),
    0 4px 16px rgba(220, 38, 38, 0.2),
    inset 0 1px 0 rgba(220, 38, 38, 0.15);
}

.view-mode-button:active {
  transform: translateY(0);
}

.view-mode-icon {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  transition: transform 0.3s ease;
}

.view-mode-button:hover .view-mode-icon {
  transform: scale(1.1);
}

/* Quad View Layout */
.quad-view-container {
  padding: 1.5rem;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  box-sizing: border-box;
}

.quad-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 1rem;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  box-sizing: border-box;
}

.quad-item {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
}

.quad-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.quad-select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font-size: 0.8125rem;
}

.quad-video {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  min-height: 150px; /* Prevent quad videos from becoming too small */
  background: transparent !important;
  background-color: transparent !important;
  border-radius: 12px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 12px 36px rgba(0, 0, 0, 0.7),
    0 18px 48px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  position: relative;
  display: block;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  object-fit: contain; /* Ensure video content fits properly */
}

/* Quad videos are transparent by default */
.quad-video {
  background: transparent !important;
}

.quad-video:hover {
  box-shadow:
    0 0 0 1px rgba(220, 38, 38, 0.15),
    0 14px 42px rgba(0, 0, 0, 0.8),
    0 21px 56px rgba(220, 38, 38, 0.1),
    inset 0 1px 0 rgba(220, 38, 38, 0.08);
  transform: translateY(-2px);
}

/* Video placeholder for empty slots (both single and quad) */
.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(15, 15, 15, 0.95) 0%, rgba(10, 10, 10, 0.98) 100%);
  border-radius: 12px;
  border: 1px dashed rgba(220, 38, 38, 0.2);
  transition: all 0.3s ease;
  pointer-events: none;
}

/* Hide placeholder when video has source for both single and quad view */
/* Use general sibling combinator (~) instead of adjacent (+) because .video-placeholder is not always immediately adjacent to the <video> or .quad-video element in the DOM.
   This ensures the placeholder is hidden whenever a valid video source is present, regardless of their relative positions within the parent container. */
video[src]:not([src=""]) ~ .video-placeholder,
.quad-video[src]:not([src=""]) ~ .video-placeholder {
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

.placeholder-icon {
  width: 48px;
  height: 48px;
  color: rgba(220, 38, 38, 0.3);
  margin-bottom: 0.5rem;
}

.placeholder-text {
  color: rgba(229, 229, 229, 0.4);
  font-size: 0.875rem;
  font-weight: 500;
  margin: 0;
  letter-spacing: 0.02em;
}

/* View-specific controls visibility */
.single-view-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.quad-view-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

/* Informational message about stream privileges */
.stream-info-message {
  position: relative;
  z-index: 10;
  width: auto; /* Only as wide as content needs */
  max-width: 90%; /* Prevent overflow on small screens */
  margin: 0 auto 1.5rem;
  padding: 0.75rem 1.5rem;
  text-align: center;
  background: rgba(15, 15, 15, 0.6);
  backdrop-filter: blur(20px);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  opacity: 0.8;
  transition: opacity 0.3s ease, transform 0.2s ease;
  box-sizing: border-box;
  flex-shrink: 0; /* Prevent shrinking */
}

.stream-info-message:hover {
  opacity: 1;
  transform: translateY(-2px);
}

.stream-info-message p-text {
  color: rgba(255, 255, 255, 0.7);
  line-height: 1.6;
  display: block;
}

/* ========================================
   RESPONSIVE DESIGN - Mobile & Tablet
   ========================================

   Breakpoints:
   - Desktop:       > 1024px  (2x2 quad grid)
   - Tablet:        769-1024px (2x2 quad grid)
   - Mobile/Phone:  ≤ 768px   (vertical stack)
   - Small Mobile:  ≤ 500px   (optimized vertical stack)
   ======================================== */

/* Tablet and below (max-width: 1024px) - Continue single-line layout */
@media (max-width: 1024px) and (min-width: 769px) {
  .header {
    align-items: center;
    padding: 0.75rem 1.5rem;
    gap: 0.75rem;
  }

  .header-center {
    position: static;
    transform: none;
    order: 2;
    width: auto;
    flex: 1;
    margin: 0;
    text-align: center;
  }

  .header-center p-heading {
    font-size: 1rem;
  }

  .header-left {
    order: 1;
    flex-shrink: 0;
  }

  .header-right {
    order: 3;
    width: auto;
    flex-shrink: 0;
    justify-content: flex-end;
    gap: 0.5rem;
  }

  .header-logo {
    max-width: 140px;
    max-height: 40px;
  }

  .view-mode-button {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
  }

  .text-username {
    padding: 0.4rem 0.65rem;
    font-size: 0.75rem;
  }

  .logout-button {
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
  }

  .controls {
    height: 60px;
    padding: 0.5rem 1rem;
    gap: 0.75rem;
  }

  .content-area {
    padding-bottom: 60px;
  }

  /* Keep 2x2 grid on tablets (landscape mode) */
  .quad-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
  body {
    overflow-y: auto; /* Allow body scrolling on mobile */
  }

  .header {
    flex-direction: column;
    align-items: center;
    min-height: auto;
    max-height: none;
    position: relative;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }

  .header-left {
    width: 100%;
    justify-content: center;
    order: 1;
  }

  .header-logo {
    max-width: 160px;
  }

  .header-center {
    position: static;
    transform: none;
    width: 100%;
    order: 2;
    margin: 0;
  }

  .header-center p-heading {
    text-align: center;
    font-size: 1.125rem;
  }

  .header-right {
    width: 100%;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0.75rem;
    order: 3;
    padding: 0 0; /* No additional padding needed, using header padding */
  }

  .view-mode-selector {
    width: 100%;
    justify-content: center;
    flex-direction: row;
  }

  .view-mode-button {
    flex: 1;
    font-size: 0.8125rem;
    padding: 0.625rem 0.875rem;
    min-width: 0;
    justify-content: center;
  }

  .text-username {
    width: 100%;
    text-align: center;
  }

  .custom-button {
    width: 100%;
    padding: 0.5rem 0.75rem; /* Reduced padding to save space */
    font-size: 0.875rem; /* Slightly smaller font */
  }

  .controls {
    position: fixed; /* Keep footer fixed at bottom on mobile */
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    min-height: 70px;
    max-height: none;
    flex-direction: column;
    gap: 0.75rem; /* Match header gap */
    padding: 0.75rem 1rem; /* Match header horizontal padding */
    flex-shrink: 0;
    z-index: 90; /* Ensure it stays on top */
  }

  .content-area {
    padding-bottom: 200px; /* Reserve space for fixed footer on mobile - taller due to stacked controls */
    padding-top: 0; /* No top padding needed - header is relative positioned and scrolls with content */
    padding-left: 0;
    padding-right: 0;
    overflow-y: visible; /* Changed from auto to visible - let body handle scrolling on mobile */
    overflow-x: hidden;
    align-items: flex-start; /* Align to top to prevent content hiding behind header */
    justify-content: flex-start; /* Align content to top to ensure proper scroll positioning */
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
  }

  .custom-select {
    min-width: 100%;
    max-width: 100%;
  }

  .single-view-controls,
  .quad-view-controls {
    gap: 0.75rem; /* Match header gap on mobile */
    width: 100%;
    flex-direction: column;
  }

  /* CRITICAL: Stack quad view videos vertically on mobile (smartphones) */
  .quad-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.75rem; /* Reduced gap */
    padding: 0.5rem;
    max-width: 100%;
    width: 100%;
    align-items: stretch; /* Ensure items take full width */
  }

  .quad-item {
    width: 100%;
    max-width: 100%;
  }

  /* Ensure video wrappers maintain proper sizing on mobile */
  .video-wrapper {
    width: 100%;
    max-width: 100%;
  }

  /* Optimize video containers on mobile - reduced padding, centered */
  .video-container {
    padding: 0.5rem; /* Reduced padding */
    margin: 0;
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .quad-view-container {
    padding: 0.5rem; /* Reduced padding */
    margin: 0;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column; /* Ensure vertical stacking */
    justify-content: flex-start; /* Start from top */
    align-items: center; /* Center horizontally */
  }

  .single-view-container {
    padding: 0.5rem; /* Reduced padding */
    margin: 0;
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Align to top */
  }
}

/* Small mobile (max-width: 500px) */
@media (max-width: 500px) {
  .toast {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
    padding: 0.875rem 1.25rem;
    font-size: 0.875rem;
  }

  .header {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .header-logo {
    max-width: 140px;
  }

  .header-center p-heading {
    font-size: 1rem;
  }

  .controls {
    padding: 0.5rem; /* Further reduced padding for small mobile */
    gap: 0.375rem; /* Tighter gap */
    min-height: auto; /* Allow natural height based on content */
  }

  /* Adjust content area padding to account for smaller mobile footer */
  .content-area {
    padding-bottom: 180px; /* Adjusted for reduced footer padding */
    padding-top: 0; /* No top padding needed - header is relative positioned */
  }

  .view-mode-button {
    padding: 0.5rem 0.625rem; /* Reduced padding */
    font-size: 0.75rem;
    gap: 0.25rem;
  }

  .view-mode-icon {
    width: 14px;
    height: 14px;
  }

  .text-username {
    font-size: 0.8125rem;
    padding: 0.5rem 0.625rem; /* Reduced padding */
  }

  .custom-button {
    font-size: 0.8125rem;
    padding: 0.5rem 0.625rem; /* Reduced padding to save space */
  }

  /* Optimize video display for small screens */
  video {
    min-height: 150px;
    border-radius: 10px;
  }

  .quad-video {
    min-height: 120px;
    border-radius: 8px;
  }

  /* Ensure quad grid remains single column on small devices */
  .quad-grid {
    display: flex !important;
    flex-direction: column !important;
    padding: 0.25rem;
    gap: 0.5rem; /* Reduced gap */
    width: 100%;
    align-items: stretch; /* Ensure items take full width */
  }

  /* Optimize containers for small mobile - reduced padding, centered */
  .video-container {
    padding: 0.375rem; /* Reduced padding */
    margin: 0;
    width: 100%;
    max-width: 100%;
  }

  .quad-view-container {
    padding: 0.25rem;
    margin: 0;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .single-view-container {
    padding: 0.375rem; /* Reduced padding */
    margin: 0;
    width: 100%;
    max-width: 100%;
  }

  .placeholder-icon {
    width: 36px;
    height: 36px;
  }

  .placeholder-text {
    font-size: 0.75rem;
  }

  .quad-select {
    font-size: 0.75rem;
    padding: 0.4rem 2rem 0.4rem 0.75rem;
  }

  .custom-select {
    font-size: 0.8125rem;
  }

  .centered-content-headline {
    width: 95%;
    font-size: 1.125rem;
    margin: 1.5rem auto 1rem;
  }

  .centered-content-text {
    width: 95%;
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: 1rem;
  }
}

/* iOS Safari specific video fixes for inline playback */
/* Prevent videos from entering fullscreen mode on iOS */
video::-webkit-media-controls-start-playback-button {
  display: none !important;
  -webkit-appearance: none;
}

/* Ensure video elements respect container bounds on iOS */
@supports (-webkit-touch-callout: none) {
  video {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  
  .quad-video {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
  
  /* Safari-specific font rendering improvements for dropdowns */
  .custom-select {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Force font inheritance in Safari */
    font-synthesis: none;
  }
  
  .custom-select option {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Force Safari to use the specified font */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    font-weight: 500 !important;
    font-synthesis: none;
  }
}
