/* Grafici e Statistiche - stile */
:root {
  --sfondo: #f4f6f9; --scheda: #ffffff; --testo: #1b2430; --tenue: #64748b; --bordo: #e2e8f0;
  --primario: #2563eb; --primario-testo: #ffffff; --primario-chiaro: #dbeafe;
  --buono: #15803d; --cattivo: #b91c1c; --attenzione-sf: #fff7e6; --attenzione-bd: #f59e0b;
  --ok-sf: #ecfdf3; --ok-bd: #16a34a; --errore-sf: #fef2f2; --errore-bd: #dc2626;
  --lato: #0b0f17; --lato-testo: #cbd5e1; --lato-attivo: #2563eb; --lato-hover: #1a2233;
  --alto: #ffffff; --ombra: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .05);
  --c0: #eef2ff; --c1: #dbe4ff; --c2: #c3d2fe; --c3: #a5b8fc; --c4: #8499f7; --c5: #6a7ff0; --c6: #5165e3; --c7: #3d4fcf; --c8: #2d3cb5; --c9: #1e2a8f;
  --alto-barra: 56px; --largo-lato: 270px;
  font-size: 16px;
}
:root[data-carattere="s"] { font-size: 14px; }
:root[data-carattere="l"] { font-size: 18px; }
:root[data-carattere="xl"] { font-size: 20px; }
:root[data-tema="scuro"] {
  --sfondo: #0e131b; --scheda: #161d28; --testo: #e5e9f0; --tenue: #94a3b8; --bordo: #263042;
  --primario: #3b82f6; --primario-chiaro: #1e3a5f;
  --buono: #4ade80; --cattivo: #f87171; --attenzione-sf: #2b2210; --ok-sf: #0f2a1b; --errore-sf: #2d1414;
  --lato: #05070b; --lato-hover: #121a28; --alto: #111824; --ombra: 0 1px 2px rgba(0, 0, 0, .4);
  --c0: #18213a; --c1: #1d2a4f; --c2: #223465; --c3: #283f7c; --c4: #2f4b94; --c5: #3858ac; --c6: #4468c4; --c7: #5a7fd8; --c8: #7a9ae6; --c9: #a3bbf2;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--sfondo); color: var(--testo); font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.45; }
a { color: var(--primario); }
h1 { font-size: 1.55rem; margin: 0 0 .3rem; }
h2 { font-size: 1.2rem; margin: 0 0 .6rem; }
h3 { font-size: 1.02rem; margin: 0 0 .5rem; }
code, pre { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; }
pre { background: var(--sfondo); border: 1px solid var(--bordo); padding: .6rem .8rem; border-radius: 6px; overflow-x: auto; }
.tenue { color: var(--tenue); }
.piccolo { font-size: .85rem; }
.nascosto, [hidden] { display: none !important; }
.in-linea { display: inline; }
.spazio-sopra { margin-top: 1.2rem; }
.info { color: var(--tenue); cursor: help; font-size: .85em; }

/* --- barra in alto ------------------------------------------------ */
.barra-alta { position: fixed; top: 0; left: 0; right: 0; height: var(--alto-barra); z-index: 30; display: flex; align-items: center; gap: .8rem;
  background: var(--alto); border-bottom: 1px solid var(--bordo); padding: 0 .9rem; box-shadow: var(--ombra); }
.marchio { font-weight: 700; color: var(--testo); text-decoration: none; white-space: nowrap; font-size: 1.05rem; }
.marchio .logo { color: var(--primario); font-size: 1.25rem; }
.tasti-alti { display: flex; gap: .2rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tasti-alti a { padding: .45rem .75rem; border-radius: 8px; text-decoration: none; color: var(--testo); white-space: nowrap; font-weight: 500; }
.tasti-alti a:hover { background: var(--primario-chiaro); }
.tasti-alti a.attivo { background: var(--primario); color: var(--primario-testo); }
.comandi { display: flex; align-items: center; gap: .25rem; margin-left: auto; }
.senza-menu .comandi { margin-left: auto; }
.tasto-icona { background: transparent; border: 1px solid var(--bordo); color: var(--testo); border-radius: 8px; padding: .3rem .5rem; cursor: pointer;
  font-size: .9rem; text-decoration: none; line-height: 1.2; }
.tasto-icona:hover { background: var(--primario-chiaro); }
.caratteri { display: inline-flex; gap: 2px; }
.apri-lato { display: none; background: none; border: 0; font-size: 1.4rem; color: var(--testo); cursor: pointer; }

/* --- colonna a sinistra ------------------------------------------- */
.lato { position: fixed; top: var(--alto-barra); bottom: 0; left: 0; width: var(--largo-lato); background: var(--lato); color: var(--lato-testo);
  overflow-y: auto; padding: 1rem .8rem 2rem; z-index: 20; }
.scelta-attivita label { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: #94a3b8; margin-bottom: .35rem; }
.scelta-attivita select { width: 100%; padding: .55rem; border-radius: 8px; background: #111827; color: #fff; border: 1px solid #334155; font-size: .95rem; }
.menu-lato { margin-top: 1rem; }
.menu-lato details { border-bottom: 1px solid #1f2937; }
.menu-lato summary { cursor: pointer; padding: .6rem .35rem; font-weight: 600; color: #e2e8f0; list-style: none; display: flex; justify-content: space-between; }
.menu-lato summary::after { content: "▸"; transition: transform .15s; color: #64748b; }
.menu-lato details[open] summary::after { transform: rotate(90deg); }
.menu-lato summary::-webkit-details-marker { display: none; }
.menu-lato ul { list-style: none; margin: 0 0 .5rem; padding: 0; }
.menu-lato li a { display: block; padding: .38rem .6rem .38rem 1rem; color: var(--lato-testo); text-decoration: none; border-radius: 6px; font-size: .93rem; }
.menu-lato li a:hover { background: var(--lato-hover); color: #fff; }
.menu-lato li a.attivo { background: var(--lato-attivo); color: #fff; }
.link-dati { display: block; margin-top: 1rem; color: #93c5fd; text-decoration: none; font-size: .9rem; }
.aiuto-lato { font-size: .9rem; color: #94a3b8; }
.versione { font-size: .75rem; color: #475569; margin-top: 2rem; }

/* --- contenuto ---------------------------------------------------- */
.contenuto { padding: calc(var(--alto-barra) + 1.2rem) 1.4rem 3rem; max-width: 1600px; }
.con-menu .contenuto { margin-left: var(--largo-lato); }
.senza-menu .contenuto { margin: 0 auto; }
.intestazione { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.briciole { color: var(--tenue); font-size: .85rem; margin-bottom: .2rem; }
.spiegazione { color: var(--tenue); margin: .2rem 0 0; max-width: 70ch; }
.azioni-intestazione { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.scheda { background: var(--scheda); border: 1px solid var(--bordo); border-radius: 12px; padding: 1rem 1.1rem; box-shadow: var(--ombra); margin-bottom: 1rem; min-width: 0; }
.scheda.vuota { text-align: center; padding: 2rem; }
.riga-pulsanti { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; justify-content: flex-start; }
.scheda.vuota .riga-pulsanti { justify-content: center; }
.due-colonne { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 1rem; }

/* pulsanti e moduli */
.pulsante { display: inline-block; background: var(--primario); color: var(--primario-testo); border: 1px solid var(--primario); border-radius: 8px;
  padding: .5rem .95rem; font-size: .95rem; cursor: pointer; text-decoration: none; font-weight: 500; }
.pulsante:hover { filter: brightness(1.08); }
.pulsante.secondario { background: transparent; color: var(--primario); }
.pulsante.pericolo { background: var(--cattivo); border-color: var(--cattivo); }
.pulsante.piccolo, .tasto-piccolo { padding: .25rem .55rem; font-size: .82rem; }
.pulsante.largo { width: 100%; margin-top: .6rem; }
.pulsante[disabled] { opacity: .5; cursor: not-allowed; }
.tasto-piccolo { background: transparent; border: 1px solid var(--bordo); color: var(--testo); border-radius: 6px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.tasto-piccolo:hover { background: var(--primario-chiaro); }
label { display: block; font-size: .9rem; margin-bottom: .6rem; }
input, select { font: inherit; color: var(--testo); background: var(--scheda); border: 1px solid var(--bordo); border-radius: 7px; padding: .42rem .55rem; }
label > input:not([type=checkbox]):not([type=file]), label > select { display: block; width: 100%; margin-top: .2rem; }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primario); outline-offset: 1px; }
.box-accesso { max-width: 440px; margin: 2rem auto; }
.riga-modulo { display: flex; gap: .8rem; flex-wrap: wrap; align-items: flex-end; }
.riga-modulo label { margin: 0; min-width: 180px; }
.link-invito { width: min(100%, 640px); margin: .4rem 0; }

/* filtri sopra le analisi */
.filtri { display: flex; flex-wrap: wrap; gap: .7rem 1rem; align-items: flex-end; background: var(--scheda); border: 1px solid var(--bordo); border-radius: 12px;
  padding: .7rem .9rem; margin-bottom: 1rem; }
.filtri label { margin: 0; font-size: .82rem; color: var(--tenue); }
.filtri select, .filtri input { display: block; margin-top: .15rem; color: var(--testo); min-width: 9rem; }
.date-scelte { display: inline-flex; gap: .5rem; align-items: flex-end; }
.periodo-testo { font-size: .85rem; margin-left: auto; }

/* avvisi */
.avviso { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .8rem; border-left: 4px solid var(--primario); background: var(--primario-chiaro); }
.avviso.ok { background: var(--ok-sf); border-color: var(--ok-bd); }
.avviso.errore { background: var(--errore-sf); border-color: var(--errore-bd); }
.avviso.attenzione { background: var(--attenzione-sf); border-color: var(--attenzione-bd); }
.nota { color: var(--tenue); font-size: .88rem; }

/* riquadri numerici */
.riquadri { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 185px), 1fr)); gap: .75rem; margin-bottom: 1rem; }
.riquadro { background: var(--scheda); border: 1px solid var(--bordo); border-radius: 12px; padding: .75rem .9rem; box-shadow: var(--ombra); min-width: 0; }
.riquadro-nome { color: var(--tenue); font-size: .82rem; }
.riquadro-valore { font-size: 1.45rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.riquadro-delta { font-size: .8rem; margin-top: .15rem; font-weight: 600; }
.riquadro-delta.buono { color: var(--buono); }
.riquadro-delta.cattivo { color: var(--cattivo); }

/* grafici */
.griglia-grafici { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 1rem; margin-bottom: 1rem; }
.grafico { margin: 0; }
.grafico.largo { grid-column: 1 / -1; }
.grafico figcaption { display: flex; justify-content: space-between; gap: .5rem; align-items: center; font-weight: 600; margin-bottom: .5rem; }
.tela { position: relative; width: 100%; }

/* tabelle */
.scorri { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tabella { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabella th, .tabella td { padding: .42rem .55rem; border-bottom: 1px solid var(--bordo); text-align: left; vertical-align: top; }
.tabella th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--tenue); white-space: nowrap; position: sticky; top: 0; background: var(--scheda); }
.tabella td.num, .tabella th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabella tbody tr:hover { background: var(--primario-chiaro); }
.tabella.piccola { font-size: .8rem; }
.ordinabile th[data-ordina] { cursor: pointer; }
.ordinabile th.su::after { content: " ▲"; }
.ordinabile th.giu::after { content: " ▼"; }
.testa-tabella { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; margin-bottom: .5rem; }
.testa-tabella h3 { margin: 0; }
.cerca-tabella { margin-left: auto; min-width: 200px; }

/* mappa di calore */
.calore { border-collapse: separate; border-spacing: 2px; font-size: .72rem; }
.calore th { font-weight: 500; color: var(--tenue); padding: 2px 4px; white-space: nowrap; text-align: right; }
.calore thead th { text-align: center; }
.calore td { min-width: 34px; height: 28px; text-align: center; border-radius: 4px; color: var(--testo); font-variant-numeric: tabular-nums; white-space: nowrap; padding: 0 3px; }
.l0 { background: var(--c0); } .l1 { background: var(--c1); } .l2 { background: var(--c2); } .l3 { background: var(--c3); } .l4 { background: var(--c4); }
.l5 { background: var(--c5); color: #fff !important; } .l6 { background: var(--c6); color: #fff !important; } .l7 { background: var(--c7); color: #fff !important; }
.l8 { background: var(--c8); color: #fff !important; } .l9 { background: var(--c9); color: #fff !important; }
:root[data-tema="scuro"] .l7, :root[data-tema="scuro"] .l8, :root[data-tema="scuro"] .l9 { color: #0b1020 !important; }
.legenda-calore { display: flex; align-items: center; gap: 2px; font-size: .75rem; color: var(--tenue); margin-top: .4rem; }
.legenda-calore i { display: inline-block; width: 18px; height: 10px; border-radius: 2px; }
.legenda-calore span { margin: 0 .3rem; }

/* home */
.carte-attivita { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 1rem; }
.carta.scelta { border-color: var(--primario); box-shadow: 0 0 0 2px var(--primario-chiaro); }
.carta.spenta { opacity: .55; }
.stato-dati { padding-left: 0; list-style: none; font-size: .9rem; }
.stato-dati li { margin-bottom: .3rem; }

/* dati */
.carica { display: flex; gap: .7rem; flex-wrap: wrap; align-items: center; }
.scegli-file { margin: 0; }
.scegli-file input { display: block; margin-top: .2rem; max-width: 100%; }
.griglia-campi { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: .2rem 1rem; }
.griglia-campi label.obbligatorio { font-weight: 600; }
.dettagli-campi { margin-top: .8rem; }
.dettagli-campi summary { cursor: pointer; color: var(--primario); }
.svuota input { width: 9rem; }
.guida li { margin-bottom: .35rem; }
.indice a { white-space: nowrap; }
.azioni-riga { white-space: nowrap; }

.largo-box { max-width: 560px; }
.qr { text-align: center; margin: .6rem 0; }
.qr img { background: #fff; padding: 6px; border-radius: 8px; }
.chiave { word-break: break-all; }
input.codice { font-size: 1.4rem; letter-spacing: .25em; text-align: center; font-variant-numeric: tabular-nums; }
.codici { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem; padding: 0; list-style: none; font-size: 1.15rem; }
.codici code { display: block; padding: .4rem; text-align: center; border: 1px dashed var(--bordo); border-radius: 6px; }
.riga-errore td { color: var(--cattivo); }

/* assistente */
.tasto-chat { position: fixed; right: 18px; bottom: 18px; z-index: 40; background: var(--primario); color: #fff; border: 0; border-radius: 999px;
  padding: .65rem 1rem; font-size: .95rem; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); cursor: pointer; }
.chat { position: fixed; right: 18px; bottom: 74px; z-index: 41; width: min(380px, calc(100vw - 24px)); height: min(520px, calc(100vh - 140px));
  background: var(--scheda); border: 1px solid var(--bordo); border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .3); display: flex; flex-direction: column; }
.chat[hidden] { display: none; }
.chat header { display: flex; justify-content: space-between; align-items: center; padding: .6rem .8rem; border-bottom: 1px solid var(--bordo); }
.chat-messaggi { flex: 1; overflow-y: auto; padding: .7rem; display: flex; flex-direction: column; gap: .5rem; font-size: .9rem; }
.msg { padding: .5rem .7rem; border-radius: 10px; max-width: 92%; overflow-wrap: anywhere; }
.msg.bot { background: var(--sfondo); align-self: flex-start; }
.msg.io { background: var(--primario); color: #fff; align-self: flex-end; }
.msg.proposte { display: flex; flex-wrap: wrap; gap: .3rem; padding: 0; }
.msg.proposte .tasto-piccolo { white-space: normal; text-align: left; }
.chat-form { display: flex; gap: .4rem; padding: .6rem; border-top: 1px solid var(--bordo); }
.chat-form input { flex: 1; min-width: 0; }
.chat-guida { font-size: .8rem; padding: 0 .8rem .6rem; }

/* giro guidato */
.tour { position: fixed; inset: 0; z-index: 60; background: rgba(5, 8, 15, .6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.tour-box { background: var(--scheda); border-radius: 16px; max-width: 520px; width: 100%; padding: 1.6rem 1.5rem 1.2rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); }
.tour-icona { font-size: 2.4rem; }
.tour-passo h2 { margin-top: .4rem; }
.tour-punti { display: flex; gap: 6px; justify-content: center; margin: 1rem 0 .8rem; }
.tour-punti i { width: 8px; height: 8px; border-radius: 50%; background: var(--bordo); }
.tour-punti i.attivo { background: var(--primario); width: 22px; border-radius: 4px; }
.tour-tasti { justify-content: flex-end; }
.tour-tasti [data-tour="salta"] { margin-right: auto; }
.faq details { border-bottom: 1px solid var(--bordo); padding: .45rem 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { margin: .4rem 0 .2rem; }

/* telefono */
@media (max-width: 900px) {
  .apri-lato { display: inline-block; }
  .lato { transform: translateX(-100%); transition: transform .2s; width: min(86vw, 320px); box-shadow: 4px 0 24px rgba(0, 0, 0, .35); }
  body.lato-aperto .lato { transform: none; }
  .con-menu .contenuto { margin-left: 0; }
  .contenuto { padding-left: 1rem; padding-right: 1rem; }
  .tasti-alti { display: none; }
  body.lato-aperto .tasti-alti { display: none; }
  .nome-utente, .caratteri [data-carattere="m"] { display: none; }
  .marchio { font-size: .95rem; }
  .comandi { gap: .15rem; }
  .tasto-icona { padding: .25rem .4rem; }
  .riquadro-valore { font-size: 1.2rem; }
  .periodo-testo { margin-left: 0; }
  .cerca-tabella { margin-left: 0; width: 100%; }
}
.menu-mobile { display: none; }
@media (max-width: 900px) {
  .menu-mobile { display: block; margin-bottom: 1rem; border-bottom: 1px solid #1f2937; padding-bottom: .6rem; }
  .menu-mobile a { display: block; color: #e2e8f0; text-decoration: none; padding: .35rem .3rem; }
}

@media (max-width: 480px) {
  .nome-marchio { display: none; }
}

/* stampa */
@media print {
  .tasto-chat, .chat, .tour,
  .barra-alta, .lato, .filtri, .azioni-intestazione, .tasto-piccolo, .cerca-tabella, .apri-lato, .link-dati, noscript { display: none !important; }
  .con-menu .contenuto { margin: 0; padding: 0; }
  body { background: #fff; color: #000; }
  .scheda, .riquadro { box-shadow: none; break-inside: avoid; }
  .grafico { break-inside: avoid; }
  .sezione-report { break-before: page; }
  .sezione-report:first-of-type { break-before: auto; }
}
