/**
 * Layout Styles
 * Split mode, stacked containers, fit mode
 */

:root {
  --accent-primary: #5bc0be;
  --accent-secondary: #47a2a0;
  --accent-danger: #e74c3c;
  --accent-warning: #f39c12;
  --bg-primary: #0a0e14;
  --bg-secondary: #131920;
  --bg-tertiary: #1a222c;
  --text-primary: #e8edf3;
  --text-secondary: #8b95a5;
  --border-color: rgba(91, 192, 190, 0.2);
  --shadow-color: rgba(0, 0, 0, 0.3);
  --transition-fast: 0.2s ease;
}

.stacked-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==========================================
   FIT MODE
   ========================================== */
.video-area.fit-mode video {
  object-fit: contain;
  background: #000;
}

.video-area.fit-mode .video-panel {
  background: #000;
}

/* ==========================================
   LAYOUT MODE CLASSES
   ========================================== */
.video-area {
  transition: flex-direction 0.3s ease;
}

.video-panel {
  /* No transition on flex - handled dynamically by JS during drag */
}

/* ==========================================
   SPLIT MODE PANEL ORDERING - Swaps left/right visually
   ========================================== */
.video-area.mode-split .video-panel {
  order: 0;
}
.video-area.mode-split .split-resizer {
  order: 1;
}
/* When self is first (isSelfFirst = true): self on left, remote on right */
.video-area.mode-split .video-panel.left-panel {
  order: 1;
}
.video-area.mode-split .split-resizer {
  order: 2;
}
.video-area.mode-split .video-panel.right-panel {
  order: 3;
}

.video-panel.no-transition {
  transition: none !important;
}

/* ==========================================
   MOBILE LAYOUT
   ========================================== */
@media (max-width: 768px) {
  .video-area.mode-split {
    flex-direction: column;
  }

  .video-area.mode-split .video-panel.left-panel,
  .video-area.mode-split .video-panel.right-panel {
    width: 100%;
  }

  .video-area.mode-split .video-panel.left-panel {
    height: 40%;
  }

  .video-area.mode-split .video-panel.right-panel {
    height: 60%;
  }

  .split-resizer {
    width: 100%;
    height: 8px;
    cursor: row-resize;
  }

  .resizer-track {
    width: 100%;
    height: 100%;
  }

  .stacked-container {
    bottom: 8px;
    right: 8px;
  }

  .stacked-item {
    width: 80px;
  }
}

/* ==========================================
   LANDSCAPE ORIENTATION
   ========================================== */
@media (orientation: landscape) and (max-height: 500px) {
  .video-area.mode-split {
    flex-direction: row;
  }

  .video-area.mode-split .video-panel.left-panel,
  .video-area.mode-split .video-panel.right-panel {
    height: 100%;
  }

  .split-resizer {
    width: 8px;
    height: 100%;
    cursor: col-resize;
  }

  .resizer-track {
    width: 100%;
    height: 100%;
  }
}

/* ==========================================
   MODE CONTAINERS - Show/Hide based on mode
   ========================================== */
.split-mode-container {
  position: absolute;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
}

.pip-mode-container {
  position: absolute;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  background: #000;
}

/* Show/hide based on body class */
body.pip-mode .split-mode-container {
  display: none;
}

body.pip-mode .pip-mode-container {
  display: flex;
}

/* When in pip-mode class on body, hide split and show pip */
.video-area.mode-pip ~ .pip-mode-container {
  display: flex;
}

.video-area.mode-pip ~ .split-mode-container {
  display: none;
}

/* ==========================================
   NEW PiP MODE STYLES
   ========================================== */

/* PiP Overlay - draggable, resizable container */
.pip-overlay {
  position: absolute;
  z-index: 1000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  user-select: none;
  min-width: 120px;
  min-height: 160px;
  max-width: 600px;
  background: rgba(0, 0, 0, 0.9);
  /* Default position - will be set by JS */
  left: 20px;
  top: 20px;
  width: 320px;
  /* Height auto - let content determine height */
  height: auto;
  display: flex;
  flex-direction: column;
}

/* PiP Main Panel - shows the main content type (takes remaining space) */
.pip-main-panel {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
}

.pip-main-panel .pip-main-content {
  width: 100%;
  height: 100%;
}

.pip-main-panel .pip-main-content video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Mirror self webcam in PiP main panel (not screen share) */
.pip-main-panel[data-content-type="self-webcam"] video {
  transform: scaleX(-1);
}

/* PiP Main Panel Header (matches slot header style) */
.pip-main-panel .video-panel-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  pointer-events: none;
}

/* PiP Stack Container - vertical layout for slots (below main panel) */
.pip-stack-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.85);
  overflow: visible;
}

/* Individual PiP Video Slot */
.pip-video-slot {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  overflow: hidden;
  background: #000;
  min-height: 120px;
  min-width: 120px;
}

.pip-video-slot video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Mirror self webcam in PiP slots (not screen share) */
.pip-video-slot[data-content-type="self-webcam"] video {
  transform: scaleX(-1);
}

/* PiP Slot Header (matches main panel header style) */
.pip-video-slot .video-panel-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  pointer-events: none;
}

/* PiP Slot Swap Button */
.pip-video-slot .pip-swap-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.pip-video-slot .pip-swap-btn:hover {
  opacity: 1;
  background: rgba(91, 192, 190, 0.8);
}

/* ==========================================
   FIT MODE - object-fit: contain for all videos
   ========================================== */

/* Fit mode for split mode videos */
.video-area.fit-mode video {
  object-fit: contain;
}

/* Fit mode for PiP mode videos - main panel and stack slots */
.call-page.fit-mode .pip-main-panel .pip-main-content video,
.call-page.fit-mode .pip-video-slot video {
  object-fit: contain;
}

/* PiP Resize Handles - Enhanced for mobile touch */
.pip-overlay-handle {
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Larger invisible hit areas for mobile */
.pip-overlay-handle::before {
  content: '';
  position: absolute;
  display: block;
}

/* Corner handles - larger hit area */
.pip-overlay-handle-nw::before,
.pip-overlay-handle-ne::before,
.pip-overlay-handle-sw::before,
.pip-overlay-handle-se::before {
  width: 44px;
  height: 44px;
}

.pip-overlay-handle-nw::before {
  top: -12px;
  left: -12px;
}

.pip-overlay-handle-ne::before {
  top: -12px;
  right: -12px;
}

.pip-overlay-handle-sw::before {
  bottom: -12px;
  left: -12px;
}

.pip-overlay-handle-se::before {
  bottom: -12px;
  right: -12px;
}

/* Edge handles - larger hit area */
.pip-overlay-handle-n::before,
.pip-overlay-handle-s::before {
  width: 100%;
  height: 44px;
  left: 0;
}

.pip-overlay-handle-n::before {
  top: -12px;
}

.pip-overlay-handle-s::before {
  bottom: -12px;
}

.pip-overlay-handle-e::before,
.pip-overlay-handle-w::before {
  width: 44px;
  height: 100%;
  top: 0;
}

.pip-overlay-handle-e::before {
  right: -12px;
}

.pip-overlay-handle-w::before {
  left: -12px;
}

/* Handle visibility on hover */
.pip-overlay:hover .pip-overlay-handle:not(.handle-center) {
  opacity: 0.7;
}

.pip-overlay-handle:not(.handle-center):hover {
  opacity: 1 !important;
}

.handle-center {
  inset: 0;
  cursor: move;
  pointer-events: none;
}

.pip-overlay:hover .handle-center {
  pointer-events: auto;
}

/* Mobile-specific adjustments */
@media (max-width: 768px) {
  .pip-overlay-handle::before {
    width: 56px;
    height: 56px;
  }
  
  .pip-overlay-handle-nw::before,
  .pip-overlay-handle-ne::before,
  .pip-overlay-handle-sw::before,
  .pip-overlay-handle-se::before {
    top: -16px;
    left: -16px;
  }
  
  .pip-overlay-handle-ne::before {
    top: -16px;
    right: -16px;
    left: auto;
  }
  
  .pip-overlay-handle-sw::before {
    bottom: -16px;
    left: -16px;
    top: auto;
  }
  
  .pip-overlay-handle-se::before {
    bottom: -16px;
    right: -16px;
    top: auto;
    left: auto;
  }
  
  .pip-overlay-handle-n::before,
  .pip-overlay-handle-s::before {
    top: -16px;
    height: 56px;
  }
  
  .pip-overlay-handle-s::before {
    bottom: -16px;
    top: auto;
  }
  
  .pip-overlay-handle-e::before,
  .pip-overlay-handle-w::before {
    top: -16px;
    height: 56px;
    width: 56px;
  }
  
  .pip-overlay-handle-w::before {
    left: -16px;
    right: auto;
  }
  
  .pip-overlay-handle-e::before {
    right: -16px;
    left: auto;
  }
}