:root {
  /* Palette brand Sata Holding (dal logo) */
  --blu: #1f4e88;
  --blu-scuro: #143257;
  --terra: #c46429;         /* terracotta */
  --terra-scuro: #a8511d;
  --verde: #3f9b3a;         /* verde logo */
  --verde-scuro: #2f7d2b;
  --bg: #eef1f7;
  --bordo: #dde3ec;
  --testo: #1f2733;
  --grigio: #6b7685;
  --giallo: #d99500;
  --rosso: #c8392f;
  --ombra: 0 1px 2px rgba(20,50,87,.05), 0 6px 18px rgba(20,50,87,.06);
  --ombra-hover: 0 4px 10px rgba(20,50,87,.10), 0 14px 34px rgba(20,50,87,.12);
  --grad-brand: linear-gradient(90deg, var(--terra) 0%, var(--verde) 52%, var(--blu) 100%);
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1100px 520px at 100% -5%, rgba(63,155,58,.08), transparent 60%),
    radial-gradient(1000px 480px at -5% 0%, rgba(196,100,41,.08), transparent 60%),
    var(--bg);
  color: var(--testo); font-size: 15px;
}
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }
a { color: var(--blu); }

/* LOGIN */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 12% 8%, rgba(63,155,58,.30), transparent 58%),
    radial-gradient(1000px 520px at 88% 92%, rgba(196,100,41,.34), transparent 55%),
    linear-gradient(135deg, #143257, #1f4e88 55%, #2a6fb8);
}
.login-card {
  background: #fff; padding: 34px 32px 30px; border-radius: 16px; width: 380px; max-width: 100%;
  box-shadow: 0 24px 70px rgba(0,0,0,.32); border-top: 5px solid transparent;
  border-image: var(--grad-brand) 1; position: relative;
}
.login-logo { display: block; height: 76px; width: auto; margin: 4px auto 22px; }
.login-card h1 { margin: 0 0 2px; font-size: 26px; font-weight: 800; letter-spacing: .3px; color: var(--blu); text-align: center; }
.login-card .sub { margin: 0 0 20px; color: var(--grigio); font-size: 13px; text-align: center; }
.login-card .sub-brand { margin-bottom: 16px; font-weight: 600; color: var(--terra); text-transform: uppercase; letter-spacing: 1.4px; font-size: 11px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--grigio); }
.login-card input { width: 100%; margin-top: 5px; padding: 11px; border: 1px solid var(--bordo); border-radius: 9px; font-size: 15px; transition: border-color .15s, box-shadow .15s; }
.login-card input:focus { outline: none; border-color: var(--blu); box-shadow: 0 0 0 3px rgba(31,78,136,.15); }
.login-card button { width: 100%; padding: 12px; background: var(--blu); color: #fff; border: 0; border-radius: 9px; font-size: 15px; font-weight: 700; margin-top: 8px; transition: background .15s, transform .05s, box-shadow .15s; box-shadow: 0 6px 16px rgba(31,78,136,.28); }
.login-card button:hover { background: var(--blu-scuro); box-shadow: var(--ombra-hover); }
.login-card button:active { transform: translateY(1px); }
.errore { color: var(--rosso); font-size: 13px; min-height: 18px; margin: 10px 0 0; text-align: center; }
/* Uscita dalla schermata di cambio password obbligatorio: non deve sembrare il pulsante principale */
.login-card .link-esci { width: auto; display: block; margin: 12px auto 0; padding: 4px; background: none; color: var(--grigio); box-shadow: none; font-size: 13px; font-weight: 600; text-decoration: underline; }
.login-card .link-esci:hover { background: none; color: var(--blu); box-shadow: none; }

/* BANNER AMBIENTE DI COLLAUDO (solo se il database è una copia anonimizzata) */
/* Sta sopra tutte le schermate (accesso compreso) e resta agganciato in alto durante lo
   scorrimento. Sotto la modale (z-index 50), così una finestra di modifica lo copre. */
.banner-collaudo {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px 10px;
  padding: 6px 16px; text-align: center;
  background: linear-gradient(90deg, #ffe6ad, #ffd98a 50%, #ffe6ad);
  color: #6b4200; border-bottom: 2px solid var(--giallo);
  font-size: 12.5px; font-weight: 600; letter-spacing: .2px;
  box-shadow: 0 2px 8px rgba(20,50,87,.12);
}
.banner-collaudo strong { font-weight: 800; letter-spacing: 1px; }

/* TOPBAR */
.topbar {
  /* min-height e non height: sotto i ~1600px il menu va a capo e con un'altezza fissa sborda
     dalla barra — la prima riga di voci finiva sopra il bordo superiore, fuori dallo schermo
     e non cliccabile (visibile sui portatili a 1280-1440px). Così la barra cresce quanto serve. */
  display: flex; align-items: center; gap: 22px; min-height: 72px; padding: 0 22px; color: #fff;
  background: linear-gradient(120deg, #143257 0%, #1f4e88 60%, #235595 100%);
  border-bottom: 3px solid transparent; border-image: var(--grad-brand) 1;
  box-shadow: 0 4px 18px rgba(20,50,87,.18); position: sticky; top: 0; z-index: 20;
  /* Con il banner la barra si aggancia SOTTO di esso, altrimenti scorrendo verrebbe coperta.
     --h-banner la misura app.js (il testo può andare a capo); senza banner vale 0. */
  top: var(--h-banner, 0px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-chip { display: inline-flex; align-items: center; background: #fff; border-radius: 10px; padding: 6px 10px; box-shadow: 0 2px 8px rgba(0,0,0,.18); flex: none; }
.logo-chip img { height: 36px; width: auto; display: block; }
.brand-text { font-weight: 800; font-size: 17px; letter-spacing: .3px; white-space: nowrap; }
.brand-sub { font-weight: 400; opacity: .72; font-size: 14px; }
#menu { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#menu button { background: transparent; border: 0; color: #d6e3f3; padding: 8px 14px; border-radius: 8px; font-size: 14px; transition: background .15s, color .15s; }
#menu button:hover { background: rgba(255,255,255,.12); color: #fff; }
#menu button.attivo { background: rgba(255,255,255,.16); color: #fff; font-weight: 700; box-shadow: inset 0 -2px 0 var(--terra); }
.user-box { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.user-box .link { background: transparent; border: 0; color: #d6e3f3; text-decoration: underline; }
.user-box .link:hover { color: #fff; }

@media (max-width: 1000px) { .brand-sub { display: none; } }
@media (max-width: 640px) { .brand-text { display: none; } .topbar { gap: 12px; padding: 0 14px; } }

main { padding: 22px 20px 40px; max-width: none; margin: 0; }

h2.titolo-pagina { margin: 0 0 4px; font-size: 23px; font-weight: 800; }
.descr-pagina { color: var(--grigio); margin: 0 0 20px; font-size: 14px; }

/* BOTTONI */
.btn { background: var(--blu); color: #fff; border: 0; padding: 10px 17px; border-radius: 9px; font-size: 14px; font-weight: 700; transition: background .15s, transform .05s, box-shadow .15s; box-shadow: 0 3px 10px rgba(31,78,136,.22); }
.btn:hover { background: var(--blu-scuro); box-shadow: var(--ombra-hover); }
.btn:active { transform: translateY(1px); }
.btn-sec { background: #fff; color: var(--blu); border: 1px solid #c4d2e6; box-shadow: none; }
.btn-sec:hover { background: #f2f6fc; border-color: var(--blu); }
.btn-piccolo { padding: 6px 11px; font-size: 13px; box-shadow: none; }
.btn-danger { background: #fff; color: var(--rosso); border: 1px solid #e6b3ae; box-shadow: none; }
.btn-danger:hover { background: #fdf1f0; border-color: var(--rosso); }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }

/* CARD / TABELLE */
.card { background: #fff; border: 1px solid var(--bordo); border-radius: 12px; padding: 0; overflow-x: auto; box-shadow: var(--ombra); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; font-size: 14px; border-bottom: 1px solid var(--bordo); }
thead tr:first-child th { background: #eef3fa; color: #47566a; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 2px solid #dbe4f0; }
tbody tr { transition: background .12s; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f5f9ff; }
.vuoto { padding: 30px; text-align: center; color: var(--grigio); }

/* BADGE STATO */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.ok { background: #e5f5e3; color: var(--verde-scuro); }
.badge.in_scadenza { background: #fdf2dc; color: var(--giallo); }
.badge.scaduto { background: #fbe3e1; color: var(--rosso); }

/* DASHBOARD CARDS */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { position: relative; background: #fff; border: 1px solid var(--bordo); border-radius: 12px; padding: 18px 18px 18px 20px; box-shadow: var(--ombra); overflow: hidden; transition: transform .12s, box-shadow .15s; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--blu); }
.stat:hover { transform: translateY(-2px); box-shadow: var(--ombra-hover); }
.stat .num { font-size: 32px; font-weight: 800; line-height: 1.1; }
.stat .lab { color: var(--grigio); font-size: 13px; margin-top: 2px; }
.stat.rosso::before { background: var(--rosso); }
.stat.giallo::before { background: var(--giallo); }
.stat.verde::before { background: var(--verde); }
.stat.blu::before { background: var(--blu); }
.stat.rosso .num { color: var(--rosso); }
.stat.giallo .num { color: var(--giallo); }
.stat.verde .num { color: var(--verde-scuro); }
.stat.blu .num { color: var(--blu); }

/* MODALE */
.modale { position: fixed; inset: 0; background: rgba(15,28,48,.55); backdrop-filter: blur(2px); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modale-box { background: #fff; border-radius: 14px; width: min(94vw, 900px); max-width: 100%; box-shadow: 0 24px 70px rgba(0,0,0,.32); border-top: 4px solid transparent; border-image: var(--grad-brand) 1; }
.modale-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--bordo); }
.modale-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.modale-head .link { background: 0; border: 0; font-size: 18px; color: var(--grigio); }
.modale-head .link:hover { color: var(--rosso); }
#modale-corpo { padding: 22px; }

/* FORM */
/* Form orizzontali (landscape ~16:10): campi su 3 colonne */
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .due { grid-column: span 2; }
@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full, .form-grid .due { grid-column: 1 / -1; }
}
/* Scheda collaboratore: più larga e orizzontale (~16:10), 5 colonne per ridurre lo scroll */
.modale-box:has(#f-dip) { width: min(97vw, 1360px); }
#f-dip .form-grid { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1200px) { #f-dip .form-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 820px)  { #f-dip .form-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px)  { #f-dip .form-grid { grid-template-columns: 1fr; } }
/* Spaziature verticali ridotte nella scheda collaboratore */
.modale-box:has(#f-dip) #modale-corpo { padding: 16px 20px; }
#f-dip .form-grid { gap: 8px 16px; }
#f-dip .campo { font-size: 12px; }
#f-dip .campo input, #f-dip .campo select, #f-dip .campo textarea { margin-top: 3px; padding: 7px 9px; }
#f-dip .campo textarea { min-height: 42px; }
#f-dip .sottotitolo { margin: 12px 0 2px; padding-bottom: 4px; }
#f-dip .form-azioni { margin-top: 12px; }
.campo { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; color: var(--grigio); }
.campo input, .campo select, .campo textarea { margin-top: 5px; padding: 10px; border: 1px solid var(--bordo); border-radius: 9px; font-size: 14px; font-family: inherit; font-weight: 400; color: var(--testo); transition: border-color .15s, box-shadow .15s; }
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: none; border-color: var(--blu); box-shadow: 0 0 0 3px rgba(31,78,136,.13); }
.campo textarea { resize: vertical; min-height: 60px; }
.form-azioni { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.msg-form { color: var(--rosso); font-size: 13px; margin-top: 10px; min-height: 16px; }

.link-file { color: var(--blu); text-decoration: none; font-size: 13px; }
.link-file:hover { text-decoration: underline; }
.link-file.scarica { color: var(--grigio); margin-left: 2px; }
.link-file.scarica:hover { color: var(--blu); }
.azioni-cella { display: flex; gap: 6px; }
.filtro-sel { padding: 8px; border: 1px solid var(--bordo); border-radius: 9px; font-size: 14px; }

/* Tabelle: ordinamento e filtri per colonna */
th.ord { cursor: pointer; user-select: none; white-space: nowrap; }
th.ord:hover { color: var(--blu); }
.filtri-row th { padding: 4px 8px 10px; background: #eef3fa; }
.filtro-col { width: 100%; box-sizing: border-box; padding: 5px 7px; font-size: 12px; font-weight: 400; border: 1px solid var(--bordo); border-radius: 6px; }
.filtro-col:focus { outline: none; border-color: var(--blu); box-shadow: 0 0 0 2px rgba(31,78,136,.12); }

/* Maniglia per ridimensionare le colonne a trascinamento */
th .th-label { display: inline-block; cursor: grab; }
th .th-label:active { cursor: grabbing; }
th.col-drop { box-shadow: inset 3px 0 0 var(--terra); }
.col-resizer { position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: col-resize; user-select: none; z-index: 2; }
.col-resizer:hover { background: var(--blu); opacity: .25; }
th, td { overflow: hidden; text-overflow: ellipsis; }
.sottotitolo { font-size: 15px; font-weight: 700; color: var(--blu); margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 2px solid #e7edf6; }

/* ONBOARDING */
.prog { display: inline-block; vertical-align: middle; width: 120px; height: 9px; background: #e7edf6; border-radius: 6px; overflow: hidden; }
.prog-fill { height: 100%; background: linear-gradient(90deg, var(--verde), var(--verde-scuro)); border-radius: 6px; transition: width .3s; }
.prog-lab { font-size: 12px; color: var(--grigio); margin-left: 8px; vertical-align: middle; }
.onb-cruscotto { display: flex; align-items: center; gap: 18px; background: #fff; border: 1px solid var(--bordo); border-left: 5px solid var(--verde); border-radius: 12px; padding: 16px 20px; box-shadow: var(--ombra); margin-bottom: 22px; }
.onb-cruscotto .prog { width: 100%; height: 12px; }
.onb-crusc-perc { font-size: 34px; font-weight: 800; color: var(--verde-scuro); min-width: 90px; }
/* Selettore di fase (Pre-ingresso / Piano di inserimento) */
.onb-fase-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.onb-fase-tab { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; background: #fff; border: 1px solid var(--bordo); border-radius: 10px; padding: 10px 16px; cursor: pointer; min-width: 220px; box-shadow: var(--ombra); transition: border-color .15s, box-shadow .15s, transform .05s; }
.onb-fase-tab:hover { border-color: #b8c6dd; }
.onb-fase-tab.attivo { border-color: var(--blu); box-shadow: inset 0 -3px 0 var(--blu), var(--ombra); }
.onb-fase-tab-tit { font-weight: 700; font-size: 14px; color: var(--blu); }
.onb-fase-tab-cont { font-size: 12px; color: var(--grigio); }
.onb-fase { margin-bottom: 26px; }
.onb-fase-tit { font-size: 17px; font-weight: 800; color: var(--blu); margin: 18px 0 12px; }
.onb-fase-cont { font-size: 13px; font-weight: 600; color: var(--grigio); background: #eef3fa; padding: 2px 10px; border-radius: 20px; margin-left: 8px; }
.onb-sez { margin-bottom: 16px; }
.onb-sez-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: #47566a; margin: 10px 2px 6px; }
.onb-sez-prog { display: flex; align-items: center; text-transform: none; }
.onb-tab td { vertical-align: top; }
.onb-tab th, .onb-tab td { white-space: normal; overflow: visible; text-overflow: clip; }
.onb-att { font-weight: 600; color: var(--testo); }
.onb-note { font-size: 12px; color: var(--grigio); margin-top: 3px; }
.onb-hint { display: block; font-size: 11px; color: var(--grigio); margin-top: 2px; }
.onb-stato { padding: 6px 8px; border: 1px solid var(--bordo); border-radius: 8px; font-size: 13px; font-family: inherit; background: #fff; }
.onb-notain { width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--bordo); border-radius: 8px; font-size: 13px; font-family: inherit; }
.onb-notain:focus, .onb-stato:focus { outline: none; border-color: var(--blu); box-shadow: 0 0 0 3px rgba(31,78,136,.12); }
tr.onb-voce.stato-fatto td { background: #f2fbf1; }
tr.onb-voce.stato-na td { background: #f6f7f9; color: var(--grigio); }
tr.onb-voce.stato-in_corso td { background: #fffdf4; }
.onb-file-cell { white-space: nowrap; }
.onb-upload { display: inline-block; font-size: 12px; font-weight: 600; color: var(--blu); border: 1px dashed #b8c6dd; border-radius: 7px; padding: 4px 8px; cursor: pointer; background: #fff; }
.onb-upload:hover { background: #f2f6fc; border-color: var(--blu); }
.onb-file-x { border: 0; background: transparent; color: var(--grigio); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.onb-file-x:hover { color: var(--rosso); }
