:root {
  --primary: #1e5c4f;
  --secondary: #a3e635;
  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --bg-hover: #f8fafc;
  --nav-active-bg: #f1f5f9;
  --nav-active-text: #1e5c4f;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-faint: #cbd5e1;
  --border: #e2e8f0;
  --success: #10b981;
  --success-bg: #f0fdf4;
  --success-text: #166534;
  --success-strong: #16a34a;
  --danger: #dc2626;
  --danger-light: #ef4444;
  --danger-bg: #fef2f2;
  --danger-strong: #991b1b;
  --warning: #f59e0b;
  --warning-bg: #fef9c3;
  --warning-text: #854d0e;
  --info-bg: #eff6ff;
  --info-text: #1d4ed8;
  --purple-bg: #faf5ff;
  --purple-text: #6d28d9;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --radius-lg: 1.5rem;
  --radius-md: 0.75rem;
  --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Tema scuro "Sistema": si applica solo se l'utente non ha scelto esplicitamente "Chiaro" */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-app: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --nav-active-bg: #334155;
    --nav-active-text: #a3e635;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-faint: #475569;
    --border: #334155;
    --success-bg: #052e1c;
    --success-text: #4ade80;
    --danger-bg: #450a0a;
    --sdi-rosso-text: #fca5a5;
    --warning-bg: #422006;
    --warning-text: #fde047;
    --info-bg: #172554;
    --info-text: #93c5fd;
    --purple-bg: #2e1065;
    --purple-text: #c4b5fd;
  }
}

/* Tema scuro scelto esplicitamente dall'utente, indipendente dal sistema operativo */
:root[data-theme="dark"] {
  --bg-app: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --nav-active-bg: #334155;
  --nav-active-text: #a3e635;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-faint: #475569;
  --border: #334155;
  --success-bg: #052e1c;
  --success-text: #4ade80;
  --danger-bg: #450a0a;
  --sdi-rosso-text: #fca5a5;
  --warning-bg: #422006;
  --warning-text: #fde047;
  --info-bg: #172554;
  --info-text: #93c5fd;
  --purple-bg: #2e1065;
  --purple-text: #c4b5fd;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease, padding 0.2s ease;
}

/* Concept: sidebar a scomparsa (solo desktop, vedi .sidebar-toggle / toggleSidebarCollapse) */
@media (min-width: 769px) {
  .sidebar.collapsed {
    width: 84px;
    min-width: 84px;
    padding: 2rem 0.9rem;
  }

  .sidebar.collapsed .sidebar-label {
    display: none;
  }

  .sidebar.collapsed #sidebar-header-row {
    flex-direction: column;
    gap: 0.75rem;
  }

  .sidebar.collapsed .flex.items-center.gap-3 {
    justify-content: center;
  }

  .sidebar.collapsed .nav-item {
    justify-content: center;
    gap: 0;
    padding: 0.75rem 0.5rem;
  }
}

.main-content {
  flex: 1;
  padding: 2.5rem;
  overflow-y: auto;
}

/* Components */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.stat-value {
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0.5rem 0;
}

.stat-trend {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--success-bg);
  color: var(--success-text);
}

.chart-section {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 2rem;
}

.chart-span-2 {
  grid-column: span 2;
}

/* WHY min-width:0 + overflow:hidden: senza questo il grafico Incassi, quando
   ha molte barre (periodo Personalizzato con range ampio), forza la sua
   colonna della grid a crescere oltre lo spazio disponibile invece di
   restare nel proprio track e scorrere internamente (vedi #chart-scroll in
   chart.html). */
#chart-card {
  min-width: 0;
  overflow: hidden;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-family: inherit;
  font-size: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  font-weight: 500;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
}

.nav-item:hover {
  background: var(--bg-hover);
}

.nav-item.active {
  background: var(--nav-active-bg);
  /* WHY: in tema scuro il verde primario su ardesia non si leggeva */
  color: var(--nav-active-text);
}

/* Voce di sottomenu (es. "Prodotti più venduti" sotto Statistiche). */
.nav-item.nav-sub {
  padding: 0.5rem 1rem 0.5rem 2.75rem;
  margin-top: -0.25rem;
  font-size: 0.85rem;
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.data-table th {
  text-align: left;
  padding: 1rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.data-table th.sortable:hover {
  color: var(--primary);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-card);
  border-radius: 1.5rem;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  padding: 2rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-body {
  overflow-y: auto;
  flex: 1;
}

/* Search */
.search-container {
  position: relative;
  max-width: 300px;
}

.search-input {
  width: 100%;
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  font-size: 0.875rem;
  outline: none;
  transition: all 0.2s;
  font-family: inherit;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(30, 92, 79, 0.1);
}

.search-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Login */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, var(--border), var(--bg-app));
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  padding: 2.5rem;
  border-radius: 2rem;
  box-shadow: var(--shadow);
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text-primary);
  outline: none;
  font-family: inherit;
  font-size: inherit;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(30, 92, 79, 0.1);
}

/* Utilities */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.text-center {
  text-align: center;
}

.gap-2 {
  gap: 0.5rem;
}

.gap-3 {
  gap: 0.75rem;
}

.gap-4 {
  gap: 1rem;
}

.mb-2 {
  margin-bottom: 0.5rem;
}

.mb-4 {
  margin-bottom: 1rem;
}

.mb-8 {
  margin-bottom: 2rem;
}

.text-sm {
  font-size: 0.875rem;
}

.text-xs {
  font-size: 0.75rem;
}

.text-muted {
  color: var(--text-secondary);
}

.font-bold {
  font-weight: 700;
}

.w-full {
  width: 100%;
}

.desktop-only {
  display: flex;
}

.hidden {
  display: none !important;
}

.theme-option {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
}

.theme-option.active {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--bg-hover);
}

/* HTMX loading indicator */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

/* Smooth transitions for HTMX swaps */
.htmx-swapping {
  opacity: 0;
  transition: opacity 0.15s ease-out;
}

.htmx-settling {
  opacity: 1;
  transition: opacity 0.15s ease-in;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
  .chart-section {
    grid-template-columns: minmax(0, 1fr);
  }

  /* WHY: con una sola colonna esplicita, uno "span 2" residuo dal layout
     desktop costringe la grid a crearsi una colonna implicita fantasma
     (per soddisfare lo span), che spinge la card larga oltre lo schermo. */
  .chart-span-2 {
    grid-column: auto;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    z-index: 1001;
    transition: left 0.3s ease;
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.1);
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: none;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .main-content {
    padding: 1.5rem;
    padding-top: 5rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .desktop-only {
    display: none;
  }

  header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 1.5rem;
  }

  .mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    display: flex;
    /* WHY: la regola `header` qui sopra impila in colonna le intestazioni di
       pagina; la barra fissa del menu deve restare su una riga, altrimenti
       raddoppia d'altezza e copre il titolo. */
    flex-direction: row;
    gap: 0;
    justify-content: space-between;
    align-items: center !important;
    z-index: 999;
    border-bottom: 1px solid var(--border);
  }

  .table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 1rem;
    border-radius: var(--radius-md);
  }

  .data-table {
    min-width: 600px;
  }

  .card {
    padding: 1.25rem;
  }

  .modal-content {
    padding: 1.5rem;
    width: 95%;
  }

  h1 {
    font-size: 1.5rem !important;
  }
}

/* Hidden elements on mobile by default */
.mobile-header {
  display: none;
}

@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }
}

@media print {
  .sidebar, .mobile-header, .sidebar-overlay, .no-print { display: none !important; }
  .main-content, .app-container { margin: 0 !important; padding: 0 !important; }
  @page { size: A4; margin: 1.5cm; }
  body { font-size: 11pt; color: #000; background: #fff; }
  .card { box-shadow: none !important; border: 1px solid #e2e8f0; }
  table { page-break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

/* Grafico Incassi: con molte barre (es. un mese di 31 giorni) il contenuto
   interno e' piu' largo del riquadro visibile e scorre orizzontalmente.
   Scrollbar sempre visibile (non overlay) cosi' e' chiaro che c'e' altro
   contenuto a destra invece di sembrare tagliato. */
.chart-scroll {
  scrollbar-width: thin;
  scrollbar-color: var(--text-faint) transparent;
}
.chart-scroll::-webkit-scrollbar {
  height: 8px;
}
.chart-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.chart-scroll::-webkit-scrollbar-thumb {
  background: var(--text-faint);
  border-radius: 4px;
}
.chart-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---------- Statistiche: istogramma per operatore, torta reparti, filtri ---------- */

/* Bottoni sotto le barre (mesi/giorni): posizionati da chart.html leggendo la x
   di ogni barra, così restano allineati anche quando il grafico scorre. */
.stats-pills {
  position: relative;
  height: 30px;
  margin-top: 0.5rem;
}

.stats-pill {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  min-width: 26px;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.stats-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.stats-pill.on {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--bg-card);
}

.stats-pill.empty:not(.on) {
  border-style: dashed;
  color: var(--text-faint);
}

.stats-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

.stats-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}

.stats-legend-item:hover {
  border-color: var(--primary);
}

.stats-legend-item.on {
  border-color: var(--text-primary);
  font-weight: 700;
}

/* Voce di legenda che non fa nulla al clic ("Altri", non filtrabile; "Costo
   merce", solo illustrativo): stesso aspetto disabilitato per entrambe,
   anche se una è un <button disabled> e l'altra uno <span> (che l'attributo
   disabled non lo supporta). */
.stats-legend-item[disabled],
.stats-legend-item.static,
.stats-legend-item.static:hover {
  cursor: default;
  border-color: var(--border);
  color: var(--text-muted);
  opacity: 0.7;
}

.stats-legend-item i,
.pie-row i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}

.pie-wrap {
  display: flex;
  justify-content: center;
}

.pie {
  width: 100%;
  max-width: 250px;
  height: auto;
  overflow: visible;
}

/* Anello sottile: ogni segmento è un arco con il bordo colorato (il colore sta
   nell'attributo stroke). Lo spessore va tenuto uguale a _STROKE in charts.py. */
.pie-slice {
  fill: none;
  stroke-width: 14;
  transition: opacity 0.15s, stroke-width 0.15s;
}

.pie-slice[data-stats-reparto] {
  cursor: pointer;
}

.pie-slice[data-stats-reparto]:hover {
  stroke-width: 17;
}

.pie-slice.dim {
  opacity: 0.25;
}

.pie-slice.picked {
  stroke-width: 18;
}

/* Con il clic il browser disegna un rettangolo di focus attorno all'elemento
   (per un segmento grande copre tutta la torta): lo togliamo e, per chi usa la
   tastiera, ingrandiamo e ombreggiamo il segmento invece del rettangolo. */
.pie-slice:focus,
.pie-center:focus {
  outline: none;
}

.pie-slice:focus-visible {
  stroke-width: 18;
  filter: drop-shadow(0 0 3px var(--text-primary));
}

.pie-tip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  padding: 0.45rem 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

.pie-center {
  cursor: pointer;
}

/* Il cerchio è solo l'area cliccabile del centro. */
.pie-center circle {
  fill: transparent;
  stroke: none;
  transition: fill 0.15s;
}

.pie-center:hover circle,
.pie-center:focus-visible circle {
  fill: var(--bg-app);
}

.pie-center text {
  fill: var(--text-primary);
  text-anchor: middle;
}

.pie-center .amount {
  font-weight: 700;
}

.pie-center .sub {
  fill: var(--text-secondary);
  font-size: 8.5px;
  font-weight: 600;
}

.pie-center .hint {
  fill: var(--text-muted);
  font-size: 7.5px;
}

.pie-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 1rem;
}

.pie-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  gap: 0.6rem;
  align-items: center;
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 0;
  border-radius: 0.6rem;
  background: none;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.8rem;
  text-align: left;
}

.pie-row[data-stats-reparto] {
  cursor: pointer;
}

.pie-row[data-stats-reparto]:hover {
  background: var(--bg-hover);
}

.pie-row.on {
  background: var(--success-bg);
  font-weight: 700;
}

.pie-row.vincite {
  margin-top: 0.25rem;
  border-top: 1px dashed var(--border);
  border-radius: 0;
  color: var(--danger-strong);
  font-weight: 600;
}

.pie-row .pct {
  width: 3rem;
  text-align: right;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.pie-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pie-more {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.6rem 0.5rem 0;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: var(--primary);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.pie-more:hover {
  text-decoration: underline;
}

.stats-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  min-height: 1.9rem;
}

.stats-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.35rem 0.2rem 0.7rem;
  border-radius: 999px;
  background: var(--success-bg);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
}

.stats-filter-chip small {
  color: var(--text-muted);
  font-weight: 500;
}

.stats-filter-chip button {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}

.stats-filter-chip button:hover {
  color: var(--danger);
}

.stats-link-btn {
  padding: 0 0.25rem;
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
}

.doc-reparto-cell {
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

/* Colonne numeriche della tabella Documenti: importi allineati a destra. */
.data-table th.num,
.data-table td.num {
  text-align: right;
  white-space: nowrap;
}

/* Con 9-11 colonne il padding standard (1rem) fa scorrere la tabella già a 1000px. */
#documents-card .data-table th,
#documents-card .data-table td {
  padding: 0.75rem 0.6rem;
}

#documents-card .data-table td.nowrap {
  white-space: nowrap;
}

.data-table .doc-detail-col {
  width: 1%;
  text-align: right;
}

.doc-detail-link {
  display: inline-flex;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
}

.doc-detail-link:hover,
.doc-detail-link:focus-visible {
  background: var(--bg-hover);
  color: var(--primary);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Totali dei documenti filtrati, sopra la tabella. */
.doc-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 0.75rem;
}

.doc-total {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-md);
  background: var(--bg-hover);
  border: 1px solid var(--border);
}

.doc-total span {
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.doc-total strong {
  color: var(--text-primary);
  font-size: 1.05rem;
}

.doc-total-reparto {
  background: var(--success-bg);
}

.doc-total-reparto strong {
  color: var(--primary);
}

/* Menu Tipo documento / Pagamento della tabella Documenti. */
.stats-doc-filter {
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.stats-doc-filter:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(30, 92, 79, 0.1);
}

/* Periodi rapidi di Vendite e Movimenti: il periodo scelto resta evidenziato. */
.date-presets {
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.date-preset {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  color: var(--primary);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.date-preset:hover {
  background: var(--bg-hover);
}

.date-preset[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* Guida online contestuale (templates/help, static/js/help.js) */
.help-dialog {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text-primary);
  width: min(720px, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  margin: auto;
  overflow: visible;
}

.help-dialog::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
}

.help-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 3rem);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.help-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.help-kicker {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.help-title {
  margin: 0.1rem 0 0;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
}

.help-close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
}

.help-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.help-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}

.help-toc[hidden] {
  display: none;
}

.help-toc a {
  padding: 0.2rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  text-decoration: none;
}

.help-toc a:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.help-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 1.5rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-secondary);
  outline: none;
}

.help-body h3 {
  margin: 1.5rem 0 0.4rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.help-body section:first-child h3,
.help-body .help-lead + section h3 {
  margin-top: 1rem;
}

.help-body p {
  margin: 0 0 0.6rem;
}

.help-body .help-lead {
  font-size: 0.95rem;
  color: var(--text-primary);
}

.help-body ul,
.help-body ol {
  margin: 0 0 0.6rem;
  padding-left: 1.25rem;
}

.help-body li {
  margin-bottom: 0.3rem;
}

.help-body dl {
  margin: 0 0 0.6rem;
}

.help-body dt {
  font-weight: 700;
  color: var(--text-primary);
}

.help-body dd {
  margin: 0 0 0.6rem;
}

.help-body strong {
  color: var(--text-primary);
}

.help-body section {
  scroll-margin-top: 0.5rem;
}

.help-tip,
.help-note {
  margin: 0.75rem 0;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
}

.help-tip {
  background: var(--success-bg);
  color: var(--text-primary);
}

.help-note {
  background: var(--warning-bg);
  color: var(--text-primary);
}

.help-tip::before,
.help-note::before {
  font-weight: 700;
}

.help-tip::before {
  content: "Suggerimento · ";
}

.help-note::before {
  content: "Attenzione · ";
}

.help-message {
  padding: 2rem 0;
  text-align: center;
  color: var(--text-muted);
}

.help-footer {
  padding: 0.6rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.help-footer kbd {
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  background: var(--bg-hover);
  font-family: inherit;
  font-size: 0.7rem;
}

/* Sotto i 640px la guida occupa lo schermo intero. */
@media (max-width: 640px) {
  .help-dialog {
    width: 100vw;
    max-width: 100vw;
    max-height: 100dvh;
    height: 100dvh;
  }

  .help-panel {
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
}

body:has(.help-dialog[open]) {
  overflow: hidden;
}

/* ---- Mappa oraria "Quando vendi" (Statistiche) ---- */
.heat-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  overflow: hidden;
}

.heat-toggle button {
  border: 0;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}

.heat-toggle button[aria-pressed="true"] {
  background: var(--primary);
  color: #fff;
}

.heat-scroll {
  overflow-x: auto;
}

.heat-grid {
  display: grid;
  gap: 4px;
  min-width: 36rem;
}

.heat-hour {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
}

.heat-day {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
}

/* --a: intensità 0-1 della casella; il colore è il primario del tema. */
.heat-cell,
.heat-scale i {
  background: color-mix(in srgb, var(--primary) calc(var(--a) * 100%), var(--bg-hover));
}

.heat-cell {
  aspect-ratio: 1.5;
  border: 0;
  border-radius: 0.35rem;
  padding: 0;
  cursor: pointer;
  position: relative;
}

.heat-cell:disabled {
  cursor: default;
}

.heat-cell:not(:disabled):hover,
.heat-cell:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.heat-cell.picked {
  outline: 2px solid var(--secondary);
  outline-offset: 1px;
}

.heat-cell.best::after {
  content: "★";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.7rem;
}

.heat-scale {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.heat-scale i {
  width: 1.3rem;
  height: 0.6rem;
  border-radius: 0.2rem;
  display: block;
}

.heat-best {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--success-bg);
  padding: 0.3rem 0.7rem;
  border-radius: 0.5rem;
}

/* ---- Pagine Operatori e Storni ---- */
.range-filters {
  padding: 1rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

.range-filters .form-input {
  font-size: 0.8rem;
  min-width: 150px;
}

.range-filters .btn-primary {
  font-size: 0.8rem;
  padding: 0.5rem 1rem;
}

.range-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  padding: 0.3rem 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
}

.range-chip.strong {
  font-weight: 700;
  border-color: transparent;
  background: var(--success-bg);
  color: var(--primary);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: 0.75rem 0.85rem;
  text-align: right;
  white-space: nowrap;
  font-size: 0.84rem;
}

.data-table th {
  white-space: normal;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  font-weight: 600;
}

.data-table .left {
  text-align: left;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--bg-app);
}

.data-table tfoot td {
  font-weight: 700;
  border-top: 1px solid var(--border);
}

.data-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}

.data-table th[data-sort]:hover,
.data-table th[aria-sort] {
  color: var(--primary);
}

.data-table th[aria-sort="descending"]::after {
  content: " ▼";
}

.data-table th[aria-sort="ascending"]::after {
  content: " ▲";
}

.data-table tr.row-link {
  cursor: pointer;
}

.data-table tr.row-link:hover,
.data-table tr.row-link:focus-visible {
  background: var(--bg-hover);
  outline: none;
}

.row-title {
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.row-title.muted {
  color: var(--text-secondary);
}

.bar-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.mini-bar {
  width: 3.5rem;
  height: 0.4rem;
  border-radius: 999px;
  background: var(--bg-hover);
  overflow: hidden;
}

.mini-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.flag-hot {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--danger-strong);
  background: var(--danger-bg);
  padding: 0.1rem 0.45rem;
  border-radius: 0.4rem;
}

.storni-kpis {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.storni-kpis .stat-value {
  font-size: 1.6rem;
  margin: 0.35rem 0;
}

.stat-card.alert .stat-value {
  color: var(--danger);
}

/* Grafico per operatore sopra, elenco sotto: affiancati, l'elenco (8 colonne)
   non ci stava senza scorrere nemmeno su uno schermo largo. */
.storni-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

.storni-grid .hbars {
  max-width: 52rem;
}

.hbars {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.hbar {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr) 6rem;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.8rem;
}

.hbar.on .hbar-name {
  font-weight: 700;
  color: var(--primary);
}

.hbar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hbar-track {
  position: relative;
  height: 0.7rem;
  border-radius: 999px;
  background: var(--bg-hover);
}

.hbar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.hbar-fill.hot {
  background: var(--danger);
}

.hbar-avg {
  position: absolute;
  top: -0.25rem;
  bottom: -0.25rem;
  width: 2px;
  background: var(--text-muted);
}

.hbar-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.page-btn {
  font-size: 0.75rem;
  padding: 0.35rem 0.7rem;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--bg-card);
  text-decoration: none;
}

/* ---------- Report di giornata ---------- */

.report-print {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--primary);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.report-daybar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.report-daynav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.report-arrow {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  text-decoration: none;
}

a.report-arrow:hover,
a.report-arrow:focus-visible {
  border-color: var(--primary);
  color: var(--primary);
}

.report-arrow[aria-disabled="true"] {
  opacity: 0.35;
  cursor: not-allowed;
}

.report-daylabel {
  display: flex;
  flex-direction: column;
  min-width: 14rem;
  text-align: center;
}

.report-daylabel strong {
  font-size: 1.05rem;
}

.report-daylabel span {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.report-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem;
}

.report-filters fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.report-filters fieldset[hidden] {
  display: none;
}

.report-filters .form-input {
  font-size: 0.8rem;
}

.report-filters .btn-primary {
  font-size: 0.8rem;
  padding: 0.5rem 1rem;
}

.report-mode {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  overflow: hidden;
}

.report-mode button {
  border: 0;
  background: var(--bg-card);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.78rem;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
}

.report-mode button[aria-pressed="true"] {
  background: var(--primary);
  color: #fff;
}

.report-kpis {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.report-kpi {
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
}

.report-kpi .stat-value {
  font-size: 1.5rem;
  margin: 0.25rem 0;
}

.report-kpi-icon {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  flex: none;
  border-radius: 0.6rem;
  background: var(--success-bg);
  color: var(--primary);
}

.cost-warn {
  color: var(--warning-text);
}

.cost-badge {
  display: inline-block;
  margin-left: 0.35rem;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--warning-text);
  background: var(--warning-bg);
  padding: 0.05rem 0.4rem;
  border-radius: 0.35rem;
  cursor: help;
}

.report-grid {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: 1.5rem;
  align-items: start;
}

.report-side {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

.report-table .report-bar-col {
  width: 28%;
}

.report-table .report-utile {
  color: var(--success-text);
  font-weight: 600;
}

.report-bar {
  display: block;
  height: 0.45rem;
  border-radius: 999px;
  background: var(--bg-hover);
  overflow: hidden;
}

.report-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
}

.report-pay-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.report-pay-row,
.report-op-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.report-pay-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.report-pay-label i {
  display: block;
  width: 0.6rem;
  height: 0.6rem;
  flex: none;
  border-radius: 50%;
}

.report-pay-row small,
.report-op-top small {
  color: var(--text-muted);
}

.report-stack {
  display: flex;
  gap: 2px;
  height: 0.55rem;
  margin-top: 0.8rem;
  border-radius: 999px;
  overflow: hidden;
}

.report-stack span {
  display: block;
  height: 100%;
}

.report-cash-na {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.9rem 1rem;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.report-cash-na strong {
  color: var(--text-primary);
  font-size: 0.82rem;
}

.report-ops {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.report-op {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

@media (max-width: 1100px) {
  .report-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .report-daynav {
    width: 100%;
  }

  .report-daylabel {
    flex: 1;
    min-width: 0;
  }

  .report-table .report-bar-col {
    display: none;
  }
}

@media print {
  .report-daybar {
    border: 0;
    padding: 0;
  }

  .report-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .report-stack span,
  .report-bar span,
  .report-pay-label i {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
}

/* ---------- Margini e Rotazione ---------- */

.stat-card.warn .stat-value {
  color: var(--warning-text);
}

a.stat-card:hover,
a.stat-card:focus-visible {
  border-color: var(--primary);
}

.margini-grid {
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
}

.margin-bar {
  grid-template-columns: 8.5rem minmax(0, 1fr) 3.5rem;
}

.margin-bar .hbar-name small {
  display: block;
  font-size: 0.66rem;
  font-weight: 600;
}

.hbar-fill.low {
  background: var(--warning);
}

.margin-pos {
  color: var(--success-text);
  font-weight: 600;
}

.margin-neg {
  color: var(--danger);
  font-weight: 600;
}

.flag-low {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--warning-text);
  background: var(--warning-bg);
  padding: 0.1rem 0.45rem;
  border-radius: 0.4rem;
}

/* Schede come link (la pagina si ricarica): Margini e Rotazione. */
.page-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}

.page-tab {
  padding: 0.85rem 0.8rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.page-tab:hover,
.page-tab:focus-visible {
  color: var(--primary);
}

.page-tab[aria-current="page"] {
  color: var(--primary);
  font-weight: 700;
  border-bottom-color: var(--primary);
}

.page-tab-count {
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg-hover);
  color: var(--text-secondary);
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
}

.page-tab-caption {
  padding: 0.75rem 1.25rem;
}

.page-tab-empty {
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--text-muted);
}

.rotation-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.rotation-window {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.rotation-banner {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-md);
  background: var(--info-bg);
  color: var(--info-text);
  font-size: 0.82rem;
  line-height: 1.5;
}

.rotation-banner strong {
  display: block;
}

.mini-bar .cover-red {
  background: var(--danger);
}

.mini-bar .cover-amber {
  background: var(--warning);
}

.mini-bar .cover-green {
  background: var(--primary);
}

@media (max-width: 1100px) {
  .margini-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Pagamenti: forme di pagamento e quota per giorno, settimana o mese */
.pay-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.pay-grid .data-table th,
.pay-grid .data-table td {
  padding-inline: 0.75rem;
}

.pay-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pay-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.pay-legend i {
  display: block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
}

.pay-trend {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pay-trend-row {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr) 3.5rem 6.5rem;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.pay-trend-head {
  font-size: 0.7rem;
}

.pay-trend-cash,
.pay-trend-total {
  text-align: right;
}

.pay-trend-total {
  font-weight: 600;
}

.pay-trend-bar {
  display: flex;
  gap: 2px;
  height: 0.75rem;
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-hover);
}

.pay-trend-bar span {
  display: block;
  height: 100%;
}

@media (max-width: 1100px) {
  .pay-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .pay-trend-row {
    grid-template-columns: minmax(0, 1fr) 3rem 5.5rem;
    row-gap: 0.3rem;
  }

  .pay-trend-bar {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .pay-trend-head span:nth-child(2) {
    display: none;
  }
}

/* Venduti insieme: il prodotto scelto si toglie con un clic */
a.focus-chip {
  text-decoration: none;
  color: inherit;
  gap: 0.35rem;
}

a.focus-chip:hover {
  border-color: var(--primary);
}

/* Stato invii SDI: aziende in cima e stato del documento colorato per gruppo. */
.sdi-aziende {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
}

.sdi-azienda {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.25rem;
}

.sdi-aggiornamento {
  text-align: right;
  flex: none;
}

.sdi-stato {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 0.4rem;
}

.sdi-verde {
  color: var(--success-text);
  background: var(--success-bg);
}

.sdi-giallo {
  color: var(--warning-text);
  background: var(--warning-bg);
}

.sdi-rosso,
.sdi-sconosciuto {
  color: var(--sdi-rosso-text, var(--danger-strong));
  background: var(--danger-bg);
}

/* Quattro riquadri su una riga anche su schermi medi. */
.sdi-kpis {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.sdi-motivo {
  margin-top: 0.3rem;
  color: var(--text-secondary);
  max-width: 32rem;
  white-space: normal;
}

/* Report email SDI: preferenze, destinatari e pagine pubbliche dei link. */
.sdi-scelta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sdi-preferenze {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.9rem;
}

.sdi-opzione {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  cursor: pointer;
}

.sdi-opzione input {
  margin-top: 0.25rem;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--primary);
}

.sdi-azioni {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: flex-start;
}

.sdi-btn-piccolo {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
}

.sdi-btn-piccolo.btn-primary {
  background: var(--primary);
  color: var(--secondary);
  border-color: var(--primary);
}

.sdi-rimuovi {
  color: var(--sdi-rosso-text, var(--danger));
}

.sdi-sostituisci summary {
  list-style: none;
  cursor: pointer;
}

.sdi-sostituisci summary::-webkit-details-marker {
  display: none;
}

.sdi-sostituisci form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 0.25rem;
}

.sdi-sostituisci .form-input {
  min-width: 14rem;
  padding: 0.4rem 0.6rem;
}

.sdi-aggiungi {
  padding: 1.25rem;
  border-top: 1px solid var(--border);
}

.sdi-aggiungi-riga {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.35rem 0;
}

.sdi-aggiungi-riga .form-input {
  flex: 1;
  min-width: 14rem;
}

.sdi-pubblica p + p {
  margin-top: 0.75rem;
}

.sdi-destinatari {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.sdi-destinatario {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.sdi-destinatario-info {
  min-width: 0;
}

.sdi-destinatario-email {
  font-weight: 600;
  margin-right: 0.5rem;
  overflow-wrap: anywhere;
}
