/* ============================================================
   Componenti unici: bottoni, campi, tabella, finestra, menu, pannello,
   etichette, barre, stati. Un componente ha una sola forma, in tutti i temi.
   ============================================================ */

/* --- Bottoni ------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--bersaglio); padding: 0 var(--s3);
  border: 1px solid transparent; border-radius: var(--r2); background: none; cursor: pointer; font-weight: 550; white-space: nowrap; text-decoration: none;
  transition: background-color .1s, border-color .1s;
}
.btn .ic { width: 16px; height: 16px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primario { background: var(--azione); color: var(--azione-testo); }
.btn-primario:hover:not(:disabled) { background: var(--azione-sopra); }
.btn-secondario { background: var(--superficie); border-color: var(--bordo-forte); color: var(--testo); }
.btn-secondario:hover:not(:disabled) { background: var(--passaggio); }
.btn-tenue { color: var(--testo-2); }
.btn-tenue:hover:not(:disabled) { background: var(--passaggio); color: var(--testo); }
.btn-pericolo { background: var(--rosso-tenue); color: var(--rosso); border-color: var(--rosso); }
.btn-pericolo:hover:not(:disabled) { background: var(--rosso); color: var(--superficie); }
.btn-piccolo { height: 28px; padding: 0 var(--s2); font-size: var(--t-piccolo); }
.btn-icona {
  position: relative; display: inline-grid; place-items: center; width: var(--bersaglio); height: var(--bersaglio); padding: 0; flex: none;
  border: 0; border-radius: var(--r2); background: none; color: var(--testo-2); cursor: pointer; text-decoration: none;
}
.btn-icona:hover { background: var(--passaggio); color: var(--testo); }
.riga-bottoni { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }

.segmenti { display: inline-flex; border: 1px solid var(--bordo-forte); border-radius: var(--r2); overflow: hidden; }
.segmenti button { height: 30px; padding: 0 var(--s3); border: 0; background: var(--superficie); color: var(--testo-2); cursor: pointer; font-weight: 600; font-size: var(--t-piccolo); }
.segmenti button + button { border-left: 1px solid var(--bordo-forte); }
.segmenti button.attivo { background: var(--neutro-tenue); color: var(--testo); box-shadow: inset 0 -2px 0 var(--marchio); }

/* --- Campi --------------------------------------------------------------- */
:where(input:not([type=checkbox], [type=radio], [type=color], [type=file]), select, textarea) {
  width: 100%; min-height: var(--bersaglio); padding: 5px var(--s2); border: 1px solid var(--bordo-forte); border-radius: var(--r2);
  background: var(--superficie); color: var(--testo);
}
textarea { resize: vertical; }
select { cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--testo-3); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--fuoco); outline-offset: 0; border-color: transparent; }
input[type=color] { width: 56px; height: var(--bersaglio); padding: 2px; border: 1px solid var(--bordo-forte); border-radius: var(--r2); background: var(--superficie); cursor: pointer; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--azione); margin: 0; flex: none; }
.campo { display: grid; gap: var(--s1); min-width: 0; }
.campo-et { font-size: var(--t-piccolo); font-weight: 600; color: var(--testo-2); }
.campo-et em { font-style: normal; color: var(--rosso); }
.campo-aiuto { font-size: var(--t-piccolo); color: var(--testo-3); }
.spunte { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); }
.spunta { display: inline-flex; align-items: center; gap: 6px; min-height: var(--bersaglio); cursor: pointer; }
.modulo { display: grid; gap: var(--s3); }
.modulo-stretto { max-width: 480px; }
.modulo-due, .griglia-campi { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--s3); }
.griglia-campi .largo { grid-column: 1 / -1; }
.modulo-piede { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s1); }
.filtri { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.filtri input[type=search] { flex: 1 1 220px; width: auto; min-width: 160px; }
.filtri select { flex: 0 1 180px; width: auto; }

.menzioni { position: fixed; z-index: 60; width: 260px; max-height: 240px; overflow: auto; background: var(--superficie); border: 1px solid var(--bordo-forte); border-radius: var(--r2); box-shadow: var(--ombra-finestra); }
.menzioni.dentro { position: absolute; top: 100%; left: 0; margin-top: var(--s1); }
.menzioni-voce { display: flex; align-items: center; gap: var(--s2); padding: 6px var(--s2); cursor: pointer; }
.menzioni-voce small { color: var(--testo-3); margin-left: auto; }
.menzioni-voce:hover, .menzioni-voce.attiva { background: var(--passaggio); }
.assegnatari { display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; }
.assegnatario { display: inline-flex; align-items: center; gap: var(--s1); height: 28px; padding: 0 var(--s1) 0 2px; border: 1px solid var(--bordo); border-radius: 14px; background: var(--superficie-2); }
.assegnatario button { display: grid; place-items: center; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--testo-3); cursor: pointer; }
.assegnatario button:hover { background: var(--passaggio); color: var(--testo); }
.assegnatario .ic { width: 14px; height: 14px; }
.assegnatari-cerca { position: relative; flex: 1 1 160px; min-width: 140px; }
.allegati { display: grid; gap: 2px; margin-top: var(--s2); }
.allegati li { display: flex; align-items: center; gap: var(--s2); min-height: 32px; }
.allegati a, .allegati span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.allegati small { color: var(--testo-3); }

/* --- Avatar -------------------------------------------------------------- */
.avatar {
  display: inline-grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 50%; overflow: hidden;
  background: var(--neutro-tenue); color: var(--testo); font-size: var(--t-micro); font-weight: 650;
}
.avatar[style] { color: var(--azione-testo); }
.avatar[style].su-chiaro { color: var(--scuro-marchio); }
.avatar { box-shadow: 0 0 0 1px var(--bordo-forte); }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.piccolo { width: 22px; height: 22px; font-size: 10px; }
.avatar.grande { width: 64px; height: 64px; font-size: 20px; }
.avatar-gruppo { display: inline-flex; align-items: center; gap: 2px; }

/* --- Etichette ----------------------------------------------------------- */
.etichetta { display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 6px; border-radius: var(--r1); font-size: var(--t-micro); font-weight: 600; white-space: nowrap; background: var(--neutro-tenue); color: var(--testo-2); }
.etichetta .ic { width: 13px; height: 13px; }
.tono-ok.etichetta { background: var(--ok-tenue); color: var(--ok); }
.tono-ambra.etichetta { background: var(--ambra-tenue); color: var(--ambra); }
.tono-rosso.etichetta { background: var(--rosso-tenue); color: var(--rosso); }
.tono-info.etichetta { background: var(--info-tenue); color: var(--info); }
.tono-testo-ambra h2, h2.tono-testo-ambra { color: var(--ambra); }
.tono-testo-rosso h2, h2.tono-testo-rosso { color: var(--rosso); }

/* --- Schede -------------------------------------------------------------- */
.schede { display: flex; gap: var(--s1); flex: none; min-height: 33px; border-bottom: 1px solid var(--bordo); overflow-x: auto; scrollbar-width: none; }
.schede a, .schede button {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 var(--s2); margin-bottom: -1px; flex: none;
  border: 0; border-bottom: 2px solid transparent; background: none; color: var(--testo-3); text-decoration: none; font-weight: 550; cursor: pointer;
}
.schede a:hover, .schede button:hover { color: var(--testo); }
.schede .attiva { color: var(--testo); border-bottom-color: var(--marchio); }
.schede-conta { padding: 0 5px; border-radius: 9px; background: var(--neutro-tenue); color: var(--testo-2); font-size: var(--t-micro); font-variant-numeric: tabular-nums; }

/* --- Tabella ------------------------------------------------------------- */
.tab-vano { flex: 1; min-height: 0; overflow: auto; }
.tab { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--superficie); }
.tab th {
  position: sticky; top: 0; z-index: 2; height: 30px; padding: 0 var(--s2); text-align: left; white-space: nowrap;
  background: var(--superficie-2); color: var(--testo-3); font-size: var(--t-piccolo); font-weight: 600; border-bottom: 1px solid var(--bordo);
}
.tab td { padding: 6px var(--s2); border-bottom: 1px solid var(--bordo); vertical-align: middle; }
.tab th:first-child, .tab td:first-child { padding-left: var(--pagina-m); }
.tab th:last-child, .tab td:last-child { padding-right: var(--pagina-m); }
.tab .destra { text-align: right; font-variant-numeric: tabular-nums; }
.tab tr.apribile { cursor: pointer; }
.tab tbody tr:hover { background: var(--passaggio); }
.tab tbody tr:focus-visible { outline-offset: -2px; }
.tab-ordina { display: inline-flex; align-items: center; gap: 2px; height: 28px; padding: 0; border: 0; background: none; color: inherit; font-weight: 600; cursor: pointer; }
.tab-ordina:hover { color: var(--testo); }
.tab-ordina .ic { width: 14px; height: 14px; }
.tab-ordina .ic.tenue { opacity: .55; }
.pagina-corpo:not(.senza-margine) .tab-vano { border: 1px solid var(--bordo); border-radius: var(--r2); margin-top: var(--s2); }
.pagina-corpo:not(.senza-margine) .tab th:first-child, .pagina-corpo:not(.senza-margine) .tab td:first-child { padding-left: var(--s2); }
.pagina-corpo:not(.senza-margine) .tab th:last-child, .pagina-corpo:not(.senza-margine) .tab td:last-child { padding-right: var(--s2); }
.cella-card { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.cella-card a { text-decoration: none; font-weight: 550; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cella-card a:hover { text-decoration: underline; }
.con-punto { display: inline-flex; align-items: center; gap: 6px; }

.tab-semplice { width: 100%; border-collapse: collapse; }
.tab-semplice th, .tab-semplice td { padding: 5px var(--s2) 5px 0; border-bottom: 1px solid var(--bordo); text-align: left; vertical-align: top; }
.tab-semplice th { color: var(--testo-3); font-weight: 600; font-size: var(--t-piccolo); }
.testo-tabella { overflow-x: auto; }

.dati { display: grid; grid-template-columns: minmax(110px, max-content) minmax(0, 1fr); gap: var(--s1) var(--s3); }
.dati dt { color: var(--testo-3); }
.dati dd { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

/* --- Finestra ------------------------------------------------------------ */
dialog.finestra {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--bordo); border-radius: var(--r3);
  background: var(--superficie); color: var(--testo); box-shadow: var(--ombra-finestra); overflow: hidden;
}
dialog.finestra[open] { display: flex; flex-direction: column; }
dialog.finestra.larga { width: min(860px, calc(100vw - 24px)); }
dialog.finestra::backdrop { background: var(--velo); }
.finestra-testa { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s3) var(--s3) var(--s2) var(--s4); }
.finestra-testa h2 { font-size: var(--t-titolo); font-weight: 650; min-width: 0; overflow-wrap: anywhere; }
.finestra-corpo { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s1) var(--s4) var(--s4); display: grid; gap: var(--s3); align-content: start; }
.finestra-piede { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s2) var(--s4) var(--s3); }
.finestra-testo { color: var(--testo-2); overflow-wrap: anywhere; }
.finestra-conseguenze { display: flex; gap: var(--s2); padding: var(--s2); border-radius: var(--r2); background: var(--ambra-tenue); color: var(--ambra); }
.scelte { display: grid; gap: var(--s1); }
.scelte button { padding: var(--s2) var(--s3); min-height: 40px; border: 1px solid var(--bordo); border-radius: var(--r2); background: var(--superficie); text-align: left; cursor: pointer; }
.scelte button:hover { border-color: var(--bordo-forte); background: var(--passaggio); }

/* --- Avvisi -------------------------------------------------------------- */
.avvisi { position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%); z-index: 70; display: grid; gap: var(--s2); width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.avviso { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r2); background: var(--testo); color: var(--superficie); box-shadow: var(--ombra-finestra); pointer-events: auto; }
.avviso span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.avviso button { border: 0; background: none; color: inherit; font-weight: 650; text-decoration: underline; cursor: pointer; padding: var(--s1); }
@media (max-width: 768px) { .avvisi { bottom: 68px; } }

/* --- Menu ---------------------------------------------------------------- */
.menu { position: relative; display: inline-block; }
.menu-lista {
  position: absolute; right: 0; top: 100%; z-index: 30; min-width: 190px; max-height: 320px; overflow: auto; margin-top: 2px; padding: var(--s1);
  background: var(--superficie); border: 1px solid var(--bordo-forte); border-radius: var(--r2); box-shadow: var(--ombra-finestra);
}
.menu-lista.sopra { top: auto; bottom: 100%; margin: 0 0 2px; }
.menu-lista button { display: flex; align-items: center; gap: var(--s2); width: 100%; min-height: 30px; padding: 0 var(--s2); border: 0; border-radius: var(--r1); background: none; text-align: left; cursor: pointer; color: var(--testo); white-space: nowrap; }
.menu-lista button:hover, .menu-lista button:focus-visible { background: var(--passaggio); }
.menu-lista button.pericolo { color: var(--rosso); }
.menu-lista .ic { width: 16px; height: 16px; }
.menu-sezione { padding: var(--s1) var(--s2) 2px; color: var(--testo-3); font-size: var(--t-micro); font-weight: 600; }

/* --- Pannello ------------------------------------------------------------ */
.pannello-velo { position: fixed; inset: 0; z-index: 20; background: var(--velo); }
.pannello { position: fixed; top: 0; right: 0; bottom: 0; z-index: 21; display: flex; flex-direction: column; width: min(720px, 100vw); background: var(--superficie); border-left: 1px solid var(--bordo); outline: none; box-shadow: var(--ombra-finestra); }
.pannello-testa { flex: none; display: flex; align-items: center; gap: var(--s1); height: var(--testata-h); padding: 0 var(--s3) 0 var(--s4); border-bottom: 1px solid var(--bordo); }
.pannello-briciole { flex: 1; min-width: 0; color: var(--testo-3); font-size: var(--t-piccolo); }
.pannello-testa > span:first-child { flex: 1; }
.pannello-corpo { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s3) var(--s4) var(--s6); display: grid; gap: var(--s3); align-content: start; }

/* --- Barra di consumo ---------------------------------------------------- */
.consumo { display: grid; gap: 3px; }
.consumo-riga { display: flex; justify-content: space-between; gap: var(--s2); font-size: var(--t-piccolo); }
.consumo-riga span { color: var(--testo-3); font-variant-numeric: tabular-nums; text-align: right; }
.consumo-binario { height: 8px; border-radius: 4px; overflow: hidden; background: var(--neutro-tenue); }
.consumo-binario i { display: block; height: 100%; border-radius: 4px; transition: width .3s ease; }
.livello-basso { background: var(--ok); } .livello-medio { background: var(--ambra); } .livello-alto { background: var(--rosso); }
.consumo-nota { font-size: var(--t-piccolo); color: var(--testo-3); }

/* --- Riquadri: solo per oggetti reali ------------------------------------ */
.griglia-riquadri { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: var(--s3); }
.griglia-riquadri.quattro { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.riquadro { display: grid; gap: var(--s3); align-content: start; padding: var(--s3) var(--s4); border: 1px solid var(--bordo); border-radius: var(--r3); background: var(--superficie); color: inherit; text-decoration: none; }
.riquadro.cliccabile:hover { border-color: var(--bordo-forte); background: var(--superficie-2); }
.riquadro-testa { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.riquadro-testa h2 { font-size: var(--t-medio); font-weight: 650; }

/* --- Stati --------------------------------------------------------------- */
.segnaposto { display: grid; gap: var(--s3); padding: var(--s2) 0; }
.segnaposto i { display: block; height: 12px; border-radius: 3px; background: var(--neutro-tenue); animation: respiro 1.3s ease-in-out infinite alternate; }
@keyframes respiro { from { opacity: .55; } to { opacity: 1; } }
.stato { flex: 1; display: grid; justify-items: center; align-content: center; gap: var(--s2); padding: var(--s8) var(--s4); text-align: center; color: var(--testo-3); }
.stato .ic { width: 28px; height: 28px; }
.stato h1, .stato h2 { font-size: var(--t-titolo); font-weight: 650; color: var(--testo); }
.stato-errore .ic { color: var(--rosso); }
.segnale { display: flex; align-items: center; gap: var(--s2); min-height: 32px; padding: var(--s1) 0; font-weight: 600; }
.segnale.tono-ok { color: var(--ok); } .segnale.tono-rosso { color: var(--rosso); }

/* --- Testo formattato ---------------------------------------------------- */
.testo-ricco { display: grid; gap: var(--s2); line-height: 1.5; overflow-wrap: anywhere; }
.testo-ricco ul { list-style: disc; padding-left: var(--s5); }
.testo-titolo { font-weight: 650; margin-top: var(--s1); }
