:root {
  --bg: #f6f7f9; --fg: #1b1f24; --muted: #667085; --card: #fff; --line: #d9dde3;
  --accent: #1f6feb; --accent-fg: #fff; --err: #b42318; --ok: #067647;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --fg: #e8eaed; --muted: #9aa3b0; --card: #1c2027; --line: #2d333d; --accent: #4c8dff; --accent-fg: #0b1220; --err: #ff7b72; --ok: #56d364; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 system-ui, sans-serif; }
header { padding: 12px 16px 0; border-bottom: 1px solid var(--line); background: var(--card); }
h1 { font-size: 18px; margin: 0 0 8px; }
nav { display: flex; gap: 4px; overflow-x: auto; }
nav button { border: 0; background: none; color: var(--muted); padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; font: inherit; }
nav button[aria-current="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
main { padding: 16px; max-width: 1000px; margin: 0 auto; }
.barra { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.barra input[type=search] { flex: 1 1 220px; }
input, select, button { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); }
button { cursor: pointer; }
button.primario { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.check input { padding: 0; }
#messaggio { min-height: 1.4em; margin: 4px 0 8px; color: var(--muted); }
#messaggio.errore { color: var(--err); }
#messaggio.ok { color: var(--ok); }
.tabella-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
td.num { text-align: right; }
td.spento { color: var(--muted); }
form { margin-top: 16px; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
form h2 { margin: 0 0 12px; font-size: 16px; }
.campo { display: grid; gap: 4px; margin-bottom: 10px; }
.campo label { color: var(--muted); font-size: 13px; }
.campo input[type=checkbox] { width: 18px; height: 18px; }
.azioni { display: flex; gap: 8px; margin-top: 8px; }
@media (max-width: 600px) { main { padding: 12px; } }

.testa { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#utente { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
#utente button { padding: 3px 10px; }
.menu { display: flex; gap: 16px; margin-bottom: 4px; }
.menu a { color: var(--muted); text-decoration: none; padding: 4px 0; border-bottom: 2px solid transparent; }
.menu a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.griglia { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
tfoot td { font-weight: 600; border-bottom: 0; }
#righe td input, #righe td select { width: 100%; min-width: 90px; }
body.login main { max-width: 360px; margin-top: 12vh; }
.scheda-login { display: grid; gap: 4px; }
.scheda-login h1 { font-size: 20px; margin-bottom: 12px; }

td.ritardo { color: var(--err); font-weight: 600; }

/* Narratore (pensato per il telefono) */
.aiuto { color: var(--muted); }
body.narratore input[type="search"] { width: 100%; font-size: 1.1rem; padding: .8rem; box-sizing: border-box; }
.elenco-carte { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .5rem; }
.elenco-carte a { display: flex; flex-direction: column; gap: .15rem; padding: .8rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; color: var(--fg); text-decoration: none; min-height: 44px; }
.elenco-carte a span { color: var(--muted); font-size: .9rem; }
.indietro { margin-bottom: .5rem; min-height: 44px; }
.racconto p { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .8rem; margin: .5rem 0; line-height: 1.45; }
.racconto p.attenzione { border-color: var(--err); color: var(--err); }
.cronologia { list-style: none; padding: 0; margin: 0; }
.cronologia li { display: flex; flex-direction: column; gap: .1rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.cronologia time { color: var(--muted); font-size: .85rem; }
@media (min-width: 700px) { body.narratore main { max-width: 720px; margin-inline: auto; } }
/* Percorso a fasi (vista a colonne) */
main.largo { max-width: none; }
.legenda { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; font-size: .85rem; }
.legenda span { padding: .15rem .5rem; border-radius: 4px; border-left: 4px solid var(--line); background: var(--card); }
.percorso-wrap { overflow: auto; max-height: calc(100vh - 240px); min-height: 240px; border: 1px solid var(--line); border-radius: 8px; padding: .4rem; scrollbar-gutter: stable; }
.percorso { --colonne: 5; display: grid; min-width: calc(180px + var(--colonne) * 220px); gap: .4rem; }
.riga { display: grid; grid-template-columns: 180px repeat(var(--colonne), minmax(220px, 1fr)); gap: .4rem; align-items: stretch; }
.testa-riga { position: sticky; top: 0; z-index: 3; background: var(--bg); }
.testa-riga .caso { z-index: 4; }
.colonna { font-weight: 600; padding: .5rem; border-bottom: 2px solid var(--line); }
.caso { position: sticky; left: 0; z-index: 1; display: flex; flex-direction: column; gap: .15rem; padding: .6rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; color: var(--fg); text-decoration: none; }
.caso span { color: var(--muted); font-size: .85rem; }
.cella { padding: .5rem .6rem; border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 8px; background: var(--card); font-size: .9rem; line-height: 1.4; }
.cella p, .cella ul { margin: .25rem 0; }
.cella ul { padding-left: 1.1rem; }
.cella .attenzione { color: var(--err); font-weight: 600; }
.s-completa { border-left-color: var(--ok); }
.s-in_corso { border-left-color: var(--accent); }
.s-attenzione { border-left-color: var(--err); }
.s-vuota { border-left-color: var(--line); color: var(--muted); }
.s-nd { border-left-color: var(--line); color: var(--muted); border-style: dashed; border-left-style: dashed; }
/* Modalita' incorporata nell'editor: il menu e' nel sandwich dell'editor */
body.embed .testa h1, body.embed #menu { display: none; }
body.embed .testa { justify-content: flex-end; }
#utente select { margin-right: .5rem; }
