/* ─────────────────────────────────────────────────────────────────────────────
   DRCS — Design System v4
   Un solo accento (blu DRCS) usato con parsimonia · neutri freddi · stati chiari
   Tema chiaro e scuro con gli stessi token semantici.
   File unico del design system: assets/css/drcs.css

   INDICE
     01 Token (colori, spazi, raggi, ombre, tipografia, altezze, z-index)
     02 Alias legacy (--color-*, --c-*, --t-*) per markup e stili inline esistenti
     03 Base (reset, tipografia, focus, scrollbar, link)
     04 Icone (Lucide)
     05 Layout app (sidebar, topbar mobile, contenitore pagina)
     06 Intestazione pagina e sezioni
     07 Card · KPI
     08 Pulsanti
     09 Form (input, select, textarea, label, ricerca, check, switch)
     10 Badge · tag · chip · dot
     11 Tabelle (+ scroll e versione a card su mobile)
     12 Toolbar / filtri · tab segmentate · paginazione
     13 Stati vuoti · banner · toast · skeleton · spinner
     14 Modali (+ alias .ds-modal-*) · palette comandi
     15 Componenti specifici (righe preventivi, avatar, divider, progress…)
     16 Utility minime (solo dove Tailwind non c'è)
     17 Compatibilità markup legacy (classi Tailwind colorate → token)
     18 Mobile, stampa, movimento ridotto

   I pattern specifici delle pagine stanno in due file separati, caricati dopo questo:
     assets/css/drcs-admin.css   Home, schede della dashboard, pagine admin di dettaglio
     assets/css/drcs-public.css  pagine viste dai clienti (preventivo, portali, prenotazione…)

   Nota cascata: su molte pagine Tailwind Play CDN inietta il proprio <style>
   IN FONDO all'<head>, dopo questo file. A parità di specificità vince
   Tailwind: per questo i componenti usano classi (mai selettori di elemento
   nudi) e lo strato di compatibilità usa !important dove serve.
   ──────────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ═══ 01 · TOKEN ═════════════════════════════════════════════════════════ */
:root {
  color-scheme: light;

  /* Blu DRCS — unica tinta di brand */
  --brand-50:  #EFF4FF;
  --brand-100: #DCE7FE;
  --brand-200: #C0D4FE;
  --brand-300: #94B6FD;
  --brand-400: #6191FA;
  --brand-500: #3B6EF5;
  --brand-600: #2459E6;
  --brand-700: #1C47C4;
  --brand-800: #1D3C9C;
  --brand-900: #1B3274;

  /* Superfici e testo (neutri freddi) */
  --bg:          #F7F8FA;
  --bg-2:        #F1F3F6;
  --surface:     #FFFFFF;
  --surface-2:   #FAFBFC;
  --surface-3:   #F2F4F7;
  --surface-4:   #E7EAEF;
  --sidebar:     #F3F5F8;
  --overlay:     rgba(10, 13, 18, 0.45);

  --ink:   #0E1116;   /* titoli, valori        18.9:1 */
  --ink-2: #30363F;   /* testo corrente        12.2:1 */
  --ink-3: #5B6371;   /* secondario             6.1:1 */
  --ink-4: #6A7281;   /* meta, date, placeholder 4.8:1 (AA anche su --bg) */
  --ink-5: #AEB4BE;   /* icone decorative */
  --ink-6: #D3D7DE;

  --line:        rgba(14, 17, 22, 0.08);
  --line-2:      rgba(14, 17, 22, 0.13);
  --line-strong: rgba(14, 17, 22, 0.22);

  /* Accento */
  --accent:        var(--brand-600);   /* pulsante primario, elementi attivi (5.8:1 con bianco) */
  --accent-hover:  #1F4FD3;
  --accent-press:  #1A44B8;
  --accent-ink:    #FFFFFF;
  --accent-text:   #1F4FD3;            /* link e testo accentato su superficie (6.6:1) */
  --accent-soft:   #EFF4FF;
  --accent-soft-2: #DCE7FE;
  --accent-line:   rgba(36, 89, 230, 0.28);
  --accent-ring:   rgba(36, 89, 230, 0.22);

  /* Stati — sempre colore + testo, mai solo colore. "Info" è viola per non
     confondersi con l'accento blu dei comandi. */
  --success: #15803D;  --success-bg: #EEF8F1;  --success-line: #C6E7D0;  --success-solid: #15803D;
  --warning: #B45309;  --warning-bg: #FEF6E8;  --warning-line: #F3D9AC;  --warning-solid: #B45309;
  --danger:  #C2261B;  --danger-bg:  #FEF1F0;  --danger-line:  #F6CDC8;  --danger-solid:  #C2261B;
  --info:    #6D3FD9;  --info-bg:    #F5F1FE;  --info-line:    #DED2FB;  --info-solid:    #6D3FD9;
  --neutral: #4D5562;  --neutral-bg: #F2F4F7;  --neutral-line: #E3E6EB;
  --plum:    var(--info); --plum-bg: var(--info-bg); --plum-line: var(--info-line);

  /* Spaziatura (base 4) */
  --sp-0: 2px;  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 28px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;

  /* Raggi */
  --r-xs: 4px;  --r-sm: 6px;  --r: 8px;  --r-md: 10px;  --r-lg: 12px;  --r-xl: 16px;  --r-full: 999px;

  /* Ombre */
  --sh-xs: 0 1px 2px rgba(14, 17, 22, 0.05);
  --sh-sm: 0 1px 3px rgba(14, 17, 22, 0.07), 0 1px 2px rgba(14, 17, 22, 0.04);
  --sh-md: 0 8px 20px -6px rgba(14, 17, 22, 0.12), 0 2px 5px rgba(14, 17, 22, 0.05);
  --sh-lg: 0 24px 48px -12px rgba(14, 17, 22, 0.24), 0 6px 14px rgba(14, 17, 22, 0.07);
  --sh-focus: 0 0 0 3px var(--accent-ring);

  /* Toast (superficie invertita, uguale nei due temi) */
  --toast-bg: #161A21; --toast-ink: #EEF0F4; --toast-mute: #9AA2AF; --toast-line: rgba(255, 255, 255, 0.06);
  --toast-success: #5BD38A; --toast-error: #FB8A80; --toast-warning: #F2B544;
  --on-solid: #FFFFFF;   /* testo sui pulsanti pieni (accento, pericolo, successo) */

  /* Tipografia */
  --f-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-11: 11px; --fs-12: 12px; --fs-13: 13px; --fs-14: 14px; --fs-15: 15px;
  --fs-16: 16px; --fs-18: 18px; --fs-20: 20px; --fs-24: 24px; --fs-28: 28px;

  /* Altezze controlli */
  --h-xs: 26px; --h-sm: 32px; --h-md: 36px; --h-lg: 42px;

  /* Layout */
  --sidebar-w: 244px;
  --sidebar-w-slim: 64px;
  --topbar-h: 56px;
  --shell-max: 1440px;

  /* Livelli */
  --z-sticky: 20; --z-sidebar: 40; --z-overlay: 45; --z-modal: 60; --z-palette: 80; --z-toast: 100;

  /* Movimento */
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --d-fast: 120ms; --d: 180ms; --d-slow: 280ms;
}

/* Tema scuro: classe .dark su <html> (impostata prima del paint) */
.dark {
  color-scheme: dark;

  --bg:          #0B0D11;
  --bg-2:        #0E1015;
  --surface:     #12151B;
  --surface-2:   #171B22;
  --surface-3:   #1E232B;
  --surface-4:   #282E38;
  --sidebar:     #0E1015;
  --overlay:     rgba(3, 5, 8, 0.66);

  --ink:   #ECEEF2;
  --ink-2: #C9CED6;
  --ink-3: #9AA2AF;
  --ink-4: #808896;
  --ink-5: #545B67;
  --ink-6: #3A404A;

  --line:        rgba(236, 240, 248, 0.07);
  --line-2:      rgba(236, 240, 248, 0.11);
  --line-strong: rgba(236, 240, 248, 0.18);

  --accent:        #3366F0;
  --accent-hover:  #4475F5;
  --accent-press:  #2A58DC;
  --accent-ink:    #FFFFFF;
  --accent-text:   #8AB1FF;
  --accent-soft:   rgba(110, 155, 255, 0.12);
  --accent-soft-2: rgba(110, 155, 255, 0.20);
  --accent-line:   rgba(110, 155, 255, 0.34);
  --accent-ring:   rgba(110, 155, 255, 0.34);

  --success: #5BD38A;  --success-bg: rgba(91, 211, 138, 0.10);  --success-line: rgba(91, 211, 138, 0.24);  --success-solid: #1F8A4C;
  --warning: #F2B544;  --warning-bg: rgba(242, 181, 68, 0.10);  --warning-line: rgba(242, 181, 68, 0.26);  --warning-solid: #B9690E;
  --danger:  #FB8A80;  --danger-bg:  rgba(251, 138, 128, 0.10); --danger-line:  rgba(251, 138, 128, 0.26); --danger-solid:  #C93328;
  --info:    #B8A2FF;  --info-bg:    rgba(184, 162, 255, 0.11); --info-line:    rgba(184, 162, 255, 0.28); --info-solid:    #7048E0;
  --neutral: #B7BDC7;  --neutral-bg: rgba(236, 240, 248, 0.06); --neutral-line: rgba(236, 240, 248, 0.12);

  --sh-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
  --sh-sm: 0 1px 3px rgba(0, 0, 0, 0.40), 0 1px 2px rgba(0, 0, 0, 0.30);
  --sh-md: 0 10px 24px -6px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.35);
  --sh-lg: 0 28px 60px -12px rgba(0, 0, 0, 0.70), 0 8px 18px rgba(0, 0, 0, 0.40);
}

/* ═══ 02 · ALIAS LEGACY ══════════════════════════════════════════════════
   Il markup esistente e molti stili inline usano questi nomi: restano validi
   e puntano ai nuovi token: "blu" = accento, "viola" = stato informativo. */
:root, .dark {
  --c-blue-50: var(--accent-soft);   --c-blue-100: var(--accent-soft-2); --c-blue-200: var(--accent-line);
  --c-blue-300: var(--accent-text);  --c-blue-400: var(--accent-text);   --c-blue-500: var(--accent);
  --c-blue-600: var(--accent);       --c-blue-700: var(--accent-text);   --c-blue-800: var(--accent-press);
  --c-blue-900: var(--brand-900);
  --c-violet-50: var(--info-bg); --c-violet-100: var(--info-line); --c-violet-300: var(--info);
  --c-violet-400: var(--info); --c-violet-500: var(--info); --c-violet-600: var(--info); --c-violet-700: var(--info);
  --c-cyan-400: var(--info); --c-cyan-500: var(--info); --c-cyan-600: var(--info);
  --c-amber-300: var(--warning); --c-amber-400: var(--warning); --c-amber-500: var(--warning); --c-amber-600: var(--warning);
  --c-rose-300: var(--danger); --c-rose-400: var(--danger); --c-rose-500: var(--danger); --c-rose-600: var(--danger);
  --c-emerald-300: var(--success); --c-emerald-400: var(--success); --c-emerald-500: var(--success); --c-emerald-600: var(--success);
  --c-indigo-400: var(--info); --c-indigo-500: var(--info); --c-indigo-600: var(--info);

  --accent-2: var(--accent-hover);
  --accent-glow: var(--accent-line);
  --violet: var(--info);
  --violet-glow: var(--info-line);
  --violet-soft: var(--info-bg);

  --t-success: var(--success); --t-success-bg: var(--success-bg); --t-success-line: var(--success-line);
  --t-warn: var(--warning);    --t-warn-bg: var(--warning-bg);    --t-warn-line: var(--warning-line);
  --t-danger: var(--danger);   --t-danger-bg: var(--danger-bg);   --t-danger-line: var(--danger-line);
  --t-info: var(--info);       --t-info-bg: var(--info-bg);       --t-info-line: var(--info-line);
  --t-neutral: var(--neutral); --t-neutral-bg: var(--neutral-bg); --t-neutral-line: var(--neutral-line);
  --t-system: var(--info);     --t-system-bg: var(--info-bg);     --t-system-line: var(--info-line);

  --color-surface: var(--surface);   --color-surface-2: var(--surface-2);
  --color-bone: var(--bg-2);         --color-bone-2: var(--surface-3);   --color-bone-3: var(--ink-6);
  --color-ink: var(--ink);           --color-ink-soft: var(--ink-2);     --color-ink-mute: var(--ink-3);
  --color-ink-faint: var(--ink-4);   --color-ink-ghost: var(--ink-5);
  --color-line: var(--line);         --color-line-strong: var(--line-2);
  --color-primary-50: var(--accent-soft);  --color-primary-100: var(--accent-soft-2); --color-primary-200: var(--accent-line);
  --color-primary-300: var(--accent-text); --color-primary-400: var(--accent-text);   --color-primary-500: var(--accent);
  --color-primary-600: var(--accent);      --color-primary-700: var(--accent-text);   --color-primary-800: var(--accent-press);
  --color-primary-900: var(--brand-900);
  --color-accent-50: var(--accent-soft);   --color-accent-100: var(--accent-soft-2);  --color-accent-200: var(--accent-line);
  --color-accent-300: var(--accent-text);  --color-accent-400: var(--accent-text);    --color-accent-500: var(--accent);
  --color-accent-600: var(--accent-text);  --color-accent-700: var(--accent-text);
  --color-sage-50: var(--success-bg);  --color-sage-100: var(--success-line);  --color-sage-500: var(--success);  --color-sage-600: var(--success);  --color-sage-700: var(--success);
  --color-ochre-50: var(--warning-bg); --color-ochre-100: var(--warning-line); --color-ochre-500: var(--warning); --color-ochre-600: var(--warning); --color-ochre-700: var(--warning);
  --color-slate-50: var(--info-bg);    --color-slate-100: var(--info-line);    --color-slate-500: var(--info);    --color-slate-600: var(--info);    --color-slate-700: var(--info);
  --color-plum-50: var(--danger-bg);   --color-plum-100: var(--danger-line);   --color-plum-500: var(--danger);   --color-plum-600: var(--danger);   --color-plum-700: var(--danger);
  --color-clay-50: var(--neutral-bg);  --color-clay-100: var(--neutral-line);  --color-clay-500: var(--ink-4);    --color-clay-600: var(--ink-3);    --color-clay-700: var(--ink-2);
  --color-olive-50: var(--info-bg);    --color-olive-100: var(--info-line);    --color-olive-500: var(--info);    --color-olive-600: var(--info);    --color-olive-700: var(--info);
  --color-danger-50: var(--danger-bg); --color-danger-100: var(--danger-line); --color-danger-500: var(--danger); --color-danger-600: var(--danger); --color-danger-700: var(--danger);
  --color-success-50: var(--success-bg); --color-success-100: var(--success-line); --color-success-500: var(--success); --color-success-600: var(--success);
  --color-info-50: var(--info-bg);     --color-info-100: var(--info-line);     --color-info-500: var(--info);
  --color-warning-50: var(--warning-bg); --color-warning-100: var(--warning-line); --color-warning-500: var(--warning);
  --radius-sm: var(--r-sm); --radius: var(--r); --radius-md: var(--r-md); --radius-lg: var(--r-lg); --radius-xl: var(--r-xl);
  --radius-card: var(--r-lg);
  --shadow-xs: var(--sh-xs); --shadow-sm: var(--sh-sm); --shadow-md: var(--sh-md); --shadow-lg: var(--sh-lg);
  --ease-out-quart: var(--ease); --ease-out-expo: var(--ease-spring);
  --font-sans: var(--f-sans); --font-mono: var(--f-mono);
}

/* ═══ 03 · BASE ══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
  letter-spacing: -0.006em;
}
body { min-height: 100vh; min-height: 100dvh; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--line-strong); background-clip: padding-box; }
::selection { background: var(--accent-soft-2); color: var(--ink); }

a { color: inherit; text-decoration: none; }
img, svg, video { max-width: 100%; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-xs); }

/* Tipografia */
.tx-display { font-size: var(--fs-28); font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; color: var(--ink); }
.tx-h1 { font-size: var(--fs-24); font-weight: 600; letter-spacing: -0.022em; line-height: 1.2; color: var(--ink); }
.tx-h2 { font-size: var(--fs-18); font-weight: 600; letter-spacing: -0.018em; line-height: 1.3; color: var(--ink); }
.tx-h3 { font-size: var(--fs-15); font-weight: 600; letter-spacing: -0.012em; line-height: 1.35; color: var(--ink); }
.tx-body { font-size: var(--fs-14); line-height: 1.55; color: var(--ink-2); }
.tx-mute { font-size: var(--fs-13); line-height: 1.55; color: var(--ink-3); }
.tx-faint { font-size: var(--fs-12); line-height: 1.5; color: var(--ink-4); }
/* .tx-mono resta per codici/ID; i numeri usano Inter tabulare (più leggibile) */
.tx-mono { font-family: var(--f-mono); font-size: 0.94em; letter-spacing: -0.01em; }
.tx-num, .tabular, .tabular-nums { font-variant-numeric: tabular-nums; font-feature-settings: "tnum", "cv11"; }
code, kbd, samp, pre, .font-mono { font-family: var(--f-mono) !important; }

/* Eyebrow: piccola etichetta di contesto sopra un titolo */
.eyebrow, .ds-eyebrow {
  font-family: var(--f-sans);
  font-size: var(--fs-12);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-3);
  line-height: 1.3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.eyebrow.is-accent { color: var(--accent-text); }
.eyebrow .eyebrow-bar { display: none; }

/* ═══ 04 · ICONE ═════════════════════════════════════════════════════════ */
svg.lucide, i[data-lucide], [data-lucide] {
  width: 16px; height: 16px;
  flex-shrink: 0;
  stroke-width: 1.75;
  vertical-align: middle;
}
i[data-lucide] { display: inline-block; }
svg.lucide.w-3,  [data-lucide].w-3  { width: 12px; }   svg.lucide.h-3,  [data-lucide].h-3  { height: 12px; }
svg.lucide.w-3\.5, [data-lucide].w-3\.5 { width: 14px; } svg.lucide.h-3\.5, [data-lucide].h-3\.5 { height: 14px; }
svg.lucide.w-4,  [data-lucide].w-4  { width: 16px; }   svg.lucide.h-4,  [data-lucide].h-4  { height: 16px; }
svg.lucide.w-5,  [data-lucide].w-5  { width: 18px; }   svg.lucide.h-5,  [data-lucide].h-5  { height: 18px; }
svg.lucide.w-6,  [data-lucide].w-6  { width: 20px; }   svg.lucide.h-6,  [data-lucide].h-6  { height: 20px; }
svg.lucide.w-8,  [data-lucide].w-8  { width: 24px; }   svg.lucide.h-8,  [data-lucide].h-8  { height: 24px; }
svg.lucide.w-10, [data-lucide].w-10 { width: 28px; }   svg.lucide.h-10, [data-lucide].h-10 { height: 28px; }
svg.lucide.w-12, [data-lucide].w-12 { width: 32px; }   svg.lucide.h-12, [data-lucide].h-12 { height: 32px; }

/* ═══ 05 · LAYOUT APP ════════════════════════════════════════════════════ */
.app-body { background: var(--bg); }

#sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: var(--z-sidebar);
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  color: var(--ink-2);
  border-right: 1px solid var(--line);
  transition: transform var(--d-slow) var(--ease), width var(--d) var(--ease);
}
#sidebar.sidebar-slim { width: var(--sidebar-w-slim); }

main.app-main { min-width: 0; }
@media (min-width: 1024px) {
  main.app-main { margin-left: var(--sidebar-w); transition: margin-left var(--d) var(--ease); }
  body.sidebar-slim main.app-main { margin-left: var(--sidebar-w-slim); }
}
@media (max-width: 1023.98px) {
  #sidebar { transform: translateX(-100%); width: min(300px, 86vw); box-shadow: none; }
  #sidebar.is-open { transform: translateX(0); box-shadow: var(--sh-lg); }
}

.ds-shell {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-8) var(--sp-16);
  min-width: 0;
}
@media (max-width: 1023.98px) { .ds-shell { padding: var(--sp-5) var(--sp-4) var(--sp-12); } }

/* Sidebar — testata */
.sidebar-head {
  display: flex; align-items: center; gap: 10px;
  height: 60px;
  padding: 0 14px 0 16px;
  flex-shrink: 0;
}
.sidebar-brand {
  width: 30px; height: 30px;
  border-radius: var(--r);
  background: linear-gradient(145deg, var(--brand-400) 0%, var(--brand-600) 55%, var(--brand-700) 100%);
  color: var(--on-solid);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; letter-spacing: -0.01em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), var(--sh-xs);
  flex-shrink: 0;
}
.sidebar-logo { width: 30px; height: 30px; object-fit: contain; border-radius: var(--r-sm); flex-shrink: 0; }
.sidebar-brand-text { min-width: 0; flex: 1; }
.sidebar-brand-text .b-name { font-size: 13.5px; font-weight: 600; letter-spacing: -0.012em; color: var(--ink); line-height: 1.2; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-brand-text .b-eyebrow { font-size: 11.5px; font-weight: 500; color: var(--ink-4); line-height: 1.2; margin: 2px 0 0; }
.sidebar-collapse, .sidebar-close {
  margin-left: auto;
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  border: 0;
  background: transparent;
  color: var(--ink-4);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background var(--d) var(--ease), color var(--d) var(--ease);
}
.sidebar-collapse:hover, .sidebar-close:hover { background: var(--surface-3); color: var(--ink); }
.sidebar-collapse svg, .sidebar-close svg { width: 16px !important; height: 16px !important; }

/* Sidebar — ricerca rapida */
.sidebar-search {
  margin: 2px 12px 10px;
  height: 34px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px 0 10px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line-2);
  color: var(--ink-4);
  font-size: 13px;
  cursor: pointer;
  width: calc(100% - 24px);
  text-align: left;
  box-shadow: var(--sh-xs);
  transition: border-color var(--d) var(--ease), color var(--d) var(--ease);
}
.sidebar-search:hover { border-color: var(--line-strong); color: var(--ink-3); }
.sidebar-search span { flex: 1; }
.sidebar-search svg { width: 15px !important; height: 15px !important; }
.dark .sidebar-search { background: var(--surface-2); box-shadow: none; }

/* Sidebar — navigazione */
/* Sfumatura sul bordo inferiore: segnala che l'elenco continua sotto il piede.
   Il padding finale tiene l'ultima voce fuori dalla sfumatura quando si arriva in fondo. */
.sidebar-nav {
  flex: 1; overflow-y: auto; padding: 4px 0 36px; overscroll-behavior: contain;
  -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 36px), transparent);
  mask-image: linear-gradient(to bottom, black calc(100% - 36px), transparent);
}
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-group { margin-bottom: 8px; }
.sidebar-group-label {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  width: calc(100% - 20px);
  margin: 0 10px 2px;
  padding: 0 10px 0 12px;
  height: 26px;
  font-family: var(--f-sans);
  font-size: 12px; font-weight: 600;
  letter-spacing: 0;
  color: var(--ink-4);
  background: transparent; border: 0; border-radius: var(--r-sm);
  text-align: left;
}
button.sidebar-group-label { cursor: pointer; }
button.sidebar-group-label:hover { color: var(--ink-2); background: rgba(14, 17, 22, 0.04); }
.dark button.sidebar-group-label:hover { background: rgba(236, 240, 248, 0.04); }
.sidebar-group-label svg { width: 14px !important; height: 14px !important; opacity: 0; transition: transform var(--d) var(--ease), opacity var(--d) var(--ease); }
#sidebar:hover .sidebar-group-label svg, .sidebar-group.is-collapsed .sidebar-group-label svg { opacity: 0.8; }
.sidebar-group.is-collapsed .sidebar-group-label svg { transform: rotate(-90deg); }
.sidebar-group.is-collapsed .sidebar-group-items { display: none; }
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  height: 31px;
  padding: 0 10px;
  margin: 1px 10px;
  border-radius: var(--r);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-2);
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
  white-space: nowrap;
}
.nav-link svg, .nav-link i { width: 16px !important; height: 16px !important; color: var(--ink-4); transition: color var(--d-fast) var(--ease); }
.nav-link span { overflow: hidden; text-overflow: ellipsis; }
.nav-link:hover { background: rgba(14, 17, 22, 0.05); color: var(--ink); text-decoration: none !important; }
.dark .nav-link:hover { background: rgba(236, 240, 248, 0.05); }
.nav-link:hover svg { color: var(--ink-3); }
.nav-link.is-active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: var(--sh-xs), inset 0 0 0 1px var(--line);
}
.dark .nav-link.is-active { background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line); }
.nav-link.is-active svg, .nav-link.is-active i { color: var(--accent-text); }
.nav-link-badge {
  margin-left: auto;
  min-width: 20px; height: 18px;
  padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--surface-4);
  color: var(--ink-3);
  font-size: 11px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.nav-link-badge.is-alert { background: var(--accent); color: var(--accent-ink); }

/* Sidebar — piede */
.sidebar-foot { flex-shrink: 0; padding: 8px 10px; border-top: 1px solid var(--line); }
.sidebar-user { display: flex; align-items: center; gap: 8px; padding: 4px 2px 4px 6px; border-radius: var(--r); }
.sidebar-user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-4);
  color: var(--ink-2);
  flex-shrink: 0; object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 11.5px;
  border: 1px solid var(--line);
}
.sidebar-user-info { min-width: 0; flex: 1; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.25; margin: 0; text-transform: capitalize; }
.sidebar-user-role { font-size: 11.5px; color: var(--ink-4); line-height: 1.25; margin: 1px 0 0; }
.sidebar-tools { display: flex; gap: 2px; flex-shrink: 0; }
.sidebar-tool {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-3);
  border-radius: var(--r);
  font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}
.sidebar-tool:hover { background: rgba(14, 17, 22, 0.05); color: var(--ink); text-decoration: none !important; }
.dark .sidebar-tool:hover { background: rgba(236, 240, 248, 0.05); }
.sidebar-tool.danger:hover { color: var(--danger); background: var(--danger-bg); }
.sidebar-tool svg, .sidebar-tool i { width: 15px !important; height: 15px !important; }
.sidebar-tool.is-icon { flex: 0 0 30px; width: 30px; height: 30px; }

/* Sidebar ridotta (solo desktop) */
#sidebar.sidebar-slim .sidebar-brand-text,
#sidebar.sidebar-slim .sidebar-collapse,
#sidebar.sidebar-slim .sidebar-group-label,
#sidebar.sidebar-slim .nav-link span,
#sidebar.sidebar-slim .nav-link-badge,
#sidebar.sidebar-slim .sidebar-user-info,
#sidebar.sidebar-slim .sidebar-search span,
#sidebar.sidebar-slim .sidebar-search kbd,
#sidebar.sidebar-slim .sidebar-tool span { display: none !important; }
#sidebar.sidebar-slim .sidebar-head { justify-content: center; padding: 0; }
#sidebar.sidebar-slim .nav-link { justify-content: center; padding: 0; margin: 2px 12px; }
#sidebar.sidebar-slim .sidebar-group { margin-bottom: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
#sidebar.sidebar-slim .sidebar-group:first-child { border-top: 0; }
#sidebar.sidebar-slim .sidebar-group.is-collapsed .sidebar-group-items { display: block; }
#sidebar.sidebar-slim .sidebar-search { justify-content: center; padding: 0; margin: 2px 12px 10px; width: calc(100% - 24px); }
#sidebar.sidebar-slim .sidebar-user { flex-direction: column; justify-content: center; padding: 4px 0; gap: 6px; }
#sidebar.sidebar-slim .sidebar-tools { flex-direction: column; }
.sidebar-expand { display: none !important; }
.sidebar-foot .sidebar-expand { width: 100%; margin-bottom: 6px; }
#sidebar.sidebar-slim .sidebar-expand { display: flex !important; }

.sidebar-overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  background: var(--overlay);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fade-in var(--d) var(--ease);
}
#sidebar.is-open { z-index: calc(var(--z-overlay) + 1); }

/* Topbar mobile (sostituisce il vecchio pulsante flottante che copriva le azioni) */
.app-topbar {
  position: sticky; top: 0;
  z-index: var(--z-sticky);
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.app-topbar .tb-title { transition: opacity var(--d) var(--ease), transform var(--d) var(--ease); }
.app-topbar.is-title-hidden .tb-title { opacity: 0; transform: translateY(4px); }
.app-topbar .tb-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: -0.012em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 1024px) { .app-topbar { display: none; } }

/* ═══ 06 · INTESTAZIONI ══════════════════════════════════════════════════ */
.ds-page-head, .ds-page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4) var(--sp-6);
  margin: 0 0 var(--sp-6);
  padding: 0;
  border: 0;
  flex-wrap: wrap;
}
.ds-page-head .ph-meta, .ds-page-header > .min-w-0 { min-width: 0; flex: 1 1 320px; }
.ds-page-head .ph-eyebrow {
  font-size: var(--fs-12); font-weight: 500;
  letter-spacing: 0; text-transform: none;
  color: var(--ink-3);
  margin: 0 0 6px;
  display: flex; align-items: center; gap: 6px;
  line-height: 1.3;
}
.ds-page-head .ph-eyebrow::before { content: none; }
.ds-page-head h1, .ds-page-header h1, .ds-page-header h2 {
  font-size: var(--fs-24); font-weight: 600; letter-spacing: -0.022em;
  margin: 0; color: var(--ink); line-height: 1.2;
}
.ds-page-head .ph-sub, .ds-page-subtitle {
  font-size: var(--fs-14); color: var(--ink-3); margin: 6px 0 0; max-width: 72ch; line-height: 1.5;
}
.ds-page-head .ph-actions, .ds-page-header > .flex {
  display: flex; align-items: center; gap: var(--sp-2);
  flex-shrink: 0; flex-wrap: wrap;
}
.ds-page-head .ph-actions > .btn { height: var(--h-md); }
.ds-page-head .ph-actions > .btn.btn-sm { height: var(--h-sm); }
@media (max-width: 639.98px) {
  .ds-page-head, .ds-page-header { align-items: stretch; margin-bottom: var(--sp-5); }
  .ds-page-head h1, .ds-page-header h1, .ds-page-header h2 { font-size: var(--fs-20); }
  .ds-page-head .ph-actions { width: 100%; }
  .ds-page-head .ph-actions > .btn-accent:last-child:not(:only-child),
  .ds-page-head .ph-actions > .btn-primary:last-child:not(:only-child) { margin-left: auto; }
  .ds-page-head .ph-actions > .btn:only-child { flex: 1 1 auto; }
}

/* Sezione numerata (legacy) → intestazione di sezione pulita */
.ds-section { margin: var(--sp-8) 0 var(--sp-3); display: flex; align-items: center; gap: var(--sp-3); }
.ds-section .ds-section-num, .section-num { display: none; }
.ds-section .ds-section-title, .section-title { font-size: var(--fs-14); font-weight: 600; letter-spacing: -0.01em; color: var(--ink); margin: 0; }
.ds-section .ds-section-rule, .section-rule { flex: 1; height: 1px; background: var(--line); }
.modal-body .ds-section { margin: var(--sp-3) 0 0; }

.section-ds {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); margin: var(--sp-8) 0 var(--sp-3);
  padding: 0; border: 0;
}
.section-ds h2, .section-ds h3 {
  font-family: var(--f-sans); font-size: var(--fs-15); font-weight: 600;
  text-transform: none; letter-spacing: -0.012em; color: var(--ink); margin: 0;
  display: inline-flex; align-items: center; gap: 8px;
}
.section-ds h2::before, .section-ds h3::before { content: none; }
.section-ds svg, .section-ds i { width: 16px !important; height: 16px !important; color: var(--ink-4); }

/* ═══ 07 · CARD · KPI ════════════════════════════════════════════════════ */
.card, .card-ds {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  position: relative;
  background-image: none !important;
  min-width: 0;
}
.dark .card, .dark .card-ds { box-shadow: none; }
.card-h, .card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3);
  padding: 10px var(--sp-5);
  min-height: 54px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.card-head > .btn-ghost:last-child, .card-head > :last-child > .btn-ghost:last-child { margin-right: -8px; }
.card-head > div:first-child { flex: 1 1 auto; min-width: 0; }
.card-head > :last-child:not(:first-child) { margin-left: auto; }
.card-h .ch-title, .card-head .ch-title, .ch-title {
  font-size: var(--fs-14); font-weight: 600;
  color: var(--ink); letter-spacing: -0.01em; margin: 0;
  display: inline-flex; align-items: center; gap: 8px;
  line-height: 1.35;
}
.ch-title svg, .ch-title i { width: 16px !important; height: 16px !important; color: var(--ink-4); }
.card-head .badge, .card-head .tag { flex-shrink: 0; }
.card-b, .card-body { padding: var(--sp-5); }
.ds-card-body.p-5 { padding: var(--sp-5); }
.card-f, .card-foot {
  padding: 12px var(--sp-5);
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2);
  flex-wrap: wrap;
}
.card > :last-child { border-bottom-left-radius: inherit; border-bottom-right-radius: inherit; }
.card-hover { transition: border-color var(--d) var(--ease), box-shadow var(--d) var(--ease); }
.card-hover:hover { border-color: var(--line-2); box-shadow: var(--sh-sm); }
@media (max-width: 639.98px) {
  .card-h, .card-head { padding: 12px var(--sp-4); }
  .card-b, .card-body, .ds-card-body.p-5 { padding: var(--sp-4); }
  .card-f, .card-foot { padding: 12px var(--sp-4); }
}

/* KPI */
.kpi, .kpi-tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5);
  display: flex; flex-direction: column; gap: 8px;
  min-width: 0;
  box-shadow: var(--sh-xs);
  background-image: none !important;
  overflow: hidden;
}
.dark .kpi, .dark .kpi-tile { box-shadow: none; }
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; min-height: 28px; }
.kpi-label, .kpi-tile .kpi-label {
  font-family: var(--f-sans);
  font-size: 13px; font-weight: 500;
  letter-spacing: 0; text-transform: none;
  color: var(--ink-3); margin: 0; line-height: 1.3;
  min-width: 0; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.kpi-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r);
  background: var(--surface-3);
  color: var(--ink-3);
  flex-shrink: 0;
}
.kpi-icon svg, .kpi-icon i { width: 15px !important; height: 15px !important; }
.kpi-value, .kpi-tile .kpi-value {
  font-family: var(--f-sans);
  font-size: 26px; font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink);
  margin: 0; line-height: 1.15;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum", "cv11";
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-foot { display: flex; align-items: center; gap: 6px; font-size: var(--fs-12); flex-wrap: wrap; min-width: 0; }
.kpi-foot-label { color: var(--ink-3); font-size: var(--fs-12); line-height: 1.4; }
.kpi-delta {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: var(--fs-12); font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 1px 6px; border-radius: var(--r-xs);
  background: var(--neutral-bg); color: var(--neutral);
}
.kpi-delta.up   { color: var(--success); background: var(--success-bg); }
.kpi-delta.down { color: var(--danger);  background: var(--danger-bg); }
.kpi.t-success .kpi-icon, .kpi-tile.kpi-sage .kpi-icon   { background: var(--success-bg); color: var(--success); }
.kpi.t-warn .kpi-icon,    .kpi-tile.kpi-ochre .kpi-icon  { background: var(--warning-bg); color: var(--warning); }
.kpi.t-danger .kpi-icon,  .kpi-tile.kpi-danger .kpi-icon, .kpi-tile.kpi-plum .kpi-icon { background: var(--danger-bg); color: var(--danger); }
.kpi.t-info .kpi-icon, .kpi.t-system .kpi-icon, .kpi-tile.kpi-slate .kpi-icon { background: var(--info-bg); color: var(--info); }
.kpi.t-accent .kpi-icon,  .kpi-tile.kpi-accent .kpi-icon { background: var(--accent-soft); color: var(--accent-text); }
.kpi.t-violet .kpi-icon { background: var(--surface-3); color: var(--ink-3); }
/* kpi-tile legacy: barretta di stato sottile a sinistra */
.kpi-tile::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: transparent; }
.kpi-tile.kpi-sage::before   { background: var(--success); }
.kpi-tile.kpi-ochre::before  { background: var(--warning); }
.kpi-tile.kpi-danger::before, .kpi-tile.kpi-plum::before { background: var(--danger); }
.kpi-tile.kpi-slate::before  { background: var(--info); }
.kpi-tile.kpi-accent::before { background: var(--accent); }
.kpi-tile p:first-child:not(.kpi-value) { font-family: var(--f-sans); font-size: 13px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--ink-3); }
.kpi-tile [class*="text-2xl"], .kpi-tile [class*="text-3xl"] { font-family: var(--f-sans); font-size: 24px; font-weight: 600; letter-spacing: -0.025em; color: var(--ink); line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-tile small, .kpi-tile .text-xs { color: var(--ink-3); font-size: var(--fs-12); }
.kpi-tile svg:not(.kpi-tile-mark), .kpi-tile i:not(.kpi-tile-mark) { width: 16px !important; height: 16px !important; }
@media (max-width: 639.98px) {
  .kpi, .kpi-tile { padding: 14px; gap: 6px; }
  .kpi-value, .kpi-tile .kpi-value { font-size: 21px; }
  .kpi-label { font-size: 12.5px; }
  .kpi-head { align-items: flex-start; min-height: 33px; }
  .kpi-icon { width: 24px; height: 24px; }
  .kpi-icon svg, .kpi-icon i { width: 13px !important; height: 13px !important; }
}

/* ═══ 08 · PULSANTI ══════════════════════════════════════════════════════
   Tipi: primary (=accent) · secondary · ghost · danger · success
   Taglie: xs 26 · sm 32 · md 36 (default) · lg 42 · icon (quadrato)       */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  height: var(--h-md); padding: 0 14px;
  font-family: var(--f-sans);
  font-size: 13.5px; font-weight: 500;
  letter-spacing: -0.006em;
  line-height: 1;
  border-radius: var(--r);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  text-decoration: none !important;
  position: relative;
  transition: background-color var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease), color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn svg, .btn i { width: 15px !important; height: 15px !important; flex-shrink: 0; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled, .btn.is-disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; box-shadow: none !important; }

.btn-primary, .btn-accent, .btn-violet {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink) !important;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.16), 0 1px 2px rgba(14,17,22,0.14);
}
.btn-primary:hover, .btn-accent:hover, .btn-violet:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active, .btn-accent:active, .btn-violet:active { background: var(--accent-press); border-color: var(--accent-press); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink-2);
  border-color: var(--line-2);
  box-shadow: var(--sh-xs);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:active { background: var(--surface-3); }
.dark .btn-secondary { background: var(--surface-2); box-shadow: none; }
.dark .btn-secondary:hover { background: var(--surface-3); }

.btn-ghost { background: transparent; color: var(--ink-3); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn-ghost:active { background: var(--surface-4); }

.btn-danger { background: var(--danger-solid); border-color: var(--danger-solid); color: var(--on-solid) !important; font-weight: 600; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-success { background: var(--success-solid); border-color: var(--success-solid); color: var(--on-solid) !important; font-weight: 600; }
.btn-success:hover { filter: brightness(0.92); }
/* Varianti "soft" per azioni distruttive in linea */
.btn-ghost.is-danger, .btn-danger-ghost { color: var(--danger); }
.btn-ghost.is-danger:hover, .btn-danger-ghost:hover { background: var(--danger-bg); color: var(--danger); }

.btn-xs { height: var(--h-xs); padding: 0 8px;  font-size: 12px; gap: 4px; border-radius: var(--r-sm); }
.btn-xs svg, .btn-xs i { width: 13px !important; height: 13px !important; }
.btn-sm { height: var(--h-sm); padding: 0 12px; font-size: 13px; gap: 6px; }
.btn-sm svg, .btn-sm i { width: 14px !important; height: 14px !important; }
.btn-lg { height: var(--h-lg); padding: 0 18px; font-size: 14.5px; gap: 8px; border-radius: var(--r-md); }
.btn-lg svg, .btn-lg i { width: 16px !important; height: 16px !important; }
.btn-icon { width: var(--h-md); padding: 0; }
.btn-icon.btn-xs { width: var(--h-xs); }
.btn-icon.btn-sm { width: var(--h-sm); }
.btn-icon.btn-lg { width: var(--h-lg); }
.btn-block { width: 100%; }

/* Stato di caricamento (aggiunto da ui.js all'invio dei form) */
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--ink-4); border-right-color: transparent;
  animation: spin 0.7s linear infinite;
}
.btn-primary.is-loading::after, .btn-accent.is-loading::after, .btn-danger.is-loading::after, .btn-success.is-loading::after { border-color: rgba(255,255,255,0.9); border-right-color: transparent; }

.btn-group {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border-radius: var(--r);
  background: var(--surface-3);
  border: 1px solid var(--line);
}
.btn-group > .btn { height: 28px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-3); box-shadow: none; padding: 0 10px; font-size: 12.5px; }
.btn-group > .btn:hover { color: var(--ink); background: transparent; }
.btn-group > .btn.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--sh-xs); font-weight: 600; }
.dark .btn-group > .btn.is-active { background: var(--surface-4); }

/* ═══ 09 · FORM ══════════════════════════════════════════════════════════ */
.input, .input-ds, .select, .textarea, .ds-input {
  width: 100%;
  height: var(--h-md);
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--f-sans);
  font-size: 13.5px;
  line-height: 1.3;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  box-shadow: var(--sh-xs);
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease), background var(--d-fast) var(--ease);
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
.dark .input, .dark .input-ds, .dark .select, .dark .textarea, .dark .ds-input { background-color: var(--surface-2); box-shadow: none; }
.textarea, textarea.input-ds, textarea.input { min-height: 88px; padding: 9px 12px; height: auto; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder, .input-ds::placeholder, .ds-input::placeholder { color: var(--ink-4); opacity: 1; }
.input:hover, .input-ds:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .input-ds:focus, .select:focus, .textarea:focus, .ds-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--sh-focus);
}
.input:disabled, .input-ds:disabled, .select:disabled, .textarea:disabled,
.input[readonly], .input-ds[readonly] { background: var(--surface-3); color: var(--ink-3); cursor: not-allowed; box-shadow: none; }
.input[readonly], .input-ds[readonly] { cursor: default; }
.input:user-invalid, .input-ds:user-invalid, .select:user-invalid, .textarea:user-invalid { border-color: var(--danger); }

select.input, select.input-ds, .select, select.ds-input {
  padding-right: 32px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238A92A0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  cursor: pointer;
  text-overflow: ellipsis;
}
select[multiple].input, select[multiple].input-ds, select[multiple].select { height: auto; background-image: none; padding: 6px; }
input[type="date"].input, input[type="date"].input-ds, input[type="time"].input, input[type="time"].input-ds,
input[type="datetime-local"].input, input[type="datetime-local"].input-ds, input[type="month"].input { padding-right: 8px; }
input[type="color"] { padding: 2px; height: 32px; width: 44px; cursor: pointer; }
/* Slider: traccia e cursore sui token (le tracce native restano chiare anche in scuro) */
input[type="range"] { -webkit-appearance: none; appearance: none; height: 20px; background: transparent; cursor: pointer; accent-color: var(--accent); }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: var(--surface-4); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); box-shadow: var(--sh-sm); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 999px; background: var(--surface-4); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
input[type="file"] { font-size: 13px; color: var(--ink-3); max-width: 100%; }
input[type="file"]::file-selector-button {
  height: 32px; margin-right: 10px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: var(--r);
  background: var(--surface); color: var(--ink-2);
  font: 500 13px var(--f-sans); cursor: pointer;
}
input[type="file"]::file-selector-button:hover { background: var(--surface-2); }
.input-mono { font-family: var(--f-mono); font-size: 13px; letter-spacing: -0.01em; }
.input-sm, .input.input-sm, .select.select-sm { height: var(--h-sm); font-size: 13px; }

label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.ds-label, label.l-eyebrow, .l-eyebrow, label.eyebrow {
  display: block;
  font-family: var(--f-sans);
  font-size: 13px; font-weight: 500;
  letter-spacing: 0; text-transform: none;
  color: var(--ink-2);
  margin-bottom: 6px;
  line-height: 1.35;
}
label.l-eyebrow + .input.mt-1, label.l-eyebrow + .select.mt-1, label.l-eyebrow + .textarea.mt-1 { margin-top: 0; }
.ds-help, .form-help { font-family: var(--f-sans); font-size: 12px; color: var(--ink-3); margin-top: 6px; letter-spacing: 0; line-height: 1.45; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { margin: 0; }
.form-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* Ricerca con icona */
.search { position: relative; display: flex; align-items: center; width: 100%; min-width: 0; }
.search > input, .search > .input, .search > .input-ds { width: 100%; padding: 0 44px 0 36px; }
.search > i, .search > svg.lucide, .search > [data-lucide] {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 15px !important; height: 15px !important;
  color: var(--ink-4); pointer-events: none; margin: 0; z-index: 1;
}
.search > kbd, kbd.kbd, .kbd {
  font-family: var(--f-sans) !important;
  font-size: 11px; font-weight: 500;
  color: var(--ink-4);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: var(--r-xs);
  line-height: 1.4;
}
.search > kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); pointer-events: none; }
@media (hover: none), (max-width: 639.98px) { .search > kbd { display: none; } .search > input, .search > .input { padding-right: 12px; } }

input[type="search"] { -webkit-appearance: none; appearance: none; }
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration { -webkit-appearance: none; display: none; }

/* Icona dentro input (legacy) */
.has-icon-left { position: relative; }
.has-icon-left .input-ic, .has-icon-right .input-ic-right {
  position: absolute !important; top: 50% !important; transform: translateY(-50%) !important;
  width: 15px !important; height: 15px !important;
  color: var(--ink-4) !important; pointer-events: none !important; z-index: 2;
}
.has-icon-left .input-ic { left: 12px !important; }
.has-icon-right .input-ic-right { right: 12px !important; }
.has-icon-left > input:not([type="checkbox"]):not([type="radio"]), .has-icon-left > select, .has-icon-left > textarea { padding-left: 36px !important; }
.has-icon-right > input:not([type="checkbox"]):not([type="radio"]) { padding-right: 36px !important; }

/* Checkbox / radio nativi con accento */
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }
input[type="checkbox"]:not(.switch):not(.no-ds), input[type="radio"]:not(.no-ds) {
  -webkit-appearance: none; appearance: none;
  margin: 0; display: inline-grid; place-content: center; vertical-align: middle;
  background: var(--surface); border: 1.5px solid var(--ink-5);
  transition: background var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease);
}
input[type="checkbox"]:not(.switch):not(.no-ds) { border-radius: 4px; }
input[type="radio"]:not(.no-ds) { border-radius: 50%; }
.dark input[type="checkbox"]:not(.switch):not(.no-ds), .dark input[type="radio"]:not(.no-ds) { background: var(--surface-2); border-color: var(--ink-4); }
input[type="checkbox"]:not(.switch):not(.no-ds):hover, input[type="radio"]:not(.no-ds):hover { border-color: var(--accent); }
input[type="checkbox"]:not(.switch):not(.no-ds):checked, input[type="checkbox"]:not(.switch):not(.no-ds):indeterminate { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:not(.switch):not(.no-ds)::after {
  content: ""; width: 10px; height: 10px; background: var(--on-solid); transform: scale(0);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>") center / contain no-repeat;
  transition: transform var(--d-fast) var(--ease-spring);
}
input[type="checkbox"]:not(.switch):not(.no-ds):checked::after { transform: scale(1); }
input[type="radio"]:not(.no-ds)::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); transform: scale(0); transition: transform var(--d-fast) var(--ease-spring); }
input[type="radio"]:not(.no-ds):checked { border-color: var(--accent); }
input[type="radio"]:not(.no-ds):checked::after { transform: scale(1); }
input[type="checkbox"]:not(.no-ds):focus-visible, input[type="radio"]:not(.no-ds):focus-visible { outline: none; box-shadow: var(--sh-focus); }
input[type="checkbox"]:disabled, input[type="radio"]:disabled { opacity: 0.5; cursor: not-allowed; }

/* Switch (checkbox con classe .switch) */
input[type="checkbox"].switch {
  appearance: none; -webkit-appearance: none;
  width: 34px; height: 20px; border-radius: 999px;
  background: var(--surface-4); position: relative;
  transition: background var(--d) var(--ease);
  border: 0;
}
input[type="checkbox"].switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--on-solid); box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform var(--d) var(--ease-spring);
}
input[type="checkbox"].switch:checked { background: var(--accent); }
input[type="checkbox"].switch:checked::after { transform: translateX(14px); }

/* Checklist scrollabile */
.ds-checklist { border: 1px solid var(--line-2); border-radius: var(--r); background: var(--surface); max-height: 240px; overflow-y: auto; }
.ds-checkitem { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13.5px; color: var(--ink-2); }
.ds-checkitem:last-child { border-bottom: 0; }
.ds-checkitem:hover { background: var(--surface-2); }

/* ═══ 10 · BADGE · TAG · CHIP ════════════════════════════════════════════ */
.badge, .badge-ds {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px;
  padding: 0 8px;
  font-family: var(--f-sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  border-radius: var(--r-sm);
  border: 0;
  line-height: 1;
  vertical-align: middle;
  white-space: nowrap;
  background: var(--neutral-bg);
  color: var(--neutral);
  box-shadow: inset 0 0 0 1px var(--neutral-line);
}
.badge svg, .badge-ds svg, .badge i, .badge-ds i { width: 12px !important; height: 12px !important; }
.badge .dot, .badge-ds .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; flex-shrink: 0; }
.badge.is-mono, .badge-ds.is-mono { font-family: var(--f-sans); font-size: 12px; letter-spacing: 0; }
.badge.is-lg { height: 26px; padding: 0 10px; font-size: 13px; }

.badge-neutral, .badge-ds-neutral, .badge-ds-clay { background: var(--neutral-bg); color: var(--neutral); box-shadow: inset 0 0 0 1px var(--neutral-line); }
.badge-success, .badge-ds-success, .badge-ds-sage { background: var(--success-bg); color: var(--success); box-shadow: inset 0 0 0 1px var(--success-line); }
.badge-warn, .badge-warning, .badge-ds-warning, .badge-ds-ochre { background: var(--warning-bg); color: var(--warning); box-shadow: inset 0 0 0 1px var(--warning-line); }
.badge-danger, .badge-ds-danger, .badge-ds-plum { background: var(--danger-bg); color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger-line); }
.badge-info, .badge-ds-info, .badge-ds-slate, .badge-system, .badge-ds-system, .badge-ds-olive { background: var(--info-bg); color: var(--info); box-shadow: inset 0 0 0 1px var(--info-line); }
.badge-accent, .badge-ds-accent, .badge-primary, .badge-ds-primary { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent-line); }
.badge-violet { background: var(--plum-bg); color: var(--plum); box-shadow: inset 0 0 0 1px var(--plum-line); }

/* Tag: metadato neutro (conteggi, categorie) */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 7px;
  font-family: var(--f-sans); font-size: 12px; font-weight: 500;
  background: var(--surface-3);
  color: var(--ink-2);
  border: 0;
  border-radius: var(--r-sm);
  letter-spacing: 0;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}
.tag svg, .tag i { width: 12px !important; height: 12px !important; flex-shrink: 0; color: var(--ink-4); }
.tag.is-mono { font-family: var(--f-mono); font-size: 11.5px; }
.tag.is-accent  { background: var(--accent-soft); color: var(--accent-text); }
.tag.is-emerald { background: var(--success-bg);  color: var(--success); }
.tag.is-amber   { background: var(--warning-bg);  color: var(--warning); }
.tag.is-rose    { background: var(--danger-bg);   color: var(--danger); }
.tag.is-cyan, .tag.is-info { background: var(--info-bg); color: var(--info); }
.tag.is-violet  { background: var(--plum-bg);     color: var(--plum); }
.tag[class*="is-"] svg, .tag[class*="is-"] i { color: currentColor; }

/* Chip filtro (pillola) */
.chip, .dh-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  font-family: var(--f-sans); font-size: 13px; font-weight: 500;
  letter-spacing: 0;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-full);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none !important;
  transition: background var(--d-fast) var(--ease), border-color var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}
.dark .chip, .dark .dh-chip { background: var(--surface-2); }
.chip:hover, .dh-chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip.is-active, .dh-chip.is-active, .chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.dark .chip.is-active, .dark .dh-chip.is-active { background: var(--ink); color: var(--surface); border-color: var(--ink); box-shadow: none; }
.chip .chip-count { opacity: 0.6; font-weight: 600; font-variant-numeric: tabular-nums; }
.chip svg, .chip i { width: 14px !important; height: 14px !important; }

/* Pallino di stato con alone */
.pulse { position: relative; display: inline-block; width: 8px; height: 8px; border-radius: 999px; background: var(--success); flex-shrink: 0; }
.pulse::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: inherit; opacity: 0.5; animation: pulse-ring 2s var(--ease) infinite; }
@keyframes pulse-ring { 0% { transform: scale(1); opacity: 0.5; } 100% { transform: scale(2.6); opacity: 0; } }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-5); flex-shrink: 0; }

/* ═══ 11 · TABELLE ═══════════════════════════════════════════════════════ */
.table-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.table-scroll { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; overscroll-behavior-x: contain; }
.card > .table-scroll:last-child, .card > div[style*="overflow-x"]:last-child { border-bottom-left-radius: var(--r-lg); border-bottom-right-radius: var(--r-lg); }

.table, .table-ds, .dh-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
.table thead th, .table-ds thead th, .dh-table thead th {
  font-family: var(--f-sans);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-3);
  padding: 10px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  height: 40px;
  vertical-align: middle;
}
.table tbody td, .table-ds tbody td, .dh-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
  vertical-align: middle;
  line-height: 1.45;
}
.table thead th:first-child, .table tbody td:first-child { padding-left: var(--sp-5); }
.table thead th:last-child, .table tbody td:last-child { padding-right: var(--sp-5); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background var(--d-fast) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-emphasized td { background: var(--accent-soft); }
.table tbody tr.is-warn td   { background: var(--warning-bg); }
.table tbody tr.is-danger td { background: var(--danger-bg); }
.table-compact thead th { padding: 8px 12px; height: 34px; }
.table-compact tbody td { padding: 8px 12px; }
.table .num, .table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions, .table td.actions { text-align: right; white-space: nowrap; width: 1%; }
.cell-id { font-family: var(--f-mono); font-size: 12px; color: var(--ink-3); }
.cell-name { font-weight: 500; color: var(--ink); letter-spacing: -0.006em; margin: 0; }
.cell-sub { font-size: 12.5px; color: var(--ink-3); margin: 2px 0 0; line-height: 1.4; }
.cell-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; }

/* Allineamento di default a specificità zero: classi come .num, .text-right, .text-center vincono sempre */
:where(table) :where(th) { text-align: left; }
th.num, td.num, :where(table) .text-right { text-align: right; }
:where(table) .text-center { text-align: center; }

/* Tabelle senza classe (legacy) — specificità zero: le classi nel markup hanno la precedenza */
:where(table:not(.table):not(.no-ds):not(.table-ds):not(.dh-table):not([class*="fc-"])) { width: 100%; font-size: 13.5px; border-collapse: separate; border-spacing: 0; }
:where(table:not(.table):not(.no-ds):not(.table-ds):not(.dh-table):not([class*="fc-"])) :where(thead th) {
  font-family: var(--f-sans); font-size: 12.5px; font-weight: 500; letter-spacing: 0; text-transform: none;
  color: var(--ink-3); padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap;
}
:where(table:not(.table):not(.no-ds):not(.table-ds):not(.dh-table):not([class*="fc-"])) :where(tbody td) { padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--ink-2); vertical-align: middle; }
:where(table:not(.table):not(.no-ds):not(.table-ds):not(.dh-table):not([class*="fc-"])) :where(tbody tr:hover) { background: var(--surface-2); }
:where(table:not(.table):not(.no-ds):not(.table-ds):not(.dh-table):not([class*="fc-"])) :where(tbody tr:last-child td) { border-bottom: 0; }

/* Mobile: tabelle a card (opt-in con .table-stack; ui.js aggiunge data-label) */
@media (max-width: 767.98px) {
  .table-stack { min-width: 0 !important; }
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody { display: block; width: 100%; }
  .table-stack tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 12px;
    padding: 14px var(--sp-4);
    border-bottom: 1px solid var(--line);
  }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack tbody tr.hidden, .table-stack .hidden { display: none !important; }
  .table-stack tbody td.ds-empty-cell { display: none !important; }
  .table-stack tbody tr:hover { background: transparent; }
  .table-stack tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    grid-column: 1 / -1;
    padding: 0 !important;
    border: 0 !important;
    min-width: 0;
    width: auto !important;
    text-align: right;
  }
  .table-stack tbody td::before {
    content: attr(data-label);
    font-size: 12px; font-weight: 500; color: var(--ink-3);
    text-align: left; flex-shrink: 0;
  }
  .table-stack tbody td[data-label=""]::before, .table-stack tbody td.no-label::before { content: none; }
  .table-stack tbody td:first-child { grid-column: 1 / 2; justify-content: flex-start; text-align: left; padding-bottom: 4px !important; }
  .table-stack tbody td:first-child::before { content: none; }
  .table-stack tbody td.actions, .table-stack tbody td:last-child:has(.btn) { grid-column: 2 / 3; grid-row: 1; justify-content: flex-end; align-self: start; }
  .table-stack tbody td.actions::before, .table-stack tbody td:last-child:has(.btn)::before { content: none; }
  .table-stack tbody td[colspan] { grid-column: 1 / -1; justify-content: center; text-align: center; }
  .table-stack tbody td[colspan]::before { content: none; }
  .table-stack tbody td > .min-w-0, .table-stack tbody td .truncate { max-width: 100%; }
  .table-stack .cell-sub { text-align: inherit; }
}

/* ═══ 12 · TOOLBAR · TAB · PAGINAZIONE ═══════════════════════════════════ */
.toolbar {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  flex-wrap: wrap;
  min-width: 0;
}
.dark .toolbar { box-shadow: none; }
.toolbar .toolbar-spacer { flex: 1; }
.toolbar .toolbar-divider { width: 1px; height: 20px; background: var(--line-2); flex-shrink: 0; }
.toolbar > .input, .toolbar > .select, .toolbar > .btn, .toolbar > .search, .toolbar > .search .input, .toolbar > select, .toolbar > input { height: var(--h-sm); }
.toolbar > .search > input, .toolbar > .search > .input { height: var(--h-sm); }
@media (max-width: 639.98px) {
  .toolbar { padding: 8px; }
  .toolbar > .search { flex: 1 1 100% !important; min-width: 0 !important; }
  .toolbar > .select, .toolbar > select { flex: 1 1 100%; width: auto !important; min-width: 0; }
  .toolbar .toolbar-divider, .toolbar .toolbar-spacer { display: none; }
  .toolbar > button[type="submit"], .toolbar > .btn-secondary { flex: 1 1 auto; }
}

/* Tab segmentate / sottonavigazione */
.ds-tabs, .seg {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.ds-tabs::-webkit-scrollbar, .seg::-webkit-scrollbar { display: none; }
.is-scroll-x:not(.is-scroll-end) { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
.ds-tab, .seg > a, .seg > button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  border-radius: var(--r-sm);
  font-size: 13px; font-weight: 500;
  color: var(--ink-3);
  background: transparent; border: 0;
  white-space: nowrap; cursor: pointer;
  text-decoration: none !important;
  transition: background var(--d-fast) var(--ease), color var(--d-fast) var(--ease);
}
.ds-tab:hover, .seg > a:hover, .seg > button:hover { color: var(--ink); }
.ds-tab.is-active, .seg > .is-active { background: var(--surface); color: var(--ink); box-shadow: var(--sh-xs); font-weight: 600; }
.dark .ds-tab.is-active, .dark .seg > .is-active { background: var(--surface-4); }
.ds-tab svg, .seg svg { width: 14px !important; height: 14px !important; }

/* Tab a sottolineatura */
.ds-underline-tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.ds-underline-tabs > * { padding: 10px 0; font-size: 13.5px; font-weight: 500; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.ds-underline-tabs > .is-active { color: var(--ink); border-bottom-color: var(--accent); }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagination-info { font-size: 12.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ═══ 13 · STATI VUOTI · BANNER · TOAST · SKELETON ═══════════════════════ */
.empty, .ds-empty { padding: 48px 24px; text-align: center; color: var(--ink-3); }
.empty-icon, .ds-empty-icon {
  width: 44px; height: 44px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-4);
}
.empty-icon svg, .empty-icon i, .ds-empty-icon svg, .ds-empty-icon i, .empty svg, .empty i { width: 20px !important; height: 20px !important; opacity: 1; }
.empty-title, .ds-empty-title { font-size: 14.5px; font-weight: 600; color: var(--ink); margin: 0 0 4px; letter-spacing: -0.01em; }
.empty-text, .ds-empty-text { font-size: 13.5px; color: var(--ink-3); max-width: 360px; margin: 0 auto; line-height: 1.5; }
.empty .btn, .ds-empty .btn { margin-top: 16px; }

.banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--surface);
  font-size: 13.5px; line-height: 1.45;
  margin-bottom: 16px;
  color: var(--ink-2);
}
.banner svg, .banner i { width: 16px !important; height: 16px !important; flex-shrink: 0; margin-top: 1px; }
.banner-success { background: var(--success-bg); border-color: var(--success-line); color: var(--ink); }
.banner-success svg { color: var(--success); }
.banner-warn    { background: var(--warning-bg); border-color: var(--warning-line); color: var(--ink); }
.banner-warn svg { color: var(--warning); }
.banner-danger  { background: var(--danger-bg);  border-color: var(--danger-line);  color: var(--ink); }
.banner-danger svg { color: var(--danger); }
.banner-info    { background: var(--info-bg);    border-color: var(--info-line);    color: var(--ink); }
.banner-info svg { color: var(--info); }

/* Toast */
.toast-region {
  position: fixed; z-index: var(--z-toast);
  right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
@media (max-width: 639.98px) { .toast-region { left: 12px; right: 12px; top: calc(10px + env(safe-area-inset-top)); bottom: auto; flex-direction: column-reverse; align-items: stretch; max-width: none; } }
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 280px; max-width: 420px;
  padding: 12px 12px 12px 14px;
  border-radius: var(--r-md);
  background: var(--toast-bg);
  color: var(--toast-ink);
  box-shadow: var(--sh-lg);
  font-size: 13.5px; line-height: 1.45;
  white-space: pre-line;
  animation: toast-in var(--d-slow) var(--ease-spring) both;
  border: 1px solid var(--toast-line);
}
.dark .toast { --toast-bg: #222833; border-color: var(--line-2); }
@media (max-width: 639.98px) { .toast { min-width: 0; max-width: none; } }
.toast.is-leaving { animation: toast-out var(--d) var(--ease) both; }
.toast-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; color: var(--toast-mute); }
.toast-icon svg { width: 18px !important; height: 18px !important; }
.toast.is-success .toast-icon { color: var(--toast-success); }
.toast.is-error .toast-icon { color: var(--toast-error); }
.toast.is-warning .toast-icon { color: var(--toast-warning); }
.toast-body { flex: 1; min-width: 0; overflow-wrap: anywhere; white-space: pre-line; }
.toast-close { background: transparent; border: 0; color: var(--toast-mute); cursor: pointer; padding: 2px; border-radius: var(--r-xs); line-height: 0; }
.toast-close:hover { color: var(--toast-ink); }
.toast-close svg { width: 15px !important; height: 15px !important; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@media (max-width: 639.98px) { .toast { animation-name: toast-in-top; } @keyframes toast-in-top { from { opacity: 0; transform: translateY(-10px) scale(0.98); } to { opacity: 1; transform: none; } } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 50%, var(--surface-3) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm);
  color: transparent !important;
}
.skeleton-line { height: 12px; border-radius: var(--r-xs); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-right-color: var(--accent); animation: spin 0.7s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.animate-spin { color: inherit; }

/* Barra di avanzamento sottile in cima durante la navigazione */
.nav-progress { position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--accent); z-index: var(--z-toast); transition: width 8s cubic-bezier(0.1, 0.7, 0.2, 1), opacity var(--d) var(--ease); }
.nav-progress.is-active { width: 85%; }

/* ═══ 14 · MODALI ════════════════════════════════════════════════════════ */
.modal, .ds-modal-wrap {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal:not(.hidden), .ds-modal-wrap { animation: fade-in var(--d) var(--ease); }
@media (min-width: 640px) { .modal, .ds-modal-wrap { align-items: center; padding: 24px; } }
.modal-backdrop, .ds-modal-backdrop {
  position: fixed; inset: 0;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.modal-panel, .ds-modal-panel, .ds-modal-card {
  position: relative; z-index: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: var(--sh-lg);
  animation: sheet-in var(--d-slow) var(--ease-spring);
}
@media (min-width: 640px) {
  .modal-panel, .ds-modal-panel, .ds-modal-card { border-radius: var(--r-xl); animation-name: scale-in; max-height: calc(100dvh - 48px); }
}
.modal-panel.is-wide { max-width: 820px; }
.modal-panel.is-narrow { max-width: 420px; }
.modal-head { padding: 20px 56px 16px 24px; border-bottom: 1px solid var(--line); }
.modal-head .mh-eyebrow { font-size: var(--fs-12); font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-3); margin: 0 0 4px; font-family: var(--f-sans); }
.modal-head .mh-title { font-size: 17px; font-weight: 600; letter-spacing: -0.016em; color: var(--ink); margin: 0; line-height: 1.3; }
.modal-head .mh-sub { font-size: 13.5px; color: var(--ink-3); margin: 4px 0 0; line-height: 1.45; }
.modal-body { padding: 20px 24px; }
.modal-foot {
  position: sticky; bottom: 0; z-index: 2;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  flex-wrap: wrap;
}
@media (max-width: 639.98px) {
  .modal-head { padding: 18px 52px 14px 18px; }
  .modal-body { padding: 16px 18px; }
  .modal-foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot > .btn { flex: 1 1 0; }
}
/* Pulsante chiudi (iniettato da ui.js se assente) */
.modal-close {
  position: absolute; top: 14px; right: 14px; z-index: 3;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r);
  border: 0; background: transparent;
  color: var(--ink-4); cursor: pointer;
}
.modal-close:hover { background: var(--surface-3); color: var(--ink); }
.modal-close svg { width: 18px !important; height: 18px !important; }
/* Maniglia del bottom-sheet su mobile */
@media (max-width: 639.98px) {
  .modal-panel::before, .ds-modal-panel::before {
    content: ""; position: sticky; top: 0; display: block;
    width: 36px; height: 4px; border-radius: 4px;
    margin: 8px auto -12px; background: var(--line-strong);
  }
}
@keyframes fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes scale-in { from { opacity: 0; transform: translateY(6px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.fade-in  { animation: fade-in 200ms var(--ease) both; }
.scale-in { animation: scale-in 220ms var(--ease-spring) both; }
.slide-up { animation: slide-up 240ms var(--ease) both; }
.stagger > * { animation: slide-up 260ms var(--ease) both; }
.stagger > *:nth-child(2) { animation-delay: 25ms; }
.stagger > *:nth-child(3) { animation-delay: 50ms; }
.stagger > *:nth-child(4) { animation-delay: 75ms; }
.stagger > *:nth-child(5) { animation-delay: 100ms; }
.stagger > *:nth-child(n+6) { animation-delay: 120ms; }

/* Palette comandi (⌘K) */
.cmdk { position: fixed; inset: 0; z-index: var(--z-palette); display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; }
.cmdk[hidden] { display: none; }
.cmdk-backdrop { position: absolute; inset: 0; background: var(--overlay); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade-in var(--d) var(--ease); }
.cmdk-panel { position: relative; width: 100%; max-width: 600px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-xl); box-shadow: var(--sh-lg); overflow: hidden; animation: scale-in var(--d) var(--ease-spring); }
.cmdk-input-wrap { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.cmdk-input-wrap svg { width: 18px !important; height: 18px !important; color: var(--ink-4); }
.cmdk-input { flex: 1; height: 54px; border: 0 !important; outline: 0; background: transparent !important; font: 400 15.5px var(--f-sans); color: var(--ink); box-shadow: none !important; padding: 0 !important; }
.cmdk-list { max-height: min(56vh, 440px); overflow-y: auto; padding: 6px; }
.cmdk-group { font-size: 12px; font-weight: 600; color: var(--ink-4); padding: 10px 10px 4px; }
.cmdk-item { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px; border-radius: var(--r); color: var(--ink-2); font-size: 14px; cursor: pointer; text-decoration: none !important; }
.cmdk-item svg { width: 16px !important; height: 16px !important; color: var(--ink-4); }
.cmdk-item .cmdk-sub { margin-left: auto; font-size: 12px; color: var(--ink-4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.cmdk-item.is-selected { background: var(--surface-3); color: var(--ink); }
.cmdk-item.is-selected svg { color: var(--accent-text); }
.cmdk-empty { padding: 28px 12px; text-align: center; color: var(--ink-3); font-size: 13.5px; }
.cmdk-foot { display: flex; gap: 14px; padding: 9px 14px; border-top: 1px solid var(--line); background: var(--surface-2); font-size: 12px; color: var(--ink-4); }
@media (max-width: 639.98px) { .cmdk { padding-top: 10px; } .cmdk-foot { display: none; } }

/* ═══ 15 · COMPONENTI SPECIFICI ══════════════════════════════════════════ */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface-3); color: var(--ink-2);
  font-size: 12px; font-weight: 600; letter-spacing: 0;
  flex-shrink: 0; overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--line);
}
.avatar.is-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar.is-lg { width: 40px; height: 40px; font-size: 14px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.divider { height: 1px; background: var(--line); border: 0; margin: 16px 0; }
.divider-y { width: 1px; background: var(--line); align-self: stretch; }

.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span, .progress > div { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

dl.dl { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 8px 16px; margin: 0; font-size: 13.5px; }
dl.dl dt { color: var(--ink-3); }
dl.dl dd { margin: 0; color: var(--ink); min-width: 0; overflow-wrap: anywhere; }

/* Righe preventivi (scheda Preventivi) */
.quote-list { display: flex; flex-direction: column; gap: 8px; }
.quote-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 14px 18px 14px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
.dark .quote-row { box-shadow: none; }
.quote-row::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0; background: var(--ink-6); }
.quote-row:hover { border-color: var(--line-2); box-shadow: var(--sh-sm); }
.quote-row[data-status="draft"]::before    { background: var(--ink-5); }
.quote-row[data-status="sent"]::before     { background: var(--info); }
.quote-row[data-status="accepted"]::before { background: var(--success); }
.quote-row[data-status="rejected"]::before { background: var(--danger); }
.quote-row[data-status="expired"]::before  { background: var(--danger); }
.qr-main { min-width: 0; }
.qr-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.qr-title { font-size: 14.5px; font-weight: 600; color: var(--ink); margin: 0; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.qr-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--ink-3); margin-bottom: 2px; }
.qr-meta svg, .qr-meta i { width: 13px !important; height: 13px !important; color: var(--ink-4); }
.qr-num { font-family: var(--f-mono); font-weight: 500; color: var(--ink-2); font-size: 12px; }
.qr-dot { color: var(--ink-5); }
.qr-desc { font-size: 13px; color: var(--ink-3); margin: 4px 0 6px; line-height: 1.45; max-width: 72ch; }
.qr-foot { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-4); margin-top: 6px; font-variant-numeric: tabular-nums; }
.qr-foot span { display: inline-flex; align-items: center; gap: 4px; }
.qr-foot svg, .qr-foot i { width: 12px !important; height: 12px !important; }
.qr-side { display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 10px; flex-shrink: 0; }
.qr-amount { font-size: 18px; font-weight: 600; color: var(--ink); letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.qr-amount-sub { font-size: 12px; color: var(--ink-4); text-align: right; }
.qr-actions { display: inline-flex; align-items: center; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 639.98px) {
  .quote-row { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 14px 14px 14px 18px; }
  .qr-side { flex-direction: row; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }
  .qr-actions { justify-content: flex-end; margin-left: auto; }
}

/* Topbar alternativa (legacy) */
.ds-topbar { position: sticky; top: 0; z-index: var(--z-sticky); background: color-mix(in srgb, var(--surface) 88%, transparent); -webkit-backdrop-filter: saturate(160%) blur(12px); backdrop-filter: saturate(160%) blur(12px); border-bottom: 1px solid var(--line); min-height: 56px; }

/* ═══ 16 · UTILITY MINIME (pagine senza Tailwind) ════════════════════════ */
.flex { display: flex; } .inline-flex { display: inline-flex; } .grid { display: grid; }
.items-center { align-items: center; } .items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; } .justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.flex-1 { flex: 1 1 0%; } .flex-wrap { flex-wrap: wrap; } .flex-shrink-0 { flex-shrink: 0; } .min-w-0 { min-width: 0; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); } .grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; } .mt-8 { margin-top: 32px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; } .mb-8 { margin-bottom: 32px; }
.text-center { text-align: center; } .text-right { text-align: right; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none; }
.relative { position: relative; }
.font-medium { font-weight: 500; } .font-semibold { font-weight: 600; } .font-bold { font-weight: 700; }
.text-ink { color: var(--ink); } .text-ink-2 { color: var(--ink-2); } .text-ink-3 { color: var(--ink-3); } .text-ink-4 { color: var(--ink-4); }
.text-accent { color: var(--accent-text); }
.text-violet { color: var(--accent-text); }
.text-success { color: var(--success); } .text-warning { color: var(--warning); } .text-danger { color: var(--danger); } .text-info { color: var(--info); }
.bg-surface { background: var(--surface); } .bg-surface-2 { background: var(--surface-2); }
.border-line { border: 1px solid var(--line); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ═══ 17 · COMPATIBILITÀ LEGACY ══════════════════════════════════════════
   Pagine ancora scritte con classi Tailwind colorate: le riportiamo sulla
   palette. html …: specificità sufficiente a battere il CDN iniettato dopo. */

/* Testi: link. Solo ancore "testuali" (senza classi o con classe .link):
   le ancore usate come card/righe ereditano il colore del contenitore. */
/* specificità bassa (0,1,1): le regole di componente come ".footer a" possono sovrascriverla */
a:not([class]), a[class=""], a.link { color: var(--accent-text); }
a[class*="underline"]:not(.btn) { color: var(--accent-text); }
a:not([class]):hover, a.link:hover { text-decoration: underline; text-underline-offset: 2px; }

/* Accento (blu/indaco legacy → blu DRCS); viola → info */
html .bg-blue-50, html .bg-blue-100, html .bg-indigo-50, html .bg-indigo-100, html .bg-sky-50, html .bg-sky-100 { background-color: var(--accent-soft) !important; }
html .bg-purple-50, html .bg-purple-100, html .bg-violet-50, html .bg-violet-100 { background-color: var(--info-bg) !important; }
html .bg-blue-500, html .bg-blue-600, html .bg-blue-700, html .bg-indigo-500, html .bg-indigo-600, html .bg-indigo-700, html .bg-purple-500, html .bg-purple-600, html .bg-violet-600, html .bg-sky-500, html .bg-sky-600 { background-color: var(--accent) !important; }
html .hover\:bg-blue-700:hover, html .hover\:bg-blue-600:hover, html .hover\:bg-indigo-700:hover, html .hover\:bg-purple-700:hover { background-color: var(--accent-hover) !important; }
html .text-blue-400, html .text-blue-500, html .text-blue-600, html .text-blue-700, html .text-blue-800, html .text-blue-900,
html .text-indigo-500, html .text-indigo-600, html .text-indigo-700, html .text-indigo-800, html .text-sky-600, html .text-sky-700 { color: var(--accent-text) !important; }
html .text-purple-500, html .text-purple-600, html .text-purple-700, html .text-purple-800, html .text-violet-600, html .text-violet-700 { color: var(--info) !important; }
html .border-blue-100, html .border-blue-200, html .border-blue-300, html .border-blue-500, html .border-blue-600, html .border-indigo-200, html .border-purple-200, html .border-indigo-500 { border-color: var(--accent-line) !important; }
html .focus\:ring-blue-500:focus, html .focus\:border-blue-500:focus, html .focus\:ring-indigo-500:focus { --tw-ring-color: var(--accent-ring) !important; border-color: var(--accent) !important; }
html .from-blue-500, html .from-blue-600, html .from-indigo-500, html .from-purple-500 { --tw-gradient-from: var(--accent) var(--tw-gradient-from-position) !important; --tw-gradient-to: var(--accent) var(--tw-gradient-to-position) !important; --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important; }
html .to-blue-600, html .to-blue-700, html .to-indigo-600, html .to-purple-600 { --tw-gradient-to: var(--accent-hover) var(--tw-gradient-to-position) !important; }

/* Successo */
html .bg-green-50, html .bg-green-100, html .bg-emerald-50, html .bg-emerald-100, html .bg-teal-50, html .bg-teal-100 { background-color: var(--success-bg) !important; }
html .bg-green-500, html .bg-green-600, html .bg-green-700, html .bg-emerald-500, html .bg-emerald-600 { background-color: var(--success-solid) !important; }
html .hover\:bg-green-700:hover, html .hover\:bg-emerald-700:hover { background-color: var(--success-solid) !important; filter: brightness(0.92); }
html .text-green-500, html .text-green-600, html .text-green-700, html .text-green-800, html .text-green-900,
html .text-emerald-500, html .text-emerald-600, html .text-emerald-700, html .text-emerald-800, html .text-teal-600, html .text-teal-700 { color: var(--success) !important; }
html .border-green-100, html .border-green-200, html .border-green-300, html .border-emerald-200, html .border-green-500 { border-color: var(--success-line) !important; }

/* Attenzione */
html .bg-yellow-50, html .bg-yellow-100, html .bg-amber-50, html .bg-amber-100, html .bg-orange-50, html .bg-orange-100 { background-color: var(--warning-bg) !important; }
html .bg-yellow-400, html .bg-yellow-500, html .bg-amber-500, html .bg-orange-500, html .bg-orange-600 { background-color: var(--warning-solid) !important; }
html .text-yellow-500, html .text-yellow-600, html .text-yellow-700, html .text-yellow-800, html .text-yellow-900,
html .text-amber-500, html .text-amber-600, html .text-amber-700, html .text-amber-800, html .text-orange-500, html .text-orange-600, html .text-orange-700, html .text-orange-800 { color: var(--warning) !important; }
html .border-yellow-200, html .border-yellow-300, html .border-amber-200, html .border-orange-200, html .border-yellow-400 { border-color: var(--warning-line) !important; }

/* Errore */
html .bg-red-50, html .bg-red-100, html .bg-rose-50, html .bg-rose-100, html .bg-pink-50, html .bg-pink-100 { background-color: var(--danger-bg) !important; }
html .bg-red-500, html .bg-red-600, html .bg-red-700, html .bg-rose-500, html .bg-rose-600 { background-color: var(--danger-solid) !important; }
html .hover\:bg-red-700:hover, html .hover\:bg-red-600:hover { background-color: var(--danger-solid) !important; filter: brightness(0.92); }
html .text-red-400, html .text-red-500, html .text-red-600, html .text-red-700, html .text-red-800, html .text-red-900,
html .text-rose-500, html .text-rose-600, html .text-rose-700, html .text-pink-600, html .text-pink-700 { color: var(--danger) !important; }
html .border-red-200, html .border-red-300, html .border-red-500, html .border-rose-200 { border-color: var(--danger-line) !important; }

/* Info (ciano) */
html .bg-cyan-50, html .bg-cyan-100 { background-color: var(--info-bg) !important; }
html .text-cyan-600, html .text-cyan-700 { color: var(--info) !important; }

/* Neutri */
html .bg-white { background-color: var(--surface) !important; }
html .bg-gray-50, html .bg-slate-50, html .bg-stone-50 { background-color: var(--surface-2) !important; }
html .bg-gray-100, html .bg-slate-100 { background-color: var(--surface-3) !important; }
html .bg-gray-200, html .bg-slate-200 { background-color: var(--surface-4) !important; }
html .hover\:bg-gray-50:hover, html .hover\:bg-gray-100:hover { background-color: var(--surface-3) !important; }
html .text-gray-300, html .text-slate-300 { color: var(--ink-5) !important; }
html .text-gray-400, html .text-slate-400 { color: var(--ink-4) !important; }
html .text-gray-500, html .text-slate-500 { color: var(--ink-3) !important; }
html .text-gray-600, html .text-slate-600 { color: var(--ink-3) !important; }
html .text-gray-700, html .text-slate-700, html .text-gray-800, html .text-slate-800 { color: var(--ink-2) !important; }
html .text-gray-900, html .text-slate-900, html .text-black { color: var(--ink) !important; }
html .border-gray-100, html .border-gray-200, html .border-slate-100, html .border-slate-200 { border-color: var(--line) !important; }
html .border-gray-300, html .border-slate-300 { border-color: var(--line-2) !important; }
html .divide-gray-200 > :not([hidden]) ~ :not([hidden]), html .divide-gray-100 > :not([hidden]) ~ :not([hidden]) { border-color: var(--line) !important; }

/* Varianti dark: Tailwind (Play CDN) usa :is(.dark *) → stessi token */
html.dark .dark\:bg-gray-700, html.dark .dark\:bg-gray-700\/50, html.dark .dark\:bg-slate-700 { background-color: var(--surface-3) !important; }
html.dark .dark\:bg-gray-800, html.dark .dark\:bg-slate-800, html.dark .dark\:bg-gray-800\/50 { background-color: var(--surface) !important; }
html.dark .dark\:bg-gray-900, html.dark .dark\:bg-slate-900, html.dark .dark\:bg-gray-950 { background-color: var(--bg) !important; }
html.dark .dark\:bg-gray-900\/10, html.dark .dark\:bg-gray-900\/20, html.dark .dark\:bg-gray-900\/40, html.dark .dark\:bg-gray-900\/50 { background-color: var(--surface-2) !important; }
html.dark .dark\:hover\:bg-gray-700:hover, html.dark .dark\:hover\:bg-gray-600:hover { background-color: var(--surface-4) !important; }
html.dark .dark\:text-white, html.dark .dark\:text-gray-100 { color: var(--ink) !important; }
html.dark .dark\:text-gray-200, html.dark .dark\:text-gray-300 { color: var(--ink-2) !important; }
html.dark .dark\:text-gray-400, html.dark .dark\:text-gray-500 { color: var(--ink-3) !important; }
html.dark .dark\:border-gray-600 { border-color: var(--line-2) !important; }
html.dark .dark\:border-gray-700, html.dark .dark\:border-gray-800 { border-color: var(--line) !important; }
html.dark .dark\:divide-gray-700 > :not([hidden]) ~ :not([hidden]) { border-color: var(--line) !important; }
html.dark [class*="dark:bg-yellow-"], html.dark [class*="dark:bg-amber-"], html.dark [class*="dark:bg-orange-"] { background-color: var(--warning-bg) !important; background-image: none !important; }
html.dark [class*="dark:bg-green-"], html.dark [class*="dark:bg-emerald-"], html.dark [class*="dark:bg-teal-"] { background-color: var(--success-bg) !important; background-image: none !important; }
html.dark [class*="dark:bg-red-"], html.dark [class*="dark:bg-rose-"], html.dark [class*="dark:bg-pink-"] { background-color: var(--danger-bg) !important; background-image: none !important; }
html.dark [class*="dark:bg-blue-"], html.dark [class*="dark:bg-indigo-"], html.dark [class*="dark:bg-sky-"] { background-color: var(--accent-soft) !important; background-image: none !important; }
html.dark [class*="dark:bg-purple-"], html.dark [class*="dark:bg-violet-"] { background-color: var(--info-bg) !important; background-image: none !important; }
html.dark [class*="dark:bg-cyan-"] { background-color: var(--info-bg) !important; background-image: none !important; }
html.dark [class*="dark:text-yellow-"], html.dark [class*="dark:text-amber-"], html.dark [class*="dark:text-orange-"] { color: var(--warning) !important; }
html.dark [class*="dark:text-green-"], html.dark [class*="dark:text-emerald-"], html.dark [class*="dark:text-teal-"] { color: var(--success) !important; }
html.dark [class*="dark:text-red-"], html.dark [class*="dark:text-rose-"] { color: var(--danger) !important; }
html.dark [class*="dark:text-blue-"], html.dark [class*="dark:text-indigo-"], html.dark [class*="dark:text-sky-"] { color: var(--accent-text) !important; }
html.dark [class*="dark:text-purple-"], html.dark [class*="dark:text-violet-"] { color: var(--info) !important; }
html.dark [class*="dark:border-yellow-"], html.dark [class*="dark:border-amber-"] { border-color: var(--warning-line) !important; }
html.dark [class*="dark:border-green-"], html.dark [class*="dark:border-emerald-"] { border-color: var(--success-line) !important; }
html.dark [class*="dark:border-red-"], html.dark [class*="dark:border-rose-"] { border-color: var(--danger-line) !important; }
html.dark [class*="dark:border-blue-"], html.dark [class*="dark:border-indigo-"], html.dark [class*="dark:border-purple-"] { border-color: var(--accent-line) !important; }
/* Testo su fondi colorati scuri in dark resta leggibile */
html.dark .text-gray-900, html.dark .text-gray-800 { color: var(--ink) !important; }

/* Sfondi pagina legacy */
html body.bg-gray-50, html body.bg-gray-100, html body[class*="bg-gradient-to"] { background: var(--bg) !important; background-image: none !important; }
html .min-h-screen.bg-gray-50, html .min-h-screen.bg-gray-100 { background-color: var(--bg) !important; }

/* Gradienti legacy → superfici piatte tinte */
html [class*="bg-gradient-to-"][class*="from-blue-"], html [class*="bg-gradient-to-"][class*="from-indigo-"], html [class*="bg-gradient-to-"][class*="from-sky-"] { background: var(--accent-soft) !important; }
html [class*="bg-gradient-to-"][class*="from-purple-"], html [class*="bg-gradient-to-"][class*="from-violet-"], html [class*="bg-gradient-to-"][class*="from-fuchsia-"] { background: var(--info-bg) !important; }
html [class*="bg-gradient-to-"][class*="from-green-"], html [class*="bg-gradient-to-"][class*="from-emerald-"], html [class*="bg-gradient-to-"][class*="from-teal-"] { background: var(--success-bg) !important; }
html [class*="bg-gradient-to-"][class*="from-yellow-"], html [class*="bg-gradient-to-"][class*="from-amber-"], html [class*="bg-gradient-to-"][class*="from-orange-"] { background: var(--warning-bg) !important; }
html [class*="bg-gradient-to-"][class*="from-red-"], html [class*="bg-gradient-to-"][class*="from-rose-"], html [class*="bg-gradient-to-"][class*="from-pink-"] { background: var(--danger-bg) !important; }
html [class*="bg-gradient-to-"][class*="from-cyan-"] { background: var(--info-bg) !important; }
html [class*="bg-gradient-to-"][class*="from-gray-"], html [class*="bg-gradient-to-"][class*="from-slate-"] { background: var(--surface-2) !important; }
/* …ma i gradienti pieni con testo bianco (testate legacy) diventano accento pieno */
html [class*="bg-gradient-to-"][class*="from-blue-6"][class*="text-white"], html [class*="bg-gradient-to-"][class*="from-blue-5"][class*="text-white"],
html [class*="bg-gradient-to-"][class*="from-indigo-6"][class*="text-white"], html [class*="bg-gradient-to-"][class*="from-purple-6"][class*="text-white"] { background: var(--accent) !important; }

/* Raggi e ombre legacy */
html .rounded-lg { border-radius: var(--r) ; }
html .rounded-xl { border-radius: var(--r-lg); }
html .rounded-2xl { border-radius: var(--r-xl); }
html .shadow, html .shadow-sm { box-shadow: var(--sh-xs) !important; }
html .shadow-md { box-shadow: var(--sh-sm) !important; }
html .shadow-lg, html .shadow-xl, html .shadow-2xl { box-shadow: var(--sh-md) !important; }
html.dark .shadow, html.dark .shadow-sm, html.dark .shadow-md { box-shadow: none !important; }

/* Card legacy (bg-white arrotondato) → bordo hairline */
html .bg-white.rounded-lg, html .bg-white.rounded-xl, html .bg-white.rounded-2xl, html .bg-white.rounded-md { border: 1px solid var(--line); }

/* Pulsanti legacy Tailwind (bg-colore + text-white) → geometria DS */
html button[class*="text-white"][class*="bg-"]:not(.btn), html a[class*="text-white"][class*="bg-"][class*="px-"]:not(.btn), html input[type="submit"][class*="bg-"] {
  border-radius: var(--r) !important;
  font-weight: 600;
  letter-spacing: -0.006em;
  transition: background-color var(--d-fast) var(--ease), filter var(--d-fast) var(--ease);
}
html button[class*="border-gray-300"][class*="text-gray-700"]:not(.btn), html a[class*="border-gray-300"][class*="text-gray-700"]:not(.btn) {
  background-color: var(--surface) !important; color: var(--ink-2) !important; border-color: var(--line-2) !important; border-radius: var(--r) !important;
}

/* Input legacy senza classe DS */
html input[type="text"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input):not(.cmdk-input),
html input[type="email"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="password"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="tel"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="url"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="number"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="search"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="date"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="datetime-local"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="time"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html input[type="month"]:not(.no-ds):not(.input):not(.input-ds):not(.ds-input),
html select:not(.no-ds):not(.input):not(.input-ds):not(.select):not(.ds-input),
html textarea:not(.no-ds):not(.input):not(.input-ds):not(.textarea):not(.ds-input) {
  font-family: var(--f-sans);
  background-color: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  font-size: 13.5px;
  min-height: 34px;
  transition: border-color var(--d-fast) var(--ease), box-shadow var(--d-fast) var(--ease);
}
html.dark input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not(.no-ds):not(.input):not(.input-ds):not(.ds-input):not(.cmdk-input),
html.dark select:not(.no-ds):not(.input):not(.input-ds):not(.select):not(.ds-input),
html.dark textarea:not(.no-ds):not(.input):not(.input-ds):not(.textarea):not(.ds-input) { background-color: var(--surface-2); }
html input:not(.no-ds):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not(.cmdk-input):focus,
html select:not(.no-ds):focus, html textarea:not(.no-ds):focus {
  outline: none;
  border-color: var(--accent) !important;
  box-shadow: var(--sh-focus) !important;
}
html input::placeholder, html textarea::placeholder { color: var(--ink-4); opacity: 1; }

/* Pillole di stato legacy (rounded-full + bg-colore-100) */
html .rounded-full[class*="bg-"][class*="-100"][class*="text-"][class*="px-"] { font-weight: 500; letter-spacing: 0; }

/* Backdrop modali legacy */
html .fixed.inset-0.bg-gray-500.bg-opacity-75, html .fixed.inset-0.bg-gray-600.bg-opacity-50, html .fixed.inset-0.bg-black.bg-opacity-50,
html .fixed.inset-0[class*="bg-black/"], html .fixed.inset-0.bg-gray-900\/50 {
  background: var(--overlay) !important;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  opacity: 1 !important;
}

/* Numeri grandi legacy: tabulari */
html .text-2xl.font-bold, html .text-3xl.font-bold, html .text-4xl.font-bold { font-variant-numeric: tabular-nums; letter-spacing: -0.025em; font-weight: 600; }

/* Icone dentro titoli legacy */
html h2 > svg.lucide, html h3 > svg.lucide { width: 18px; height: 18px; }

/* ═══ 18 · MOBILE · STAMPA · MOVIMENTO ═══════════════════════════════════ */
@media (max-width: 639.98px) {
  html, body { font-size: 14px; }
  .hide-mobile { display: none !important; }
  /* Griglie con colonne fisse in markup legacy: mai più strette di 0 */
  .ds-shell [style*="grid-template-columns"] { min-width: 0; }
  .ds-shell pre { white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; }
}
@media (min-width: 640px) { .show-mobile { display: none !important; } }

/* Nessun overflow orizzontale di pagina: i contenuti larghi scorrono nel loro contenitore */
.ds-shell img, .ds-shell iframe, .ds-shell video, .ds-shell canvas { max-width: 100%; }
.ds-shell .card, .ds-shell .kpi, .ds-shell .toolbar { max-width: 100%; }
.break-anywhere { overflow-wrap: anywhere; word-break: break-word; }

@media print {
  #sidebar, .app-topbar, .toast-region, .cmdk, .sidebar-overlay, .no-print { display: none !important; }
  main.app-main { margin: 0 !important; }
  body { background: #fff !important; color: #000; }
  .card, .kpi { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
}

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