/* =============================================================================
   Tema di SGE - Gestionale Impianti: variabili dei colori e componenti condivisi dell'interfaccia.

   - Le variabili vengono calcolate da /js/theme.js (palette scelta dall'utente) e iniettate
     nel <style id="sge-theme-vars">. I valori qui sotto sono solo la riserva del preset
     "Azzurro SGE" (stessi valori generati da theme.js), usata se lo script non e' ancora attivo.
   - In tutto il CSS i colori si esprimono con queste variabili, mai con valori fissi:
       --tone-*  scala del colore primario (50 chiarissimo ... 900 scurissimo; invertita in scuro)
       --gray-*  grigi leggermente tinti (--gray-0 = superficie delle schede)
       --ok-* / --warn-* / --bad-*  stati (completato, avviso, errore)
       --primary / --secondary (+ -strong, -hover) con il testo --on-primary / --on-secondary
       --gradient-bg / --gradient-sidebar / --gradient-header  sfondi
   - Modalita' scura: attributo data-theme="dark" su <html> (solo a schermo, mai in stampa).
   ============================================================================= */

/* Riserva generata da theme.js: preset "Azzurro SGE" (non modificare a mano). */
:root {
  --tone-50: #f3f9fc;
  --tone-100: #e6f4f9;
  --tone-150: #daeef6;
  --tone-200: #c5e5f1;
  --tone-300: #9cd6ec;
  --tone-400: #6dc2e3;
  --tone-500: #3eaeda;
  --tone-600: #2595c1;
  --tone-700: #1d7496;
  --tone-800: #15566f;
  --tone-900: #0f3b4d;
  --tone2-50: #f3f8fc;
  --tone2-100: #e6f2f9;
  --tone2-150: #daebf6;
  --tone2-200: #c5e1f1;
  --tone2-300: #9cceec;
  --tone2-400: #6db6e3;
  --tone2-500: #3e9fda;
  --tone2-600: #2585c1;
  --tone2-700: #1d6896;
  --tone2-800: #154d6f;
  --tone2-900: #0f354d;
  --gray-0: #ffffff;
  --gray-50: #f9fafb;
  --gray-100: #f4f5f6;
  --gray-150: #ebeeef;
  --gray-200: #e0e4e6;
  --gray-300: #c6cfd2;
  --gray-400: #9eadb3;
  --gray-500: #768b93;
  --gray-600: #5e7178;
  --gray-700: #4a595e;
  --gray-800: #364045;
  --gray-900: #242b2e;
  --ok-50: #f4fbf8;
  --ok-100: #e8f7f0;
  --ok-150: #ddf3e9;
  --ok-200: #caecdc;
  --ok-300: #a8e1c6;
  --ok-400: #7fd2ab;
  --ok-500: #55c390;
  --ok-600: #3caa76;
  --ok-700: #2e845c;
  --ok-800: #226244;
  --ok-900: #18442f;
  --warn-50: #fcf8f3;
  --warn-100: #f9f0e6;
  --warn-150: #f6e9da;
  --warn-200: #f1ddc5;
  --warn-300: #ecc79c;
  --warn-400: #e3ac6d;
  --warn-500: #da913e;
  --warn-600: #c17825;
  --warn-700: #965d1d;
  --warn-800: #6f4515;
  --warn-900: #4d300f;
  --bad-50: #fcf3f3;
  --bad-100: #f9e6e7;
  --bad-150: #f6dadb;
  --bad-200: #f1c5c7;
  --bad-300: #e9a0a4;
  --bad-400: #de7378;
  --bad-500: #d3454c;
  --bad-600: #ba2c33;
  --bad-700: #912227;
  --bad-800: #6b191d;
  --bad-900: #4a1114;
  --primary: #02aff3;
  --primary-strong: #028bc0;
  --on-primary: #0d1b24;
  --primary-hover: #1cbdfd;
  --primary-hover-strong: #02a5e3;
  --on-primary-hover: #0d1b24;
  --primary-active: #0175a2;
  --secondary: #0b4f79;
  --secondary-strong: #083754;
  --on-secondary: #ffffff;
  --secondary-hover: #083d5d;
  --on-secondary-hover: #ffffff;
  --accent: #02aff3;
  --focus-ring: rgba(2,175,243,0.55);
  --surface: #ffffff;
  --gradient-bg: linear-gradient(180deg, #f2fbfe, #eef3f6);
  --gradient-sidebar: linear-gradient(180deg, #e1f5fe, #c9d8e2);
  --gradient-header: linear-gradient(120deg, #ffffff, #e6f4f9);
  --shadow: 0 7px 24px rgba(11,79,121,0.08);
  --backdrop: rgba(11,79,121,0.42);
}
@media screen {
  :root[data-theme="dark"] {
    --tone-50: #1f2a2e;
    --tone-100: #253237;
    --tone-150: #2b3a40;
    --tone-200: #205165;
    --tone-300: #2a6a84;
    --tone-400: #3586a7;
    --tone-500: #49a2c5;
    --tone-600: #70b6d2;
    --tone-700: #96cade;
    --tone-800: #b9dbe9;
    --tone-900: #d8ebf3;
    --tone2-50: #1f282e;
    --tone2-100: #253037;
    --tone2-150: #2b3840;
    --tone2-200: #204a65;
    --tone2-300: #2a6184;
    --tone2-400: #357ba7;
    --tone2-500: #4996c5;
    --tone2-600: #70acd2;
    --tone2-700: #96c3de;
    --tone2-800: #b9d7e9;
    --tone2-900: #d8e9f3;
    --gray-0: #1f2223;
    --gray-50: #242729;
    --gray-100: #282d2e;
    --gray-150: #2f3537;
    --gray-200: #3b4244;
    --gray-300: #4e575a;
    --gray-400: #6b767b;
    --gray-500: #8a9599;
    --gray-600: #a5adb1;
    --gray-700: #c0c6c8;
    --gray-800: #d9dcde;
    --gray-900: #e9ebec;
    --ok-50: #1f2e27;
    --ok-100: #25372f;
    --ok-150: #2b4036;
    --ok-200: #226244;
    --ok-300: #2d8059;
    --ok-400: #39a271;
    --ok-500: #4ec18b;
    --ok-600: #73cea4;
    --ok-700: #99dbbc;
    --ok-800: #bbe7d3;
    --ok-900: #d9f2e6;
    --warn-50: #2e271f;
    --warn-100: #372f25;
    --warn-150: #40362b;
    --warn-200: #654520;
    --warn-300: #845a2a;
    --warn-400: #a77135;
    --warn-500: #c58b49;
    --warn-600: #d2a470;
    --warn-700: #debd96;
    --warn-800: #e9d3b9;
    --warn-900: #f3e6d8;
    --bad-50: #2e1f1f;
    --bad-100: #372526;
    --bad-150: #402b2c;
    --bad-200: #652023;
    --bad-300: #842a2e;
    --bad-400: #a7353a;
    --bad-500: #c5494f;
    --bad-600: #d27074;
    --bad-700: #de969a;
    --bad-800: #e9b9bc;
    --bad-900: #f3d8da;
    --primary: #217697;
    --primary-strong: #18556d;
    --on-primary: #ffffff;
    --primary-hover: #1b5f7a;
    --primary-hover-strong: #123e50;
    --on-primary-hover: #ffffff;
    --primary-active: #124254;
    --secondary: #0d5b8c;
    --secondary-strong: #0a4367;
    --on-secondary: #ffffff;
    --secondary-hover: #0a4970;
    --on-secondary-hover: #ffffff;
    --accent: #21bffd;
    --focus-ring: rgba(2,175,243,0.7);
    --surface: #1f2223;
    --gradient-bg: linear-gradient(180deg, #242729, #282d2e);
    --gradient-sidebar: linear-gradient(180deg, #222f35, #1f303b);
    --gradient-header: linear-gradient(120deg, #1f2223, #253237);
    --shadow: 0 1px 3px rgba(0,0,0,.28);
    --backdrop: rgba(0,0,0,.6);
  }
}

/* --- Alias storici usati dal CSS del gestionale ----------------------------------- */
:root {
  --bg: var(--gray-100);
  --paper: var(--gray-0);
  --card: var(--gray-0);
  --ink: var(--gray-900);
  --muted: var(--gray-600);
  --blue: var(--tone-800);
  --line: var(--tone-200);
  --light: var(--tone-50);
  --green: var(--ok-700);
  --orange: var(--warn-700);
  --red: var(--bad-700);
  --radius: 12px;
  /* Riempimenti di stato (uguali in chiaro e scuro, contrasto verificato con il testo sopra) */
  --ok-solid: #1f7a4d;
  --ok-solid-strong: #17603c;
  --warn-solid: #f0a43a;
  --warn-solid-strong: #e08e1c;
  --ease: cubic-bezier(.2, .7, .3, 1);
}
:root[data-theme="dark"] { --line: var(--gray-200); }

/* --- Interazioni comuni ----------------------------------------------------------- */
.btn { transition: background-color .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), color .15s var(--ease); }
.btn:not(.primary):not(.danger):hover { background: var(--tone-50); border-color: var(--tone-300); }
.btn.primary:hover { background: linear-gradient(135deg, var(--primary-hover), var(--primary-hover-strong)); color: var(--on-primary-hover); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--focus-ring); outline-offset: 2px;
}
::selection { background: var(--tone-200); color: var(--tone-900); }
:root[data-theme="dark"] .sidebar-brand { border-color: var(--gray-300); }
:root[data-theme="dark"] .dialog { background: var(--gray-0); }
:root[data-theme="dark"] img { filter: none; }
.dialog { background: var(--gray-0); color: var(--ink); }

/* --- Intestazione: strumenti a destra (ricerca rapida e menu utente) --------------- */
.header-tools { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.header .sync-status { margin-left: 0; }
.quick-search-btn {
  display: inline-flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px 0 12px;
  border: 1px solid var(--tone-200); border-radius: 10px; background: var(--gray-0); color: var(--muted);
  font-size: 13px; cursor: pointer; transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.quick-search-btn:hover { border-color: var(--tone-400); box-shadow: 0 0 0 3px var(--tone-100); }
.quick-search-btn svg { color: var(--tone-700); }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid var(--gray-300); border-bottom-width: 2px;
  border-radius: 6px; background: var(--gray-50); color: var(--gray-700); font: 600 11px/1.5 ui-monospace, Consolas, monospace; text-align: center;
}

/* --- Menu utente (avatar + menu a discesa) ---------------------------------------- */
.user-menu { position: relative; }
.user-menu-trigger {
  display: inline-flex; align-items: center; gap: 10px; padding: 4px 10px 4px 4px; min-height: 44px;
  border: 1px solid var(--tone-200); border-radius: 999px; background: var(--gray-0); color: var(--ink); cursor: pointer;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.user-menu-trigger:hover, .user-menu-trigger[aria-expanded="true"] { border-color: var(--tone-400); box-shadow: 0 0 0 3px var(--tone-100); }
.user-menu-trigger .who { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; text-align: left; }
.user-menu-trigger .who strong { font-size: 13px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-trigger .who small { font-size: 11px; color: var(--muted); }
.user-menu-trigger .chevron { color: var(--muted); transition: transform .15s var(--ease); }
.user-menu-trigger[aria-expanded="true"] .chevron { transform: rotate(180deg); }
.user-avatar {
  display: inline-grid; place-items: center; flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%; overflow: hidden;
  background: linear-gradient(135deg, var(--primary), var(--secondary)); color: var(--on-secondary);
  font: 700 13px/1 var(--font-ui); letter-spacing: .5px; text-transform: uppercase;
}
.user-avatar.large { width: 46px; height: 46px; font-size: 16px; }
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; width: 290px; max-width: calc(100vw - 24px);
  padding: 8px; border: 1px solid var(--gray-200); border-radius: 14px; background: var(--gray-0); color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .16); transform-origin: top right; animation: menu-in .14s var(--ease);
}
.user-menu-panel[hidden] { display: none; }
.user-menu-profile { display: flex; gap: 12px; align-items: center; padding: 10px 10px 12px; border-bottom: 1px solid var(--gray-150); margin-bottom: 6px; }
.user-menu-profile strong { display: block; font-size: 14px; overflow-wrap: anywhere; }
.user-menu-profile small { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.user-menu-profile .role-pill { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 999px; background: var(--tone-100); color: var(--tone-800); font-size: 11px; font-weight: 700; }
.user-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 9px;
  background: transparent; color: var(--ink); font-size: 13px; font-weight: 600; text-align: left; text-decoration: none; cursor: pointer;
}
.user-menu-item svg { color: var(--tone-700); flex-shrink: 0; }
.user-menu-item:hover, .user-menu-item:focus-visible { background: var(--tone-50); outline: none; }
.user-menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--focus-ring); }
.user-menu-item .hint { margin-left: auto; }
.user-menu-item.danger, .user-menu-item.danger svg { color: var(--bad-700); }
.user-menu-item.danger:hover, .user-menu-item.danger:focus-visible { background: var(--bad-50); }
.user-menu-sep { height: 1px; margin: 6px 4px; background: var(--gray-150); border: 0; }
/* Badge sulle voci (es. aggiornamento disponibile) e pallino sull'avatar */
.user-menu-trigger { position: relative; }
.user-menu-dot {
  position: absolute; left: 30px; top: 3px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--warn-solid, var(--warn-600)); box-shadow: 0 0 0 2px var(--gray-0); pointer-events: none;
}
.user-menu-dot[hidden], .menu-badge[hidden] { display: none; }
.menu-badge {
  margin-left: auto; padding: 1px 8px; border-radius: 999px; background: var(--warn-100); color: var(--warn-800);
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.user-menu-foot { padding: 8px 10px 2px; margin-top: 6px; border-top: 1px solid var(--gray-150); color: var(--muted); font-size: 11px; text-align: right; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* Barra superiore delle pagine senza menu laterale (amministrazione) */
.topbar .user-menu-trigger { background: color-mix(in srgb, var(--gray-0) 85%, transparent); }

/* --- Notifiche toast --------------------------------------------------------------- */
.toast-stack {
  position: fixed; right: 20px; bottom: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 10px;
  width: min(400px, calc(100vw - 32px)); pointer-events: none;
}
.toast-item {
  position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start;
  padding: 12px 12px 14px; border: 1px solid var(--gray-200); border-left: 4px solid var(--tone-500); border-radius: 12px;
  background: var(--gray-0); color: var(--ink); box-shadow: 0 12px 32px rgba(0, 0, 0, .14);
  pointer-events: auto; overflow: hidden; animation: toast-in .2s var(--ease);
}
.toast-item.leaving { animation: toast-out .18s var(--ease) forwards; }
.toast-item .toast-icon { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--tone-100); color: var(--tone-700); }
.toast-item .toast-text { font-size: 13px; line-height: 1.45; white-space: pre-line; overflow-wrap: anywhere; padding-top: 2px; }
.toast-item .toast-close { border: 0; background: none; color: var(--muted); width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: 16px; line-height: 1; }
.toast-item .toast-close:hover { background: var(--gray-100); color: var(--ink); }
.toast-item .toast-progress { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: currentColor; opacity: .25; transform-origin: left; animation: toast-progress linear forwards; }
.toast-item.success { border-left-color: var(--ok-600); }
.toast-item.success .toast-icon { background: var(--ok-150); color: var(--ok-700); }
.toast-item.success .toast-progress { color: var(--ok-600); }
.toast-item.error { border-left-color: var(--bad-600); }
.toast-item.error .toast-icon { background: var(--bad-100); color: var(--bad-700); }
.toast-item.error .toast-progress { color: var(--bad-600); }
.toast-item.warning { border-left-color: var(--warn-500); }
.toast-item.warning .toast-icon { background: var(--warn-100); color: var(--warn-700); }
.toast-item.warning .toast-progress { color: var(--warn-500); }
.toast-item.info .toast-progress { color: var(--tone-500); }
.toast-item:hover .toast-progress { animation-play-state: paused; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@keyframes toast-progress { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (max-width: 600px) { .toast-stack { right: 16px; left: 16px; bottom: 16px; width: auto; } }

/* --- Skeleton loader ---------------------------------------------------------------- */
.skeleton-screen { display: grid; gap: 18px; }
.sk {
  display: block; border-radius: 8px;
  background: linear-gradient(90deg, var(--gray-150) 25%, var(--gray-100) 37%, var(--gray-150) 63%);
  background-size: 400% 100%; animation: sk-shimmer 1.3s ease infinite;
}
.sk-title { width: 260px; max-width: 70%; height: 26px; }
.sk-text { width: 420px; max-width: 90%; height: 13px; }
.sk-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.sk-stat { height: 96px; border-radius: 14px; }
.sk-panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.sk-panel { display: grid; gap: 12px; padding: 18px; border: 1px solid var(--gray-150); border-radius: 14px; background: var(--gray-0); }
.sk-row { height: 14px; }
.sk-row:nth-child(3n) { width: 75%; }
.sk-row:nth-child(3n+2) { width: 90%; }
.sk-table { display: grid; gap: 1px; border: 1px solid var(--gray-150); border-radius: 12px; overflow: hidden; background: var(--gray-150); }
.sk-table > div { height: 42px; background: var(--gray-0); display: flex; align-items: center; padding: 0 14px; }
.sk-table > div:first-child { background: var(--tone-100); }
.sk-table .sk { width: 100%; height: 12px; }
@keyframes sk-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (max-width: 800px) { .sk-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } .sk-panels { grid-template-columns: 1fr; } }

/* --- Ricerca rapida (Ctrl/Cmd + K) ---------------------------------------------------- */
.cmdk {
  width: min(640px, 94vw); max-height: min(560px, 80vh); padding: 0; border: 1px solid var(--gray-200); border-radius: 16px;
  background: var(--gray-0); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, .3); overflow: hidden; margin-top: 12vh;
}
.cmdk[open] { display: flex; flex-direction: column; }
.cmdk::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.cmdk-search { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--gray-150); }
.cmdk-search svg { color: var(--tone-700); flex-shrink: 0; }
.cmdk-search input { flex: 1; min-width: 0; min-height: 0; padding: 4px 0; border: 0; outline: none; background: transparent; color: var(--ink); font-size: 16px; }
.cmdk-search input:focus-visible { outline: none; }
.cmdk-list { flex: 1; overflow-y: auto; padding: 6px; margin: 0; list-style: none; }
.cmdk-group { padding: 10px 10px 4px; font-size: 11px; font-weight: 800; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
.cmdk-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.cmdk-item svg { color: var(--tone-700); flex-shrink: 0; }
.cmdk-item .cmdk-label { flex: 1; min-width: 0; }
.cmdk-item .cmdk-label strong { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item .cmdk-label small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item mark { background: var(--tone-150); color: inherit; border-radius: 3px; }
.cmdk-item[aria-selected="true"] { background: var(--tone-100); }
.cmdk-item[aria-selected="true"] .cmdk-enter { visibility: visible; }
.cmdk-enter { visibility: hidden; color: var(--muted); font-size: 12px; }
.cmdk-empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.cmdk-footer { display: flex; gap: 16px; flex-wrap: wrap; padding: 9px 16px; border-top: 1px solid var(--gray-150); color: var(--muted); font-size: 12px; background: var(--gray-50); }

/* --- Pannello "Personalizza interfaccia" ------------------------------------------- */
.theme-dialog { width: min(720px, 96vw); padding: 0; border: 0; border-radius: 18px; background: var(--gray-0); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, .3); }
.theme-dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
.theme-dialog form { display: flex; flex-direction: column; max-height: min(88vh, 860px); }
.theme-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--gray-150); background: var(--gradient-header); }
.theme-head h2 { margin: 0; font-size: 20px; color: var(--tone-800); }
.theme-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.theme-body { overflow-y: auto; padding: 18px 22px; display: grid; gap: 22px; }
.theme-section > h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.segmented { display: inline-grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 12px; background: var(--gray-100); border: 1px solid var(--gray-200); width: min(460px, 100%); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 10px; border-radius: 9px; font-size: 13px; font-weight: 700; color: var(--gray-700); cursor: pointer; }
.segmented input:checked + span { background: var(--gray-0); color: var(--tone-800); box-shadow: 0 2px 6px rgba(0, 0, 0, .1); }
.segmented input:focus-visible + span { outline: 3px solid var(--focus-ring); outline-offset: 1px; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.preset {
  display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 8px; border: 2px solid var(--gray-200); border-radius: 12px;
  background: var(--gray-0); color: var(--ink); cursor: pointer; text-align: left; font-weight: 700; font-size: 13px;
}
.preset:hover { border-color: var(--tone-300); }
.preset[aria-pressed="true"] { border-color: var(--tone-600); box-shadow: 0 0 0 3px var(--tone-100); }
.preset-swatch { display: block; width: 100%; height: 42px; border-radius: 8px; position: relative; overflow: hidden; }
.preset-swatch::after { content: ""; position: absolute; right: 8px; bottom: 8px; width: 16px; height: 16px; border-radius: 50%; background: var(--sw-secondary); border: 2px solid #fff; }
.preset .preset-name { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.preset .preset-check { visibility: hidden; color: var(--tone-700); }
.preset[aria-pressed="true"] .preset-check { visibility: visible; }
.color-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.color-field { display: grid; gap: 6px; }
.color-field > span { font-size: 13px; font-weight: 700; color: var(--gray-700); }
.color-input { display: flex; align-items: center; gap: 8px; padding: 6px; border: 1px solid var(--tone-200); border-radius: 10px; background: var(--gray-0); }
.color-input input[type="color"] { width: 44px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: none; cursor: pointer; flex-shrink: 0; min-height: 0; }
.color-input input[type="text"] { flex: 1; min-width: 0; min-height: 0; border: 0; padding: 6px 4px; background: transparent; color: var(--ink); font: 600 14px ui-monospace, Consolas, monospace; text-transform: lowercase; }
.color-input input[type="text"]:focus-visible { outline: none; }
.color-input:focus-within { border-color: var(--tone-500); box-shadow: 0 0 0 3px var(--tone-100); }
.color-field small { color: var(--muted); font-size: 12px; }

.theme-preview { display: grid; grid-template-columns: 180px 1fr; gap: 0; border: 1px solid var(--gray-200); border-radius: 14px; overflow: hidden; min-height: 150px; }
.theme-preview .pv-side { background: var(--gradient-sidebar); padding: 12px; display: grid; gap: 8px; align-content: start; }
.theme-preview .pv-nav { padding: 9px 10px; border-radius: 9px; font-size: 12px; font-weight: 700; background: linear-gradient(130deg, var(--primary), var(--primary-strong)); color: var(--on-primary); }
.theme-preview .pv-nav.active { background: linear-gradient(130deg, var(--secondary), var(--secondary-strong)); color: var(--on-secondary); box-shadow: inset 4px 0 0 var(--accent); }
.theme-preview .pv-main { background: var(--gradient-bg); padding: 14px; display: grid; gap: 10px; align-content: start; }
.theme-preview .pv-card { background: var(--gray-0); border: 1px solid var(--tone-200); border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.theme-preview .pv-card strong { color: var(--tone-800); }
.theme-preview .pv-th { background: linear-gradient(var(--secondary), var(--secondary-strong)); color: var(--on-secondary); border-radius: 8px; padding: 7px 10px; font-size: 12px; font-weight: 700; }
.theme-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 22px; border-top: 1px solid var(--gray-150); background: var(--gray-0); }
.theme-foot .tools { display: flex; gap: 8px; }
@media (max-width: 600px) {
  .color-fields { grid-template-columns: 1fr; }
  .theme-preview { grid-template-columns: 1fr; }
  .theme-preview .pv-side { grid-template-columns: 1fr 1fr; }
}

/* --- Schermi stretti: intestazione compatta ---------------------------------------- */
@media (max-width: 900px) {
  .user-menu-trigger .who, .user-menu-trigger .chevron { display: none; }
  .user-menu-trigger { padding: 3px; }
  .quick-search-btn .label, .quick-search-btn kbd { display: none; }
  .quick-search-btn { padding: 0 10px; }
}

/* --- Movimento ridotto e stampa ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media print {
  .header-tools, .toast-stack, .user-menu, .cmdk, .theme-dialog { display: none !important; }
}

/* Testo solo per lettori di schermo */
.sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* --- Campanella delle notifiche ---------------------------------------------------- */
.notif-center { position: relative; }
.bell-btn {
  position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--tone-200); background: var(--gray-0); color: var(--tone-800); cursor: pointer;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.bell-btn:hover, .bell-btn[aria-expanded="true"] { border-color: var(--tone-400); box-shadow: 0 0 0 3px var(--tone-100); }
.bell-btn.urgent svg { animation: bell-ring 1.6s ease 2; transform-origin: 50% 10%; }
.bell-count {
  position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px;
  background: var(--warn-600); color: var(--gray-0); font: 700 11px/20px var(--font-ui); text-align: center; border: 2px solid var(--gray-0);
}
.bell-btn.urgent .bell-count { background: var(--bad-600); }
.notif-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; width: 380px; max-width: calc(100vw - 24px); max-height: min(70vh, 560px);
  display: flex; flex-direction: column; border: 1px solid var(--gray-200); border-radius: 14px; background: var(--gray-0); color: var(--ink);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .16); animation: menu-in .14s var(--ease); overflow: hidden;
}
.notif-panel[hidden] { display: none; }
.notif-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--gray-150); }
.notif-head > span { padding: 1px 8px; border-radius: 999px; background: var(--tone-100); color: var(--tone-800); font-size: 12px; font-weight: 700; }
.notif-head .btn { margin-left: auto; }
.notif-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.notif-item { display: flex; gap: 10px; width: 100%; padding: 10px; border: 0; border-radius: 10px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.notif-item:hover, .notif-item:focus-visible { background: var(--tone-50); }
.notif-item .notif-dot { width: 10px; height: 10px; margin-top: 4px; border-radius: 50%; flex-shrink: 0; background: var(--warn-500); }
.notif-item.red .notif-dot { background: var(--bad-600); }
.notif-item.unseen { background: color-mix(in srgb, var(--tone-50) 70%, transparent); }
.notif-body strong { display: block; font-size: 13px; }
.notif-body small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.notif-empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.notif-empty svg { color: var(--ok-600); }
@keyframes bell-ring { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(14deg); } 30% { transform: rotate(-12deg); } 45% { transform: rotate(8deg); } 60% { transform: rotate(-4deg); } }

/* --- Stato del collegamento in tempo reale ---------------------------------------- */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--gray-400); vertical-align: middle; }
.live-dot.on { background: var(--ok-600); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok-600) 25%, transparent); }

/* --- Toast: pulsante d'azione (es. Annulla) -------------------------------------- */
.toast-action {
  display: inline-block; margin-left: 8px; padding: 2px 10px; border: 1px solid currentColor; border-radius: 7px;
  background: transparent; color: var(--tone-800); font-weight: 700; font-size: 12px; cursor: pointer;
}
.toast-action:hover { background: var(--tone-50); }

/* --- Profilo -------------------------------------------------------------------------- */
.user-avatar.xl { width: 84px; height: 84px; font-size: 28px; }
.profile-identity { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.profile-photo-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.profile-photo-actions small { flex-basis: 100%; color: var(--muted); font-size: 12px; }
.profile-input { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--tone-200); border-radius: 8px; background: var(--gray-0); color: var(--ink); }
.profile-error { color: var(--bad-700); min-height: 1em; margin: 8px 0 0; font-size: 13px; }
.profile-check { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; cursor: pointer; }
.profile-check input { width: 20px; height: 20px; min-height: 0; margin-top: 2px; accent-color: var(--tone-700); }
.profile-check small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.segmented.two { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }

/* --- Densita' compatta ------------------------------------------------------------ */
:root[data-density="compact"] td { padding-top: 5px; padding-bottom: 5px; }
:root[data-density="compact"] th { padding-top: 7px; padding-bottom: 7px; }
:root[data-density="compact"] .table-wrap table th, :root[data-density="compact"] .table-wrap table td { padding-top: 5px; padding-bottom: 5px; }

:root[data-density="compact"] .stat { padding: 12px 14px; }
:root[data-density="compact"] .nav button { min-height: 42px; padding-top: 8px; padding-bottom: 8px; }

:root[data-density="compact"] .panel { padding: 14px; }

/* --- Banner della licenza (tutte le pagine: js/license-banner.js) ------------------------ */
.license-banner {
  position: sticky; top: 0; z-index: 1500; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; font-size: 14px; line-height: 1.4; border-bottom: 1px solid transparent;
}
.license-banner.warn { background: var(--warn-100); color: var(--warn-800, var(--warn-700)); border-color: var(--warn-200, var(--warn-150)); }
.license-banner.bad { background: var(--bad-100); color: var(--bad-800, var(--bad-600)); border-color: var(--bad-200); }
.license-banner-icon { display: inline-flex; flex-shrink: 0; }
.license-banner-text { flex: 1; min-width: 0; }
.license-banner a { color: inherit; font-weight: 700; text-decoration: underline; white-space: nowrap; }
.license-banner-close {
  display: inline-flex; flex-shrink: 0; padding: 6px; border: 0; border-radius: 6px; background: transparent; color: inherit; cursor: pointer;
}
.license-banner-close:hover { background: rgba(0, 0, 0, .08); }
.license-banner a:focus-visible, .license-banner-close:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
@media print { .license-banner { display: none !important; } }

/* --- Avvisi di sistema (tutte le pagine: js/system-notice.js), es. aggiornamento in arrivo -------- */
.system-banner {
  position: sticky; top: 0; z-index: 1501; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; font-size: 14px; line-height: 1.4; border-bottom: 1px solid transparent;
}
.system-banner.warn { background: var(--warn-100); color: var(--warn-800, var(--warn-700)); border-color: var(--warn-200, var(--warn-150)); }
.system-banner.info { background: var(--tone-100); color: var(--tone-900); border-color: var(--tone-200); }
.system-banner.ok { background: var(--ok-100); color: var(--ok-800, var(--ok-700)); border-color: var(--ok-200); }
.system-banner-icon { display: inline-flex; flex-shrink: 0; }
.system-banner-text { flex: 1; min-width: 200px; }
.system-banner-count { font-variant-numeric: tabular-nums; }
.system-banner-action { flex-shrink: 0; }
@media print { .system-banner { display: none !important; } }

/* Utenti collegati (admin.js, sezione "Collegati") */
.online-summary { display: flex; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; }
.online-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--ok-700); vertical-align: middle; }
.online-dot.recent { background: var(--tone-700); opacity: .6; }
.install-online { margin: 12px 0; }
.install-online ul { margin: 6px 0 0; padding-left: 20px; }
.install-delay { display: flex; gap: 16px; flex-wrap: wrap; margin: 6px 0 12px; border: 0; padding: 0; }
.install-delay legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.install-delay label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* --- Logo caricabile (js/branding.js): immagini di qualsiasi proporzione restano contenute --- */
img[src^="/branding/logo"] { object-fit: contain; }
.sidebar-brand .brand-logo, .card-logo { max-height: 110px; }
html[data-sidebar="compact"] .sidebar-brand .brand-logo { max-height: 48px; }

.branding-editor { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.branding-preview { width: 220px; min-height: 110px; display: grid; place-items: center; padding: 12px; border: 1px dashed var(--tone-300); border-radius: 12px; background: #fff; }
.branding-preview img { max-width: 100%; max-height: 120px; }
.branding-text { flex: 1; min-width: 240px; }
.branding-text p { margin: 0 0 10px; }
.branding-meta { color: var(--muted); font-size: 12.5px; }
.branding-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Verifica in due passaggi (mfa-panel.js): stili propri, validi in tutte le pagine ---- */
.mfa-dialog { width: min(600px, 96vw); }
.mfa-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 40px; padding: 8px 15px;
  border: 1px solid var(--tone-200); border-radius: 10px; background: var(--gray-0); color: var(--tone-800);
  font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.mfa-btn:hover { background: var(--tone-50); border-color: var(--tone-300); }
.mfa-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.mfa-btn:disabled { opacity: .55; cursor: not-allowed; }
.mfa-btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-strong)); border-color: var(--primary-strong); color: var(--on-primary); }
.mfa-btn.primary:hover { background: linear-gradient(135deg, var(--primary-hover), var(--primary-hover-strong)); color: var(--on-primary-hover); }
.mfa-btn.danger { background: var(--bad-50); border-color: var(--bad-200); color: var(--bad-700); }
.mfa-btn.gray { color: var(--gray-700); }
.mfa-btn.small { min-height: 32px; padding: 5px 11px; font-size: 13px; }
.mfa-btn.icon { width: 38px; padding: 7px; }
.mfa-state { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: 12px; }
.mfa-state strong { display: block; font-size: 16px; }
.mfa-state small { color: var(--muted); font-size: 13px; }
.mfa-state.on { background: var(--ok-150); color: var(--ok-800); }
.mfa-state.off { background: var(--tone-50); color: var(--tone-800); border: 1px solid var(--tone-150); }
.mfa-text { margin: 0 0 10px; font-size: 14px; line-height: 1.5; }
.mfa-text.warn { padding: 10px 12px; border-radius: 10px; background: var(--warn-100); color: var(--warn-700); }
.mfa-setup { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.mfa-setup > div { flex: 1 1 220px; }
.mfa-qr { width: 200px; height: 200px; border-radius: 10px; border: 1px solid var(--tone-200); background: #fff; image-rendering: pixelated; }
.mfa-key { display: inline-block; padding: 6px 10px; border-radius: 8px; background: var(--tone-50); border: 1px solid var(--tone-150); font-size: 14px; letter-spacing: .06em; word-break: break-all; }
.mfa-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-width: 340px; }
.mfa-field span { font-size: 13px; font-weight: 700; color: var(--gray-700); }
.mfa-field input { min-height: 42px; padding: 8px 10px; border: 1px solid var(--tone-200); border-radius: 8px; background: var(--gray-0); color: var(--ink); font: inherit; }
.mfa-field input.mfa-code { font-size: 20px; letter-spacing: .15em; }
.mfa-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; margin: 0 0 12px; padding: 12px 12px 12px 34px; border-radius: 10px; background: var(--tone-50); border: 1px solid var(--tone-150); }
.mfa-codes code { font-size: 16px; letter-spacing: .06em; }
.mfa-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.mfa-check { display: flex; gap: 10px; align-items: center; font-weight: 700; cursor: pointer; }
.mfa-check input { width: 18px; height: 18px; accent-color: var(--tone-700); }
.mfa-error { color: var(--bad-700); min-height: 1em; margin: 0; font-size: 13px; }
.mfa-error:empty { display: none; }
@media (max-width: 520px) { .mfa-codes { grid-template-columns: 1fr; } .mfa-qr { width: 100%; height: auto; max-width: 240px; } }
.badge-2fa { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 5px; font-size: 10px; font-weight: 800; letter-spacing: .4px; background: var(--ok-150); color: var(--ok-800); vertical-align: 1px; }

/* =====================================================================================
   A. Tipografia: font di sistema dell'apparecchio (Segoe UI su Windows, San Francisco su
   iPhone/Mac, Roboto su Android) e cifre a larghezza fissa dove si confrontano numeri.
   ===================================================================================== */
:root {
  /* Senza "system-ui": su Linux puo' indicare un font privo del grassetto (lo evita anche GitHub) */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Liberation Sans", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
h1, h2, h3 { letter-spacing: -0.012em; }
table, .stat-value, .nav-number, .num, .numeric, .badge, kbd, time {
  font-variant-numeric: tabular-nums;
}
code, kbd, .mfa-key, .mfa-codes code { font-family: var(--font-mono); }

/* =====================================================================================
   E. Modalita' scura morbida: il logo (spesso su fondo bianco) sta su un fondo chiaro ma non
   bianco pieno, leggermente attenuato; le scale "morbide" sono generate da theme.js.
   ===================================================================================== */
@media screen {
  :root[data-theme="dark"] .sidebar-brand { background: #e3e7e8; border-color: var(--gray-300); }
  :root[data-theme="dark"] .sidebar-brand > span { color: #46555a; }
  :root[data-theme="dark"] .sidebar-brand img,
  :root[data-theme="dark"] .card-logo{ filter: brightness(.9); }
  :root[data-theme="dark"] .card-logo { background: #e3e7e8; }
}

/* --- Trascina in basso per aggiornare (pull-refresh.js, solo telefoni) ----------------------------------- */
html.pull-refresh-on, html.pull-refresh-on body { overscroll-behavior-y: contain; }
.pull-indicator {
  position: fixed; top: -44px; left: 50%; z-index: 2000; transform: translate(-50%, 0); display: none; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px; background: var(--gray-0); color: var(--tone-800); border: 1px solid var(--tone-300);
  box-shadow: var(--shadow); font-size: 13px; font-weight: 700; pointer-events: none;
}
.pull-indicator.show { display: inline-flex; }
.pull-indicator.busy { transform: translate(-50%, 64px); }
.pull-spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--tone-200); border-top-color: var(--tone-600); }
.pull-indicator.ready .pull-spinner { border-color: var(--tone-600); }
.pull-indicator.busy .pull-spinner { animation: pull-spin .8s linear infinite; }
@keyframes pull-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .pull-indicator.busy .pull-spinner { animation: none; } }
@media print { .pull-indicator { display: none !important; } }
