:root {
  --navy: #1F3864;
  --blue: #2E5395;
  --teal: #0F6B5C;
  --gold: #B8860B;
  --grey: #595959;
  --light-grey: #F2F2F2;
  --light-blue: #EAF0F8;
  --light-teal: #E8F3F0;
  --red: #B23A34;
  --light-red: #FBEAEA;
  --border: #DDE3EC;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", Calibri, Arial, sans-serif;
  margin: 0;
  background: #F7F9FC;
  color: #1a1a1a;
}

header.topbar {
  background: var(--navy);
  color: #fff;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header.topbar .brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
}
header.topbar .brand span { color: #E8C468; }

header.topbar nav a {
  color: #dfe7f5;
  text-decoration: none;
  margin-left: 22px;
  font-size: 14px;
  font-weight: 600;
}
header.topbar nav a.active, header.topbar nav a:hover { color: #fff; border-bottom: 2px solid var(--gold); padding-bottom: 4px; }

main { max-width: 1180px; margin: 0 auto; padding: 26px 28px 60px; }

h1 { color: var(--navy); font-size: 26px; margin: 4px 0 6px; }
.subtitle { color: var(--grey); font-size: 14px; margin-bottom: 22px; }

.stats-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 24px; }
.stat-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px; min-width: 140px; flex: 1;
}
.stat-card .n { font-size: 26px; font-weight: 700; color: var(--navy); }
.stat-card .l { font-size: 12.5px; color: var(--grey); }
.stat-card.warn .n { color: var(--red); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar select, .toolbar input[type=text] {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 13.5px;
}
.toolbar input[type=text] { min-width: 220px; }
.spacer { flex: 1; }

button {
  font-family: inherit; cursor: pointer; border: none; border-radius: 7px;
  padding: 9px 16px; font-size: 13.5px; font-weight: 600;
}
button.primary { background: var(--navy); color: #fff; }
button.primary:hover { background: #16294a; }
button.ghost { background: #fff; color: var(--navy); border: 1px solid var(--border); }
button.ghost:hover { background: var(--light-blue); }
button.small { padding: 5px 10px; font-size: 12.5px; }
button.danger { background: #fff; color: var(--red); border: 1px solid #e3b8b5; }

table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
thead th {
  background: var(--navy); color: #fff; text-align: left; font-size: 12.5px;
  padding: 10px 12px; font-weight: 600;
}
tbody td { padding: 10px 12px; font-size: 13.5px; border-top: 1px solid var(--border); vertical-align: top; }
tbody tr:hover { background: #FAFBFD; cursor: pointer; }
tbody tr.chiusa { opacity: 0.6; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge.aperta { background: var(--light-red); color: var(--red); }
.badge.chiusa { background: var(--light-teal); color: var(--teal); }
.badge.norma { background: var(--light-blue); color: var(--blue); }

.section-title {
  background: var(--light-blue); color: var(--navy); font-weight: 700; font-size: 13px;
  padding: 8px 14px; margin-top: 22px; border-radius: 7px;
}

.empty { color: var(--grey); font-style: italic; padding: 30px; text-align: center; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,30,50,0.45); display: flex;
  align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal {
  background: #fff; border-radius: 12px; padding: 26px 28px; max-width: 720px; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal h2 { color: var(--navy); margin-top: 0; font-size: 20px; }
.modal .close { float: right; cursor: pointer; color: var(--grey); font-size: 20px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-top: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 12px; font-weight: 600; color: var(--grey); margin-bottom: 4px; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 13.5px; font-family: inherit;
}
.form-grid textarea { min-height: 60px; resize: vertical; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.error-box { background: var(--light-red); color: var(--red); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-top: 12px; }

.detail-row { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.detail-row .k { width: 200px; color: var(--grey); font-weight: 600; flex-shrink: 0; }
.detail-row .v { flex: 1; }

.history-list { list-style: none; margin: 8px 0 0; padding: 0; }
.history-list li { padding: 8px 10px; background: var(--light-grey); border-radius: 7px; margin-bottom: 6px; font-size: 13px; }

/* Home — app grid */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.app-tile {
  display: block;
  text-decoration: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 20px 18px;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
  position: relative;
}
.app-tile:hover { box-shadow: 0 6px 18px rgba(31,56,100,0.12); transform: translateY(-2px); border-color: var(--blue); }
.app-tile .icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; margin-bottom: 12px;
}
.app-tile .title { color: var(--navy); font-weight: 700; font-size: 15.5px; margin-bottom: 5px; }
.app-tile .desc { color: var(--grey); font-size: 12.5px; line-height: 1.4; }
.app-tile .tag { position: absolute; top: 16px; right: 16px; font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.app-tile .tag.count { background: var(--light-blue); color: var(--blue); }
.app-tile .tag.warn { background: var(--light-red); color: var(--red); }

.app-tile.disabled {
  cursor: default;
  background: #FAFBFC;
  border-style: dashed;
}
.app-tile.disabled:hover { box-shadow: none; transform: none; border-color: var(--border); }
.app-tile.disabled .icon { background: var(--light-grey) !important; color: var(--grey) !important; }
.app-tile.disabled .title { color: #8b93a1; }
.app-tile.disabled .desc { color: #a3aab5; }
.app-tile.disabled .tag { background: var(--light-grey); color: var(--grey); }

.section-label {
  font-size: 12px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  color: var(--grey); margin: 30px 0 12px;
}

/* Hero / landing */
.hero {
  position: relative;
  background: linear-gradient(120deg, var(--navy) 0%, #24487d 55%, var(--teal) 130%);
  overflow: hidden;
  padding: 40px 28px;
}
.hero-pitto {
  position: absolute; top: 50%; right: -60px; transform: translateY(-50%);
  width: 420px; opacity: 0.10; pointer-events: none;
}
.hero-pitto img { width: 100%; display: block; filter: brightness(0) invert(1); }
.hero-inner {
  position: relative; max-width: 1180px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 40px; flex-wrap: wrap;
}
.hero-text { flex: 1; min-width: 280px; max-width: 620px; }
.hero-logo { height: 34px; width: auto; margin-bottom: 18px; display: block; }
.hero-text h1 { color: #fff; font-size: 27px; margin: 0 0 10px; }
.hero-lead { color: #dfe7f5; font-size: 14.5px; line-height: 1.55; margin: 0 0 16px; }
.hero-invito {
  color: #fff; font-size: 13.5px; line-height: 1.55; margin: 0;
  background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px; padding: 12px 16px; max-width: 540px;
}
.hero-qr {
  background: #fff; border-radius: 14px; padding: 18px 20px 16px;
  box-shadow: 0 12px 30px rgba(10,20,40,0.25); text-align: center; flex-shrink: 0;
}
.hero-qr img { width: 148px; height: 148px; display: block; margin: 0 auto; }
.hero-qr-label {
  font-size: 12.5px; font-weight: 700; color: var(--navy); margin-top: 10px; line-height: 1.35;
}
.hero-qr-link {
  display: inline-block; margin-top: 8px; font-size: 12px; color: var(--blue); text-decoration: none; font-weight: 600;
}
.hero-qr-link:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .hero-inner { flex-direction: column; align-items: stretch; }
  .hero-qr { align-self: center; }
}

/* Audit / check list */
.audit-sezione {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  margin-top: 14px; overflow: hidden;
}
.audit-sezione summary {
  cursor: pointer; padding: 12px 16px; font-weight: 700; font-size: 13.5px;
  color: var(--navy); background: var(--light-blue); list-style: none;
}
.audit-sezione summary::-webkit-details-marker { display: none; }
.audit-sezione-body { padding: 4px 16px 12px; }

.audit-item { padding: 14px 0; border-top: 1px solid var(--border); }
.audit-item:first-child { border-top: none; }
.audit-item-testo { font-size: 13.5px; line-height: 1.5; margin-bottom: 10px; }
.audit-item-rif {
  display: inline-block; margin-left: 8px; font-size: 10.5px; font-weight: 700;
  color: var(--blue); background: var(--light-blue); padding: 1px 7px; border-radius: 10px; white-space: nowrap;
}
.audit-item-resp { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.resp-pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700;
  border: 1.5px solid var(--border); border-radius: 20px; padding: 5px 12px; cursor: pointer;
  color: var(--grey); user-select: none; transition: all 0.1s;
}
.resp-pill input { margin: 0; }
.resp-pill:hover { border-color: var(--blue); }
.resp-pill.resp-si.checked { background: #E6F4EA; border-color: #2E7D46; color: #1E5E31; }
.resp-pill.resp-no.checked { background: var(--light-red); border-color: var(--red); color: var(--red); }
.resp-pill.resp-na.checked { background: var(--light-grey); border-color: #8b93a1; color: #595959; }
.resp-pill.resp-nc.checked { background: #FBEAEA; border-color: #B23A34; color: #B23A34; }
.resp-pill.resp-rac.checked { background: var(--light-blue); border-color: var(--blue); color: var(--blue); }
.resp-pill.resp-sug.checked { background: #FBF3E2; border-color: var(--gold); color: var(--gold); }
.audit-item-fields { display: flex; gap: 8px; flex-wrap: wrap; }
.audit-item-fields textarea {
  flex: 2; min-width: 240px; min-height: 44px; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 7px; font-size: 12.5px; font-family: inherit; resize: vertical;
}
.audit-item-fields input {
  flex: 1; min-width: 180px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px; font-size: 12.5px; font-family: inherit;
}
.saving-indicator { font-size: 10.5px; color: var(--teal); margin-top: 4px; height: 12px; }

/* Allegato file nel dettaglio documento */
.file-box {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--light-blue); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; flex-wrap: wrap;
}
.file-box-info { display: flex; align-items: center; gap: 10px; }
.file-box-icon { font-size: 20px; }
.file-box-name { font-weight: 600; font-size: 13.5px; color: var(--navy); word-break: break-word; }
.file-box-meta { font-size: 12px; color: var(--grey); }
.file-box-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Organizzazioni e referenti */
.org-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.org-card h3 { margin: 0; font-size: 16px; color: var(--navy); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.org-card .alias { font-size: 12px; color: var(--grey); margin-top: 4px; }
.org-card table { margin-top: 10px; }
.org-card td, .org-card th { font-size: 12.5px; }
.stat-card.clic { cursor: pointer; }
.stat-card.clic:hover { border-color: var(--blue); }
.stat-card.attivo { outline: 2px solid var(--blue); }
.scad-ko { color: var(--red); font-weight: 700; }
.scad-vicina { color: #B26A00; font-weight: 700; }
.form-grid input[type=checkbox], .form-grid input[type=radio] { width: auto; margin-right: 4px; vertical-align: middle; }

/* --- Guida in linea ------------------------------------------------------------------------------ */
.guida-testo { font-size: 14px; line-height: 1.6; color: #1d2733; }
.guida-testo h1 { font-size: 22px; color: var(--navy); margin: 0 0 10px; }
.guida-testo h2 { font-size: 17px; color: var(--navy); margin: 22px 0 6px; }
.guida-testo h3 { font-size: 14.5px; color: var(--navy); margin: 16px 0 4px; }
.guida-testo table { margin: 8px 0 14px; font-size: 13px; }
.guida-testo table th { position: static; }
.guida-testo table tr { cursor: default; }
.guida-testo blockquote { margin: 10px 0; padding: 8px 12px; background: #fff8e1; border-left: 4px solid #e8c468; border-radius: 6px; }
.guida-testo code { background: #eef3fa; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.guida-testo ul, .guida-testo ol { padding-left: 22px; }
.help-btn { margin-left: 14px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.5); background: transparent; color: #fff; font-weight: 700; cursor: pointer; font-size: 14px; line-height: 1; }
.help-btn:hover { background: rgba(255,255,255,0.15); }
.help-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: #fff; box-shadow: -8px 0 30px rgba(0,0,0,0.18); z-index: 1000; display: flex; flex-direction: column; transform: translateX(105%); transition: transform .2s ease; }
.help-drawer.aperto { transform: translateX(0); }
.help-drawer .testa { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.help-drawer .testa strong { color: var(--navy); flex: 1; }
.help-drawer .corpo { overflow: auto; padding: 16px 20px 30px; }
@media print {
  .help-drawer, .help-btn { display: none !important; }
}

/* --- Schede (tab) e programma audit -------------------------------------------------------------- */
.tabs .tab { background: none; border: none; border-bottom: 3px solid transparent; padding: 8px 14px; font-weight: 600; color: var(--grey); cursor: pointer; border-radius: 0; }
.tabs .tab.attiva { color: var(--navy); border-bottom-color: var(--navy); }
.prog-grid td { vertical-align: top; }
.prog-grid td.cella { cursor: pointer; min-width: 130px; }
.prog-grid td.cella:hover { background: #f3f7fc; }
.chip { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 10px; margin: 2px 0; font-weight: 600; white-space: nowrap; }
.chip.Svolto { background: #e2efda; color: #375623; }
.chip.Pianificato { background: #ddebf7; color: #1f4e79; }
.chip.Rinviato { background: #fff2cc; color: #7f6000; }
.chip.Annullato { background: #ededed; color: #777; text-decoration: line-through; }
.chip.ritardo { background: #fce4d6; color: #a12b00; }
.chip .terza { font-size: 10px; margin-left: 4px; opacity: .8; }
