/* =============================================================================
   stile.css — ASPETTO GRAFICO DI TUTTA L'APP
   -----------------------------------------------------------------------------
   CSS = regole "selettore { proprietà: valore; }".
   Il selettore dice A QUALI elementi HTML si applica la regola:
     .classe   → elementi con class="classe"
     #id       → l'elemento con id="id"
     tag       → tutti gli elementi di quel tipo (es. button)
   ============================================================================= */


/* -----------------------------------------------------------------------------
   1. VARIABILI (come i #define in C: si cambia un colore qui e cambia ovunque)
   ----------------------------------------------------------------------------- */
:root {
  --colore-primario: #1f5f7a;        /* blu petrolio, tono "clinico" */
  --colore-primario-scuro: #164558;
  --colore-primario-chiaro: #e7f1f5;
  --colore-testo: #1d2a33;
  --colore-testo-tenue: #5b6b76;
  --colore-sfondo: #f5f7f8;
  --colore-superficie: #ffffff;
  --colore-bordo: #dde3e7;

  --colore-ok: #1e7b4f;          --sfondo-ok: #e4f4ec;
  --colore-attenzione: #9a5b00;  --sfondo-attenzione: #fdf1dc;
  --colore-pericolo: #b42318;    --sfondo-pericolo: #fde8e6;

  --raggio: 10px;
  --ombra: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --carattere: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}


/* -----------------------------------------------------------------------------
   2. BASE
   ----------------------------------------------------------------------------- */
* { box-sizing: border-box; }   /* larghezze che includono bordo e padding */

body {
  margin: 0;
  font-family: var(--carattere);
  font-size: 15px;
  line-height: 1.5;
  color: var(--colore-testo);
  background: var(--colore-sfondo);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
a { color: var(--colore-primario); }
small { color: var(--colore-testo-tenue); }

.contenitore { max-width: 1200px; margin: 0 auto; padding: 1.25rem; }
.nascosto { display: none !important; }


/* -----------------------------------------------------------------------------
   3. INTESTAZIONE E MENU
   ----------------------------------------------------------------------------- */
#intestazione {
  background: var(--colore-primario);
  color: #fff;
  position: sticky; top: 0; z-index: 10;   /* resta in alto scorrendo */
}
.intestazione-contenuto {
  max-width: 1200px; margin: 0 auto; padding: .6rem 1.25rem;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
}
.logo { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.logo small { color: rgba(255,255,255,.7); font-weight: 400; font-size: .8rem; }
.menu { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.menu-voce {
  color: rgba(255,255,255,.85); text-decoration: none;
  padding: .35rem .75rem; border-radius: 6px;
}
.menu-voce:hover { background: rgba(255,255,255,.12); }
.menu-voce.attiva { background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }
.menu-voce.disabilitata { opacity: .45; cursor: not-allowed; }
.utente { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.utente small { display: block; color: rgba(255,255,255,.7); font-size: .75rem; }
/* Nome utente cliccabile (apre "Il mio account") */
.utente-nome {
  background: none; border: none; color: #fff; font: inherit; text-align: right;
  cursor: pointer; padding: .2rem .4rem; border-radius: 6px;
}
.utente-nome:hover { background: rgba(255,255,255,.12); }
.solo-mobile { display: none; }

/* Barra della lunghezza della password */
.barra-lunghezza { height: 6px; background: var(--colore-bordo); border-radius: 999px; margin-top: .45rem; overflow: hidden; }
.barra-riempimento { height: 100%; width: 0; border-radius: 999px; transition: width .15s, background-color .15s; }
.barra-riempimento.scarsa { background: var(--colore-pericolo); }
.barra-riempimento.buona  { background: #e0a100; }
.barra-riempimento.ottima { background: var(--colore-ok); }

/* Regole della password, spuntate mentre si scrive */
.regole-password { list-style: none; padding: 0; margin: .4rem 0; font-size: .85rem; }
.regola-ok { color: var(--colore-ok); }
.regola-no { color: var(--colore-testo-tenue); }

/* Riquadro di istruzioni apribile (<details>) */
.aiuto-esteso { background: var(--colore-primario-chiaro); border-radius: 8px; padding: .6rem .9rem; margin-bottom: 1rem; font-size: .92rem; }
.aiuto-esteso summary { cursor: pointer; font-weight: 600; color: var(--colore-primario); }
.aiuto-esteso ol { margin: .6rem 0 .2rem; padding-left: 1.3rem; }


/* -----------------------------------------------------------------------------
   4. PULSANTI E CAMPI
   ----------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  font: inherit; font-weight: 600;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; background: var(--colore-primario); color: #fff;
}
.btn:hover { background: var(--colore-primario-scuro); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-secondario { background: var(--colore-superficie); color: var(--colore-testo); border-color: var(--colore-bordo); }
.btn-secondario:hover { background: var(--colore-primario-chiaro); }
.btn-pericolo { background: var(--colore-pericolo); }
.btn-piccolo { padding: .3rem .65rem; font-size: .85rem; }
#intestazione .btn-secondario { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; font: inherit; padding: .55rem .7rem;
  border: 1px solid var(--colore-bordo); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--colore-primario); outline-offset: 1px; border-color: transparent;
}
/* Campi disattivati: niente cursore di scrittura, aspetto "spento" */
input:disabled, select:disabled, textarea:disabled {
  cursor: not-allowed; background: #f3f5f6; color: var(--colore-testo-tenue);
}
.campo { margin-bottom: .9rem; }
.campi-riga { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.aiuto { font-size: .8rem; color: var(--colore-testo-tenue); margin-top: .2rem; }


/* -----------------------------------------------------------------------------
   5. SCHEDE, RIEPILOGHI, TABELLE
   ----------------------------------------------------------------------------- */
.scheda {
  background: var(--colore-superficie); border: 1px solid var(--colore-bordo);
  border-radius: var(--raggio); box-shadow: var(--ombra); padding: 1.25rem;
}
.riepilogo { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.riepilogo .scheda { cursor: pointer; padding: 1rem 1.25rem; }
.riepilogo .scheda:hover { border-color: var(--colore-primario); }
.riepilogo .numero { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.riepilogo .etichetta { color: var(--colore-testo-tenue); font-size: .9rem; }
.numero.pericolo { color: var(--colore-pericolo); }
.numero.attenzione { color: var(--colore-attenzione); }

.barra-strumenti { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.barra-strumenti .campo { margin: 0; min-width: 180px; }
.barra-strumenti .spazio { flex: 1; }

.filtri { display: flex; gap: .4rem; flex-wrap: wrap; }
.filtro {
  font: inherit; font-size: .85rem; padding: .35rem .8rem; border-radius: 999px;
  border: 1px solid var(--colore-bordo); background: #fff; cursor: pointer;
}
.filtro.attivo { background: var(--colore-primario); color: #fff; border-color: var(--colore-primario); }

.tabella-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--colore-bordo); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--colore-testo-tenue); background: #fafbfc; }
td.numero-cella, th.numero-cella { text-align: right; font-variant-numeric: tabular-nums; }
td.azioni { white-space: nowrap; text-align: right; }
tr:hover td { background: #fafcfd; }
.vuoto { text-align: center; color: var(--colore-testo-tenue); padding: 2rem; }

.etichetta-stato {
  display: inline-block; font-size: .78rem; font-weight: 600;
  padding: .15rem .55rem; border-radius: 999px; white-space: nowrap;
}
.stato-ok         { background: var(--sfondo-ok); color: var(--colore-ok); }
.stato-attenzione { background: var(--sfondo-attenzione); color: var(--colore-attenzione); }
.stato-pericolo   { background: var(--sfondo-pericolo); color: var(--colore-pericolo); }
.stato-info       { background: var(--colore-primario-chiaro); color: var(--colore-primario); }
.stato-neutro     { background: #eef1f3; color: var(--colore-testo-tenue); }

/* Pallino numerico accanto a una voce di menu o a una scheda */
.contatore {
  display: inline-block; min-width: 1.4em; padding: 0 .4em; margin-left: .25rem;
  border-radius: 999px; background: #f5a524; color: #1d2a33;
  font-size: .75rem; font-weight: 700; text-align: center; line-height: 1.4;
}

/* Schede (tab) sopra un elenco */
.schede-tab { display: flex; gap: .25rem; border-bottom: 1px solid var(--colore-bordo); margin-bottom: 1rem; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 600; background: none; border: none; cursor: pointer;
  padding: .6rem .9rem; color: var(--colore-testo-tenue); border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab.attiva { color: var(--colore-primario); border-bottom-color: var(--colore-primario); }

/* Elenco di richieste come schede */
.elenco-richieste { display: grid; gap: .75rem; }
/* Bacheca */
.avviso-importante { border-left: 4px solid var(--colore-pericolo); }
.avviso-nuovo { box-shadow: 0 0 0 2px #f5a524 inset, var(--ombra); }
.testo-avviso { white-space: pre-line; margin: .5rem 0; }   /* rispetta gli "a capo" */
.titolo-gruppo { font-size: 1rem; margin: .75rem 0 0; color: var(--colore-testo-tenue); text-transform: uppercase; letter-spacing: .04em; }
.titolo-gruppo:first-child { margin-top: 0; }
.titolo-gruppo.oggi { color: var(--colore-primario); }
/* Finestra di conferma: un po' più stretta delle altre */
dialog.dialogo-conferma { width: min(460px, calc(100vw - 2rem)); }
.richiesta { padding: 1rem 1.1rem; }
.richiesta-testa { display: flex; justify-content: space-between; gap: .75rem; flex-wrap: wrap; align-items: start; }
.richiesta-testa h3 { margin: 0; font-size: 1.05rem; }
.richiesta-testa > div:last-child { margin-left: auto; text-align: right; }
.richiesta-dati { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .35rem 1rem; margin: .6rem 0; font-size: .92rem; }
.richiesta-dati dt { font-size: .75rem; color: var(--colore-testo-tenue); text-transform: uppercase; letter-spacing: .03em; }
.richiesta-dati dd { margin: 0 0 .2rem; }
.richiesta-azioni { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.evidenza { background: var(--colore-primario-chiaro); border-radius: 8px; padding: .5rem .7rem; margin: .4rem 0; font-size: .92rem; }

/* Caselle di spunta con testo accanto */
.spunta { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; margin-bottom: .6rem; cursor: pointer; }
.spunta input { width: auto; margin-top: .25rem; }

/* Risultati di ricerca in un menu sotto un campo */
.risultati-ricerca { border: 1px solid var(--colore-bordo); border-radius: 8px; margin-top: .3rem; max-height: 220px; overflow-y: auto; }
.risultati-ricerca button {
  display: block; width: 100%; text-align: left; font: inherit; background: #fff;
  border: none; border-bottom: 1px solid var(--colore-bordo); padding: .5rem .7rem; cursor: pointer;
}
.risultati-ricerca button:hover { background: var(--colore-primario-chiaro); }
.risultati-ricerca button:last-child { border-bottom: none; }
.paziente-scelto { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }


/* -----------------------------------------------------------------------------
   6. FINESTRE DI DIALOGO (<dialog>)
   ----------------------------------------------------------------------------- */
dialog {
  border: none; border-radius: var(--raggio); padding: 0;
  width: min(560px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
dialog.largo { width: min(860px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
.dialogo-testa { padding: 1rem 1.25rem; border-bottom: 1px solid var(--colore-bordo); display: flex; justify-content: space-between; align-items: center; }
.dialogo-testa h2 { margin: 0; }
.dialogo-corpo { padding: 1.25rem; overflow-y: auto; }
.dialogo-piede { padding: .9rem 1.25rem; border-top: 1px solid var(--colore-bordo); display: flex; justify-content: flex-end; gap: .5rem; background: #fafbfc; }
.chiudi { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--colore-testo-tenue); line-height: 1; }


/* -----------------------------------------------------------------------------
   7. LOGIN E PAGINE SEMPLICI
   ----------------------------------------------------------------------------- */
.pagina-centrata { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.pagina-centrata .scheda { width: min(420px, 100%); }
.pagina-centrata h1 { color: var(--colore-primario); }
.messaggio-errore { background: var(--sfondo-pericolo); color: var(--colore-pericolo); padding: .6rem .8rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.messaggio-ok { background: var(--sfondo-ok); color: var(--colore-ok); padding: .6rem .8rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.avviso-finestra { font-weight: 500; }
.messaggio-info { background: var(--colore-primario-chiaro); padding: .6rem .8rem; border-radius: 8px; margin-bottom: 1rem; font-size: .9rem; }
.controllo { display: flex; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--colore-bordo); }
.controllo:last-child { border-bottom: none; }


/* -----------------------------------------------------------------------------
   8. AVVISI A COMPARSA
   ----------------------------------------------------------------------------- */
#avvisi { position: fixed; bottom: 1rem; right: 1rem; display: grid; gap: .5rem; z-index: 100; }
.avviso { padding: .7rem 1rem; border-radius: 8px; color: #fff; box-shadow: var(--ombra); max-width: 360px; font-weight: 500; }
.avviso-ok { background: var(--colore-ok); }
.avviso-errore { background: var(--colore-pericolo); }


/* -----------------------------------------------------------------------------
   9. SCHERMI PICCOLI (telefono) — "@media" = applica solo se la condizione è vera
   ----------------------------------------------------------------------------- */
@media (max-width: 700px) {
  .contenitore { padding: .9rem; }
  .campi-riga { grid-template-columns: 1fr; }
  .colonna-opzionale { display: none; }   /* nasconde colonne meno importanti */

  /* Intestazione compatta: logo e Esci sulla prima riga, menu scorrevole sotto */
  .intestazione-contenuto { gap: .4rem 1rem; padding: .5rem .9rem; }
  .utente { margin-left: auto; }
  .solo-desktop { display: none; }
  .solo-mobile { display: inline; font-size: 1.2rem; }
  .menu { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .menu-voce { white-space: nowrap; }

  .riepilogo { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .riepilogo .scheda { padding: .7rem; }
  .riepilogo .numero { font-size: 1.5rem; }
  .riepilogo .etichetta { font-size: .75rem; line-height: 1.25; }
  .barra-strumenti .campo { min-width: 0; flex: 1 1 100%; }

  /* Tabelle "a schede": ogni riga diventa un riquadro, ogni cella una riga
     con la sua etichetta (presa dall'attributo data-etichetta del <td>). */
  .tabella-schede thead { display: none; }
  .tabella-schede tr { display: block; padding: .7rem 0; border-bottom: 1px solid var(--colore-bordo); }
  .tabella-schede td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: none; padding: .15rem 0; text-align: right; }
  .tabella-schede td::before { content: attr(data-etichetta); font-size: .78rem; color: var(--colore-testo-tenue); text-align: left; }
  .tabella-schede td:first-child { display: block; text-align: left; padding-bottom: .3rem; }
  .tabella-schede td:first-child::before { content: none; }
  .tabella-schede td.azioni { justify-content: flex-end; gap: .4rem; padding-top: .5rem; }
  .tabella-schede td.azioni::before { content: none; }
  .tabella-schede td.vuoto { display: block; text-align: center; }
  .tabella-schede tr:hover td { background: none; }
}

/* -----------------------------------------------------------------------------
   10. STAMPA (lista riordino): nasconde menu e pulsanti
   ----------------------------------------------------------------------------- */
@media print {
  body * { visibility: hidden; }
  #stampa-area, #stampa-area * { visibility: visible; }
  #stampa-area { position: absolute; inset: 0; padding: 1rem; }
  .non-stampare { display: none !important; }
  .solo-stampa { display: block !important; }
}


/* -----------------------------------------------------------------------------
   11. AREA PAZIENTE (pagine in paziente/) ed elementi piccoli condivisi
   ----------------------------------------------------------------------------- */
.contenitore-stretto { max-width: 720px; margin-left: auto; margin-right: auto; }
.btn-largo { width: 100%; justify-content: center; }
.btn-link { background: none; border: none; padding: 0; color: var(--colore-primario); text-decoration: underline; cursor: pointer; font: inherit; }
.btn-link:disabled { color: var(--colore-testo-tenue); text-decoration: none; cursor: default; }
.azioni-secondarie { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 1rem 0 0; font-size: .9rem; }
.campo-codice { font-size: 1.6rem; letter-spacing: .4em; text-align: center; }
.elenco-semplice { list-style: none; padding: 0; margin: .5rem 0 0; }
.elenco-semplice li { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; padding: .4rem 0; border-bottom: 1px solid var(--colore-bordo); }
.elenco-semplice li:last-child { border-bottom: none; }
.elenco-semplice li .btn { margin-left: auto; }

.saluto { margin-bottom: 1.25rem; }
.titolo-sezione { margin: 1.5rem 0 .75rem; }
.archivio { margin-top: 1rem; }
.archivio summary { cursor: pointer; font-weight: 600; }
.archivio .elenco-richieste { margin-top: .75rem; }
.data-grande { font-size: 1.15rem; font-weight: 700; color: var(--colore-primario-scuro); }
.nota-clinica { background: var(--colore-primario-chiaro); border-radius: 8px; padding: .5rem .7rem; margin: .5rem 0 0; white-space: pre-line; }
.familiare { margin-bottom: .75rem; }
.familiare-testa { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; flex-wrap: wrap; }
.nota-piede { margin: 1.5rem 0 2rem; text-align: center; }
.riquadro-famiglia { margin-top: 1rem; padding: .75rem 1rem; border: 1px solid var(--colore-bordo); border-radius: 8px; }
.riquadro-famiglia h3 { margin: 0 0 .25rem; font-size: 1rem; }
.famiglia-testa { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .25rem; }
.famiglia-testa input { flex: 1 1 14rem; font-weight: 600; }
.famiglia-testa h3 { margin: 0; }
.famiglia-azioni { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.famiglia-azioni input { flex: 1 1 16rem; }
.interruttore-vista { display: flex; gap: .25rem; align-self: end; }
.etichetta-cliccabile { border: none; cursor: pointer; font: inherit; font-size: .8rem; }
.etichetta-cliccabile:hover { text-decoration: underline; }
.titolo-deleghe { margin: .9rem 0 .25rem; font-size: .95rem; }
