:root {
  --bg: #f4f5f7; --surface: #fff; --panel: #fafbfc; --fg: #1f2328; --muted: #5d6673;
  --border: #d8dde3; --accent: #1d5fd6; --accent-fg: #fff; --barra: #13294b; --barra-fg: #fff;
  --ok: #1a7f37; --ok-bg: #e6f4ea; --warn: #8a5a00; --warn-bg: #fff4d6; --danger: #b42318; --danger-bg: #fdecea;
  --raggio: 4px; --menu: 260px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --surface: #1a1f27; --panel: #202733; --fg: #e6e9ee; --muted: #9aa4b2;
    --border: #2e3644; --accent: #5aa9ff; --accent-fg: #0b1220; --barra: #0b1a30;
    --ok: #4ac26b; --ok-bg: #12301c; --warn: #e3b341; --warn-bg: #33270a; --danger: #ff7b72; --danger-bg: #3a1513;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nascosto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Barra in alto */
.barra { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 16px; background: var(--barra); color: var(--barra-fg); }
.marchio { color: var(--barra-fg); font-weight: 700; letter-spacing: .04em; text-decoration: none; }
.hamburger { display: none; background: none; border: 0; color: inherit; width: 44px; height: 44px; margin-left: -10px; cursor: pointer; }
.hamburger svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2; fill: none; }
.scelta-app { position: relative; }
.scelta-app summary { cursor: pointer; list-style: none; padding: 6px 10px; border-radius: var(--raggio); }
.scelta-app summary::after { content: " ▾"; }
.scelta-app summary:hover { background: rgba(255,255,255,.1); }
.scelta-app ul { position: absolute; top: 40px; left: 0; min-width: 240px; margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raggio); box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.scelta-app a { display: block; padding: 8px 10px; border-radius: 2px; color: var(--fg); text-decoration: none; }
.scelta-app a:hover, .scelta-app a[aria-current] { background: var(--panel); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--panel); color: var(--muted); border: 1px solid var(--border); }
.badge.avviso { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

.utente { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.utente .esci { background: transparent; color: var(--barra-fg); border-color: rgba(255,255,255,.35); }

/* Accesso */
.accesso { max-width: 380px; margin: 48px auto; padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; display: flex; flex-direction: column; gap: 12px; }
.accesso h1 { margin: 0; font-size: 22px; }
.accesso form { display: flex; flex-direction: column; gap: 12px; }
.utenti-prova { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.utenti-prova legend { font-size: 13px; color: var(--muted); margin-bottom: 4px; padding: 0; }
.utente-prova { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--raggio); cursor: pointer; }
.utente-prova:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.utente-prova input { width: auto; flex: none; margin: 0; }
.utente-prova .badge { flex: none; }
.utente-prova .chi { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.utente-prova .nome { font-weight: 600; }
.utente-prova .upn { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.carica { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }

/* Impianto */
.impianto { display: grid; grid-template-columns: var(--menu) minmax(0, 1fr); min-height: calc(100vh - 48px); }
.impianto.senza-menu { grid-template-columns: minmax(0, 1fr); }
.menu { position: sticky; top: 48px; height: calc(100vh - 48px); overflow-y: auto; padding: 12px 8px 24px; background: var(--surface); border-right: 1px solid var(--border); }
.filtro-menu { flex: 1; min-width: 0; }

/* Icone dello sprite (img/icone.svg). */
.icona { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pulsante { gap: 6px; }
.pulsante.piccolo .icona, .menu-a-tendina .tendina .icona { width: 16px; height: 16px; }
.hamburger .icona { width: 22px; height: 22px; }

/* Menu laterale: icona + nome; compresso (solo desktop) resta la colonna delle icone. */
.testa-menu { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.comprimi-menu { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 2px; background: transparent; color: var(--muted); cursor: pointer; }
.comprimi-menu:hover { background: var(--panel); color: var(--fg); }
.comprimi-menu .se-compresso, .menu-compresso .comprimi-menu .se-aperto { display: none; }
.menu-compresso .comprimi-menu .se-compresso { display: contents; }
.menu li a, .menu li .non-disponibile { display: flex; align-items: center; gap: 10px; }
.menu li .icona { color: var(--muted); }
.menu li a[aria-current] .icona, .menu li a:hover .icona { color: inherit; }
.testo-voce { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 901px) {
  .menu-compresso .impianto:not(.senza-menu) { grid-template-columns: 60px minmax(0, 1fr); }
  .menu-compresso .menu { padding: 12px 6px 24px; overflow-x: hidden; }
  .menu-compresso .filtro-menu, .menu-compresso .menu .area, .menu-compresso .menu .titolo-gruppo, .menu-compresso .testo-voce { display: none; }
  .menu-compresso .testa-menu { justify-content: center; }
  .menu-compresso .menu li a, .menu-compresso .menu li .non-disponibile { justify-content: center; padding: 9px 0; }
  .menu-compresso .menu .gruppo + .gruppo { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
}
@media (max-width: 900px) { .comprimi-menu { display: none; } }
/* Sui telefoni i pulsanti della barra restano icone; il testo rimane per gli screen reader. */
@media (max-width: 640px) { .barra-comandi .testo-pulsante { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } }
.menu .area { margin: 12px 8px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.menu .titolo-gruppo { margin: 10px 8px 2px; font-size: 12px; font-weight: 600; color: var(--muted); }
.menu ul { list-style: none; margin: 0; padding: 0; }
.menu li a, .menu li .non-disponibile { padding: 7px 10px; border-radius: 2px; color: var(--fg); text-decoration: none; }
.menu li a:hover { background: var(--panel); }
.menu li a[aria-current] { background: var(--accent); color: var(--accent-fg); }
.menu .non-disponibile { color: var(--muted); cursor: not-allowed; }
.fondale { display: none; }
.contenuto { padding: 20px 24px 48px; min-width: 0; }

/* Barra dei comandi agganciata sotto l'header: titolo e pulsanti restano a vista mentre si scorre */
.barra-comandi { position: sticky; top: 48px; z-index: 12; margin: -20px -24px 12px; padding: 6px 24px; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.barra-comandi .comandi { margin: 0; flex-wrap: nowrap; gap: 6px; }
.barra-comandi .pulsante { min-height: 34px; padding: 0 10px; }
.barra-comandi input[type=search] { min-height: 34px; padding: 5px 10px; }
.barra-comandi .ricerca { flex: 0 1 260px; min-width: 120px; }
.barra-comandi .spazio { flex: 1; }
.barra-comandi .conteggio { color: var(--muted); font-size: 13px; white-space: nowrap; }
.scelta-vista > summary { display: flex; align-items: baseline; gap: 8px; min-height: 34px; padding: 4px 8px 4px 0; cursor: pointer; border-radius: 2px; max-width: 420px; white-space: nowrap; }
.scelta-vista > summary h1 { margin: 0; font-size: 18px; }
.scelta-vista > summary .nome-vista { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.scelta-vista > summary:hover .nome-vista { color: var(--accent); }
.testata.barra-comandi { align-items: center; flex-wrap: nowrap; }
.testata.barra-comandi .sopratitolo { font-size: 12px; margin: 0; }
.testata.barra-comandi h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.testata.barra-comandi > div:first-child { min-width: 0; }
.testata.barra-comandi .azioni { flex-wrap: nowrap; }
@media (max-width: 1100px) {
  .barra-comandi .comandi { flex-wrap: wrap; }
  .barra-comandi .ricerca { order: 10; flex: 1 1 100%; max-width: none; }
}

/* Testata della pagina */
.testata { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.testata h1 { margin: 0; font-size: 22px; }
.sopratitolo { margin: 0 0 2px; font-size: 13px; }
.sottotitolo { margin: 2px 0 0; color: var(--muted); }
.azioni { display: flex; gap: 8px; flex-wrap: wrap; }
.in-linea { display: inline; }

/* Controlli */
input, select, textarea { font: inherit; font-size: 16px; color: var(--fg); background: var(--surface); border: 1px solid var(--border); border-radius: 2px; padding: 7px 10px; min-height: 38px; width: 100%; }
@media (min-width: 760px) { input, select, textarea { font-size: 14px; } }
textarea { resize: vertical; }
input[type=checkbox] { width: auto; min-height: auto; }
.pulsante { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 0 14px; border-radius: 2px; border: 1px solid var(--border); background: var(--surface); color: var(--fg); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.pulsante.primario { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.pulsante.ghost { background: transparent; }
.pulsante.pericolo { color: var(--danger); border-color: var(--danger); background: transparent; }
.pulsante.piccolo { min-height: 30px; padding: 0 10px; font-size: 13px; }
.comandi { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.comandi .vista { flex: 0 1 280px; }
.comandi .ricerca { flex: 1 1 220px; max-width: 420px; }

/* Viste, colonne e filtri */
.comandi .ricerca { flex: 1 1 220px; max-width: 420px; }
.menu-a-tendina { position: relative; }
.menu-a-tendina > summary { list-style: none; }
.menu-a-tendina > summary::-webkit-details-marker { display: none; }
.menu-a-tendina > summary::after { content: " ▾"; color: var(--muted); }
.scelta-vista > summary .nome-vista { font-weight: 500; }
.tendina { position: absolute; z-index: 15; top: calc(100% + 6px); left: 0; width: min(360px, calc(100vw - 32px)); max-height: 70vh; overflow-y: auto; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raggio); box-shadow: 0 12px 32px rgba(0,0,0,.18); display: flex; flex-direction: column; gap: 8px; }
.menu-a-tendina:not(.scelta-vista) > .tendina { left: auto; right: 0; }
.tendina ul { list-style: none; margin: 0; padding: 0; }
.tendina li a { display: block; padding: 7px 10px; border-radius: 2px; color: var(--fg); text-decoration: none; }
.tendina li a:hover, .tendina li a[aria-current] { background: var(--panel); }
.tendina li a[aria-current] { font-weight: 600; }
.titolo-tendina { margin: 6px 4px 0; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.tendina .scelte li label, .opzione { display: flex; gap: 8px; align-items: center; padding: 5px 4px; cursor: pointer; }
.tendina fieldset { margin: 0; padding: 8px 10px 10px; border: 1px solid var(--border); border-radius: 2px; display: flex; flex-direction: column; gap: 6px; }
.tendina fieldset legend { padding: 0 4px; font-size: 13px; font-weight: 600; }
.tendina hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
.intervallo { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.azioni-tendina { position: sticky; bottom: -10px; display: flex; justify-content: flex-end; gap: 8px; padding: 8px 0 0; background: var(--surface); }
.riga-tendina { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.nuova-vista { display: flex; flex-direction: column; gap: 8px; }
.nuova-vista > label:first-of-type { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.pastiglie { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.pastiglia { display: inline-flex; gap: 6px; align-items: center; padding: 4px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--border); color: var(--fg); font-size: 13px; text-decoration: none; }
.pastiglia span { color: var(--muted); font-size: 15px; }
.pastiglia:hover { border-color: var(--accent); }
@media (max-width: 640px) {
  .tendina { position: fixed; inset: 48px 0 0 0; width: auto; max-height: none; border-radius: 0; }
}

/* Messaggi */
.messaggio { padding: 10px 14px; border-radius: var(--raggio); margin: 0 0 12px; }
.messaggio.ok { background: var(--ok-bg); color: var(--ok); }
.messaggio.errore { background: var(--danger-bg); color: var(--danger); }
.messaggio.avviso { background: var(--warn-bg); color: var(--warn); }
.messaggio ul { margin: 6px 0 0; padding-left: 18px; }
.vuoto { color: var(--muted); }
.muto { color: var(--muted); }

/* Griglia */
.griglia { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raggio); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel); font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
th a { color: inherit; text-decoration: none; }
tbody tr[data-href] { cursor: pointer; }
tbody tr:hover { background: var(--panel); }
tbody tr:last-child td { border-bottom: 0; }
tr.inattivo td { color: var(--muted); }
.pagine { display: flex; gap: 8px; margin-top: 12px; }

/* Riquadri della home */
.riquadri { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.riquadri a { display: flex; flex-direction: column; gap: 4px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; color: var(--fg); text-decoration: none; }
.riquadri a:hover { border-color: var(--accent); }
.riquadri span { color: var(--muted); font-size: 13px; }

/* Scheda */
.scelta-form { margin-bottom: 12px; max-width: 360px; }
.intestazione { display: flex; flex-wrap: wrap; gap: 8px 24px; padding: 12px 16px; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raggio); }
.intestazione .campo { min-width: 140px; }
.schede { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.schede a { padding: 10px 14px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.schede a[aria-selected=true] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.colonne { display: flex; flex-wrap: wrap; gap: 12px; }
.colonna { flex-grow: 1; min-width: min(100%, 320px); display: flex; flex-direction: column; gap: 12px; }
.sezione { margin: 0; padding: 12px 16px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raggio); display: grid; grid-template-columns: repeat(var(--colonne, 1), minmax(0, 1fr)); gap: 12px 16px; }
.sezione legend { padding: 0 4px; font-weight: 600; }
.campo { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campo label { font-size: 13px; color: var(--muted); }
.campo[hidden] { display: none; }
/* Bloccato da una regola del modulo: i controlli sono disabilitati e non si inviano. */
.campo.bloccato .togli, .campo.bloccato .nuovo-rapido { display: none; }
.campo.bloccato :is(input, select, textarea):disabled { background: var(--panel); color: var(--fg); opacity: 1; cursor: not-allowed; }
.campo .errore-campo { margin: 0; font-size: 13px; color: var(--danger); }
.testo-campo { min-height: 38px; padding: 8px 0; overflow-wrap: anywhere; }
.interruttore { display: inline-flex; gap: 8px; align-items: center; min-height: 38px; }
.interruttore input[type=checkbox] { appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 40px; height: 22px; margin: 0; border-radius: 999px; background: var(--border); cursor: pointer; transition: background .15s; }
.interruttore input[type=checkbox]::before { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.interruttore input[type=checkbox]:checked { background: var(--accent); }
.interruttore input[type=checkbox]:checked::before { transform: translateX(18px); }
.interruttore input[type=checkbox]:disabled { opacity: .5; cursor: not-allowed; }
@media (prefers-reduced-motion: reduce) { .interruttore input[type=checkbox], .interruttore input[type=checkbox]::before { transition: none; } }
@media (forced-colors: active) { .interruttore input[type=checkbox] { border: 1px solid CanvasText; } .interruttore input[type=checkbox]:checked::before { background: Highlight; } }
.segmenti { display: inline-flex; border: 1px solid var(--border); border-radius: 2px; overflow: hidden; }
.segmenti label { display: inline-flex; align-items: center; min-height: 32px; padding: 0 10px; cursor: pointer; border-left: 1px solid var(--border); }
.segmenti label:first-child { border-left: 0; }
.segmenti input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmenti label:has(input:checked) { background: var(--accent); color: var(--accent-fg); }
.segmenti label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.sottogriglia { display: flex; flex-direction: column; gap: 8px; }
.sottogriglia h3 { margin: 4px 0 0; font-size: 15px; }
.comandi-griglia { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.comandi-griglia .abbina { width: min(260px, 100%); }

/* Lookup */
.lookup { position: relative; display: flex; gap: 6px; align-items: center; }
.lookup .scelta { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; min-height: 38px; padding: 4px 6px 4px 10px; border: 1px solid var(--border); border-radius: 2px; background: var(--surface); }
.lookup .scelta[hidden], .lookup input[hidden] { display: none; }
.lookup .scelta a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.togli { flex: none; width: 30px; height: 30px; border: 0; border-radius: 2px; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; }
.togli:hover { background: var(--panel); color: var(--fg); }
.nuovo-rapido { flex: none; width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 2px; background: var(--surface); color: var(--accent); font-size: 20px; line-height: 1; cursor: pointer; }
.nuovo-rapido:hover { border-color: var(--accent); }

/* La finestra unica (modale.js, docs/guida-modal.md): testata e piede fermi, scorre solo il corpo.
   Finestra dentro finestra = schede, con il percorso in testata. */
dialog.modale { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--fg); box-shadow: 0 24px 64px rgba(0,0,0,.3); }
dialog.modale.larga { width: min(1100px, calc(100vw - 32px)); }
dialog.modale::backdrop { background: rgba(0,0,0,.4); }
.finestra { display: flex; flex-direction: column; max-height: calc(100vh - 50px); }
.finestra-testata { padding: 10px 8px 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.finestra-titolo { display: flex; align-items: center; gap: 4px; }
.finestra-titolo h2 { flex: 1; min-width: 0; margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finestra-icona { flex: none; width: 36px; height: 36px; border: 0; border-radius: 2px; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; }
.finestra-icona:hover, .finestra-icona[aria-pressed=true] { background: var(--panel); color: var(--fg); }
.percorso { display: flex; flex-wrap: wrap; align-items: center; margin: 0 0 4px; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.percorso[hidden] { display: none; }
.percorso li + li::before { content: "›"; margin: 0 6px; }
.percorso button { padding: 2px 4px; border: 0; border-radius: 4px; background: none; color: var(--accent); font: inherit; cursor: pointer; }
.percorso button:hover { background: var(--panel); }
.percorso [aria-current] { padding: 2px 4px; color: var(--fg); font-weight: 600; }
.finestra-corpo { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
.finestra-scheda { display: flex; flex-direction: column; gap: 12px; }
.finestra-scheda[hidden] { display: none; }
.finestra-scheda > .vuoto { margin: 8px 0; }
.finestra-scheda .messaggio { margin: 0; }
.finestra-piede { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface); }
.finestra-piede [hidden] { display: none; }
.rapida-campi { display: flex; flex-direction: column; gap: 12px; }
/* Elenco completo di un lookup: ricerca, griglia e «Altri», tutto dal server. */
.scegli-cerca { display: flex; gap: 8px; }
.scegli .griglia table { width: 100%; border-collapse: collapse; }
.scegli .griglia th { position: sticky; top: 0; padding: 8px 10px; text-align: left; background: var(--panel); color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
.scegli .griglia td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.scegli .griglia tbody tr { cursor: pointer; }
.scegli .griglia tbody tr:hover, .scegli .griglia tbody tr:focus-visible { background: var(--panel); }
.scegli .griglia tbody tr.inattivo td { color: var(--muted); }
.scegli-altri { align-self: center; }
.lookup .risultati .piede-lookup { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; padding: 6px 2px 0; border-top: 1px solid var(--border); cursor: default; }
.lookup .risultati .piede-lookup:hover { background: none; }
.lookup .risultati .piede-lookup button { padding: 6px 8px; border: 0; border-radius: 2px; background: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.lookup .risultati .piede-lookup button:hover { background: var(--panel); }
@media (max-width: 767px) {
  dialog.modale, dialog.modale.larga { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .finestra { height: 100%; max-height: none; }
  [data-modale-allarga] { display: none; }
}
.lookup .risultati { position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin: 4px 0 0; padding: 4px; list-style: none; max-height: 280px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raggio); box-shadow: 0 8px 24px rgba(0,0,0,.16); }
.aggiungi-filtro { border: 1px dashed var(--border); border-radius: 2px; padding: 6px 8px; }
.aggiungi-filtro > summary { display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--accent); }
.aggiungi-filtro[open] > summary { margin-bottom: 6px; }
.aggiungi-filtro .scelte { max-height: 240px; overflow-y: auto; margin-top: 6px; }
.aggiungi-filtro .scelte a { display: block; padding: 5px 6px; border-radius: 4px; font-size: 13px; color: var(--fg); text-decoration: none; }
.aggiungi-filtro .scelte a:hover { background: var(--panel); }
.tendina .lookup { flex-wrap: wrap; }
.tendina .lookup input[data-lookup-testo] { flex: 1; min-width: 0; }
.tendina .lookup .risultati { position: static; flex-basis: 100%; margin: 0; box-shadow: none; max-height: 200px; } /* dentro la tendina che scorre */
.lookup .risultati li { padding: 8px 10px; border-radius: 2px; cursor: pointer; }
.lookup .risultati li[aria-selected=true], .lookup .risultati li:hover { background: var(--panel); }

/* Telefono e tablet */
@media (max-width: 900px) {
  .hamburger { display: inline-flex; align-items: center; justify-content: center; }
  .impianto { grid-template-columns: minmax(0, 1fr); }
  .menu { position: fixed; top: 48px; left: 0; bottom: 0; width: min(86vw, 320px); height: auto; z-index: 25; transform: translateX(-100%); transition: transform .2s; }
  body.menu-aperto .menu { transform: none; }
  body.menu-aperto .fondale { display: block; position: fixed; inset: 48px 0 0; z-index: 24; background: rgba(0,0,0,.35); }
  .contenuto { padding: 16px; }
  .barra-comandi { margin: -16px -16px 10px; padding: 6px 16px; }
  .barra-comandi .conteggio { display: none; }
  .testata.barra-comandi .azioni .pulsante.ghost:not([form]) { padding: 0 8px; }
}
@media (max-width: 760px) {
  .barra { gap: 8px; padding-right: 8px; }
  .barra .badge { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .scelta-app summary { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .utente .nome-utente { display: none; }
  .pulsante, .menu li a, .schede a { min-height: 44px; }
  .sezione { grid-template-columns: minmax(0, 1fr); }
  .campo[style] { grid-column: auto !important; }
  .griglia { border: 0; background: none; }
  .griglia table, .griglia tbody, .griglia tr, .griglia td { display: block; }
  .griglia thead { display: none; }
  .griglia tr { margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raggio); padding: 6px 0; }
  .griglia td { border: 0; padding: 4px 12px; }
  .griglia td::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); }
}

/* Griglia Tabulator con i colori dell'app */
.griglia-tabulator.tabulator { font-size: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--raggio); color: var(--fg); }
.griglia-tabulator .tabulator-header { background: var(--panel); border-bottom: 1px solid var(--border); color: var(--muted); font-weight: 600; }
.griglia-tabulator .tabulator-header .tabulator-col { background: var(--panel); border-right: 1px solid var(--border); }
.griglia-tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 8px 10px; }
.griglia-tabulator .tabulator-tableholder { background: var(--surface); }
.griglia-tabulator .tabulator-row { background: var(--surface); border-bottom: 1px solid var(--border); min-height: 34px; cursor: pointer; }
.griglia-tabulator .tabulator-row.tabulator-row-even { background: var(--surface); }
.griglia-tabulator .tabulator-row.tabulator-selectable:hover { background: var(--panel); }
.griglia-tabulator .tabulator-row.tabulator-selected { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.griglia-tabulator .tabulator-row.inattivo .tabulator-cell { color: var(--muted); }
.griglia-tabulator .tabulator-row .tabulator-cell { padding: 8px 10px; border-right: 0; }
.griglia-tabulator .tabulator-row .tabulator-cell.tabulator-frozen { background: inherit; }
.griglia-tabulator .tabulator-placeholder-contents { color: var(--muted); font-weight: 400; font-size: 14px; }
.griglia-tabulator input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); cursor: pointer; }
.azioni-blocco { display: flex; gap: 8px; align-items: center; margin: 0 0 8px; padding: 6px 10px; border-radius: var(--raggio); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.azioni-blocco[hidden] { display: none; }
.azioni-blocco span { font-weight: 600; margin-right: auto; }

/* Elenchi densi su schermo largo: una riga per record, il testo lungo si accorcia (title con il testo intero) */
@media (min-width: 761px) {
  .griglia td { max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-top: 7px; padding-bottom: 7px; }
}
.nessun-record td { text-align: center; color: var(--muted); padding: 16px; }
.avviso-lookup { display: block; min-height: 0; font-size: 12px; color: var(--warn); }
.avviso-lookup:empty { display: none; }
.sezione-import { display: flex; flex-direction: column; gap: 10px; max-width: 760px; margin-bottom: 16px; }
.sezione-import h2 { margin: 0; font-size: 17px; }
tr.riga-errore td { background: var(--danger-bg); }
.errori-riga { margin: 0; padding-left: 18px; color: var(--danger); }

/* ---------------------------------------------------------------------------------------------
   Stile delle app model-driven (Power Apps): barra comandi piatta, testata del record con i campi di
   intestazione a destra, sezioni come riquadri bianchi, etichetta a sinistra del campo, campi su
   fondo grigio senza bordo, angoli dritti. Tutto con i token di sopra: vale anche col tema scuro.
   --------------------------------------------------------------------------------------------- */
:root { --campo: #f5f6f7; --campo-hover: #eceef0; --etichetta: 38%; }
@media (prefers-color-scheme: dark) { :root { --campo: #222a35; --campo-hover: #29323f; } }

/* Barra comandi del record */
.comandi-record { display: flex; align-items: center; gap: 2px; flex-wrap: nowrap; overflow-x: auto; padding: 4px 16px; }
.comandi-record .in-linea { display: contents; }
.comando { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border: 0; border-radius: 2px; background: transparent; color: var(--fg); font: inherit; font-size: 14px; text-decoration: none; white-space: nowrap; cursor: pointer; }
.comando:hover { background: var(--panel); }
.comando .icona { width: 16px; height: 16px; color: var(--muted); }
.comando:hover .icona { color: var(--fg); }
.comandi-record .separatore { flex: none; width: 1px; height: 20px; margin: 0 4px; background: var(--border); }

/* Testata del record: titolo grande, tipo sotto, campi di intestazione a destra (valore sopra, etichetta sotto). */
.testata-record { display: flex; align-items: center; justify-content: space-between; gap: 16px 32px; flex-wrap: wrap; margin: 0 0 4px; }
.titolo-record { min-width: 0; }
.titolo-record h1 { display: inline; margin: 0; font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.titolo-record .badge { margin-left: 8px; vertical-align: 3px; }
.tipo-record { margin: 2px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.testata-record .intestazione { display: flex; flex-wrap: wrap; gap: 8px 0; margin: 0; padding: 0; background: none; border: 0; }
.testata-record .intestazione .campo { display: flex; flex-direction: column-reverse; gap: 0; min-width: 0; padding: 0 20px; border-left: 1px solid var(--border); }
.testata-record .intestazione .campo:first-child { border-left: 0; }
.testata-record .intestazione .campo label { font-size: 12px; }
.testata-record .intestazione .testo-campo { min-height: 0; padding: 0; font-weight: 600; }

/* Schede: sottolineatura spessa sotto quella attiva. */
.schede { gap: 8px; margin-bottom: 12px; }
.schede a { padding: 10px 6px; color: var(--fg); border-bottom-width: 3px; }
.schede a[aria-selected=true] { font-weight: 600; }

/* Sezioni: riquadri bianchi con ombra leggera, titolo in grassetto dentro il riquadro. */
.scheda .sezione { border: 0; border-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 0 1px rgba(0,0,0,.08); padding: 12px 16px 16px; gap: 10px 16px; }
.scheda .sezione legend { float: left; grid-column: 1 / -1; width: 100%; padding: 0; margin: 0 0 4px; font-size: 15px; font-weight: 600; }

/* Campi: fondo grigio, niente bordo, angoli dritti; il bordo compare passando sopra e col focus. */
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  border-radius: 0; background: var(--campo); border-color: transparent; }
input:not([type=checkbox]):not([type=radio]):not([type=file]):hover, select:hover, textarea:hover { background: var(--campo-hover); }
input:not([type=checkbox]):not([type=radio]):focus, select:focus, textarea:focus { background: var(--surface); border-color: var(--border); border-bottom: 2px solid var(--accent); outline: none; }
.asterisco { color: var(--danger); }

/* Etichetta a sinistra del campo nelle schede record (sopra su telefono e nelle finestre strette). */
@media (min-width: 641px) {
  .scheda .sezione .campo:not(:has(.interruttore)) { display: grid; grid-template-columns: minmax(110px, var(--etichetta)) minmax(0, 1fr); align-items: start; gap: 4px 12px; }
  .scheda .sezione .campo:has(.interruttore) { display: grid; grid-template-columns: minmax(110px, var(--etichetta)) minmax(0, 1fr); align-items: center; gap: 4px 12px; }
  .scheda .sezione .campo > label { padding-top: 9px; font-size: 14px; color: var(--fg); }
  .scheda .sezione .campo:has(.interruttore) > label { padding-top: 0; }
  .scheda .sezione .campo > :not(label) { grid-column: 2; }
  .scheda .sezione .campo .asterisco { float: right; }
}

/* Sola lettura: testo su fondo grigio, come un campo bloccato. */
.scheda .sezione .testo-campo { min-height: 36px; padding: 8px 10px; background: var(--campo); }

/* Sottogriglie: titolo maiuscolo, comandi a destra, niente cornice doppia. */
.sottogriglia h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .02em; }
.scheda .sottogriglia .griglia { border-width: 0 0 1px; border-radius: 0; }
.scheda .sottogriglia th { background: var(--surface); color: var(--fg); }

/* Lookup: valore scelto come link nel campo grigio, chevron a destra al posto della lente. */
.lookup .scelta { background: var(--campo); border-color: transparent; border-radius: 0; padding-right: 40px; }
.lookup .scelta a { text-decoration: underline; font-weight: 400; }
.lookup input[data-lookup-testo] { padding-right: 40px; }
.chevron-lookup { position: absolute; top: 1px; right: 1px; bottom: 1px; width: 36px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--muted); cursor: pointer; }
.chevron-lookup:hover { background: var(--campo-hover); color: var(--fg); }
.chevron-lookup .icona { width: 16px; height: 16px; }
.campo.bloccato .chevron-lookup, .sola-lettura .chevron-lookup { display: none; }
.lookup .nuovo-rapido[hidden] { display: none; }

/* Tendina del lookup: una griglia con intestazione, prima colonna in colore; in fondo «+ Nuovo» e
   «Seleziona da elenco completo». Larga almeno 460px anche sotto un campo stretto. */
.lookup .risultati { width: max(100%, 460px); max-width: calc(100vw - 32px); right: auto; margin-top: 2px; padding: 0; border-radius: 0; box-shadow: 0 6px 18px rgba(0,0,0,.16); max-height: 320px; }
.lookup .risultati li { display: grid; grid-template-columns: repeat(var(--colonne-lookup, 1), minmax(0, 1fr)); gap: 12px; padding: 7px 12px; border-radius: 0; border-bottom: 1px solid var(--border); }
.lookup .risultati li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lookup .risultati li[data-id] span:first-child { color: var(--accent); font-weight: 600; }
.lookup .risultati li.muto { display: block; }
.lookup .risultati .testa-lookup { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; cursor: default; }
.lookup .risultati .testa-lookup:hover { background: var(--surface); }
.lookup .risultati .piede-lookup { position: sticky; bottom: 0; display: flex; justify-content: space-between; align-items: center; margin: 0; padding: 4px; background: var(--surface); border-top: 1px solid var(--border); border-bottom: 0; }
.lookup .risultati .piede-lookup:hover { background: var(--surface); }
.lookup .risultati .piede-lookup button { border-radius: 0; }

/* Finestra: angoli dritti anche lei. */
dialog.modale { border-radius: 4px; }
@media (max-width: 640px) { .comandi-record { padding: 4px 8px; } .testata-record .intestazione .campo { padding: 0 12px 0 0; border: 0; } }

/* Record aperto in una scheda della finestra: il titolo è già nella testata della finestra. */
.scheda-finestra { display: flex; flex-direction: column; gap: 12px; }
.scheda-finestra .titolo-record h1, .scheda-finestra .titolo-record .badge { display: none; }
.scheda-finestra .testata-record { margin: 0; }
.scheda-finestra .messaggio { margin: 0; }

/* Attesa durante i salvataggi: velo sopra il contenitore e la «W» del logo che si disegna e si
   cancella, col gradiente del marchio (#654ac6 → #1d09c1). Con le animazioni ridotte: pulsa. */
:root { --velo: rgba(244,245,247,.72); }
@media (prefers-color-scheme: dark) { :root { --velo: rgba(18,22,28,.72); } }
.velo-attesa { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; align-content: center; gap: 10px; background: var(--velo); backdrop-filter: blur(1px); cursor: progress; }
body > .velo-attesa { position: fixed; z-index: 60; }
.finestra { position: relative; }
.velo-attesa p { margin: 0; font-weight: 600; color: var(--muted); }
.loader-w { width: 88px; height: 56px; }
.loader-w path { fill: none; stroke: url(#wima-gradiente); stroke-width: 11; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 330; stroke-dashoffset: 330; animation: loader-w-disegna 1.6s cubic-bezier(.65,0,.35,1) infinite; }
@keyframes loader-w-disegna { 0% { stroke-dashoffset: 330; } 50% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -330; } }
@keyframes loader-w-pulsa { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .loader-w path { stroke-dasharray: none; stroke-dashoffset: 0; animation: loader-w-pulsa 2s ease-in-out infinite; }
}

/* Elenco caricato dopo la pagina: loader W dentro la griglia, conteggio che arriva a parte */
.griglia-tabulator .tabulator-alert { background: var(--velo); }
.griglia-tabulator .tabulator-alert .tabulator-alert-msg.tabulator-alert-state-msg { border: 0; background: transparent; padding: 0; }
.griglia-attesa { display: grid; place-items: center; gap: 10px; }
.griglia-attesa p { margin: 0; font-weight: 600; color: var(--muted); }
.barra-comandi .conteggio.in-attesa { animation: loader-w-pulsa 1.4s ease-in-out infinite; }
