/* Backoffice — palette coerente con l'app mobile (#2b5d8a blu, #f5f2ea carta) */
:root {
  --blue: #2b5d8a;
  --blue-dark: #214a6e;
  --paper: #f5f2ea;
  --card: #ffffff;
  --ink: #2b2b2b;
  --muted: #6b6b6b;
  --line: #e2ddd1;
  --danger: #c22f2f;
  --ok: #4a8f5c;
  --warn: #d9a11b;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 16px rgb(0 0 0 / 0.05);
  --s1: #3f7a8c; --s2: #4a8f5c; --s3: #d9a11b; --s4: #d96b1b; --s5: #c22f2f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---- Pulsanti ---- */
.btn {
  font: inherit; font-weight: 600; border-radius: 8px; border: 1px solid transparent;
  padding: .55rem 1rem; cursor: pointer; background: #ece8dd; color: var(--ink);
  display: inline-flex; align-items: center; gap: .35rem; text-decoration: none;
}
.btn:hover { filter: brightness(.96); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgb(43 93 138 / .35); outline-offset: 1px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); filter: none; }
.btn-danger { background: #fbe9e9; color: var(--danger); border-color: #f1caca; }
.btn-ghost { background: transparent; color: var(--blue); }
.btn-ghost:hover { background: rgb(43 93 138 / .08); filter: none; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; justify-content: center; margin-top: .6rem; }

/* ---- Form ---- */
label { display: block; font-weight: 600; font-size: .9rem; margin: .8rem 0 .25rem; }
input, select, textarea {
  font: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid #d5cfc1;
  border-radius: 8px; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
input:user-invalid, textarea:user-invalid, select:user-invalid { border-color: var(--danger); background: #fdf1f1; }
.hint { display: block; color: var(--muted); font-size: .8rem; margin-bottom: .25rem; }
.form-error { color: var(--danger); min-height: 1.2em; margin: .6rem 0 0; font-size: .9rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }

/* ---- Login / cambio password ---- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(380px, 100%); background: var(--card); border-radius: 14px; padding: 2rem;
  box-shadow: var(--shadow); text-align: left;
}
.auth-card h1 { text-align: center; }
.auth-card > .muted { text-align: center; margin-bottom: 1rem; }
.auth-logo { display: block; margin: 0 auto 1rem; object-fit: contain; }

/* ---- Shell ---- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.5rem;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .6rem; font-size: 1rem; }
.brand img { object-fit: contain; }
.brand strong { color: var(--blue); }
.topbar nav ul { list-style: none; display: flex; gap: .25rem; margin: 0; padding: 0; }
.topbar nav a {
  display: block; padding: .45rem .9rem; border-radius: 8px; color: var(--ink);
  text-decoration: none; font-weight: 600;
}
.topbar nav a:hover { background: #f1eee6; }
.topbar nav a[aria-current="page"] { background: var(--blue); color: #fff; }
.user-box { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.content { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head p { margin: 0; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2rem; }

/* ---- Tabelle ---- */
.table-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #faf8f3; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfbf8; }
tr.is-inactive td { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: flex-end; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* ---- Badge ---- */
.badge {
  display: inline-block; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem;
  font-weight: 700; background: #ece8dd; color: var(--ink); white-space: nowrap;
}
.badge-ok { background: #e3f1e6; color: #2f6b3e; }
.badge-warn { background: #fbf1d8; color: #8a6510; }
.badge-off { background: #eee; color: #777; }
.badge-danger { background: #fbe9e9; color: var(--danger); }
.badge-blue { background: #e4edf5; color: var(--blue); }
.sev { color: #fff; }
.sev-molto_bassa { background: var(--s1); } .sev-bassa { background: var(--s2); }
.sev-media { background: var(--s3); } .sev-alta { background: var(--s4); } .sev-critica { background: var(--s5); }

/* ---- Filtri ---- */
.filters { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; margin-bottom: 1rem; }
.filters label { margin: 0 0 .2rem; font-size: .8rem; }
.filters select { min-width: 160px; }

/* ---- Dettaglio ispezione ---- */
.meta { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; margin: .3rem 0 0; padding: 0; list-style: none; color: var(--muted); font-size: .9rem; }
.meta strong { color: var(--ink); font-weight: 600; }
.toolbar { display: flex; flex-wrap: wrap; gap: .4rem; }
.notice { background: #fbf1d8; border: 1px solid #efdca6; color: #6d5210; padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.detail { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 1.2rem; align-items: start; }
.map-card { position: sticky; top: 76px; }
.map-frame { position: relative; line-height: 0; border-radius: 8px; overflow: hidden; background: #eee; }
.map-frame img { width: 100%; height: auto; display: block; }
.pin {
  position: absolute; left: calc(var(--x) * 100%); top: calc(var(--y) * 100%);
  transform: translate(-50%, -50%); min-width: 26px; height: 26px; padding: 0 5px;
  border-radius: 13px; border: 2px solid #fff; color: #fff; font-weight: 800; font-size: 12px;
  line-height: 22px; text-align: center; cursor: pointer; box-shadow: 0 1px 4px rgb(0 0 0 / .35);
}
.pin.is-excluded { opacity: .45; border-style: dashed; }
.pin.is-active { outline: 3px solid var(--ink); z-index: 2; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; line-height: 1.4; }
.reports { display: grid; gap: .8rem; }
.report {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1.1rem; border-left: 5px solid var(--sevc, #999); scroll-margin-top: 90px;
}
.report.is-active { box-shadow: 0 0 0 3px rgb(43 93 138 / .35), var(--shadow); }
.report.is-excluded { opacity: .7; }
.report-head { display: flex; justify-content: space-between; gap: .6rem; align-items: flex-start; }
.report-head h3 { font-size: 1rem; margin: 0; }
.report dl { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: .6rem 0; font-size: .9rem; }
.report dt { color: var(--muted); }
.report dd { margin: 0; }
.report .desc { white-space: pre-wrap; margin: .4rem 0; }
.transcript { font-style: italic; color: #444; background: #faf8f3; padding: .5rem .7rem; border-radius: 6px; }
.photos { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.photos a { display: block; line-height: 0; }
.photos img { width: 84px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

/* ---- Mappe ---- */
.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 1rem; }
.site-card-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .8rem; }
.site-card-head h2 { font-size: 1.05rem; margin: 0; }
/* Le planimetrie hanno proporzioni molto diverse (banchine strette e lunghe,
   atri quasi quadrati, discenderie strette e alte): altezza fissa e larghezza
   libera rendono ogni miniatura leggibile invece di schiacciarla in un
   riquadro 4:3 con bordi vuoti. */
.map-thumbs { display: flex; flex-wrap: wrap; gap: .7rem; }
.map-thumb {
  display: flex; flex-direction: column; gap: .35rem; padding: 0; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; cursor: zoom-in; text-align: left; overflow: hidden;
  max-width: 100%;
}
.map-thumb:hover { border-color: var(--blue); }
.map-thumb-img {
  display: flex; align-items: center; justify-content: center; height: 190px; width: auto;
  background: #f1eee6; overflow: hidden;
}
.map-thumb-img img { height: 100%; width: auto; max-width: 340px; object-fit: contain; display: block; }
.map-thumb-label { font-size: .78rem; padding: 0 .5rem .5rem; color: var(--ink); line-height: 1.25; max-width: 340px; }

@media (max-width: 560px) {
  .map-thumb-img { height: 140px; }
  .map-thumb-img img { max-width: 240px; }
  .map-thumb-label { max-width: 240px; }
}

.map-zoom {
  position: relative; overflow: hidden; border-radius: 8px; background: #f1eee6;
  height: 78vh; max-height: 78vh; touch-action: none; cursor: grab; user-select: none;
}
.map-zoom.is-dragging { cursor: grabbing; }
.map-zoom img {
  position: absolute; top: 0; left: 0; max-width: none; width: 100%; height: 100%;
  object-fit: contain; transform-origin: 0 0; pointer-events: none;
}
.map-zoom-actions { display: flex; justify-content: flex-end; margin-top: .5rem; }

/* ---- Assegnazioni ---- */
.site-block { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .9rem .7rem; margin: .7rem 0; }
.site-block legend { font-weight: 700; padding: 0 .3rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin: .35rem 0; }
.check input { width: auto; margin: 0; }
.check.all { font-weight: 700; border-bottom: 1px solid var(--line); padding-bottom: .4rem; }

/* ---- Dialog ---- */
dialog {
  border: 0; border-radius: 14px; padding: 1.5rem; width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto;
  box-shadow: 0 20px 60px rgb(0 0 0 / .25); color: var(--ink);
}
dialog::backdrop { background: rgb(30 30 30 / .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.2rem; }
#dialog-body p { margin: .3rem 0; }

/* ---- Toast ---- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: .7rem 1.2rem; border-radius: 8px; opacity: 0;
  pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

@media (max-width: 980px) {
  .detail { grid-template-columns: 1fr; }
  .map-card { position: static; }
  .topbar { flex-wrap: wrap; gap: .6rem; padding: .6rem 1rem; }
  .user-box { margin-left: 0; }
  .content { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
}

/* Testo solo per screen reader */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
input:disabled, select:disabled, textarea:disabled { background: #f3f1ec; color: var(--muted); }

/* --- Schede guidate: RdV per sito, controlli --- */
.rdv-box { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; margin-bottom: .9rem; background: #faf8f3; }
.rdv-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .4rem; }
.rdv-head h3 { font-size: .95rem; margin: 0; margin-right: auto; }
.rdv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.rdv-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .3rem 0; border-top: 1px solid var(--line); }
.rdv-row.is-off .rdv-who { opacity: .55; }
.rdv-who { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.rdv-actions { display: flex; gap: .3rem; flex-wrap: wrap; }
.check-card { margin-bottom: 1.2rem; }
.check-card h2 { font-size: 1.1rem; margin-top: 0; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.check-card h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 .8rem; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .25rem .7rem; cursor: pointer; font: inherit; font-size: .82rem; }
.chip.is-on { background: var(--blue); color: #fff; border-color: var(--blue); }
.table-wrap.inner { box-shadow: none; border: 1px solid var(--line); margin-top: .5rem; }
.pad { padding: .5rem .8rem; }
.legacy { margin: .3rem 0; }
.legacy summary { cursor: pointer; }
