:root {
  color-scheme: dark;
  --page: #08131b;
  --surface: #13212c;
  --surface-2: #182a37;
  --line: #315063;
  --text: #f5fbff;
  --muted: #b8cbd7;
  --green: #4de0a2;
  --blue: #6bbcf2;
  --amber: #ffd166;
  --red: #ff596f;
  --violet: #b491ff;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  overflow: hidden;
}

button, input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1b25;
  color: var(--text);
  min-height: 40px;
  padding: 0 12px;
  font-weight: 900;
  cursor: pointer;
}

button:hover {
  border-color: var(--green);
}

.topbar {
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #0d1a24;
}

.eyebrow {
  display: inline-flex;
  color: var(--green);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 950;
  letter-spacing: .08em;
}

h1 {
  margin: 2px 0 0;
  font-size: 26px;
  line-height: 1;
}

.runtime {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(77, 224, 162, .12);
}

.dot.warn { background: var(--amber); box-shadow: 0 0 0 5px rgba(255, 209, 102, .12); }
.dot.off { background: var(--red); box-shadow: 0 0 0 5px rgba(255, 89, 111, .12); }

.shell {
  height: calc(100vh - 74px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
}

.map-panel {
  position: relative;
  min-width: 0;
}

#map {
  height: 100%;
  width: 100%;
  background: #0b151d;
}

.side-panel {
  border-left: 1px solid var(--line);
  background: #0c1720;
  padding: 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-card, .teams-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.card-title {
  padding: 12px 12px 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 950;
  color: var(--muted);
}

dl { margin: 0; }
dl div, .metrics {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 10px 12px;
}

dt {
  color: var(--muted);
  font-weight: 800;
}

dd { margin: 0; overflow-wrap: anywhere; }

.metrics {
  grid-template-columns: repeat(3, 1fr);
  font-size: 12px;
}

.metrics b {
  display: block;
  font-size: 24px;
  color: var(--green);
}

.diagnostics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}

.diagnostics-grid span {
  min-width: 0;
  padding: 9px 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.diagnostics-grid span:nth-child(3n) {
  border-right: 0;
}

.diagnostics-grid b {
  display: block;
  color: var(--green);
  font-size: 18px;
  line-height: 1;
}

.diag-last {
  padding: 8px 12px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.diag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
}

.diag-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 950;
}

.diag-devices {
  display: grid;
  gap: 5px;
  padding: 0 12px 12px;
}

.diag-device {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 8px;
  font-size: 11px;
}

.diag-device strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.diag-device small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.diag-device-actions {
  display: grid;
  justify-items: end;
  gap: 4px;
}

.diag-device-actions button {
  min-height: 24px;
  padding: 0 7px;
  border-radius: 6px;
  font-size: 10px;
}

.activity-list {
  display: grid;
}

.activity-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  border-top: 1px solid var(--line);
  border-left: 4px solid var(--line);
  padding: 9px 10px 9px 8px;
  font-size: 12px;
}

.activity-row.team_position { border-left-color: var(--green); }
.activity-row.team_target { border-left-color: var(--amber); }
.activity-row.repeater_command { border-left-color: var(--blue); }

.activity-row strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.activity-row small,
.activity-row time {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.teams-list {
  display: flex;
  flex-direction: column;
}

.command-capabilities {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
}

.capability-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 950;
}

.capability-chip.on {
  color: #061018;
  border-color: transparent;
  background: var(--green);
}

.capability-chip.off {
  color: white;
  border-color: transparent;
  background: #5d6d78;
}

.team-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  min-height: 0;
  border-radius: 0;
}

.team-row strong {
  display: block;
}

.team-row small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.status-pill {
  align-self: center;
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 950;
  color: #061018;
  background: var(--green);
}

.status-pattuglia { background: var(--blue); }
.status-sul-posto { background: var(--amber); }
.status-operando { background: var(--violet); }
.status-supporto { background: var(--red); color: white; }
.status-rientro { background: #b6c7d2; }
.status-fuori-servizio, .status-offline { background: #5d6d78; color: white; }
.status-bonifica { background: #21c47b; }
.status-in-sicurezza { background: #38d2d2; }

.team-marker {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 3px solid white;
  background: var(--green);
  color: #061018;
  font-size: 20px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .36);
}

.team-marker.stale {
  opacity: .65;
}

.team-marker.offline {
  filter: grayscale(1);
  opacity: .45;
}

.team-marker.supporto {
  background: var(--red);
  color: white;
  animation: pulse 1s infinite;
}

.team-marker.appiedato::before { content: "P"; }
.team-marker.mezzo::before { content: "V"; }

.repeater-marker {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  border: 2px solid white;
  background: #53616b;
  color: white;
  font-size: 14px;
  font-weight: 950;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .34);
}

.repeater-marker.fresh { background: var(--green); color: #061018; }
.repeater-marker.tx { background: var(--red); color: white; }
.repeater-marker.rx { background: var(--amber); color: #061018; }
.repeater-marker.stale { opacity: .7; }
.repeater-marker.expired, .repeater-marker.missing { opacity: .42; filter: grayscale(1); }

.repeater-row {
  cursor: pointer;
}

.repeater-row .mini {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
}

.mini span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.mini .on {
  color: #061018;
  border-color: transparent;
  background: var(--green);
}

.mini .tx-on {
  color: white;
  border-color: transparent;
  background: var(--red);
}

.mini .rx-on {
  color: #061018;
  border-color: transparent;
  background: var(--amber);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.target-hint {
  position: absolute;
  right: 18px;
  bottom: 86px;
  z-index: 600;
  background: #0d1a24;
  border: 1px solid var(--green);
  color: var(--green);
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 950;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
}

.toast-stack {
  position: absolute;
  right: 18px;
  top: 18px;
  z-index: 700;
  width: min(360px, calc(100% - 36px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  background: #0d1a24;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
}

.toast.supporto {
  border-left-color: var(--red);
}

.toast strong { display: block; }
.toast small { display: block; color: var(--muted); margin-top: 3px; }

.leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}

.leaflet-popup-content {
  margin: 0;
}

.team-popup {
  width: 270px;
  color: #0b1520;
  padding: 10px;
}

.popup-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.popup-head strong {
  display: block;
  font-size: 18px;
}

.popup-head small {
  display: block;
  color: #52626e;
  margin-top: 2px;
}

.popup-head button {
  background: #101c26;
  color: white;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
}

.popup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}

.popup-grid button {
  min-height: 36px;
  border-color: #d6e0e6;
  color: white;
  background: #111d28;
  font-size: 12px;
}

.popup-grid button.active {
  background: var(--green);
  border-color: var(--green);
  color: #07131b;
}

.popup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.popup-actions button {
  min-height: 38px;
  background: #0f8f72;
  border-color: #0f8f72;
  color: white;
  font-size: 13px;
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .shell {
    min-height: calc(100vh - 74px);
    height: auto;
    grid-template-columns: 1fr;
  }
  .map-panel {
    height: 62vh;
  }
  .side-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: none;
  }
}
