/* ============================================================
   SRDELI — Multiview (multiview-fs.css) v3.1
   ------------------------------------------------------------
   DESIGN PRINCIPLE: The stage is INVISIBLE.
   Only tiles are visible. Empty space shows the page background.

   OVERLAY LAYOUT (top-left to right):
   [drag-handle] [name-label · viewers]     [X-remove]
   All overlay elements share opacity behavior:
   hidden by default, shown via .mv216-show-overlay,
   :hover, :focus-within, .is-dragging, .is-drop-target.

   JS INLINE-STYLE CONSTRAINTS:
   - layout(): sets left/top/width/height on slots (plain)
   - alignSuggestBox(): !important left/top/width (viewport coords)
     → suggest must be position:fixed
   - hardenNativeFrameFullscreen(): !important on fullscreen frame
   ============================================================ */

/* ═══════════════════════════════════════════
   1. PAGE WRAPPER — fills viewport, no scroll
   ═══════════════════════════════════════════ */
body:has(.mv216-page),
body:has(#mv216-page) {
  overflow: hidden;
}
.container:has(.mv216-page),
main.container:has(#mv216-page) {
  height: calc(100svh - var(--topbar));
  min-height: 0;
  padding: var(--sp-3) var(--page-pad) var(--sp-3);
  display: flex;
  flex-direction: column;
  max-width: var(--container);
}

.mv216-page,
#mv216-page {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  max-width: 100%;
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   2. HEADER
   ═══════════════════════════════════════════ */
.mv216-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--hairline);
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.mv216-titleblock h1 {
  font-size: clamp(20px, 2.6vw, 26px);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}
.mv216-titleblock p {
  margin-top: 4px;
  color: var(--text-2);
  font-size: 13px;
}
.mv216-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* 2-stream layout switcher */
.mv216-layout,
#mv216-layout {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 2px;
  gap: 2px;
}
.mv216-layout[hidden],
#mv216-layout[hidden] { display: none; }
.mv216-layout button,
#mv216-layout button {
  width: 30px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  color: var(--text-3);
  font-size: 15px;
  line-height: 1;
  border-radius: var(--r-xs);
  padding: 0 !important;
  transition: background var(--t-fast), color var(--t-fast);
}
.mv216-layout button:hover,
#mv216-layout button:hover { background: var(--surface-3) !important; color: var(--text); }
.mv216-layout button.is-active,
#mv216-layout button.is-active {
  background: var(--surface-4) !important;
  color: var(--text);
}

.mv216-mainbtn,
#mv216-fullscreen.mv216-mainbtn {
  padding: 7px 14px !important;
  font-size: 12px !important;
  font-weight: 600 !important;
}

/* ═══════════════════════════════════════════
   3. TOOLBAR
   ═══════════════════════════════════════════ */
.mv216-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.mv216-add,
#mv216-add {
  display: flex;
  align-items: stretch;
  gap: var(--sp-2);
  flex: 1;
  max-width: 400px;
  position: relative;
}
#mv216-input {
  flex: 1;
  background: var(--surface-2);
  padding: 8px 14px;
  font-size: 13px;
  height: 36px;
}
#mv216-input:focus {
  background: var(--surface-3);
  box-shadow: 0 0 0 1px var(--accent-line);
}
.mv216-add .srd-plus-submit { height: 36px; }
.mv216-secondary,
#mv216-clear {
  padding: 7px 14px !important;
  font-size: 12px !important;
  font-weight: 500;
}

/* ═══════════════════════════════════════════
   4. SUGGEST DROPDOWN
   JS alignSuggestBox() uses viewport coordinates (getBoundingClientRect)
   WITHOUT scroll offset → must be position:fixed.
   ═══════════════════════════════════════════ */
.mv216-suggest,
#mv216-suggest {
  position: fixed;
  z-index: 220;
  background: var(--surface);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r);
  padding: 4px;
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.mv216-suggest[hidden],
#mv216-suggest[hidden] { display: none; }

/* ═══════════════════════════════════════════
   5. STAGE — INVISIBLE, fills remaining space
   ═══════════════════════════════════════════ */
.mv216-stage,
#mv216-stage {
  position: relative;
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  /* NO background, NO border, NO shadow, NO border-radius */
}

/* Empty state — just text */
.mv216-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
  padding: var(--sp-6);
}

/* ═══════════════════════════════════════════
   6. SLOTS
   position:absolute — JS sets left/top/width/height.
   No padding — tiles fill their computed rect exactly.
   Gap between tiles is created by the JS compute() function
   (gap=14px), not by CSS padding.
   ═══════════════════════════════════════════ */
.mv216-slot {
  position: absolute;
  box-sizing: border-box;
  /* No padding — tile fills its rect exactly */
}

.mv216-frame {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
  border-radius: var(--r);
  overflow: hidden;
  transition: opacity var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.mv216-media {
  position: absolute;
  inset: 0;
  background: #000;
}
.mv216-media video {
  width: 100% !important;
  height: 100% !important;
  background: #000;
  object-fit: cover;
}
/* When a tile is gated, hide only the <video> element — the access gate
   panel (.mv216-access) must remain visible so the user sees the password
   form / whitelist message / offline message instead of a black tile. */
.mv216-media-gated > video { display: none; }
.mv216-frame.mv216-frame-gated .mv216-media > video { display: none; }

/* ═══════════════════════════════════════════
   7. SLOT OVERLAY — all elements share opacity
   Layout: [drag] [name · viewers] ... [X]
   Top row spans full width. All elements auto-hide.
   ═══════════════════════════════════════════ */

/* Bottom fade — on the frame, full-width, no gaps */
.mv216-frame::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 80px;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.65) 0%, transparent 100%);
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transition: opacity var(--t);
}
.mv216-frame.mv216-show-overlay::after { opacity: 1; }

.mv216-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--t);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: var(--sp-2);
  gap: var(--sp-2);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, transparent 30%);
}
.mv216-frame.mv216-show-overlay .mv216-overlay,
.mv216-frame:hover .mv216-overlay,
.mv216-frame:focus-within .mv216-overlay,
.mv216-slot.is-dragging .mv216-overlay,
.mv216-slot.is-drop-target .mv216-overlay { opacity: 1; }
.mv216-overlay > * { pointer-events: auto; }

/* Top-left cluster: drag handle + name label + viewers (flex row) */
.mv216-drag-button,
.mv216-name-label,
.mv216-viewers {
  position: static;
  flex: 0 0 auto;
}

/* Drag handle (first item in flex row) — stands out as a draggable element */
.mv216-drag-button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: var(--r-sm);
  cursor: grab;
  padding: 0;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.mv216-drag-button:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--accent-2);
  transform: scale(1.15);
}
.mv216-drag-button:active { cursor: grabbing; }
.mv216-drag-button svg { width: 14px; height: 14px; }

/* Name label (second item in flex row) */
.mv216-name-label {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: calc(100% - 120px);
  background: transparent;
  color: #fff;
  padding: 0;
  border-radius: 0;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-ui);
  line-height: 28px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--t-fast);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.9);
}
.mv216-name-label:hover { color: var(--accent-2); }
.mv216-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Viewer count — right next to the name label, same font/style */
.mv216-viewers {
  display: inline-flex;
  align-items: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-ui);
  line-height: 28px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.9);
  padding: 0;
  background: transparent;
}

/* Remove button (X) — right edge, vertically centered at 75% (original position)
   Default signal red, always visible (new feature, needs to be obvious) */
.mv216-remove {
  position: absolute;
  right: 10px;
  top: 75%;
  transform: translateY(-50%);
  z-index: 27;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--live);
  color: #fff;
  border-radius: var(--r-sm);
  font-size: 18px;
  line-height: 1;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t), transform var(--t-fast), background var(--t-fast);
}
.mv216-frame.mv216-show-overlay .mv216-remove,
.mv216-frame:hover .mv216-remove,
.mv216-frame:focus-within .mv216-remove,
.mv216-slot.is-dragging .mv216-remove,
.mv216-slot.is-drop-target .mv216-remove {
  opacity: 1;
  pointer-events: auto;
}
/* When a tile is gated, keep the remove (×) button visible so the user can
   always remove the tile — even without hovering. The button keeps its
   default position (bottom-right area); this only forces opacity. */
.mv216-frame.mv216-frame-gated .mv216-remove {
  opacity: 1;
  pointer-events: auto;
}
/* Bei einem gated Tile (offline / Passwort / Whitelist) deckt das Gate
   (.mv216-access, z-index 6, schwarzer Hintergrund) sonst die obere
   UI-Schicht ab — man sähe nicht, WELCHER Kanal hier zugefügt und offline
   ist. Deshalb liegt das Overlay (Drag-Handle + Username + Viewer-Zahl) bei
   gateten Tiles ÜBER dem Gate und bleibt dauerhaft sichtbar. */
.mv216-frame.mv216-frame-gated .mv216-overlay {
  opacity: 1;
  z-index: 8;
}
.mv216-remove:hover {
  background: #ff2a32;
  color: #fff;
  transform: translateY(-50%) scale(1.12);
}

/* ═══════════════════════════════════════════
   8. SLOT LOADING SPINNER
   ═══════════════════════════════════════════ */
.mv216-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  z-index: 5;
}
.mv216-loading[hidden] { display: none; }
.mv216-spinner {
  width: 28px;
  height: 28px;
  border-radius: var(--r-pill);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--text);
  animation: mv216-spin 0.9s linear infinite;
}
@keyframes mv216-spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════
   9. SLOT FREEZE OVERLAY
   ═══════════════════════════════════════════ */
.mv216-freeze-overlay {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-color: #000;
  z-index: 3;
  pointer-events: none;
  opacity: 0.85;
}
/* Kein Reconnecting-Text-Badge mehr (siehe channel-clean.css): während eines
   Reconnects zeigt das Tile das eingefrorene letzte Bild plus den
   durchlaufenden Spinner (.mv216-loading). Die Klasse
   .mv216-freeze-reconnecting wird vom JS nicht mehr gesetzt. */

/* ═══════════════════════════════════════════
   10. SLOT CONTEXT SURFACE
   ═══════════════════════════════════════════ */
.srd-context-surface {
  position: absolute;
  inset: 0;
  z-index: 2;
}

/* ═══════════════════════════════════════════
   11. SLOT MINI CONTROLS — icons only, no solid background
   ═══════════════════════════════════════════ */
.srd-player-controls,
.srd-player-controls-mini {
  position: absolute;
  bottom: var(--sp-2);
  left: var(--sp-2);
  right: var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0;
  background: transparent;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t);
}
.mv216-frame.mv216-show-overlay .srd-player-controls,
.mv216-frame.mv216-show-overlay .srd-player-controls-mini,
.mv216-frame:focus-within .srd-player-controls,
.mv216-frame:focus-within .srd-player-controls-mini {
  opacity: 1;
  pointer-events: auto;
}
.srd-player-controls > *,
.srd-player-controls-mini > * { pointer-events: auto; }

.srd-ctrl {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 0 !important;
  transition: color var(--t-fast), transform var(--t-fast);
  flex: 0 0 auto;
}
.srd-ctrl:hover { color: var(--accent-2); transform: scale(1.15); }
.srd-ctrl svg { width: 18px; height: 18px; }

.srd-volume {
  -webkit-appearance: none;
  appearance: none;
  width: 80px !important;
  max-width: 80px !important;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--r-pill);
  outline: 0;
  cursor: pointer;
  flex: 0 0 auto;
}
.srd-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--text);
  border-radius: var(--r-pill);
  border: 0;
  cursor: pointer;
}
.srd-volume::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--text);
  border-radius: var(--r-pill);
  border: 0;
  cursor: pointer;
}
.srd-control-spacer { flex: 1; }

/* ═══════════════════════════════════════════
   12. SLOT ACCESS GATE
   The gate panel itself (.chan297-gate and friends) is styled by
   channel-clean.css — loaded on this page so the multiview tiles use the
   exact same gate look as the single-channel page. This section only
   styles the .mv216-access wrapper that centers the panel inside a tile
   and keeps the remove (×) button above it.
   ═══════════════════════════════════════════ */
.mv216-access {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: var(--sp-3);
}
.mv216-access[hidden] { display: none; }
/* The gate panel sits below the remove (×) button. The remove button has
   its own z-index (7) so it stays clickable above the gate. */
.mv216-access .chan297-gate {
  max-width: calc(100% - 24px);
}

/* ═══════════════════════════════════════════
   13. DRAG AND DROP — COMPLETE VISUAL STATES
   ═══════════════════════════════════════════ */
.mv216-slot.is-dragging {
  z-index: 10;
}
.mv216-slot.is-dragging .mv216-frame {
  opacity: 0.3;
  transform: scale(0.97);
}

/* Drop target — clear dashed outline */
.mv216-slot.is-drop-target { z-index: 5; }
.mv216-slot.is-drop-target::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px dashed rgba(255, 255, 255, 0.4);
  border-radius: var(--r);
  pointer-events: none;
  z-index: 20;
  animation: dash-pulse 1.2s ease-in-out infinite;
}
@keyframes dash-pulse {
  0%, 100% { border-color: rgba(255, 255, 255, 0.35); }
  50% { border-color: rgba(255, 255, 255, 0.6); }
}

/* Body during drag */
body.mv216-dragging-body {
  cursor: grabbing !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}
body.mv216-dragging-body * { cursor: grabbing !important; }

/* Ghost */
.mv216-drag-ghost {
  position: fixed;
  z-index: 2147483646;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px 14px 6px 8px;
  background: var(--surface-4);
  color: var(--text);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  transform: translate(14px, 14px);
}
.mv216-drag-ghost-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: var(--accent-soft);
  color: var(--text);
  border-radius: var(--r-pill);
}
.mv216-drag-ghost-icon svg { width: 12px; height: 12px; }

/* ═══════════════════════════════════════════
   14. FULLSCREEN MODE
   ═══════════════════════════════════════════ */
html.mv216-fullscreen {
  background: #000;
  overflow: hidden;
}
html.mv216-fullscreen body { background: #000; }
html.mv216-fullscreen .topbar,
html.mv216-fullscreen .shell-topbar,
html.mv216-fullscreen .topbar-v234 { display: none; }
html.mv216-fullscreen main.container { padding: 0; max-width: none; min-height: 0; }
html.mv216-fullscreen .mv216-head,
html.mv216-fullscreen .mv216-toolbar { display: none; }

html.mv216-fullscreen .mv216-page,
html.mv216-fullscreen #mv216-page {
  max-width: none;
  height: 100vh;
  padding: 0;
  gap: 0;
}
html.mv216-fullscreen .mv216-stage,
html.mv216-fullscreen #mv216-stage {
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  min-height: 0;
}

/* Floating chrome bar */
.mv216-float,
#mv216-float {
  position: fixed;
  top: var(--sp-3);
  right: var(--sp-3);
  z-index: 2147483646;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px;
  background: rgba(20, 20, 20, 0.8);
  border: 1px solid var(--hairline-2);
  border-radius: var(--r);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t);
}
html.mv216-show-float .mv216-float,
html.mv216-show-float #mv216-float { opacity: 1; pointer-events: auto; }
.mv216-float[hidden],
#mv216-float[hidden] { display: none; }

#mv216-float-layout,
#mv216-exit {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  border-radius: var(--r-sm);
  padding: 0 !important;
  transition: background var(--t-fast);
}
#mv216-float-layout:hover,
#mv216-exit:hover { background: rgba(255, 255, 255, 0.1) !important; color: var(--text); }

/* ═══════════════════════════════════════════
   15. SOLO FRAME — when in multiview fullscreen, clicking
   fullscreen on a frame solos it (fills the stage).
   Clicking again exits solo back to multiview grid.
   ═══════════════════════════════════════════ */

/* Non-solo slots: hidden */
html.mv216-fullscreen.mv216-solo-frame .mv216-slot:not(.mv216-solo-slot) {
  display: none !important;
}

/* Solo slot: fills the stage */
html.mv216-fullscreen.mv216-solo-frame .mv216-slot.mv216-solo-slot {
  display: block !important;
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  right: auto !important;
  bottom: auto !important;
  width: 100% !important;
  height: 100% !important;
}

/* Solo frame: fills the slot */
html.mv216-fullscreen.mv216-solo-frame .mv216-frame.mv216-frame-solo {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border: 0 !important;
  border-radius: 0 !important;
}

/* Solo frame media: fill */
html.mv216-fullscreen.mv216-solo-frame .mv216-frame.mv216-frame-solo .mv216-media,
html.mv216-fullscreen.mv216-solo-frame .mv216-frame.mv216-frame-solo .mv216-media video {
  width: 100% !important;
  height: 100% !important;
}

/* Non-fullscreen solo (shouldn't happen, but just in case) */
html.mv216-solo-frame .mv216-slot:not(.mv216-solo-slot) { z-index: 1; }
html.mv216-solo-frame .mv216-slot:not(.mv216-solo-slot) .mv216-frame { opacity: 0.2; }
.mv216-slot.mv216-solo-slot { z-index: 10; }
.mv216-frame.mv216-frame-solo {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12);
}

/* Native frame fullscreen — JS hardens with !important inline */
.mv216-frame.mv216-native-fullscreen { /* styled by JS inline !important */ }

/* ═══════════════════════════════════════════
   16. RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 720px) {
  body:has(.mv216-page),
  body:has(#mv216-page) { overflow: auto; }
  .container:has(.mv216-page),
  main.container:has(#mv216-page) {
    height: auto;
    min-height: calc(100vh - var(--topbar));
  }
  .mv216-page, #mv216-page { height: auto; overflow: visible; }
  .mv216-head { flex-direction: column; align-items: flex-start; gap: var(--sp-3); }
  .mv216-add, #mv216-add { max-width: none; }
  .mv216-toolbar { flex-direction: column; align-items: stretch; }
  .mv216-stage, #mv216-stage { flex: 1 1 300px; min-height: 280px; }
}
