: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;
  --ok-bg: #e5f4ea;
  --warn-bg: #fff4e0;
  --err-bg: #fdecea;
  --surface-2: #fafbfc;
  --field: #fff;
  --field-line: #c9cdd6;
  --hover: #f6f7f9;
  --readonly: #f3f4f6;
  --code-bg: #eef0f3;
  --row-line: #eef0f3;
  --paper-bg: #e6e8ec;
  /* Grafici (statistiche): inchiostri e serie categoriali validate per il fondo chiaro */
  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;
  --chart-muted: #898781;
  --chart-tip-bg: #16181d;
  --chart-tip-ink: #fff;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  --radius: 10px;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
}
/* Tema scuro: scelto dall'utente (data-theme="dark") oppure dal sistema quando il tema è automatico.
   I due blocchi devono restare uguali. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e6e8ec; --ink-2: #b4bac6; --muted: #8f96a3; --line: #2f343d;
  --bg: #111317; --card: #1a1d22; --surface-2: #20242a;
  --field: #15181d; --field-line: #3b414c; --hover: #252a31; --readonly: #22262c; --code-bg: #262a31; --row-line: #262a31;
  --paper-bg: #0b0c0f;
  --ok: #4cc27a; --warn: #e0a53a; --err: #f1786b;
  --ok-bg: rgba(76, 194, 122, .14); --warn-bg: rgba(224, 165, 58, .14); --err-bg: rgba(241, 120, 107, .14);
  --red-l: color-mix(in srgb, var(--red) 24%, #1a1d22);
  --red-d: color-mix(in srgb, var(--red) 60%, #fff);
  --chart-grid: #2c2c2a; --chart-axis: #383835; --chart-muted: #898781;
  --chart-tip-bg: #f0efec; --chart-tip-ink: #16181d;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ink: #e6e8ec; --ink-2: #b4bac6; --muted: #8f96a3; --line: #2f343d;
    --bg: #111317; --card: #1a1d22; --surface-2: #20242a;
    --field: #15181d; --field-line: #3b414c; --hover: #252a31; --readonly: #22262c; --code-bg: #262a31; --row-line: #262a31;
    --paper-bg: #0b0c0f;
    --ok: #4cc27a; --warn: #e0a53a; --err: #f1786b;
    --ok-bg: rgba(76, 194, 122, .14); --warn-bg: rgba(224, 165, 58, .14); --err-bg: rgba(241, 120, 107, .14);
    --red-l: color-mix(in srgb, var(--red) 24%, #1a1d22);
    --red-d: color-mix(in srgb, var(--red) 60%, #fff);
    --chart-grid: #2c2c2a; --chart-axis: #383835; --chart-muted: #898781;
    --chart-tip-bg: #f0efec; --chart-tip-ink: #16181d;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  }
}
* { 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: var(--code-bg); padding: 0 .3em; border-radius: 4px; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .5rem 1.25rem; background: var(--card); 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 { display: inline-flex; align-items: center; gap: .45rem; padding: .55rem .75rem; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.nav-ico { width: 18px; height: 18px; flex: 0 0 auto; opacity: .85; }
.topbar nav a.active .nav-ico, .topbar nav a:hover .nav-ico { opacity: 1; }
.topbar nav a:hover { background: var(--bg); }
.topbar nav a.active { background: var(--red-l); color: var(--red-d); }
.who { position: relative; display: flex; align-items: center; gap: .75rem; color: var(--muted); }
.who form { margin: 0; }

/* Foto utente e sottomenu */
.who-btn { display: flex; align-items: center; gap: .5rem; min-height: 44px; padding: .25rem .55rem .25rem .3rem; border: 1px solid transparent; border-radius: 99px; background: none; color: var(--ink-2); font: inherit; font-weight: 500; cursor: pointer; }
.who-btn:hover, .who-btn[aria-expanded="true"] { background: var(--hover); border-color: var(--line); color: var(--ink); }
.who-btn .avatar { width: 34px; height: 34px; }
.who-btn .avatar-empty { font-size: .95rem; }
.who-btn .chev { width: 16px; height: 16px; flex: 0 0 auto; transition: transform .15s; }
.who-btn[aria-expanded="true"] .chev { transform: rotate(180deg); }
.user-menu { position: absolute; right: 0; top: calc(100% + .45rem); z-index: 30; width: max-content; min-width: 230px; max-width: calc(100vw - 1.5rem); padding: .4rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18); }
.user-menu[hidden] { display: none; }
.user-menu-head { display: grid; gap: .1rem; padding: .55rem .75rem .7rem; margin-bottom: .3rem; border-bottom: 1px solid var(--line); color: var(--ink); }
.um-item { display: flex; align-items: center; gap: .7rem; width: 100%; min-height: 44px; padding: .5rem .75rem; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer; }
.um-item:hover, .um-item:focus-visible { background: var(--hover); outline: none; }
.um-item.active { color: var(--red-d); }
.um-item svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--ink-2); }
.um-item.danger, .um-item.danger svg { color: var(--err); }
.user-menu form { margin-top: .3rem; padding-top: .3rem; border-top: 1px solid var(--line); }

.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 var(--field-line); border-radius: 8px; background: var(--field); min-height: 44px; }
select { max-width: 100%; text-overflow: ellipsis; }
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: var(--readonly); }
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 var(--field-line); background: var(--field); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.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: var(--card); 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: var(--surface-2); }
table.list th.r { text-align: right; }
table.list tfoot th { text-transform: none; font-size: .85rem; color: var(--ink); background: var(--surface-2); border-top: 2px solid var(--line); border-bottom: 0; }
table.list td { padding: .6rem .8rem; border-bottom: 1px solid var(--row-line); 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: var(--warn-bg); color: var(--warn); }
.badge-inviato { background: var(--ok-bg); 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: var(--ok-bg); color: var(--ok); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-err { background: var(--err-bg); color: var(--err); }

/* Piè di pagina del sito: resta in fondo anche nelle pagine corte */
body { display: flex; flex-direction: column; min-height: 100vh; }
body > main.wrap { flex: 1 0 auto; width: 100%; }
.site-footer { padding: 1rem; border-top: 1px solid var(--line); font-size: .82rem; color: var(--muted); line-height: 1.5; display: flex; justify-content: space-between; align-items: flex-end; gap: .5rem 1.5rem; flex-wrap: wrap; }
.footer-cliente { text-align: left; }
.licenza-piena td { color: var(--err); font-weight: 600; }
#licenza h2 .badge { vertical-align: middle; margin-left: .35rem; }
.badge-licenza { background: var(--red-l); color: var(--red-d); }
.backup-azioni { display: inline-flex; gap: .4rem; justify-content: flex-end; flex-wrap: wrap; margin: 0; }
.footer-credit { margin-left: auto; text-align: right; white-space: nowrap; }
.footer-credit a { color: inherit; font-weight: 600; }

/* Auth */
body.auth { display: grid; place-items: center; grid-template-rows: 1fr auto; min-height: 100vh; }
body.auth .site-footer { border-top: 0; }
.auth-card { width: min(420px, 100%); background: var(--card); 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; }
.auth-product-logo { display: block; width: min(220px, 60vw); height: auto; margin: 2rem auto -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: var(--paper-bg); 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.
   Resta sempre un foglio bianco, anche con il tema scuro. */
.doc { color-scheme: light; }

/* Tema chiaro/scuro */
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--card); color: var(--ink-2); cursor: pointer; flex: 0 0 auto; }
.theme-toggle:hover { background: var(--hover); color: var(--ink); }
.theme-toggle svg { width: 20px; height: 20px; }
.js-theme .ico-sun { display: none; }
:root[data-theme="dark"] .js-theme .ico-sun { display: block; }
:root[data-theme="dark"] .js-theme .ico-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .js-theme .ico-sun { display: block; }
  :root:not([data-theme="light"]) .js-theme .ico-moon { display: none; }
}
.theme-float { position: fixed; top: .75rem; right: .75rem; z-index: 20; }
/* Loghi e anteprime immagine: su fondo scuro restano su una base chiara per non perdere le scritte scure */
:root[data-theme="dark"] .auth-product-logo { background: #fff; padding: 10px 14px; border-radius: 12px; }
:root[data-theme="dark"] .brand img, :root[data-theme="dark"] .auth-logo { background: #fff; padding: 3px 6px; border-radius: 6px; box-sizing: content-box; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .auth-product-logo { background: #fff; padding: 10px 14px; border-radius: 12px; }
  :root:not([data-theme="light"]) .brand img, :root:not([data-theme="light"]) .auth-logo { background: #fff; padding: 3px 6px; border-radius: 6px; box-sizing: content-box; }
}

/* Menu a scomparsa (telefono e tablet) */
.nav-toggle { display: none; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; padding: 0 .8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.nav-toggle svg { width: 20px; height: 20px; }
.nav-toggle .ico-close, .topbar.open .nav-toggle .ico-menu { display: none; }
.topbar.open .nav-toggle .ico-close { display: block; }

/* Responsive */
/* Portatili: il nome resta nel sottomenu e le voci si stringono, così il menu sta su una riga */
@media (min-width: 1181px) and (max-width: 1400px) {
  .topbar { gap: 1rem; }
  .topbar nav { gap: .1rem; }
  .topbar nav a { padding: .55rem .55rem; gap: .35rem; }
  .who-btn .who-name { display: none; }
}
@media (max-width: 1180px) {
  .topbar { gap: .5rem; padding: .5rem 1rem; }
  .who { margin-left: auto; gap: .5rem; }
  .nav-toggle { display: inline-flex; }
  .topbar nav { display: none; order: 5; flex: 1 0 100%; flex-direction: column; gap: .15rem; padding: .25rem 0 .5rem; max-height: calc(100vh - 64px); overflow-y: auto; }
  .topbar.open nav { display: flex; }
  .topbar nav a { padding: .75rem .9rem; gap: .7rem; }
  .nav-ico { width: 20px; height: 20px; }
}
@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; }
  .who-btn .who-name { display: none; }
  .costs label, .tot { grid-template-columns: 1fr 110px; }
  /* 16px: sotto questa misura iPhone ingrandisce la pagina quando si tocca un campo */
  input, select, textarea { font-size: 16px; }
  .wrap { padding: 1rem .75rem 3rem; }
  .card { padding: 1rem; }
  h1 { font-size: 1.3rem; }
  .paper-wrap { padding: .5rem; }
}
@media (max-width: 400px) {
  .nav-toggle-txt { display: none; }
  .nav-toggle { padding: 0 .65rem; }
  .brand img { height: 28px; }

}

/* Tabelle a schede (telefono e tablet): ogni riga diventa un riquadro con etichetta e valore */
@media (max-width: 1100px) {
  table.list.stack thead { display: none; }
  table.list.stack, table.list.stack tbody, table.list.stack tfoot, table.list.stack tr { display: block; width: 100%; }
  table.list.stack tr { padding: .7rem .9rem; border-bottom: 1px solid var(--line); }
  table.list.stack tbody tr:last-child { border-bottom: 0; }
  table.list.stack tfoot tr { border-top: 2px solid var(--line); border-bottom: 0; background: var(--surface-2); }
  table.list.stack td, table.list.stack tfoot th { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .2rem 0; border: 0; background: none; text-align: right; white-space: normal; }
  table.list.stack td::before, table.list.stack tfoot th::before { content: attr(data-label); flex: 0 0 auto; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: left; }
  table.list.stack td:not([data-label])::before, table.list.stack tfoot th:not([data-label])::before { content: none; }
  table.list.stack td:first-child { display: block; text-align: left; font-size: 1rem; padding-bottom: .35rem; }
  table.list.stack td.actions { justify-content: flex-start; flex-wrap: wrap; gap: .4rem; padding-top: .6rem; }
  table.list.stack td.actions form.inline { flex-wrap: wrap; }
  table.list.stack td.empty { display: block; text-align: center; }
  table.list.stack tfoot th:empty { display: none; }
  table.list.stack td > input, table.list.stack td > select { flex: 0 1 11rem; }
  table.list.stack.tipi-table td:first-child { min-width: 0; width: auto; }
  table.list.stack.tipi-table td:first-child input { width: 100%; }
  table.list.stack.contratti-table td:first-child { min-width: 0; width: auto; }
  table.list.stack.contratti-table td:first-child input { width: 100%; }
}
/* Tablet: le voci della scheda stanno su due colonne */
@media (min-width: 761px) and (max-width: 1100px) {
  table.list.stack tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 2rem; }
  table.list.stack td:first-child, table.list.stack td.actions, table.list.stack td.empty { grid-column: 1 / -1; }
}

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #111; }
  .theme-toggle, .nav-toggle, .site-footer, .user-menu { display: none !important; }
  .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; min-width: 0; }
.logo-row form.js-confirm { flex: 0 0 auto; }

/* Favicon e piè di pagina (impostazioni) */
.favicon-previews { display: flex; align-items: flex-end; gap: .75rem; padding: .5rem; border: 1px dashed var(--line); border-radius: 8px; background: #fff; }
.fav-lg { width: 64px; height: 64px; object-fit: contain; }
.fav-sm { width: 16px; height: 16px; object-fit: contain; }
.footer-preview { padding: .75rem 1rem; border: 1px dashed var(--line); border-radius: 8px; text-align: center; font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }

/* 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 */
.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; }

/* Classificazioni: pagina di gestione e testi predefiniti nel rapportino */
.class-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .25rem 1rem; }
.class-nome { flex: 1 1 280px; }
.class-head .tiny { padding-bottom: 1.1rem; }
.class-card.disattivo input, .class-card.disattivo textarea { color: var(--muted); }
.class-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.preset { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.preset[hidden] { display: none; }
.preset-title { flex-basis: 100%; margin: 0 0 .1rem; font-size: .8rem; color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: .35rem; min-height: 36px; max-width: 100%; padding: .35rem .75rem; border: 1px dashed var(--field-line); border-radius: 99px; background: var(--field); color: var(--ink-2); font: inherit; font-size: .85rem; text-align: left; cursor: pointer; }
.chip::before { content: "+"; font-weight: 700; color: var(--red-d); }
.chip:hover { background: var(--hover); color: var(--ink); }
.chip[aria-pressed="true"] { border-style: solid; border-color: var(--red); background: var(--red-l); color: var(--red-d); }
.chip[aria-pressed="true"]::before { content: "✓"; }

/* 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); }
.tipi-table td .check { margin: 0; white-space: nowrap; }

/* Contratti monte ore (scheda cliente) */
.contratti-table input { margin: 0; min-width: 0; }
.contratti-table td:first-child { min-width: 220px; }
.contratti-table input.num { width: 5.5rem; text-align: right; }
.monte-info { margin: .35rem 0 0; padding: .55rem .75rem; border-radius: 8px; background: var(--ok-bg); color: var(--ok); font-size: .85rem; }
.monte-info.warn { background: var(--warn-bg); color: var(--warn); }

/* ================= Statistiche ================= */
.stats-filters { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1rem; }
.stats-filters label { flex: 1 1 150px; min-width: 0; margin: 0; font-size: .82rem; }
.stats-filters label select, .stats-filters label input { margin-top: .25rem; }
.stats-filters .filter-actions { display: flex; gap: .5rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: .2rem; }
.kpi-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.kpi-sub { font-size: .82rem; color: var(--ink-2); }
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.chart-card { margin: 0; min-width: 0; }
.chart-card.wide { grid-column: 1 / -1; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 340px; }
.chart-card details { margin-top: .75rem; font-size: .85rem; overflow-x: auto; }
.chart-card summary { cursor: pointer; color: var(--red-d); font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.table-scroll { overflow-x: auto; }
table.list.compact th, table.list.compact td { padding: .4rem .6rem; }
table.list.compact td.r, table.list.compact th.r { font-variant-numeric: tabular-nums; }
.empty-state { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
@media (max-width: 860px) {
  .charts { grid-template-columns: 1fr; }
  .chart-box { height: 230px; }
}

/* Azzera dati (impostazioni) */
.danger-zone { border-color: var(--err); }
.danger-zone h2 { color: var(--err); }
.azzera-list { border: 0; padding: 0; margin: .75rem 0 1rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: .6rem 1.5rem; }
.azzera-list legend { font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: .4rem; padding: 0; }
.azzera-list label.check { align-items: flex-start; gap: .5rem; }
.azzera-list label.check input { margin-top: .2rem; flex: none; }
.btn.danger-fill { background: var(--err); border-color: var(--err); color: var(--card); }

/* Altri tecnici nel rapportino (una riga per ogni unità tecnica oltre la prima) */
#altri-tecnici[hidden], #altri-tecnici .tec-row[hidden] { display: none; }
#ore-lavoro:empty { display: none; }

/* Etichette del rapportino (impostazioni) */
.et-sezione { border-top: 1px solid var(--line); padding: .6rem 0; }
.et-sezione summary { cursor: pointer; font-weight: 600; }
.et-sezione[open] summary { margin-bottom: .6rem; }

/* ---------- Blocco dopo l'invio, registro, avvisi contratti ---------- */
.badge-riaperto { background: var(--code-bg); color: var(--s1); }
.badge-fatturato { background: var(--ok-bg); color: var(--ok); }
.badge-dafatturare { background: var(--err-bg); color: var(--err); }
.badge-contratto { background: var(--code-bg); color: var(--s1); }
.fatt-check { gap: .4rem; min-height: 0; cursor: pointer; }
.fatt-check input { margin: 0; }
.lock-box { border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius); padding: .75rem; margin-bottom: 1rem; font-size: .875rem; }
.lock-box .riapri-form { margin-top: .5rem; }
.lock-box .riapri-form input { margin-bottom: .5rem; }
ul.storico { list-style: none; padding: 0; margin: 0; font-size: .8rem; }
ul.storico li { display: grid; gap: .1rem; padding: .5rem 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.registro-table .registro-dett { max-width: 38rem; overflow-wrap: anywhere; font-size: .85rem; }
.pager { display: flex; gap: .75rem; align-items: center; justify-content: center; margin: 1rem 0; }
.inline-label { display: flex; align-items: center; gap: .35rem; flex: 0 1 auto; margin: 0; white-space: nowrap; }
.filters .inline-label input { flex: 1 1 140px; }
.avvisi-box { border-left: 4px solid var(--warn); }
.avvisi-box h2 { margin-bottom: .5rem; }
.avvisi-box ul { list-style: none; padding: 0; margin: 0 0 .5rem; }
.avvisi-box li { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; padding: .45rem 0; border-top: 1px solid var(--row-line); }
.avvisi-box li > span { color: var(--warn); flex: 1 1 14rem; }
.avvisi-box .avviso-forte { color: var(--err); font-weight: 700; }

/* ---------- Esecuzione automatica (cron) in Impostazioni ---------- */
#cron .avviso-forte { color: var(--err); font-weight: 700; }
#cron .pre { white-space: pre-wrap; margin: .25rem 0 .5rem; }
#cron code { word-break: break-all; }
#cron details p { margin: .4rem 0; }
.copy-row { display: flex; gap: .5rem; align-items: center; }
.copy-row input { flex: 1 1 auto; min-width: 0; margin: 0; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.rinnovo-box { border: 1px dashed var(--field-line); border-radius: var(--radius); padding: .75rem 1rem; margin: 1rem 0; background: var(--surface-2); }
.auth-link { text-align: center; margin: 1rem 0 0; font-size: .875rem; }

/* ---------- Foto del rapportino ---------- */
.foto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem; margin-bottom: .75rem; }
.foto-grid:empty { display: none; }
.foto-item { margin: 0; border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; background: var(--surface-2); display: grid; gap: .4rem; align-content: start; }
.foto-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--code-bg); }
.foto-item input[type=text], .foto-item input:not([type]) { margin: 0; }
.foto-item.nuova { border-style: dashed; }
.foto-item .check { margin: 0; }
#foto-add { cursor: pointer; }
#foto-stato { margin-left: .5rem; }

/* ---------- Senza connessione ---------- */
.offline-bar { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 50; width: min(46rem, calc(100% - 2rem));
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--ok); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18); padding: .65rem .9rem; font-size: .875rem; }
.offline-bar.warn { border-left-color: var(--warn); }
.offline-bar .btn { margin-left: .25rem; }

/* ---------- Anteprime al passaggio del mouse (elenco rapportini) ---------- */
.js-pop { cursor: help; border-bottom: 1px dotted var(--muted); }
.js-pop:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; border-radius: 3px; }
.pop-foto-ico { border-bottom: 0; }
.pop { position: fixed; z-index: 60; width: min(380px, calc(100vw - 16px)); max-height: calc(100vh - 16px); overflow: auto;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 32px rgba(0, 0, 0, .2); padding: .75rem .9rem; font-size: .85rem; line-height: 1.4; }
.pop p { margin: 0 0 .4rem; overflow-wrap: anywhere; }
.pop-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; padding-bottom: .4rem; border-bottom: 1px solid var(--line); }
.pop-dl { display: grid; grid-template-columns: auto 1fr; gap: .2rem .75rem; margin: 0 0 .5rem; }
.pop-dl dt { color: var(--muted); }
.pop-dl dd { margin: 0; overflow-wrap: anywhere; }
.pop-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin-top: .5rem !important; }
.pop-kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem; margin-bottom: .5rem; }
.pop-kpi div { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: .35rem .5rem; display: grid; }
.pop-kpi b { font-size: 1rem; }
.pop-kpi span { font-size: .72rem; color: var(--muted); }
.pop-contratto { background: var(--ok-bg); color: var(--ok); border-radius: 8px; padding: .35rem .5rem; }
.pop.pop-foto { width: min(460px, calc(100vw - 16px)); }
.pop-galleria { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .5rem; }
.pop-galleria figure { margin: 0; }
.pop-galleria img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--code-bg); display: block; }
.pop-galleria figcaption { font-size: .75rem; color: var(--muted); margin-top: .15rem; overflow-wrap: anywhere; }

/* ---------- PC desktop (schermo largo, mouse): pagine con tabelle a tutta larghezza, senza scorrimento orizzontale ----------
   Telefoni e tablet (touch) restano come sono: tabelle a schede sotto i 1100px e larghezza massima 1280px. */
@media (min-width: 1101px) and (hover: hover) and (pointer: fine) {
  .wrap:has(table.list) { max-width: none; padding-left: 2rem; padding-right: 2rem; }
  .table-wrap { overflow-x: visible; }
  table.list td { overflow-wrap: break-word; }
  table.list td[data-label="E-mail"], table.list td.clip { overflow-wrap: anywhere; }  /* email e testi senza spazi vanno a capo solo se serve */
  .registro-table .registro-dett { max-width: none; }
}
/* PC con schermo fino a 1600px: i pulsanti delle righe vanno a capo invece di allargare la tabella */
@media (min-width: 1101px) and (max-width: 1599px) and (hover: hover) and (pointer: fine) {
  table.list td.actions { white-space: normal; }
  table.list td.actions:has(> :nth-child(4)) { min-width: 14rem; }  /* molti pulsanti: al massimo su due righe */
  table.list td.actions form.inline { margin: .15rem 0; }
  table.list td.actions > .btn { margin: .15rem 0; }
}

/* Posizione GPS di inizio/fine e trasferta */
.dt-gps label { margin-bottom: .35rem; }
.dt-gps .js-gps { margin-bottom: .25rem; }
.gps-info { margin: .15rem 0 .5rem; color: var(--ok); }
.gps-info.warn { color: var(--warn); }
.gps-info:empty { display: none; }
ul.gps-list { list-style: none; padding: 0; margin: 0 0 .75rem; font-size: .85rem; }
ul.gps-list li { padding: .45rem 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.gps-lontano { color: var(--warn); font-weight: 600; }
#trasferta-info { margin: -.2rem 0 .5rem; }
.km-row { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.km-row label { flex: 0 1 260px; margin-bottom: 0; }
.km-row .btn { margin-bottom: 1px; }
#km-stato.warn { color: var(--warn); }
details.percorso { margin: .75rem 0 0; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: 8px; }
details.percorso summary { cursor: pointer; font-size: .85rem; font-weight: 600; }
details.percorso[open] summary { margin-bottom: .5rem; }
#percorso-stato { margin: .4rem 0 0; }
#percorso-stato.warn { color: var(--warn); }
.partenza-form { display: flex; gap: .4rem; align-items: center; min-width: 260px; }
.partenza-form input { margin: 0; flex: 1; min-width: 0; }
.percorso-mappa { margin: .6rem 0 0; }
.percorso-mappa img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 6px; }
.percorso-mappa.vecchia img { opacity: .35; }

/* Checklist del tipo di intervento */
.checklist { display: grid; gap: .4rem; }
.ck-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(8rem, 14rem); gap: .4rem .75rem; align-items: center; padding: .35rem 0; border-top: 1px solid var(--line); }
.ck-row:first-child { border-top: 0; }
.ck-voce { font-weight: 500; }
.ck-esiti { display: inline-flex; gap: .25rem; }
.ck-esito { display: inline-flex; align-items: center; gap: .25rem; padding: .3rem .55rem; border: 1px solid var(--line); border-radius: 6px; font-size: .85rem; cursor: pointer; white-space: nowrap; }
.ck-esito input { margin: 0; }
.ck-esito.ck-ok:has(input:checked) { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.ck-esito.ck-ko:has(input:checked) { border-color: var(--err); background: var(--err-bg); color: var(--err); font-weight: 600; }
.ck-esito.ck-na:has(input:checked) { border-color: var(--muted, #888); font-weight: 600; }
.ck-nota { width: 100%; }
@media (max-width: 640px) {
  .ck-row { grid-template-columns: 1fr; }
}
.checklist-row td { padding-top: 0; }
.checklist-row details summary { cursor: pointer; font-size: .85rem; color: var(--muted, #666); }
.checklist-row textarea { width: 100%; margin: .4rem 0 .2rem; }
