* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; font-family: 'Segoe UI', system-ui, sans-serif;
  background: #f2f4f8; color: #1c2733; font-size: 14px;
}

/* pagine elenco: tutto fisso, scorrono solo le righe dentro .scroll-lista */
body.pagina-lista { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
body.pagina-lista .topbar { flex: 0 0 auto; }
body.pagina-lista main {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
  overflow: hidden; width: calc(100% - 44px); max-width: 1400px;
  margin: 14px auto 12px; padding: 0;
}
body.pagina-lista main > * { flex: 0 0 auto; }
body.pagina-lista main h1 { margin-bottom: 10px; }
.scroll-lista {
  overflow-y: auto;
  border-radius: 10px; box-shadow: 0 1px 3px rgba(20, 40, 70, .08);
  background: #fff;
}
.scroll-area { overflow-y: auto; }
body.pagina-lista main > .scroll-lista,
body.pagina-lista main > .scroll-area { flex: 1 1 auto; min-height: 0; }
.scroll-lista th, .scroll-area th { top: 0; }

/* barra superiore */
.topbar {
  display: flex; align-items: center; gap: 18px;
  background: #14324f; color: #fff; padding: 10px 22px;
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-size: 17px; font-weight: 600; }
.topbar nav { display: flex; gap: 4px; }
.topbar a { color: #cfdcea; text-decoration: none; padding: 7px 13px; border-radius: 6px; }
.topbar a:hover { background: #1e4a72; color: #fff; }
.topbar a.attivo { background: #2d6da3; color: #fff; }
.topbar .spazio { flex: 1; }
.topbar .utente-loggato {
  background: #2d6da3; color: #fff; padding: 5px 12px; border-radius: 20px;
  font-weight: 600; font-size: 13px; white-space: nowrap;
}
.topbar .aggiorna { color: #9fd8ff; font-weight: 600; }
.topbar .esci { color: #ffb3ab; }

main { max-width: 1400px; margin: 22px auto; padding: 0 22px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 15px; margin: 20px 0 8px; color: #34495e; }
.flash {
  background: #e2f5e5; border: 1px solid #9fd8a8; color: #1e6b2c;
  padding: 9px 14px; border-radius: 8px; margin-bottom: 14px;
}

/* dashboard */
.schede { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.scheda {
  flex: 1; min-width: 160px; background: #fff; border-radius: 12px;
  padding: 16px 18px; text-decoration: none; color: inherit;
  border: 1px solid #e1e6ee; border-left: 5px solid #7f8c9b;
  box-shadow: 0 1px 3px rgba(20, 40, 70, .06);
}
.scheda:hover { box-shadow: 0 3px 10px rgba(20, 40, 70, .12); }
.scheda .numero { font-size: 28px; font-weight: 700; }
.scheda .etichetta { color: #5a6a7c; margin-top: 2px; }
.scheda.blu { border-left-color: #2d6da3; }
.scheda.rossa { border-left-color: #c0392b; }
.scheda.rossa .numero { color: #c0392b; }
.scheda.arancio { border-left-color: #e67e22; }
.scheda.arancio .numero { color: #b95d0a; }
.scheda.verde { border-left-color: #27ae60; }
.colonne { display: grid; grid-template-columns: 3fr 2fr; gap: 26px; }
@media (max-width: 900px) { .colonne { grid-template-columns: 1fr; } }

/* tabelle: layout fisso, righe a altezza costante, testo troncato con ... e tooltip */
table {
  width: 100%; border-collapse: collapse; background: #fff;
  table-layout: fixed;
}
table tr:first-child th:first-child { border-top-left-radius: 10px; }
table tr:first-child th:last-child { border-top-right-radius: 10px; }
.scroll-lista table th { border-radius: 0; }
th, td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
th {
  text-align: left; background: #e8edf4; color: #33465c;
  padding: 8px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .3px;
  position: sticky; top: 45px; z-index: 5;
}
th .link-sort { color: inherit; text-decoration: none; display: block; }
th .link-sort:hover { color: #1f5a8c; }
th.dx, td.dx { text-align: right; }
td { padding: 6px 8px; border-top: 1px solid #eef1f6; vertical-align: middle; font-size: 13px; }
tr[onclick] { cursor: pointer; }
tr[onclick]:hover td { background: #f0f6fc; }
td.cliente { font-weight: 600; }
.testo-cella { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
td.azioni-riga { white-space: nowrap; overflow: visible; }
td.azioni-riga form { display: inline-block; margin: 0; }
td.azioni-riga button { padding: 4px 7px; font-size: 11.5px; }
button.chiudi { background: #27ae60; border-color: #27ae60; }
button.chiudi:hover { background: #1f8c4d; }
td.giorni { font-weight: 700; text-align: center; }

.riga-scaduta td { background: #fdeceb; }
.riga-scaduta td.giorni { color: #c0392b; }
.riga-in_scadenza td { background: #fdf3e4; }
.riga-in_scadenza td.giorni { color: #b95d0a; }
.riga-chiusa td { color: #8b98a7; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-aperta { background: #dbe9f7; color: #1f5a8c; }
.badge-scaduta { background: #f6d3cf; color: #92251a; }
.badge-in_scadenza { background: #fbe3c0; color: #8c5008; }
.badge-chiusa { background: #e4e8ed; color: #5f6d7c; }

/* tabs e filtri */
.tabs { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.tabs .spazio { flex: 1; }
.tab {
  padding: 7px 16px; border-radius: 8px 8px 0 0; text-decoration: none;
  color: #33465c; background: #dfe5ee; font-weight: 600;
}
.tab.attivo { background: #14324f; color: #fff; }
.filtri { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.filtri input[name=q] { flex: 1; min-width: 220px; }
.filtri input[name=cliente] { min-width: 180px; }
.filtri label.filtro-data {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; color: #43556b; white-space: nowrap;
}
.filtri input[type=date] { padding: 6px 8px; }
.conteggio { color: #5a6a7c; margin: 4px 0 8px; }

/* form */
input, select, textarea, button {
  font: inherit; padding: 8px 10px; border: 1px solid #c3cdd9;
  border-radius: 7px; background: #fff; color: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #2d6da3; border-color: #2d6da3; }
button {
  background: #2d6da3; border-color: #2d6da3; color: #fff;
  font-weight: 600; cursor: pointer; padding: 9px 20px;
}
button:hover { background: #245a88; }
button.pericolo { background: #c0392b; border-color: #c0392b; }
button.pericolo:hover { background: #9d2e22; }
.bottone-secondario {
  display: inline-block; padding: 8px 16px; border-radius: 7px;
  background: #e4e9f0; color: #33465c; text-decoration: none; font-weight: 600;
  border: 1px solid #c9d3df;
}
.bottone-secondario:hover { background: #d6deea; }

.scheda-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 1000px) { .scheda-form { grid-template-columns: 1fr; } }
.scheda-form fieldset {
  background: #fff; border: 1px solid #e1e6ee; border-radius: 12px;
  padding: 8px 16px 12px; margin: 0; min-width: 0;
  box-shadow: 0 1px 3px rgba(20, 40, 70, .06);
}
.scheda-form .doppia { grid-column: 1 / -1; }
.scheda-form legend { font-weight: 700; color: #14324f; padding: 0 6px; }
.griglia { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 14px; }
.griglia.griglia3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1000px) { .griglia, .griglia.griglia3 { grid-template-columns: repeat(2, 1fr); } }
.griglia label {
  display: flex; flex-direction: column; gap: 3px;
  font-weight: 600; color: #43556b; font-size: 12px; min-width: 0;
}
.griglia label input, .griglia label select, .griglia label textarea {
  font-weight: 400; font-size: 13.5px; padding: 6px 9px; width: 100%;
}
.griglia .larga2 { grid-column: span 2; }
.griglia .larga4 { grid-column: 1 / -1; }
.azioni { display: flex; gap: 10px; align-items: center; margin: 0; grid-column: 1 / -1; padding-bottom: 14px; }

/* storico */
.azione-eliminazione { background: #f6d3cf; color: #92251a; }
.azione-creazione { background: #d9f2df; color: #1e6b2c; }
.azione-chiusura, .azione-archiviazione { background: #dbe9f7; color: #1f5a8c; }
.azione-modifica, .azione-conferma, .azione-annullo { background: #e4e8ed; color: #5f6d7c; }
.azione-ripristino, .azione-ripescaggio { background: #fbe3c0; color: #8c5008; }
.mini-link { padding: 4px 10px; font-size: 11.5px; }

/* parametri */
.unisci-multi {
  background: #fff; border: 1px solid #e1e6ee; border-radius: 10px;
  padding: 8px 12px; box-shadow: 0 1px 3px rgba(20, 40, 70, .06);
}
.unisci-multi .etichetta-unisci { font-size: 12.5px; font-weight: 600; color: #43556b; }
input.suggerita { background: #fff6da; border-color: #e0a93e; }
#cerca-voce { flex: 1; min-width: 240px; max-width: 420px; }
.riga-suggerita td { background: #fffbef; }
.riga-azioni { display: inline-flex; gap: 6px; margin-right: 10px; vertical-align: middle; }
.riga-azioni input { padding: 5px 8px; width: 180px; }
.lista-usi li, details summary { white-space: normal; }
button.mini { padding: 5px 12px; font-size: 12.5px; }
.bottone-grigio { background: #7f8c9b; border-color: #7f8c9b; }
.bottone-grigio:hover { background: #6a7684; }
.lista-usi { margin: 6px 0 2px; padding-left: 18px; max-height: 220px; overflow-y: auto; }
.lista-usi a { color: #1f5a8c; text-decoration: none; }
.lista-usi a:hover { text-decoration: underline; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }

/* report */
.griglia-report { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 18px; }
@media (max-width: 1000px) { .griglia-report { grid-template-columns: 1fr; } }
.pannello-report {
  background: #fff; border: 1px solid #e1e6ee; border-radius: 12px;
  padding: 14px 18px 18px; box-shadow: 0 1px 3px rgba(20, 40, 70, .06);
}
.pannello-report h2 { margin-top: 2px; }
.pannello-largo { grid-column: 1 / -1; }
table.report { box-shadow: none; border-radius: 0; }
table.report td { border-top: 1px solid #f2f4f8; padding: 5px 8px; }
table.report .voce { max-width: 320px; font-weight: 600; }
table.report .num { font-weight: 700; }
.barra-cella { width: 40%; min-width: 120px; }
.barra {
  height: 16px; border-radius: 4px; min-width: 3px;
  background: linear-gradient(90deg, #2d6da3, #4f93cd);
}

/* allegati */
.lista-allegati { list-style: none; margin: 4px 0 10px; padding: 0; }
.lista-allegati li {
  display: flex; align-items: center; gap: 10px; padding: 5px 2px;
  border-bottom: 1px solid #eef1f6;
}
.lista-allegati a { color: #1f5a8c; text-decoration: none; font-weight: 600; }
.lista-allegati a:hover { text-decoration: underline; }
.dettaglio-allegato { color: #7a879a; font-size: 12px; }
.lista-allegati button { margin-left: auto; padding: 2px 8px; }
.carica-allegati { display: flex; flex-direction: column; gap: 4px; font-weight: 600; color: #43556b; font-size: 12px; }
.carica-allegati input[type=file] { font-weight: 400; background: #f6f8fb; }
.suggerimento { color: #7a879a; font-weight: 400; font-size: 11.5px; }

/* stampa: solo il contenuto, tabelle per intero, foglio orizzontale */
@page { size: A4 landscape; margin: 10mm; }
@media print {
  .topbar, .filtri, .tabs, .flash, button,
  .bottone-secondario, td.azioni-riga, th.col-azioni, td.col-azioni,
  .azioni, .no-print { display: none !important; }
  body, body.pagina-lista { height: auto; overflow: visible; display: block; background: #fff; font-size: 11px; }
  body.pagina-lista main { display: block; overflow: visible; width: auto; max-width: none; margin: 0; }
  .scroll-lista, .scroll-area { overflow: visible; box-shadow: none; border-radius: 0; }
  table { table-layout: auto; }
  th { position: static; }
  th, td { white-space: normal; overflow: visible; font-size: 10.5px; padding: 4px 6px; }
  tr[onclick] { cursor: auto; }
  .griglia-report { display: block; }
  .pannello-report { page-break-inside: avoid; box-shadow: none; margin-bottom: 12px; }
  .barra { background: #9db8d0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* login */
.pagina-login {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(140deg, #14324f, #2d6da3);
}
.box-login {
  background: #fff; padding: 34px 38px; border-radius: 14px; width: 340px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.box-login h1 { margin: 0; font-size: 20px; text-align: center; }
.box-login .sottotitolo { margin: 0 0 6px; text-align: center; color: #5a6a7c; font-size: 13px; }
.box-login label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; color: #43556b; }
.box-login .errore { background: #fdeceb; color: #92251a; padding: 8px 12px; border-radius: 7px; text-align: center; }
