/* =========================================================
   BASE / THEME (JW-like, light only)
========================================================= */

/* FIX: fai funzionare davvero l'attributo hidden */
[hidden] { display: none !important; }

:root{
  color-scheme: light;

  --bg: #f2f4f7;
  --card: #ffffff;

  --text: #1d2b36;
  --muted: #55626f;

  --border: #d7dee6;
  --shadow: 0 10px 24px rgba(0,0,0,.08);

  --primary: #2a5c9a;
  --primary-ink: #ffffff;

  --danger: #c62828;
  --accent: #f0b429;

  --radius: 12px;
  --focus: rgba(42,92,154,.22);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  
  /* Blocca il ricaricamento accidentale tirando giù (pull-to-refresh) sui cellulari */
  overscroll-behavior-y: none; 
}

a{ color: inherit; }
button,input{ font: inherit; }

.shell{
  width: min(1120px, 100% - 24px);
  margin: 0 auto;
}

.sr-only{
  position:absolute;
  width:1px;height:1px;
  margin:-1px;padding:0;
  overflow:hidden;clip:rect(0,0,0,0);
  white-space:nowrap;border:0;
}

.skip-link{
  position:absolute;
  left:-999px; top:8px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 10px;
  z-index: 9999;
}
.skip-link:focus{ left: 8px; }

.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.muted{ color: var(--muted); }
.hint{ color: var(--muted); margin: 12px 0 0; font-size: 14px; }

.btn{
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1;
}
.btn:hover{ filter: brightness(1.02); }
.btn:active{ transform: translateY(1px); }

.btn.primary{
  background: var(--primary);
  border-color: transparent;
  color: var(--primary-ink);
}
.btn.danger{
  background: var(--danger);
  border-color: transparent;
  color: #fff;
}

.input, #login input{
  width:100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 12px 12px;
  outline: none;
}
.input:focus, #login input:focus{
  border-color: rgba(42,92,154,.55);
  box-shadow: 0 0 0 4px var(--focus);
}

.error{ color: var(--danger); margin: 10px 0 0; min-height: 1.25em; }

/* =========================================================
   LOGIN
========================================================= */
.login{
  min-height: 100vh;
  display:flex;
  align-items:center;
  justify-content:center;
}
.login-card{
  width: min(520px, 100%);
  padding: 28px 24px;
}
#login h1{ margin: 0 0 12px; font-size: 22px; }
.form{ display:grid; gap: 10px; }
.form-group{ display:flex; flex-direction: column; gap: 6px; }
.form label{ font-weight: 650; }

/* =========================================================
   HEADER (COMPATTO E MODERNO)
========================================================= */
.app-header{
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.app-header__top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 8px;
  padding: 8px 0;
}

.brand{
  display:flex;
  align-items:center;
  gap: 12px;
  min-width: 0;
}
.brand__mark{
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--primary);
  box-shadow: 0 10px 18px rgba(42,92,154,.18);
}
.brand__title{
  min-width: 0;
}
.brand__title h1{
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .2px;
}
.brand__title p{
  display: none; /* Nascosto per risparmiare spazio verticale */
}

.app-header__actions{
  display:flex;
  gap: 6px;
  align-items:center;
  flex-shrink: 0;
}
.app-header__actions .btn {
  padding: 6px 10px;
  font-size: 13px;
}

.app-header__bottom{
  padding: 0 0 10px 0;
}

/* =========================================================
   TABS MAPPE (Stile compatto a griglia)
========================================================= */
.map-tabs{
  border-top: 1px solid rgba(215,222,230,.75);
  padding-top: 6px;
}

.tablist{
  display:flex;
  flex-wrap: wrap; /* Fa andare a capo i bottoni automaticamente */
  justify-content: center;
  gap: 4px;
  padding-bottom: 6px;
}

.tab{
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  background: #fff;
  cursor:pointer;
  flex-grow: 1;
  text-align: center;
  font-weight: 500;
}
.tab[aria-selected="true"]{
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}


/* =========================================================
   MAP (FULL SCREEN APP VERA)
========================================================= */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh; 
  overflow: hidden; 
}

/* Forziamo il contenitore principale a ignorare i margini e prendere il 100% dello schermo */
main#main {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  flex-grow: 1; 
  display: flex;
  flex-direction: column;
}

/* Togliamo TUTTI i bordi, i margini e gli angoli arrotondati dalla card */
.map-card {
  flex-grow: 1; 
  margin: 0; 
  border-radius: 0; 
  border: none;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #ffffff; /* Sfondo bianco puro, così si fonde con le immagini delle piantine */
  
  display: flex;
  justify-content: center;
  align-items: center;
}

.map-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
}


#map-image {
  width: 100%;
  height: auto;
  max-height: 100%; /* Evita che un'immagine altissima sballi le proporzioni */
  object-fit: contain; /* Si adatta perfettamente senza deformarsi */
  display: block;
  user-select: none;
}

.points-layer {
  position: absolute;
  inset: 0;
}

/* Marker buttons */
.marker{
  --size: clamp(40px, 4.2vw, 48px);
  position:absolute;
  width: var(--size);
  height: var(--size);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  display:grid;
  place-items:center;

  background: rgba(255,255,255,.55);
  border: 2px solid rgba(0,0,0,.06);
  cursor:pointer;
  padding:0;
  touch-action: manipulation;
}
.marker > span{
  display:block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  display:grid;
  place-items:center;
  font-weight: 900;
  font-size: 14px;

  background: var(--primary);
  color: #fff;
  border: 2px solid rgba(255,255,255,.95);
  box-shadow: 0 10px 18px rgba(0,0,0,.18);
}
.marker:focus-visible{
  outline: none;
  box-shadow: 0 0 0 5px var(--focus);
}
.marker:hover > span{ filter: brightness(1.02); }

/* “purple” -> accent (punti di raccolta) */
.marker--purple > span{
  background: var(--accent);
  color: #12324f;
}

/* =========================================================
   ANIMAZIONE RADAR - A PROVA DI SMANDRUPPAMENTO
========================================================= */
@keyframes radar-pulse {
  0% { box-shadow: 0 0 0 0 rgba(240, 180, 41, 0.9); }
  70% { box-shadow: 0 0 0 25px rgba(240, 180, 41, 0); }
  100% { box-shadow: 0 0 0 0 rgba(240, 180, 41, 0); }
}

.marker.is-pulsing {
  /* Dura 1 secondo, si ripete 5 volte, poi si blocca */
  animation: radar-pulse 1s 5 forwards;
  z-index: 10;
}

.marker.is-pulsing > span {
  background: var(--accent);
  color: #12324f;
  border-color: #12324f;
}

/* =========================================================
   PANEL (mobile bottom-sheet / desktop side)
========================================================= */
.overlay{
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .35);
  z-index: 55;
}

.panel{
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 60;
  background: var(--card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -18px 40px rgba(0,0,0,.18);
  border-radius: 16px 16px 0 0;
  max-height: 82vh;
  display:flex;
  flex-direction: column;
  
  /* Cuscinetto per iPhone con barra home in basso */
  padding-bottom: env(safe-area-inset-bottom);
}
.panel__header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}
.panel__title{ margin:0; font-size: 16px; font-weight: 800; }
.panel__body{ padding: 12px; overflow:auto; }

.point-list{
  list-style:none;
  margin: 12px 0 0;
  padding: 0;
  display:grid;
  gap: 10px;
}
.point-item button{
  width:100%;
  text-align:left;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
  border-radius: 12px;
}
.badge{
  min-width: 44px;
  height: 30px;
  border-radius: 999px;
  display:grid;
  place-items:center;
  font-weight: 900;
  background: rgba(42,92,154,.10);
  border: 1px solid rgba(42,92,154,.25);
}

/* Desktop: panel side */
@media (min-width: 920px){
  .panel{
    top: 116px;
    bottom: auto;
    left: auto;
    right: 16px;
    width: 360px;
    max-height: calc(100vh - 140px);
    border-radius: 14px;
    border: 1px solid var(--border);
    padding-bottom: 0;
  }
}

/* Blocca scroll quando overlay/panel/dialog aperti */
body.panel-open,
body.modal-open{
  overflow: hidden;
}

/* =========================================================
   DIALOG
========================================================= */
.dialog{
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 70;
  width: min(640px, calc(100% - 24px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow:hidden;
}
.dialog__header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.dialog__title{ margin:0; font-size: 16px; font-weight: 900; }
.dialog__content{
  padding: 12px;
  max-height: min(60vh, 520px);
  overflow:auto;
}

/* =========================================================
   FAB / MENU EMERGENZE
========================================================= */
.fab {
  position: fixed;
  
  /* Cuscinetto per iPhone con barra home in basso */
  bottom: calc(18px + env(safe-area-inset-bottom));
  right: 18px;
  
  z-index: 75;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 12px;
}

/* Bottone principale (SOS) */
.fab__main {
  width: 60px;
  height: 60px;
  border-radius: 999px;
  border: none;
  background: var(--danger); /* Rosso emergenza */
  color: #fff;
  font-size: 24px;
  box-shadow: 0 10px 22px rgba(0,0,0,.22);
  cursor: pointer;
  transition: transform 0.2s;
}
.fab__main:active { transform: scale(0.95); }

/* Pannello aperto */
.fab__options {
  display: none;
  flex-direction: column;
  align-items: stretch; 
  gap: 10px;
  background: var(--card);
  padding: 16px;
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0,0,0,.15);
  border: 1px solid var(--border);
  width: min(calc(100vw - 36px), 320px); /* Si adatta al telefono */
  transform-origin: bottom right;
  animation: popIn 0.2s ease-out forwards;
}
.fab.open .fab__options { display: flex; }

@keyframes popIn {
  from { opacity: 0; transform: scale(0.9) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Banner: Qual è il problema? */
.fab-banner {
  text-align: center;
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  color: var(--text);
}

/* Stile dei singoli bottoni di emergenza */
.emergency-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  padding: 12px;
  border-radius: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--text);
  transition: background 0.2s;
}
.emergency-btn:active { transform: translateY(1px); background: #f1f4f8; }

.emergency-btn .icon {
  font-size: 20px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  flex-shrink: 0;
}

.emergency-btn .info {
  display: flex;
  flex-direction: column;
}

.emergency-btn .title {
  font-weight: 700;
  font-size: 15px;
}

.emergency-btn .subtitle {
  font-size: 13px;
  color: var(--muted);
}

/* Colori specifici per le icone delle categorie */
.journalists .icon { background: var(--accent); color: #12324f; }
.police .icon { background: var(--primary); }
.non-medical .icon { background: var(--accent); color: #12324f; }
.medical .icon { background: var(--danger); }

/* Nascondi FAB quando panel/dialog aperti (mobile UX) */
body.panel-open .fab,
body.modal-open .fab {
  display: none;
}

/* =========================================================
   MOBILE TUNING
========================================================= */
@media (max-width: 560px){
  .app-header__top{
    flex-direction: row; /* Modificato: forza la riga singola in alto */
    align-items: center;
  }
  .btn{ padding: 10px 12px; }
  .brand__title h1{ font-size: 16px; }
  .brand__title p{ display: none; /* Rimosso per pulizia */ }
  .panel{ max-height: 88vh; }
}
