/* Contenitore pagina: usa tutta la larghezza quando contiene la tabella ruoli (per adattamento) */
#qms-page-content:has(.azstab-page) {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Stili scoped per la pagina "Aziende & Stabilimenti" montata via qms-layout */
.azstab-page {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  color: var(--text-color);
  box-sizing: border-box;
}

.azstab-page .page-header h1 {
  margin-bottom: 6px;
  font-size: 1.75rem;
}

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

/* BLOCCO SOTTO IL TITOLO: sfondo e testo SEMPRE leggibili (non dipendono da variabili) */
.azstab-page .page-header {
  background: #e2e8f0;
  color: #0f172a;
  padding: 16px 24px;
  border-radius: 8px;
  margin-bottom: 4px;
}
.azstab-page .page-header .page-title,
.azstab-page .page-header h1 {
  color: #0f172a !important;
}
.azstab-page .page-header-desc,
.azstab-page .page-header .muted,
.azstab-page .page-header p {
  color: #1e293b !important;
  font-size: 1rem;
  font-weight: 500;
  margin-top: 0.35rem;
  line-height: 1.45;
}

/* Tema scuro: stesso blocco, colori invertiti */
body.theme-dark .azstab-page .page-header,
html.theme-dark .azstab-page .page-header {
  background: #1e293b !important;
  color: #f1f5f9 !important;
}
body.theme-dark .azstab-page .page-header .page-title,
body.theme-dark .azstab-page .page-header h1,
html.theme-dark .azstab-page .page-header .page-title,
html.theme-dark .azstab-page .page-header h1 {
  color: #f1f5f9 !important;
}
body.theme-dark .azstab-page .page-header-desc,
body.theme-dark .azstab-page .page-header .muted,
body.theme-dark .azstab-page .page-header p,
html.theme-dark .azstab-page .page-header-desc,
html.theme-dark .azstab-page .page-header .muted,
html.theme-dark .azstab-page .page-header p {
  color: #e2e8f0 !important;
  font-weight: 500;
}

@media (prefers-color-scheme: dark) {
  .azstab-page .page-header {
    background: #1e293b !important;
    color: #f1f5f9 !important;
  }
  .azstab-page .page-header .page-title,
  .azstab-page .page-header h1 { color: #f1f5f9 !important; }
  .azstab-page .page-header-desc,
  .azstab-page .page-header .muted,
  .azstab-page .page-header p { color: #e2e8f0 !important; font-weight: 500; }
}

/* Messaggio errore sync (ruoli-locali): ben visibile */
.azstab-page .ruoli-sync-error,
.azstab-page #ruoli-status.ruoli-sync-error {
  color: #dc2626 !important;
  font-weight: 500;
}
body.theme-dark .azstab-page .ruoli-sync-error,
body.theme-dark .azstab-page #ruoli-status.ruoli-sync-error,
html.theme-dark .azstab-page #ruoli-status.ruoli-sync-error {
  color: #f87171 !important;
}

.azstab-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.azstab-stat-card {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.azstab-stat-card .label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.azstab-stat-card .value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-color);
}

.azstab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
  align-items: start;
}

.az-card {
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.az-card--full {
  grid-column: 1 / -1;
}

/* Ruoli Locali: tabella e card si adattano alla larghezza disponibile */
.azstab-page .az-card--full {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.azstab-page .az-card__body {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: visible;
}

/* Wrapper tabella: occupa il 100%, scroll orizzontale se necessario (solo qui, non tutta la pagina) */
.azstab-page #ruoli-table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overflow-y: visible;
}

.azstab-page #ruoli-table-wrap.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Tabella: 100% del wrapper; min-width solo per evitare colonne schiacciate, scroll nel wrapper su schermi piccoli */
.azstab-page #ruoli-table.qms-table {
  width: 100%;
  min-width: 640px;
  table-layout: auto;
}

/* Colonna Azioni: Imposta + Assegna reparti sempre visibili (anche su schermi stretti) */
.azstab-page #ruoli-table td.row-actions {
  min-width: 160px;
  vertical-align: middle;
}
.azstab-page #ruoli-table .row-actions.row-actions--stacked .row-actions__group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}
.azstab-page #ruoli-table .row-actions .row-actions__group .btn-sm {
  white-space: nowrap;
  width: 100%;
  max-width: 140px;
  text-align: center;
}

.azstab-page .form-hint--table {
  margin: 0 0 8px 0;
  font-size: 0.85rem;
}

.az-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-light);
}

.az-card__header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.az-card__body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.az-pill {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.az-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.filter-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: block;
}

.filter-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-white);
  font-size: 14px;
}

.filter-input:focus {
  outline: 2px solid var(--primary-color);
  border-color: var(--primary-color);
}

.table-container {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.azstab-page table {
  width: 100%;
  border-collapse: collapse;
}

.azstab-page thead {
  background: var(--bg-light);
}

.azstab-page th,
.azstab-page td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
}

/* Hover: sempre sfondo scuro + testo chiaro per contrasto leggibile (evita bianco su bianco) */
.azstab-page tbody tr:hover {
  background: #4b5563 !important;
}
.azstab-page table tbody tr:hover td,
.azstab-page table tbody tr:hover th {
  background: #4b5563 !important;
  color: #f9fafb !important;
}

.selected-row {
  background: #eef2ff;
}

.actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-white);
  cursor: pointer;
  transition: background var(--transition-base), color var(--transition-base), border-color var(--transition-base);
}

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

.badge {
  padding: 6px 10px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 12px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.badge-success {
  background: #10b981;
  color: white;
}

.badge-danger {
  background: #ef4444;
  color: white;
}

.badge-primary {
  background: #3b82f6;
  color: white;
}

.badge-legacy {
  background: #ffe8cc;
  color: #8a5a00;
  border: 1px solid #ffc078;
  font-weight: 600;
}

/* Badge arancioni/gialli in tabella: testo SEMPRE scuro su sfondo chiaro (leggibile in ogni tema) */
.azstab-page #ruoli-table .badge-legacy,
#ruoli-table .badge-legacy,
.azstab-page #ruoli-table td .badge-legacy,
#ruoli-table td .badge-legacy {
  color: #0f172a !important;
  background: #ffedd5 !important;
  border: 1px solid #ea580c !important;
}
.azstab-page #ruoli-table .badge-legacy small,
#ruoli-table .badge-legacy small {
  color: #475569 !important;
}
body.theme-dark .azstab-page #ruoli-table .badge-legacy,
body.theme-dark #ruoli-table .badge-legacy,
html.theme-dark #ruoli-table .badge-legacy {
  color: #0f172a !important;
  background: #ffedd5 !important;
  border-color: #ea580c !important;
}
body.theme-dark .azstab-page #ruoli-table .badge-legacy small,
body.theme-dark #ruoli-table .badge-legacy small {
  color: #475569 !important;
}

/* Badge blu (override v2): testo bianco su sfondo blu, sempre leggibile */
.azstab-page #ruoli-table .badge-primary,
#ruoli-table .badge-primary {
  color: #ffffff !important;
  background: #2563eb !important;
}
body.theme-dark .azstab-page #ruoli-table .badge-primary,
body.theme-dark #ruoli-table .badge-primary {
  color: #ffffff !important;
  background: #2563eb !important;
}

/* Badge "Ruolo base" in tabella: contrasto garantito */
.azstab-page #ruoli-table .badge-base,
#ruoli-table .badge-base {
  color: #0f172a !important;
  background: #e2e8f0 !important;
}
body.theme-dark .azstab-page #ruoli-table .badge-base,
body.theme-dark #ruoli-table .badge-base {
  color: #f1f5f9 !important;
  background: #475569 !important;
}

/* Colonna Override: testo leggibile e adattabile (evita troncamento) */
.azstab-page #ruoli-table td:nth-child(7) {
  min-width: 140px;
  max-width: 280px;
  word-break: break-word;
}
.azstab-page #ruoli-table .override-detail-text {
  font-size: 0.9rem;
  line-height: 1.4;
  white-space: normal;
}
.azstab-page #ruoli-table .override-detail-text br {
  display: block;
  content: "";
  margin-top: 2px;
}
body.theme-dark .azstab-page #ruoli-table .override-detail-text { color: #e5e7eb !important; }
@media (prefers-color-scheme: dark) {
  .azstab-page #ruoli-table .override-detail-text { color: #e5e7eb !important; }
}

/* Tabella "Override attivi": testo leggibile in tema scuro */
#ruoli-overrides-wrap .qms-table thead th { color: var(--text-color); }
#ruoli-overrides-wrap .qms-table tbody td { color: var(--text-color); }
body.theme-dark #ruoli-overrides-wrap .qms-table thead th,
body.theme-dark #ruoli-overrides-wrap .qms-table tbody td { color: #e5e7eb !important; }
@media (prefers-color-scheme: dark) {
  #ruoli-overrides-wrap .qms-table thead th,
  #ruoli-overrides-wrap .qms-table tbody td { color: #e5e7eb !important; }
}

.badge-info {
  background: #0ea5e9;
  color: white;
}

.empty-state {
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
}

.loading {
  padding: 16px;
  color: var(--text-muted);
}

.note {
  font-size: 13px;
  color: var(--text-muted);
}

.table-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.table-title h3 {
  font-size: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
}

.detail-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  background: var(--bg-white);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 14px;
}

.detail-row:last-child {
  border-bottom: none;
}

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

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.split-col h3 {
  margin: 0 0 8px 0;
}

.warning-box {
  background: #fffbeb;
  border: 1px solid #f59e0b;
  color: #92400e;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin: 12px 0 0;
}

/* Modale override: checkboxes aziende e testo aiuto */
.override-aziende-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.override-azienda-check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: normal;
}

.override-azienda-check input {
  margin: 0;
  width: auto;
}

.form-help--modal {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
}

.form-hint.hidden {
  display: none;
}

.override-stabilimenti-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 220px;
  overflow-y: auto;
}

.override-stab-block {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: #f8fafc;
  color: #1e293b;
}

.override-stab-block__title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: #1e293b;
}

.override-stab-check {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: normal;
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: #334155;
}

.override-stab-check:last-child {
  margin-bottom: 0;
}

.override-stab-check input {
  margin: 0;
  width: auto;
}

/* Contrasto modale: blocchi stabilimenti sempre leggibili (tema scuro) */
body.theme-dark .override-stab-block,
html.theme-dark .override-stab-block {
  background: #374151;
  border-color: #4b5563;
  color: #e5e7eb;
}

body.theme-dark .override-stab-block__title,
html.theme-dark .override-stab-block__title {
  color: #f3f4f6;
}

body.theme-dark .override-stab-check,
html.theme-dark .override-stab-check {
  color: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  .override-stab-block {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
  }
  .override-stab-block__title { color: #f3f4f6; }
  .override-stab-check { color: #e5e7eb; }
}

@media (max-width: 768px) {
  .azstab-page {
    padding: 12px 8px;
    width: 100%;
  }

  body.theme-dark .azstab-page .page-header,
  html.theme-dark .azstab-page .page-header {
    padding: 12px 16px;
  }

  .az-card__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .az-card__header--actions .header-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  .azstab-page #ruoli-table-wrap {
    margin-left: -8px;
    margin-right: -8px;
    width: calc(100% + 16px);
  }

  .azstab-page #ruoli-table.qms-table {
    min-width: 560px;
  }
}

/* Modal Ruoli Locali: usabile da mobile */
@media (max-width: 600px) {
  #modal-override .qms-modal__content {
    width: 95%;
    max-width: none;
    margin: 10px;
    max-height: 85vh;
    overflow-y: auto;
  }

  #modal-override .override-aziende-checkboxes,
  #modal-override .override-stabilimenti-wrap {
    max-height: 140px;
  }
}

/* ========================================
   FILTRI E STATO — contrasto leggibile in tema scuro (Azienda, Stabilimento, Caricati)
   ======================================== */
body.theme-dark .az-filters label,
html.theme-dark .az-filters label {
  color: #e5e7eb !important;
}

body.theme-dark .azstab-page .az-card__body .muted,
body.theme-dark .az-card__body #reparti-status,
body.theme-dark .azstab-page .page-header.muted,
body.theme-dark .azstab-page .page-header .muted,
html.theme-dark .azstab-page .az-card__body .muted,
html.theme-dark #reparti-status,
html.theme-dark .azstab-page .page-header .muted {
  color: #e2e8f0 !important;
  font-size: 0.95rem;
}
@media (prefers-color-scheme: dark) {
  .azstab-page .page-header .muted,
  .azstab-page .page-header.muted,
  .azstab-page .page-header-desc {
    color: #e2e8f0 !important;
    font-size: 0.95rem;
  }
}

/* Ruoli Locali: testo istruzioni nella card (form-hint) leggibile in tema scuro */
body.theme-dark .azstab-page .az-card__body .form-hint,
body.theme-dark .azstab-page .az-card__body .form-hint--table,
html.theme-dark .azstab-page .az-card__body .form-hint,
html.theme-dark .azstab-page .az-card__body .form-hint--table {
  color: #e2e8f0 !important;
  font-size: 0.9rem;
}
@media (prefers-color-scheme: dark) {
  .azstab-page .az-card__body .form-hint,
  .azstab-page .az-card__body .form-hint--table {
    color: #e2e8f0 !important;
    font-size: 0.9rem;
  }
}

/* Reparti: hint sotto il titolo leggibile in dark (evita grigio troppo chiaro) */
.reparti-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}
body.theme-dark .azstab-page .reparti-hint,
html.theme-dark .azstab-page .reparti-hint {
  color: #cbd5e1 !important;
}
@media (prefers-color-scheme: dark) {
  .azstab-page .reparti-hint { color: #cbd5e1 !important; }
}

body.theme-dark .az-filters .filter-label,
html.theme-dark .az-filters .filter-label {
  color: #e5e7eb !important;
}

/* Modal Nuovo reparto: titolo, hint e label leggibili in tema scuro */
body.theme-dark .reparti-modal-content .reparti-modal-title,
html.theme-dark .reparti-modal-content .reparti-modal-title {
  color: #f3f4f6 !important;
}

body.theme-dark .reparti-modal-content .reparti-modal-hint,
html.theme-dark .reparti-modal-content .reparti-modal-hint {
  color: #d1d5db !important;
}

body.theme-dark .reparti-modal-content .form-label--contrast,
body.theme-dark .reparti-modal-content .form-label,
html.theme-dark .reparti-modal-content .form-label--contrast,
html.theme-dark .reparti-modal-content .form-label {
  color: #e5e7eb !important;
}

body.theme-dark .reparti-modal-content .form-readonly,
html.theme-dark .reparti-modal-content .form-readonly {
  color: #e5e7eb !important;
  margin: 4px 0 0 0;
}

/* Modal Assegna reparti (ruoli-locali): testo sempre leggibile, evita semi-trasparente */
#modal-assegna-reparti .qms-modal__content {
  color: #1e293b;
}
#modal-assegna-reparti .qms-modal__content .form-group > label {
  color: #1e293b;
  font-weight: 500;
}
#modal-assegna-reparti .qms-modal__content .form-hint,
#modal-assegna-reparti .qms-modal__content p.muted {
  color: #475569;
  font-size: 0.9rem;
}
#modal-assegna-reparti #reparti_checkboxes_wrap label,
#modal-assegna-reparti #reparti_checkboxes_wrap .override-stab-check {
  color: #334155;
}
#modal-assegna-reparti .qms-modal__content select {
  background: #fff;
  color: #1e293b;
  border-color: #e2e8f0;
}
body.theme-dark #modal-assegna-reparti .qms-modal__content,
html.theme-dark #modal-assegna-reparti .qms-modal__content {
  background: #1e293b;
  color: #e2e8f0;
}
body.theme-dark #modal-assegna-reparti .qms-modal__content .form-group > label,
html.theme-dark #modal-assegna-reparti .qms-modal__content .form-group > label {
  color: #e2e8f0 !important;
}
body.theme-dark #modal-assegna-reparti .qms-modal__content .form-hint,
body.theme-dark #modal-assegna-reparti .qms-modal__content p.muted,
html.theme-dark #modal-assegna-reparti .qms-modal__content .form-hint,
html.theme-dark #modal-assegna-reparti .qms-modal__content p.muted {
  color: #94a3b8 !important;
}
body.theme-dark #modal-assegna-reparti #reparti_checkboxes_wrap label,
body.theme-dark #modal-assegna-reparti #reparti_checkboxes_wrap .override-stab-check,
html.theme-dark #modal-assegna-reparti #reparti_checkboxes_wrap label,
html.theme-dark #modal-assegna-reparti #reparti_checkboxes_wrap .override-stab-check {
  color: #e2e8f0 !important;
}
body.theme-dark #modal-assegna-reparti .qms-modal__content select,
html.theme-dark #modal-assegna-reparti .qms-modal__content select {
  background: #334155 !important;
  color: #f1f5f9 !important;
  border-color: #475569 !important;
}

/* Reparti: card header h2 e pulsanti leggibili in tema scuro */
body.theme-dark .azstab-page .az-card__header h2,
html.theme-dark .azstab-page .az-card__header h2 {
  color: #f3f4f6 !important;
}

body.theme-dark .azstab-page .az-card__header .btn-primary,
html.theme-dark .azstab-page .az-card__header .btn-primary {
  background: #2563eb;
  color: #ffffff !important;
  border-color: #2563eb;
}

body.theme-dark .azstab-page .az-card__header .btn-primary:hover:not(:disabled),
html.theme-dark .azstab-page .az-card__header .btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
  color: #ffffff !important;
}

body.theme-dark .azstab-page .az-card__header .btn-primary:disabled,
html.theme-dark .azstab-page .az-card__header .btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Aree: Nuova Area — sempre riceve il click (tema scuro aveva pointer-events:none su :disabled) */
#btn-new-area {
  pointer-events: auto !important;
  cursor: pointer !important;
}

/*
 * Aree — modale: .qms-modal in qms-global è stilato come "card" in flow, non come overlay.
 * Senza position:fixed il blocco finisce in fondo al body (sotto la piega) → "clicco e non succede nulla".
 */
#modal-area.qms-modal {
  position: fixed !important;
  inset: 0 !important;
  z-index: 10050 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 !important;
  max-width: none !important;
  width: 100% !important;
  height: 100% !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: rgba(15, 23, 42, 0.55) !important;
}
#modal-area.qms-modal.hidden {
  display: none !important;
}
#modal-area .qms-modal__overlay {
  position: absolute;
  inset: 0;
  z-index: 0;
  cursor: pointer;
}
#modal-area .qms-modal__content {
  position: relative;
  z-index: 1;
  max-width: 560px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  /* Nessuna variabile tema: su app in dark, --text-color è chiaro e --bg-panel può restare chiaro → testo illeggibile */
  background: #ffffff !important;
  color: #0f172a !important;
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  padding: 1.25rem 1.5rem;
}
#modal-area .qms-modal__content h3 {
  color: #020617 !important;
  margin-top: 0;
}
#modal-area .qms-modal__content label {
  color: #334155 !important;
}
#modal-area .qms-modal__content input[type="text"] {
  color: #0f172a !important;
  background: #f8fafc !important;
  border: 1px solid #cbd5e1 !important;
}
body.theme-dark #modal-area .qms-modal__content,
html.theme-dark #modal-area .qms-modal__content {
  /* Stessa scheda chiara anche in tema scuro: massimo contrasto */
  background: #ffffff !important;
  color: #0f172a !important;
}
body.theme-dark #modal-area .qms-modal__content h3,
html.theme-dark #modal-area .qms-modal__content h3 {
  color: #020617 !important;
}
body.theme-dark #modal-area .qms-modal__content label,
html.theme-dark #modal-area .qms-modal__content label {
  color: #334155 !important;
}
body.theme-dark #modal-area .qms-modal__content input[type="text"],
html.theme-dark #modal-area .qms-modal__content input[type="text"] {
  color: #0f172a !important;
  background: #f8fafc !important;
  border: 1px solid #cbd5e1 !important;
}

/* Tabella Reparti: contrasto leggibile in tema scuro */
body.theme-dark #reparti-table thead th,
html.theme-dark #reparti-table thead th {
  color: #f3f4f6 !important;
  background: #374151 !important;
}

body.theme-dark #reparti-table tbody td,
html.theme-dark #reparti-table tbody td {
  color: #e5e7eb !important;
}

body.theme-dark #reparti-table tbody tr:hover td,
html.theme-dark #reparti-table tbody tr:hover td {
  background: #4b5563;
  color: #f9fafb !important;
}

/* Hover tabelle azstab in tema scuro: sfondo scuro + testo chiaro (automezzi, celle, aree, ecc.) */
body.theme-dark .azstab-page table tbody tr:hover,
html.theme-dark .azstab-page table tbody tr:hover {
  background: #4b5563 !important;
}
body.theme-dark .azstab-page table tbody tr:hover td,
body.theme-dark .azstab-page table tbody tr:hover th,
html.theme-dark .azstab-page table tbody tr:hover td,
html.theme-dark .azstab-page table tbody tr:hover th {
  background: #4b5563 !important;
  color: #f9fafb !important;
}

/* Empty state Reparti: titolo e sottotitolo leggibili */
body.theme-dark #reparti-empty .empty-title,
body.theme-dark #reparti-empty .empty-sub,
html.theme-dark #reparti-empty .empty-title,
html.theme-dark #reparti-empty .empty-sub {
  color: #e5e7eb !important;
}

body.theme-dark .az-filters select,
html.theme-dark .az-filters select {
  background: #374151;
  border-color: #4b5563;
  color: #f3f4f6;
}

@media (prefers-color-scheme: dark) {
  .az-filters label { color: #e5e7eb !important; }
  .azstab-page .az-card__body .muted,
  .azstab-page .page-header .muted,
  #reparti-status { color: #d1d5db !important; }
  .az-filters .filter-label { color: #e5e7eb !important; }
}

/* ========================================
   RUOLI LOCALI — contrasto tema scuro (tabella e stato leggibili)
   ======================================== */
body.theme-dark .azstab-page #ruoli-status,
html.theme-dark .azstab-page #ruoli-status,
body.theme-dark .az-card__body #ruoli-status {
  color: #d1d5db !important;
}

body.theme-dark .azstab-page .qms-table thead th,
body.theme-dark .azstab-page #ruoli-table thead th,
html.theme-dark .azstab-page .qms-table thead th {
  color: #f3f4f6 !important;
  background: #374151 !important;
}

body.theme-dark .azstab-page .qms-table tbody td,
body.theme-dark .azstab-page #ruoli-table tbody td,
body.theme-dark .az-card__body .qms-table tbody td,
html.theme-dark .azstab-page .qms-table tbody td {
  color: #e5e7eb !important;
}

/* Stesso contrasto quando il SISTEMA è in dark (senza toggle body.theme-dark) */
@media (prefers-color-scheme: dark) {
  .azstab-page #ruoli-status,
  .az-card__body #ruoli-status {
    color: #d1d5db !important;
  }
  .azstab-page #ruoli-table.qms-table thead th,
  #ruoli-table.qms-table thead th {
    color: #f3f4f6 !important;
    background: #374151 !important;
  }
  .azstab-page #ruoli-table.qms-table tbody td,
  #ruoli-table.qms-table tbody td {
    color: #e5e7eb !important;
  }
}

/* Reparti — azioni riga */
#reparti-table .reparti-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
#reparti-table .reparti-actions .btn-sm {
  font-size: 0.75rem;
  padding: 0.2rem 0.45rem;
  line-height: 1.2;
}
#reparti-table .reparti-badge-archiviato {
  font-size: 0.7rem;
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
  background: rgba(107, 114, 128, 0.35);
  color: inherit;
  margin-right: 0.25rem;
}
