/* ==========================================================================
   dbMeteo - Responsive & Modular Player Engine (Container Queries)
   ========================================================================== */

/* 1. CONTENITORE ESTERNO (Area nera complessiva) */
.webcam-box {
  position: relative;
  width: 100%;
  max-width: 1100px;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  cursor: default;
  margin: 0 auto;
}

.webcam-box.hide-ui { cursor: none; }

.webcam-box video,
#historyImage {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000;
}

#historyImage { display: none; z-index: 2; }

/* 2. CANVAS GEOMETRICA CHE RITAGLIA L'IMMAGINE REALE DEL VIDEO */
.video-canvas {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
  container-type: inline-size;
  container-name: videoSurface;
  /* AGGIUNGI QUESTE 2 RIGHE: */
  opacity: 0;
  transition: opacity 0.4s ease;
}

/* 3. SPINNER */
.spinner-overlay {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: clamp(8px, 1.5cqi, 14px);
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  z-index: 4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* AGGIUNGI: */
.spinner-text {
  color: rgba(255, 255, 255, 0.8);
  font-size: clamp(9px, 1.2cqi, 12px);
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
.spinner-overlay.active { opacity: 1; }

.loader-ring {
  width: clamp(30px, 5cqi, 55px);
  height: clamp(30px, 5cqi, 55px);
  border: 3px solid rgba(255, 171, 0, 0.15);
  border-top: 3px solid #ffab00;
  border-radius: 50%;
  animation: spin 0.8s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ==========================================================================
   PULSANTE AZIONE RAPIDA PER SMARTPHONE (SOLO MOBILE VERTICALE)
   ========================================================================== */
.mobile-action-bar {
  display: none;
  width: 100%;
  max-width: 1100px;
  margin: 12px auto 0 auto;
}

.btn-mobile-landscape {
  background: linear-gradient(135deg, #ffab00 0%, #d99100 100%) !important;
  color: #142537 !important;
  border: none !important;
  border-radius: 8px !important;
  padding: 12px 18px !important;
  font-size: 14px !important;
  font-weight: 800 !important;
  box-shadow: 0 4px 15px rgba(255, 171, 0, 0.35) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: transform 0.15s, filter 0.15s !important;
  letter-spacing: 0.3px;
}
.btn-mobile-landscape:active {
  transform: scale(0.98);
  filter: brightness(0.95);
}
.btn-mobile-landscape i {
  font-size: 20px;
}

@media (max-width: 991.98px) and (orientation: portrait) {
  .mobile-action-bar {
    display: block;
  }
}

@media (max-width: 500px) {
    /* Nascondiamo i badge, meteo e testo libero */
    #unifiedBadge { display: none !important; }
    #weatherLayer { display: none !important; }
    #weatherAnchorBlock { display: none !important; }
    #customTextBadge { display: none !important; }
    #logoContainer { display: none !important; }
}

/* ==========================================================================
   SISTEMA DI POSIZIONAMENTO A 9 SETTORI (CON IMPILAMENTO AUTOMATICO FLEX)
   ========================================================================== */
:root {
  --player-pad-x: clamp(8px, 2cqi, 24px);
  --player-pad-y: clamp(8px, 2cqi, 24px);
  --elem-gap: clamp(5px, 0.8cqi, 10px);
}

.zone-container {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: var(--elem-gap);
  z-index: 10;
  pointer-events: none;
}

/* Quadranti Superiori: impilano verso il basso */
.pos-top-left {
  top: var(--player-pad-y);
  left: var(--player-pad-x);
  align-items: flex-start;
}
.pos-top-center {
  top: var(--player-pad-y);
  left: 50%;
  transform: translateX(-50%);
  align-items: center;
}
.pos-top-right {
  top: var(--player-pad-y);
  right: var(--player-pad-x);
  align-items: flex-end;
}

/* Quadranti Centrali */
.pos-center-left {
  top: 50%;
  left: var(--player-pad-x);
  transform: translateY(-50%);
  align-items: flex-start;
}
.pos-center-right {
  top: 50%;
  right: var(--player-pad-x);
  transform: translateY(-50%);
  align-items: flex-end;
}

/* Quadranti Inferiori: impilano dal basso verso l'alto (column-reverse) */
.pos-bottom-left {
  bottom: var(--player-pad-y);
  left: var(--player-pad-x);
  flex-direction: column-reverse;
  align-items: flex-start;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.pos-bottom-center {
  bottom: var(--player-pad-y);
  left: 50%;
  transform: translate(-50%, 0);
  flex-direction: column-reverse;
  align-items: center;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.pos-bottom-right {
  bottom: var(--player-pad-y);
  right: var(--player-pad-x);
  flex-direction: column-reverse;
  align-items: flex-end;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Traslazione dinamica all'attivazione dei controlli */
.webcam-box:not(.hide-ui) .pos-bottom-left,
.webcam-box:not(.hide-ui) .pos-bottom-right {
  transform: translateY(var(--dynamic-lift, 0px));
}

.webcam-box:not(.hide-ui) .pos-bottom-center {
  transform: translate(-50%, var(--dynamic-lift, 0px));
}

.webcam-box:not(.hide-ui) .weather-layer {
  transform: translateY(var(--dynamic-lift, 0px));
}

/* ==========================================================================
   WIDGET 1: BADGE UNIFICATO (TITOLO / STATO / OROLOGIO)
   ========================================================================== */
.unified-badge {
  display: inline-flex;
  align-items: center;
  gap: calc(clamp(6px, 1cqi, 10px) * var(--badge-scale, 1));
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: calc(clamp(4px, 0.6cqi, 8px) * var(--badge-scale, 1)) calc(clamp(8px, 1.2cqi, 14px) * var(--badge-scale, 1));
  border-radius: clamp(6px, 1cqi, 8px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  user-select: none;
  pointer-events: auto;
  color: #fff;
}

.status-dot {
  width: calc(clamp(7px, 1cqi, 10px) * var(--badge-scale, 1));
  height: calc(clamp(7px, 1cqi, 10px) * var(--badge-scale, 1));
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.mode-live {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
  animation: pulse-dot 2s infinite;
}
.status-dot.mode-history { background: #3b82f6; box-shadow: 0 0 8px #3b82f6; }
.status-dot.mode-reconn { background: #eab308; box-shadow: 0 0 8px #eab308; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.status-text {
  font-size: calc(clamp(9px, 1.1cqi, 13px) * var(--badge-scale, 1));
  font-weight: 800;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge-divider {
  width: 1px;
  height: calc(clamp(10px, 1.4cqi, 14px) * var(--badge-scale, 1));
  background: rgba(255, 255, 255, 0.2);
}

.badge-station-name {
  font-size: calc(clamp(10px, 1.2cqi, 14px) * var(--badge-scale, 1));
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.badge-station-name .tz {
  color: #ffab00;
  font-size: 0.85em;
  margin-left: 4px;
}

.badge-clock {
  font-size: calc(clamp(10px, 1.2cqi, 14px) * var(--badge-scale, 1));
  font-weight: 800;
  color: #38bdf8;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ==========================================================================
   WIDGET 2: TESTO LIBERO PERSONALIZZATO
   ========================================================================== */
.custom-text-badge {
  display: inline-flex;
  align-items: center;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: calc(clamp(4px, 0.6cqi, 8px) * var(--custom-text-scale, 1)) calc(clamp(8px, 1.2cqi, 14px) * var(--custom-text-scale, 1));
  border-radius: clamp(6px, 1cqi, 8px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  font-size: calc(clamp(10px, 1.2cqi, 14px) * var(--custom-text-scale, 1));
  font-weight: 700;
  color: #fff;
  user-select: none;
  pointer-events: auto;
  white-space: nowrap;
}

/* ==========================================================================
   WIDGET 3: LOGO DELLA STAZIONE
   ========================================================================== */
.logo-container {
  display: inline-flex;
  align-items: center;
  pointer-events: auto;
}

.player-logo {
  position: static !important;
  width: auto !important;
  height: auto !important;
  max-height: calc(clamp(36px, 7.5cqi, 95px) * var(--logo-scale, 1)) !important;
  max-width: calc(clamp(120px, 24cqi, 300px) * var(--logo-scale, 1)) !important;
  object-fit: contain;
  background: transparent !important;
  user-select: none;
}

.btn-add-logo {
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  border: 1px dashed rgba(255, 171, 0, 0.6);
  color: #ffab00;
  padding: calc(clamp(5px, 0.8cqi, 10px) * var(--logo-scale, 1)) calc(clamp(10px, 1.5cqi, 16px) * var(--logo-scale, 1));
  border-radius: clamp(6px, 1cqi, 8px);
  font-size: calc(clamp(10px, 1.3cqi, 14px) * var(--logo-scale, 1));
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.btn-add-logo:hover {
  background: rgba(255, 171, 0, 0.2);
  border-color: #ffab00;
  transform: scale(1.04);
}

/* ==========================================================================
   WIDGET 4: TELEMETRIA METEO
   ========================================================================== */
.weather-layer {
  position: absolute;
  bottom: var(--player-pad-y);
  left: var(--player-pad-x);
  right: var(--player-pad-x);
  z-index: 12;
  pointer-events: none;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.weather-row {
  display: flex;
  align-items: center;
  gap: calc(clamp(8px, 1.8cqi, 22px) * var(--weather-scale, 1));
  flex-wrap: wrap;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85);
}

.weather-pill {
  display: flex;
  align-items: baseline;
  gap: 3px;
  color: #f8fafc;
}
.weather-pill .val {
  font-size: calc(clamp(12px, 1.9cqi, 21px) * var(--weather-scale, 1));
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.weather-pill .unit {
  font-size: calc(clamp(8px, 1.1cqi, 12px) * var(--weather-scale, 1));
  font-weight: 600;
  color: #cbd5e1;
}
.temp-color { color: #ffab00 !important; }

.weather-block {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: calc(clamp(4px, 0.6cqi, 8px) * var(--weather-scale, 1)) calc(clamp(8px, 1.2cqi, 14px) * var(--weather-scale, 1));
  border-radius: clamp(6px, 1cqi, 8px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

/* ==========================================================================
   BARRA CONTROLLI TIMELINE
   ========================================================================== */
.control-layer {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 15;
  padding: clamp(14px, 2.5cqi, 28px) clamp(10px, 2.2cqi, 26px) clamp(8px, 1.4cqi, 14px) clamp(10px, 2.2cqi, 26px);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.3) 70%, transparent 100%);
  /* MODIFICA: da opacity: 1 a opacity: 0 con pointer-events: none */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.webcam-box.media-ready .video-canvas {
  opacity: 1;
}

.webcam-box.media-ready:not(.hide-ui) .control-layer {
  opacity: 1;
  pointer-events: auto;
}

.webcam-box.hide-ui .control-layer {
  opacity: 0;
  pointer-events: none;
}

.control-row {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.2cqi, 16px);
}

.ctrl-btn {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  width: clamp(28px, 3.8cqi, 40px);
  height: clamp(28px, 3.8cqi, 40px);
  border-radius: 50%;
  display: flex; justify-content: center; align-items: center;
  cursor: pointer;
  transition: 0.2s;
  flex-shrink: 0;
  padding: 0;
}
.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.06);
}

.ctrl-btn i {
  font-size: clamp(15px, 2.1cqi, 22px);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctrl-btn .bx-play {
  margin-left: 2px;
}

.slider-wrapper {
  position: relative;
  flex-grow: 1;
  display: flex; flex-direction: column; justify-content: center;
}
.timeline-slider {
  width: 100%;
  -webkit-appearance: none;
  height: clamp(3px, 0.6cqi, 6px);
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.3);
  outline: none;
  cursor: pointer;
}
.timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: clamp(11px, 1.5cqi, 18px);
  height: clamp(11px, 1.5cqi, 18px);
  border-radius: 50%;
  background: #ffab00;
  cursor: pointer;
  box-shadow: 0 0 8px #ffab00;
}

.ticks-bar {
  position: relative;
  width: 100%;
  height: clamp(10px, 1.4cqi, 16px);
  margin-top: 3px;
}
.tick-label {
  position: absolute;
  font-size: clamp(8px, 1cqi, 11px);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  user-select: none;
}
.tick-label:hover { color: #ffab00; }

.live-btn {
  background: #ef4444; color: white; border: none;
  padding: clamp(4px, 0.6cqi, 8px) clamp(8px, 1.2cqi, 14px);
  border-radius: clamp(4px, 0.6cqi, 8px);
  font-size: clamp(9px, 1.1cqi, 12px);
  font-weight: 800; cursor: pointer;
  flex-shrink: 0; transition: 0.2s;
}
.live-btn:hover { background: #dc2626; transform: scale(1.04); }

/* ==========================================================================
   FULLSCREEN & RESPONSIVE DESKTOP
   ========================================================================= */
.webcam-box:fullscreen {
  width: 100vw !important; height: 100vh !important;
  max-width: 100vw !important; max-height: 100vh !important;
  aspect-ratio: auto !important; border-radius: 0 !important; margin: 0 !important;
}
.webcam-box:-webkit-full-screen {
  width: 100vw !important; height: 100vh !important;
  max-width: 100vw !important; max-height: 100vh !important;
  aspect-ratio: auto !important; border-radius: 0 !important; margin: 0 !important;
}
.webcam-box:-moz-full-screen {
  width: 100vw !important; height: 100vh !important;
  max-width: 100vw !important; max-height: 100vh !important;
  aspect-ratio: auto !important; border-radius: 0 !important; margin: 0 !important;
}

@media (min-width: 992px) {
  .webcam-box { margin-bottom: 160px; }
}

/* AVVISO STATO C */
.no-stream-overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle, #1a2936 0%, #0d1620 100%);
  z-index: 25; text-align: center; padding: 24px;
}
.no-stream-box { display: flex; flex-direction: column; align-items: center; max-width: 380px; }
.no-stream-icon { font-size: clamp(2.5rem, 6cqi, 4.5rem); color: #ffab00; margin-bottom: 10px; opacity: 0.85; }
.no-stream-title { color: #fff; font-size: clamp(1rem, 2cqi, 1.4rem); font-weight: 700; margin-bottom: 6px; }
.no-stream-desc { color: #94a3b8; font-size: clamp(0.75rem, 1.2cqi, 0.95rem); margin: 0; line-height: 1.4; }
