:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #182230;
  --muted: #667085;
  --line: #e4e7ec;
  --primary: #175cd3;
  --primary-dark: #1849a9;
  --danger: #d92d20;
  --warning: #dc6803;
  --success: #079455;
  --info: #1570ef;
  --purple: #7a5af8;
  --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
.app-shell { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); box-shadow: 0 1px 4px rgba(16, 24, 40, 0.03); }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.status-pill { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); background: #fff; }
.status-pill.online { color: var(--success); border-color: #abefc6; background: #ecfdf3; }
.status-pill.offline { color: var(--warning); border-color: #fedf89; background: #fffaeb; }
.btn { border: 0; border-radius: 10px; padding: 9px 12px; font-weight: 700; cursor: pointer; transition: .15s ease; }
.btn.primary { color: #fff; background: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { color: var(--text); background: #eef4ff; border: 1px solid #c7d7fe; }
.btn.tiny { padding: 5px 8px; font-size: 12px; background: #f2f4f7; }
.btn.full { width: 100%; margin-top: 10px; }
.kpi-bar { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; padding: 12px 14px; background: var(--bg); }
.kpi-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; box-shadow: var(--shadow); }
.kpi-card span { display: block; font-size: 24px; font-weight: 800; }
.kpi-card small { color: var(--muted); font-weight: 700; }
.kpi-card.danger span { color: var(--danger); }
.kpi-card.warning span { color: var(--warning); }
.kpi-card.success span { color: var(--success); }
.kpi-card.info span { color: var(--info); }
.kpi-card.purple span { color: var(--purple); }
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px 1fr 360px; gap: 12px; padding: 0 14px 14px; }
.sidebar { min-height: 0; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); }
.sidebar h2 { margin: 0 0 12px; font-size: 16px; }
label { display: block; font-size: 12px; font-weight: 800; color: #344054; margin: 12px 0 6px; }
input, select, textarea { width: 100%; border: 1px solid #d0d5dd; border-radius: 10px; padding: 10px; font: inherit; outline: none; background: #fff; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #84adff; box-shadow: 0 0 0 3px #eff4ff; }
.filter-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.filter-row input { width: auto; }
.filter-row label { margin: 0; }
.map-wrap { min-height: 0; overflow: hidden; border-radius: 20px; box-shadow: var(--shadow); border: 1px solid var(--line); }
#map { width: 100%; height: 100%; min-height: 540px; background: #d0d5dd; }
.panel-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.panel-card h2 { font-size: 16px; margin: 0 0 10px; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--muted); }
.detail-title { font-weight: 900; font-size: 17px; margin-bottom: 4px; }
.detail-meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 4px 8px; font-size: 12px; font-weight: 800; background: #f2f4f7; color: #344054; margin: 2px; }
.badge.danger { color: #b42318; background: #fef3f2; }
.badge.warning { color: #b54708; background: #fffaeb; }
.badge.success { color: #027a48; background: #ecfdf3; }
.badge.info { color: #175cd3; background: #eff4ff; }
.badge.purple { color: #5925dc; background: #f4f3ff; }
.area-list, .notifications-list, .route-list { display: grid; gap: 8px; }
.area-item, .notification-item, .route-item { border: 1px solid var(--line); background: #fcfcfd; border-radius: 12px; padding: 9px 10px; font-size: 13px; }
.area-item strong, .notification-item strong { display: block; }
.notification-item.high { border-color: #fecdca; background: #fef3f2; }
.notification-item.medium { border-color: #fedf89; background: #fffaeb; }
.notification-item.low { border-color: #d0d5dd; }
.popup-title { font-weight: 900; }
.popup-actions { display: flex; gap: 6px; margin-top: 8px; }
.popup-actions button { border: 0; background: #eef4ff; color: #1849a9; border-radius: 8px; padding: 6px 8px; cursor: pointer; font-weight: 800; }
.marker-pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.marker-pin span { display: block; transform: rotate(45deg); color: #fff; font-size: 11px; font-weight: 900; line-height: 22px; text-align: center; }
@media (max-width: 1150px) {
  .workspace { grid-template-columns: 260px 1fr; }
  .right-panel { display: none; }
  .kpi-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .topbar { height: auto; align-items: flex-start; gap: 8px; flex-direction: column; }
  .workspace { grid-template-columns: 1fr; overflow-y: auto; }
  .sidebar.left-panel { max-height: 330px; }
  .map-wrap { min-height: 520px; }
  .kpi-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* =========================================================
   Auth login compatto - Rimini Control Hub
   ========================================================= */

.topbar {
  gap: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: nowrap;
}

.auth-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.auth-box input {
  width: 150px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid #cfd7e6;
  border-radius: 12px;
  background: #ffffff;
  font-size: 14px;
  line-height: 38px;
  outline: none;
}

.auth-box input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.auth-box .btn {
  height: 38px;
  padding: 0 14px;
  white-space: nowrap;
}

#authStatus {
  font-size: 13px;
  white-space: nowrap;
  color: #667085;
}

@media (max-width: 1200px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .auth-box {
    width: 100%;
    justify-content: flex-end;
  }

  .auth-box input {
    width: 140px;
  }
}

/* =========================================================
   Selezione area - elenco locali selezionati
   ========================================================= */

.selection-list {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.selection-row {
  border: 1px solid #e4e7ec;
  border-radius: 12px;
  padding: 10px;
  background: #ffffff;
}

.selection-row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.selection-row-main strong {
  font-size: 13px;
  color: #101828;
}

.selection-row-main span {
  font-size: 12px;
  color: #667085;
}

.selection-row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.selection-row-meta span {
  font-size: 11px;
  border-radius: 999px;
  padding: 3px 7px;
  background: #f2f4f7;
  color: #475467;
}

/* =========================================================
   Azioni massive su selezione area
   ========================================================= */

.bulk-actions {
  border: 1px solid #e4e7ec;
  border-radius: 14px;
  padding: 12px;
  background: #f9fafb;
  margin: 10px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bulk-actions label {
  font-size: 12px;
  font-weight: 600;
  color: #344054;
}

.bulk-actions select,
.bulk-actions input,
.bulk-actions textarea {
  width: 100%;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  background: #ffffff;
}

.bulk-actions textarea {
  min-height: 64px;
  resize: vertical;
}

/* =========================================================
   Selezione area - focus locale selezionato
   ========================================================= */

.selection-row-clickable {
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.selection-row-clickable:hover {
  border-color: #84caff;
  background: #f5fbff;
}

.selection-row-clickable.active {
  border-color: #1570ef;
  box-shadow: 0 0 0 3px rgba(21, 112, 239, 0.14);
  background: #eff8ff;
}

/* =========================================================
   Aree operative cliccabili
   ========================================================= */

.area-item-button {
  width: 100%;
  text-align: left;
  border: 1px solid #e4e7ec;
  background: #ffffff;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.area-item-button:hover {
  border-color: #84caff;
  background: #f5fbff;
  box-shadow: 0 0 0 3px rgba(21, 112, 239, 0.08);
}

/* =========================================================
   UI Refresh 43A - Topbar e KPI
   ========================================================= */

:root {
  --rch-bg: #f4f7fb;
  --rch-surface: #ffffff;
  --rch-surface-soft: #f8fafc;
  --rch-border: #e4e7ec;
  --rch-text: #101828;
  --rch-muted: #667085;
  --rch-primary: #1570ef;
  --rch-primary-soft: #eff8ff;
  --rch-danger: #d92d20;
  --rch-warning: #dc6803;
  --rch-success: #079455;
  --rch-purple: #d946ef;
  --rch-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --rch-shadow-md: 0 10px 24px rgba(16, 24, 40, 0.08);
}

body {
  background:
    radial-gradient(circle at top left, rgba(21, 112, 239, 0.08), transparent 34%),
    linear-gradient(180deg, #f7faff 0%, var(--rch-bg) 100%);
  color: var(--rch-text);
}

.app-shell {
  background: transparent;
}

.topbar {
  margin: 14px 14px 10px;
  padding: 16px 18px;
  border: 1px solid rgba(228, 231, 236, 0.85);
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.96), rgba(248,250,252,0.94));
  box-shadow: var(--rch-shadow-md);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  font-size: 24px;
  letter-spacing: -0.03em;
  color: #0b1220;
  margin-bottom: 2px;
}

.topbar p {
  font-size: 13px;
  color: var(--rch-muted);
  font-weight: 500;
}

.topbar-actions {
  gap: 9px;
}

.status-pill {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--rch-shadow-sm);
}

.status-pill.online {
  background: #ecfdf3;
  color: #067647;
  border: 1px solid #abefc6;
}

.status-pill.offline {
  background: #fff1f3;
  color: #c01048;
  border: 1px solid #fecdd6;
}

.btn {
  border-radius: 12px;
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(16, 24, 40, 0.12);
}

.btn.primary {
  background: linear-gradient(135deg, #1570ef, #175cd3);
  border-color: #1570ef;
}

.btn.secondary {
  background: #ffffff;
  border: 1px solid #d0d5dd;
  color: #344054;
}

.btn.secondary:hover {
  background: #f9fafb;
  border-color: #98a2b3;
}

.auth-box {
  padding: 4px;
  border: 1px solid #e4e7ec;
  border-radius: 16px;
  background: rgba(255,255,255,0.86);
  box-shadow: var(--rch-shadow-sm);
}

.auth-box input {
  height: 34px;
  border-radius: 10px;
  border-color: transparent;
  background: #f8fafc;
}

.auth-box input:focus {
  background: #ffffff;
}

#authStatus {
  padding: 0 4px;
  font-weight: 700;
}

#authStatus.auth-ok {
  color: #067647;
}

/* KPI cards refresh */

.kpi-bar {
  margin: 0 14px 12px;
  gap: 12px;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(228, 231, 236, 0.92);
  border-radius: 20px;
  background: rgba(255,255,255,0.96);
  box-shadow: var(--rch-shadow-sm);
  min-height: 82px;
  padding: 16px 16px 14px;
}

.kpi-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: #1570ef;
  opacity: 0.95;
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -28px;
  top: -28px;
  width: 92px;
  height: 92px;
  border-radius: 999px;
  background: rgba(21, 112, 239, 0.08);
}

.kpi-card span {
  position: relative;
  z-index: 1;
  display: block;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.04em;
  font-weight: 800;
  color: #101828;
}

.kpi-card small {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: var(--rch-muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-card.danger::before {
  background: #d92d20;
}

.kpi-card.danger::after {
  background: rgba(217, 45, 32, 0.10);
}

.kpi-card.warning::before {
  background: #d946ef;
}

.kpi-card.warning::after {
  background: rgba(217, 70, 239, 0.10);
}

.kpi-card.info::before {
  background: #7a5af8;
}

.kpi-card.info::after {
  background: rgba(122, 90, 248, 0.10);
}

.kpi-card.success::before {
  background: #079455;
}

.kpi-card.success::after {
  background: rgba(7, 148, 85, 0.10);
}

.kpi-card.purple::before {
  background: #d946ef;
}

.kpi-card.purple::after {
  background: rgba(217, 70, 239, 0.10);
}

@media (max-width: 1200px) {
  .topbar {
    border-radius: 18px;
  }

  .kpi-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .kpi-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .auth-box {
    width: 100%;
    justify-content: flex-start;
  }
}

/* =========================================================
   Fix 43A-1 - Allineamento pulsante Esci
   ========================================================= */

#logoutBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  height: 38px;
  padding: 0 16px;
  line-height: 1;
}

.auth-box #logoutBtn {
  margin: 0;
}


/* =========================================================
   UI Refresh 43B - Sidebar filtri e aree operative
   ========================================================= */

.sidebar {
  border: 1px solid rgba(228, 231, 236, 0.92);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--rch-shadow-sm);
}

.left-panel {
  padding: 18px;
}

.left-panel h2 {
  margin: 0 0 14px;
  font-size: 20px;
  letter-spacing: -0.02em;
  color: #101828;
}

.left-panel label {
  display: block;
  margin: 12px 0 7px;
  font-size: 13px;
  font-weight: 800;
  color: #344054;
}

.left-panel input[type="search"],
.left-panel select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d0d5dd;
  border-radius: 13px;
  padding: 0 14px;
  background: #ffffff;
  color: #101828;
  font-size: 14px;
  font-weight: 600;
  outline: none;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.left-panel input[type="search"]::placeholder {
  color: #98a2b3;
  font-weight: 500;
}

.left-panel input[type="search"]:focus,
.left-panel select:focus {
  border-color: #1570ef;
  box-shadow: 0 0 0 4px rgba(21, 112, 239, 0.12);
  background: #ffffff;
}

.filter-row {
  margin: 14px 0 18px;
  padding: 10px 12px;
  border: 1px solid #e4e7ec;
  border-radius: 13px;
  background: #f9fafb;
  display: flex;
  align-items: center;
  gap: 10px;
}

.filter-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #1570ef;
}

.filter-row label {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  color: #344054;
}

.area-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 8px;
}

.area-item,
.area-item-button {
  position: relative;
  border-radius: 15px;
  padding: 12px 13px;
  background: #ffffff;
  border: 1px solid #e4e7ec;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.area-item::before,
.area-item-button::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 4px;
  border-radius: 999px;
  background: #1570ef;
  opacity: 0.75;
}

.area-item strong,
.area-item-button strong {
  display: block;
  padding-left: 8px;
  font-size: 13px;
  color: #101828;
  font-weight: 800;
  line-height: 1.2;
}

.area-item span,
.area-item-button span {
  display: block;
  padding-left: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: #667085;
  font-weight: 600;
}

.area-item-button:hover {
  border-color: #84caff;
  background: linear-gradient(135deg, #ffffff, #f5fbff);
  box-shadow: 0 0 0 4px rgba(21, 112, 239, 0.08);
}

.area-item-button:active {
  transform: translateY(1px);
}

.left-panel .muted {
  color: #667085;
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 980px) {
  .left-panel {
    padding: 14px;
  }

  .left-panel h2 {
    font-size: 18px;
  }
}

/* =========================================================
   UI Refresh 43C - Mappa, marker, cluster e toolbar
   ========================================================= */

.map-wrap {
  position: relative;
  border: 1px solid rgba(228, 231, 236, 0.96);
  border-radius: 24px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 16px 34px rgba(16, 24, 40, 0.10);
}

#map {
  border-radius: 24px;
  overflow: hidden;
  background: #eef4ff;
}

/* Leaflet controls */

.leaflet-control-container .leaflet-top.leaflet-left {
  margin-top: 12px;
  margin-left: 12px;
}

.leaflet-control-zoom,
.leaflet-draw,
.leaflet-bar {
  border: none !important;
  box-shadow: 0 10px 22px rgba(16, 24, 40, 0.16) !important;
  border-radius: 14px !important;
  overflow: hidden;
}

.leaflet-bar a,
.leaflet-bar a:hover {
  width: 38px !important;
  height: 38px !important;
  line-height: 38px !important;
  border-bottom: 1px solid #e4e7ec !important;
  background: rgba(255, 255, 255, 0.96) !important;
  color: #101828 !important;
  font-weight: 800 !important;
}

.leaflet-bar a:hover {
  background: #eff8ff !important;
  color: #1570ef !important;
}

.leaflet-bar a:last-child {
  border-bottom: none !important;
}

.leaflet-draw-toolbar a {
  background-color: rgba(255, 255, 255, 0.96) !important;
}

.leaflet-draw-toolbar a:hover {
  background-color: #eff8ff !important;
}

/* Popup */

.leaflet-popup-content-wrapper {
  border-radius: 18px !important;
  box-shadow: 0 18px 40px rgba(16, 24, 40, 0.18) !important;
  border: 1px solid #e4e7ec;
}

.leaflet-popup-content {
  margin: 14px !important;
}

.leaflet-popup-tip {
  box-shadow: 0 8px 18px rgba(16, 24, 40, 0.12) !important;
}

/* Marker custom */

.marker-pin {
  width: 30px;
  height: 30px;
  border-radius: 999px 999px 999px 6px;
  transform: rotate(-45deg);
  border: 3px solid #ffffff;
  box-shadow:
    0 8px 18px rgba(16, 24, 40, 0.26),
    inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-pin span {
  transform: rotate(45deg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,0.28);
}

/* Cluster refresh */

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background-color: rgba(21, 112, 239, 0.18) !important;
  border-radius: 999px;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,0.45), transparent 28%),
    linear-gradient(135deg, #1570ef, #175cd3) !important;
  color: #ffffff !important;
  font-weight: 900 !important;
  border: 3px solid #ffffff;
  box-shadow: 0 10px 22px rgba(21, 112, 239, 0.30);
}

/* Area selezionata / SVG overlay */

.leaflet-overlay-pane svg path {
  vector-effect: non-scaling-stroke;
}

/* Attribution */

.leaflet-control-attribution {
  border-radius: 999px 0 0 0;
  padding: 3px 8px !important;
  background: rgba(255, 255, 255, 0.86) !important;
  color: #475467 !important;
  font-size: 10px !important;
}

/* Selection panel in map/right context remains readable */

.selection-list {
  scrollbar-width: thin;
  scrollbar-color: #98a2b3 #f2f4f7;
}

.selection-list::-webkit-scrollbar {
  width: 8px;
}

.selection-list::-webkit-scrollbar-track {
  background: #f2f4f7;
  border-radius: 999px;
}

.selection-list::-webkit-scrollbar-thumb {
  background: #98a2b3;
  border-radius: 999px;
}


/* =========================================================
   Fix 43C-1 - Font corporate, marker centrati, icone disegno
   ========================================================= */

/* Font più aziendale, senza dipendenze esterne */
body,
button,
input,
select,
textarea {
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
}

/* Marker: centratura più precisa del contenuto */
.marker-pin {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
}

.marker-pin span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.02em;
}

/* Cluster: numeri più centrati e leggibili */
.marker-cluster div {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  text-align: center !important;
}

.marker-cluster span {
  line-height: 1 !important;
  transform: translateY(0) !important;
  font-weight: 900 !important;
  letter-spacing: -0.03em;
}

/* Leaflet.draw: ripristino icone visibili con stile pulito */
.leaflet-draw-toolbar a {
  position: relative;
  background-image: none !important;
  background-color: rgba(255, 255, 255, 0.98) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  color: #101828 !important;
}

.leaflet-draw-toolbar a::after {
  font-size: 17px;
  line-height: 1;
  font-weight: 900;
  color: #344054;
}

.leaflet-draw-toolbar a:hover::after {
  color: #1570ef;
}

/* Poligono */
.leaflet-draw-draw-polygon::after {
  content: "⬠";
}

/* Rettangolo */
.leaflet-draw-draw-rectangle::after {
  content: "▭";
  font-size: 20px;
}

/* Cancella selezione */
.leaflet-draw-edit-remove::after {
  content: "⌫";
  font-size: 18px;
}

/* Eventuali strumenti edit disabilitati o nascosti */
.leaflet-draw-edit-edit::after {
  content: "✎";
}

/* Migliore contrasto tooltip disegno */
.leaflet-draw-tooltip {
  border-radius: 10px !important;
  background: rgba(16, 24, 40, 0.92) !important;
  color: #ffffff !important;
  box-shadow: 0 12px 24px rgba(16, 24, 40, 0.22) !important;
  padding: 8px 10px !important;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif !important;
}

.leaflet-draw-tooltip:before {
  border-right-color: rgba(16, 24, 40, 0.92) !important;
}


/* =========================================================
   UI Refresh 43D - Pannello destro
   ========================================================= */

.right-panel {
  gap: 14px;
  padding: 18px;
}

.panel-card,
#selectionPanel {
  border: 1px solid rgba(228, 231, 236, 0.96);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(249,250,251,0.96));
  box-shadow:
    0 1px 2px rgba(16, 24, 40, 0.05),
    0 12px 28px rgba(16, 24, 40, 0.06);
  padding: 18px;
}

.panel-card h2,
#selectionPanel h2 {
  margin: 0 0 12px;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: #101828;
}

.panel-card .muted,
#selectionPanel .muted {
  color: #667085;
  font-size: 14px;
  line-height: 1.45;
}

.detail-title {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #101828;
  margin: 4px 0 4px;
}

.detail-meta {
  color: #667085;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
  margin: 0 5px 6px 0;
  border: 1px solid transparent;
}

.badge.danger {
  background: #fef3f2;
  color: #b42318;
  border-color: #fecdca;
}

.badge.warning {
  background: #fff7ed;
  color: #b54708;
  border-color: #fed7aa;
}

.badge.info {
  background: #eff8ff;
  color: #175cd3;
  border-color: #b2ddff;
}

.badge.success {
  background: #ecfdf3;
  color: #067647;
  border-color: #abefc6;
}

.badge.purple {
  background: #fdf4ff;
  color: #c026d3;
  border-color: #f5d0fe;
}

/* Form nel dettaglio */

#detailPanel label,
#selectionPanel label {
  display: block;
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 800;
  color: #344054;
}

#detailPanel select,
#detailPanel input,
#detailPanel textarea,
#selectionPanel select,
#selectionPanel input,
#selectionPanel textarea {
  width: 100%;
  border: 1px solid #d0d5dd;
  border-radius: 12px;
  background: #ffffff;
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 600;
  color: #101828;
  outline: none;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

#detailPanel select:focus,
#detailPanel input:focus,
#detailPanel textarea:focus,
#selectionPanel select:focus,
#selectionPanel input:focus,
#selectionPanel textarea:focus {
  border-color: #1570ef;
  box-shadow: 0 0 0 4px rgba(21, 112, 239, 0.12);
}

#detailPanel textarea,
#selectionPanel textarea {
  min-height: 76px;
  resize: vertical;
}

#detailPanel .btn.full,
#selectionPanel .btn.full {
  margin-top: 12px;
  min-height: 42px;
}

/* Notifiche */

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

.panel-title-row h2 {
  margin: 0;
}

.btn.tiny {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
}

.notifications-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.notification-item,
.notifications-list > div {
  border: 1px solid #e4e7ec;
  border-radius: 15px;
  background: #ffffff;
  padding: 12px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.notification-item strong,
.notifications-list strong {
  color: #101828;
  font-size: 13px;
  font-weight: 900;
}

.notification-item p,
.notifications-list p {
  margin: 4px 0 0;
  color: #475467;
  font-size: 12px;
  line-height: 1.35;
}

/* Percorso */

.route-list {
  border: 1px dashed #d0d5dd;
  border-radius: 14px;
  background: #f9fafb;
  padding: 12px;
  font-size: 13px;
  line-height: 1.45;
}

#openRouteBtn {
  margin-top: 12px;
}

/* Selezione area */

#selectionPanel {
  border-color: #b2ddff;
  background:
    linear-gradient(180deg, #ffffff, #f5fbff);
}

.selection-list {
  margin-top: 12px;
  max-height: 300px;
}

.selection-row {
  border-radius: 14px;
}

.bulk-actions {
  border-radius: 16px;
  background:
    linear-gradient(180deg, #f9fafb, #ffffff);
}


/* =========================================================
   UI Refresh 43E - Immagine attività e azioni dettaglio
   ========================================================= */

.activity-hero {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.activity-image-placeholder {
  flex: 0 0 76px;
  width: 76px;
  height: 76px;
  border-radius: 18px;
  background:
    radial-gradient(circle at 25% 20%, rgba(255,255,255,0.45), transparent 30%),
    linear-gradient(135deg, #1570ef, #7a5af8);
  box-shadow: 0 14px 24px rgba(21, 112, 239, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.activity-image-placeholder span {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.04em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.activity-hero-content {
  min-width: 0;
  flex: 1;
}

.activity-hero-content .detail-title {
  margin-top: 0;
}

.activity-badges {
  margin-top: 8px;
}

.detail-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 14px;
}

.detail-action-row .btn {
  min-height: 40px;
  justify-content: center;
}

@media (max-width: 760px) {
  .activity-hero {
    flex-direction: column;
  }

  .activity-image-placeholder {
    width: 100%;
    height: 92px;
  }
}


/* =========================================================
   UI Refresh 43F - Andamento complessivo
   ========================================================= */

.analytics-modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
}

.analytics-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, 0.42);
  backdrop-filter: blur(5px);
}

.analytics-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(1040px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(228, 231, 236, 0.9);
  border-radius: 26px;
  background:
    radial-gradient(circle at top left, rgba(21,112,239,0.08), transparent 34%),
    #ffffff;
  box-shadow: 0 28px 80px rgba(16, 24, 40, 0.30);
  padding: 22px;
}

.analytics-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.analytics-header h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.03em;
  color: #101828;
}

.analytics-header p {
  margin: 5px 0 0;
  color: #667085;
  font-size: 14px;
  font-weight: 600;
}

.analytics-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.analytics-kpi {
  border: 1px solid #e4e7ec;
  border-radius: 20px;
  background: #ffffff;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.05);
  position: relative;
  overflow: hidden;
}

.analytics-kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: #1570ef;
}

.analytics-kpi.danger::before {
  background: #d92d20;
}

.analytics-kpi.info::before {
  background: #1570ef;
}

.analytics-kpi.purple::before {
  background: #d946ef;
}

.analytics-kpi span {
  display: block;
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: #101828;
}

.analytics-kpi small {
  display: block;
  margin-top: 8px;
  color: #667085;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.analytics-progress-card {
  border: 1px solid #dbeafe;
  border-radius: 22px;
  background: linear-gradient(135deg, #eff8ff, #ffffff);
  padding: 18px;
  margin-bottom: 14px;
}

.analytics-progress-main {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: center;
}

.analytics-progress-main strong {
  display: block;
  font-size: 42px;
  line-height: 1;
  letter-spacing: -0.06em;
  color: #175cd3;
}

.analytics-progress-main span {
  display: block;
  margin-top: 6px;
  color: #475467;
  font-weight: 800;
  font-size: 13px;
}

.analytics-progress-bar,
.analytics-bar-track {
  height: 13px;
  border-radius: 999px;
  background: #e4e7ec;
  overflow: hidden;
}

.analytics-progress-bar i,
.analytics-bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1570ef, #d946ef);
}

.analytics-mini-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.analytics-mini-stats div {
  border: 1px solid #e4e7ec;
  border-radius: 15px;
  background: rgba(255,255,255,0.8);
  padding: 10px;
}

.analytics-mini-stats strong {
  display: block;
  font-size: 20px;
  color: #101828;
}

.analytics-mini-stats span {
  display: block;
  color: #667085;
  font-size: 12px;
  font-weight: 700;
}

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.analytics-card {
  border: 1px solid #e4e7ec;
  border-radius: 22px;
  background: #ffffff;
  padding: 16px;
}

.analytics-card h3 {
  margin: 0 0 14px;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.analytics-bars {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.analytics-bar-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.analytics-bar-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.analytics-bar-label span {
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.analytics-bar-label strong {
  color: #101828;
  font-size: 13px;
  font-weight: 900;
}

.analytics-bar-row small {
  color: #667085;
  font-size: 11px;
  font-weight: 800;
}

@media (max-width: 900px) {
  .analytics-kpi-grid,
  .analytics-grid,
  .analytics-progress-main {
    grid-template-columns: 1fr;
  }
}

/* =========================================================
   UI Refresh 43G - Pianificazione percorso
   ========================================================= */

.route-empty {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.route-empty strong {
  color: #101828;
  font-size: 13px;
}

.route-empty span {
  color: #667085;
  font-size: 12px;
}

.route-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.route-summary div {
  border: 1px solid #e4e7ec;
  border-radius: 14px;
  background: #ffffff;
  padding: 10px;
  text-align: center;
}

.route-summary strong {
  display: block;
  font-size: 18px;
  line-height: 1;
  color: #101828;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.route-summary span {
  display: block;
  margin-top: 5px;
  color: #667085;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.route-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.route-actions .btn {
  min-height: 38px;
  font-size: 12px;
}

.route-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

.route-item {
  display: grid;
  grid-template-columns: 30px 1fr 26px;
  gap: 8px;
  align-items: start;
  border: 1px solid #e4e7ec;
  border-radius: 15px;
  background: #ffffff;
  padding: 9px;
}

.route-index {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #eff8ff;
  color: #175cd3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 12px;
}

.route-content {
  min-width: 0;
}

.route-content strong {
  display: block;
  color: #101828;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.25;
}

.route-content span {
  display: block;
  margin-top: 3px;
  color: #475467;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
}

.route-content small {
  display: block;
  margin-top: 4px;
  color: #667085;
  font-size: 10px;
  font-weight: 800;
}

.route-remove-btn {
  width: 24px;
  height: 24px;
  border: 1px solid #e4e7ec;
  border-radius: 999px;
  background: #ffffff;
  color: #667085;
  cursor: pointer;
  font-size: 17px;
  line-height: 20px;
  font-weight: 900;
}

.route-remove-btn:hover {
  background: #fef3f2;
  color: #b42318;
  border-color: #fecdca;
}

.route-items {
  scrollbar-width: thin;
  scrollbar-color: #98a2b3 #f2f4f7;
}

.route-items::-webkit-scrollbar {
  width: 8px;
}

.route-items::-webkit-scrollbar-track {
  background: #f2f4f7;
  border-radius: 999px;
}

.route-items::-webkit-scrollbar-thumb {
  background: #98a2b3;
  border-radius: 999px;
}

/* =========================================================
   Ruoli 45D-1 - Avviso sola lettura
   ========================================================= */

.readonly-notice {
  margin-top: 12px;
  border: 1px solid #fecdca;
  border-radius: 14px;
  background: #fef3f2;
  color: #b42318;
  padding: 11px 12px;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
}

#detailPanel select:disabled,
#detailPanel input:disabled,
#detailPanel textarea:disabled {
  background: #f9fafb;
  color: #667085;
  cursor: not-allowed;
}

/* =========================================================
   Ruoli 45D-3 - Pulsanti disabilitati per permessi
   ========================================================= */

.btn:disabled,
.btn-disabled {
  opacity: 0.48;
  cursor: not-allowed !important;
  transform: none !important;
  box-shadow: none !important;
}


/* =========================================================
   Ruoli 45D-4 - Percorso disabilitato per sola lettura
   ========================================================= */

.route-disabled {
  opacity: 0.82;
}

.route-disabled .route-empty {
  border: 1px solid #e4e7ec;
  border-radius: 14px;
  background: #f9fafb;
  padding: 12px;
}


/* =========================================================
   UI 46C - Accesso lettore e riepilogo aggregato
   ========================================================= */

.reader-modal {
  position: fixed;
  inset: 0;
  z-index: 6000;
}

.reader-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, 0.46);
  backdrop-filter: blur(5px);
}

.reader-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(1080px, calc(100vw - 36px));
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(228, 231, 236, 0.9);
  border-radius: 28px;
  background:
    radial-gradient(circle at top left, rgba(21, 112, 239, 0.09), transparent 34%),
    #ffffff;
  box-shadow: 0 30px 90px rgba(16, 24, 40, 0.32);
  padding: 22px;
}

.reader-header,
.reader-dashboard-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.reader-header h2,
.reader-dashboard-title h3 {
  margin: 0;
  color: #101828;
  letter-spacing: -0.03em;
}

.reader-header h2 {
  font-size: 25px;
}

.reader-dashboard-title h3 {
  font-size: 22px;
}

.reader-header p,
.reader-dashboard-title p,
.reader-help {
  margin: 5px 0 0;
  color: #667085;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.45;
}

.reader-login-box {
  border: 1px solid #e4e7ec;
  border-radius: 20px;
  background: #f9fafb;
  padding: 16px;
  margin-bottom: 14px;
}

.reader-login-box label {
  display: block;
  margin-bottom: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 900;
}

.reader-login-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.reader-login-row input {
  min-height: 42px;
  border: 1px solid #d0d5dd;
  border-radius: 13px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 600;
  outline: none;
}

.reader-login-row input:focus {
  border-color: #1570ef;
  box-shadow: 0 0 0 4px rgba(21, 112, 239, 0.12);
}

.reader-message {
  border-radius: 16px;
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid #e4e7ec;
  background: #ffffff;
}

.reader-message strong {
  color: #101828;
  font-size: 14px;
}

.reader-message span {
  color: #667085;
  font-size: 13px;
}

.reader-message.error {
  border-color: #fecdca;
  background: #fef3f2;
}

.reader-message.error strong {
  color: #b42318;
}

.reader-message.warning {
  border-color: #fedf89;
  background: #fffaeb;
}

.reader-message.warning strong {
  color: #b54708;
}

.reader-kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.reader-kpi {
  position: relative;
  overflow: hidden;
  border: 1px solid #e4e7ec;
  border-radius: 18px;
  background: #ffffff;
  padding: 14px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.05);
}

.reader-kpi::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: #1570ef;
}

.reader-kpi.danger::before {
  background: #d92d20;
}

.reader-kpi.purple::before {
  background: #7a5af8;
}

.reader-kpi.info::before {
  background: #1570ef;
}

.reader-kpi.success::before {
  background: #079455;
}

.reader-kpi.fuchsia::before {
  background: #d946ef;
}

.reader-kpi span {
  display: block;
  color: #101828;
  font-size: 26px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.reader-kpi small {
  display: block;
  margin-top: 8px;
  color: #667085;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.reader-progress-card {
  border: 1px solid #dbeafe;
  border-radius: 22px;
  background: linear-gradient(135deg, #eff8ff, #ffffff);
  padding: 16px;
  margin-bottom: 14px;
}

.reader-progress-card strong {
  display: block;
  color: #175cd3;
  font-size: 40px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.06em;
}

.reader-progress-card span {
  display: block;
  margin-top: 5px;
  color: #475467;
  font-size: 13px;
  font-weight: 800;
}

.reader-progress-bar {
  height: 13px;
  border-radius: 999px;
  background: #e4e7ec;
  overflow: hidden;
  margin-top: 13px;
}

.reader-progress-bar i,
.reader-bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1570ef, #d946ef);
}

.reader-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.reader-card {
  border: 1px solid #e4e7ec;
  border-radius: 22px;
  background: #ffffff;
  padding: 16px;
}

.reader-card-wide {
  grid-column: 1 / -1;
}

.reader-card h4 {
  margin: 0 0 14px;
  color: #101828;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.reader-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reader-bar-row {
  display: grid;
  gap: 5px;
}

.reader-bar-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.reader-bar-label span {
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.reader-bar-label strong {
  color: #101828;
  font-size: 13px;
  font-weight: 900;
}

.reader-bar-track {
  height: 11px;
  border-radius: 999px;
  background: #e4e7ec;
  overflow: hidden;
}

.reader-bar-row small {
  color: #667085;
  font-size: 11px;
  font-weight: 800;
}

@media (max-width: 980px) {
  .reader-kpi-grid,
  .reader-grid,
  .reader-login-row {
    grid-template-columns: 1fr;
  }
}


/* =========================================================
   UI FINAL - Topbar compatta e KPI definitivi
   ========================================================= */

/* ---------- Topbar ---------- */

.topbar {
  position: relative !important;
  z-index: 10 !important;
  display: grid !important;
  grid-template-columns: auto 1fr auto !important;
  align-items: center !important;
  gap: 14px !important;
  margin: 12px 14px 10px !important;
  padding: 12px 18px !important;
  border-radius: 22px !important;
  min-height: 0 !important;
  height: auto !important;
  overflow: visible !important;
}

.brand-block {
  display: flex !important;
  align-items: center !important;
  gap: 12px !important;
  max-width: 280px !important;
  margin: 0 !important;
}

.brand-mark {
  width: 44px !important;
  height: 44px !important;
  flex: 0 0 44px !important;
  border-radius: 14px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: linear-gradient(145deg, #1570ef, #7a5af8) !important;
  color: #ffffff !important;
  font-size: 26px !important;
  line-height: 1 !important;
  box-shadow: 0 8px 18px rgba(21, 112, 239, 0.18) !important;
}

.brand-copy {
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  min-width: 0 !important;
}

.brand-copy h1 {
  margin: 0 !important;
  font-size: 18px !important;
  line-height: 1.05 !important;
  font-weight: 900 !important;
  color: #101828 !important;
  letter-spacing: -0.035em !important;
  white-space: nowrap !important;
}

.brand-copy p {
  margin: 4px 0 0 !important;
  font-size: 12px !important;
  line-height: 1.1 !important;
  font-weight: 700 !important;
  color: #667085 !important;
  white-space: nowrap !important;
}

.topbar-middle {
  display: flex !important;
  justify-content: center !important;
  min-width: 0 !important;
}

.auth-box {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-wrap: nowrap !important;
  gap: 8px !important;
  width: auto !important;
  max-width: none !important;
  padding: 3px !important;
  margin: 0 !important;
  border-radius: 15px !important;
}

.auth-box input {
  width: 155px !important;
  min-width: 120px !important;
  height: 38px !important;
  padding: 0 12px !important;
  border-radius: 12px !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  margin: 0 !important;
}

#authStatus {
  height: 38px !important;
  min-height: 38px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 8px !important;
  font-size: 13px !important;
  font-weight: 800 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  margin: 0 !important;
}

.topbar-actions {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  flex-wrap: nowrap !important;
  gap: 8px !important;
  margin: 0 !important;
}

.topbar .btn,
.auth-box .btn,
.topbar-actions .btn,
#loginBtn,
#logoutBtn,
#readerAccessBtn,
#refreshBtn,
#analyticsBtn,
#exportBtn {
  height: 38px !important;
  min-height: 38px !important;
  padding: 0 13px !important;
  border-radius: 13px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 7px !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  margin: 0 !important;
}

#loginBtn,
#logoutBtn {
  min-width: 86px !important;
}

#readerAccessBtn {
  min-width: 138px !important;
}

#refreshBtn,
#analyticsBtn {
  min-width: 106px !important;
}

#exportBtn {
  min-width: 120px !important;
}

.status-pill {
  height: 38px !important;
  min-height: 38px !important;
  padding: 0 13px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  white-space: nowrap !important;
  line-height: 1.1 !important;
  margin: 0 !important;
}

.topbar svg,
.auth-box svg,
.topbar-actions svg,
.topbar i,
.auth-box i,
.topbar-actions i {
  width: 16px !important;
  height: 16px !important;
  flex: 0 0 auto !important;
}

/* ---------- KPI ---------- */

.kpi-bar {
  margin: 0 14px 12px !important;
  display: grid !important;
  grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
  gap: 12px !important;
  align-items: stretch !important;
  position: relative !important;
  z-index: 1 !important;
}

.kpi-card {
  position: relative !important;
  min-height: 84px !important;
  height: 84px !important;
  display: block !important;
  padding: 14px 72px 12px 18px !important;
  border-radius: 18px !important;
  overflow: hidden !important;
}

/* Barra laterale colorata */
.kpi-card::before {
  content: "" !important;
  position: absolute !important;
  left: 0 !important;
  top: 10px !important;
  bottom: 10px !important;
  width: 5px !important;
  border-radius: 0 999px 999px 0 !important;
  background: #1570ef !important;
  opacity: 1 !important;
  z-index: 2 !important;
}

/* Cerchio decorativo in alto a destra */
.kpi-card::after {
  content: "" !important;
  position: absolute !important;
  right: -20px !important;
  top: -22px !important;
  width: 90px !important;
  height: 90px !important;
  border-radius: 999px !important;
  background: rgba(21, 112, 239, 0.08) !important;
  z-index: 1 !important;
}

/* Icona nel cerchio */
.kpi-card .kpi-icon {
  position: absolute !important;
  right: 18px !important;
  top: 16px !important;
  z-index: 3 !important;
  width: 36px !important;
  height: 36px !important;
  border-radius: 999px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: rgba(21, 112, 239, 0.10) !important;
  color: #1570ef !important;
  box-shadow: none !important;
}

.kpi-card .kpi-icon svg {
  width: 19px !important;
  height: 19px !important;
  stroke-width: 2.8 !important;
}

/* Numero sopra descrizione */
.kpi-card .kpi-copy {
  position: relative !important;
  z-index: 4 !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  justify-content: flex-start !important;
  height: 100% !important;
  width: 100% !important;
  padding-top: 2px !important;
  min-width: 0 !important;
}

.kpi-card .kpi-copy span {
  display: block !important;
  width: 100% !important;
  margin: 0 !important;
  color: #101828 !important;
  font-size: 29px !important;
  line-height: 1 !important;
  font-weight: 900 !important;
  letter-spacing: -0.045em !important;
  text-align: left !important;
}

.kpi-card .kpi-copy small {
  display: block !important;
  width: 100% !important;
  margin: 12px 0 0 !important;
  color: #667085 !important;
  font-size: 11px !important;
  line-height: 1.1 !important;
  font-weight: 900 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.04em !important;
  text-align: left !important;
  white-space: nowrap !important;
}

/* Colori stato KPI */

.kpi-card.danger::before {
  background: #d92d20 !important;
}

.kpi-card.danger::after {
  background: rgba(217, 45, 32, 0.09) !important;
}

.kpi-card.danger .kpi-icon {
  background: #fef3f2 !important;
  color: #d92d20 !important;
}

.kpi-card.warning::before {
  background: #d946ef !important;
}

.kpi-card.warning::after {
  background: rgba(217, 70, 239, 0.10) !important;
}

.kpi-card.warning .kpi-icon {
  background: #fdf4ff !important;
  color: #d946ef !important;
}

.kpi-card.info::before {
  background: #7a5af8 !important;
}

.kpi-card.info::after {
  background: rgba(122, 90, 248, 0.10) !important;
}

.kpi-card.info .kpi-icon {
  background: #f4f3ff !important;
  color: #7a5af8 !important;
}

.kpi-card.success::before {
  background: #079455 !important;
}

.kpi-card.success::after {
  background: rgba(7, 148, 85, 0.10) !important;
}

.kpi-card.success .kpi-icon {
  background: #ecfdf3 !important;
  color: #079455 !important;
}

.kpi-card.purple::before {
  background: #d946ef !important;
}

.kpi-card.purple::after {
  background: rgba(217, 70, 239, 0.10) !important;
}

.kpi-card.purple .kpi-icon {
  background: #fdf4ff !important;
  color: #d946ef !important;
}

/* Responsive */

@media (max-width: 1450px) {
  .topbar {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .brand-block,
  .topbar-middle,
  .topbar-actions {
    justify-content: center !important;
  }

  .topbar-actions,
  .auth-box {
    flex-wrap: wrap !important;
  }
}

@media (max-width: 1280px) {
  .kpi-bar {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 760px) {
  .brand-copy h1,
  .brand-copy p {
    white-space: normal !important;
  }

  .auth-box input {
    width: 100% !important;
    max-width: 220px !important;
  }

  .kpi-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .kpi-card {
    padding-right: 58px !important;
  }

  .kpi-card .kpi-copy small {
    white-space: normal !important;
  }
}


/* =========================================================
   UI-3F - Topbar su una sola riga desktop
   ========================================================= */

.topbar {
  display: grid !important;
  grid-template-columns: auto minmax(560px, 1fr) auto !important;
  align-items: center !important;
  gap: 14px !important;
  min-height: 76px !important;
  padding: 12px 18px !important;
}

.brand-block {
  justify-content: flex-start !important;
}

.topbar-middle {
  justify-content: center !important;
}

.auth-box {
  flex-wrap: nowrap !important;
}

.topbar-actions {
  justify-content: flex-end !important;
  flex-wrap: nowrap !important;
}

/* Riduce leggermente gli elementi per farli stare in una riga */
.auth-box input {
  width: 140px !important;
}

#readerAccessBtn {
  min-width: 132px !important;
}

#refreshBtn,
#analyticsBtn {
  min-width: 102px !important;
}

#exportBtn {
  min-width: 112px !important;
}

.topbar .btn,
.auth-box .btn,
.topbar-actions .btn,
#loginBtn,
#logoutBtn,
#readerAccessBtn,
#refreshBtn,
#analyticsBtn,
#exportBtn,
.status-pill {
  height: 36px !important;
  min-height: 36px !important;
  padding-left: 12px !important;
  padding-right: 12px !important;
}

/* Mantiene il fallback a più righe solo quando lo spazio è davvero insufficiente */
@media (max-width: 1500px) {
  .topbar {
    grid-template-columns: 1fr !important;
    min-height: 0 !important;
  }

  .brand-block,
  .topbar-middle,
  .topbar-actions {
    justify-content: center !important;
  }

  .auth-box,
  .topbar-actions {
    flex-wrap: wrap !important;
  }
}


/* =========================================================
   UI-3G - Brand a sinistra e topbar orizzontale
   ========================================================= */

.topbar {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  flex-wrap: nowrap !important;
  gap: 18px !important;
  min-height: 82px !important;
  padding: 14px 18px !important;
}

.brand-block {
  flex: 0 0 auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 12px !important;
  margin: 0 !important;
  min-width: 260px !important;
  max-width: 260px !important;
}

.brand-copy {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-start !important;
  justify-content: center !important;
  text-align: left !important;
}

.brand-copy h1 {
  text-align: left !important;
  margin: 0 !important;
}

.brand-copy p {
  text-align: left !important;
  margin: 4px 0 0 !important;
}

.topbar-middle {
  flex: 1 1 auto !important;
  display: flex !important;
  justify-content: center !important;
  min-width: 0 !important;
}

.auth-box {
  flex-wrap: nowrap !important;
  justify-content: center !important;
}

.topbar-actions {
  flex: 0 0 auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  flex-wrap: nowrap !important;
  gap: 8px !important;
}

/* Compatta leggermente per stare in una sola riga */
.auth-box input {
  width: 132px !important;
}

#authStatus {
  font-size: 12px !important;
  padding: 0 8px !important;
}

#readerAccessBtn {
  min-width: 128px !important;
}

#refreshBtn,
#analyticsBtn {
  min-width: 98px !important;
}

#exportBtn {
  min-width: 110px !important;
}

/* Se lo schermo è più stretto, torna a righe multiple in modo controllato */
@media (max-width: 1550px) {
  .topbar {
    flex-wrap: wrap !important;
    justify-content: center !important;
  }

  .brand-block {
    min-width: auto !important;
    max-width: none !important;
    width: 100% !important;
    justify-content: center !important;
  }

  .brand-copy {
    align-items: center !important;
    text-align: center !important;
  }

  .brand-copy h1,
  .brand-copy p {
    text-align: center !important;
  }

  .topbar-middle,
  .topbar-actions {
    width: 100% !important;
    justify-content: center !important;
  }

  .auth-box,
  .topbar-actions {
    flex-wrap: wrap !important;
  }
}


/* =========================================================
   UI-3H - Brand allineato a sinistra
   ========================================================= */

.topbar {
  align-items: flex-start !important;
}

/* Il brand resta sempre a sinistra, anche quando la topbar va su più righe */
.brand-block {
  align-self: flex-start !important;
  justify-content: flex-start !important;
  margin-left: 34px !important;
  margin-right: auto !important;
}

.brand-copy {
  align-items: flex-start !important;
  text-align: left !important;
}

.brand-copy h1 {
  text-align: left !important;
  font-size: 19px !important;
  letter-spacing: -0.025em !important;
}

.brand-copy p {
  text-align: left !important;
  font-size: 12px !important;
  letter-spacing: 0 !important;
}

/* Sovrascrive il centraggio introdotto nei breakpoint precedenti */
@media (max-width: 1550px) {
  .brand-block {
    width: auto !important;
    min-width: 260px !important;
    max-width: 320px !important;
    justify-content: flex-start !important;
    margin-left: 34px !important;
    margin-right: auto !important;
  }

  .brand-copy {
    align-items: flex-start !important;
    text-align: left !important;
  }

  .brand-copy h1,
  .brand-copy p {
    text-align: left !important;
  }
}

@media (max-width: 760px) {
  .brand-block {
    margin-left: 0 !important;
    justify-content: center !important;
  }

  .brand-copy {
    align-items: flex-start !important;
  }
}


/* =========================================================
   UI-3I - Brand centrato con parametri attuali
   ========================================================= */

.topbar {
  align-items: center !important;
}

.brand-block {
  align-self: center !important;
  justify-content: center !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

.brand-copy {
  align-items: flex-start !important;
  text-align: left !important;
}

.brand-copy h1,
.brand-copy p {
  text-align: left !important;
}

/* Mantiene il brand centrato anche nei breakpoint precedenti */
@media (max-width: 1550px) {
  .brand-block {
    width: auto !important;
    min-width: 260px !important;
    max-width: 320px !important;
    justify-content: center !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .brand-copy {
    align-items: flex-start !important;
    text-align: left !important;
  }

  .brand-copy h1,
  .brand-copy p {
    text-align: left !important;
  }
}

@media (max-width: 760px) {
  .brand-block {
    margin-left: auto !important;
    margin-right: auto !important;
    justify-content: center !important;
  }
}


/* =========================================================
   UI-48A - Topbar compatta per recuperare spazio mappa
   ========================================================= */

/* Desktop: una sola riga compatta */
@media (min-width: 1201px) {
  .topbar {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    gap: 12px !important;
    min-height: 62px !important;
    margin: 10px 14px 8px !important;
    padding: 9px 14px !important;
    border-radius: 20px !important;
  }

  .brand-block {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 230px !important;
    max-width: 250px !important;
    justify-content: flex-start !important;
    margin: 0 !important;
    gap: 10px !important;
  }

  .brand-mark {
    width: 38px !important;
    height: 38px !important;
    flex: 0 0 38px !important;
    border-radius: 12px !important;
    font-size: 23px !important;
  }

  .brand-copy h1 {
    font-size: 17px !important;
    line-height: 1.05 !important;
    white-space: nowrap !important;
  }

  .brand-copy p {
    margin-top: 3px !important;
    font-size: 11px !important;
    line-height: 1.05 !important;
    white-space: nowrap !important;
  }

  .topbar-middle {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    display: flex !important;
    justify-content: center !important;
    width: auto !important;
  }

  .auth-box {
    flex-wrap: nowrap !important;
    gap: 6px !important;
    padding: 3px !important;
    width: auto !important;
    max-width: none !important;
  }

  .auth-box input {
    width: 118px !important;
    min-width: 105px !important;
    height: 34px !important;
    padding: 0 10px !important;
    font-size: 12px !important;
    border-radius: 11px !important;
  }

  /* Nasconde “Non autenticato” per recuperare spazio.
     Quando l’utente è loggato, resta visibile grazie alla classe auth-ok. */
  #authStatus.muted:not(.auth-ok) {
    display: none !important;
  }

  #authStatus {
    height: 34px !important;
    min-height: 34px !important;
    max-width: 250px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    padding: 0 8px !important;
    font-size: 12px !important;
  }

  .topbar-actions {
    flex: 0 0 auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    width: auto !important;
  }

  .topbar .btn,
  .auth-box .btn,
  .topbar-actions .btn,
  #loginBtn,
  #logoutBtn,
  #readerAccessBtn,
  #refreshBtn,
  #analyticsBtn,
  #exportBtn {
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 10px !important;
    border-radius: 11px !important;
    gap: 6px !important;
    font-size: 12px !important;
    line-height: 1 !important;
  }

  #loginBtn,
  #logoutBtn {
    min-width: 76px !important;
  }

  #readerAccessBtn {
    min-width: 118px !important;
  }

  #refreshBtn,
  #analyticsBtn {
    min-width: 92px !important;
  }

  #exportBtn {
    min-width: 104px !important;
  }

  .status-pill {
    height: 34px !important;
    min-height: 34px !important;
    padding: 0 10px !important;
    font-size: 12px !important;
  }

  .topbar svg,
  .auth-box svg,
  .topbar-actions svg,
  .topbar i,
  .auth-box i,
  .topbar-actions i {
    width: 15px !important;
    height: 15px !important;
  }

  .kpi-bar {
    margin-top: 0 !important;
  }
}

/* Tablet/schermi più stretti: righe ordinate ma più compatte */
@media (max-width: 1200px) {
  .topbar {
    margin: 10px 14px 8px !important;
    padding: 10px 14px !important;
    gap: 9px !important;
  }

  .brand-block {
    justify-content: center !important;
  }

  .auth-box,
  .topbar-actions {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .topbar .btn,
  .auth-box .btn,
  .topbar-actions .btn,
  .status-pill {
    height: 34px !important;
    min-height: 34px !important;
  }
}


/* =========================================================
   UI-50G - KPI label senza evidenziazioni indesiderate
   ========================================================= */

.kpi-card .kpi-copy small {
  background: transparent !important;
  box-shadow: none !important;
}

.kpi-card.success .kpi-copy small {
  background: transparent !important;
  color: #667085 !important;
}


/* =========================================================
   UI-53 - Punto di partenza percorso
   ========================================================= */

.route-start {
  border: 1px solid #bfdbfe;
  background: linear-gradient(135deg, #eff6ff, #ffffff);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.route-start strong {
  color: #175cd3;
  font-size: 13px;
  font-weight: 900;
}

.route-start span {
  display: block;
  margin-top: 3px;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.route-empty {
  color: #667085;
  font-size: 13px;
  font-weight: 700;
}


/* =========================================================
   UI-54D - Storico modifiche dettaglio attività
   ========================================================= */

.history-panel {
  margin-top: 16px;
  border: 1px solid #e4e7ec;
  border-radius: 18px;
  background: #ffffff;
  padding: 14px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.history-header h3 {
  margin: 0;
  color: #101828;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.history-header span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #667085;
  font-size: 11px;
  font-weight: 900;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.history-list.muted {
  color: #667085;
  font-size: 13px;
  font-weight: 700;
}

.history-item {
  border: 1px solid #e4e7ec;
  border-radius: 14px;
  background: #f9fafb;
  padding: 10px;
}

.history-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-item-top strong {
  color: #101828;
  font-size: 12px;
  font-weight: 900;
}

.history-item-top span {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #eff8ff;
  color: #175cd3;
  padding: 4px 7px;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-user {
  margin-top: 5px;
  color: #667085;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  word-break: break-word;
}

.history-item ul {
  margin: 8px 0 0;
  padding-left: 17px;
  color: #344054;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 700;
}

.history-item li + li {
  margin-top: 3px;
}


/* =========================================================
   UI-55H - Pulsante Le mie attività
   ========================================================= */

.filter-action-btn {
  margin-top: 8px;
  margin-bottom: 8px;
  width: 100%;
  min-height: 38px;
  font-weight: 900;
}


/* =========================================================
   UI-56C - Azioni rapide assegnazione
   ========================================================= */

.filter-actions-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 8px 0 10px;
}

.filter-actions-grid .filter-action-btn {
  margin: 0;
}

@media (min-width: 1380px) {
  .filter-actions-grid {
    grid-template-columns: 1fr 1fr;
  }

  .filter-actions-grid .btn {
    padding-left: 8px;
    padding-right: 8px;
    font-size: 12px;
  }
}


/* =========================================================
   UI-57A - Avanzamento per accertatore
   ========================================================= */

.analytics-card-wide {
  grid-column: 1 / -1;
}

.assignee-progress-item {
  border: 1px solid #e4e7ec;
  border-radius: 16px;
  background: #f9fafb;
  padding: 12px;
}

.assignee-progress-item + .assignee-progress-item {
  margin-top: 10px;
}

.assignee-progress-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.assignee-progress-top strong {
  display: block;
  color: #101828;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.assignee-progress-top span {
  display: block;
  margin-top: 4px;
  color: #667085;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.assignee-progress-top b {
  flex: 0 0 auto;
  color: #175cd3;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.assignee-progress-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.assignee-progress-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #e4e7ec;
  color: #475467;
  font-size: 11px;
  font-weight: 900;
}


/* =========================================================
   UI-57A - Avanzamento per accertatore
   ========================================================= */

.analytics-card-wide {
  grid-column: 1 / -1;
}

.assignee-progress-item {
  border: 1px solid #e4e7ec;
  border-radius: 16px;
  background: #f9fafb;
  padding: 12px;
}

.assignee-progress-item + .assignee-progress-item {
  margin-top: 10px;
}

.assignee-progress-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.assignee-progress-top strong {
  display: block;
  color: #101828;
  font-size: 14px;
  font-weight: 900;
}

.assignee-progress-top span {
  display: block;
  margin-top: 4px;
  color: #667085;
  font-size: 12px;
  font-weight: 700;
}

.assignee-progress-top b {
  flex: 0 0 auto;
  color: #175cd3;
  font-size: 18px;
  font-weight: 900;
}

.assignee-progress-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.assignee-progress-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid #e4e7ec;
  color: #475467;
  font-size: 11px;
  font-weight: 900;
}


/* =========================================================
   UI-59 - Mappa fullscreen
   ========================================================= */

.map-wrap {
  position: relative;
}

.map-fullscreen-btn,
.map-fullscreen-close-btn {
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 900;
  min-height: 38px;
  border: 1px solid rgba(208, 213, 221, 0.92);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  color: #344054;
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.14);
  backdrop-filter: blur(8px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.map-fullscreen-btn:hover,
.map-fullscreen-close-btn:hover {
  background: #ffffff;
  border-color: #b2ddff;
  color: #175cd3;
}

.map-fullscreen-btn svg,
.map-fullscreen-close-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.7;
}

.map-fullscreen-close-btn {
  display: none;
}

/* Stato fullscreen */

body.map-fullscreen-active {
  overflow: hidden;
}

body.map-fullscreen-active .topbar,
body.map-fullscreen-active .kpi-bar,
body.map-fullscreen-active .sidebar.left-panel,
body.map-fullscreen-active .sidebar.right-panel {
  display: none !important;
}

body.map-fullscreen-active .app-layout,
body.map-fullscreen-active main,
body.map-fullscreen-active .main-layout {
  display: block !important;
  height: 100vh !important;
  min-height: 100vh !important;
  padding: 0 !important;
  margin: 0 !important;
}

body.map-fullscreen-active .map-wrap {
  position: fixed !important;
  inset: 10px !important;
  z-index: 5000 !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  border-radius: 24px !important;
  overflow: hidden !important;
  background: #ffffff !important;
  box-shadow: 0 30px 90px rgba(16, 24, 40, 0.34) !important;
}

body.map-fullscreen-active #map {
  width: 100% !important;
  height: 100% !important;
  min-height: calc(100vh - 20px) !important;
}

body.map-fullscreen-active .map-fullscreen-btn {
  display: none !important;
}

body.map-fullscreen-active .map-fullscreen-close-btn {
  display: inline-flex !important;
  z-index: 5100 !important;
}

/* Migliore leggibilità controlli Leaflet in fullscreen */
body.map-fullscreen-active .leaflet-control-container {
  z-index: 5050;
}

@media (max-width: 760px) {
  .map-fullscreen-btn span,
  .map-fullscreen-close-btn span {
    display: none;
  }

  .map-fullscreen-btn,
  .map-fullscreen-close-btn {
    width: 40px;
    padding: 0;
  }

  body.map-fullscreen-active .map-wrap {
    inset: 6px !important;
    border-radius: 18px !important;
  }

  body.map-fullscreen-active #map {
    min-height: calc(100vh - 12px) !important;
  }
}


/* =========================================================
   UI-60A - Qualità dati
   ========================================================= */

.quality-panel {
  max-height: 86vh;
  overflow-y: auto;
}

.quality-kpi-grid {
  margin-bottom: 18px;
}

.quality-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.quality-card {
  border: 1px solid #e4e7ec;
  border-radius: 18px;
  background: #ffffff;
  padding: 14px;
}

.quality-card.has-issues {
  border-color: #fedf89;
  background: linear-gradient(180deg, #fffcf5, #ffffff);
}

.quality-card.is-clean {
  border-color: #abefc6;
  background: linear-gradient(180deg, #f6fef9, #ffffff);
}

.quality-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.quality-card-head h3 {
  margin: 0;
  color: #101828;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.quality-card-head p {
  margin: 5px 0 0;
  color: #667085;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 700;
}

.quality-card-head span {
  flex: 0 0 auto;
  min-width: 36px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #101828;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
}

.quality-card.has-issues .quality-card-head span {
  background: #fff7ed;
  color: #c2410c;
}

.quality-card.is-clean .quality-card-head span {
  background: #ecfdf3;
  color: #067647;
}

.quality-severity {
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #475467;
  font-size: 11px;
  font-weight: 900;
}

.quality-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 12px;
}

.quality-item {
  width: 100%;
  border: 1px solid #e4e7ec;
  background: #ffffff;
  border-radius: 13px;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
}

.quality-item:hover {
  border-color: #b2ddff;
  background: #f5fbff;
}

.quality-item strong {
  display: block;
  color: #101828;
  font-size: 12px;
  font-weight: 900;
}

.quality-item span {
  display: block;
  margin-top: 3px;
  color: #667085;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
}

.quality-empty {
  margin-top: 12px;
  color: #067647;
  font-size: 12px;
  font-weight: 900;
}

.quality-more {
  color: #667085;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 2px;
}

@media (max-width: 980px) {
  .quality-grid {
    grid-template-columns: 1fr;
  }
}


/* =========================================================
   FIX TOPBAR - Accesso lettore compatto / Online realtime
   ========================================================= */

.topbar-actions {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 8px !important;
  flex-wrap: nowrap !important;
  min-width: 0 !important;
}

.auth-box {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-wrap: nowrap !important;
  min-width: 0 !important;
}

.reader-btn {
  flex: 0 0 auto !important;
  white-space: nowrap !important;
  min-width: auto !important;
  transition: all 0.18s ease !important;
}

.reader-btn .reader-btn-label {
  white-space: nowrap !important;
}

/* Quando l'utente è autenticato il pulsante diventa più corto */
body.is-authenticated .reader-btn {
  min-width: 92px !important;
  padding-left: 10px !important;
  padding-right: 10px !important;
}

body.is-authenticated .reader-btn .reader-btn-label {
  font-size: 12px !important;
}

/* Se lo spazio è limitato, mantiene la topbar ordinata senza sovrapporre i pulsanti */
@media (max-width: 1500px) {
  .topbar {
    gap: 10px !important;
  }

  .auth-box {
    gap: 6px !important;
  }

  .topbar-actions {
    gap: 6px !important;
  }

  body.is-authenticated .reader-btn {
    min-width: 78px !important;
    padding-left: 9px !important;
    padding-right: 9px !important;
  }
}


/* =========================================================
   FIX TOPBAR 5 - Acc. Lett. compatto + email ruolo leggibili
   ========================================================= */

#readerAccessBtn.reader-btn,
.reader-btn {
  min-width: 86px !important;
  max-width: 92px !important;
  padding-left: 9px !important;
  padding-right: 9px !important;
  gap: 5px !important;
  white-space: nowrap !important;
  flex: 0 0 auto !important;
}

#readerAccessBtn .reader-btn-label,
.reader-btn .reader-btn-label {
  font-size: 12px !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

#readerAccessBtn svg,
.reader-btn svg {
  width: 15px !important;
  height: 15px !important;
}

/* Email + ruolo non devono essere tagliati */
#authStatus {
  flex: 0 0 auto !important;
  width: auto !important;
  max-width: none !important;
  min-width: max-content !important;
  overflow: visible !important;
  text-overflow: clip !important;
  white-space: nowrap !important;
  padding-left: 8px !important;
  padding-right: 8px !important;
}

/* Riduzione leggera dei pulsanti operativi per recuperare spazio */
#refreshBtn,
#analyticsBtn,
#qualityBtn {
  min-width: auto !important;
  padding-left: 10px !important;
  padding-right: 10px !important;
}

#exportBtn {
  min-width: auto !important;
  padding-left: 12px !important;
  padding-right: 12px !important;
}

.topbar-actions,
.auth-box {
  gap: 7px !important;
}

/* Se la larghezza non basta, meglio andare a capo ordinatamente che tagliare email/ruolo */
@media (max-width: 1420px) {
  .topbar {
    flex-wrap: wrap !important;
  }

  .brand-block {
    flex: 0 0 auto !important;
  }

  .topbar-middle,
  .topbar-actions {
    flex-wrap: wrap !important;
  }
}


/* =========================================================
   FIX TOPBAR 6 - Riga unica compatta
   ========================================================= */

.topbar {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  flex-wrap: nowrap !important;
  gap: 10px !important;
  min-height: 64px !important;
  padding: 10px 16px !important;
  overflow: hidden !important;
}

.brand-block {
  flex: 0 0 auto !important;
  min-width: 230px !important;
  max-width: 260px !important;
  margin: 0 !important;
}

.brand-mark {
  width: 38px !important;
  height: 38px !important;
  flex: 0 0 38px !important;
}

.brand-copy h1 {
  font-size: 17px !important;
  line-height: 1.05 !important;
  white-space: nowrap !important;
}

.brand-copy p {
  font-size: 11px !important;
  line-height: 1.05 !important;
  white-space: nowrap !important;
}

/* Blocco login + stato utente */
.topbar-middle {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  display: flex !important;
  justify-content: center !important;
}

.auth-box {
  display: flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: 6px !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

.auth-box input {
  width: 112px !important;
  min-width: 96px !important;
  height: 34px !important;
  padding: 0 10px !important;
  font-size: 12px !important;
}

#loginBtn,
#logoutBtn {
  min-width: 72px !important;
  height: 34px !important;
  padding: 0 10px !important;
  font-size: 12px !important;
}

#authStatus {
  flex: 1 1 auto !important;
  min-width: 180px !important;
  max-width: 310px !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  font-size: 12px !important;
  padding: 0 6px !important;
}

/* Accesso lettore compatto */
#readerAccessBtn,
#readerAccessBtn.reader-btn,
.reader-btn {
  flex: 0 0 auto !important;
  min-width: 82px !important;
  max-width: 88px !important;
  height: 34px !important;
  padding: 0 8px !important;
  gap: 5px !important;
  font-size: 12px !important;
  white-space: nowrap !important;
}

#readerAccessBtn .reader-btn-label,
.reader-btn .reader-btn-label {
  font-size: 12px !important;
  white-space: nowrap !important;
}

#readerAccessBtn svg,
.reader-btn svg {
  width: 14px !important;
  height: 14px !important;
}

/* Azioni destra sempre sulla stessa riga */
.topbar-actions {
  flex: 0 0 auto !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  flex-wrap: nowrap !important;
  gap: 6px !important;
  min-width: 0 !important;
}

.status-pill {
  height: 34px !important;
  min-height: 34px !important;
  padding: 0 10px !important;
  font-size: 12px !important;
  white-space: nowrap !important;
}

#refreshBtn,
#analyticsBtn,
#qualityBtn,
#exportBtn {
  height: 34px !important;
  min-height: 34px !important;
  min-width: auto !important;
  padding: 0 10px !important;
  gap: 5px !important;
  font-size: 12px !important;
  white-space: nowrap !important;
}

#exportBtn {
  padding-left: 12px !important;
  padding-right: 12px !important;
}

.topbar svg,
.auth-box svg,
.topbar-actions svg {
  width: 15px !important;
  height: 15px !important;
}

/* Annulla i vecchi breakpoint che mandavano la topbar a capo */
@media (max-width: 1550px),
       (max-width: 1500px),
       (max-width: 1420px),
       (max-width: 1200px) {
  .topbar {
    flex-wrap: nowrap !important;
    justify-content: space-between !important;
  }

  .brand-block {
    width: auto !important;
    min-width: 220px !important;
    max-width: 250px !important;
    justify-content: flex-start !important;
    margin: 0 !important;
  }

  .topbar-middle {
    width: auto !important;
    justify-content: center !important;
  }

  .topbar-actions {
    width: auto !important;
    flex-wrap: nowrap !important;
    justify-content: flex-end !important;
  }

  .auth-box {
    flex-wrap: nowrap !important;
  }
}

/* Sotto questa soglia è meglio accorciare etichette invece di andare a capo */
@media (max-width: 1350px) {
  #qualityBtn span {
    max-width: 54px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  #analyticsBtn span {
    max-width: 74px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  #authStatus {
    max-width: 240px !important;
  }
}


/* =========================================================
   FIX TOPBAR FINAL - Riga unica, Acc. Lett., nessuna sovrapposizione
   ========================================================= */

.topbar {
  flex-wrap: nowrap !important;
  overflow: hidden !important;
}

.auth-box {
  flex-wrap: nowrap !important;
  gap: 8px !important;
  min-width: 0 !important;
}

#authStatus {
  flex: 0 1 auto !important;
  min-width: 250px !important;
  max-width: 360px !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  padding-left: 8px !important;
  padding-right: 8px !important;
}

#readerAccessBtn,
#readerAccessBtn.reader-btn {
  flex: 0 0 84px !important;
  width: 84px !important;
  min-width: 84px !important;
  max-width: 84px !important;
  height: 34px !important;
  padding: 0 7px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
  overflow: hidden !important;
  white-space: nowrap !important;
}

#readerAccessBtn .reader-btn-label,
#readerAccessBtn.reader-btn .reader-btn-label {
  display: inline-block !important;
  max-width: 52px !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  font-size: 11px !important;
  font-weight: 900 !important;
  line-height: 1 !important;
}

#readerAccessBtn svg,
#readerAccessBtn.reader-btn svg {
  flex: 0 0 14px !important;
  width: 14px !important;
  height: 14px !important;
}

.topbar-actions {
  flex-wrap: nowrap !important;
  gap: 6px !important;
}

/* recupero spazio dai pulsanti operativi senza mandarli a capo */
#refreshBtn,
#analyticsBtn,
#qualityBtn,
#exportBtn,
.status-pill {
  height: 34px !important;
  min-height: 34px !important;
  font-size: 12px !important;
  white-space: nowrap !important;
}

#refreshBtn,
#analyticsBtn,
#qualityBtn {
  padding-left: 9px !important;
  padding-right: 9px !important;
}

#exportBtn {
  padding-left: 11px !important;
  padding-right: 11px !important;
}

@media (max-width: 1450px) {
  #authStatus {
    min-width: 220px !important;
    max-width: 310px !important;
  }

  .brand-block {
    min-width: 220px !important;
    max-width: 245px !important;
  }
}


/* =========================================================
   UI-61A - Filtro operativo qualità dati
   ========================================================= */

.quality-severity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.quality-severity-row .quality-severity {
  margin-top: 0;
}

.quality-filter-btn {
  border: 1px solid #b2ddff;
  background: #eff8ff;
  color: #175cd3;
  border-radius: 999px;
  min-height: 26px;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.quality-filter-btn:hover {
  background: #d1e9ff;
}

.quality-filter-banner {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 850;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 170px);
  border: 1px solid #b2ddff;
  border-radius: 16px;
  background: rgba(239, 248, 255, 0.95);
  box-shadow: 0 10px 25px rgba(16, 24, 40, 0.14);
  backdrop-filter: blur(8px);
  padding: 9px 10px 9px 12px;
}

.quality-filter-banner strong {
  display: block;
  color: #175cd3;
  font-size: 12px;
  font-weight: 900;
}

.quality-filter-banner span {
  display: block;
  color: #344054;
  font-size: 11px;
  font-weight: 800;
  margin-top: 2px;
}

.quality-filter-banner button {
  border: 0;
  border-radius: 999px;
  background: #ffffff;
  color: #175cd3;
  min-height: 28px;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.quality-filter-banner button:hover {
  background: #d1e9ff;
}

body.map-fullscreen-active .quality-filter-banner {
  z-index: 5150;
}


/* =========================================================
   FIX UI-61A - Banner filtro qualità centrato sulla mappa
   ========================================================= */

.quality-filter-banner {
  left: 50% !important;
  top: 16px !important;
  transform: translateX(-50%) !important;
  max-width: min(520px, calc(100% - 220px)) !important;
  min-width: 280px !important;
  justify-content: space-between !important;
  z-index: 880 !important;
}

body.map-fullscreen-active .quality-filter-banner {
  top: 18px !important;
  z-index: 5150 !important;
}

@media (max-width: 760px) {
  .quality-filter-banner {
    left: 50% !important;
    top: 12px !important;
    max-width: calc(100% - 90px) !important;
    min-width: 0 !important;
    transform: translateX(-50%) !important;
  }
}


/* =========================================================
   UI-61B - Export anomalie qualità dati
   ========================================================= */

.quality-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

#exportQualityBtn {
  gap: 6px;
}

#exportQualityBtn svg {
  width: 15px;
  height: 15px;
  stroke-width: 2.7;
}

@media (max-width: 760px) {
  .quality-header-actions {
    justify-content: flex-start;
  }

  #exportQualityBtn span {
    display: none;
  }
}


/* =========================================================
   MOBILE OPTIMIZATION - Rimini Control Hub
   ========================================================= */

@media (max-width: 900px) {

  body {
    overflow-x: hidden;
  }

  .app-shell,
  .app-container,
  main {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Topbar compatta */
  .topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 2000 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    min-height: auto !important;
    padding: 10px !important;
    border-radius: 0 0 18px 18px !important;
    overflow: visible !important;
  }

  .brand-block {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    justify-content: flex-start !important;
  }

  .brand-mark {
    width: 36px !important;
    height: 36px !important;
    flex-basis: 36px !important;
  }

  .brand-copy h1 {
    font-size: 16px !important;
  }

  .brand-copy p {
    font-size: 11px !important;
  }

  .topbar-middle {
    width: 100% !important;
    justify-content: stretch !important;
  }

  .auth-box {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 6px !important;
  }

  .auth-box input {
    width: 100% !important;
    min-width: 0 !important;
  }

  #loginBtn,
  #logoutBtn,
  #readerAccessBtn {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
  }

  #authStatus {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    text-align: center !important;
    font-size: 12px !important;
  }

  .topbar-actions {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  .topbar-actions .btn,
  .topbar-actions .status-pill {
    width: 100% !important;
    min-width: 0 !important;
    justify-content: center !important;
  }

  #exportBtn {
    grid-column: 1 / -1 !important;
  }

  /* KPI mobile: scroll orizzontale */
  .kpi-bar {
    display: flex !important;
    gap: 10px !important;
    overflow-x: auto !important;
    padding: 10px !important;
    scroll-snap-type: x mandatory;
  }

  .kpi-card {
    flex: 0 0 170px !important;
    min-height: 82px !important;
    scroll-snap-align: start;
  }

  .kpi-card span {
    font-size: 26px !important;
  }

  .kpi-card small {
    font-size: 11px !important;
  }

  /* Layout principale mobile */
  .main-layout,
  .content-grid,
  .app-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 10px !important;
  }

  /* La mappa deve venire prima */
  .map-wrap {
    order: 1 !important;
    height: calc(100vh - 250px) !important;
    min-height: 430px !important;
    border-radius: 20px !important;
  }

  #map {
    height: 100% !important;
    min-height: 430px !important;
  }

  /* Sidebar filtri e pannello destro sotto la mappa */
  .sidebar.left-panel {
    order: 2 !important;
    max-height: none !important;
  }

  .sidebar.right-panel {
    order: 3 !important;
    max-height: none !important;
  }

  .sidebar,
  .panel-card {
    border-radius: 20px !important;
  }

  /* Filtri più touch-friendly */
  .sidebar label {
    font-size: 13px !important;
  }

  .sidebar input,
  .sidebar select,
  .sidebar button,
  .btn {
    min-height: 42px !important;
    font-size: 14px !important;
  }

  .filter-actions-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Pulsante fullscreen mappa */
  .map-fullscreen-btn,
  .map-fullscreen-close-btn {
    top: 12px !important;
    right: 12px !important;
    min-height: 40px !important;
    border-radius: 14px !important;
  }

  /* Banner qualità */
  .quality-filter-banner {
    top: 12px !important;
    max-width: calc(100% - 105px) !important;
    min-width: 0 !important;
    padding: 8px 9px !important;
  }

  .quality-filter-banner strong {
    font-size: 11px !important;
  }

  .quality-filter-banner span {
    font-size: 10px !important;
  }

  /* Modali mobile */
  .analytics-panel,
  .quality-panel {
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    max-height: calc(100vh - 20px) !important;
    overflow-y: auto !important;
    border-radius: 22px !important;
    padding: 18px !important;
  }

  .analytics-kpi-grid,
  .quality-kpi-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .analytics-grid,
  .quality-grid {
    grid-template-columns: 1fr !important;
  }

  .analytics-header,
  .quality-header-actions {
    align-items: flex-start !important;
  }
}

/* Mobile stretto */
@media (max-width: 520px) {

  .topbar-actions {
    grid-template-columns: 1fr 1fr !important;
  }

  .topbar-actions .btn span,
  .topbar-actions .status-pill span {
    font-size: 12px !important;
  }

  .kpi-card {
    flex-basis: 150px !important;
  }

  .map-wrap {
    height: calc(100vh - 280px) !important;
    min-height: 390px !important;
  }

  #map {
    min-height: 390px !important;
  }

  .filter-actions-grid {
    grid-template-columns: 1fr !important;
  }

  .analytics-kpi-grid,
  .quality-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  .analytics-mini-stats {
    grid-template-columns: 1fr !important;
  }
}


/* =========================================================
   MOBILE APP MODE - pannelli e barra azioni
   ========================================================= */

.mobile-action-bar {
  display: none;
}

/* Solo mobile/tablet verticale */
@media (max-width: 900px) {

  body {
    padding-bottom: 76px !important;
  }

  /* La web app diventa una vista mappa-first */
  .main-layout,
  .content-grid,
  .app-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .map-wrap {
    order: 1 !important;
    height: calc(100vh - 250px) !important;
    min-height: 430px !important;
  }

  #map {
    height: 100% !important;
    min-height: 430px !important;
  }

  /* Filtri e pannello destro diventano pannelli nascosti */
  .sidebar.left-panel,
  .sidebar.right-panel {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    bottom: 82px !important;
    top: auto !important;
    z-index: 4200 !important;
    max-height: min(72vh, 680px) !important;
    overflow-y: auto !important;
    border-radius: 24px !important;
    box-shadow: 0 24px 80px rgba(16, 24, 40, 0.34) !important;
    transform: translateY(calc(100% + 110px)) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: transform 0.22s ease, opacity 0.22s ease !important;
  }

  body.mobile-panel-filters-open .sidebar.left-panel {
    transform: translateY(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  body.mobile-panel-detail-open .sidebar.right-panel,
  body.mobile-panel-route-open .sidebar.right-panel {
    transform: translateY(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Ombra dietro ai pannelli */
  body.mobile-panel-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 4100;
    background: rgba(16, 24, 40, 0.32);
    backdrop-filter: blur(2px);
  }

  body.mobile-panel-open .sidebar.left-panel,
  body.mobile-panel-open .sidebar.right-panel,
  body.mobile-panel-open .mobile-action-bar {
    z-index: 4300 !important;
  }

  /* Barra azioni mobile sempre presente */
  .mobile-action-bar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 4400;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    border: 1px solid rgba(208, 213, 221, 0.85);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 55px rgba(16, 24, 40, 0.24);
    backdrop-filter: blur(12px);
    padding: 8px;
  }

  .mobile-action-bar button {
    border: 0;
    border-radius: 16px;
    background: #f8fafc;
    color: #344054;
    min-height: 48px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 900;
    cursor: pointer;
  }

  .mobile-action-bar button:hover,
  .mobile-action-bar button:active {
    background: #eff8ff;
    color: #175cd3;
  }

  .mobile-action-bar svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.7;
  }

  /* Quando non c'è pannello aperto, il pulsante Chiudi è meno evidente */
  body:not(.mobile-panel-open) #mobileClosePanelsBtn {
    opacity: 0.45;
  }

  /* Topbar ancora più compatta in modalità app */
  .topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 3500 !important;
  }

  .kpi-bar {
    position: relative !important;
    z-index: 1 !important;
  }

  /* Pannelli interni più comodi al touch */
  .sidebar.left-panel select,
  .sidebar.left-panel input,
  .sidebar.left-panel button,
  .sidebar.right-panel select,
  .sidebar.right-panel input,
  .sidebar.right-panel textarea,
  .sidebar.right-panel button {
    min-height: 44px !important;
    font-size: 15px !important;
  }

  .panel-card {
    padding: 16px !important;
  }

  /* Il dettaglio non deve risultare schiacciato */
  #detailPanel {
    min-height: 160px;
  }

  /* Fullscreen mappa resta prioritario e nasconde barra azioni */
  body.map-fullscreen-active .mobile-action-bar {
    display: none !important;
  }

  body.map-fullscreen-active .sidebar.left-panel,
  body.map-fullscreen-active .sidebar.right-panel {
    display: none !important;
  }
}

/* Smartphone stretti */
@media (max-width: 520px) {

  .mobile-action-bar {
    left: 8px;
    right: 8px;
    bottom: 8px;
    border-radius: 20px;
    gap: 5px;
    padding: 7px;
  }

  .mobile-action-bar button {
    min-height: 46px;
    border-radius: 14px;
    font-size: 10px;
  }

  .mobile-action-bar svg {
    width: 17px;
    height: 17px;
  }

  .sidebar.left-panel,
  .sidebar.right-panel {
    left: 8px !important;
    right: 8px !important;
    bottom: 76px !important;
    max-height: 74vh !important;
  }

  .map-wrap {
    min-height: 410px !important;
  }

  #map {
    min-height: 410px !important;
  }
}


/* =========================================================
   MOBILE APP FIX 1 - Topbar centrata e Acc. Lett. ordinato
   ========================================================= */

@media (max-width: 900px) {

  .topbar {
    text-align: center !important;
  }

  .brand-block {
    justify-content: center !important;
    text-align: left !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }

  .brand-copy {
    text-align: left !important;
  }

  .auth-box {
    justify-items: center !important;
  }

  #readerAccessBtn,
  #readerAccessBtn.reader-btn {
    grid-column: 1 / -1 !important;
    justify-self: center !important;
    width: 150px !important;
    min-width: 150px !important;
    max-width: 150px !important;
  }

  #readerAccessBtn .reader-btn-label,
  #readerAccessBtn.reader-btn .reader-btn-label {
    max-width: none !important;
    font-size: 12px !important;
  }

  #authStatus {
    justify-self: center !important;
    text-align: center !important;
  }
}


/* =========================================================
   MOBILE APP FIX 2 - Pannelli dettaglio/percorso sopra overlay
   ========================================================= */

@media (max-width: 900px) {

  body.mobile-panel-open::after {
    z-index: 4100 !important;
  }

  body.mobile-panel-filters-open .sidebar.left-panel,
  body.mobile-panel-detail-open .sidebar.right-panel,
  body.mobile-panel-route-open .sidebar.right-panel {
    display: block !important;
    visibility: visible !important;
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    bottom: 82px !important;
    top: auto !important;
    z-index: 4600 !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    transform: translateY(0) !important;
    max-height: min(72vh, 680px) !important;
    overflow-y: auto !important;
  }

  body.mobile-panel-detail-open .sidebar.right-panel,
  body.mobile-panel-route-open .sidebar.right-panel {
    background: #ffffff !important;
  }

  body.mobile-panel-open .mobile-action-bar {
    z-index: 4700 !important;
  }

  /* evita che il pannello venga coperto da elementi interni */
  body.mobile-panel-detail-open .panel-card,
  body.mobile-panel-route-open .panel-card {
    position: relative !important;
    z-index: 1 !important;
  }
}

@media (max-width: 520px) {

  body.mobile-panel-filters-open .sidebar.left-panel,
  body.mobile-panel-detail-open .sidebar.right-panel,
  body.mobile-panel-route-open .sidebar.right-panel {
    left: 8px !important;
    right: 8px !important;
    bottom: 76px !important;
    max-height: 74vh !important;
  }
}


/* =========================================================
   TABLET / iPAD PRO OPTIMIZATION
   iPad Pro 13 verticale e orizzontale
   ========================================================= */

/* Tablet ampi: iPad Pro verticale / landscape compatto */
@media (min-width: 901px) and (max-width: 1180px) {

  body {
    overflow-x: hidden;
  }

  .topbar {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    padding: 12px !important;
    min-height: auto !important;
    overflow: visible !important;
  }

  .brand-block {
    justify-content: center !important;
    min-width: 0 !important;
    max-width: none !important;
    width: 100% !important;
  }

  .brand-copy h1 {
    font-size: 20px !important;
    white-space: nowrap !important;
  }

  .brand-copy p {
    font-size: 12px !important;
    white-space: nowrap !important;
  }

  .topbar-middle {
    width: 100% !important;
    justify-content: center !important;
  }

  .auth-box {
    display: flex !important;
    justify-content: center !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .auth-box input {
    width: 150px !important;
    min-width: 130px !important;
  }

  #authStatus {
    min-width: 260px !important;
    max-width: 380px !important;
    text-align: center !important;
  }

  #readerAccessBtn,
  #readerAccessBtn.reader-btn {
    min-width: 96px !important;
    width: 96px !important;
    max-width: 96px !important;
  }

  .topbar-actions {
    width: 100% !important;
    justify-content: center !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
  }

  .topbar-actions .btn,
  .topbar-actions .status-pill {
    height: 38px !important;
    min-height: 38px !important;
    font-size: 13px !important;
  }

  /* KPI: 3 + 3 ordinati */
  .kpi-bar {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 12px !important;
    padding: 12px !important;
    overflow: visible !important;
  }

  .kpi-card {
    min-height: 96px !important;
    flex: none !important;
  }

  .kpi-card span {
    font-size: 30px !important;
  }

  .kpi-card small {
    font-size: 12px !important;
  }

  /* Layout tablet: filtri + mappa sopra, dettaglio sotto */
  .main-layout,
  .content-grid,
  .app-layout {
    display: grid !important;
    grid-template-columns: 320px minmax(0, 1fr) !important;
    grid-template-areas:
      "filters map"
      "right right" !important;
    gap: 14px !important;
    padding: 12px !important;
  }

  .sidebar.left-panel {
    grid-area: filters !important;
    max-height: calc(100vh - 260px) !important;
    overflow-y: auto !important;
  }

  .map-wrap {
    grid-area: map !important;
    height: calc(100vh - 260px) !important;
    min-height: 560px !important;
  }

  #map {
    height: 100% !important;
    min-height: 560px !important;
  }

  .sidebar.right-panel {
    grid-area: right !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 14px !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .sidebar.right-panel .panel-card {
    min-height: 180px !important;
  }

  /* Pulsanti e select più comodi touch */
  .sidebar input,
  .sidebar select,
  .sidebar button,
  .panel-card button,
  .panel-card input,
  .panel-card select,
  .panel-card textarea {
    min-height: 42px !important;
    font-size: 14px !important;
  }

  .filter-actions-grid {
    grid-template-columns: 1fr !important;
  }

  /* Barra mobile nascosta su tablet largo */
  .mobile-action-bar {
    display: none !important;
  }
}

/* iPad Pro verticale: preferiamo modalità app con pannelli, ma più ariosa dello smartphone */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {

  body {
    padding-bottom: 82px !important;
  }

  .topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 3500 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    padding: 12px !important;
    border-radius: 0 0 22px 22px !important;
  }

  .brand-block {
    justify-content: center !important;
    width: 100% !important;
  }

  .topbar-middle,
  .topbar-actions {
    width: 100% !important;
    justify-content: center !important;
  }

  .topbar-actions {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .topbar-actions .btn,
  .topbar-actions .status-pill {
    width: 100% !important;
    justify-content: center !important;
  }

  #exportBtn {
    grid-column: auto !important;
  }

  .kpi-bar {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 12px !important;
    padding: 12px !important;
    overflow: visible !important;
  }

  .kpi-card {
    flex: none !important;
    min-height: 92px !important;
  }

  .main-layout,
  .content-grid,
  .app-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 12px !important;
  }

  .map-wrap {
    order: 1 !important;
    height: calc(100vh - 330px) !important;
    min-height: 610px !important;
    border-radius: 24px !important;
  }

  #map {
    height: 100% !important;
    min-height: 610px !important;
  }

  /* In verticale usiamo pannelli tipo app */
  .sidebar.left-panel,
  .sidebar.right-panel {
    position: fixed !important;
    left: 18px !important;
    right: 18px !important;
    bottom: 96px !important;
    top: auto !important;
    z-index: 4200 !important;
    max-height: min(70vh, 760px) !important;
    overflow-y: auto !important;
    border-radius: 28px !important;
    box-shadow: 0 24px 90px rgba(16, 24, 40, 0.34) !important;
    transform: translateY(calc(100% + 120px)) !important;
    opacity: 0 !important;
    pointer-events: none !important;
    transition: transform 0.22s ease, opacity 0.22s ease !important;
  }

  body.mobile-panel-filters-open .sidebar.left-panel,
  body.mobile-panel-detail-open .sidebar.right-panel,
  body.mobile-panel-route-open .sidebar.right-panel {
    display: block !important;
    visibility: visible !important;
    transform: translateY(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: 4600 !important;
    background: #ffffff !important;
  }

  body.mobile-panel-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 4100;
    background: rgba(16, 24, 40, 0.30);
    backdrop-filter: blur(2px);
  }

  .mobile-action-bar {
    position: fixed;
    left: 18px;
    right: 18px;
    bottom: 14px;
    z-index: 4700;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    border: 1px solid rgba(208, 213, 221, 0.85);
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 60px rgba(16, 24, 40, 0.24);
    backdrop-filter: blur(12px);
    padding: 10px;
  }

  .mobile-action-bar button {
    min-height: 54px;
    border-radius: 18px;
    font-size: 12px;
  }

  .mobile-action-bar svg {
    width: 20px;
    height: 20px;
  }

  .filter-actions-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .sidebar.left-panel select,
  .sidebar.left-panel input,
  .sidebar.left-panel button,
  .sidebar.right-panel select,
  .sidebar.right-panel input,
  .sidebar.right-panel textarea,
  .sidebar.right-panel button {
    min-height: 46px !important;
    font-size: 15px !important;
  }
}

/* iPad Pro orizzontale grande: desktop pieno ma compatto */
@media (min-width: 1181px) and (max-width: 1380px) and (orientation: landscape) {

  .topbar {
    padding: 10px 14px !important;
    gap: 8px !important;
  }

  .brand-block {
    min-width: 220px !important;
    max-width: 240px !important;
  }

  .brand-copy h1 {
    font-size: 17px !important;
  }

  .brand-copy p {
    font-size: 11px !important;
  }

  #authStatus {
    max-width: 260px !important;
    min-width: 210px !important;
  }

  .topbar-actions {
    gap: 5px !important;
  }

  #refreshBtn,
  #analyticsBtn,
  #qualityBtn,
  #exportBtn,
  .status-pill {
    padding-left: 8px !important;
    padding-right: 8px !important;
    font-size: 12px !important;
  }

  .kpi-card {
    min-height: 88px !important;
  }

  .main-layout,
  .content-grid,
  .app-layout {
    grid-template-columns: 280px minmax(0, 1fr) 330px !important;
    gap: 12px !important;
  }

  .map-wrap {
    min-height: 580px !important;
  }

  #map {
    min-height: 580px !important;
  }

  .sidebar.left-panel,
  .sidebar.right-panel {
    max-height: 580px !important;
    overflow-y: auto !important;
  }
}


/* =========================================================
   TABLET FIX - iPad Pro verticale: mappa visibile
   ========================================================= */

@media (min-width: 768px) and (max-width: 1100px) and (orientation: portrait) {

  body {
    min-height: 100vh !important;
    padding-bottom: 92px !important;
    overflow-x: hidden !important;
  }

  .main-layout,
  .content-grid,
  .app-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-areas: none !important;
    gap: 12px !important;
    padding: 12px !important;
    min-height: auto !important;
  }

  /* La mappa deve comparire subito dopo i KPI */
  .map-wrap {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    order: 1 !important;
    grid-area: auto !important;
    width: 100% !important;
    height: calc(100vh - 470px) !important;
    min-height: 520px !important;
    max-height: 720px !important;
    margin: 0 !important;
    border-radius: 24px !important;
    overflow: hidden !important;
    background: #dbeafe !important;
  }

  #map {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 520px !important;
    background: #dbeafe !important;
  }

  .leaflet-container {
    width: 100% !important;
    height: 100% !important;
    min-height: 520px !important;
  }

  /* I pannelli restano bottom sheet, non devono occupare spazio nella pagina */
  .sidebar.left-panel,
  .sidebar.right-panel {
    order: initial !important;
    grid-area: auto !important;
    position: fixed !important;
    left: 18px !important;
    right: 18px !important;
    bottom: 96px !important;
    top: auto !important;
    z-index: 4200 !important;
    max-height: min(70vh, 760px) !important;
    overflow-y: auto !important;
    transform: translateY(calc(100% + 120px)) !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  body.mobile-panel-filters-open .sidebar.left-panel,
  body.mobile-panel-detail-open .sidebar.right-panel,
  body.mobile-panel-route-open .sidebar.right-panel {
    transform: translateY(0) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    z-index: 4600 !important;
  }

  /* Barra inferiore sempre visibile su iPad verticale */
  .mobile-action-bar {
    display: grid !important;
    position: fixed !important;
    left: 18px !important;
    right: 18px !important;
    bottom: 14px !important;
    z-index: 4700 !important;
  }

  /* KPI più compatti per lasciare spazio alla mappa */
  .kpi-bar {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 10px !important;
    padding: 10px 12px !important;
    margin: 0 !important;
  }

  .kpi-card {
    min-height: 82px !important;
    height: 82px !important;
  }

  .kpi-card span {
    font-size: 25px !important;
  }

  .kpi-card small {
    font-size: 10px !important;
  }

  /* Topbar leggermente più compatta */
  .topbar {
    margin-bottom: 8px !important;
  }
}

/* iPad Pro verticale alto: mappa ancora più ampia */
@media (min-width: 900px) and (max-width: 1100px) and (min-height: 1200px) and (orientation: portrait) {
  .map-wrap {
    height: calc(100vh - 440px) !important;
    min-height: 620px !important;
  }

  #map,
  .leaflet-container {
    min-height: 620px !important;
  }
}


/* =========================================================
   TABLET FIX 2 - iPad verticale: mappa full width sotto KPI
   ========================================================= */

@media (min-width: 768px) and (max-width: 1100px) and (orientation: portrait) {

  /* forza il contenitore principale a una sola colonna reale */
  .main-layout,
  .content-grid,
  .app-layout,
  main {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    gap: 12px !important;
  }

  /* KPI prima della mappa */
  .kpi-bar {
    order: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* mappa full width */
  .map-wrap,
  section.map-wrap,
  #mapWrap {
    order: 1 !important;
    display: block !important;
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: 0 0 auto !important;
    align-self: stretch !important;
    height: calc(100vh - 430px) !important;
    min-height: 640px !important;
    max-height: 760px !important;
    margin: 0 !important;
    border-radius: 24px !important;
    overflow: hidden !important;
  }

  #map,
  .map-wrap #map,
  #mapWrap #map {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 100% !important;
    height: 100% !important;
    min-height: 640px !important;
  }

  .leaflet-container {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 100% !important;
    height: 100% !important;
    min-height: 640px !important;
  }

  /* filtri e dettaglio non devono riservare colonne/spazio nel layout */
  .sidebar.left-panel,
  .sidebar.right-panel {
    flex: none !important;
    width: auto !important;
    max-width: none !important;
  }

  /* quando sono chiusi devono uscire dal flusso */
  body:not(.mobile-panel-filters-open) .sidebar.left-panel,
  body:not(.mobile-panel-detail-open):not(.mobile-panel-route-open) .sidebar.right-panel {
    position: fixed !important;
  }
}


/* =========================================================
   TABLET FIX 3 - iPad verticale: mappa più alta
   ========================================================= */

@media (min-width: 768px) and (max-width: 1100px) and (orientation: portrait) {

  .map-wrap,
  section.map-wrap,
  #mapWrap {
    height: calc(100vh - 390px) !important;
    min-height: 720px !important;
    max-height: 860px !important;
  }

  #map,
  .map-wrap #map,
  #mapWrap #map,
  .leaflet-container {
    min-height: 720px !important;
  }

  .mobile-action-bar {
    bottom: 12px !important;
  }
}

/* iPad Pro 13 verticale specifico */
@media (min-width: 1000px) and (max-width: 1100px) and (min-height: 1300px) and (orientation: portrait) {

  .map-wrap,
  section.map-wrap,
  #mapWrap {
    height: calc(100vh - 370px) !important;
    min-height: 780px !important;
    max-height: 920px !important;
  }

  #map,
  .map-wrap #map,
  #mapWrap #map,
  .leaflet-container {
    min-height: 780px !important;
  }
}

