/* NH — theme-vars.css
 * Override tema (light/dark) globale per TUTTE le pagine, anche quelle che
 * dichiarano solo valori dark in :root senza override light.
 *
 * Strategia:
 *   1) Ridefinire tutte le CSS custom properties principali in due blocchi
 *      (light / dark) con specificità html[data-theme="x"] > :root.
 *   2) Forzare body + input/select/textarea/button a usare le custom properties
 *      con !important, così il tema funziona anche se la pagina ha style
 *      inline diretti (background:#0f172a etc.).
 *   3) color-scheme coerente per la UI nativa (scrollbar, form controls).
 *
 * Include come ULTIMA risorsa CSS nel <head>:
 *   <link rel="stylesheet" href="/shared/theme-vars.css">
 * ========================================================================== */

/* ░░ FONT SELF-HOSTED exoCortex (WebObject) · Sprint 2 (2026-11-01) ░░
 * Sora (display), Inter (body), JetBrains Mono (codici/ID). Niente Google Fonts in prod.
 * woff2 subset (latin/latin-ext) in /shared/fonts/. Inter/Sora variabili (un file = tutti i pesi). */
@font-face{ font-family:"Inter"; font-style:normal; font-weight:100 900; font-display:swap;
  src:url("/shared/fonts/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face{ font-family:"Inter"; font-style:normal; font-weight:100 900; font-display:swap;
  src:url("/shared/fonts/inter-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face{ font-family:"Sora"; font-style:normal; font-weight:100 800; font-display:swap;
  src:url("/shared/fonts/sora-latin-wght-normal.woff2") format("woff2");
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face{ font-family:"Sora"; font-style:normal; font-weight:100 800; font-display:swap;
  src:url("/shared/fonts/sora-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
@font-face{ font-family:"JetBrains Mono"; font-style:normal; font-weight:400; font-display:swap;
  src:url("/shared/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

/* ────────────────────── PALETTE LIGHT ──────────────────────────────────── */
html[data-theme="light"] {
  color-scheme: light;

  /* Sfondi */
  --bg:         #f3f5f8;
  --bg-2:       #ffffff;
  --bg-3:       #eef2f6;
  --bg-4:       #e5e9f0;

  /* Testo */
  --text:       #0f172a;
  --text-1:     #0f172a;
  --text-2:     #475569;
  --text-3:     #64748b;
  --text-4:     #94a3b8;
  --text-dim:   #6b7280;

  /* Bordi / ombre */
  --border:     #d9dee4;
  --border-hi:  #94a3b8;
  --shadow:     0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-sm:  0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-lg:  0 8px 24px rgba(15, 23, 42, 0.12);

  /* Superfici */
  --surface:    #ffffff;
  --surface-2:  #f8fafc;
  --surface-3:  #eef2f6;

  /* Accenti — Sprint 2 recolor: azione = brand WebObject (indaco). */
  --accent:     var(--brand);
  --blue:       var(--brand);
  --blue-2:     var(--brand-hover);
  --blue-dim:   var(--brand-tint);
  /* Tinte categoriche: WebObject non le definisce → invariate (palette chart/KPI). */
  --violet:     #7c3aed;
  --purple:     #7c3aed;
  --pink:       #db2777;
  --cyan:       #0891b2;
  --teal:       #0d9488;
  --green:      #157F3B;
  --amber:      #A14A06;
  --red:        #C62828;

  /* Stati — valori semantici WebObject. */
  --success:    #157F3B;
  --warn:       #A14A06;
  --warning:    #A14A06;
  --danger:     #C62828;
  --error:      #C62828;
  --info:       var(--brand);

  --glow:       color-mix(in srgb, var(--brand) 18%, transparent);
  --hero-bg:    linear-gradient(135deg, #e0e7ff 0%, #f3f5f8 60%, #dbeafe 100%);
  /* Testo sopra l'hero: in light il bg è chiaro → scritte scure */
  --hero-text:       #0f172a;
  --hero-text-muted: #334155;
  --hero-text-dim:   #475569;
  --hero-border:     rgba(15,23,42,.12);
  --hero-surface:    rgba(255,255,255,.55);

  /* ░░ PRIMITIVE BRAND exoCortex (WebObject) — LIGHT · Sprint 1 (2026-11-01) ░░
   * Vocabolario del brand (fonte: webObject/Stile exoCortex/tokens.css).
   * SOLO nomi NUOVI: non ancora consumati dal CSS esistente → nessun cambio visivo.
   * Lo "switch" (es. --accent/--blue → var(--brand)) avviene nello Sprint 2. */
  --brand:            #3B3BD9;
  --brand-hover:      #2A2AA8;
  --brand-tint:       #ECECFD;
  --on-brand:         #FFFFFF;
  --human:            #FF6A45;
  --human-text:       #C2401C;
  --human-tint:       #FFF0EB;
  --ink:              #0E1530;
  --ink-muted:        #4A5170;
  --ink-subtle:       #626885;
  --ink-inverse:      #FFFFFF;
  --surface-alt:      #F5F6FA;
  --surface-sunken:   #ECEEF5;
  --surface-inverse:  #0E1530;
  --border-control:   #8A90A8;
  --focus-ring:       #3B3BD9;
  --success-tint:     #E8F5EC;
  --warning-tint:     #FFF4E5;
  --danger-tint:      #FDECEC;
  --shadow-md:        0 8px 24px rgba(14,21,48,0.10);
}

/* ────────────────────── PALETTE DARK ───────────────────────────────────── */
html[data-theme="dark"] {
  color-scheme: dark;

  --bg:         #0f172a;
  --bg-2:       #1e293b;
  --bg-3:       #334155;
  --bg-4:       #475569;

  --text:       #f1f5f9;
  --text-1:     #f1f5f9;
  --text-2:     #cbd5e1;
  --text-3:     #94a3b8;
  --text-4:     #64748b;
  --text-dim:   #94a3b8;

  --border:     #334155;
  --border-hi:  #64748b;
  --shadow:     0 24px 60px -12px rgba(0, 0, 0, 0.4), 0 8px 20px -8px rgba(0, 0, 0, 0.3);
  --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg:  0 30px 70px -12px rgba(0, 0, 0, 0.6);

  --surface:    #1e293b;
  --surface-2:  #0f172a;
  --surface-3:  #334155;

  /* Accenti — Sprint 2 recolor: azione = brand WebObject (indaco chiaro). */
  --accent:     var(--brand);
  --blue:       var(--brand);
  --blue-2:     var(--brand-hover);
  --blue-dim:   var(--brand-tint);
  /* Tinte categoriche: WebObject non le definisce → invariate. */
  --violet:     #a78bfa;
  --purple:     #8b5cf6;
  --pink:       #f472b6;
  --cyan:       #22d3ee;
  --teal:       #2dd4bf;
  --green:      #4ADE80;
  --amber:      #FBBF24;
  --red:        #F87171;

  --success:    #4ADE80;
  --warn:       #FBBF24;
  --warning:    #FBBF24;
  --danger:     #F87171;
  --error:      #F87171;
  --info:       var(--brand);

  --glow:       color-mix(in srgb, var(--brand) 25%, transparent);
  --hero-bg:    linear-gradient(135deg, #1e1b4b 0%, #0b1220 60%, #172554 100%);
  /* Testo sopra l'hero: in dark il bg è scuro → scritte chiare */
  --hero-text:       #f1f5f9;
  --hero-text-muted: #cbd5e1;
  --hero-text-dim:   #94a3b8;
  --hero-border:     rgba(255,255,255,.08);
  --hero-surface:    rgba(255,255,255,.04);

  /* ░░ PRIMITIVE BRAND exoCortex (WebObject) — DARK · Sprint 1 (2026-11-01) ░░
   * Valori dark da webObject/Stile exoCortex/tokens.css. SOLO nomi nuovi. */
  --brand:            #8C8CFF;
  --brand-hover:      #A9A9FF;
  --brand-tint:       #1C2150;
  --on-brand:         #0B1124;
  --human:            #FF6A45;
  --human-text:       #FF8A6B;
  --human-tint:       #3A1E16;
  --ink:              #F2F4FA;
  --ink-muted:        #B8BED6;
  --ink-subtle:       #8F96B3;
  --ink-inverse:      #0E1530;
  --surface-alt:      #121A38;
  --surface-sunken:   #0E1530;
  --surface-inverse:  #F2F4FA;
  --border-control:   #5E6890;
  --focus-ring:       #A9A9FF;
  --success-tint:     #0F2A1C;
  --warning-tint:     #2E2410;
  --danger-tint:      #3A1517;
  --shadow-md:        0 8px 24px rgba(0,0,0,0.5);
}

/* ────────────────────── FORZATURE GLOBALI ──────────────────────────────── */
/* Assicurano il tema anche su pagine con colori hardcoded. !important è
   necessario perché alcune pagine (soc/xdr/icc/grc/ops) dichiarano `body { background: #0f172a }`
   direttamente senza custom property. */
html[data-theme="light"] body,
html[data-theme="dark"]  body {
  background: var(--bg) !important;
  color: var(--text-1) !important;
  transition: background-color .15s ease, color .15s ease;
}

/* Form controls — devono adattarsi al tema anche quando la pagina non li tematizza. */
html[data-theme="light"] input:not([type="color"]):not([type="range"]):not([type="checkbox"]):not([type="radio"]),
html[data-theme="light"] select,
html[data-theme="light"] textarea {
  background-color: var(--surface);
  color: var(--text-1);
  border-color: var(--border);
}
html[data-theme="dark"] input:not([type="color"]):not([type="range"]):not([type="checkbox"]):not([type="radio"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background-color: var(--surface-2);
  color: var(--text-1);
  border-color: var(--border);
}
html[data-theme="light"] input::placeholder,
html[data-theme="light"] textarea::placeholder { color: var(--text-3); }
html[data-theme="dark"]  input::placeholder,
html[data-theme="dark"]  textarea::placeholder { color: var(--text-4); }

/* Scrollbar chrome-style coerente */
html[data-theme="dark"] *::-webkit-scrollbar-track   { background: #0f172a; }
html[data-theme="dark"] *::-webkit-scrollbar-thumb   { background: #334155; border-radius: 4px; }
html[data-theme="light"] *::-webkit-scrollbar-track  { background: #f1f5f9; }
html[data-theme="light"] *::-webkit-scrollbar-thumb  { background: #cbd5e1; border-radius: 4px; }

/* ░░ TIPOGRAFIA BRAND (WebObject) applicata globalmente · Sprint 2 (2026-11-01) ░░
 * body = Inter, titoli h1–h4 = Sora, codici/ID = JetBrains Mono.
 * Specificità html[data-theme] (non !important) → vince le regole di pagina per
 * elemento/classe, ma una pagina può sempre sovrascrivere con specificità maggiore. */
html[data-theme] body { font-family: var(--font-body); }
html[data-theme] h1, html[data-theme] h2, html[data-theme] h3, html[data-theme] h4 { font-family: var(--font-display); }
html[data-theme] code, html[data-theme] kbd, html[data-theme] samp, html[data-theme] pre, html[data-theme] .mono { font-family: var(--font-mono); }

/* ─── NH Uniform Topbar / Breadcrumb (global) ─────────────────────────────
 * Normalizza tipografia del brand e del link "Home" su tutte le pagine.
 * Applicato via theme-vars.css → incluso in tutte le pagine.
 */
.topbar .brand,
.topbar .logo,
header .brand,
header .logo {
  font-weight: 700 !important;
  font-size: 15px !important;
  letter-spacing: -0.01em;
}

/* Link "Home" nelle breadcrumb: sempre stessa dimensione, grassetto, accento */
.crumb a,
.breadcrumb a,
.topbar .crumb a {
  font-weight: 700 !important;
  font-size: 13px !important;
  text-decoration: none;
  cursor: pointer;
}
.crumb strong,
.breadcrumb strong,
.topbar .crumb strong {
  font-weight: 700 !important;
  font-size: 13px !important;
}

/* ════════════════════════════════════════════════════════════════════════
   NH Z-INDEX SCALE 2026-05-30 (Z-SCALE-S1)
   ════════════════════════════════════════════════════════════════════════
   Scala binaria — NON inventare valori intermedi.
   Bug ricorrenti causati da z-index hardcoded: questa scala è la SoT.

   Layer base       (0–99)     · UI inline · stacking minore
   --nh-z-base        : 1
   --nh-z-elevated    : 5
   --nh-z-sticky      : 50      · sticky header, sidebar
   --nh-z-dropdown    : 100     · menu a tendina, select custom
   --nh-z-tooltip     : 500     · tooltip, hover popover
   --nh-z-fixed-bar   : 1000    · toolbar fissa, bottom-dock

   Layer overlay    (5000–9999) · feedback UI
   --nh-z-toast       : 9000    · toast notifications
   --nh-z-loader      : 9500    · spinner full-screen

   Layer modal      (10000–10999) · modali di prima generazione
   --nh-z-modal-base  : 10500   · modal standard (es. dettaglio utente)
   --nh-z-modal-edit  : 10600   · modal edit / form
   --nh-z-modal-confirm:10700   · confirm dialog (sopra edit)

   Layer overlay-top (11000–11999) · azioni distruttive / chiavi
   --nh-z-modal-overlay:11000   · password reveal, integrity check
   --nh-z-modal-critical:11500  · DELETE confirm "type ID"

   Layer alert       (12000)    · errori/alert bloccanti SOPRA ogni modal/drawer
   --nh-z-alert       : 12000   · NHAlert (segnalazioni errore con OK, sempre in primo piano)

   Layer system     (≥99000)    · solo casi eccezionali documentati
   --nh-z-emergency   : 99000   · debug overlay, crash reporter

   Regola d'oro: una modal aperta DA UN'ALTRA modal deve avere z-index ≥
   z-index del genitore + 100. Usa la scala, non inventare.
*/
:root {
  --nh-z-base:           1;
  --nh-z-elevated:       5;
  --nh-z-sticky:         50;
  --nh-z-dropdown:       100;
  --nh-z-tooltip:        500;
  --nh-z-fixed-bar:      1000;
  --nh-z-toast:          9000;
  --nh-z-loader:         9500;
  --nh-z-modal-base:     10500;
  --nh-z-modal-edit:     10600;
  --nh-z-modal-confirm:  10700;
  --nh-z-modal-overlay:  11000;
  --nh-z-modal-critical: 11500;
  --nh-z-alert:          12000;
  --nh-z-emergency:      99000;
}

/* ░░ PRIMITIVE BRAND exoCortex (WebObject) — TEMA-INDIPENDENTI · Sprint 1 (2026-11-01) ░░
 * Tipografia, griglia 4px, raggi, altezze controlli, durate (fonte: webObject tokens.css).
 * Strutturali app (--sidebar-width/--topbar-height/--control-height-sm) allineati ai
 * valori VIVI delle dashboard (sidebar 220px, topbar 52px). SOLO nomi nuovi → nessun
 * cambio visivo: nessuna regola esistente li consuma ancora (wiring negli Sprint 2–3). */
:root {
  --font-display:  Sora, Inter, "Noto Sans", system-ui, sans-serif;
  --font-body:     Inter, "Noto Sans", system-ui, sans-serif;
  --font-mono:     "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px; --space-5: 24px;
  --space-6: 32px; --space-7: 48px; --space-8: 64px; --space-9: 96px; --space-10: 128px;

  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 16px; --radius-xl: 24px; --radius-pill: 999px;

  --control-height:    48px;
  --control-height-sm: 36px;
  --sidebar-width:     220px;
  --topbar-height:     52px;

  --duration-fast: 120ms;
  --duration-base: 200ms;
}

/* 🆕 2026-07-28 — Campi OBBLIGATORI (standard globale, tutti i portali): etichetta rossa + ✱ davanti.
   Marcatore: attributo [data-required] sull'etichetta. Applicato dai renderer condivisi
   (nh-new-ticket, nh-dynamic-fields) e progressivamente dai form a mano. */
[data-required]::before{ content:"✱ "; color:var(--danger,#dc2626); font-weight:700; }
[data-required]{ color:var(--danger,#dc2626) !important; }

/* ═══════════════════════════════════════════════════════════════════════════
 * MODAL SHELL condiviso (W0 · 2026-09-26) — layout a 3 fasce: header e footer
 * SEMPRE visibili, scorre SOLO il corpo. Le modal adottano queste classi
 * (.nhm-dialog > .nhm-head + .nhm-body + .nhm-foot) o l'helper NHM.shell().
 * SoT unica del comportamento header/footer-fissi (usabilità pulsanti).
 * ═══════════════════════════════════════════════════════════════════════════ */
.nhm-modal{ position:fixed; inset:0; background:rgba(15,23,42,.55); display:flex; align-items:center; justify-content:center; padding:20px; z-index:9000; }
.nhm-dialog{ background:var(--surface,#fff); color:var(--text-1,#0f172a); border:1px solid var(--border,#e2e8f0); border-radius:14px;
  width:100%; max-width:640px; max-height:88vh; display:flex; flex-direction:column; overflow:hidden; box-shadow:0 24px 64px rgba(0,0,0,.30); }
.nhm-head{ flex:0 0 auto; display:flex; align-items:center; gap:10px; padding:14px 18px; border-bottom:1px solid var(--border,#e2e8f0); background:var(--surface,#fff); }
.nhm-head .nhm-title{ font-size:16px; font-weight:800; flex:1; min-width:0; }
.nhm-head .nhm-x{ border:0; background:transparent; color:var(--text-3,#64748b); font-size:22px; line-height:1; cursor:pointer; padding:0 4px; }
.nhm-body{ flex:1 1 auto; overflow:auto; padding:16px 18px; -webkit-overflow-scrolling:touch; overscroll-behavior:contain; }
.nhm-foot{ flex:0 0 auto; display:flex; gap:8px; justify-content:flex-end; align-items:center; padding:12px 18px; border-top:1px solid var(--border,#e2e8f0); background:var(--surface,#fff); }
/* feedback "c'è altro da scorrere" (attivato da NHM.wireBodyShadows) */
.nhm-body.is-scrolled-top{ box-shadow:inset 0 8px 8px -8px rgba(0,0,0,.18); }
.nhm-body.is-scrolled-bot{ box-shadow:inset 0 -8px 8px -8px rgba(0,0,0,.18); }
.nhm-body.is-scrolled-top.is-scrolled-bot{ box-shadow:inset 0 8px 8px -8px rgba(0,0,0,.18), inset 0 -8px 8px -8px rgba(0,0,0,.18); }
/* larghezze opzionali */
.nhm-dialog.nhm-sm{ max-width:440px; } .nhm-dialog.nhm-lg{ max-width:860px; } .nhm-dialog.nhm-xl{ max-width:1100px; }
/* mobile: quasi full-screen con gutter */
@media (max-width:560px){
  .nhm-modal{ padding:0; align-items:stretch; }
  .nhm-dialog{ max-width:none; max-height:100vh; height:100vh; border-radius:0; }
}
