/* LeakFinder Cloud - tema "Notte" per il dettaglio sessione e il viewer pubblico.
   Va caricato DOPO notte.css. Le due pagine hanno molta logica (mappa Leaflet,
   grafico, tabella delle misure) legata ai nomi di classe storici: qui quei
   nomi vengono rivestiti con il tema, senza toccare la logica. */

.viewer-page { min-height: 100dvh; }
.viewer-shell { max-width: 1320px; margin: 0 auto; padding: 20px 20px 48px; display: flex; flex-direction: column; gap: 22px; min-height: 100dvh; }

/* messaggi in alto a destra */
.flash-stack { position: fixed; top: 14px; right: 14px; z-index: 9000; max-width: 420px; display: flex; flex-direction: column; gap: 10px; }

/* ------------------------------------------------------------ navigazione */
.lang-switch { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.lang-switch button {
  min-width: 40px; min-height: 36px; border: none; border-radius: 999px; background: transparent;
  color: var(--muted); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.lang-switch button.active { background: var(--line); color: #ffffff; }

.user-menu { position: relative; }
.user-menu .user-btn { cursor: pointer; }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 12px); min-width: 210px; padding: 8px; z-index: 40;
  border-radius: 20px; background: var(--core); border: 1px solid var(--line-strong);
  box-shadow: 0 24px 48px -20px rgba(0, 0, 0, 0.9);
  opacity: 0; transform: translateY(-8px) scale(0.98); pointer-events: none;
  transition: opacity 0.4s var(--spring), transform 0.4s var(--spring);
}
.user-dropdown.show { opacity: 1; transform: none; pointer-events: auto; }
.user-dropdown a { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px; border-radius: 12px; color: var(--text); }
.user-dropdown a:hover { background: var(--tile); color: var(--text); }
.user-dropdown a.logout { color: var(--bad); }
.user-dropdown .divider { height: 1px; background: var(--line); margin: 6px 4px; }

/* intestazione della pagina */
.header-title h1 { font-size: clamp(30px, 3.6vw, 40px); font-weight: 300; letter-spacing: -0.03em; line-height: 1.1; overflow-wrap: anywhere; }
.header-title p { color: var(--muted); margin-top: 4px; }
.controls-bar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.controls-left { color: var(--muted); }
.controls-right { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------ grafico e mappa */
.cards-stack { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.card {
  display: flex; flex-direction: column; min-height: 500px; overflow: hidden;
  border-radius: var(--r-core); background: var(--core);
  border: 1px solid var(--shell-line);
  box-shadow: 0 0 0 6px var(--shell), 0 0 0 7px var(--shell-line), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  margin: 7px;
}
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.card-body { flex: 1; position: relative; padding: 16px; display: flex; flex-direction: column; }
.chart-card .card-body { padding: 20px; }
.chart-container { flex: 1; position: relative; min-height: 320px; }
#chart { width: 100%; height: 100%; }
.map-container { position: absolute; inset: 0; }
#map { width: 100%; height: 100%; background: var(--tile); }

.nav-buttons { display: flex; gap: 4px; }
.nav-btn {
  width: 36px; height: 36px; border: 1px solid var(--line-strong); background: transparent; border-radius: 999px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--muted);
}
.nav-btn:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }

.number-picker { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.number-picker label { white-space: nowrap; }
.number-picker input[type='number'], .map-controls select, .unit-picker select {
  min-height: 36px; padding: 4px 10px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--bg); color: var(--text); font: inherit; font-size: 13px;
}
.number-picker input[type='number'] { width: 92px; }
.number-picker input[type='number']:focus, .map-controls select:focus, .unit-picker select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18); }
.number-picker span { color: var(--muted); font-size: 12px; }

.map-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; width: 100%; }
.toggle-group { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.toggle-btn {
  min-height: 36px; padding: 0 14px; border: 1px solid var(--line-strong); background: transparent; border-radius: 999px;
  cursor: pointer; font: inherit; font-size: 13px; color: var(--muted); white-space: nowrap;
  transition: background 0.4s var(--spring), color 0.4s var(--spring);
}
.toggle-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.toggle-btn.active { background: var(--line); color: #ffffff; border-color: var(--line); }

.leaks-label {
  position: absolute; bottom: 12px; left: 12px; z-index: 1000; padding: 6px 12px; border-radius: 999px;
  background: rgba(8, 9, 11, 0.86); border: 1px solid var(--line-strong); font-size: 13px; color: var(--muted);
}
.leaks-label strong { color: var(--text); font-weight: 500; }

/* ------------------------------------------------------------ tabella e foto */
.data-section {
  border-radius: var(--r-core); background: var(--core); border: 1px solid var(--shell-line);
  box-shadow: 0 0 0 6px var(--shell), 0 0 0 7px var(--shell-line), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  margin: 7px; padding: 22px;
}
.data-section h3 { font-size: 18px; font-weight: 500; letter-spacing: -0.01em; margin: 0; }
.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.unit-picker { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.data-table th { padding: 10px 12px; text-align: left; font-weight: 400; font-size: 13px; color: var(--muted); white-space: nowrap; border-bottom: 1px solid var(--line); }
.data-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.data-table input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.excluded-leak { opacity: 0.5; }
.excluded-leak td { text-decoration: line-through; color: var(--muted); }

.btn-delete {
  width: 30px; height: 30px; padding: 0; border-radius: 999px; border: 1px solid #5a2a2a; background: transparent;
  color: var(--bad); font-size: 18px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.btn-delete:hover { background: rgba(252, 165, 165, 0.1); }

.photo-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 14px; }
.photo-item { cursor: pointer; border-radius: 16px; overflow: hidden; background: var(--tile); transition: transform 0.5s var(--spring); }
.photo-item:hover { transform: translateY(-3px); }
.photo-item img { width: 100%; height: 150px; object-fit: cover; display: block; }

/* ------------------------------------------------------------ viewer pubblico: caricamento */
.upload-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 20px; align-items: stretch; }
.upload-intro { display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 24px 8px; }
.hero-title { font-size: clamp(36px, 5vw, 60px); font-weight: 300; letter-spacing: -0.04em; line-height: 1.04; }
.upload-label { font-family: var(--mono); font-size: 12px; font-weight: 400; letter-spacing: 0.06em; color: var(--muted); }
.upload-intro p { color: var(--muted); font-size: 17px; max-width: 46ch; }
.formats { display: flex; flex-wrap: wrap; gap: 8px; }
.formats span { padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.06); font-family: var(--mono); font-size: 13px; }

#dropZone {
  min-height: 320px; height: 100%; border-radius: var(--r-tile); border: 1.5px dashed #3a3f48;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 32px; text-align: center; cursor: pointer;
  transition: border-color 0.4s var(--spring), background 0.4s var(--spring);
}
#dropZone:hover, #dropZone.is-over { border-color: var(--accent); background: rgba(52, 211, 153, 0.05); }
#dropZone .drop-icon { order: -1; font-size: 40px; color: var(--accent); line-height: 1; }
#dropZone .drop-title { font-size: 22px; }
#dropZone .drop-sub { color: var(--muted); }
#fileInfo { margin-top: 14px; color: var(--muted); }
#fileInfo strong, #fileInfo span { color: var(--text); }

/* ------------------------------------------------------------ etichette sulla mappa (Leaflet) */
.leak-tooltip {
  background: var(--core) !important; color: var(--text) !important; border: 1px solid var(--line-strong) !important;
  border-radius: 12px !important; padding: 8px 12px !important; font-size: 13px !important;
  box-shadow: 0 12px 28px -12px rgba(0, 0, 0, 0.9) !important;
}
.leak-label-permanent {
  background: rgba(8, 9, 11, 0.9) !important; border: 1px solid var(--line-strong) !important; border-radius: 8px !important;
  padding: 4px 8px !important; font-size: 12px !important; font-weight: 600 !important; color: #ffffff !important;
  box-shadow: 0 6px 16px -8px rgba(0, 0, 0, 0.9) !important;
}
.leak-label-permanent::before { border-top-color: rgba(8, 9, 11, 0.9) !important; }
.leaflet-container { font-family: var(--font); }

/* ------------------------------------------------------------ avviso cookie */
.cookie-banner {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 10000; margin: 0 auto; max-width: 980px;
  padding: 18px 22px; border-radius: var(--r-core); background: var(--core); border: 1px solid var(--line-strong);
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.95);
}
.cookie-content { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.cookie-text { flex: 1; min-width: 260px; }
.cookie-text p { margin: 0; color: var(--muted); }
.cookie-text strong { color: var(--text); font-weight: 500; }
.cookie-text a { color: var(--ok) !important; }
.cookie-buttons { display: flex; gap: 8px; }
.cookie-banner button { min-height: 44px; padding: 0 20px; border-radius: 999px; font: inherit; font-weight: 500; cursor: pointer; }
.btn-accept { border: none; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-decline { border: 1px solid var(--line-strong); background: transparent; color: var(--text); }

/* ------------------------------------------------------------ pie' di pagina condiviso */
.site-footer { margin-top: auto; padding-top: 8px; text-align: center; color: var(--muted); font-size: 13px; }
.site-footer p { margin: 0; }
.site-footer a { color: var(--muted); text-decoration: underline; }
.site-footer a:hover { color: var(--text); }

@media (max-width: 1100px) {
  .cards-stack { grid-template-columns: 1fr; }
  .card { min-height: 420px; }
}
@media (max-width: 720px) {
  .viewer-shell { padding: 12px 12px 40px; }
  .toggle-group { margin-left: 0; }
  .data-section { padding: 16px; }
}

/* ------------------------------------------------------------ viewer: con o senza dati */
.no-data #controlsBar, .no-data #cardsStack, .no-data .data-section { display: none; }
.has-data #uploadSection { display: none; }
.customer-login-btn { margin-left: 4px; }

/* ------------------------------------------------------------ pannello di aiuto */
.help-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); z-index: 9998; display: none; opacity: 0; transition: opacity 0.3s ease; }
.help-overlay.active { display: block; opacity: 1; }
.help-panel {
  position: fixed; top: 0; right: -440px; width: 420px; max-width: 100%; height: 100%; z-index: 9999; overflow-y: auto;
  background: var(--core); border-left: 1px solid var(--line-strong); box-shadow: -24px 0 60px -30px rgba(0, 0, 0, 0.95);
  transition: right 0.5s var(--spring);
}
.help-panel.active { right: 0; }
.help-panel-header { position: sticky; top: 0; z-index: 10; background: var(--core); padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.help-panel-header h2 { font-size: 18px; font-weight: 500; margin: 0; }
.help-panel-controls { display: flex; align-items: center; gap: 8px; }
.help-lang-switch { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.help-lang-switch button { min-width: 38px; min-height: 32px; border: none; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; }
.help-lang-switch button.active { background: var(--line); color: #ffffff; }
.help-close-btn { width: 36px; height: 36px; border: none; border-radius: 999px; background: transparent; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.help-close-btn:hover { background: var(--tile); color: var(--text); }
.help-panel-content { padding: 20px; font-size: 14px; line-height: 1.6; color: var(--muted); }
.help-panel-content h3 { font-size: 16px; font-weight: 500; color: var(--text); margin: 24px 0 10px; }
.help-panel-content h3:first-child { margin-top: 0; }
.help-panel-content p { margin: 0 0 12px; }
.help-panel-content ul, .help-panel-content ol { margin: 0 0 12px 20px; padding: 0; }
.help-panel-content li { margin-bottom: 6px; }
.help-panel-content strong { font-weight: 600; color: var(--text); }
.help-section { display: none; }
.help-section.active { display: block; }
@media (max-width: 720px) { .help-panel { width: 100%; right: -100%; } }
