/* ============================================================
   SegnalaANZIO — Stile principale
   Mobile-first, design istituzionale comunale
   ============================================================ */

/* --- Variabili colori ---------------------------------------- */
:root {
  --blu-comune:    #1a3a6b;
  --blu-hover:     #142d55;
  --blu-chiaro:    #e8f0fe;
  --arancio:       #e67e22;
  --rosso:         #c0392b;
  --verde:         #27ae60;
  --grigio-bg:     #f4f6f9;
  --grigio-bordo:  #dee2e6;
  --testo:         #333333;
  --testo-sec:     #6c757d;
  --bianco:        #ffffff;
  --radius:        8px;
  --shadow:        0 2px 12px rgba(0,0,0,.08);
  --shadow-lg:     0 4px 24px rgba(0,0,0,.12);
}

/* --- Reset & base -------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  /* Blocca scroll orizzontale: evita che elementi più larghi dello schermo
     causino scorrimento con testo bianco su sfondo chiaro su mobile */
  overflow-x: hidden;
  /* Colore overscroll iOS in alto/basso uguale alla topbar */
  background: var(--blu-comune);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--grigio-bg);
  color: var(--testo);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--blu-comune); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* --- Topbar -------------------------------------------------- */
.topbar {
  background: var(--blu-comune);
  color: var(--bianco);
  padding: 0 16px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  width: 100%;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--bianco);
  text-decoration: none;
}

.topbar-brand .logo-pin { font-size: 1.4rem; }

.topbar-brand small {
  display: block;
  font-size: 0.65rem;
  font-weight: 400;
  opacity: .75;
  line-height: 1;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.topbar-actions a, .topbar-actions button {
  color: var(--bianco);
  background: rgba(255,255,255,.12);
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: .85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background .2s;
}
.topbar-actions a:hover, .topbar-actions button:hover {
  background: rgba(255,255,255,.22);
  text-decoration: none;
}

/* --- Hamburger (solo mobile) -------------------------------- */
#btn-hamburger {
  display: none;
  background: rgba(255,255,255,.12);
  border: none;
  border-radius: 6px;
  color: var(--bianco);
  padding: 8px 10px;
  cursor: pointer;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
}
#btn-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--bianco);
  border-radius: 2px;
  transition: transform .25s, opacity .25s;
}
#btn-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#btn-hamburger.open span:nth-child(2) { opacity: 0; }
#btn-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* --- Menu mobile a scomparsa ------------------------------- */
#mobile-menu {
  display: none;
  position: fixed;
  top: 58px;
  left: 0;
  right: 0;
  background: var(--blu-comune);
  z-index: 998;
  padding: 8px 0 16px;
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
  overflow-y: auto;
  max-height: calc(100vh - 58px);
}
#mobile-menu.open { display: block; }

.mobile-menu-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  color: rgba(255,255,255,.92);
  font-size: .95rem;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,.08);
  transition: background .15s;
}
.mobile-menu-link:hover, .mobile-menu-link:active {
  background: rgba(255,255,255,.12);
  text-decoration: none;
  color: #fff;
}
.mobile-menu-link i { width: 20px; text-align: center; opacity: .8; }

.mobile-menu-section {
  padding: 8px 20px 4px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.45);
  margin-top: 6px;
}

.mobile-menu-divider {
  height: 1px;
  background: rgba(255,255,255,.12);
  margin: 6px 0;
}

@media (max-width: 768px) {
  .topbar-actions { display: none; }
  #btn-hamburger  { display: flex; }
}

/* --- Dropdown menu topbar (solo desktop) ------------------- */
.nav-dropdown { position: relative; }

.nav-dropdown-btn {
  color: var(--bianco);
  background: rgba(255,255,255,.12);
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: .85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background .2s;
  white-space: nowrap;
}
.nav-dropdown-btn:hover { background: rgba(255,255,255,.22); }

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 210px;
  background: var(--bianco);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,.18);
  z-index: 2000;
  overflow: hidden;
  animation: dropIn .15s ease;
}
.nav-dropdown-menu.nav-dropdown-right { left: auto; right: 0; }
.nav-dropdown-menu.open { display: block; }

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.nav-dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--testo);
  font-size: .875rem;
  text-decoration: none;
  transition: background .12s;
}
.nav-dropdown-menu a:hover { background: var(--grigio-bg); color: var(--blu-comune); }
.nav-dropdown-menu a i { width: 16px; text-align: center; color: var(--testo-sec); }

.dd-header {
  padding: 12px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dd-header strong { font-size: .875rem; color: var(--blu-comune); }
.dd-header small  { font-size: .75rem; color: var(--testo-sec); }

.dd-divider {
  height: 1px;
  background: var(--grigio-bordo);
  margin: 2px 0;
}

/* --- Navigazione mobile (bottom bar) ----------------------- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bianco);
  border-top: 1px solid var(--grigio-bordo);
  height: 64px;
  z-index: 999;
  padding: 0 8px;
}

.bottom-nav-items {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-around;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 12px;
  color: var(--testo-sec);
  font-size: .7rem;
  text-decoration: none;
  border-radius: 8px;
  transition: color .2s;
}
.bottom-nav-item.active, .bottom-nav-item:hover {
  color: var(--blu-comune);
  text-decoration: none;
}
.bottom-nav-item .icon { font-size: 1.4rem; }

.bottom-nav-fab {
  background: var(--blu-comune);
  color: var(--bianco) !important;
  border-radius: 50%;
  width: 52px;
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 4px 14px rgba(26,58,107,.4);
}
.bottom-nav-fab .icon { font-size: 1.6rem; margin: 0; }

@media (max-width: 768px) {
  .bottom-nav { display: block; }
  body { padding-bottom: 64px; }
}

/* --- Layout principale -------------------------------------- */
.main-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
  box-sizing: border-box;
  width: 100%;
}

/* --- Grid 2 colonne responsive ------------------------------ */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 768px) {
  .grid-2col { grid-template-columns: 1fr; row-gap: 28px; }
}

/* --- Sidebar desktop ---------------------------------------- */
.layout-with-sidebar {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  align-items: start;
}

.sidebar {
  background: var(--bianco);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 0;
  position: sticky;
  top: 78px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--testo);
  font-size: .9rem;
  transition: background .15s, color .15s;
}
.sidebar-nav-item:hover, .sidebar-nav-item.active {
  background: var(--blu-chiaro);
  color: var(--blu-comune);
  text-decoration: none;
}
.sidebar-nav-item .icon { font-size: 1.1rem; width: 22px; }
.sidebar-divider {
  height: 1px;
  background: var(--grigio-bordo);
  margin: 8px 0;
}
.sidebar-section-title {
  padding: 8px 20px 4px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--testo-sec);
  font-weight: 600;
}

@media (max-width: 900px) {
  .layout-with-sidebar {
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
}

/* --- Card --------------------------------------------------- */
.card {
  background: var(--bianco);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--grigio-bordo);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2, .card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--blu-comune);
  margin: 0;
}

.card-body { padding: 20px; }

/* --- Pulsanti ----------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 6px;
  border: none;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
  line-height: 1.3;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn:active { transform: scale(.97); }

.btn-primary   { background: var(--blu-comune);  color: var(--bianco); }
.btn-danger    { background: var(--rosso);        color: var(--bianco); }
.btn-success   { background: var(--verde);        color: var(--bianco); }
.btn-warning   { background: var(--arancio);      color: var(--bianco); }
.btn-secondary { background: #6c757d;             color: var(--bianco); }
.btn-outline   { background: transparent; border: 1.5px solid var(--blu-comune); color: var(--blu-comune); }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-full { width: 100%; justify-content: center; }

/* --- Form --------------------------------------------------- */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--testo);
}
.form-label .req { color: var(--rosso); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--grigio-bordo);
  border-radius: 6px;
  font-size: .9rem;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
  background: var(--bianco);
  color: var(--testo);
}
.form-control:focus {
  outline: none;
  border-color: var(--blu-comune);
  box-shadow: 0 0 0 3px rgba(26,58,107,.1);
}
.form-control.is-invalid { border-color: var(--rosso); }

textarea.form-control { resize: vertical; min-height: 90px; }

.form-hint { font-size: .78rem; color: var(--testo-sec); margin-top: 4px; }
.form-error { font-size: .78rem; color: var(--rosso); margin-top: 4px; }

/* Checkbox personalizzato */
.form-check { display: flex; align-items: flex-start; gap: 10px; }
.form-check input[type="checkbox"] {
  width: 18px; height: 18px; margin-top: 2px;
  accent-color: var(--blu-comune); flex-shrink: 0;
}

/* --- Badge stato ticket ------------------------------------ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-danger    { background: #fde8e8; color: #c0392b; }
.badge-warning   { background: #fef3e2; color: #b7770d; }
.badge-info      { background: #e3f3ff; color: #1a6ea8; }
.badge-primary   { background: var(--blu-chiaro); color: var(--blu-comune); }
.badge-secondary { background: #e9ecef; color: #495057; }
.badge-success   { background: #e9f7ef; color: #1e8449; }
.badge-dark      { background: #343a40; color: #ffffff; }
.badge-light     { background: #f8f9fa; color: #495057; border: 1px solid #dee2e6; }

/* --- Priorità ---------------------------------------------- */
.priority-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}
.priority-urgente { background: var(--rosso); }
.priority-alta    { background: var(--arancio); }
.priority-media   { background: #f0c040; }
.priority-bassa   { background: var(--verde); }

/* --- Alert ------------------------------------------------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .9rem;
  margin-bottom: 16px;
  border-left: 4px solid;
}
.alert-danger  { background: #fde8e8; border-color: var(--rosso); color: #922b21; }
.alert-success { background: #eafaf1; border-color: var(--verde); color: #1e6b39; }
.alert-warning { background: #fef9e7; border-color: var(--arancio); color: #7d5a00; }
.alert-info    { background: #e8f4fd; border-color: #2980b9; color: #1a4f7a; }

/* --- Tabella ----------------------------------------------- */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Impedisce che lo scroll interno propaghi al body (fix iOS) */
  overscroll-behavior-x: contain;
  max-width: 100%;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.table th {
  padding: 10px 14px;
  background: var(--grigio-bg);
  font-weight: 600;
  text-align: left;
  color: var(--testo-sec);
  border-bottom: 2px solid var(--grigio-bordo);
  white-space: nowrap;
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--grigio-bordo);
  vertical-align: middle;
}
.table tr:hover td { background: #f9fbff; }
.table tr.urgente td { background: #fff5f5; }

/* --- Stats card -------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bianco);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  text-align: center;
  border-top: 3px solid var(--blu-comune);
}
.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--blu-comune);
  line-height: 1;
}
.stat-card .stat-label {
  font-size: .75rem;
  color: var(--testo-sec);
  margin-top: 6px;
}
.stat-card.danger  { border-color: var(--rosso); }
.stat-card.danger  .stat-value { color: var(--rosso); }
.stat-card.success { border-color: var(--verde); }
.stat-card.success .stat-value { color: var(--verde); }
.stat-card.warning { border-color: var(--arancio); }
.stat-card.warning .stat-value { color: var(--arancio); }

/* --- Mappa ------------------------------------------------- */
#mappa, #mappa-pubblica, #mappa-segnalazione {
  width: 100%;
  height: 400px;
  border-radius: var(--radius);
}
#mappa-fullscreen { height: 520px; }

.mappa-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* --- Upload foto ------------------------------------------- */
.foto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.foto-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
.foto-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.foto-thumb .remove-btn {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-zone {
  border: 2px dashed var(--grigio-bordo);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--testo-sec);
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--blu-comune);
  background: var(--blu-chiaro);
}
.drop-zone .icon { font-size: 2rem; display: block; margin-bottom: 8px; }

/* --- Timeline cronologia ----------------------------------- */
.timeline { padding-left: 0; list-style: none; }

.timeline-item {
  position: relative;
  padding: 0 0 20px 36px;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 24px;
  bottom: 0;
  width: 2px;
  background: var(--grigio-bordo);
}
.timeline-item:last-child::before { display: none; }

.timeline-dot {
  position: absolute;
  left: 4px;
  top: 6px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--blu-comune);
  border: 2px solid var(--bianco);
  box-shadow: 0 0 0 2px var(--blu-comune);
}

.timeline-date { font-size: .75rem; color: var(--testo-sec); }
.timeline-stato { font-weight: 600; color: var(--blu-comune); margin: 2px 0; }
.timeline-note { font-size: .85rem; color: var(--testo); }

/* --- Pagina login/register --------------------------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--blu-comune) 0%, #2c5aa0 100%);
  padding: 20px;
}

.auth-card {
  background: var(--bianco);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}

.auth-header {
  background: var(--blu-comune);
  padding: 28px 24px;
  text-align: center;
  color: var(--bianco);
}
.auth-header .logo-pin { font-size: 2.5rem; }
.auth-header h1 { font-size: 1.5rem; font-weight: 700; margin: 8px 0 4px; }
.auth-header p  { font-size: .85rem; opacity: .8; margin: 0; }

.auth-body { padding: 28px 24px; }

.auth-footer {
  padding: 16px 24px;
  background: var(--grigio-bg);
  text-align: center;
  font-size: .85rem;
  border-top: 1px solid var(--grigio-bordo);
}

/* --- Dettaglio segnalazione -------------------------------- */
.segnalazione-header {
  background: var(--bianco);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.protocollo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--blu-comune);
  letter-spacing: .03em;
}

/* --- Filtri ------------------------------------------------ */
.filtri-bar {
  background: var(--bianco);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.filtri-bar .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }

/* --- Toast notifica ---------------------------------------- */
.toast-container {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #333;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: .875rem;
  box-shadow: var(--shadow-lg);
  animation: slideIn .3s ease;
  max-width: 320px;
}
.toast.success { background: var(--verde); }
.toast.error   { background: var(--rosso); }

@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* .fab-segnala definita nell'inline style di layout.php */

/* --- Utility ----------------------------------------------- */
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-muted   { color: var(--testo-sec); }
.text-danger  { color: var(--rosso); }
.text-success { color: var(--verde); }
.text-warning { color: var(--arancio); }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.w-100 { width: 100%; }
.hidden { display: none !important; }
