/* app.css — stile base ConsuntivaODS.
   Mobile-first: l'operatore accede da smartphone in ~90% dei casi. Bersagli
   ampi, contrasto alto (si legge all'aperto), nessun framework CSS, nessun build.
   L'area admin/coordinatore e' desktop-first e usa le stesse primitive. */

:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --fg: #1c2530;
  --muted: #5b6b7c;
  --accent: #0b6b3a;
  --accent-scuro: #085129;
  --pericolo: #a32020;
  --avviso: #8a6100;
  --border: #d8dee5;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

/* Bersagli tattili: minimo 44px, come da linee guida mobile. */
button, .btn, input[type="submit"] {
  display: inline-block;
  min-height: 44px;
  padding: 10px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--accent-scuro); }

.btn-secondario {
  background: var(--card);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-secondario:hover { background: #f0f6f2; }
.btn-pericolo { background: var(--pericolo); }
.btn-pericolo:hover { background: #7d1818; }

input, select, textarea {
  min-height: 44px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;      /* < 16px farebbe zoomare iOS al focus */
  background: var(--card);
  color: var(--fg);
}
input[type="checkbox"] { width: auto; min-height: auto; }

label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: .95rem; }
label.inline {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 4px 12px 4px 0; font-weight: 400;
}

/* ── Login ─────────────────────────────────────────────────────────── */

.login-body {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
}
.login-card h1 { margin: 0 0 4px; font-size: 1.5rem; }
.login-card .sub { margin: 0 0 20px; color: var(--muted); font-size: .95rem; }
.login-footer { color: var(--muted); font-size: .85rem; }

.form-login { text-align: left; }
.form-login label { margin-top: 14px; }
.form-login button { width: 100%; margin-top: 20px; }

.separatore {
  display: flex; align-items: center; gap: 10px;
  margin: 22px 0 16px; color: var(--muted); font-size: .85rem;
}
.separatore::before, .separatore::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.login-card .btn-secondario { width: 100%; }

/* ── Struttura interna ─────────────────────────────────────────────── */

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar-ruolo {
  margin-left: 8px; padding: 2px 8px;
  border-radius: 999px; background: var(--bg);
  color: var(--muted); font-size: .78rem; text-transform: uppercase;
}
.topbar-nav { display: flex; gap: 16px; }
.topbar-nav a { text-decoration: none; font-weight: 600; }

.contenuto { max-width: 1100px; margin: 0 auto; padding: 20px; }
.footer { padding: 24px 20px; text-align: center; color: var(--muted); font-size: .85rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card-stretta { max-width: 480px; margin: 0 auto; }
.card h1 { margin-top: 0; font-size: 1.4rem; }

.nota { color: var(--muted); font-size: .9rem; line-height: 1.5; }
.aiuto { display: block; margin-top: 4px; color: var(--muted); font-size: .82rem; }
.vuoto { color: var(--muted); font-style: italic; }
.attenzione { color: var(--avviso); font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.piccolo { font-size: .8rem; }

/* ── Avvisi ────────────────────────────────────────────────────────── */

.avvisi { margin-bottom: 16px; }
.avviso {
  padding: 12px 14px; margin-bottom: 10px;
  border-radius: var(--radius); border-left: 4px solid;
  font-size: .92rem; line-height: 1.45; text-align: left;
}
.avviso-ok      { background: #eaf5ee; border-color: var(--accent); }
.avviso-errore  { background: #fbeaea; border-color: var(--pericolo); }
.avviso-avviso  { background: #fdf4e3; border-color: var(--avviso); }

/* ── Form a griglia (admin, desktop-first) ─────────────────────────── */

.form-griglia {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: start; margin-top: 12px;
}
.form-griglia button { grid-column: 1 / -1; justify-self: start; }
.campo-largo { grid-column: 1 / -1; }
.blocco-nuovo { margin: 18px 0 24px; }
.blocco-nuovo > summary { cursor: pointer; font-weight: 600; padding: 8px 0; }

.lista-cantieri {
  display: flex; flex-wrap: wrap;
  max-height: 220px; overflow-y: auto;
  padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg);
}

.risultati-ricerca {
  display: flex; flex-direction: column;
  margin-top: 6px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); max-height: 240px; overflow-y: auto;
}
.risultato {
  background: none; color: var(--fg); border-radius: 0;
  text-align: left; border-bottom: 1px solid var(--border);
}
.risultato:hover { background: var(--bg); }

/* ── Tabelle ───────────────────────────────────────────────────────── */

/* Il contenuto largo scorre nel suo contenitore: la pagina non deve mai
   scorrere orizzontalmente. */
.tabella-scroll { overflow-x: auto; margin-top: 16px; }
.tabella { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabella th, .tabella td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.tabella th { background: var(--bg); font-size: .85rem; text-transform: uppercase; }
.azioni details { min-width: 260px; }
.azioni summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.azioni form { margin: 12px 0; padding-bottom: 12px; border-bottom: 1px dashed var(--border); }
.azioni form:last-child { border-bottom: 0; }

.badge {
  display: inline-block; padding: 3px 10px;
  border-radius: 999px; font-size: .78rem; font-weight: 600;
}
.badge-ok   { background: #eaf5ee; color: var(--accent); }
.badge-warn { background: #fdf4e3; color: var(--avviso); }
.badge-off  { background: #eceff2; color: var(--muted); }

/* ── Agenda operatore (mobile-first) ───────────────────────────────── */

.agenda-testata {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.agenda-periodo h1 { margin: 0; font-size: 1.25rem; text-transform: capitalize; }
.agenda-contatore { margin: 4px 0 0; color: var(--avviso); font-weight: 600; font-size: .9rem; }
.agenda-contatore.ok { color: var(--accent); }
.agenda-nav { display: flex; gap: 8px; }
.agenda-nav .btn { padding: 10px 14px; }

.agenda-viste { display: flex; gap: 6px; margin-bottom: 16px; }
.agenda-viste .vista {
  flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--muted);
  text-align: center; text-decoration: none; text-transform: capitalize; font-size: .9rem;
}
.agenda-viste .vista.attiva { background: var(--accent); border-color: var(--accent); color: #fff; }

.ods-lista { display: flex; flex-direction: column; gap: 10px; }

/* L'intera card è il bersaglio tattile: niente link piccoli da centrare. */
.ods-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px; border: 1px solid var(--border); border-left: 5px solid var(--border);
  border-radius: var(--radius); background: var(--card);
  color: inherit; text-decoration: none;
}
.ods-card:hover { border-color: var(--accent); }
.ods-card.stato-da_consuntivare { border-left-color: var(--avviso); }
.ods-card.stato-bozza { border-left-color: var(--avviso); }
.ods-card.stato-confermato_operatore,
.ods-card.stato-validato_coordinatore { border-left-color: var(--accent); }

.ods-orario {
  display: flex; flex-direction: column; align-items: center;
  min-width: 56px; font-size: .95rem;
}
.ods-orario span { color: var(--muted); font-size: .85rem; }
.ods-corpo { flex: 1; min-width: 0; }
.ods-servizio { font-weight: 600; line-height: 1.3; }
.ods-meta {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 4px; color: var(--muted); font-size: .85rem;
}
.ods-ruolo {
  padding: 1px 8px; border-radius: 999px; background: var(--bg);
  font-size: .75rem; text-transform: uppercase;
}
.ods-firma { margin-top: 4px; color: var(--muted); font-size: .8rem; font-style: italic; }
.ods-stato { flex-shrink: 0; }

.giorno { margin-bottom: 18px; }
.giorno-testata {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--border); margin-bottom: 8px;
}
.giorno-testata a { text-transform: capitalize; font-weight: 600; text-decoration: none; }
.giorno-oggi .giorno-testata { border-bottom-color: var(--accent); }
.giorno-vuoto { opacity: .55; }

/* ── Consuntivo ────────────────────────────────────────────────────── */

.consuntivo-testata h1 { margin-bottom: 4px; font-size: 1.25rem; }
.form-consuntivo fieldset { border: 0; padding: 0; margin: 0; }
.form-consuntivo fieldset[disabled] { opacity: .7; }
.form-consuntivo h2 { margin: 20px 0 4px; font-size: 1rem; text-transform: uppercase; color: var(--muted); }

/* Due campi affiancati su desktop, impilati su mobile stretto. */
.coppia { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.campo { margin-top: 10px; }

.squadra { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.squadra-voce {
  padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); margin: 0;
}

.dettagli { margin: 20px 0; }
.dettagli > summary {
  cursor: pointer; padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); font-weight: 600;
}

.azioni-consuntivo { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.azioni-consuntivo button { flex: 1; min-width: 140px; }
.azioni-consuntivo .btn-conferma { background: var(--accent); font-weight: 600; }
.azioni-consuntivo button[type="submit"]:not(.btn-conferma) {
  background: var(--card); color: var(--accent); border: 1px solid var(--accent);
}

.storico { list-style: none; padding: 0; font-size: .88rem; }
.storico > li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.diff { margin: 6px 0 0 18px; color: var(--muted); font-size: .85rem; }

/* ══════════════════════════════════════════════════════════════════════
   Cruscotto coordinatore (Fase 3)
   Desktop-first, al contrario dell'agenda operatore: qui si guardano molte
   righe insieme su schermo grande (par. 6.4). Su mobile la tabella scorre
   orizzontalmente invece di spezzarsi: una riga per ODS resta leggibile.
   ══════════════════════════════════════════════════════════════════════ */

.cruscotto { display: flex; flex-direction: column; gap: 14px; }

.filtri {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.filtri label { display: flex; flex-direction: column; gap: 4px;
                font-size: .85rem; color: var(--muted); }
.filtri select, .filtri input { min-width: 140px; width: auto; }
.btn-testo {
  background: none; color: var(--accent); border: 0;
  min-height: 32px; padding: 4px 8px; text-decoration: underline;
}
.btn-testo:hover { background: none; color: var(--accent-scuro); }

/* I contatori sono anche i filtri: cliccarne uno restringe l'elenco, cosi'
   numero ed elenco non possono mai raccontare cose diverse. */
.contatori { display: flex; flex-wrap: wrap; gap: 8px; }
.contatore {
  display: flex; flex-direction: column; align-items: center;
  min-width: 92px; padding: 8px 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); text-decoration: none; color: var(--fg);
}
.contatore:hover { border-color: var(--accent); }
.contatore.attivo { border-color: var(--accent); background: #f0f6f2; }
.contatore-n { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.contatore-et { font-size: .78rem; color: var(--muted); text-align: center; }
.contatore-senza_squadra .contatore-n,
.contatore-da_consuntivare .contatore-n { color: var(--avviso); }
.contatore-confermati .contatore-n { color: var(--accent); }

.azioni-massive {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 4px 0;
}
.azioni-massive .nota { flex: 1 1 260px; margin: 0; }
button:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; }

.tabella-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabella {
  width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .92rem;
}
.tabella th, .tabella td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: top; white-space: nowrap;
}
.tabella thead th {
  position: sticky; top: 0; z-index: 1;
  background: #eef2f5; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .03em; color: var(--muted);
}
.tabella tbody tr:hover { background: #f7fafc; }
.tabella .col-check { width: 34px; }
.tabella .col-check input { width: 20px; min-height: 20px; }
.tabella .col-servizio { white-space: normal; min-width: 220px; max-width: 380px; }
.tabella .firma { font-size: .75rem; color: var(--muted); }
.tabella .sfumato { color: var(--border); }

/* Scostamento fra pianificato ed effettivo: si accende su poche righe (3-9%
   dei casi misurati), ed e' proprio per questo che vale la pena evidenziarlo. */
.tabella .scostamento { color: var(--avviso); font-weight: 600; }
.riga-senza-squadra td:first-child { box-shadow: inset 3px 0 0 var(--avviso); }

.badge-attesa { background: #e8f0fb; color: #1c4f9c; }
.badge-eco    { background: #f2ecf8; color: #5b3a86; }
.nota-eco {
  background: #f7f3fb; border-left: 3px solid #5b3a86;
  padding: 8px 12px; border-radius: 0 var(--radius) var(--radius) 0;
}
.btn-valida { background: #1c4f9c; }
.btn-valida:hover { background: #163f7d; }
