:root {
  --blu: #0b3a6e;
  --blu-scuro: #072a52;
  --blu-chiaro: #e8eff8;
  --azzurro: #1d6fb8;
  --testo: #1f2933;
  --grigio: #5f6b7a;
  --bordo: #d9e0e8;
  --sfondo: #f4f6f9;
  --rosso: #b3261e;
  --verde: #1e7a46;
  --ambra: #8a5a00;
  --radius: 8px;
  font-family: "Titillium Web", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--testo);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--sfondo); font-size: 16px; line-height: 1.5; }
a { color: var(--azzurro); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
main.wrap { padding-top: 28px; padding-bottom: 48px; }
h1 { font-size: 1.6rem; margin: 0 0 12px; color: var(--blu-scuro); }
h2 { font-size: 1.2rem; margin: 0 0 12px; color: var(--blu-scuro); }
.muted { color: var(--grigio); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar { background: var(--blu); color: #fff; border-bottom: 4px solid var(--azzurro); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; }
.brand strong { display: block; font-size: 1.1rem; letter-spacing: .2px; }
.brand small { display: block; font-size: .8rem; opacity: .85; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 6px;
  background: #fff; color: var(--blu); font-weight: 700; }
.user { display: flex; align-items: center; gap: 12px; }
.user form { margin: 0; }
.user-name { font-size: .95rem; }

.card { background: #fff; border: 1px solid var(--bordo); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.crumbs { margin: 0 0 12px; font-size: .95rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px;
  border: 1px solid var(--bordo); background: #fff; color: var(--blu-scuro); border-radius: 6px; font: inherit;
  font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--blu-chiaro); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, th button:focus-visible {
  outline: 3px solid #f2b705; outline-offset: 2px; }
.btn-primary { background: var(--azzurro); border-color: var(--azzurro); color: #fff; }
.btn-primary:hover { background: var(--blu); }
.btn-danger { color: var(--rosso); border-color: #e7b9b5; }
.btn-danger:hover { background: #fbeceb; }
dialog .btn-danger[type=submit] { background: var(--rosso); color: #fff; border-color: var(--rosso); }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-small { padding: 4px 10px; font-size: .9rem; }
.btn-wide { width: 100%; margin-top: 8px; }

.alert { padding: 10px 14px; border-radius: 6px; margin: 0 0 16px; }
.alert-error { background: #fbeceb; color: var(--rosso); border: 1px solid #efc4c0; }
.alert-ok { background: #e7f4ec; color: var(--verde); border: 1px solid #bfe0cc; }
.alert-info { background: var(--blu-chiaro); color: var(--blu-scuro); border: 1px solid #c8d8ec; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.search input { width: min(420px, 90vw); }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid #b8c3d0; border-radius: 6px; font: inherit; background: #fff; }
textarea { resize: vertical; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--bordo); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--bordo); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fafc; }
.table th { background: var(--blu-chiaro); }
.table th button { all: unset; cursor: pointer; font-weight: 700; color: var(--blu-scuro); }
.table th button::after { content: " ↕"; opacity: .35; }
.table th button[data-dir=asc]::after { content: " ↑"; opacity: 1; }
.table th button[data-dir=desc]::after { content: " ↓"; opacity: 1; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions-col { width: 1%; white-space: nowrap; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; }
.badge-bozza { background: #eef1f4; color: var(--grigio); }
.badge-attivo { background: #e7f4ec; color: var(--verde); }
.badge-concluso { background: #fdf3dd; color: var(--ambra); }

.form label { display: block; font-weight: 600; margin-bottom: 14px; }
.form label input, .form label select, .form label textarea { margin-top: 4px; font-weight: 400; }
.form.grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; }
.span2 { grid-column: 1 / -1; }
.req { color: var(--rosso); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--rosso); }
.err { display: block; color: var(--rosso); font-weight: 400; font-size: .9rem; margin-top: 4px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }
@media (max-width: 720px) { .form.grid { grid-template-columns: 1fr; } }

.login { max-width: 420px; margin: 40px auto; }

.details { display: grid; grid-template-columns: 180px 1fr; gap: 10px 20px; margin: 0; }
.details dt { color: var(--grigio); font-weight: 600; }
.details dd { margin: 0; }
.pre { white-space: pre-wrap; }
@media (max-width: 640px) { .details { grid-template-columns: 1fr; } .details dd { margin-bottom: 6px; } }

.history { list-style: none; padding: 0; margin: 0; }
.history > li { border-left: 3px solid var(--azzurro); padding: 4px 0 10px 14px; margin-bottom: 10px; }
.history time { color: var(--grigio); margin-left: 6px; font-size: .9rem; }
.diff { margin: 6px 0 0; padding-left: 18px; }
.diff .field { color: var(--grigio); }
.diff del { color: var(--rosso); }
.diff ins { color: var(--verde); text-decoration: none; }

.empty { text-align: center; }
.dialog { border: 0; border-radius: var(--radius); padding: 24px; max-width: 440px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(7, 42, 82, .45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.table td.actions { display: table-cell; white-space: nowrap; }
.table td.actions > * + * { margin-left: 6px; }
