/* MA Healthcare Suite — shell styles */
:root {
  --bg: #f3f5f9;
  --bg-2: #ffffff;
  --ink: #1f2330;
  --muted: #6b7280;
  --brand: #2c44b0;
  --brand-soft: #dbe4ff;
  --brand-ink: #1a2a6e;
  --line: #e3e6ed;
  --ok: #2f9e44;
  --warn: #e67700;
  --err: #c92a2a;
  --shadow: 0 1px 2px rgba(20,30,60,0.06);
}

/* Dark mode — attivata da <html data-theme="dark"> */
html[data-theme="dark"] {
  --bg: #0f1320;
  --bg-2: #1a2032;
  --ink: #e6e9f2;
  --muted: #98a1b8;
  --brand: #6b80e8;
  --brand-soft: #1e2a55;
  --brand-ink: #b6c2ff;
  --line: #2a3148;
  --ok: #51cf66;
  --warn: #ffb84a;
  --err: #ff6b6b;
  --shadow: 0 1px 2px rgba(0,0,0,0.4);
}
html[data-theme="dark"] body { color-scheme: dark; background: var(--bg) !important; color: var(--ink) !important; }
/* Leaflet tiles in dark: leggera inversione + desaturazione */
html[data-theme="dark"] .leaflet-tile-pane { filter: invert(0.92) hue-rotate(180deg) brightness(0.9) contrast(0.85); }
html[data-theme="dark"] .leaflet-control-attribution,
html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip { background: var(--bg-2) !important; color: var(--ink) !important; }
html[data-theme="dark"] .leaflet-control-zoom a { background: var(--bg-2) !important; color: var(--ink) !important; border-color: var(--line) !important; }

/* ── Override esplicito per tutte le sezioni del hub principale in dark ── */
html[data-theme="dark"] .topbar, html[data-theme="dark"] header.topbar { background: var(--bg-2) !important; border-color: var(--line) !important; color: var(--ink) !important; }
html[data-theme="dark"] .panel, html[data-theme="dark"] .card, html[data-theme="dark"] .map-card, html[data-theme="dark"] .kpi-card { background: var(--bg-2) !important; color: var(--ink) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .muted { color: var(--muted) !important; }
html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h3, html[data-theme="dark"] h4 { color: var(--ink) !important; }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea, html[data-theme="dark"] button {
  background: var(--bg-2) !important; color: var(--ink) !important; border-color: var(--line) !important;
}
html[data-theme="dark"] .services-table, html[data-theme="dark"] .services-table code { background: var(--bg-2) !important; color: var(--ink) !important; }
html[data-theme="dark"] .services-table th { background: var(--bg) !important; color: var(--muted) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .services-table td { border-color: var(--line) !important; color: var(--ink) !important; }
html[data-theme="dark"] .tab { color: var(--muted) !important; }
html[data-theme="dark"] .tab:hover { background: var(--bg) !important; color: var(--ink) !important; }
html[data-theme="dark"] .tab.active { background: var(--brand-soft) !important; color: var(--brand-ink) !important; }
html[data-theme="dark"] .bars .bar-label { color: var(--ink) !important; }
html[data-theme="dark"] .bars .bar-num { color: var(--muted) !important; }
html[data-theme="dark"] .bars .bar-track { background: var(--bg) !important; }
html[data-theme="dark"] .dash-divider { background: var(--line) !important; }
html[data-theme="dark"] .dash-grid, html[data-theme="dark"] .dash-wrap { background: transparent !important; color: var(--ink) !important; }
/* Iframe contenitore: si vede comunque il dark intorno */
html[data-theme="dark"] iframe { background: var(--bg) !important; color-scheme: dark; }

/* Exports table (lista file Run precedenti in Gestione): hover hardcoded #fafbff */
html[data-theme="dark"] .exports-table-wrap { background: var(--bg-2) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .exports-table { color: var(--ink) !important; }
html[data-theme="dark"] .exports-table th { background: var(--bg) !important; color: var(--muted) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .exports-table td { color: var(--ink) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .exports-table tbody tr:hover { background: rgba(107,128,232,0.08) !important; }
html[data-theme="dark"] .exports-table code { background: var(--bg) !important; color: var(--brand-ink) !important; padding: 2px 5px; border-radius: 3px; }

/* ── Storico modifiche (tab Storico) ── */
html[data-theme="dark"] .history-list { background: var(--bg-2) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .hist-item { color: var(--ink) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .hist-item:hover { background: rgba(107,128,232,0.08) !important; }
html[data-theme="dark"] .hist-when, html[data-theme="dark"] .hist-target { color: var(--muted) !important; }
html[data-theme="dark"] .hist-summary { color: var(--ink) !important; }
html[data-theme="dark"] .hist-src.creator    { color: #91a0f0 !important; }
html[data-theme="dark"] .hist-src.updator    { color: #ffb84a !important; }
html[data-theme="dark"] .hist-src.gestionale { color: #51cf66 !important; }
html[data-theme="dark"] .hist-src.hub        { color: var(--muted) !important; }
html[data-theme="dark"] .hist-src.system     { color: var(--muted) !important; }
html[data-theme="dark"] .hist-action.insert  { background: rgba(47,158,68,0.18) !important;  color: #51cf66 !important; }
html[data-theme="dark"] .hist-action.update  { background: rgba(202,138,4,0.18) !important;  color: #ffd966 !important; }
html[data-theme="dark"] .hist-action.delete  { background: rgba(201,42,42,0.18) !important;  color: #ff6b6b !important; }
html[data-theme="dark"] .hist-action.geocode,
html[data-theme="dark"] .hist-action.import,
html[data-theme="dark"] .hist-action.note    { background: rgba(107,128,232,0.18) !important; color: var(--brand-ink) !important; }
html[data-theme="dark"] .hist-toolbar select { background: var(--bg-2) !important; color: var(--ink) !important; border-color: var(--line) !important; }

/* ── Header barra "Target aggiornati · running …" (arricchimento attivo) ── */
html[data-theme="dark"] .enrich-results { background: var(--bg-2) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .enrich-results-head {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%) !important;
  border-color: var(--line) !important;
}
html[data-theme="dark"] .enrich-results-head strong { color: var(--brand-ink) !important; }

/* Bottoni "Salva ora" / "Annulla job" hanno inline style con colori light */
html[data-theme="dark"] #btn-enrich-merge-now {
  background: #1e2a55 !important;
  color: var(--brand-ink) !important;
  border-color: var(--brand) !important;
}
html[data-theme="dark"] #btn-enrich-merge-now:hover { background: #2a3870 !important; }
html[data-theme="dark"] #btn-enrich-cancel {
  background: rgba(201,42,42,0.18) !important;
  color: #ff6b6b !important;
  border-color: rgba(201,42,42,0.4) !important;
}
html[data-theme="dark"] #btn-enrich-cancel:hover { background: rgba(201,42,42,0.28) !important; }
html[data-theme="dark"] #btn-enrich-results-close {
  background: var(--bg-2) !important; color: var(--ink) !important; border-color: var(--line) !important;
}
html[data-theme="dark"] #btn-enrich-results-close:hover { background: var(--bg) !important; }

/* Card di arricchimento (grid: ogni target trovato) */
html[data-theme="dark"] .enrich-card { background: var(--bg-2) !important; border-color: var(--line) !important; color: var(--ink) !important; }
html[data-theme="dark"] .enrich-change { background: var(--bg) !important; }
html[data-theme="dark"] .enrich-change.new { background: rgba(47,158,68,0.10) !important; border-left-color: var(--ok) !important; }
html[data-theme="dark"] .enrich-change.changed { background: rgba(230,119,0,0.10) !important; border-left-color: var(--warn) !important; }
html[data-theme="dark"] .enrich-change.enrich-excluded { background: rgba(201,42,42,0.10) !important; border-left-color: var(--err) !important; }
html[data-theme="dark"] .enrich-change-label { color: var(--muted) !important; }
html[data-theme="dark"] .enrich-change-value, html[data-theme="dark"] .enrich-field-text { color: var(--ink) !important; }
html[data-theme="dark"] .enrich-btn { background: var(--bg-2) !important; color: var(--ink) !important; border-color: var(--line) !important; }
html[data-theme="dark"] .enrich-btn:hover:not(:disabled) { background: #2a3870 !important; border-color: var(--brand) !important; color: var(--brand-ink) !important; }
html[data-theme="dark"] .enrich-btn-ok { background: var(--ok) !important; color: white !important; border-color: var(--ok) !important; }
html[data-theme="dark"] .enrich-btn-remove:hover:not(:disabled) { background: rgba(201,42,42,0.20) !important; color: #ff6b6b !important; border-color: var(--err) !important; }
html[data-theme="dark"] .enrich-card-head .enrich-card-title { color: var(--ink) !important; }
html[data-theme="dark"] .enrich-field-input, html[data-theme="dark"] .enrich-rs-input {
  background: var(--bg-2) !important; color: var(--ink) !important;
}

/* Pill checkbox "Fonti" sotto la ops-bar Arricchisci
   (allineata visivamente ai bottoni .btn.secondary: 8px 16px / 13px / radius 6px) */
.enrich-src-pill {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--bg-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
  margin: 0;
}
.enrich-src-pill:hover { border-color: var(--brand); }
.enrich-src-pill input[type=checkbox] { margin: 0; }
.enrich-src-pill:has(input:checked) {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-ink);
}
html[data-theme="dark"] .enrich-src-pill { background: var(--bg) !important; color: var(--ink) !important; }
html[data-theme="dark"] .enrich-src-pill:has(input:checked) { background: #1e2a55 !important; color: var(--brand-ink) !important; border-color: var(--brand) !important; }

/* ── Form controls unificati: applicati a tutta la shell, non solo alla ops-bar
   Arricchisci. Riferimento di design: pulsanti .btn.secondary (padding 8px 16px,
   font 13px/500, border 1px solid --line, radius 6px). ─────────────────────── */

/* Tutti i <select> della shell hanno lo stesso aspetto */
.panel select,
.ops-bar select,
.hist-toolbar select {
  padding: 8px 10px;
  background: var(--bg-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  min-height: 34px;
}
.panel select:hover,
.ops-bar select:hover,
.hist-toolbar select:hover { border-color: var(--brand); }

/* Label che avvolge un <select> con testo (es. "Limite:") */
label.ops-label:has(> select) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Pill di una <label> che contiene una <input type=checkbox> standalone:
   stesso look dei pulsanti, highlight quando checked. Vale dovunque, non
   solo in ops-bar. */
label.ops-label:has(> input[type=checkbox]),
label.checkbox-pill {
  padding: 8px 12px;
  background: var(--bg-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  margin: 0;
  min-height: 34px;
}
label.ops-label:has(> input[type=checkbox]):hover,
label.checkbox-pill:hover { border-color: var(--brand); }
label.ops-label:has(> input[type=checkbox]:checked),
label.checkbox-pill:has(input:checked) {
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-color: var(--brand);
}

/* Pulsanti "destructive" (azioni distruttive: reset, elimina, revoca):
   stesse dimensioni di .btn.secondary, palette rossa. Sostituisce inline-style. */
.btn.destructive,
.btn.secondary.destructive {
  background: #fde8e8 !important;
  color: #7f1d1d !important;
  border: 1px solid #f1b9b9 !important;
}
.btn.destructive:hover:not(:disabled),
.btn.secondary.destructive:hover:not(:disabled) {
  background: #fbd4d4 !important;
  border-color: #e9a0a0 !important;
}
html[data-theme="dark"] .btn.destructive,
html[data-theme="dark"] .btn.secondary.destructive {
  background: rgba(201,42,42,0.18) !important;
  color: #ff8080 !important;
  border-color: rgba(201,42,42,0.45) !important;
}
html[data-theme="dark"] .btn.destructive:hover:not(:disabled),
html[data-theme="dark"] .btn.secondary.destructive:hover:not(:disabled) {
  background: rgba(201,42,42,0.30) !important;
  border-color: rgba(201,42,42,0.65) !important;
}

html[data-theme="dark"] .panel select,
html[data-theme="dark"] .ops-bar select,
html[data-theme="dark"] .hist-toolbar select { background: var(--bg) !important; color: var(--ink) !important; }
html[data-theme="dark"] label.ops-label:has(> input[type=checkbox]),
html[data-theme="dark"] label.checkbox-pill { background: var(--bg) !important; color: var(--ink) !important; }
html[data-theme="dark"] label.ops-label:has(> input[type=checkbox]:checked),
html[data-theme="dark"] label.checkbox-pill:has(input:checked) { background: #1e2a55 !important; color: var(--brand-ink) !important; border-color: var(--brand) !important; }

/* Modal Storico Arricchimenti */
.enrich-history-modal {
  position: fixed; inset: 0;
  background: rgba(15, 19, 32, 0.78);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.enrich-history-modal.hidden { display: none; }
.enrich-history-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: min(900px, 92vw);
  max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.enrich-history-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.enrich-history-head h2 { margin: 0; font-size: 16px; color: var(--brand-ink); }
.enrich-history-body {
  padding: 12px 18px;
  overflow-y: auto;
  flex: 1;
}
.enrich-history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--bg);
}
.enrich-history-item .eh-title {
  font-weight: 600;
  color: var(--ink);
  font-size: 13px;
}
.enrich-history-item .eh-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.enrich-history-item .eh-actions { display: flex; gap: 6px; }
.enrich-history-item .eh-actions .btn {
  font-size: 11px;
  padding: 5px 10px;
}
html[data-theme="dark"] .enrich-history-modal { background: rgba(0,0,0,0.78); }

/* Bottone "Avvia arricchimento": coerente con "Storico" + icona play verde */
.btn-enrich-start .btn-play-icon {
  color: var(--ok);
  font-weight: 700;
  margin-right: 4px;
  display: inline-block;
  text-shadow: 0 0 4px rgba(47,158,68,0.4);
}
.btn-enrich-start:hover:not(:disabled) .btn-play-icon { color: #258a3a; }
html[data-theme="dark"] .btn-enrich-start .btn-play-icon { color: #51cf66; text-shadow: 0 0 5px rgba(81,207,102,0.5); }

/* Bottone "Annulla job" inline: stesse dimensioni di "Avvia arricchimento" ma icona X rossa.
   Si alterna in posizione con il pulsante di avvio mentre il job è in corso. */
.btn-enrich-cancel-inline .btn-cancel-icon {
  color: var(--err);
  font-weight: 700;
  margin-right: 4px;
  display: inline-block;
  text-shadow: 0 0 4px rgba(201,42,42,0.45);
}
.btn-enrich-cancel-inline:hover:not(:disabled) .btn-cancel-icon { color: #a31515; }
html[data-theme="dark"] .btn-enrich-cancel-inline .btn-cancel-icon { color: #ff6b6b; text-shadow: 0 0 5px rgba(255,107,107,0.5); }

/* Pulsante toggle tema nella topbar */
.theme-toggle {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: background .15s, transform .1s;
}
.theme-toggle:hover { background: var(--brand-soft); }
.theme-toggle:active { transform: scale(0.95); }
.theme-toggle .icon-dark { display: none; }
.theme-toggle .icon-light { display: inline; }
html[data-theme="dark"] .theme-toggle .icon-light { display: none; }
html[data-theme="dark"] .theme-toggle .icon-dark { display: inline; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  height: 56px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.brand-mark {
  width: 32px; height: 32px;
  background: var(--brand);
  color: white;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
}
.brand-title { font-weight: 700; font-size: 14px; line-height: 1.1; }
.brand-sub { font-size: 11px; color: var(--muted); }

.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
}
.tab:hover { background: var(--bg); color: var(--ink); }
.tab.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-color: rgba(44,68,176,0.2);
}
.tab .tab-icon {
  font-size: 13px;
  line-height: 1;
  margin-right: 2px;
  opacity: 0.85;
  filter: saturate(0.9);
}
.tab.active .tab-icon { opacity: 1; }

/* Gruppo tab con dropdown (es. "Gestione") */
.tab-group { position: relative; display: inline-flex; }
.tab-group-btn .tab-chevron {
  font-size: 9px;
  opacity: 0.6;
  margin-left: 4px;
}
.tab-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(20, 30, 60, 0.12);
  padding: 6px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tab-dropdown.hidden { display: none; }
.tab-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
.tab-dropdown-item:hover { background: var(--bg); }
.tab-dropdown-item .tab-icon { font-size: 14px; }
.tab-dropdown-item .dot {
  width: 7px; height: 7px; border-radius: 50%; background: #c0c4cc; flex-shrink: 0;
}
.tab-dropdown-item .dot.ok { background: var(--ok); }
.tab-dropdown-item .dot.warn { background: var(--warn); }
.tab-dropdown-item .dot.err { background: var(--err); }
.tab .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #c0c4cc;
  flex-shrink: 0;
}
.tab .dot.ok { background: var(--ok); }
.tab .dot.warn { background: var(--warn); }
.tab .dot.err { background: var(--err); }

/* (Status tray rimosso: lo stato dei sotto-servizi vive ora nel tab Impostazioni) */

/* Tabella stato sotto-servizi (in Impostazioni) */
.services-table-wrap {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}
.services-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.services-table th, .services-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.services-table th {
  background: var(--bg);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
}
.services-table tbody tr:last-child td { border-bottom: 0; }
.services-table code { font-size: 12px; background: var(--bg); padding: 2px 6px; border-radius: 3px; }
.svc-state {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.svc-state.online { background: #e8f5ec; color: #1b5e20; }
.svc-state.degraded { background: #fff4d6; color: #5a4400; }
.svc-state.offline { background: #fde8e8; color: #7f1d1d; }
.svc-error { color: var(--err); font-size: 11px; }
.svc-note { color: var(--muted); font-size: 11px; }

/* Visualizzatore log */
.log-viewer {
  background: #1f2330;
  color: #d8dde9;
  border-radius: 8px;
  overflow: hidden;
  margin-top: 8px;
  margin-bottom: 16px;
}
.log-viewer.hidden { display: none; }
.log-viewer-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: #2a3040;
  border-bottom: 1px solid #3a4050;
  color: #d8dde9;
  font-size: 12px;
}
.log-viewer-head .muted { color: #8a92a5; }
.log-viewer-head .btn {
  margin-left: auto;
  background: #3a4050;
  color: #d8dde9;
  border: 1px solid #4a5060;
  padding: 4px 10px;
  font-size: 11px;
}
.log-viewer-head .btn.secondary { background: transparent; }
.log-viewer-head .btn:hover { background: #4a5060; }
.log-viewer pre {
  margin: 0;
  padding: 14px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
  max-height: 400px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

#main {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.panel {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  overflow: auto;
}
/* !important per battere eventuali override con specificita' equivalente
   (es. .panel[data-tab="..."] {display: flex}). Cruciale: senza, i pannelli
   non si nascondono e finiscono sovrapposti al pannello attivo. */
.panel.hidden { display: none !important; }
.panel-inner { max-width: 1100px; margin: 0 auto; padding: 32px; width: 100%; }

iframe#app-iframe {
  flex: 1;
  width: 100%;
  border: 0;
  background: var(--bg-2);
}

/* Risultati arricchimento: card target con dati evidenziati */
.enrich-results {
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  max-height: 50vh;
  overflow-y: auto;
  flex-shrink: 0;
}
.enrich-results.hidden { display: none; }
.enrich-results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f5f7fc 0%, var(--bg-2) 100%);
}
.enrich-results-head strong { font-size: 14px; color: var(--brand-ink); }
.enrich-results-actions { display: flex; align-items: center; gap: 8px; }

/* ─── Verifica fatturati uno-a-uno ────────────────────────────────────── */
.verify-fatt-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 10px 0 14px;
}
.verify-fatt-stat {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.verify-fatt-stat-val { font-size: 22px; font-weight: 700; color: var(--brand-ink); }
.verify-fatt-stat-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.verify-fatt-stat.is-ok .verify-fatt-stat-val { color: var(--ok); }
.verify-fatt-stat.is-warn .verify-fatt-stat-val { color: #d97706; }

.verify-fatt-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.verify-fatt-list { display: flex; flex-direction: column; gap: 10px; }
.verify-fatt-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}
.verify-fatt-card.is-saved {
  border-color: var(--ok);
  background: rgba(47,158,68,0.08);
}
.verify-fatt-card-head {
  display: flex; align-items: baseline; gap: 12px;
  margin-bottom: 8px;
}
.verify-fatt-card-head strong { font-size: 14px; color: var(--ink); }
.verify-fatt-card-meta { font-size: 11px; color: var(--muted); }
.verify-fatt-card-current {
  font-size: 12px; color: var(--muted);
  padding: 4px 8px; background: var(--bg); border-radius: 4px;
  margin-left: auto;
}
.verify-fatt-card-links { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.verify-fatt-link {
  display: inline-block;
  padding: 5px 10px;
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-radius: 4px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
}
.verify-fatt-link:hover { background: var(--brand); color: white; }
.verify-fatt-form {
  display: grid;
  grid-template-columns: 1fr 80px 130px auto auto;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.verify-fatt-form input, .verify-fatt-form select {
  padding: 7px 10px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg-2); color: var(--ink);
}
.verify-fatt-actions { display: flex; gap: 6px; }
html[data-theme="dark"] .verify-fatt-stat { background: var(--bg-2); }
html[data-theme="dark"] .verify-fatt-card { background: var(--bg-2); }
html[data-theme="dark"] .verify-fatt-card.is-saved { background: rgba(47,158,68,0.18); }

/* ─── Strumento Validità dati (Impostazioni) ──────────────────────────── */
.validate-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 18px; }
.validate-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.validate-summary.hidden { display: none; }
.validate-kpi {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.validate-kpi-val { font-size: 22px; font-weight: 700; color: var(--brand-ink); }
.validate-kpi-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.validate-kpi.is-err { border-color: rgba(201,42,42,0.45); }
.validate-kpi.is-err .validate-kpi-val { color: var(--err); }
.validate-kpi.is-warn { border-color: rgba(217,119,6,0.45); }
.validate-kpi.is-warn .validate-kpi-val { color: #d97706; }
.validate-kpi.is-ok { border-color: rgba(47,158,68,0.45); }
.validate-kpi.is-ok .validate-kpi-val { color: var(--ok); }
.validate-top-codes {
  grid-column: 1 / -1;
  font-size: 12px;
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.validate-top-codes ul { margin: 6px 0 0; padding-left: 20px; }
.validate-results-wrap.hidden { display: none; }
.validate-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.validate-table-wrap {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.validate-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.validate-table th, .validate-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.validate-table th { background: var(--bg); font-weight: 600; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.validate-table tr:last-child td { border-bottom: none; }
.validate-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.validate-badge.ok   { background: rgba(47,158,68,0.18); color: var(--ok); }
.validate-badge.warn { background: rgba(217,119,6,0.20); color: #d97706; }
.validate-badge.err  { background: rgba(201,42,42,0.18); color: var(--err); }
.validate-issue { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
.validate-issue.err  { color: var(--err); }
.validate-issue.warn { color: #d97706; }
.validate-completeness-bar {
  display: inline-block;
  width: 60px; height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 4px;
}
.validate-completeness-fill { height: 100%; background: var(--brand); }
.validate-completeness-fill.low { background: var(--err); }
.validate-completeness-fill.mid { background: #d97706; }
.validate-pagination { padding: 8px 12px; display: flex; align-items: center; gap: 8px; background: var(--bg); }
html[data-theme="dark"] .validate-kpi { background: var(--bg-2); }
html[data-theme="dark"] .validate-table th { background: var(--bg); color: var(--muted); }
.enrich-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 12px;
  padding: 14px 18px;
}
.enrich-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.enrich-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.enrich-card-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.enrich-card-piva { font-size: 11px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.enrich-card-changes { display: flex; flex-direction: column; gap: 5px; }
/* Grid 2-colonne, label fissa + valore fluido. Badge e actions su riga 2,
   allineati a destra. Garantisce che il valore abbia SEMPRE tutta la larghezza
   disponibile della card senza essere schiacciato. */
.enrich-change {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 4px 8px;
  padding: 6px 8px;
  border-radius: 5px;
  font-size: 12px;
  background: var(--bg);
  align-items: start;
}
.enrich-change.new { background: #e8f5ec; border-left: 3px solid var(--ok); }
.enrich-change.changed { background: #fff4d6; border-left: 3px solid var(--warn); }
.enrich-change-label {
  grid-column: 1;
  grid-row: 1;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  font-weight: 600;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  line-height: 1.25;
  padding-top: 2px;
}
.enrich-change-value {
  grid-column: 2;
  grid-row: 1;
  font-weight: 500;
  color: var(--ink);
  word-break: normal;
  overflow-wrap: anywhere;     /* spezza URL solo se necessario, NO char-by-char gratuito */
  min-width: 0;
  line-height: 1.4;
}
/* Badge "TROVATO/ESCLUSO" e bottoni azione vanno su riga 2, allineati a destra */
.enrich-badge {
  grid-column: 1 / 3;
  grid-row: 2;
  justify-self: end;
}
.enrich-actions {
  grid-column: 1 / 3;
  grid-row: 3;
  justify-self: end;
  display: flex;
  gap: 6px;
}
.enrich-change-value .enrich-field-text {
  /* Wrap NATURALE: il valore va letto per intero, non troncato.
     - white-space: pre-wrap → rispetta spazi e newline ma permette wrap
     - overflow-wrap: anywhere → spezza URL/parole lunghe per non sforare
     - word-break: break-word → fallback per browser più vecchi */
  display: inline;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* Source span ("fonte: camerale"): wrappa normalmente ma break-word per URL */
.enrich-change-value > span.muted {
  display: block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  margin-top: 2px;
}
.enrich-change-value.was {
  color: var(--muted);
  text-decoration: line-through;
  font-weight: 400;
  font-size: 11px;
  display: block;
  margin-top: 2px;
}
.enrich-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--ok);
  color: white;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
  align-self: center;
}
.enrich-badge.changed { background: var(--warn); }
.enrich-badge.enrich-badge-off { background: var(--err); }

/* Riga esclusa: stile barrato + opacita' */
.enrich-change.enrich-excluded .enrich-field-text {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 400;
}
.enrich-change.enrich-excluded { opacity: 0.75; background: #f5e9e9; border-left-color: var(--err); }

/* Marker "modificato manualmente" */
.enrich-edited-mark {
  color: var(--warn);
  font-weight: 700;
  font-size: 11px;
  margin-left: 4px;
}

/* Azioni inline (Modifica / Rimuovi / OK / Annulla) */
.enrich-actions {
  display: inline-flex;
  gap: 4px;
  flex-shrink: 0;
  align-self: center;
}
.enrich-btn {
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
  transition: background .12s, border-color .12s;
}
.enrich-btn:hover:not(:disabled) {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-ink);
}
.enrich-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.enrich-btn-remove:hover:not(:disabled) {
  background: #fdecec; border-color: var(--err); color: var(--err);
}
.enrich-btn-ok { background: var(--ok); color: white; border-color: var(--ok); }
.enrich-btn-ok:hover { background: #258a3a; border-color: #258a3a; color: white; }
.enrich-btn-cancel:hover { background: #f3f5f9; }

/* Input inline negli edit-mode */
.enrich-field-input, .enrich-rs-input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--brand);
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  background: var(--bg-2);
  color: var(--ink);
  box-shadow: 0 0 0 2px rgba(44, 68, 176, 0.12);
}
.enrich-rs-input { font-size: 13px; font-weight: 600; }

/* Card head in edit-mode: layout orizzontale */
.enrich-card-head[data-mode="edit"] { display: flex; gap: 6px; align-items: center; }
.enrich-card-head { display: flex; gap: 6px; align-items: center; }
.enrich-card-head .enrich-card-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Toolbar operazioni del tab "Import/Export" */
.ops-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.ops-bar.hidden { display: none; }
.ops-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ops-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-right: 4px;
}

/* Sub-nav per tab "Import/Export" (3 viste interne del gestionale) */
.subnav {
  display: flex;
  gap: 6px;
  padding: 8px 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.subnav.hidden { display: none; }
.subnav-btn {
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.2;
  min-height: 34px;
  cursor: pointer;
}
.subnav-btn:hover { background: var(--bg); color: var(--ink); }
.subnav-btn.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-color: rgba(44,68,176,0.3);
}

h1 { font-size: 22px; margin: 0 0 8px; }
.hint { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.bridge-controls {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px;
}
.btn {
  padding: 8px 16px;
  background: var(--brand);
  color: white;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px; font-weight: 500;
}
.btn:hover { background: var(--brand-ink); }
.btn:disabled { background: #b0b4c0; cursor: not-allowed; }
.btn.secondary { background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--bg); }
.muted { color: var(--muted); font-size: 13px; }

.exports-table-wrap {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.exports-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.exports-table th, .exports-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.exports-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.exports-table tbody tr:last-child td { border-bottom: 0; }
.exports-table tbody tr:hover { background: #fafbff; }

/* Dashboard */
.dash-wrap { padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%; }
.dash-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 20px; }
.dash-header h1 { font-size: 22px; margin: 0; }
.dash-sub { font-size: 12px; color: var(--muted); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
}
.kpi-val { font-size: 28px; font-weight: 700; color: var(--brand-ink); line-height: 1.1; }
.kpi-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }

.dash-grid {
  display: grid;
  /* CSS variables modificabili dal JS splitter (persistite in localStorage).
     L'ordine in HTML e' [divider][left-col][side-cards]; la grid-area lo riordina. */
  grid-template-columns: minmax(420px, 1fr) 10px var(--side-cards-w, 360px);
  gap: 4px;
  align-items: start;
}
.dash-grid > .dash-divider { grid-column: 2; grid-row: 1; order: 2; }
.dash-grid > .left-col     { grid-column: 1; grid-row: 1; order: 1; }
.dash-grid > .side-cards   { grid-column: 3; grid-row: 1; order: 3; }

.dash-divider {
  cursor: col-resize;
  position: relative;
  align-self: stretch;
  min-height: 240px;
  background: transparent;
  user-select: none;
  transition: background-color .12s ease-out;
}
.dash-divider::after {
  content: '';
  position: absolute;
  left: 50%; top: 30%; bottom: 30%;
  width: 2px; margin-left: -1px;
  background: var(--line);
  border-radius: 2px;
  transition: background-color .12s ease-out;
}
.dash-divider:hover, .dash-divider.dragging { background: var(--brand-soft); }
.dash-divider:hover::after, .dash-divider.dragging::after { background: var(--brand); }

/* Colonna sinistra: mappa + card di breakdown sotto */
.left-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.map-card, .card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 13px; margin: 0; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#suite-map { height: 520px; width: 100%; }
.side-cards { display: flex; flex-direction: column; gap: 14px; }
.bars { list-style: none; margin: 0; padding: 10px 14px; }
.bars li { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 12px; }
.bars .bar-label { min-width: 0; flex: 0 0 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .bar-track { flex: 1; height: 8px; background: #eef0f5; border-radius: 4px; overflow: hidden; }
/* display:block: il fill e' un <span> inline per default, e width:N% non
   verrebbe applicato. Senza questo, le tracce restano grigie senza fill. */
.bars .bar-fill { display: block; height: 100%; background: var(--brand); border-radius: 4px; transition: width .25s ease-out; }
.bars .bar-num { font-weight: 600; min-width: 28px; text-align: right; }
/* Riga "Per regione" interattiva: hover qui (o sul marker mappa) la evidenzia */
.bars li.region-row {
  cursor: pointer;
  border-radius: 6px;
  padding-left: 8px; padding-right: 8px; margin: 0 -8px;
  transition: background-color .15s ease-out;
}
.bars li.region-row:hover,
.bars li.region-row.region-active {
  background: rgba(44, 68, 176, 0.10);
}
.bars li.region-row:hover .bar-fill,
.bars li.region-row.region-active .bar-fill {
  box-shadow: 0 0 0 1px rgba(44, 68, 176, 0.45);
}
.list { list-style: none; margin: 0; padding: 6px 0; max-height: 260px; overflow-y: auto; }
.list li { padding: 8px 14px; font-size: 12px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .li-title { font-weight: 600; font-size: 13px; }
.list .li-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }

@media (max-width: 1100px) {
  /* In viewport stretti il divider sparisce e le 2 colonne si impilano */
  .dash-grid { grid-template-columns: 1fr; }
  .dash-divider { display: none; }
  .dash-grid > .left-col   { grid-column: 1; }
  .dash-grid > .side-cards { grid-column: 1; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Badge centrale sulla mappa quando hover/click su una riga regione */
.leaflet-tooltip.mah-region-count-label {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid var(--brand);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--brand-ink);
  box-shadow: 0 4px 12px rgba(20, 30, 60, 0.18);
  pointer-events: none;
  white-space: nowrap;
}
.leaflet-tooltip.mah-region-count-label::before { display: none; }  /* no freccia */
.leaflet-tooltip.mah-region-count-label .mah-region-name {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--brand);
  text-align: center;
}
.leaflet-tooltip.mah-region-count-label .mah-region-num {
  font-weight: 600;
  font-size: 16px;
  color: var(--brand-ink);
  text-align: center;
  margin-top: 2px;
}

/* ──────────────────────────────────────────────────────────────────
   Choropleth: label permanente "<Regione> · <N>" al centro regione
   ────────────────────────────────────────────────────────────────── */
.mah-region-label-icon { background: transparent !important; border: none !important; }
.mah-region-label {
  transform: translate(-50%, -50%);   /* centra sul punto centroide */
  white-space: nowrap;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 0 3px rgba(255,255,255,0.95),
               0 0 6px rgba(255,255,255,0.95),
               1px 1px 2px rgba(255,255,255,0.95);
  font-family: -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  user-select: none;
}
.mah-region-label-name {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--brand-ink);
  text-transform: uppercase;
  line-height: 1.1;
}
.mah-region-label-count {
  display: inline-block;
  margin-top: 2px;
  font-size: 14px;
  font-weight: 800;
  color: var(--brand);
  background: rgba(255,255,255,0.85);
  padding: 1px 7px;
  border-radius: 10px;
  border: 1px solid var(--brand-soft);
  line-height: 1.3;
}

/* Tooltip "Regione · N target" sul hover */
.leaflet-tooltip.region-tooltip {
  background: rgba(255,255,255,0.96);
  border: 1.5px solid var(--brand);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--brand-ink);
  box-shadow: 0 4px 12px rgba(20,30,60,0.2);
  pointer-events: none;
}
.leaflet-tooltip.region-tooltip::before { display: none; }

/* Dark mode: la label deve mantenere leggibilita' (centroide è su tile dark) */
html[data-theme="dark"] .mah-region-label {
  text-shadow: 0 0 4px rgba(0,0,0,0.95),
               0 0 8px rgba(0,0,0,0.85),
               1px 1px 2px rgba(0,0,0,0.9);
}
html[data-theme="dark"] .mah-region-label-name { color: #d0d8ff !important; }
html[data-theme="dark"] .mah-region-label-count {
  color: white !important;
  background: rgba(44,68,176,0.92) !important;
  border-color: var(--brand) !important;
}
html[data-theme="dark"] .leaflet-tooltip.region-tooltip {
  background: var(--bg-2) !important;
  color: var(--ink) !important;
  border-color: var(--brand) !important;
}

/* Cursor pointer sui poligoni delle regioni (sono cliccabili) */
.leaflet-pane.leaflet-regions-bg-pane path,
.leaflet-pane[class*="regions-bg"] path { cursor: pointer; }

/* Nascondi attribution Leaflet + OpenStreetMap in basso a destra mappa */
.leaflet-control-attribution { display: none !important; }

/* Badge "Filtro: <Regione> ×" sopra la mappa */
.mah-region-filter-badge {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 800;
  background: var(--brand);
  color: white;
  padding: 6px 10px 6px 14px;
  border-radius: 18px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 12px rgba(20,30,60,0.3);
  font-weight: 500;
}
.mah-region-filter-badge strong { font-weight: 700; margin-left: 4px; }
.mah-region-filter-badge button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mah-region-filter-badge button:hover { background: rgba(255,255,255,0.35); }
.map-card { position: relative; }

/* Bottone "↺ Italia" in alto a destra della card mappa */
.map-card .card-head { display: flex; align-items: center; gap: 12px; }
.map-card .card-head #map-info { flex: 1; }
.btn-map-reset {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  min-height: 34px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn-map-reset:hover {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-ink);
}
html[data-theme="dark"] .btn-map-reset {
  background: var(--bg-2);
  color: var(--brand-ink);
  border-color: var(--line);
}
html[data-theme="dark"] .btn-map-reset:hover {
  background: #1e2a55;
  border-color: var(--brand);
}

/* Pannello filtri mappa */
.map-filters-panel {
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.map-filters-panel.hidden { display: none; }
.map-filters-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.map-filters-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  min-width: 110px;
  flex-shrink: 0;
}
.map-filters-options { display: flex; flex-wrap: wrap; gap: 5px; flex: 1; }
.map-filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  min-height: 34px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.map-filter-pill:hover { border-color: var(--brand); }
.map-filter-pill input[type=checkbox] { margin: 0; }
.map-filter-pill:has(input:checked) {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}
.map-filters-actions { display: flex; align-items: center; gap: 10px; padding-top: 4px; border-top: 1px dashed var(--line); }
html[data-theme="dark"] .map-filter-pill { background: var(--bg-2); color: var(--ink); border-color: var(--line); }
html[data-theme="dark"] .map-filter-pill:has(input:checked) { background: #1e2a55; color: var(--brand-ink); border-color: var(--brand); }
html[data-theme="dark"] .map-filters-panel { background: var(--bg); border-color: var(--line); }

/* Card "Top target da contattare" */
.top-targets-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: tt;
}
.top-targets-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  position: relative;
  counter-increment: tt;
}
.top-targets-list li:last-child { border-bottom: 0; }
.top-targets-list li::before {
  content: counter(tt);
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.top-targets-list .tt-main { flex: 1; min-width: 0; }
.top-targets-list .tt-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.top-targets-list .tt-name:hover { color: var(--brand); text-decoration: underline; }
.top-targets-list .tt-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.top-targets-list .tt-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 600;
}
.top-targets-list .tt-badge.score-high { background: rgba(47,158,68,0.18); color: #2f9e44; }
.top-targets-list .tt-badge.score-mid  { background: rgba(230,119,0,0.18); color: #b25b00; }
.top-targets-list .tt-badge.score-low  { background: rgba(201,42,42,0.18); color: #c92a2a; }
.top-targets-list .tt-fatt { font-weight: 600; color: var(--brand-ink); }
.top-targets-list .tt-contacts { display: flex; gap: 4px; }
.top-targets-list .tt-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; background: var(--line); align-self: center;
}
.top-targets-list .tt-dot.ok { background: var(--ok); }
html[data-theme="dark"] .top-targets-list .tt-badge.score-high { color: #51cf66 !important; }
html[data-theme="dark"] .top-targets-list .tt-badge.score-mid  { color: #ffb84a !important; }
html[data-theme="dark"] .top-targets-list .tt-badge.score-low  { color: #ff6b6b !important; }

/* Card "Dati economici" sulla Dashboard */
.econ-panel { padding: 12px 14px; }
.econ-kpis {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; margin-bottom: 12px;
}
.econ-kpis div { display: flex; flex-direction: column; align-items: flex-start; }
.econ-kpis strong { font-size: 17px; font-weight: 700; color: var(--brand-ink); }
.econ-kpis .muted { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 700px) { .econ-kpis { grid-template-columns: repeat(2, 1fr); } }

/* Card geocoder sulla Dashboard */
.geo-panel { padding: 12px 14px; }
.geo-progress-wrap { margin-bottom: 12px; }
.geo-progress-track {
  height: 8px;
  background: #eef0f5;
  border-radius: 4px;
  overflow: hidden;
}
.geo-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--brand) 0%, #4a6fd8 100%);
  border-radius: 4px;
  transition: width .4s ease-out;
}
.geo-progress-bar.working {
  background: linear-gradient(90deg, var(--ok) 0%, #4ac76b 50%, var(--ok) 100%);
  background-size: 200% 100%;
  animation: geoFlow 1.5s linear infinite;
}
@keyframes geoFlow { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.geo-progress-info {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px; font-size: 11px;
}
.geo-progress-info strong { color: var(--brand-ink); font-size: 13px; }
.geo-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 12px;
}
.geo-stats div { display: flex; flex-direction: column; align-items: flex-start; }
.geo-stats strong { font-size: 18px; font-weight: 700; color: var(--brand-ink); }
.geo-stats .muted { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.geo-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.geo-actions .btn { padding: 6px 10px; font-size: 11px; }
#geo-state { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
#geo-state.working { color: var(--ok); }
#geo-state.sleeping { color: var(--warn); }
#geo-state.stopped, #geo-state.idle { color: var(--muted); }

/* Lista ultimi processati */
.geo-recent { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.geo-recent-head {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
  display: flex; justify-content: space-between; margin-bottom: 6px;
}
.geo-recent ul { list-style: none; margin: 0; padding: 0; max-height: 140px; overflow-y: auto; }
.geo-recent li {
  display: flex; align-items: center; gap: 6px;
  padding: 3px 0; font-size: 11px;
  border-bottom: 1px dashed var(--line);
}
.geo-recent li:last-child { border-bottom: 0; }
.geo-recent .gr-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.gr-dot.ok { background: var(--ok); }
.gr-dot.cached { background: #9fb8eb; }
.gr-dot.failed { background: var(--err); }
.gr-dot.noaddr { background: var(--muted); }
.geo-recent .gr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.geo-recent .gr-time { color: var(--muted); font-size: 10px; }

/* Tab Storico (changelog) */
.hist-toolbar { display:flex; gap:10px; align-items:center; margin-bottom:14px; flex-wrap:wrap; }
/* `.hist-toolbar select` eredita la regola unificata `.panel select`. */
.history-list { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.hist-item {
  display: grid;
  grid-template-columns: 120px 100px 80px 1fr 130px;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  align-items: center;
}
.hist-item:last-child { border-bottom: 0; }
.hist-item:hover { background: #fafbff; }
.hist-when { color: var(--muted); font-size: 11px; }
.hist-src { font-weight: 600; }
.hist-src.creator    { color: #1a2a6e; }
.hist-src.updator    { color: #b25b00; }
.hist-src.gestionale { color: #2f9e44; }
.hist-src.hub        { color: var(--muted); }
.hist-src.system     { color: var(--muted); }
.hist-action {
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; text-align: center;
  text-transform: uppercase; letter-spacing: .03em;
}
.hist-action.insert { background: #e8f5ec; color: #1b5e20; }
.hist-action.update { background: #fff4d6; color: #5a4400; }
.hist-action.delete { background: #fde8e8; color: #7f1d1d; }
.hist-action.geocode, .hist-action.import, .hist-action.note { background: #e7eaf3; color: var(--brand-ink); }
.hist-target { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Popup mappa */
.map-popup { font-size: 12px; line-height: 1.4; }
.map-popup .pp-title { font-weight: 600; font-size: 13px; }
.map-popup .pp-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
.map-popup .pp-link { color: var(--brand); text-decoration: none; font-size: 11px; }

/* Impostazioni */
.key-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.key-card .key-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 4px;
}
.key-card .key-label { font-weight: 600; font-size: 14px; }
.key-card .key-meta { font-size: 11px; color: var(--muted); }
.key-card .key-desc { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.key-card input[type="password"], .key-card input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px;
}
.key-card .key-current { font-size: 11px; color: var(--muted); margin-top: 6px; }
.key-card .key-current code { background: var(--bg); padding: 2px 6px; border-radius: 3px; }
.settings-actions {
  display: flex; align-items: center; gap: 12px;
  margin-top: 16px;
}

.bridge-result {
  margin-top: 20px;
  padding: 14px 18px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
}
.bridge-result.ok {
  display: block;
  background: #e8f5ec;
  color: #1b5e20;
  border: 1px solid #b7dcc1;
}
.bridge-result.err {
  display: block;
  background: #fde8e8;
  color: #7f1d1d;
  border: 1px solid #f1b9b9;
}
