/*
 -------------------------------------------------------------------------------------------------
      _    ____      _  _____ ___    ___ _   _  ____ _____ ____ _   _ _____ ____  ___    _
     / \  |  _ \    / \|_   _/ _ \  |_ _| \ | |/ ___| ____/ ___| \ | | ____|  _ \|_ _|  / \
    / _ \ | |_) |  / _ \ | || | | |  | ||  \| | |  _|  _|| |  _|  \| |  _| | |_) || |  / _ \
   / ___ \|  _ <  / ___ \| || |_| |  | || |\  | |_| | |__| |_| | |\  | |___|  _ < | | / ___ \
  /_/   \_\_| \_\/_/   \_\_| \___/  |___|_| \_|\____|_____\____|_| \_|_____|_| \_\___/_/   \_\

 -------------------------------------------------------------------------------------------------
 Copyright (c) 2026 Arato Ingegneria. Tutti i diritti riservati.
 Name        : evo2.css
 Author      : Ing. Roberto Arato
 Version     : 0.9.2
 Copyright   : Ing. Roberto Arato (c) 2026
 Description : Aspetto della dashboard EVO2, ripreso dal vecchio configuratore NESA
               (old/config_aiotnet.zip, css/app.css): stessa tavolozza, barra laterale,
               card, tabelle, pulsanti, toast, modali, login e cassetto sotto i 768 px.
               Nessuno stile in linea nelle pagine: la Content-Security-Policy li vieta.
 -------------------------------------------------------------------------------------------------
 */

/* ---- Tavolozza: le 13 variabili, con i colori del sito www.nesasrl.eu --------------------- */
:root {
  --primary:       #0075be;
  --primary-mid:   #3b4c56;
  --primary-light: #5b7180;
  --accent:        #c62828;
  --accent-light:  #e3e7ea;
  --success:       #2e7d32;
  --warning:       #e65100;
  --info:          #0075be;
  --bg:            #e3e7ea;
  --surface:       #ffffff;
  --text:          #3b4c56;
  --text-light:    #5b7180;
  --border:        #bcc7ce;
  --sidebar-w:     220px;
  --radius:        6px;
  --shadow:        0 2px 8px rgba(0,0,0,.12);
  --shadow-md:     0 4px 16px rgba(0,0,0,.16);
}

/* ---- Base --------------------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100%;
  overflow: hidden;
}
a { text-decoration: none; color: inherit; }
a.link { color: var(--primary-light); }
a.link:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
input, select, textarea { border: 1px solid var(--border); border-radius: var(--radius); }
.nascosto { display: none !important; }
.testo-chiaro { color: var(--text-light); }
.testo-piccolo { font-size: 12px; }
.mono { font-family: Consolas, 'Courier New', monospace; font-size: 12px; }
.destra { text-align: right; }
.spazio-sopra { margin-top: 14px; }

/* ---- Struttura ---------------------------------------------------------------------------------- */
#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: transform .25s ease;
}
/* Il logo nesa e' largo (542x100): sta sopra la scritta, non accanto, cosi' non esce dai 220 px */
.sidebar-logo {
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.sidebar-logo img { width: 100%; max-width: 170px; height: auto; filter: brightness(0) invert(1); }
.sidebar-logo span { font-size: 13px; font-weight: 600; opacity: .85; letter-spacing: .3px; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  min-height: 52px;
}
.sidebar-user:hover { background: rgba(255,255,255,.08); }
.sidebar-user-icon { font-size: 26px; opacity: .7; flex-shrink: 0; }
.sidebar-user-info { min-width: 0; }
.sidebar-user-name {
  font-size: 13px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; margin-top: 2px; }
.sidebar-user-lock { font-size: 13px; opacity: .45; flex-shrink: 0; margin-left: auto; }
.sidebar-user:hover .sidebar-user-lock { opacity: .8; }
.role-operatore      { color: #80cbc4; }
.role-amministratore { color: #ffcc80; }
.role-superutente    { color: #ef9a9a; }

.nav-links { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-section-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px;
  color: rgba(255,255,255,.38); padding: 12px 20px 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: rgba(255,255,255,.78);
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.15); color: #fff; border-left-color: var(--accent-light); }
.nav-link .fa { width: 18px; text-align: center; }
.nav-link.futura { color: rgba(255,255,255,.35); cursor: default; }
.nav-link.futura:hover { background: transparent; color: rgba(255,255,255,.35); }
.nav-badge {
  margin-left: auto; background: rgba(255,255,255,.18); color: rgba(255,255,255,.85);
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; flex-shrink: 0;
}

.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-logout {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255,255,255,.25);
  color: rgba(255,255,255,.7);
  font-size: 13px;
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background .15s, color .15s;
}
.sidebar-logout:hover { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.5); }
.sidebar-versione { font-size: 10px; color: rgba(255,255,255,.38); text-align: center; }

#sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 300;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  width: 40px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

#content { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 24px; background: var(--bg); min-width: 0; }
.page { max-width: 1400px; margin: 0 auto; }
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h2 {
  font-size: 22px; font-weight: 600; color: var(--primary);
  flex: 1; display: flex; align-items: center; gap: 8px;
}
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { font-size: 12px; background: var(--primary-light); color: #fff; padding: 2px 8px; border-radius: 10px; font-weight: 500; }

/* ---- Card e sezioni ------------------------------------------------------------------------------ */
.section-card { background: var(--surface); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.section-title {
  font-size: 15px; font-weight: 600; color: var(--primary);
  margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid var(--bg);
  display: flex; align-items: center; gap: 8px;
}
.sub-title { font-size: 13px; font-weight: 600; color: var(--primary-mid); margin: 16px 0 10px; display: flex; align-items: center; gap: 6px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 16px; }
.card {
  background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
  border: 1px solid transparent; transition: box-shadow .2s, transform .2s, border-color .2s;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--primary-light); }
.card-icon { font-size: 30px; color: var(--primary); display: block; margin-bottom: 10px; }
.card h3 { font-size: 15px; font-weight: 600; color: var(--primary); margin-bottom: 6px; }
.card p { font-size: 12px; color: var(--text-light); }
.card .numero { font-size: 28px; font-weight: 600; color: var(--primary); }

/* ---- Moduli -------------------------------------------------------------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-wide { grid-column: span 2; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: .4px; }
.field input, .field select, .field textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: #fafafa; transition: border-color .15s, box-shadow .15s; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(0,117,190,.15); background: #fff;
}
.field-check { flex-direction: row; align-items: center; gap: 8px; padding-top: 18px; }
.field-check input[type="checkbox"] { width: auto; flex: 0 0 auto; margin: 0; }                /* non width: 100% dei campi */
.field-check label { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

.toggle { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #ccc; border-radius: 20px; cursor: pointer; transition: background .2s; }
.slider::before {
  content: ''; position: absolute; width: 14px; height: 14px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: transform .2s;
}
.toggle input:checked + .slider { background: var(--success); }
.toggle input:checked + .slider::before { transform: translateX(16px); }

/* ---- Pulsanti ------------------------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border: none; border-radius: var(--radius); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: filter .15s, transform .1s; white-space: nowrap; text-align: center;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }
.btn-primary   { background: var(--primary);       color: #fff; }
.btn-success   { background: var(--success);       color: #fff; }
.btn-secondary { background: var(--primary-light); color: #fff; }
.btn-info      { background: var(--info);          color: #fff; }
.btn-danger    { background: var(--accent);        color: #fff; }
.btn-warning   { background: var(--warning);       color: #fff; }
.btn-outline   { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.btn-lg        { padding: 10px 20px; font-size: 14px; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
form.in-linea  { display: inline; }
input.campo-corto { width: 90px; display: inline-block; margin-right: 6px; }

/* ---- Tabelle ------------------------------------------------------------------------------------- */
.table-scroll { overflow-x: auto; }
.info-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.info-table th {
  background: var(--primary); color: #fff; padding: 8px 12px; text-align: left;
  font-size: 12px; text-transform: uppercase; white-space: nowrap;
}
.info-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.info-table tr:nth-child(even) { background: #f4f6f7; }
.info-table td.azioni { white-space: nowrap; text-align: right; }

/* ---- Distintivi e stati ------------------------------------------------------------------------- */
.role-badge {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; padding: 2px 8px; border-radius: 10px; color: #fff;
}
.role-badge-operatore      { background: #009688; }
.role-badge-amministratore { background: #f57c00; }
.role-badge-superutente    { background: #c62828; }
.stato { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.stato::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.stato-ok     { color: var(--success); }
.stato-ko     { color: var(--accent); }
.stato-avviso { color: var(--warning); }
.stato-spento { color: #9e9e9e; }

.avviso {
  background: #fff8e1; border: 1px solid #ffe082; color: #795548;
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start;
}
.errore-box {
  background: #ffebee; color: var(--accent); border: 1px solid #ef9a9a;
  border-radius: var(--radius); padding: 8px 12px; font-size: 13px; margin-top: 12px;
}

/* ---- Dettagli apribili (modifica in riga) -------------------------------------------------------- */
details.apri summary { cursor: pointer; color: var(--primary-light); font-weight: 600; font-size: 12px; list-style: none; }
details.apri summary::-webkit-details-marker { display: none; }
details.apri[open] { background: #f0f4ff; border-radius: var(--radius); padding: 10px; margin-top: 6px; }

/* ---- Stato vuoto -------------------------------------------------------------------------------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-light); }
.empty-state .fa { font-size: 48px; opacity: .25; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ---- Toast -------------------------------------------------------------------------------------- */
.toast {
  position: fixed; bottom: -80px; left: 50%; transform: translateX(-50%);
  padding: 12px 24px; border-radius: 24px; font-size: 14px; font-weight: 500; color: #fff;
  z-index: 1000; transition: bottom .3s ease; pointer-events: none; max-width: 90vw;
  text-align: center; box-shadow: var(--shadow-md);
}
.toast.visible { bottom: 24px; }
.toast-success { background: var(--success); }
.toast-error   { background: var(--accent); }
.toast-warning { background: var(--warning); }
.toast-info    { background: var(--info); }

/* ---- Finestre modali ---------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 5000;
}
.modal-card { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-md); width: 100%; max-width: 360px; padding: 28px; margin: 16px; }
.modal-title { font-size: 16px; font-weight: 600; color: var(--primary); margin-bottom: 18px; display: flex; align-items: center; gap: 8px; }
.modal-testo { margin-bottom: 20px; }
.modal-azioni { display: flex; gap: 8px; justify-content: flex-end; }

/* ---- Accesso ------------------------------------------------------------------------------------ */
body.accesso { overflow: auto; }
#login-overlay { position: fixed; inset: 0; background: var(--primary); display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-md); width: 100%; max-width: 380px; overflow: hidden; }
.login-logo { background: var(--primary-mid); padding: 24px 28px; display: flex; align-items: center; gap: 12px; }
.login-logo img { height: 40px; filter: brightness(0) invert(1); }
.login-logo span { font-size: 15px; font-weight: 600; color: rgba(255,255,255,.9); letter-spacing: .3px; }
.login-body { padding: 28px; }
.login-title { font-size: 18px; font-weight: 600; color: var(--primary); margin-bottom: 20px; }
.login-body .field { margin-bottom: 12px; }
.login-btn { width: 100%; margin-top: 12px; padding: 11px; font-size: 15px; justify-content: center; }
.login-piede { font-size: 11px; color: var(--text-light); text-align: center; margin-top: 18px; }

/* ---- RTUN: indicatore, porte, grafici ----------------------------------------------------------- */
.rtun-link { font-size: 12px; padding: 4px 4px 2px; }
#sidebar .rtun-link.stato-ok     { color: #a5d6a7; }
#sidebar .rtun-link.stato-ko     { color: #ef9a9a; }
#sidebar .rtun-link.stato-spento { color: rgba(255,255,255,.5); }
.info-riga { background: var(--surface); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; box-shadow: var(--shadow); }
.porta {
  display: inline-block; font-family: Consolas, 'Courier New', monospace; font-size: 11px;
  background: #e8f1f8; color: var(--primary-mid); border: 1px solid #c9dbe9; border-radius: 10px;
  padding: 1px 7px; margin: 1px 4px 1px 0; white-space: nowrap;
}
svg.grafico { width: 100%; height: auto; max-height: 220px; display: block; }
svg.grafico .griglia { stroke: var(--border); stroke-width: 1; }
svg.grafico .asse { fill: var(--text-light); font-size: 9px; font-family: 'Segoe UI', Arial, sans-serif; }
svg.grafico .barra-ok     { fill: var(--success); }
svg.grafico .barra-avviso { fill: var(--warning); }
svg.grafico .barra-ko     { fill: var(--accent); }
svg.grafico .barra:hover  { opacity: .75; }
@media (max-width: 600px) {
  svg.grafico .asse { font-size: 15px; }                                                 /* il grafico si rimpicciolisce: etichette leggibili */
}

/* ---- Pagina Tema -------------------------------------------------------------------------------- */
.spazio-sotto { margin-bottom: 16px; }
.riga-colore { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.campo-colore input[type="color"] {
  width: 46px; height: 32px; padding: 2px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface); cursor: pointer; flex-shrink: 0;
}
.anteprima { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.anteprima-barra { width: 160px; background: var(--primary); padding: 12px 0; flex-shrink: 0; }
.anteprima-contenuto { flex: 1; background: var(--bg); padding: 16px; min-width: 0; }
.anteprima .section-card { margin-bottom: 0; }

/* ---- Configuratore ------------------------------------------------------------------------------ */
.schede { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; border-bottom: 2px solid var(--border); }
.scheda {
  padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--text-light); text-decoration: none;
  border-radius: var(--radius) var(--radius) 0 0; margin-bottom: -2px; border-bottom: 2px solid transparent;
}
.scheda:hover { color: var(--primary); background: var(--surface); }
.scheda.attiva { color: var(--primary); background: var(--surface); border-bottom-color: var(--primary-light); }
.scheda-destra { margin-left: auto; }
.invio { border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 12px 12px; margin-top: 12px; background: var(--bg); }
.invio .sub-title { margin-top: 10px; }
.a-destra { margin-left: auto; }
.gruppo-modo { margin-top: 10px; }
.invisibile { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.field-bottone { justify-content: flex-end; }
.barra-fissa { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; z-index: 5; }
.barra-misure { align-items: center; }
.barra-misure .badge { margin-left: auto; }
.tabella-misure td { padding: 3px 4px; vertical-align: middle; }
.tabella-misure .mini { width: 100%; min-width: 60px; padding: 4px 6px; font-size: 12px; border: 1px solid var(--border); border-radius: 4px; }
.tabella-misure .num { min-width: 64px; max-width: 90px; }
.tabella-misure .corto { min-width: 50px; max-width: 70px; }
.tabella-misure .formula { font-family: Consolas, 'Courier New', monospace; }
.tabella-misure input[data-campo="index"] { min-width: 52px; max-width: 64px; }
.tabella-misure input[data-campo="measure_name"] { min-width: 150px; }
.tabella-misure select[data-campo="sensor_base"] { min-width: 160px; }
.tabella-misure select[data-campo="measure_type"] { min-width: 120px; }
.tabella-misure select[data-campo="channel"] { min-width: 110px; }
.tabella-misure .errato { border-color: var(--accent); background: #ffebee; }
.tabella-misure tr.formula-row td { padding-top: 0; border-top: none; }
.tabella-misure td.col-id { text-align: center; color: var(--primary-mid); font-weight: 600; }
.tabella-misure td.azioni { white-space: nowrap; }
.tabella-misure td.azioni .btn { padding: 3px 7px; }
.setup-panel { background: #f0f4ff; border-radius: var(--radius); padding: 8px 12px; position: sticky; left: 0; max-width: 860px; }   /* resta visibile scorrendo la tabella */
.setup-section h4 { font-size: 12px; color: var(--primary-mid); margin: 8px 0; }
#tabella-differenze td.mono { word-break: break-all; }

/* ---- Telefono e tablet -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  body { overflow: auto; }
  #app { flex-direction: column; height: auto; min-height: 100vh; overflow: auto; }
  #sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 240px; transform: translateX(-100%); z-index: 200; }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.3); }
  #sidebar .sidebar-logo { padding-top: 64px; }                       /* sotto il pulsante del menu */
  #sidebar-toggle { display: flex; }
  #content { padding: 60px 12px 24px; overflow: visible; }
  .page-header { flex-direction: column; align-items: stretch; }
  .header-actions .btn { flex: 1; justify-content: center; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: span 1; }
  .info-table th, .info-table td { padding: 6px 8px; }
  .anteprima-barra { width: 110px; }
}
@media (max-width: 400px) {
  .cards { grid-template-columns: 1fr; }
}

/* ---- Chiave del dispositivo (mostrata una volta) ------------------------------------------------ */
.chiave { font-size: 16px; padding: 12px 14px; background: #fff8e1; border: 1px dashed var(--warning); border-radius: var(--radius); word-break: break-all; user-select: all; }

/* ---- File ricevuti: anteprima di testi e immagini (fase 8) -------------------------------------- */
.file-testo { max-height: 480px; overflow: auto; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-family: Consolas, 'Courier New', monospace; font-size: 12px; white-space: pre; }
.file-immagine { max-width: 100%; max-height: 520px; border: 1px solid var(--border); border-radius: var(--radius); display: block; }

/* ---- Software: versioni diverse dal pacchetto assegnato (fase 7) ------------------------------- */
.info-table td.ver-diversa { background: #fff3e0; color: var(--accent); font-weight: 700; }
