:root {
  --bg: #f2f7f8; --paper: #ffffff; --paper-2: #f7fafb; --ink: #12303b; --muted: #557079;
  --pool: #0e7c86; --pool-ink: #ffffff; --deep: #0b4f6c; --line: #d5e4e8;
  --ok: #1f7a4d; --ok-bg: #e3f4ea; --warn: #9a5b07; --warn-bg: #fdf0d9; --bad: #b02a2a; --bad-bg: #fbe5e5;
  --info: #0b5f8a; --info-bg: #e2f0f8; --neutral-bg: #eaf0f2;
  --radius: 10px; --shadow: 0 1px 2px rgba(18, 48, 59, .06), 0 4px 14px rgba(18, 48, 59, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1c22; --paper: #12262d; --paper-2: #0f2127; --ink: #e4f0f2; --muted: #9db6bd;
    --pool: #3fb3bd; --pool-ink: #06262b; --deep: #7cc4dd; --line: #23414a;
    --ok: #6fd39e; --ok-bg: #133a29; --warn: #f0b660; --warn-bg: #3a2b12; --bad: #ff8f8f; --bad-bg: #3d1a1a;
    --info: #7cc4dd; --info-bg: #12333f; --neutral-bg: #1a323a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1c22; --paper: #12262d; --paper-2: #0f2127; --ink: #e4f0f2; --muted: #9db6bd;
  --pool: #3fb3bd; --pool-ink: #06262b; --deep: #7cc4dd; --line: #23414a;
  --ok: #6fd39e; --ok-bg: #133a29; --warn: #f0b660; --warn-bg: #3a2b12; --bad: #ff8f8f; --bad-bg: #3d1a1a;
  --info: #7cc4dd; --info-bg: #12333f; --neutral-bg: #1a323a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; }
a { color: var(--pool); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; color: var(--deep); }
h2 { font-size: 1.1rem; margin: 0 0 10px; color: var(--deep); }
h3 { font-size: .95rem; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

#app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand small { display: block; color: var(--muted); font-size: .72rem; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--pool); color: var(--pool-ink); display: grid; place-items: center; font-size: 1.3rem; font-weight: 700; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.role-switch { display: flex; align-items: center; gap: 6px; font-size: .85rem; }
.sidebar { background: var(--paper); border-right: 1px solid var(--line); padding: 12px 8px; overflow-y: auto; position: sticky; top: 56px; height: calc(100vh - 56px); }
.sidebar a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink); font-size: .92rem; }
.sidebar a:hover { background: var(--neutral-bg); text-decoration: none; }
.sidebar a.active { background: var(--pool); color: var(--pool-ink); }
.sidebar .sep { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 4px; }
.sidebar .count { font-size: .72rem; background: var(--bad); color: #fff; border-radius: 99px; padding: 1px 7px; }
#view { padding: 20px 24px 60px; min-width: 0; outline: none; }
.only-mobile { display: none; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 14px; }
.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)); }
.span2 { grid-column: span 2; }
.stack > * + * { margin-top: 14px; }

.kpi { display: block; color: var(--ink); }
.kpi:hover { text-decoration: none; border-color: var(--pool); }
.kpi .v { font-size: 1.8rem; font-weight: 700; color: var(--deep); font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85rem; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: var(--neutral-bg); color: var(--ink); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.pool { background: var(--pool); color: var(--pool-ink); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--pool); background: var(--pool); color: var(--pool-ink); padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--pool); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { background: none; border: 0; font-size: 1.3rem; color: var(--ink); cursor: pointer; }
.linkbtn { background: none; border: 0; color: var(--pool); cursor: pointer; padding: 0; font: inherit; }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--paper-2); }
.tbl tr.dim td { opacity: .6; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tfoot td { font-weight: 600; }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .92rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.missing { color: var(--warn); font-style: italic; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field > span { font-size: .82rem; color: var(--muted); font-weight: 600; }
.field.req > span::after { content: " *"; color: var(--bad); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pool); outline-offset: -1px; }
input[type="checkbox"], input[type="radio"] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.frow { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 12px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 2px; margin: 0 0 12px; }
legend { font-weight: 600; font-size: .85rem; color: var(--deep); padding: 0 4px; }
input.out { border-color: var(--warn); background: var(--warn-bg); }
input.bad { border-color: var(--bad); background: var(--bad-bg); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--pool); border-color: var(--pool); font-weight: 600; }

.alert { border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: .9rem; border: 1px solid transparent; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

.empty { color: var(--muted); padding: 14px; text-align: center; font-size: .9rem; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 12px 10px; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--pool); }

.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(200px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.kcol { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; min-height: 120px; }
.kcol h3 { font-size: .8rem; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
.kcard { display: block; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; color: var(--ink); font-size: .88rem; }
.kcard:hover { border-color: var(--pool); text-decoration: none; }

/* Modale */
.modal-back { position: fixed; inset: 0; background: rgba(6, 20, 26, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--paper); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }

#toast-root { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; font-size: .9rem; }

/* App telefono */
.phone-wrap { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.phone { width: 390px; max-width: 100%; min-height: 720px; background: var(--paper); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.phone-top { background: var(--pool); color: var(--pool-ink); padding: 14px 16px; }
.phone-top small { opacity: .85; display: block; }
.phone-body { padding: 12px; flex: 1; overflow-y: auto; }
.phone-nav { display: flex; border-top: 1px solid var(--line); }
.phone-nav button { flex: 1; background: none; border: 0; padding: 10px 4px; font: inherit; font-size: .78rem; color: var(--muted); cursor: pointer; }
.phone-nav button.active { color: var(--pool); font-weight: 700; }
.pcard { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--paper); display: block; color: var(--ink); width: 100%; text-align: left; font: inherit; }
button.pcard { cursor: pointer; }
.pcard:hover { border-color: var(--pool); text-decoration: none; }
.phone-side { flex: 1; min-width: 260px; max-width: 460px; }
.sig { border: 1px dashed var(--muted); border-radius: 8px; height: 90px; display: grid; place-items: center; color: var(--muted); cursor: pointer; }
.sig.done { border-style: solid; border-color: var(--ok); color: var(--ok); font-family: "Segoe Script", cursive; font-size: 1.2rem; }

/* Documento stampabile */
.doc { background: #fff; color: #12303b; max-width: 820px; margin: 0 auto; padding: 32px; border: 1px solid var(--line); }
.doc h1 { color: #0b4f6c; }
.doc .tbl th, .doc .tbl td { border-color: #d5e4e8; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .sidebar { position: fixed; left: 0; top: 56px; width: 240px; transform: translateX(-100%); transition: transform .2s; z-index: 30; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  #view { padding: 16px; }
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .role-switch .muted, .brand small { display: none; }
  .topbar-right .btn { display: none; }
  .phone { border-radius: 14px; min-height: 0; }
}
@media print {
  .topbar, .sidebar, .no-print, #toast-root { display: none !important; }
  #app { display: block; }
  #view { padding: 0; }
  body { background: #fff; }
  .doc { border: 0; padding: 0; }
}

/* Colonna principale + colonna laterale (preventivo, collaudo) */
.split { grid-template-columns: minmax(0, 1fr) 310px; align-items: start; }
.sticky { position: sticky; top: 72px; }
@media (max-width: 1000px) { .split { grid-template-columns: minmax(0, 1fr); } .sticky { position: static; } }

/* Vista annuale del piano di manutenzione (MAN-08): tipo = simbolo, stato = simbolo + colore */
.calp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 14px; }
.calp-h { font-weight: 600; font-size: .85rem; color: var(--deep); margin-bottom: 4px; text-transform: capitalize; }
.calp-g { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.calp-w { font-size: .66rem; color: var(--muted); text-align: center; text-transform: uppercase; }
.calp-d { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 26px; border-radius: 5px; font-size: .72rem; color: var(--ink); line-height: 1.05; }
.calp-d i { font-style: normal; }
.calp-d b { font-size: .68rem; }
.calp-d.has { border: 1px solid var(--line); font-weight: 600; }
a.calp-d.has:hover { outline: 2px solid var(--pool); text-decoration: none; }
.calp-d.dom { color: var(--muted); }
.calp-d.fest { color: var(--bad); text-decoration: underline dotted; }
.calp-d.sv { background-image: repeating-linear-gradient(135deg, transparent 0 4px, var(--neutral-bg) 4px 7px); }
.calp-d.oggi { outline: 2px solid var(--pool); }
.calp-d.pian, .calp-chip.pian { background-color: var(--info-bg); }
.calp-d.ese, .calp-chip.ese { background-color: var(--ok-bg); color: var(--ok); }
.calp-d.spo, .calp-chip.spo { background-color: var(--warn-bg); color: var(--warn); }
.calp-d.ann, .calp-chip.ann { background-color: var(--neutral-bg); color: var(--muted); text-decoration: line-through; }
.calp-d.non, .calp-chip.non { background-color: var(--bad-bg); color: var(--bad); }
.calp-leg { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-bottom: 10px; }
.calp-leg .sep { width: 1px; height: 16px; background: var(--line); }
.calp-chip { border-radius: 99px; padding: 1px 8px; border: 1px solid var(--line); }
.calp-chip.sv { background-image: repeating-linear-gradient(135deg, transparent 0 4px, var(--neutral-bg) 4px 7px); }
.calp-chip.fest { color: var(--bad); text-decoration: underline dotted; }

/* Barra di avanzamento del cantiere nell'app cliente (CLA-14) */
.cla-bar { display: flex; gap: 3px; }
.cla-bar span { flex: 1; height: 10px; border-radius: 3px; background: var(--neutral-bg); border: 1px solid var(--line); }
.cla-bar span.ok { background: var(--ok); border-color: var(--ok); }
.cla-bar span.run { background: var(--info-bg); border-color: var(--info); }
.fase-row { padding: 8px 0; border-top: 1px solid var(--line); }
.fase-row:first-child { border-top: 0; }

/* Kit nel preventivo (LIS-07) */
.tbl tr.kit-testa td { background: var(--neutral-bg); border-top: 2px solid var(--line); }
.tbl tr.kit-riga td:first-child { padding-left: 18px; }
.tbl tr.kit-sub td { font-size: .9em; color: var(--muted); }

/* Giro del tecnico (APT-01) */
.giro-riga { display: flex; gap: 6px; align-items: stretch; margin-bottom: 4px; }
.giro-riga.dragging { opacity: .5; }
.giro-riga .pcard { margin-bottom: 2px; }
.giro-ord { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.giro-ord .btn { padding: 2px 8px; }
.giro-tratto { margin: 2px 0 2px 44px; }

/* Ricerca dell'elenco (NF-05) */
.cerca { margin: 4px 0 10px; max-width: 360px; }
.cerca input { width: 100%; }

/* Calendario unico */
.cal-legenda { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.cal-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 99px; padding: 3px 10px; font: inherit; font-size: .8rem; cursor: pointer; }
.cal-chip span { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.cal-chip.off { opacity: .45; text-decoration: line-through; }
.cal-griglia { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-gg { font-size: .78rem; color: var(--muted); font-weight: 600; text-align: center; text-transform: uppercase; }
.cal-cella { border: 1px solid var(--line); border-radius: 8px; min-height: 104px; padding: 4px; background: var(--paper); cursor: pointer; min-width: 0; overflow: hidden; }
.cal-griglia.settimana .cal-cella { min-height: 360px; }
.cal-cella:hover { border-color: var(--pool); }
.cal-cella:focus-visible { outline: 2px solid var(--pool); }
.cal-cella.oggi { outline: 2px solid var(--pool); outline-offset: -1px; }
.cal-cella.fuori { opacity: .55; }
.cal-cella.festa { background: var(--paper-2); }
.cal-num { font-size: .82rem; font-weight: 700; margin-bottom: 2px; }
.cal-num .muted { font-weight: 400; font-size: .72rem; }
.cal-voce { display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid; border-radius: 5px; padding: 2px 5px; margin-top: 2px; font: inherit; font-size: .74rem; color: var(--ink); cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal-voce:hover { filter: brightness(.96); }
.cal-voce.fatto { opacity: .55; text-decoration: line-through; }
.cal-griglia.settimana .cal-voce, .cal-giorno .cal-voce { white-space: normal; font-size: .82rem; padding: 4px 7px; }
.cal-sotto { display: block; color: var(--muted); font-size: .92em; }
.cal-giorno .cal-voce { margin-top: 6px; }
@media (max-width: 760px) {
  .cal-griglia { gap: 2px; }
  .cal-cella { min-height: 64px; padding: 2px; }
  .cal-griglia.mese .cal-voce { font-size: 0; height: 6px; padding: 0; margin-top: 2px; border-left-width: 0; }
  .cal-griglia.settimana { grid-template-columns: minmax(0, 1fr); }
  .cal-griglia.settimana .cal-gg { display: none; }
  .cal-griglia.settimana .cal-cella { min-height: 0; }
}

/* Pulsante Indietro, sempre visibile nella barra in alto */
.topbar .indietro { flex-shrink: 0; }
@media (max-width: 760px) { .topbar .indietro span { display: none; } .topbar .indietro { padding: 4px 10px; font-size: 1rem; } }

/* Pannello "Regole della sezione" */
.card.regole-sez { border-color: var(--pool); margin-bottom: 14px; }
.card.regole-sez + .card { margin-top: 0; }

/* Negozio e servizi dell'app cliente */
.phone-nav button { font-size: .7rem; padding: 10px 2px; }
.neg-card { display: flex; gap: 10px; align-items: flex-start; }
.neg-foto { width: 54px; height: 54px; flex-shrink: 0; border-radius: 10px; background: var(--paper-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 1.5rem; }
.neg-foto.sm { width: 40px; height: 40px; font-size: 1.1rem; }
.neg-galleria { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.neg-valori { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 6px; }
.neg-valori > div { display: flex; flex-direction: column; align-items: center; padding: 6px; border-radius: 8px; background: var(--paper-2); }
.neg-valori strong { font-size: 1.2rem; }
.neg-pay { text-align: center; padding: 8px 0; }

/* Accesso simulato (blocco 7) */
.esci { display: none; }
body.con-accesso .esci { display: inline-flex; }
body.bloccato .sidebar, body.bloccato .topbar-right, body.bloccato #btn-indietro { display: none !important; }
body.bloccato #app { grid-template-columns: 1fr; }

/* ================= Facilità d'uso ================= */
.solo-ufficio { display: none; }
body.ruolo-ufficio .solo-ufficio { display: block; }
body.ruolo-ufficio details.solo-ufficio { display: inline-block; }

/* Menu raggruppato */
.nav-gruppo { margin-bottom: 2px; }
.nav-testa { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 8px; background: none; border: 0; cursor: pointer;
  font: inherit; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 12px 10px 4px; text-align: left; }
.nav-testa:hover { color: var(--ink); }
.nav-testa .freccia { font-size: .8rem; }
.nav-gruppo.chiuso .nav-voci { display: none; }
.nav-gruppo.chiuso .nav-testa { padding-bottom: 8px; }

/* Ricerca unica */
.cerca-globale { position: relative; flex: 1; max-width: 460px; min-width: 120px; margin-left: 8px; }
.cerca-globale input { width: 100%; padding: 7px 34px 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); color: var(--ink); font: inherit; font-size: .9rem; }
.cerca-globale input:focus { outline: 2px solid var(--pool); outline-offset: 0; background: var(--paper); }
.cerca-tasto { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: .72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; pointer-events: none; }
.cerca-globale input:focus + .cerca-tasto { display: none; }
.cerca-risultati { position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 320px; max-height: 70vh; overflow-y: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 40; padding: 4px; }
.cerca-voce { display: flex; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px; cursor: pointer; color: var(--ink); font: inherit; }
.cerca-voce:hover, .cerca-voce.sel { background: var(--neutral-bg); }
.cerca-tipo { flex: 0 0 110px; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding-top: 2px; }
.cerca-testo { display: flex; flex-direction: column; min-width: 0; }
.cerca-testo small { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cerca-vuoto { padding: 12px; color: var(--muted); font-size: .9rem; }

/* Menu a tendina: + Nuovo e Altro */
details.tendina { position: relative; }
details.tendina > summary { list-style: none; cursor: pointer; }
details.tendina > summary::-webkit-details-marker { display: none; }
details.tendina .menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 40; padding: 4px; display: flex; flex-direction: column; }
.nuovo-menu .menu { left: 0; right: auto; }
.nuovo-menu .menu button, .altro-menu .menu > * { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 8px 10px; cursor: pointer; color: var(--ink); font: inherit; }
.nuovo-menu .menu button small { color: var(--muted); font-size: .78rem; }
.nuovo-menu .menu button:hover, .altro-menu .menu > *:hover { background: var(--neutral-bg); text-decoration: none; filter: none; }
.altro-menu .menu > .btn { border: 0; color: var(--ink); background: none; }
.page-head .actions { align-items: center; }

/* Spiegazioni sotto il titolo: una riga, poi "Come funziona" */
.page-head .sub.sub-lunga:not(.aperta) { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; max-width: 860px; }
.page-head .come-funziona { margin-top: 2px; }

/* Righe degli elenchi cliccabili */
.tbl tbody tr:has(a[href^="#/"]) { cursor: pointer; }
.tbl tbody tr:has(a[href^="#/"]):hover td { background: var(--paper-2); }

/* Schede delle impostazioni: vanno a capo invece di scorrere */
.tabs { flex-wrap: wrap; }

/* Guida rapida */
.guida { padding-left: 18px; margin: 0 0 10px; }
.guida li { margin-bottom: 8px; }
kbd { font: inherit; font-size: .8em; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--paper-2); }
.guida-btn { font-weight: 700; min-width: 30px; justify-content: center; }

/* Barre delle app con icone */
.phone-nav button .ico { display: block; font-size: 1.15rem; line-height: 1.2; }
.phone-nav button { position: relative; }
.phone-nav .pallino { position: absolute; top: 4px; left: 50%; margin-left: 6px; background: var(--bad); color: #fff; border-radius: 99px; font-size: .65rem; padding: 0 5px; line-height: 1.4; }

@media (max-width: 1100px) { .cerca-tasto { display: none; } }
@media (max-width: 760px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .brand span:not(.brand-mark) { display: none; }
  .cerca-globale { margin-left: 0; min-width: 0; }
  .cerca-globale input { padding-right: 8px; }
  .cerca-risultati { position: fixed; left: 8px; right: 8px; top: 60px; min-width: 0; }
  .cerca-tipo { flex-basis: 80px; }
  body.ruolo-ufficio .nuovo-menu > summary { padding: 4px 8px; }
  .topbar-right .guida-btn { display: inline-flex; }
}

/* Telefono: ricerca dietro la lente, numeri del cruscotto due per riga */
.cerca-lente { display: none; }
@media (max-width: 760px) {
  .cerca-globale { flex: 0 0 auto; max-width: none; }
  .cerca-globale input, .cerca-globale .cerca-tasto { display: none; }
  .cerca-lente { display: inline-flex; background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); font-size: 1rem; padding: 3px 8px; cursor: pointer; }
  .cerca-globale.aperta { position: fixed; left: 0; right: 0; top: 0; height: 56px; z-index: 60; background: var(--paper); display: flex; align-items: center; gap: 8px; padding: 0 8px; border-bottom: 1px solid var(--line); }
  .cerca-globale.aperta input { display: block; flex: 1; }
  .cerca-globale.aperta .cerca-lente::before { content: "✕"; }
  .cerca-globale.aperta .cerca-lente span { display: none; }
  .role-switch select { max-width: 112px; }
  .grid.g4:has(> .kpi), .grid.g3:has(> .kpi) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; margin: 0 !important; }
  .kpi .v { font-size: 1.35rem; }
  .kpi .l { font-size: .78rem; }
}

/* Nuovo lead: come si continua */
.lead-scelte { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.lead-scelta { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper-2); color: var(--ink); font: inherit; cursor: pointer; }
.lead-scelta span { color: var(--muted); font-size: .84rem; line-height: 1.3; }
.lead-scelta:hover, .lead-scelta:focus-visible { border-color: var(--pool); outline: none; }
.lead-scelta.principale { background: var(--pool); border-color: var(--pool); color: var(--pool-ink); }
.lead-scelta.principale span { color: var(--pool-ink); opacity: .9; }
.lead-scelta.principale:hover { filter: brightness(1.07); }
@media (max-width: 760px) { .lead-scelte { grid-template-columns: minmax(0, 1fr); } }

/* Chi lo deve fare: una o più persone */
.chi-lo-fa { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px 12px; margin: 0 0 12px; min-width: 0; }
.chi-lo-fa legend { font-weight: 600; font-size: .9rem; padding: 0 4px; }
.chi-lo-fa legend small { font-weight: 400; color: var(--muted); }
.chi-obbligo { color: var(--bad); }
.chi-lo-fa.errore { border-color: var(--bad); box-shadow: 0 0 0 1px var(--bad); }
.chi-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chi-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px 5px 8px; border: 1px solid var(--line); border-radius: 99px; background: var(--paper-2); color: var(--ink); cursor: pointer; font-size: .88rem; }
.chi-chip input { width: auto; margin: 0; accent-color: var(--pool-ink); }
.chi-chip:hover { border-color: var(--pool); }
.chi-chip:has(input:checked) { background: var(--pool); border-color: var(--pool); color: var(--pool-ink); font-weight: 600; }
.chi-chip:has(input:focus-visible) { outline: 2px solid var(--pool); outline-offset: 2px; }
.chi-resp { margin: 10px 0 0; max-width: 320px; }
.chi-resp[hidden] { display: none; }

/* Spia dell'archivio dei dati */
.spia-archivio { background: none; border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font: inherit; font-size: .78rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.spia-archivio.ok { color: var(--ok); border-color: var(--ok); }
.spia-archivio.bad { color: #fff; background: var(--bad); border-color: var(--bad); font-weight: 600; }
.spia-archivio.warn { color: var(--warn); border-color: var(--warn); font-weight: 600; }
@media (max-width: 760px) { .spia-archivio:not(.bad):not(.warn) { display: none; } }

/* Informativa privacy */
.privacy-testo { white-space: pre-wrap; font-size: .86rem; line-height: 1.5; background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
.privacy-scorri { max-height: 46vh; overflow-y: auto; }
@media print { .privacy-testo { border: 0; padding: 0; background: none; } }

/* Firma col dito */
.pad-firma canvas { display: block; width: 100%; height: auto; aspect-ratio: 640 / 220; background: #fff; border: 2px dashed var(--line); border-radius: 10px; touch-action: none; cursor: crosshair; }
.pad-firma.firmato canvas { border-style: solid; border-color: var(--ok); }
.pad-riga { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; gap: 8px; }
.firma-riepilogo { background: var(--paper-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; max-height: 32vh; overflow-y: auto; }
.firma-vista { margin-top: 6px; }
.firma-vista img { display: block; max-width: 260px; width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 2px; }
.firma-vista.piccola img { max-width: 170px; }
@media print { .firma-vista img { border: 0; } }

/* Documenti firmati */
.doc-firmato { display: flex !important; gap: 10px; align-items: center; text-decoration: none !important; color: inherit; }
.doc-firmato img { width: 84px; height: 34px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 5px; flex: none; }
.ok-txt { color: var(--ok, #1f7a4d); font-weight: 600; }
.bad-txt { color: var(--bad, #b3261e); font-weight: 600; }
.doc-firmati-griglia h3 { margin: 12px 0 6px; }
.doc-firmati-griglia h3:first-child { margin-top: 0; }
@media (min-width: 900px) { .doc-firmati-griglia { columns: 2; column-gap: 14px; } .doc-firmati-griglia .pcard, .doc-firmati-griglia h3 { break-inside: avoid; } }

/* ---------- App online per clienti e tecnici (pagina del portale) ---------- */
html.online #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
html.online .sidebar, html.online .role-switch, html.online #spia-archivio, html.online [data-act="resetDemo"], html.online .cerca-globale,
html.online .nuovo-menu, html.online .guida-btn, html.online [data-act="toggleNav"], html.online .phone-side { display: none !important; }
html.online .topbar { height: 48px; padding: 0 12px; }
html.online .topbar .brand small { display: none; }
html.online #view { padding: 0; }
html.online .phone-wrap { display: block; }
html.online .phone { width: 100%; max-width: 640px; margin: 0 auto; min-height: calc(100dvh - 48px); border: 0; border-radius: 0; box-shadow: none; }
html.online .phone-body { padding-bottom: 76px; }
html.online .phone-nav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 640px; background: var(--paper); z-index: 15; padding-bottom: env(safe-area-inset-bottom); }
html.online #view > .card, html.online #view > .doc, html.online #view > .actions { margin: 12px; }
@media (min-width: 700px) { html.online .phone { border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }
body.ao-attivo #app { display: none; }
#accesso-online { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--bg); }
#accesso-online .ao-box { width: 100%; max-width: 380px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 28px 22px; text-align: center; box-shadow: var(--shadow); }
#accesso-online .ao-logo { width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 14px; background: var(--pool); color: var(--pool-ink); font-size: 2rem; line-height: 56px; font-weight: 700; }
#accesso-online .ao-az { color: var(--muted); font-size: .9rem; }
#accesso-online h1 { font-size: 1.35rem; margin: 6px 0 8px; }
#accesso-online form { display: grid; gap: 10px; margin: 14px 0 8px; }
#accesso-online input { font-size: 1.4rem; letter-spacing: .3em; text-align: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); width: 100%; }
#accesso-online .btn { justify-content: center; padding: 12px; font-size: 1rem; }
#accesso-online .ao-err { color: var(--bad); min-height: 1.2em; font-size: .9rem; }
#online-attesa { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.18); display: flex; align-items: center; justify-content: center; }
#online-attesa > div { background: var(--paper); color: var(--ink); padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); }
