:root {
  --red: #e2231a;
  --red-d: #b51911;
  --red-l: #fdecea;
  --red-a: rgba(226, 35, 26, .35);
  --on-red: #fff;
  --ink: #16181d;
  --ink-2: #4b5160;
  --muted: #6b7180;
  --line: #dfe2e8;
  --bg: #f4f5f7;
  --card: #fff;
  --ok: #157a3e;
  --warn: #9a6200;
  --err: #b42318;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--red-d); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 .9rem; text-transform: uppercase; letter-spacing: .04em; color: var(--red-d); }
h3 { font-size: .95rem; margin: 1.4rem 0 .5rem; }
code { background: #eef0f3; padding: 0 .3em; border-radius: 4px; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .5rem 1.25rem; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand img { height: 34px; display: block; }
.topbar nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: .55rem .8rem; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-weight: 500; }
.topbar nav a:hover { background: var(--bg); }
.topbar nav a.active { background: var(--red-l); color: var(--red-d); }
.who { display: flex; align-items: center; gap: .75rem; color: var(--muted); }
.who form { margin: 0; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.btns { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Cards & forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: .75rem; }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; font: inherit; font-weight: 400; color: var(--ink); padding: .6rem .7rem; border: 1px solid #c9cdd6; border-radius: 8px; background: #fff; min-height: 44px; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--red-a); border-color: var(--red); }
input[readonly] { background: #f3f4f6; }
input[type=checkbox], input[type=radio] { display: inline-block; width: 20px; height: 20px; min-height: 0; margin: 0 .4rem 0 0; vertical-align: middle; accent-color: var(--red); }
label.check { display: flex; align-items: center; font-weight: 500; color: var(--ink); min-height: 32px; }
.checks { border: 0; padding: 0; margin: .5rem 0 0; display: flex; flex-wrap: wrap; gap: .25rem 1.5rem; align-items: center; }
.checks legend { font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: .4rem; padding: 0; }
.inline-field { display: flex; align-items: center; gap: .5rem; margin: 0; flex: 1; min-width: 220px; }
.inline-field input { margin: 0; }
.grid { display: grid; gap: 0 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.two-col.wide-left { grid-template-columns: 2fr 1fr; }
.two-col > .card { margin-bottom: 0; }
.rapp-form .two-col { margin-bottom: 1rem; }
.h2row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.pad-top { padding-top: 1.6rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.rapp-form .form-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1.5rem 0 .75rem; }

.mat-row { display: grid; grid-template-columns: 1fr 70px 44px; gap: .4rem; margin-bottom: .4rem; }
.mat-row input { margin: 0; }

.costs label { display: grid; grid-template-columns: 1fr 140px; align-items: center; gap: .75rem; margin-bottom: .45rem; }
.costs input { margin: 0; text-align: right; }
.tot { display: grid; grid-template-columns: 1fr 140px; gap: .75rem; padding: .45rem 0; border-top: 1px solid var(--line); font-weight: 600; }
.tot output { text-align: right; padding-right: .7rem; }
.tot.grand { font-size: 1.1rem; color: var(--red-d); }

.sig-label { font-weight: 600; font-size: .85rem; color: var(--ink-2); margin-bottom: .4rem; }
.sigpad { position: relative; border: 1px dashed #b7bcc7; border-radius: 8px; background: #fcfcfd; }
.sigpad canvas { display: block; width: 100%; height: auto; aspect-ratio: 10 / 3; touch-action: none; cursor: crosshair; }
.sig-profile { border: 1px solid var(--line); border-radius: 8px; background: #fff; aspect-ratio: 10 / 3; display: flex; align-items: center; justify-content: center; }
.sig-profile img { max-width: 100%; max-height: 100%; }
.sig-clear { position: absolute; top: .4rem; right: .4rem; }

.consenso { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; align-items: center; padding: .6rem 0; border-top: 1px solid var(--line); }
.consenso .muted { flex-basis: 100%; font-size: .85rem; }
details.informativa { margin-bottom: 1rem; }
details.informativa summary { cursor: pointer; color: var(--red-d); font-weight: 600; min-height: 32px; }
.pre { font-size: .85rem; color: var(--ink-2); max-height: 320px; overflow: auto; padding: .75rem; background: var(--bg); border-radius: 8px; margin-top: .5rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; min-height: 44px; padding: .55rem 1rem; border-radius: 8px; border: 1px solid #c9cdd6; background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f6f7f9; }
.btn.primary { background: var(--red); border-color: var(--red); color: var(--on-red); }
.btn.primary:hover { background: var(--red-d); }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 36px; padding: .3rem .7rem; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
button.link { background: none; border: 0; color: var(--red-d); font: inherit; cursor: pointer; padding: .5rem; min-height: 44px; }
form.inline { display: inline-flex; gap: .3rem; margin: 0; align-items: center; }
form.reset-pw input { width: 150px; margin: 0; min-height: 36px; padding: .3rem .5rem; }

/* Lists */
.filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input, .filters select { width: auto; margin: 0; flex: 1 1 180px; }
.filters input[type=search] { flex: 3 1 260px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: .7rem .8rem; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.list th.r { text-align: right; }
table.list tfoot th { text-transform: none; font-size: .85rem; color: var(--ink); background: #fafbfc; border-top: 2px solid var(--line); border-bottom: 0; }
table.list td { padding: .6rem .8rem; border-bottom: 1px solid #eef0f3; vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.actions { text-align: right; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .2rem .55rem; border-radius: 99px; }
.badge-bozza { background: #fff4e0; color: var(--warn); }
.badge-inviato { background: #e5f4ea; color: var(--ok); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.muted { color: var(--muted); }
.tiny { font-size: .78rem; }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-weight: 500; }
.flash-ok { background: #e5f4ea; color: var(--ok); }
.flash-warn { background: #fff4e0; color: var(--warn); }
.flash-err { background: #fdecea; color: var(--err); }

/* Auth */
body.auth { display: grid; place-items: center; min-height: 100vh; }
.auth-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 2rem; margin: 2rem auto; }
.auth-logo { height: 54px; display: block; margin: 0 auto 1rem; }
.auth-card h1 { text-align: center; margin-bottom: 1rem; }

/* Anteprima */
.vedi-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
.paper-wrap { overflow-x: auto; background: #e6e8ec; padding: 1rem; border-radius: var(--radius); }
.send-panel { position: sticky; top: 76px; }
.send-panel input[type=email] { margin: 0 0 .75rem; }
.send-status { white-space: pre-line; margin-top: .75rem; font-size: .9rem; }
.send-status.ok { color: var(--ok); }
.send-status.err { color: var(--err); }
ul.invii { list-style: none; padding: 0; margin: 0; font-size: .8rem; }
ul.invii li { display: grid; gap: .1rem; padding: .5rem 0; border-top: 1px solid var(--line); }
ul.invii li.ok span:last-child { color: var(--ok); }
ul.invii li.err span:last-child { color: var(--err); }

/* Il documento del rapportino ha il suo foglio di stile: assets/doc.css */

/* Responsive */
@media (max-width: 960px) {
  .vedi-grid { grid-template-columns: 1fr; }
  .send-panel { position: static; }
}
@media (max-width: 760px) {
  .two-col, .two-col.wide-left, .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .topbar { gap: .5rem; padding: .5rem 1rem; }
  .who span { display: none; }
  .costs label, .tot { grid-template-columns: 1fr 110px; }
  table.list th:nth-child(4), table.list td:nth-child(4), table.list th:nth-child(5), table.list td:nth-child(5) { display: none; }
}

@media print {
  body { background: #fff; }
  .no-print, .topbar { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .vedi-grid { display: block; }
  .paper-wrap { padding: 0; background: none; }
  .doc { box-shadow: none; width: auto; padding: 0; }
  .paper-wrap .page-break { border: 0; margin: 0; }
}

/* Logo aziendale (impostazioni) */
.logo-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.25rem; }
.logo-preview { max-width: 260px; max-height: 90px; padding: .5rem; border: 1px dashed var(--line); border-radius: 8px; background: #fff; }
.logo-row form { flex: 1 1 260px; }
.logo-row form:last-child { flex: 0 0 auto; }

/* Colori (impostazioni) */
.color-row { display: flex; align-items: center; gap: .6rem; }
.color-row input[type=color] { width: 56px; height: 44px; padding: 2px; flex: 0 0 auto; cursor: pointer; }

/* Foto profilo */
.who-link { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: block; flex: 0 0 auto; }
.avatar-lg { width: 112px; height: 112px; }
.avatar-empty { display: flex; align-items: center; justify-content: center; background: var(--red-l); color: var(--red-d); font-size: 2.5rem; font-weight: 700; }
.photo-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.25rem; }
.photo-forms { flex: 1 1 220px; display: flex; flex-direction: column; gap: .5rem; }
.photo-forms form { margin: 0; }

/* Tipi di intervento */
.tipi-table input, .tipi-table select { margin: 0; min-width: 0; }
.tipi-table td:first-child { min-width: 300px; width: 30%; }
.tipi-table input.num { width: 6.5rem; text-align: right; }
.tipi-table tr.disattivo input { color: var(--muted); }
