/* ---------- SPECTATOR / SALA DE SITUAÇÃO HUD & PIP SWAP ---------- */
#viewer-app {
  display: flex;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  position: relative;
  overflow: hidden;
  background: #0e1216;
  background-color: #0e1216;
}

/* Barra Superior Tática (HUD) */
#hud-topbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 1300;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(20, 26, 31, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  transition: transform 0.35s cubic-bezier(0.2, 0, 0, 1), opacity 0.3s ease;
}

/* Botão de Recolher HUD */
.hud-collapse-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  transition: all var(--transition-fast);
  margin-left: 4px;
}

.hud-collapse-btn:hover {
  color: #ffffff;
  border-color: var(--accent);
  background: rgba(255, 140, 70, 0.15);
}

/* Botão Flutuante de Expandir HUD */
.hud-expand-btn {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(-65px);
  z-index: 1350;
  background: rgba(20, 26, 31, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--accent);
  border-radius: 20px;
  color: #ffffff;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 5px 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 140, 70, 0.3);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
}

.hud-expand-btn:hover {
  transform: translateX(-50%) translateY(0) scale(1.05);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.9), 0 0 16px rgba(255, 140, 70, 0.5);
}

/* Estado Recolhido do HUD */
#viewer-app.hud-collapsed #hud-topbar {
  transform: translateY(-140%);
  pointer-events: none;
  opacity: 0;
}

#viewer-app.hud-collapsed .hud-expand-btn {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* Ocultar / Mostrar PiP de Vídeo */
#viewer-app.pip-hidden #video-stage-wrap {
  display: none !important;
}

.viewer-pip-restore-btn {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  right: calc(env(safe-area-inset-right, 0px) + 20px);
  z-index: 1250;
  background: rgba(20, 26, 31, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-md);
  color: #ffffff;
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 8px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.85), 0 0 12px rgba(255, 140, 70, 0.3);
  cursor: pointer;
  display: none;
  align-items: center;
  gap: 6px;
  transition: all 0.25s ease;
}

.viewer-pip-restore-btn:hover {
  background: var(--accent);
  color: #ffffff;
  transform: scale(1.04);
}

#viewer-app.pip-hidden .viewer-pip-restore-btn {
  display: flex;
}

/* Ações no PiP do Telespectador */
.pip-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1250;
  display: flex;
  gap: 4px;
}

.pip-btn {
  background: rgba(14, 18, 22, 0.85);
  border: 1px solid var(--line);
  color: #ffffff;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  transition: all var(--transition-fast);
}

.pip-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
}

.hud-left, .hud-center, .hud-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-brand h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
}

.hud-brand span {
  font-size: 9.5px;
  color: var(--accent);
  display: block;
  letter-spacing: 0.12em;
}

/* Indicador de Transmissão Ao Vivo */
.live-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(229, 72, 77, 0.15);
  border: 1px solid var(--danger);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
}

.active-cam-badge {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255, 140, 70, 0.12);
  border: 1px solid rgba(255, 140, 70, 0.3);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 5px;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(27, 34, 40, 0.6);
  border: 1px solid var(--line-soft);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
}

.hud-stat-val {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.hud-stat-lbl {
  font-size: 8.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud-clock {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--teal);
  background: rgba(49, 201, 176, 0.08);
  border: 1px solid rgba(49, 201, 176, 0.3);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ================= CONTAINER DUPLO PIP & SWAP ================= */
#main-stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Palco do Mapa */
#map-stage-wrap {
  width: 100vw;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 100;
  transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
}

/* Palco do Vídeo / Live Stream */
#video-stage-wrap {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  right: calc(env(safe-area-inset-right, 0px) + 20px);
  width: 380px;
  height: 220px;
  z-index: 1200;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.85);
  border: 2px solid var(--accent);
  background: #000000;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
}

#video-stage-wrap:hover {
  border-color: #ffffff;
  box-shadow: 0 0 20px var(--accent-glow);
}

/* MODO INVERTIDO (SWAP): Vídeo Tela Cheia, Mapa no Canto Inferior */
#viewer-app.swapped #video-stage-wrap {
  width: 100vw !important;
  height: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  top: 0 !important;
  left: 0 !important;
  bottom: auto !important;
  right: auto !important;
  z-index: 100 !important;
  border: none !important;
  border-radius: 0 !important;
  cursor: default !important;
  box-shadow: none !important;
}

#viewer-app.swapped #map-stage-wrap {
  position: absolute !important;
  top: auto !important;
  left: auto !important;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px) !important;
  right: calc(env(safe-area-inset-right, 0px) + 20px) !important;
  width: 380px !important;
  height: 220px !important;
  z-index: 1200 !important;
  border-radius: var(--radius-md) !important;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.85) !important;
  border: 2px solid var(--teal) !important;
  cursor: pointer !important;
  overflow: hidden !important;
}

#viewer-app.swapped #map-stage-wrap:hover {
  border-color: #ffffff;
  box-shadow: 0 0 20px var(--teal-glow);
}

/* MODO TELA DIVIDIDA (SPLIT SCREEN 50% / 50%) */
#viewer-app.split #map-stage-wrap {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 50vw !important;
  height: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  z-index: 100 !important;
  border-right: 2px solid var(--accent) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  cursor: default !important;
}

#viewer-app.split #video-stage-wrap {
  position: absolute !important;
  top: 0 !important;
  right: 0 !important;
  bottom: auto !important;
  left: auto !important;
  width: 50vw !important;
  height: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  z-index: 100 !important;
  border-left: 2px solid var(--accent) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  cursor: default !important;
}

#viewer-app.split .pip-hint-overlay,
#viewer-app.split .pip-badge {
  display: none !important;
}

@media (max-width: 900px) {
  #viewer-app.split #map-stage-wrap {
    width: 100vw !important;
    height: 50% !important;
    height: 50vh !important;
    height: 50dvh !important;
    top: 0 !important;
    left: 0 !important;
    border-right: none !important;
    border-bottom: 2px solid var(--accent) !important;
  }

  #viewer-app.split #video-stage-wrap {
    width: 100vw !important;
    height: 50% !important;
    height: 50vh !important;
    height: 50dvh !important;
    top: 50% !important;
    top: 50vh !important;
    top: 50dvh !important;
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    border-left: none !important;
    border-top: 2px solid var(--accent) !important;
  }
}

/* Iframe do Player de Vídeo */
#drone-video-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #050709;
  display: block;
}

/* Overlay / Banner Indicativo na Janela PIP */
.pip-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1220;
  background: rgba(13, 17, 20, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid var(--accent);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  gap: 5px;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#viewer-app.swapped .pip-badge.video-badge {
  display: none;
}

/* Overlay de Dica de Clique para Inversão */
.pip-hint-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.9) 0%, rgba(0,0,0,0) 100%);
  padding: 10px 8px 6px;
  text-align: center;
  font-size: 9.5px;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity var(--transition-fast);
  pointer-events: none;
}

#video-stage-wrap:hover .pip-hint-overlay,
#viewer-app.swapped #map-stage-wrap:hover .pip-hint-overlay {
  opacity: 1;
}

/* Painel Flutuante da Legenda no Telespectador (posicionado no lado esquerdo inferior para não sobrepor o PIP) */
#viewer-legend-drawer {
  position: absolute;
  bottom: 24px;
  left: 20px;
  width: 300px;
  max-height: 45vh;
  z-index: 1250;
  background: rgba(20, 26, 31, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal);
}

/* ================= ALERTA / CHAMADA DO OPERADOR (PISCAR BORDAS 3X) ================= */
@keyframes emergencyBorderPulse3X {
  0% {
    box-shadow: inset 0 0 0 0 transparent;
  }
  16% {
    box-shadow: inset 0 0 75px 22px rgba(255, 25, 25, 0.98), 0 0 45px rgba(255, 25, 25, 0.85);
  }
  33% {
    box-shadow: inset 0 0 0 0 transparent;
  }
  49% {
    box-shadow: inset 0 0 75px 22px rgba(255, 25, 25, 0.98), 0 0 45px rgba(255, 25, 25, 0.85);
  }
  66% {
    box-shadow: inset 0 0 0 0 transparent;
  }
  83% {
    box-shadow: inset 0 0 75px 22px rgba(255, 25, 25, 0.98), 0 0 45px rgba(255, 25, 25, 0.85);
  }
  100% {
    box-shadow: inset 0 0 0 0 transparent;
  }
}

#viewer-app.emergency-alert-active {
  animation: emergencyBorderPulse3X 2.2s cubic-bezier(0.4, 0, 0.2, 1) forwards !important;
}

#emergency-alert-banner {
  position: fixed;
  top: 75px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  z-index: 9999;
  background: rgba(220, 20, 20, 0.95);
  color: #ffffff;
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: 2px solid #ffffff;
  box-shadow: 0 10px 30px rgba(255, 0, 0, 0.6);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

#emergency-alert-banner.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.drawer-body {
  padding: 8px 12px;
  overflow-y: auto;
  flex: 1;
}

/* Banner de Reconexão */
#connection-banner {
  position: absolute;
  top: 75px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1500;
  background: var(--panel);
  border: 1px solid var(--accent);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  display: none;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-md);
}

#connection-banner.show {
  display: flex;
}

/* ================= PORTAL DE AUTENTICAÇÃO DO TELESPECTADOR ================= */
.tactical-auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(8, 10, 12, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.tactical-auth-card {
  background: var(--panel);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-md);
  width: 400px;
  max-width: 95vw;
  padding: 24px 22px;
  box-shadow: var(--shadow-lg), 0 0 35px var(--accent-glow);
  position: relative;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.auth-brand h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text);
}

.auth-brand span {
  font-size: 9.5px;
  color: var(--accent);
  display: block;
  letter-spacing: 0.12em;
  font-weight: 600;
  margin-top: 2px;
}

.auth-desc {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  margin: 0 0 16px;
}

.auth-error-msg {
  font-size: 11px;
  color: var(--danger);
  margin-top: 8px;
  min-height: 14px;
  font-weight: 600;
}

/* ================= RESPONSIVIDADE ULTRA-AVANÇADA DO TELESPECTADOR ================= */
@media (max-width: 900px) {
  #hud-topbar {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    padding: 6px 10px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .hud-center {
    display: none;
  }

  .hud-brand h2 {
    font-size: 12px;
  }

  .hud-brand span {
    font-size: 8.5px;
  }

  .hud-clock {
    font-size: 11px;
    padding: 3px 6px;
  }

  #viewer-app:not(.swapped):not(.split) #video-stage-wrap,
  #viewer-app.swapped #map-stage-wrap {
    width: 200px !important;
    height: 125px !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 26px) !important;
    right: calc(env(safe-area-inset-right, 0px) + 14px) !important;
    z-index: 2500 !important;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.95), 0 0 16px rgba(255, 140, 70, 0.35) !important;
  }

  .leaflet-control-attribution {
    display: none !important;
  }
}

@media (max-width: 540px) {
  #hud-topbar {
    padding: 6px 8px;
  }

  .hud-brand {
    gap: 6px;
  }

  .hud-brand img {
    width: 22px !important;
    height: 22px !important;
  }

  .hud-clock {
    display: none;
  }

  #hud-active-cam {
    display: none;
  }

  .hud-right {
    gap: 4px;
    flex-wrap: wrap;
  }

  .hud-right .btn {
    padding: 3px 6px !important;
    font-size: 9.5px !important;
  }

  #viewer-app:not(.swapped):not(.split) #video-stage-wrap,
  #viewer-app.swapped #map-stage-wrap {
    width: 165px !important;
    height: 105px !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 32px) !important;
    right: calc(env(safe-area-inset-right, 0px) + 12px) !important;
    z-index: 2500 !important;
    border-width: 1.5px !important;
  }
}

/* Telas Grandes / TVs 4K */
@media (min-width: 2500px) {
  .hud-brand h2 {
    font-size: 20px;
  }
  .hud-clock {
    font-size: 16px;
  }
  #video-stage-wrap {
    width: 580px;
    height: 340px;
  }
}

