/* ═══════════════════════════════════════════════════
   FONT — Figtree (variabile 300-900, self-hosted)
   Nessuna dipendenza da Google Fonts: funziona su LAN,
   offline e senza tracciamento esterno.
═══════════════════════════════════════════════════ */
@font-face {
  font-family: 'Figtree';
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url('/static/fonts/figtree-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Figtree';
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url('/static/fonts/figtree-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
                 U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
                 U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Figtree';
  font-style: italic;
  font-weight: 300 900;
  font-display: swap;
  src: url('/static/fonts/figtree-italic-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Figtree';
  font-style: italic;
  font-weight: 300 900;
  font-display: swap;
  src: url('/static/fonts/figtree-italic-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
                 U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
                 U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ═══════════════════════════════════════════════════
   SCALA TIPOGRAFICA ADATTATIVA
   Tutto il CSS è in rem: cambiando la root font-size
   scala l'intera UI (testo, padding, altezze, sidebar).
   Percentuali e non px per non annullare la preferenza
   di dimensione carattere impostata nel browser.
═══════════════════════════════════════════════════ */
html { font-size: 100%; }                                        /* 16px — laptop/desktop standard */

@media (min-width: 1600px) { html { font-size: 103.125%; } }     /* 16.5px — desktop ampio */
@media (min-width: 1920px) { html { font-size: 109.375%; } }     /* 17.5px — Full HD / 1440p */
@media (min-width: 2560px) { html { font-size: 121.875%; } }     /* 19.5px — 2K / QHD */
@media (min-width: 3200px) { html { font-size: 134.375%; } }     /* 21.5px — ultrawide */
@media (min-width: 3840px) { html { font-size: 150%; } }          /* 24px  — 4K a scala 100% */

/* ═══════════════════════════════════════════════════
   DESIGN TOKENS — TEMA CHIARO (default)
═══════════════════════════════════════════════════ */
:root {
  color-scheme: light;

  /* Brand — --primary può essere sovrascritto da settings.tema_colore */
  --primary:       #2563eb;
  --primary-dark:  color-mix(in srgb, var(--primary) 86%, #000);
  --primary-hover: var(--primary-dark);
  --primary-light: color-mix(in srgb, var(--primary) 8%,  var(--surface-card));
  --primary-glow:  color-mix(in srgb, var(--primary) 22%, transparent);
  --primary-soft:  color-mix(in srgb, var(--primary) 14%, var(--surface-card));
  --on-primary:    #ffffff;

  /* Semantic */
  --danger:         #dc2626;
  --danger-light:   #fef2f2;
  --danger-border:  #fca5a5;
  --danger-strong:  #991b1b;
  --success:        #16a34a;
  --success-light:  #f0fdf4;
  --success-border: #86efac;
  --success-strong: #166534;
  --warning:        #d97706;
  --warning-light:  #fffbeb;
  --warning-border: #fcd34d;
  --warning-strong: #92400e;
  --info:           #0891b2;
  --info-light:     #ecfeff;
  --info-border:    #67e8f9;
  --info-strong:    #155e75;

  /* Tinte pill/badge — coppia sfondo + testo, ridefinita nel tema scuro.
     Usate anche dagli style inline dei template. */
  --tint-slate-bg:  #f1f5f9;  --tint-slate-fg:  #475569;
  --tint-blue-bg:   #dbeafe;  --tint-blue-fg:   #1d4ed8;
  --tint-green-bg:  #dcfce7;  --tint-green-fg:  #15803d;
  --tint-red-bg:    #fee2e2;  --tint-red-fg:    #dc2626;
  --tint-amber-bg:  #fef3c7;  --tint-amber-fg:  #b45309;
  --tint-yellow-bg: #fef9c3;  --tint-yellow-fg: #713f12;
  --tint-orange-bg: #ffedd5;  --tint-orange-fg: #c2410c;
  --tint-indigo-bg: #e0e7ff;  --tint-indigo-fg: #4338ca;
  --tint-violet-bg: #f3e8ff;  --tint-violet-fg: #7c3aed;
  --tint-pink-bg:   #fce7f3;  --tint-pink-fg:   #9d174d;
  --tint-cyan-bg:   #ecfeff;  --tint-cyan-fg:   #155e75;

  /* Sidebar */
  --sidebar-width:           15.75rem;  /* 252px */
  --sidebar-width-collapsed: 3.75rem;   /* 60px  */
  --sidebar-bg:          #1e293b;
  --sidebar-border:      rgba(255,255,255,.07);
  --sidebar-text:        #94a3b8;
  --sidebar-heading:     #475569;
  --sidebar-strong:      #f1f5f9;
  --sidebar-hover:       rgba(255,255,255,.06);
  --sidebar-active-bg:   color-mix(in srgb, var(--primary) 18%, transparent);
  --sidebar-active-text: #93c5fd;

  /* Surface */
  --surface:      #f1f5f9;   /* sfondo pagina */
  --surface-card: #ffffff;   /* card, topbar, modal */
  --surface-2:    #f8fafc;   /* thead, hover riga, footer tabella */
  --surface-3:    #f1f5f9;   /* chip, sfondi tenui */
  --input-bg:     #ffffff;
  --overlay:      rgba(15,23,42,.45);
  --tooltip-bg:   #1e293b;
  --tooltip-fg:   #f1f5f9;

  --border:        #e2e8f0;
  --border-hover:  #cbd5e1;
  --border-strong: #94a3b8;

  /* Alias usati da alcuni template (compensi, note cliente, pagamenti fattura):
     erano riferimenti a token mai definiti, quindi quegli sfondi restavano
     trasparenti. Risolvono a --surface-2, quindi seguono il tema. */
  --bg-alt:       var(--surface-2);
  --bg-secondary: var(--surface-2);

  /* Text */
  --text:        #0f172a;
  --text-muted:  #64748b;
  --text-subtle: #94a3b8;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 8px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 24px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.04);

  /* Radius */
  --radius-sm:   .375rem;
  --radius:      .625rem;
  --radius-md:   .75rem;
  --radius-lg:   1rem;
  --radius-xl:   1.25rem;
  --radius-full: 9999px;

  /* Motion */
  --ease:       cubic-bezier(.4,0,.2,1);
  --transition: .15s var(--ease);
}

/* ═══════════════════════════════════════════════════
   DESIGN TOKENS — TEMA SCURO
   Attivato da data-theme="dark" su <html>, impostato
   dallo script pre-paint in base.html (nessun flash).
═══════════════════════════════════════════════════ */
html[data-theme="dark"] {
  color-scheme: dark;

  --primary-dark:  color-mix(in srgb, var(--primary) 82%, #fff);
  --primary-hover: color-mix(in srgb, var(--primary) 78%, #fff);
  --primary-light: color-mix(in srgb, var(--primary) 16%, var(--surface-card));
  --primary-glow:  color-mix(in srgb, var(--primary) 32%, transparent);
  --primary-soft:  color-mix(in srgb, var(--primary) 22%, var(--surface-card));

  --danger:         #f87171;
  --danger-light:   rgba(239,68,68,.14);
  --danger-border:  rgba(239,68,68,.42);
  --danger-strong:  #fca5a5;
  --success:        #4ade80;
  --success-light:  rgba(34,197,94,.14);
  --success-border: rgba(34,197,94,.42);
  --success-strong: #86efac;
  --warning:        #fbbf24;
  --warning-light:  rgba(245,158,11,.14);
  --warning-border: rgba(245,158,11,.42);
  --warning-strong: #fcd34d;
  --info:           #22d3ee;
  --info-light:     rgba(6,182,212,.14);
  --info-border:    rgba(6,182,212,.42);
  --info-strong:    #67e8f9;

  --tint-slate-bg:  rgba(148,163,184,.16); --tint-slate-fg:  #cbd5e1;
  --tint-blue-bg:   rgba(59,130,246,.20);  --tint-blue-fg:   #93c5fd;
  --tint-green-bg:  rgba(34,197,94,.20);   --tint-green-fg:  #86efac;
  --tint-red-bg:    rgba(239,68,68,.20);   --tint-red-fg:    #fca5a5;
  --tint-amber-bg:  rgba(245,158,11,.20);  --tint-amber-fg:  #fcd34d;
  --tint-yellow-bg: rgba(234,179,8,.20);   --tint-yellow-fg: #fde68a;
  --tint-orange-bg: rgba(249,115,22,.20);  --tint-orange-fg: #fdba74;
  --tint-indigo-bg: rgba(99,102,241,.20);  --tint-indigo-fg: #a5b4fc;
  --tint-violet-bg: rgba(139,92,246,.20);  --tint-violet-fg: #c4b5fd;
  --tint-pink-bg:   rgba(236,72,153,.20);  --tint-pink-fg:   #f9a8d4;
  --tint-cyan-bg:   rgba(6,182,212,.20);   --tint-cyan-fg:   #67e8f9;

  --sidebar-bg:      #0b111c;
  --sidebar-border:  rgba(255,255,255,.06);
  --sidebar-text:    #8fa0ba;
  --sidebar-heading: #5b6a83;
  --sidebar-strong:  #e6ebf4;
  --sidebar-hover:   rgba(255,255,255,.05);

  --surface:      #0f1520;
  --surface-card: #171f2e;
  --surface-2:    #1c2536;
  --surface-3:    #232d40;
  --input-bg:     #131b28;
  --overlay:      rgba(2,6,15,.66);
  --tooltip-bg:   #2a3548;
  --tooltip-fg:   #e6ebf4;

  --border:        #2a3548;
  --border-hover:  #3d4b64;
  --border-strong: #556480;

  --text:        #e6ebf4;
  --text-muted:  #9aa8bf;
  --text-subtle: #6f7d95;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.30);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.38), 0 1px 2px rgba(0,0,0,.24);
  --shadow-md: 0 4px 8px rgba(0,0,0,.42), 0 2px 4px rgba(0,0,0,.26);
  --shadow-lg: 0 10px 28px rgba(0,0,0,.52), 0 4px 10px rgba(0,0,0,.32);
}

/* ═══════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
  /* Previene scrollbar orizzontale di pagina anche a zoom alto */
  overflow-x: clip;
}

body {
  font-family: 'Figtree', 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--surface);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: .875rem;      /* 14px @ root 16px */
  line-height: 1.55;
  letter-spacing: -.005em;
  /* Fallback overflow-x per browser legacy */
  overflow-x: clip;
}

/* Cambio tema: transizione breve, disattivata per chi preferisce meno movimento */
body, .sidebar, .topbar, .card, .stat-card, .modal, input, select, textarea {
  transition: background-color .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* Permette ai flex children di shrinkare sotto il min-content (essenziale per zoom) */
.main, .content, .topbar, .card, .card-body, .card-header { min-width: 0; }

/* Input/select non sfondano mai il loro container (anche con inline width:NNNpx) */
input, select, textarea { max-width: 100%; box-sizing: border-box; }

a { color: inherit; }

/* Cifre a larghezza fissa: importi e quantità restano incolonnati */
td, .stat-value, .totale-row, input[type="number"], .righe-table input.num {
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Thin scrollbar inside sidebar */
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.10); border-radius: 2px; }

/* ── Logo ── */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-logo-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 800;
  flex-shrink: 0;
  letter-spacing: -.03em;
}
.sidebar-logo h1 {
  color: var(--sidebar-strong);
  font-size: .875rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logo span {
  display: block;
  color: var(--sidebar-text);
  font-size: .6875rem;
  margin-top: .0625rem;
}

/* ── Nav ── */
.sidebar-nav {
  padding: .5rem;
  flex: 1;
}

.nav-section {
  font-size: .625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .10em;
  color: var(--sidebar-heading);
  padding: 1rem .5rem .25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .5625rem;
  padding: .5rem .625rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .8125rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  margin-bottom: .0625rem;
  position: relative;
  min-height: 2.25rem;
}
.nav-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-strong);
}
.nav-link:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
}
/* Indicatore verticale sinistra */
.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: .375rem; bottom: .375rem;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.nav-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  opacity: .75;
}
.nav-link.active .nav-icon { opacity: 1; }
/* Il numero accanto a una voce: cose che aspettano qualcuno. */
.nav-count {
  margin-left: auto;
  min-width: 1.25rem;
  padding: 0 .375rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: .6875rem;
  font-weight: 700;
  line-height: 1.25rem;
  text-align: center;
}
/* Il numero senza urgenza: arancio. Rosso resta per cio' che scade. */
.nav-count.calmo { background: var(--warning); }
.nav-link:hover .nav-icon  { opacity: .95; }

/* ── Sidebar footer (utente) ── */
.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: .75rem .875rem;
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .625rem;
}
.sidebar-user-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8125rem;
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1;
}
.sidebar-user-avatar-img {
  object-fit: cover;
  background: transparent;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--sidebar-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.sidebar-user-role {
  font-size: .6875rem;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.sidebar-logout {
  color: var(--sidebar-text);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
  text-decoration: none;
}
.sidebar-logout:hover { color: var(--sidebar-strong); background: var(--sidebar-hover); }
.sidebar-logout:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ═══════════════════════════════════════════════════
   MAIN LAYOUT
═══════════════════════════════════════════════════ */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ═══════════════════════════════════════════════════
   TOPBAR
═══════════════════════════════════════════════════ */
.topbar {
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-xs);
}
.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
}
/* Pastiglie del filtro di stato (components/filtro_stato.html): il colore
   lo danno le classi .badge-<valore>, qui solo forma e scelta. */
.filtro-stato {
  padding: .25rem .75rem; border-radius: var(--radius-full);
  font-size: .75rem; font-weight: 600; text-decoration: none;
  border: 1.5px solid transparent;
}
.filtro-stato .n { opacity: .6; margin-left: .25rem; font-weight: 700; }
.filtro-stato.neutro { background: var(--surface-card); color: var(--text-muted); border-color: var(--border); }
.filtro-stato.attivo { border-color: currentColor; box-shadow: 0 0 0 1px currentColor; }
.filtro-stato.neutro.attivo { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: none; }
.filtro-stato:not(.attivo):hover { filter: brightness(.96); }
button.filtro-stato { font-family: inherit; line-height: inherit; cursor: pointer; }
button.filtro-stato.attivo { font-weight: 700; }
/* Le tendine di stato: il colore dello stato scelto, e di ogni voce. */
select.filtro-stato-select[class*="badge-"] { font-weight: 600; }

/* I tag (components/tag.html): contorno sottile, angoli squadrati e «#»
   davanti, perche' non si confondano con lo stato, che e' una pillola piena.
   --tag e' il colore del testo scelto in Impostazioni; nel tema scuro si
   schiarisce, altrimenti un colore scuro sparirebbe sul fondo. */
.tag {
  --tag: var(--text-muted);
  display: inline-flex; align-items: center;
  padding: 0 .375rem;
  border: 1px solid color-mix(in srgb, var(--tag) 40%, transparent);
  border-radius: .25rem;
  background: transparent;
  color: var(--tag);
  font-size: .6875rem; font-weight: 500; line-height: 1.55;
  text-decoration: none;
}
.tag::before { content: "#"; opacity: .55; margin-right: .0625rem; }
.tag-piccolo { font-size: .625rem; padding: 0 .3125rem; }
/* «Fine mese» su ordini e interventi (27/10/2026): un'etichetta, non un tag
   dell'anagrafica, quindi niente «#». */
.tag.tag-fine-mese { --tag: #b45309; font-weight: 600; white-space: nowrap; vertical-align: middle; }
.tag.tag-fine-mese::before { content: none; }
html[data-theme="dark"] .tag { color: color-mix(in srgb, var(--tag) 45%, #fff); }
.tag-filtro { font-size: .75rem; padding: .125rem .5rem; }
.tag-filtro .n { opacity: .6; margin-left: .25rem; font-weight: 700; }
.tag-filtro:not(.attivo):hover { background: color-mix(in srgb, var(--tag) 8%, transparent); }
.tag-filtro.attivo { background: color-mix(in srgb, var(--tag) 14%, transparent); border-color: currentColor; font-weight: 600; }

/* Accanto allo stato: a che punto e' con la fattura
   (components/fatturazione.html). */
.fatt-converti { display: inline-block; margin: 0 0 0 .375rem; vertical-align: middle; }
/* Da fatturare: rosso pieno, deve saltare all'occhio (26/10/2026). */
.btn.btn-converti { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn.btn-converti:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.fatt-esito {
  display: inline-block; margin-left: .375rem; vertical-align: middle;
  font-size: .75rem; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.fatt-esito.fatturato { color: var(--tint-green-fg, #15803d); }
/* Esportato a Danea, stato ancora da chiudere a mano. */
.fatt-esito.danea {
  color: var(--tint-amber-fg, #b45309);
  border: 1px dashed currentColor; border-radius: .25rem; padding: 0 .375rem;
}
.fatt-esito.in-bozza {
  color: var(--tint-blue-fg, #1d4ed8);
  border: 1px dashed currentColor; border-radius: .25rem; padding: 0 .375rem;
}
.stato-testa { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.stato-testa .fatt-converti, .stato-testa .fatt-esito { margin-left: 0; }
.stato-bloccato {
  margin-top: .5rem; padding: .5rem .75rem; font-size: .8125rem;
  background: var(--surface-2, #f8fafc); border: 1px solid var(--border); border-radius: var(--radius, .5rem);
}
.stato-bloccato details { margin-top: .375rem; }
.stato-bloccato summary { cursor: pointer; font-size: .75rem; color: var(--text-muted); }
.stato-sblocco { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .5rem 0 .25rem; }
.stato-sblocco input[name="motivo"] { flex: 1 1 16rem; }
.stato-sblocchi { margin-top: .5rem; }

/* Riepilogo dell'elenco accanto al titolo: resta in vista mentre si scorre. */
.riepilogo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 0;
}
.riepilogo-n strong { color: var(--text); font-size: .9375rem; }
.riepilogo-eur { padding-left: .5rem; border-left: 1px solid var(--border); }
.riepilogo-ivato { color: var(--text); font-weight: 600; }
.riepilogo-filtro {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: var(--radius-full);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  cursor: pointer;
}
.riepilogo-filtro:hover { color: var(--primary); border-color: var(--primary); }
@media (max-width: 1280px) { .riepilogo-eur:not(.riepilogo-ivato) { display: none; } }
@media (max-width: 900px)  { .riepilogo-eur { display: none; } }
.topbar-search {
  flex: 1;
  max-width: 21.25rem;
  position: relative;
}
.topbar-search-icon {
  position: absolute;
  left: .6875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
  display: block;
  flex-shrink: 0;
}
.topbar-search input {
  width: 100%;
  padding: .4375rem .75rem .4375rem 2.125rem;
  font-size: .8125rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text);
  transition: all var(--transition);
  height: 2.25rem;
}
.topbar-search input:hover { border-color: var(--border-hover); }
.topbar-search input:focus {
  background: var(--input-bg);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  outline: none;
}
.topbar-search input::placeholder { color: var(--text-subtle); }

.topbar-actions { display: flex; gap: .375rem; align-items: center; flex-shrink: 0; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .25rem .625rem .25rem .25rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background var(--transition), border-color var(--transition);
  margin-left: .25rem;
  min-height: 2.25rem;
}
.topbar-user:hover { background: var(--surface); border-color: var(--border-hover); }
.topbar-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1;
}
.topbar-avatar-img {
  object-fit: cover;
  background: transparent;
}
.topbar-user-name {
  font-size: .8125rem;
  font-weight: 500;
}

/* ── Selettore tema (chiaro / scuro / sistema) ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 2.125rem;
  height: 2.125rem;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--surface); color: var(--text); border-color: var(--border-hover); }
.theme-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.theme-toggle svg { width: 1.0625rem; height: 1.0625rem; }

/* L'icona mostrata dipende dal tema attivo */
.theme-icon-sun,
.theme-icon-moon,
.theme-icon-auto { display: none; }
html[data-theme="light"] .theme-icon-sun  { display: block; }
html[data-theme="dark"]  .theme-icon-moon { display: block; }
html[data-theme-pref="auto"] .theme-icon-sun,
html[data-theme-pref="auto"] .theme-icon-moon { display: none; }
html[data-theme-pref="auto"] .theme-icon-auto { display: block; }

/* ═══════════════════════════════════════════════════
   CONTENT
═══════════════════════════════════════════════════ */
.content {
  padding: 1.5rem;
  flex: 1;
  width: 100%;
}

/* Su schermi molto larghi il contenuto non si stira all'infinito */
@media (min-width: 2560px) {
  .content { max-width: 110rem; margin-inline: auto; }
}

/* ═══════════════════════════════════════════════════
   CARDS
═══════════════════════════════════════════════════ */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 3.25rem;
}
.card-title {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
}
.card-body { padding: 1.25rem; }

/* ═══════════════════════════════════════════════════
   STAT CARDS
   Struttura: label + value + sub. Nessun pseudo-elemento.
   Colore tramite border-left su varianti danger/warning/success/primary.
═══════════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11.875rem, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: .375rem;
}

/* Varianti cromatiche — solo border-left */
.stat-card.danger  { border-left-color: var(--danger); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.primary { border-left-color: var(--primary); }
.stat-card.info    { border-left-color: var(--info); }

.stat-label {
  font-size: .6875rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  letter-spacing: -.02em;
}
/* Colore valore semantico opzionale */
.stat-value.danger  { color: var(--danger); }
.stat-value.warning { color: var(--warning); }
.stat-value.success { color: var(--success); }
.stat-value.primary { color: var(--primary); }

.stat-sub {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .125rem;
}
.stat-sub a { color: var(--primary); text-decoration: none; font-weight: 500; }
.stat-sub a:hover { text-decoration: underline; }

/* ═══════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .4375rem .875rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition),
              transform var(--transition);
  line-height: 1.4;
  white-space: nowrap;
  font-family: inherit;
  min-height: 2.25rem;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Primary */
.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary-dark);
  box-shadow: 0 1px 2px var(--primary-glow);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 12px var(--primary-glow);
  color: var(--on-primary);
}

/* Secondary / ghost */
.btn-secondary {
  background: var(--surface-card);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background: var(--surface-2);
  border-color: var(--border-hover);
  color: var(--text);
}

/* Danger */
.btn-danger {
  background: var(--tint-red-bg);
  color: var(--tint-red-fg);
  border-color: var(--danger-border);
}
.btn-danger:hover {
  background: color-mix(in srgb, var(--tint-red-bg) 70%, var(--danger));
  border-color: var(--danger);
  color: var(--tint-red-fg);
}

/* Success */
.btn-success {
  background: var(--tint-green-bg);
  color: var(--tint-green-fg);
  border-color: var(--success-border);
}
.btn-success:hover {
  background: color-mix(in srgb, var(--tint-green-bg) 70%, var(--success));
  border-color: var(--success);
  color: var(--tint-green-fg);
}

/* Warning */
.btn-warning {
  background: var(--tint-amber-bg);
  color: var(--tint-amber-fg);
  border-color: var(--warning-border);
}
.btn-warning:hover {
  background: color-mix(in srgb, var(--tint-amber-bg) 70%, var(--warning));
  border-color: var(--warning);
  color: var(--tint-amber-fg);
}

/* Size modifiers */
.btn-sm { padding: .25rem .625rem; font-size: .75rem;   min-height: 1.75rem; }
.btn-xs { padding: .125rem .5rem;  font-size: .6875rem; min-height: 1.5rem; }
.btn-icon    { padding: .375rem; border-radius: var(--radius-sm); }
.btn-icon-sm { padding: .25rem;  border-radius: var(--radius-sm); }

/* ═══════════════════════════════════════════════════
   TABLES
═══════════════════════════════════════════════════ */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8125rem;
}
thead th {
  background: var(--surface-2);
  padding: .5625rem .875rem;
  text-align: left;
  font-weight: 700;
  font-size: .6875rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child { border-bottom: none; }
td {
  padding: .6875rem .875rem;
  color: var(--text);
  vertical-align: middle;
}
td a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
td a:hover { text-decoration: underline; }

/* Nel tema scuro il link primario è più leggibile schiarito.
   `:not(.wa-link)` non è cosmetico: `html[data-theme="dark"] td a` pesa (0,1,3)
   e batteva `.wa-link` (0,1,0), mentre `.wa-link:hover` (0,2,0) la ribatteva —
   per questo in elenco l'icona WhatsApp si vedeva **solo al passaggio del
   mouse**, e solo dentro una tabella. Misurato in un browser il 08/09/2026. */
html[data-theme="dark"] td a:not(.wa-link),
html[data-theme="dark"] .stat-sub a {
  color: color-mix(in srgb, var(--primary) 55%, #fff);
}

/* ═══════════════════════════════════════════════════
   BADGES
   Pill semplici, nessun ::before dot. Colori dai token
   tinta, così il tema scuro li ridefinisce in un punto solo.
═══════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .125rem .5625rem;
  border-radius: var(--radius-full);
  font-size: .6875rem;
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1.6;
}

/* Il colore dice quanto in fretta va guardato, uguale in ogni entita':
   rosso urgente (tocca a noi, soldi fermi), arancio tocca a noi, giallo
   aspetta altri, blu in corso, verde chiuso bene, grigio fuori gioco.
   Gli stati di ordini, DDT, interventi e preventivi li sovrascrive il CSS
   generato da Impostazioni (scripts/colori_stati.py); questi valgono per
   gli stati scritti nel codice e come ripiego. */
.badge-da_fatturare, .badge-da_ordinare, .badge-scaduto,
.badge-saldato_da_fatturare { background: var(--tint-red-bg);    color: var(--tint-red-fg); }
.badge-bozza, .badge-aperto, .badge-nuovo,
.badge-fatturato_parziale   { background: var(--tint-orange-bg); color: var(--tint-orange-fg); }
.badge-inviato, .badge-emesso, .badge-emessa, .badge-standby, .badge-in_ordine,
.badge-attesa_acconto, .badge-attesa_contratto, .badge-attesa_feedback,
.badge-in_attesa_ricambi, .badge-pronto_avvisato { background: var(--tint-yellow-bg); color: var(--tint-yellow-fg); }
.badge-in_lavorazione, .badge-attivo { background: var(--tint-blue-bg); color: var(--tint-blue-fg); }
.badge-accettato, .badge-completato, .badge-consegnato, .badge-fatturato, .badge-chiuso,
.badge-pagata, .badge-saldato_fatturato, .badge-rinnovato, .badge-firmato,
.badge-confermato { background: var(--tint-green-bg); color: var(--tint-green-fg); }
.badge-annullato, .badge-annullata, .badge-rifiutato, .badge-cancellato,
.badge-scartato { background: var(--tint-slate-bg); color: var(--tint-slate-fg); }
/* Richieste (richieste.py): arancione quello che aspetta noi, verde vinto,
   rosso perso. Le sfumature distinguono gli stati aperti fra loro. */
.badge-rq-nuova { background: var(--tint-orange-bg); color: var(--tint-orange-fg); font-weight: 700; }
.badge-rq-in_lavorazione { background: var(--tint-amber-bg); color: var(--tint-amber-fg); }
.badge-rq-appuntamento { background: var(--tint-amber-bg); color: var(--tint-amber-fg); }
.badge-rq-preventivo { background: var(--tint-yellow-bg); color: var(--tint-yellow-fg); }
.badge-rq-vinta { background: var(--tint-green-bg); color: var(--tint-green-fg); }
.badge-rq-persa { background: var(--tint-red-bg); color: var(--tint-red-fg); }
.badge-rq-annullata { background: var(--tint-slate-bg); color: var(--tint-slate-fg); }
.badge-rq-prospect { background: var(--tint-violet-bg); color: var(--tint-violet-fg); }
.badge-canale-whatsapp { background: var(--tint-green-bg); color: var(--tint-green-fg); }
.badge-canale-email { background: var(--tint-blue-bg); color: var(--tint-blue-fg); }
.badge-canale-telefono { background: var(--tint-indigo-bg); color: var(--tint-indigo-fg); }
.badge-canale-di_persona { background: var(--tint-violet-bg); color: var(--tint-violet-fg); }
.badge-canale-altro { background: var(--tint-slate-bg); color: var(--tint-slate-fg); }
.badge-tinta-cyan { background: var(--tint-cyan-bg); color: var(--tint-cyan-fg); }
.badge-tinta-pink { background: var(--tint-pink-bg); color: var(--tint-pink-fg); }
.badge-tinta-indigo { background: var(--tint-indigo-bg); color: var(--tint-indigo-fg); }
.badge-tinta-blue { background: var(--tint-blue-bg); color: var(--tint-blue-fg); }
.badge-tinta-violet { background: var(--tint-violet-bg); color: var(--tint-violet-fg); }
.badge-tinta-yellow { background: var(--tint-yellow-bg); color: var(--tint-yellow-fg); }
.badge-tinta-slate { background: var(--tint-slate-bg); color: var(--tint-slate-fg); }
/* L'evidenza: una barra a sinistra della riga o della scheda. */
.rq-evidenza-rosso { box-shadow: inset 4px 0 0 var(--tint-red-fg); }
.rq-evidenza-arancio { box-shadow: inset 4px 0 0 var(--tint-orange-fg); }
.rq-evidenza-verde { box-shadow: inset 4px 0 0 var(--tint-green-fg); }
.rq-testo { background: var(--surface); padding: .625rem .75rem; border-radius: .375rem; line-height: 1.6; }
.rq-testo ul, .rq-testo ol { padding-left: 1.375rem; }
.rq-soluzione { border-left: 4px solid var(--tint-green-fg); }
/* L'editor di «Cosa chiede» e «Soluzione»: si allarga trascinando l'angolo. */
.richtext-wrap { border: 1px solid var(--border); border-radius: .375rem; overflow: hidden; }
.richtext-toolbar { display: flex; gap: .1875rem; padding: .3125rem .5rem; background: var(--surface-2, #f8fafc); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.richtext-toolbar button { padding: .1875rem .5rem; border: 1px solid var(--border); border-radius: .25rem; background: var(--surface-card, white); color: inherit; cursor: pointer; font-size: .75rem; line-height: 1.4; }
.richtext-editor.rq-editor { padding: .625rem .75rem; min-height: 10rem; height: 12rem; resize: vertical; overflow: auto; outline: none; font-size: .875rem; line-height: 1.6; background: var(--surface-card, white); }
.richtext-editor.rq-editor ul, .richtext-editor.rq-editor ol { padding-left: 1.375rem; }
.richtext-editor.rq-editor:empty::before { content: attr(data-segnaposto); color: var(--text-muted); }

/* Badge modificabile: un <select> che cambia lo stato restando una pill.
   Serve a neutralizzare la regola globale su input/select/textarea, che
   imporrebbe width:100% e min-height:2.25rem dentro la cella di tabella.
   background e color restano quelli della classe badge-<valore>. */
select.badge {
  width: auto;
  min-height: 0;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  /* Spazio a destra per la freccia disegnata sotto */
  padding: .125rem 1.25rem .125rem .5625rem;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='currentColor'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .5rem center;
  transition: border-color var(--transition), box-shadow var(--transition);
}
select.badge:hover  { border-color: currentColor; }
select.badge:focus  { outline: none; border-color: currentColor; box-shadow: 0 0 0 3px var(--primary-glow); }
/* Le opzioni ereditano il colore della pill, che su alcune combinazioni
   risulterebbe illeggibile nel menu a tendina del sistema. */
select.badge option { background: var(--surface-card); color: var(--text); }

/* ═══════════════════════════════════════════════════
   FORMS
═══════════════════════════════════════════════════ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13.75rem, 1fr));
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: .3125rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group.half { grid-column: span 2; }

label {
  font-size: .6875rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

input,
select,
textarea {
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  color: var(--text);
  background: var(--input-bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
  width: 100%;
  min-height: 1.25rem;
}
input:hover, select:hover { border-color: var(--border-hover); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea { resize: vertical; min-height: 5rem; }
select { cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--text-subtle); }
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════
   SEARCH BAR
═══════════════════════════════════════════════════ */
.search-bar {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  align-items: center;
  flex-wrap: wrap;
}
.search-bar input { max-width: 17.5rem; }

/* ═══════════════════════════════════════════════════
   ALERTS
   Bordo sinistro colorato, sfondo tenue, non pieno.
═══════════════════════════════════════════════════ */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: .625rem;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-left-width: 4px;
}
.alert-warning {
  background: var(--warning-light);
  color: var(--warning-strong);
  border-color: var(--warning-border);
  border-left-color: var(--warning);
}
.alert-danger {
  background: var(--danger-light);
  color: var(--danger-strong);
  border-color: var(--danger-border);
  border-left-color: var(--danger);
}
.alert-success {
  background: var(--success-light);
  color: var(--success-strong);
  border-color: var(--success-border);
  border-left-color: var(--success);
}
.alert-info {
  background: var(--info-light);
  color: var(--info-strong);
  border-color: var(--info-border);
  border-left-color: var(--info);
}
.alert a { color: inherit; font-weight: 600; }
.alert strong { font-weight: 700; }

/* ═══════════════════════════════════════════════════
   MODAL
═══════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  max-width: 31.25rem;
  width: 100%;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .16s var(--ease);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.97) translateY(-.375rem); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ═══════════════════════════════════════════════════
   RIGHE DOCUMENTO (editor righe preventivi/fatture)
═══════════════════════════════════════════════════ */
.righe-table { width: 100%; }
.righe-table th {
  background: var(--surface-2);
  padding: .5rem .625rem;
  font-size: .6875rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
}
.righe-table td { padding: .3125rem .25rem; }
.righe-table input { padding: .375rem .5rem; font-size: .8125rem; }
.righe-table input.desc { width: 100%; min-width: 12.5rem; }
.righe-table input.num  { width: 5rem; text-align: right; }
.righe-table input.um   { width: 3.75rem; }

/* ═══════════════════════════════════════════════════
   EMPTY STATE
═══════════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: var(--text-muted);
}
.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: .75rem;
  opacity: .55;
}
.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: .375rem;
  color: var(--text);
}
.empty-state p { font-size: .8125rem; color: var(--text-muted); }

/* ═══════════════════════════════════════════════════
   DETAIL SECTIONS
═══════════════════════════════════════════════════ */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11.25rem, 1fr));
  gap: 1rem;
}
.detail-item label {
  display: block;
  font-size: .625rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .1875rem;
}
.detail-item span { font-size: .875rem; color: var(--text); }
.detail-item.full { grid-column: 1 / -1; }

/* ═══════════════════════════════════════════════════
   TOTALE BOX
═══════════════════════════════════════════════════ */
.totale-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .375rem;
  padding: 1rem 1.25rem;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.totale-row {
  display: flex;
  gap: 2rem;
  justify-content: flex-end;
  font-size: .8125rem;
}
.totale-row span:first-child { color: var(--text-muted); }
.totale-row.grand {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -.015em;
  margin-top: .25rem;
  padding-top: .625rem;
  border-top: 2px solid var(--border);
}
html[data-theme="dark"] .totale-row.grand { color: color-mix(in srgb, var(--primary) 55%, #fff); }

/* ═══════════════════════════════════════════════════
   QUICK ACTIONS (dashboard)
═══════════════════════════════════════════════════ */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: 1rem 1.25rem;
}
.quick-action-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  transition: all var(--transition);
  cursor: pointer;
  font-family: inherit;
  min-height: 2.5rem;
}
.quick-action-btn:hover {
  background: var(--primary);
  border-color: var(--primary-dark);
  color: var(--on-primary);
  box-shadow: 0 4px 12px var(--primary-glow);
  transform: translateY(-1px);
}
.quick-action-btn:active { transform: translateY(0); }
.quick-action-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.quick-action-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  opacity: .7;
}
.quick-action-btn:hover .quick-action-icon { opacity: 1; }

/* ═══════════════════════════════════════════════════
   PAGINATION (JS-injected)
═══════════════════════════════════════════════════ */
.pg-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .625rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: .8125rem;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ═══════════════════════════════════════════════════
   UTILS
═══════════════════════════════════════════════════ */
.flex         { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1  { gap: .25rem; }
.gap-2  { gap: .5rem; }
.gap-3  { gap: .75rem; }
.mt-4   { margin-top: 1rem; }
.mt-6   { margin-top: 1.5rem; }
.mb-4   { margin-bottom: 1rem; }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: .75rem; }
.text-xs     { font-size: .6875rem; }
.font-bold   { font-weight: 700; }
.font-semibold { font-weight: 600; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.divider { height: 1px; background: var(--border); margin: 1.25rem 0; }

/* ═══════════════════════════════════════════════════
   AVATAR UPLOAD (profilo)
═══════════════════════════════════════════════════ */
.avatar-section {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.avatar-preview {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 800;
  flex-shrink: 0;
  overflow: hidden;
  border: 3px solid var(--border);
}
.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.avatar-upload-label {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .375rem .875rem;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  box-shadow: var(--shadow-xs);
}
.avatar-upload-label:hover { background: var(--surface-2); border-color: var(--border-hover); }

/* ═══════════════════════════════════════════════════
   PRINT
   La stampa è sempre su tema chiaro, anche se l'utente
   sta lavorando in dark mode.
═══════════════════════════════════════════════════ */
/* Ritorno all'elenco (static/js/ritorno.js): la riga del documento appena
   aperto si accende e si spegne, per ritrovarla a colpo d'occhio. */
.riga-appena-aperta > td { animation: riga-appena-aperta 3.5s ease-out; }
@keyframes riga-appena-aperta {
  0%, 40% { background: var(--tint-amber-bg, #fef3c7); }
  100% { background: transparent; }
}

@media print {
  html, html[data-theme="dark"] {
    color-scheme: light;
    --surface: #ffffff;
    --surface-card: #ffffff;
    --surface-2: #ffffff;
    --surface-3: #ffffff;
    --input-bg: #ffffff;
    --text: #000000;
    --text-muted: #444444;
    --text-subtle: #666666;
    --border: #cccccc;
    --border-hover: #999999;
  }
  body { background: #fff !important; color: #000 !important; font-size: .75rem; }
  .sidebar, .topbar, .no-print, .sidebar-overlay { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; max-width: none !important; margin-inline: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; }
  .btn { display: none !important; }
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════ */

/* ── Sidebar overlay (mobile) — comportamento pre-allocato dal JS ── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
  z-index: 99; /* sotto la sidebar (z:100) */
}
html.sidebar-mobile-open .sidebar-overlay {
  opacity: 1;
  pointer-events: auto;
}

/* Body lock quando sidebar mobile aperta — evita scroll dietro */
html.sidebar-mobile-open,
html.sidebar-mobile-open body { overflow: hidden; }

/* ────────────────────────────────────────────────────
   DESKTOP MEDIO  (≤ 1280px)
   Riduce padding, lascia sidebar visibile.
──────────────────────────────────────────────────── */
@media (max-width: 1280px) {
  .content { padding: 1.25rem; }
  .topbar { padding: 0 1.125rem; }
  .topbar-search { max-width: 17.5rem; }
}

/* ────────────────────────────────────────────────────
   TABLET LANDSCAPE  (≤ 1024px)
   Topbar più compatta, search più piccola.
──────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .topbar-search { max-width: 13.75rem; }
  .stat-value { font-size: 1.5rem; }
  .stats-grid { gap: .75rem; }
}

/* ────────────────────────────────────────────────────
   ZOOM DESKTOP / LAPTOP STRETTO  (≤ 1100px)
   Riduce padding e neutralizza min-width inline che a zoom 110-130%
   sforerebbero lo .content (sidebar 252px ancora visibile).
──────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .content { padding: 1rem; }
  .topbar { padding: 0 .875rem; }

  /* Form-grid più fluido: cellule possono restringersi sotto i 220px */
  .form-grid { grid-template-columns: repeat(auto-fit, minmax(min(11.25rem, 100%), 1fr)); gap: .75rem; }
  .detail-grid { grid-template-columns: repeat(auto-fit, minmax(min(10rem, 100%), 1fr)); }

  /* Tabella righe documento: neutralizza i min-width inline degli <th> */
  .righe-table th[style*="min-width"],
  .righe-table td[style*="min-width"] { min-width: 0 !important; }
  .righe-table th, .righe-table td { padding: .375rem .5rem; }
  .righe-table input { padding: .3125rem .375rem; }
  .righe-table input.desc { min-width: 8.75rem; }

  /* Search bar: input non bloccato a max-width */
  .search-bar input { flex: 1 1 12.5rem; min-width: 0; }

  /* Stats grid più compatte */
  .stat-card { padding: 1rem; }
  .stat-value { font-size: 1.5rem; }
}

/* ────────────────────────────────────────────────────
   TABLET PORTRAIT / SMARTPHONE LANDSCAPE  (≤ 900px)
   Sidebar diventa off-canvas.
──────────────────────────────────────────────────── */
@media (max-width: 900px) {
  /* Sidebar off-canvas; collapsed-mode disattivata */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s var(--ease);
    width: 15.75rem !important;
    box-shadow: 4px 0 16px rgba(0,0,0,.15);
  }
  html.sidebar-mobile-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0 !important; }

  /* Topbar: più stretta, actions wrappano se necessario */
  .topbar { padding: 0 .75rem; gap: .5rem; height: auto; min-height: 3.5rem; flex-wrap: wrap; }
  .topbar-title {
    font-size: .875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 0 1 auto;
  }
  .topbar-search { flex: 1 1 100%; max-width: none; order: 99; padding-bottom: .5rem; }
  .topbar-actions { flex-wrap: wrap; gap: .25rem; justify-content: flex-end; margin-left: auto; }
  .topbar-actions .btn { font-size: .75rem; padding: .375rem .625rem; }

  .content { padding: 1rem; }

  /* Grid inline (style="grid-template-columns: repeat(N,...)" con N>2) → 2 col */
  [style*="repeat(3,"], [style*="repeat(4,"],
  [style*="repeat(5,"], [style*="repeat(6,"] {
    grid-template-columns: 1fr 1fr !important;
  }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.375rem; }

  /* Form: minmax più permissivo per evitare overflow */
  .form-grid { grid-template-columns: repeat(auto-fit, minmax(min(11.25rem, 100%), 1fr)); gap: .75rem; }
  .form-group.half { grid-column: 1 / -1; }

  .detail-grid { grid-template-columns: repeat(auto-fit, minmax(min(9.375rem, 100%), 1fr)); }

  /* Tap target più grandi */
  .btn-sm, .btn-icon { min-height: 2.375rem; min-width: 2.375rem; }
  .btn-xs { min-height: 2rem; }
  /* Evita zoom iOS su focus input (font-size ≥ 16px) */
  input, select, textarea { font-size: 1rem; }

  /* Modal: padding ridotto */
  .modal { padding: 1.25rem; }
}

/* ────────────────────────────────────────────────────
   MOBILE PORTRAIT  (≤ 600px)
──────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Tutte le inline grid → singola colonna */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: .625rem; }
  .grid-3 { grid-template-columns: 1fr; }

  /* Topbar pulita: niente search globale, niente nome utente */
  .topbar { flex-wrap: nowrap; height: 3.5rem; min-height: 3.5rem; }
  .topbar-search { display: none; }
  .topbar-user-name { display: none; }
  .topbar-title { font-size: .8125rem; }
  .topbar-user { padding: .25rem; border: none; }

  /* Content + card padding tighter */
  .content { padding: .75rem; }
  .card-body { padding: .875rem; }
  .card-header { padding: .625rem .875rem; min-height: 2.75rem; flex-wrap: wrap; }
  .card-header h3, .card-title { font-size: .875rem; }

  /* Stat card più compatta */
  .stat-card { padding: .875rem; }
  .stat-value { font-size: 1.25rem; }
  .stat-label { font-size: .625rem; }

  /* Tabelle: scroll touch + font ridotto + scroll-hint sui bordi */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background:
      linear-gradient(to right, var(--surface-card) 30%, transparent) left center,
      linear-gradient(to right, transparent, var(--surface-card) 70%) right center,
      radial-gradient(farthest-side at 0 50%, rgba(0,0,0,.10), transparent) left center,
      radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.10), transparent) right center;
    background-repeat: no-repeat;
    background-size: 30px 100%, 30px 100%, 12px 100%, 12px 100%;
    background-attachment: local, local, scroll, scroll;
  }
  .table-wrapper table { font-size: .75rem; }
  .table-wrapper th, .table-wrapper td { padding: .375rem .5rem; }

  /* Tabelle senza wrapper esplicito: forza scroll orizzontale dal card-body */
  .card-body > table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

  /* Righe-table (editor preventivi): scroll-x + input compatti */
  .righe-table { display: block; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
  .righe-table > thead, .righe-table > tbody { display: table; width: 100%; min-width: 40rem; }
  .righe-table input.desc { min-width: 10rem; }
  .righe-table input.num { width: 4.375rem; }
  .righe-table th, .righe-table td { padding: .25rem .375rem; }

  /* Search bar: input full-width, niente max */
  .search-bar { gap: .375rem; }
  .search-bar input { max-width: none; flex: 1 1 100%; min-width: 0; }
  .search-bar select { flex: 1 1 100%; }

  /* Form: single column su mobile */
  .form-grid { grid-template-columns: 1fr; gap: .625rem; }
  .form-group.half { grid-column: 1; }

  /* Detail grid: 2 col se possibile altrimenti 1 */
  .detail-grid { grid-template-columns: 1fr 1fr; gap: .625rem; }
  .detail-item.full { grid-column: 1 / -1; }

  /* Quick actions full-width stacked */
  .quick-actions { flex-direction: column; padding: .75rem .875rem; }
  .quick-action-btn { width: 100%; justify-content: flex-start; }

  /* Totale box: padding ridotto, allineamento dx mantenuto */
  .totale-box { padding: .75rem .875rem; }
  .totale-row { gap: 1rem; }
  .totale-row.grand { font-size: 1.125rem; }

  /* Modal: full-screen-ish */
  .modal-overlay { padding: .5rem; }
  .modal { padding: 1rem; max-height: calc(100vh - 1rem); border-radius: var(--radius-md); }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 auto; justify-content: center; }

  /* Avatar section: più stretta */
  .avatar-section { padding: .875rem; gap: .75rem; }
  .avatar-preview { width: 3.5rem; height: 3.5rem; font-size: 1.375rem; }

  /* Bottoni topbar */
  .topbar-actions .btn { font-size: .6875rem; padding: .3125rem .5rem; }
}

/* ────────────────────────────────────────────────────
   SMARTPHONE PICCOLO  (≤ 480px)
──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .topbar { padding: 0 .5rem; height: 3.25rem; min-height: 3.25rem; }
  .content { padding: .5rem; }
  .card-body { padding: .625rem; }
  .card-header { padding: .5rem .625rem; min-height: 2.5rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .topbar-title { font-size: .75rem; }
  .detail-grid { grid-template-columns: 1fr; }

  /* Sidebar overlay: quasi full-screen */
  .sidebar { width: 86vw !important; max-width: 18.75rem; }

  /* Stat-card single-col stacked: padding e value più grandi (più leggibile a piena larghezza) */
  .stat-card { padding: 1rem; }
  .stat-value { font-size: 1.5rem; }

  /* Pagination footer compatto */
  .pg-bar { padding: .5rem .75rem; font-size: .75rem; flex-wrap: wrap; gap: .375rem; }
}

/* ═══════════════════════════════════════════════════
   SCROLLBAR (Chromium)
═══════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ═══════════════════════════════════════════════════
   SIDEBAR COLLAPSE
═══════════════════════════════════════════════════ */
/* Smooth transition (sempre attiva) */
.sidebar { transition: width .18s ease; }
.main    { transition: margin-left .18s ease; }
.nav-link, .sidebar-logo, .sidebar-footer { transition: padding .18s ease; }

/* Stato collassato (classe applicata su <html> per evitare flash all'avvio) */
html.sidebar-collapsed .sidebar { width: var(--sidebar-width-collapsed); }
html.sidebar-collapsed .main    { margin-left: var(--sidebar-width-collapsed); }

html.sidebar-collapsed .sidebar-logo h1,
html.sidebar-collapsed .sidebar-logo span,
html.sidebar-collapsed .nav-section,
html.sidebar-collapsed .sidebar-user-info,
html.sidebar-collapsed .sidebar-logout {
  display: none;
}

html.sidebar-collapsed .sidebar-logo  { justify-content: center; padding: 1.125rem .5rem .875rem; }
html.sidebar-collapsed .sidebar-footer { padding: .75rem .5rem; }
html.sidebar-collapsed .sidebar-user  { justify-content: center; }

/* Nav link collassato: solo icona, font-size 0 nasconde testo inline */
html.sidebar-collapsed .nav-link {
  font-size: 0;
  justify-content: center;
  padding: .625rem .5rem;
  gap: 0;
}
html.sidebar-collapsed .nav-link .nav-icon { width: 1.125rem; height: 1.125rem; }
html.sidebar-collapsed .nav-count {
  position: absolute; top: .125rem; right: .125rem;
  min-width: 1rem; padding: 0 .25rem; font-size: .625rem; line-height: 1rem;
}

/* Tooltip on hover (testo iniettato via JS in data-tooltip) */
html.sidebar-collapsed .nav-link { position: relative; }
html.sidebar-collapsed .nav-link[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + .5rem);
  top: 50%;
  transform: translateY(-50%);
  background: var(--tooltip-bg);
  color: var(--tooltip-fg);
  padding: .3125rem .625rem;
  border-radius: var(--radius-sm);
  font-size: .75rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}

/* Bottone toggle in topbar */
.sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 2.125rem;
  height: 2.125rem;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-hover); }
.sidebar-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Contatti cliccabili — vedi templates/components/contatti.html */
.wa-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 62.4375rem;
  background: #25d366;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.5;
  vertical-align: middle;
  transition: filter .15s;
}
.wa-link:hover { filter: brightness(.92); color: #fff; text-decoration: none; }
/* L'icona non dipende dal colore del link: `fill="currentColor"` la
   legherebbe di nuovo a qualunque regola arrivi domani sul selettore `a`. */
.wa-link svg { flex-shrink: 0; fill: #fff; }
.contatto-riga { display: inline-flex; align-items: center; gap: 0.375rem; flex-wrap: wrap; }

/* Copia negli appunti — <button data-copia="..."> */
.btn-copia {
  border: 1px solid var(--border);
  background: var(--surface-2, #f8fafc);
  color: var(--text-muted);
  border-radius: var(--radius-sm, 0.25rem);
  font-size: 0.6875rem;
  line-height: 1;
  padding: 0.1875rem 0.375rem;
  cursor: pointer;
  vertical-align: middle;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-copia:hover { background: var(--surface, #fff); color: var(--text); border-color: var(--border-hover); }
.btn-copia:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-copia.copiato { background: #16a34a; border-color: #16a34a; color: #fff; }
.btn-copia.copia-fallita { background: var(--danger, #dc2626); border-color: var(--danger, #dc2626); color: #fff; }

/* Descrizioni delle righe: grandezza e carattere li decide il documento.
   Molte descrizioni portano font-size:14.2188px incollato dal browser
   (102 righe di preventivo e 39 d'ordine il 03/11/2026). */
.desc-edit * { font-size: inherit !important; font-family: inherit !important; line-height: inherit !important; }
