/* =====================================================================
   Diario Arnie — stile
   Pensato per il telefono, all'aperto: contrasto alto, bersagli grandi.
   ===================================================================== */
:root {
  --bg: #F1F2EC; --surface: #FFFFFF; --sunk: #E6E8DF; --ink: #1E231C; --muted: #5D6557;
  --line: #D3D8CA; --amber: #A8650F; --amber-ink: #FFFFFF; --amber-soft: #F5E4C4;
  --meadow: #43663B; --meadow-soft: #DCE8D4; --alarm: #A23A1C; --alarm-soft: #F6DCD2;
  --bar: #2B2F22; --bar-ink: #F4EEDC;
  --r: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15180F; --surface: #1F231A; --sunk: #11140D; --ink: #E9ECE1; --muted: #A3AB98;
    --line: #353B2C; --amber: #E3A548; --amber-ink: #1B1405; --amber-soft: #3A2C13;
    --meadow: #9CC48E; --meadow-soft: #23321E; --alarm: #F0957A; --alarm-soft: #3D2017;
    --bar: #0D0F09; --bar-ink: #F4EEDC;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--font);
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}
a { color: var(--amber); }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 700; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; }
.codice { font-family: var(--mono); letter-spacing: -0.02em; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.txt-allarme { color: var(--alarm); font-weight: 600; }
.errore { display: block; color: var(--alarm); font-size: 14px; }

/* --- barra superiore --- */
.bar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--bar); color: var(--bar-ink);
}
.logo { display: flex; align-items: center; gap: 8px; color: var(--amber); text-decoration: none; font-weight: 800; font-size: 17px; }
.logo span { color: var(--bar-ink); }
.logo svg { width: 22px; height: 26px; }
.az-nome { flex: 1; min-width: 0; font-size: 14px; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { background: transparent; color: var(--bar-ink); border: 1px solid #ffffff40; border-radius: 8px; padding: 6px 12px; font: 600 15px var(--font); }
.menu {
  position: fixed; z-index: 1001; right: 12px; top: calc(56px + env(safe-area-inset-top, 0px));
  width: min(300px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 12px 32px #0003; padding: 8px; display: flex; flex-direction: column;
}
.menu a, .menu button { display: block; text-align: left; padding: 12px; border-radius: 8px; color: var(--ink); text-decoration: none; background: none; border: 0; font: 16px var(--font); }
.menu a:hover, .menu button:hover { background: var(--sunk); }
.menu p { padding: 8px 12px; font-size: 14px; }
.menu label { padding: 8px 12px; }
body.fuori .bar .menu-btn, body.fuori .az-nome { visibility: hidden; }

/* --- avvisi --- */
#banner:empty { display: none; }
.avviso { padding: 10px 16px; font-size: 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.avviso.demo { background: var(--amber-soft); }
.avviso.off { background: var(--sunk); }
.avviso.coda { background: var(--meadow-soft); }

main { max-width: 720px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 24px; }
section { display: flex; flex-direction: column; gap: 12px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.conta { font-size: 14px; font-weight: 600; color: var(--muted); background: var(--sunk); border-radius: 999px; padding: 1px 8px; vertical-align: 2px; }
.head { display: flex; flex-direction: column; gap: 6px; }
.indietro { font-size: 15px; text-decoration: none; font-weight: 600; margin-bottom: -12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.dafare { background: var(--amber-soft); border-radius: 8px; padding: 8px 12px; }

/* --- controlli --- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 0;
  background: var(--sunk); color: var(--ink); font: 600 16px var(--font); text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--amber); color: var(--amber-ink); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn.pericolo { border-color: var(--alarm); color: var(--alarm); }
.btn:disabled { opacity: 0.5; cursor: default; }
button.link { background: none; border: 0; color: var(--amber); font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; color: var(--muted); }
label.stretto { max-width: 220px; }
label.grow { flex: 1 1 200px; }
input, select, textarea {
  font: 16px var(--font); color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 8px; padding: 10px; width: 100%; min-width: 0; min-height: 44px;
}
textarea { resize: vertical; line-height: 1.45; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
legend { font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 0 4px; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
form.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* --- mappa --- */
.map { height: 280px; border-radius: var(--r); border: 1px solid var(--line); background: var(--sunk); z-index: 0; }
.map.small { height: 200px; }
#mapForm { height: 300px; }
.leaflet-container { font: 14px var(--font); }
.pin-wrap { background: none; border: 0; }
.pin {
  width: 34px; height: 36px; background: var(--amber); color: var(--amber-ink);
  clip-path: polygon(50% 0, 100% 24%, 100% 70%, 50% 100%, 0 70%, 0 24%);
  display: grid; place-items: center; font: 800 14px var(--font);
  filter: drop-shadow(0 1px 2px #0006);
}
.pin.allarme { background: var(--alarm); color: #fff; }
.tu { width: 18px; height: 18px; border-radius: 50%; background: #2F6FDB; border: 3px solid #fff; box-shadow: 0 0 0 6px #2F6FDB33; }

/* --- "sei qui" --- */
.qui-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.qui-card.dentro { border: 2px solid var(--meadow); background: linear-gradient(var(--meadow-soft), var(--surface) 90px); }
.qui-card h2 { font-size: 24px; }
.qui-card h2 a { color: var(--ink); text-decoration: none; }

/* --- liste --- */
.lista { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lista > li > a, .lista > li > div, .lista li.riga-coda, .lista li.riga-op {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  color: var(--ink); text-decoration: none;
}
.lista li.riga-coda, .lista li.riga-op { justify-content: space-between; align-items: center; }
.lista li.riga-coda > div, .lista li.riga-op > div { display: flex; flex-direction: column; gap: 2px; background: none; border: 0; padding: 0; }
.lista.compatta > li > div { display: block; padding: 10px 12px; font-size: 15px; }
.lista li.riga-op > div { display: block; }
.lista b { font-weight: 700; }
.lista .riassunto { flex-basis: 100%; color: var(--muted); font-size: 14px; }
.riga-dx { margin-left: auto; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.lista .vuoto { padding: 12px 0; color: var(--muted); }
.pill { font-size: 13px; font-weight: 600; border-radius: 999px; padding: 2px 9px; background: var(--sunk); }
.pill.allarme { background: var(--alarm-soft); color: var(--alarm); }

/* --- arnie (tessere) --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 2px;
  padding: 10px 10px 10px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  color: var(--ink); text-decoration: none; min-height: 64px; overflow: hidden;
}
.tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--line); }
.tile.ok::before { background: var(--meadow); }
.tile.allarme::before { background: var(--alarm); }
.tile.mai::before { background: var(--amber); }
.tile.spenta { opacity: 0.6; }
.tile b { font: 800 19px var(--mono); }
.tile small { color: var(--muted); font-size: 12.5px; line-height: 1.25; }
.tile.allarme small { color: var(--alarm); }
.flag { font-style: normal; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--amber); }
.tile .check { display: none; position: absolute; top: 8px; right: 8px; width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--line); background: var(--surface); }
.in-selezione .tile .check { display: block; }
.in-selezione .tile.scelta { border-color: var(--amber); box-shadow: inset 0 0 0 2px var(--amber); }
.in-selezione .tile.scelta .check { background: var(--amber); border-color: var(--amber); }
.in-selezione .tile.scelta .check::after { content: ""; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px; border: solid var(--amber-ink); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); }
details.altre summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: 8px; }

.selbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
  background: var(--bar); color: var(--bar-ink);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between;
  box-shadow: 0 -6px 20px #0003;
}
.selbar .btn.ghost { color: var(--bar-ink); border-color: #ffffff50; }

.chk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.chk { flex-direction: row; align-items: center; gap: 6px; background: var(--sunk); border-radius: 8px; padding: 8px; color: var(--ink); font: 700 15px var(--mono); }
.chk input { width: 20px; height: 20px; min-height: 0; accent-color: var(--amber); }

/* --- chip stato --- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13.5px; border-radius: 999px; padding: 3px 10px; background: var(--sunk); font-variant-numeric: tabular-nums; }
.chip.ok { background: var(--meadow-soft); color: var(--meadow); }
.chip.allarme { background: var(--alarm-soft); color: var(--alarm); }
.chip.miele, .chip.mai { background: var(--amber-soft); }
.chip.spenta { background: var(--sunk); color: var(--muted); }

/* --- registrazione --- */
.registra.occupato { opacity: 0.7; pointer-events: none; }
.mic {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 72px; border-radius: 16px; border: 0; cursor: pointer;
  background: var(--amber); color: var(--amber-ink); font: 700 19px var(--font);
}
.mic svg { width: 30px; height: 30px; }
.mic.attivo { background: var(--alarm); color: #fff; }
.mic-stato { min-height: 1.5em; display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.rec { width: 12px; height: 12px; border-radius: 50%; background: var(--alarm); animation: pulsa 1s ease-in-out infinite; }
@keyframes pulsa { 50% { opacity: 0.3; } }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: gira 0.8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .rec, .spinner { animation: none; } }

/* --- storico --- */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.voce { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--ink); text-decoration: none; }
.voce.bozza { border-style: dashed; border-color: var(--amber); }
.voce.intervento { background: var(--sunk); border-color: transparent; }
.voce-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.voce time { font: 700 14px var(--mono); }
.voce p { font-size: 15px; }
.voce p b { color: var(--muted); font-weight: 600; }
.tag { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; }

/* --- scheda visita --- */
.campi { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.campi.tre { grid-template-columns: 2fr 1fr 1fr; }
.campi .wide { grid-column: 1 / -1; }
.campi .pieno input, .campi .pieno select, .campi .pieno textarea { border-color: var(--meadow); background: var(--meadow-soft); }
.dubbi { background: var(--amber-soft); border-radius: 10px; padding: 10px 14px; font-size: 15px; }
.dubbi ul { margin: 4px 0 0; padding-left: 20px; }
details.nota summary, details.dettagli summary { cursor: pointer; font-weight: 700; }
details.nota[open], details.dettagli[open] { gap: 12px; }
audio { width: 100%; }

/* --- registro --- */
.scroll-x { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); background: var(--sunk); }

/* --- accesso --- */
.accesso { max-width: 420px; margin: 8vh auto 0; display: flex; flex-direction: column; gap: 12px; }

/* --- etichette --- */
.etichette { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.etichetta { display: flex; gap: 10px; align-items: center; background: #fff; color: #111; border: 1px dashed #999; border-radius: 8px; padding: 10px; break-inside: avoid; }
.etichetta svg { width: 96px; height: 96px; flex: none; }
.etichetta b { display: block; font: 800 30px var(--mono); line-height: 1; }
.etichetta small { display: block; font-size: 11px; color: #444; }
.etichetta .url { word-break: break-all; font-size: 9px; color: #777; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px);
  z-index: 2000; max-width: min(520px, calc(100vw - 32px)); width: max-content;
  background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 10px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--alarm); color: #fff; }

@media (max-width: 440px) {
  .row2, .campi { grid-template-columns: 1fr; }
  .campi.tre { grid-template-columns: 1fr 1fr; }
  .campi.tre label:first-child { grid-column: 1 / -1; }
  h1 { font-size: 25px; }
}

@media print {
  .bar, .menu, #banner, .no-stampa, .toast { display: none !important; }
  body { background: #fff; padding: 0; }
  main { max-width: none; padding: 0; }
  .etichette { grid-template-columns: repeat(3, 1fr); gap: 4mm; }
}
