/* ==========================================================================
   tokens.css — fondamenta condivise fra vetrina e dashboard
   ellemservice.it

   Contiene: variabili di tema, reset, tipografia, e i componenti di base
   (bottoni, campi, badge, avvisi). Sia landing.css sia app.css danno per
   scontato che questo file sia già stato caricato.

   I nomi delle variabili sono gli stessi di portal.css del portale UMGCZ:
   è quel che permetterà alla dashboard della fase 4 di riusarne i
   componenti quasi alla lettera.
   ========================================================================== */


/* ==========================================================================
   1. IDENTITÀ VISIVA — l'unico blocco da cambiare per rifare il marchio
   --------------------------------------------------------------------------
   SEGNAPOSTO: palette presa dal portale di riferimento, in attesa dei colori
   veri. Per cambiarla basta riscrivere queste sei righe: tutto il resto è
   derivato e si adegua da solo, tema scuro compreso.
   ========================================================================== */
:root {
  --brand:        #0848ca;   /* colore principale: bottoni, link, accenti   */
  --brand-dark:   #06349a;   /* stato premuto / hover del principale        */
  --brand-light:  #e8edfd;   /* sfondi tenui, evidenziazioni                */
  --gold:         #fcb205;   /* accento secondario — MAI per testo su bianco */
  --gold-dark:    #d99700;   /* variante del secondario leggibile su chiaro */
  --ink:          #141414;   /* nero del testo                              */

  /* Nome che compare nel marchio in alto a sinistra. SEGNAPOSTO. */
  --brand-mark-text: "ES";
}


/* ==========================================================================
   2. Token derivati — tema chiaro
   ========================================================================== */
:root {
  --bg:            #f4f6fb;
  --surface:       #ffffff;
  --surface-alt:   #f8fafc;
  --surface-sunk:  #eef2f9;

  --text:          var(--ink);
  --text-muted:    #5e6b7f;
  --text-onbrand:  #ffffff;

  --border:        #e2e8f2;
  --border-strong: #cbd5e6;

  --ok:      #1f8a4c;  --ok-bg:     #e6f5ec;
  --warn:    #b26a00;  --warn-bg:   #fdf2df;
  --danger:  #c02626;  --danger-bg: #fdeaea;
  --info:    #1f6699;  --info-bg:   #e7f1f9;

  --accent-blue:   #0848ca;
  --accent-teal:   #0d8a8a;
  --accent-violet: #6b3fc4;
  --accent-amber:  #d99700;
  --accent-rose:   #c0316b;
  --accent-green:  #1f8a4c;

  --radius:      10px;
  --radius-sm:    6px;
  --radius-lg:   18px;

  --shadow:     0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg:  0 8px 28px rgba(16, 24, 40, .12);
  --shadow-xl:  0 18px 50px rgba(16, 24, 40, .16);

  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", "Liberation Mono", monospace;

  --header-h:  68px;
  --measure:   68ch;   /* larghezza massima leggibile di un paragrafo */
  --container: 1180px;
}


/* ==========================================================================
   3. Tema scuro
   --------------------------------------------------------------------------
   Due blocchi identici di proposito: il primo segue la preferenza di sistema
   ma si tira indietro se l'utente ha scelto "chiaro"; il secondo vale quando
   l'utente ha scelto "scuro" a prescindere dal sistema.
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0e1420;
    --surface:       #161d2c;
    --surface-alt:   #1c2434;
    --surface-sunk:  #111827;
    --brand-light:   #17224a;

    --text:          #e6ebf5;
    --text-muted:    #94a2ba;

    --border:        #26314a;
    --border-strong: #34415e;

    --ok-bg: #10301f;  --warn-bg: #33260c;
    --danger-bg: #3a1717;  --info-bg: #10283c;

    --accent-blue:   #5b8cff;
    --accent-teal:   #2bb6b6;
    --accent-violet: #a487f0;
    --accent-amber:  #f3b73f;
    --accent-rose:   #ec6b9c;
    --accent-green:  #45c67c;

    --shadow:    0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, .45);
    --shadow-xl: 0 18px 50px rgba(0, 0, 0, .55);
  }
}

:root[data-theme="dark"] {
  --bg:            #0e1420;
  --surface:       #161d2c;
  --surface-alt:   #1c2434;
  --surface-sunk:  #111827;
  --brand-light:   #17224a;

  --text:          #e6ebf5;
  --text-muted:    #94a2ba;

  --border:        #26314a;
  --border-strong: #34415e;

  --ok-bg: #10301f;  --warn-bg: #33260c;
  --danger-bg: #3a1717;  --info-bg: #10283c;

  --accent-blue:   #5b8cff;
  --accent-teal:   #2bb6b6;
  --accent-violet: #a487f0;
  --accent-amber:  #f3b73f;
  --accent-rose:   #ec6b9c;
  --accent-green:  #45c67c;

  --shadow:    0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, .45);
  --shadow-xl: 0 18px 50px rgba(0, 0, 0, .55);
}

/* Nel tema scuro l'oro pieno è troppo acceso su fondo scuro per il testo:
   si usa la variante più calda. */
:root[data-theme="dark"] { --gold-dark: #f3b73f; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --gold-dark: #f3b73f; }
}


/* ==========================================================================
   4. Reset e base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  /* Le ancore non devono finire sotto l'header fisso. */
  scroll-padding-top: calc(var(--header-h) + 12px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

img, video { max-width: 100%; height: auto; display: block; }

/* Le <svg> NON prendono display:block: le icone vivono dentro contenitori
   flex o grid, e forzarle a blocco romperebbe l'allineamento altrove.
   La dimensione la decide la classe .icon. */
svg { max-width: 100%; }

/* L'attributo hidden deve prevalere su qualsiasi display dichiarato sopra.
   Gli stili d'autore battono quelli del browser a prescindere dalla
   specificità: senza questa riga un <svg hidden> resterebbe visibile, e le
   due icone del selettore di tema comparirebbero insieme. */
[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; font-weight: 650; letter-spacing: -.011em; }
h1 { font-size: clamp(2rem, 1.3rem + 2.6vw, 3.1rem); font-weight: 700; letter-spacing: -.022em; }
h2 { font-size: clamp(1.5rem, 1.15rem + 1.3vw, 2.1rem); letter-spacing: -.018em; }
h3 { font-size: 1.16rem; }
h4 { font-size: 1rem; }

p { margin: 0 0 1em; }
p, li { max-width: var(--measure); }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { padding-left: 1.2em; }

code, pre, .mono { font-family: var(--mono); font-size: .88em; }

hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }


/* ==========================================================================
   5. Accessibilità
   ========================================================================== */
:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent);
  outline-offset: 2px;
  border-radius: 3px;
}
/* Si rimuove il contorno solo per il puntatore, mai per la tastiera. */
:focus:not(:focus-visible) { outline: none; }

.skip-link {
  position: absolute; left: .5rem; top: -100px; z-index: 200;
  padding: .7rem 1.1rem; border-radius: var(--radius-sm);
  background: var(--brand); color: var(--text-onbrand);
  font-weight: 600; transition: top .15s ease;
}
.skip-link:focus { top: .5rem; text-decoration: none; }

/* Nascosto agli occhi ma non ai lettori di schermo. */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}


/* ==========================================================================
   6. Layout
   ========================================================================== */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: 20px;   /* margine laterale minimo su telefono */
}

.section { padding-block: clamp(3rem, 2rem + 4vw, 5.5rem); }
.section-alt { background: var(--surface-alt); }

.section-head { max-width: 60ch; margin-bottom: 2.4rem; }
.section-head.center { margin-inline: auto; text-align: center; }
.section-head p { color: var(--text-muted); font-size: 1.06rem; margin-bottom: 0; }
.section-head.center p { margin-inline: auto; }

.eyebrow {
  display: inline-block;
  font-size: .76rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--brand);
  margin-bottom: .7rem;
}

.spacer { flex: 1 1 auto; }


/* ==========================================================================
   7. Marchio
   ========================================================================== */
.brand { display: inline-flex; align-items: center; gap: .65rem; color: inherit; }
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--brand) 0%, var(--brand-dark) 60%, var(--gold) 190%);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: .84rem; letter-spacing: .04em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}
.brand-mark::after { content: var(--brand-mark-text); }

.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 1rem; font-weight: 700; }
.brand-text span { font-size: .72rem; color: var(--text-muted); }


/* ==========================================================================
   8. Icone
   --------------------------------------------------------------------------
   fill, stroke e stroke-width sono proprietà ereditate: impostandole qui
   sull'elemento <svg> che contiene <use>, passano dentro allo sprite anche
   quando lo sprite è un file esterno.
   ========================================================================== */
.icon {
  width: 1.15em; height: 1.15em;
  fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
  flex: 0 0 auto;
}
.icon-lg { width: 1.6em; height: 1.6em; }


/* ==========================================================================
   9. Bottoni
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .62rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .94rem; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background .13s ease, border-color .13s ease,
              transform .13s ease, box-shadow .13s ease;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--brand); border-color: var(--brand); color: var(--text-onbrand);
  box-shadow: 0 1px 2px rgba(8, 72, 202, .25);
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

.btn-lg { padding: .82rem 1.6rem; font-size: 1.02rem; }
.btn-sm { padding: .38rem .75rem; font-size: .84rem; }

.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }

.btn-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }

.icon-button {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer;
  transition: background .13s ease, border-color .13s ease;
}
.icon-button:hover { background: var(--surface-alt); border-color: var(--border-strong); }


/* ==========================================================================
   10. Campi di modulo
   ========================================================================== */
.field { margin-bottom: 1.15rem; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.field .help { font-size: .82rem; color: var(--text-muted); margin-top: .35rem; }
.required { color: var(--danger); }

input[type="text"], input[type="email"], input[type="tel"],
input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: .68rem .8rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .96rem;
  transition: border-color .13s ease, box-shadow .13s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--text-muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
textarea { resize: vertical; min-height: 130px; }

/* Errore di validazione: colore + testo, mai il solo colore. */
.field.has-error input,
.field.has-error textarea { border-color: var(--danger); }
.field.has-error input:focus,
.field.has-error textarea:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent);
}
.field-error {
  display: none;
  margin-top: .35rem; font-size: .84rem; font-weight: 600; color: var(--danger);
}
.field.has-error .field-error { display: block; }

.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }

/* Honeypot: invisibile all'occhio e alla tastiera, ma presente nel DOM,
   così i bot che compilano tutto si tradiscono da soli. */
.hp-field {
  position: absolute !important;
  left: -9999px !important;
  width: 1px; height: 1px; overflow: hidden;
}


/* ==========================================================================
   11. Badge e avvisi
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .6rem; border-radius: 999px;
  font-size: .76rem; font-weight: 600;
  background: var(--surface-alt); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-brand { background: var(--brand-light); color: var(--brand); border-color: transparent; }
.badge-ok    { background: var(--ok-bg);    color: var(--ok);    border-color: transparent; }
.badge-warn  { background: var(--warn-bg);  color: var(--warn);  border-color: transparent; }

.alert {
  display: flex; align-items: flex-start; gap: .7rem;
  padding: .85rem 1.05rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: .94rem;
}
.alert p:last-child { margin-bottom: 0; }
.alert-success { background: var(--ok-bg);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-warning { background: var(--warn-bg);   color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-danger  { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info    { background: var(--info-bg);   color: var(--info);   border-color: color-mix(in srgb, var(--info) 25%, transparent); }


/* ==========================================================================
   12. Card
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem 1.45rem;
}


/* ==========================================================================
   13. Modalità revisione dei segnaposto
   --------------------------------------------------------------------------
   Si attiva aggiungendo ?segnaposto all'indirizzo. Evidenzia ogni testo
   ancora finto, per non dimenticarne nessuno quando arriveranno quelli veri.
   Da togliere insieme all'ultimo segnaposto.
   ========================================================================== */
body.mostra-segnaposto [data-segnaposto] {
  outline: 2px dashed var(--accent-rose);
  outline-offset: 3px;
  position: relative;
}
body.mostra-segnaposto [data-segnaposto]::after {
  content: attr(data-segnaposto);
  position: absolute; top: -.55rem; right: 0;
  transform: translateY(-100%);
  background: var(--accent-rose); color: #fff;
  font: 600 .66rem/1.5 var(--mono);
  padding: 0 .4rem; border-radius: 3px;
  white-space: nowrap; pointer-events: none; z-index: 60;
}


/* ==========================================================================
   14. Tile delle applicazioni collegate
   --------------------------------------------------------------------------
   Vive in tokens.css e non in app.css perché la pagina di attesa della
   dashboard carica solo questo file. Alla fase 4 si valuterà se spostarla.
   ========================================================================== */
.grid-app {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
}

.app-tile {
  position: relative; overflow: hidden;
  display: flex; align-items: flex-start; gap: .9rem;
  padding: 1.15rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.app-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: color-mix(in srgb, var(--tile-color, var(--brand)) 40%, var(--border));
  text-decoration: none;
}
.app-tile::before {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--tile-color, var(--brand));
}

.app-icon {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--tile-color, var(--brand)) 13%, transparent);
  color: var(--tile-color, var(--brand));
}
.app-icon .icon { width: 21px; height: 21px; }

.app-testo { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.app-testo strong { font-size: 1rem; font-weight: 650; }
.app-testo span { font-size: .87rem; color: var(--text-muted); }

/* La freccia dice che il collegamento porta fuori da questo sito. */
.app-freccia {
  margin-left: auto; flex: 0 0 auto;
  width: 1rem; height: 1rem;
  color: var(--text-muted);
  align-self: center;
}
