/* Design system BMAT (~/Code/design-system): token, tipografia e componenti.
   Ogni grigio ha un ruolo fisso; cambia solo il valore fra tema chiaro e scuro. */

@font-face { font-family: "Poppins"; font-weight: 300; font-display: swap; src: url("../fonts/Poppins-300.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-weight: 400; font-display: swap; src: url("../fonts/Poppins-400.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-weight: 500; font-display: swap; src: url("../fonts/Poppins-500.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-weight: 600; font-display: swap; src: url("../fonts/Poppins-600.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-weight: 700; font-display: swap; src: url("../fonts/Poppins-700.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 400; font-display: swap; src: url("../fonts/DMSans-400.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 500; font-display: swap; src: url("../fonts/DMSans-500.woff2") format("woff2"); }
@font-face { font-family: "DM Sans"; font-weight: 700; font-display: swap; src: url("../fonts/DMSans-700.woff2") format("woff2"); }

:root {
  color-scheme: light;
  /* Neutri caldi */
  --n-50: #F5F4F4; --n-100: #EAE8E8; --n-200: #D6D4D4; --n-300: #B7B7B7; --n-400: #757373;
  --n-500: #5C5A5A; --n-600: #3F3F3F; --n-700: #2D2B2B; --n-800: #272222; --n-900: #1D1C1C;
  --superficie: #FFFFFF; --superficie-rialzata: #FFFFFF;
  /* Blu BMAT, uguale nei due temi */
  --blu-50: #EEF2FF; --blu-100: #DFE6FF; --blu-200: #C2CFFF; --blu-300: #99AEFF; --blu-400: #6A87FF;
  --blu-500: #395FFF; --blu-600: #2447E6; --blu-700: #1B37B8; --blu-800: #1A3194; --blu-900: #1B2D75;
  --blu-testo: var(--blu-700);
  --selezione: var(--blu-50);
  /* Spettro BMAT */
  --sp-blu: #395FFF; --sp-viola: #9D3ABB; --sp-rosa: #FF456D; --sp-giallo: #F9C433;
  --sp-verde: #2EE78D; --sp-ciano: #1FCFED; --sp-menta: #6BECAD; --sp-corallo: #FD625F;
  --spettro: linear-gradient(90deg, #395FFF 0%, #9D3ABB 19%, #FF456D 39%, #F9C433 61%, #2EE78D 81%, #1FCFED 100%);
  /* Stati: fondo tenue + testo scuro */
  --ok-fondo: #D1FAE5; --ok-testo: #065F46;
  --avviso-fondo: #FEF3C7; --avviso-testo: #92400E;
  --errore-fondo: #FEE2E2; --errore-testo: #B91C1C;
  --info-fondo: #E0F2FE; --info-testo: #075985;
  --accento-fondo: var(--blu-100); --accento-testo: var(--blu-700);
  /* Inchiostri fissi */
  --ink: #1D1C1C; --ink-caldo: #272222;
  /* Forme */
  --raggio-scheda: 16px; --raggio-campo: 8px; --raggio-menu: 6px; --raggio-minuto: 4px;
  --ombra-sospesa: 0 8px 24px -8px rgb(29 28 28 / 0.18);
  /* Caratteri */
  --font: "Poppins", "Helvetica Neue", Arial, sans-serif;
  --font-meta: "DM Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Tema scuro: grigio caldo, superfici più chiare del fondo. Vale se scelto o se "Auto" e il sistema è scuro. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --n-50: #181717; --n-100: #343232; --n-200: #464343; --n-300: #736F6F; --n-400: #9A9696;
  --n-500: #B2AEAE; --n-600: #C8C5C5; --n-700: #DCDADA; --n-800: #EBE9E9; --n-900: #F5F4F4;
  --superficie: #242222; --superficie-rialzata: #2D2B2B;
  --blu-testo: var(--blu-300); --selezione: rgb(27 45 117 / 0.4);
  --ok-fondo: #022C22; --ok-testo: #6EE7B7; --avviso-fondo: #451A03; --avviso-testo: #FCD34D;
  --errore-fondo: #450A0A; --errore-testo: #FCA5A5; --info-fondo: #082F49; --info-testo: #7DD3FC;
  --accento-fondo: rgb(27 45 117 / 0.4); --accento-testo: var(--blu-300);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --n-50: #181717; --n-100: #343232; --n-200: #464343; --n-300: #736F6F; --n-400: #9A9696;
    --n-500: #B2AEAE; --n-600: #C8C5C5; --n-700: #DCDADA; --n-800: #EBE9E9; --n-900: #F5F4F4;
    --superficie: #242222; --superficie-rialzata: #2D2B2B;
    --blu-testo: var(--blu-300); --selezione: rgb(27 45 117 / 0.4);
    --ok-fondo: #022C22; --ok-testo: #6EE7B7; --avviso-fondo: #451A03; --avviso-testo: #FCD34D;
    --errore-fondo: #450A0A; --errore-testo: #FCA5A5; --info-fondo: #082F49; --info-testo: #7DD3FC;
    --accento-fondo: rgb(27 45 117 / 0.4); --accento-testo: var(--blu-300);
  }
}

/* --- Base ------------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--n-50); color: var(--n-900);
  font: 400 14px/1.45 var(--font); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.025em; }
h1 { font-size: 20px; color: var(--n-900); }
h2 { font-size: 14px; color: var(--n-800); }
p { margin: 0; }
a { color: var(--blu-testo); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--blu-500); outline-offset: 1px; }
[x-cloak] { display: none !important; }

.meta {
  font-family: var(--font-meta); font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--n-500);
}
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.attenuato { color: var(--n-400); }
.secondario { color: var(--n-500); }
.piccolo { font-size: 12px; }
.mono { font-family: var(--font-mono); font-size: 12px; }

/* Icone Lucide: a tratto, colore del testo */
.icona, [data-lucide] { width: 16px; height: 16px; stroke-width: 1.8; flex: none; }
.icona-14 { width: 14px; height: 14px; }
.icona-20 { width: 20px; height: 20px; }

/* --- Bottoni: tutto ciò che si preme è una pillola ------------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid transparent; background: none; color: var(--n-700);
  font: 500 14px/1.4 var(--font); cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn-primario { background: var(--blu-500); color: #fff; }
.btn-primario:hover { background: var(--blu-600); }
.btn-risalto { background: var(--sp-viola); color: #fff; }
.btn-contorno { border-color: var(--n-200); background: var(--superficie); }
.btn-contorno:hover, .btn-fantasma:hover { background: var(--n-100); }
.btn-pericolo { border-color: #FCA5A5; background: var(--superficie); color: var(--errore-testo); }
.btn-piccolo { font-size: 12px; padding: 4px 8px; }
.btn-icona { padding: 6px; }

/* --- Schede e tessere: rettangoli morbidi, nessuna ombra ------------------------------- */

.scheda { background: var(--superficie); border: 1px solid var(--n-100); border-radius: var(--raggio-scheda); min-width: 0; }
.scheda-testa {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--n-100);
}
.scheda-testa p { margin-top: 2px; font-size: 12px; color: var(--n-400); max-width: 72ch; }
.scheda-corpo { padding: 16px; }
.scheda-corpo.senza-margine { padding: 0; }

.tessera { padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.tessera-testa { display: flex; align-items: center; justify-content: space-between; color: var(--n-400); }
.tessera-testa .meta { font-size: 12px; color: var(--n-400); }
.tessera-testa [data-lucide] { stroke-width: 1.6; color: var(--n-300); }
.tessera-numero { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--n-900); letter-spacing: -0.02em; }
.tessera-nota { font-size: 12px; color: var(--n-400); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* --- Tabelle: compatte, niente griglia verticale, niente zebra ------------------------- */

.tabella-contenitore { overflow: auto; }
.tabella-contenitore.limitata { max-height: 384px; }
.tabella { width: 100%; border-collapse: collapse; }
.tabella th {
  position: sticky; top: 0; z-index: 1; background: var(--n-50); text-align: left;
  font-family: var(--font-meta); font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--n-500); padding: 8px 12px; border-bottom: 1px solid var(--n-100);
  white-space: nowrap;
}
.tabella td { padding: 8px 12px; border-bottom: 1px solid var(--n-100); color: var(--n-900); }
.tabella tr:last-child td { border-bottom: none; }
.tabella tbody tr:hover td { background: color-mix(in srgb, var(--n-50) 60%, transparent); }
.tabella .num { text-align: right; }
.tabella-vuota td { text-align: center; color: var(--n-400); padding: 32px 12px; }

/* --- Campi ---------------------------------------------------------------------------- */

.campo { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campo > label, .campo > .etichetta { font-size: 12px; font-weight: 500; color: var(--n-600); }
.input, .select {
  font: 400 14px/1.4 var(--font); color: var(--n-900); background: var(--superficie);
  border: 1px solid var(--n-200); border-radius: var(--raggio-campo); padding: 6px 10px; min-width: 0;
}
.select { appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23757373' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.input:focus, .select:focus { outline: none; border-color: var(--blu-500); box-shadow: 0 0 0 3px rgb(57 95 255 / 0.15); }
.input::placeholder { color: var(--n-300); }

/* Chip di filtro e scelte a pillola (radio nascosti) */
.chip-gruppo { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-block; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--n-200);
  background: var(--superficie); color: var(--n-600); font-size: 12px; font-weight: 500;
}
.chip input:checked + span { background: var(--blu-500); border-color: var(--blu-500); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--blu-500); outline-offset: 1px; }

/* --- Badge: sempre con la parola ----------------------------------------------------- */

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-neutro { background: var(--n-100); color: var(--n-700); }
.badge-ok { background: var(--ok-fondo); color: var(--ok-testo); }
.badge-avviso { background: var(--avviso-fondo); color: var(--avviso-testo); }
.badge-errore { background: var(--errore-fondo); color: var(--errore-testo); }
.badge-info { background: var(--info-fondo); color: var(--info-testo); }
.badge-accento { background: var(--accento-fondo); color: var(--accento-testo); }
.badge [data-lucide] { width: 12px; height: 12px; }

/* --- Avvisi ------------------------------------------------------------------------- */

.avviso { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--raggio-menu); border: 1px solid; font-size: 13px; }
.avviso-info { background: var(--info-fondo); color: var(--info-testo); border-color: color-mix(in srgb, var(--info-testo) 25%, transparent); }
.avviso-avviso { background: var(--avviso-fondo); color: var(--avviso-testo); border-color: color-mix(in srgb, var(--avviso-testo) 25%, transparent); }

/* --- Menu e tendine: le uniche cose con l'ombra -------------------------------------- */

.menu {
  position: absolute; z-index: 30; min-width: 240px; padding: 4px; margin-top: 6px;
  background: var(--superficie-rialzata); border: 1px solid var(--n-100); border-radius: var(--raggio-menu);
  box-shadow: var(--ombra-sospesa);
}
.menu-titolo { font-family: var(--font-meta); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--n-400); padding: 8px 10px 4px; }
.menu-voce {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 7px 10px; border-radius: 4px; color: var(--n-700); font-size: 14px; text-decoration: none; border: 0; background: none; text-align: left; font-family: inherit;
}
.menu-voce:hover { background: var(--n-100); text-decoration: none; }
.menu-voce[aria-current="page"] { background: var(--n-100); font-weight: 500; }
.menu-voce[aria-disabled="true"] { color: var(--n-400); cursor: default; }
.menu-voce[aria-disabled="true"]:hover { background: none; }

/* --- Selettore del tema: Chiaro · Auto · Scuro ------------------------------------- */

.tema { display: inline-grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.tema button {
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--n-200); background: var(--superficie);
  color: var(--n-600); font: 500 12px/1.4 var(--font); cursor: pointer;
}
.tema button[aria-pressed="true"] { border-color: var(--blu-500); background: rgb(57 95 255 / 0.1); color: var(--blu-testo); }
