/* ============================================
   PeritoMap — CSS Camera + Galleria Foto
   Overlay fotocamera, galleria miniature,
   viewer fullscreen, indicatori upload
   ============================================ */

/* ---- Overlay Fotocamera (fullscreen) ---- */

.camera-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}

.camera-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  z-index: 2;
  min-height: 44px;
}

.camera-header-info {
  font-size: 13px;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin: 0 12px;
}

.camera-btn-chiudi {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
}

.camera-btn-chiudi:active {
  background: rgba(255, 255, 255, 0.2);
}

/* Area video/preview */
.camera-viewfinder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background: #000;
}

.camera-viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-viewfinder canvas {
  display: none;
}

/* Indicatore GPS */
.camera-gps-indicatore {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 11px;
  color: #fff;
  z-index: 2;
}

.camera-gps-indicatore.attivo {
  background: rgba(13, 144, 79, 0.8);
}

.camera-gps-indicatore.cercando {
  background: rgba(255, 152, 0, 0.8);
  animation: pulsa-gps 1.5s infinite;
}

.camera-gps-indicatore.errore {
  background: rgba(244, 67, 54, 0.8);
}

@keyframes pulsa-gps {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Flash feedback allo scatto */
.camera-flash {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  transition: opacity 0.05s ease-out;
}

.camera-flash.attivo {
  opacity: 0.7;
  transition: opacity 0.02s;
}

/* Messa a fuoco al tocco: anello che appare dove si tocca il mirino */
.camera-fuoco-anello {
  position: absolute;
  width: 72px;
  height: 72px;
  margin-left: -36px;
  margin-top: -36px;
  border: 2px solid #ffeb3b;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  transform: scale(1.5);
  transition: opacity 0.15s ease-out, transform 0.3s ease-out;
  z-index: 4;
}

.camera-fuoco-anello.attivo {
  opacity: 1;
  transform: scale(1);
}

/* Suggerimento iniziale: appare e svanisce da solo */
.camera-fuoco-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 14px;
  pointer-events: none;
  z-index: 4;
  animation: cameraFuocoHint 4.5s ease forwards;
}

@keyframes cameraFuocoHint {
  0%   { opacity: 0; }
  12%  { opacity: 1; }
  72%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Controlli fotocamera (bottom) */
.camera-controlli {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 16px 24px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.85);
  z-index: 2;
}

.camera-btn-scatta {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.camera-btn-scatta::after {
  content: '';
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.1s;
}

.camera-btn-scatta:active::after {
  transform: scale(0.85);
}

.camera-btn-scatta.scattando::after {
  background: #f44336;
}

/* Selettore qualità e contatore */
.camera-btn-secondario {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 60px;
}

.camera-btn-secondario:active {
  background: rgba(255, 255, 255, 0.3);
}

.camera-btn-secondario .camera-label {
  font-size: 10px;
  opacity: 0.7;
}

.camera-contatore-scatti {
  font-size: 18px;
  font-weight: 700;
}

/* Miniature scatti recenti (strip sotto viewfinder) */
.camera-strip-miniature {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.85);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  min-height: 0;
}

.camera-strip-miniature:empty {
  display: none;
}

.camera-strip-miniature::-webkit-scrollbar {
  display: none;
}

.camera-miniatura-strip {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

.camera-miniatura-strip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-miniatura-strip .upload-stato {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.upload-stato.caricata {
  background: #0d904f;
}

.upload-stato.in_coda {
  background: #ff9800;
  animation: pulsa-gps 1.5s infinite;
}

.upload-stato.errore {
  background: #f44336;
}

/* ---- Modalità orizzontale (telefono ruotato) ----
   Quando il telefono è in orizzontale, i controlli passano in una colonna sulla
   DESTRA e l'intestazione diventa una barra flottante in alto. Cosi' il pulsante
   di scatto resta in una posizione coerente e raggiungibile sia su Android che
   iPhone (niente piu' pulsanti che si spostano in modo imprevedibile). */
@media (orientation: landscape) {
  .camera-overlay {
    flex-direction: row;
  }

  .camera-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    min-height: 0;
    padding: 6px 12px;
    background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
  }

  .camera-controlli {
    flex-direction: column;
    justify-content: space-around;
    padding: 24px 16px;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: 24px;
  }

  /* Lo strip delle miniature flotta in basso a sinistra sopra il mirino, per non
     rompere il layout a riga. */
  .camera-strip-miniature {
    position: absolute;
    left: 0;
    bottom: 0;
    max-width: calc(100% - 120px);
    background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.7));
  }
}

/* ---- Messaggio errore camera ---- */

.camera-errore {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  color: #fff;
  text-align: center;
  flex: 1;
}

.camera-errore p {
  font-size: 15px;
  line-height: 1.5;
  max-width: 300px;
}

.camera-errore .btn {
  color: #fff;
  border-color: #fff;
}

/* ---- Fallback input file ---- */

.camera-input-nascosto {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* ---- Galleria foto nel dettaglio incarico ---- */

.foto-sezione {
  margin-top: var(--spazio-md);
}

.foto-sezione-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spazio-sm);
}

.foto-sezione-titolo {
  font-size: 15px;
  font-weight: 600;
  color: var(--colore-testo);
  display: flex;
  align-items: center;
  gap: 8px;
}

.foto-sezione-contatore {
  background: var(--colore-primario);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.foto-griglia {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 6px;
}

.foto-miniatura {
  position: relative;
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--colore-sfondo);
  border: 1px solid var(--colore-bordo);
}

.foto-miniatura img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.foto-miniatura:active img {
  transform: scale(1.05);
}

.foto-miniatura-numero {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
}

.foto-miniatura-stato {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d904f;
}

.foto-miniatura-stato svg {
  width: 12px;
  height: 12px;
  stroke: #fff;
  stroke-width: 3;
  fill: none;
}

.foto-miniatura-stato.in_coda {
  background: #ff9800;
}

.foto-miniatura-stato.errore {
  background: #f44336;
}

.foto-miniatura.cancellata {
  opacity: 0.4;
}

.foto-miniatura.cancellata::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 5px,
    rgba(244, 67, 54, 0.15) 5px,
    rgba(244, 67, 54, 0.15) 10px
  );
}

/* Selezione multipla foto */
.foto-miniatura.selezionabile {
  border-color: var(--colore-primario);
}

.foto-miniatura .foto-check {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.foto-miniatura .foto-check svg { opacity: 0; }

.foto-miniatura.selezionata {
  outline: 3px solid var(--colore-primario);
  outline-offset: -3px;
}

.foto-miniatura.selezionata .foto-check {
  background: var(--colore-primario);
  border-color: var(--colore-primario);
}

.foto-miniatura.selezionata .foto-check svg { opacity: 1; }

.foto-miniatura.selezionata img { transform: scale(0.92); }

.foto-barra-selezione {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--colore-superficie, #fff);
  border: 1px solid var(--colore-bordo);
  border-radius: 10px;
}

.foto-sel-conteggio {
  font-size: 13px;
  font-weight: 600;
  color: var(--colore-testo-secondario, #666);
  margin-right: auto;
}

.foto-sel-tutte {
  background: none;
  border: none;
  color: var(--colore-primario);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
}

.foto-sel-azione {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--colore-primario);
  color: #fff;
}

.foto-sel-azione.pericolo { background: #d93025; }

.foto-sel-azione:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Bottone scatta foto nel dettaglio */
.btn-scatta-foto {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--colore-primario);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-scatta-foto:active {
  opacity: 0.85;
}

/* Bottone cestino */
.btn-cestino-foto {
  background: none;
  border: none;
  color: var(--colore-testo-secondario);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
}

.btn-cestino-foto:hover {
  background: var(--colore-sfondo);
}

/* Stato vuoto galleria */
.foto-vuoto {
  text-align: center;
  padding: var(--spazio-lg);
  color: var(--colore-testo-secondario);
}

.foto-vuoto svg {
  margin-bottom: var(--spazio-sm);
  opacity: 0.4;
}

.foto-vuoto p {
  font-size: 14px;
  margin: 0;
}

/* ---- Viewer foto fullscreen ---- */

.foto-viewer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 9998;
  display: flex;
  flex-direction: column;
}

.foto-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  min-height: 44px;
  z-index: 2;
}

.foto-viewer-titolo {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  margin: 0 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.foto-viewer-corpo {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.foto-viewer-corpo img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Navigazione precedente/successiva */
.foto-viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.foto-viewer-nav:active {
  background: rgba(255, 255, 255, 0.3);
}

.foto-viewer-nav.precedente {
  left: 8px;
}

.foto-viewer-nav.successiva {
  right: 8px;
}

/* Footer viewer con info e azioni */
.foto-viewer-footer {
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  z-index: 2;
}

.foto-viewer-info {
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 8px;
  line-height: 1.4;
}

.foto-viewer-azioni {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.foto-viewer-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.foto-viewer-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

.foto-viewer-btn.pericolo {
  color: #ff5252;
}

/* ---- Coda upload ---- */

.coda-upload-barra {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--colore-avviso-sfondo, #fff3e0);
  border-radius: 8px;
  margin-bottom: var(--spazio-sm);
  font-size: 13px;
}

.coda-upload-barra svg {
  flex-shrink: 0;
}

.coda-upload-barra .progresso {
  flex: 1;
}

/* ---- Responsive ---- */

@media (min-width: 600px) {
  .foto-griglia {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}

@media (min-width: 900px) {
  .foto-griglia {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}
