*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body.rete-page {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--rete-bg);
  color: var(--rete-text);
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.rete-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px 16px;
  padding: 12px 16px;
  background: var(--rete-panel);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.rete-header__brand {
  justify-self: start;
  min-width: 0;
}

.rete-header__brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.rete-header__brand-link:hover h1 {
  color: var(--rete-accent);
}

.rete-header__nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  justify-self: center;
}

.rete-header__nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  color: #fff;
  background: var(--rete-primary);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.rete-header__nav-btn:hover {
  filter: brightness(1.1);
}

.rete-header__nav-btn.is-active {
  background: var(--rete-accent);
  color: #1a1a1a;
  cursor: default;
  pointer-events: none;
}

.rete-header__status {
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  font-size: 0.9rem;
}

.rete-header__status p {
  margin: 0;
}

.rete-logo {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  border-radius: 8px;
  object-fit: contain;
  background: transparent;
}

.rete-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.rete-header__sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--rete-muted);
}

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

.rete-btn {
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--rete-primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.rete-btn:hover {
  filter: brightness(1.08);
}

.rete-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(190px, 200px) 1fr;
  min-height: 0;
}

.rete-sidebar {
  background: var(--rete-panel);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  overflow: auto;
  padding: 12px;
}

.rete-map-wrap {
  min-height: 420px;
  height: calc(100vh - 88px);
}

/* Stesso comportamento TemplateNuovo: scroll pagina finché la mappa non è attivata (tap sul velo) */
@media (max-width: 1024px), (hover: none) and (pointer: coarse) {
  .tn-map-guard {
    position: relative;
    isolation: isolate;
  }
  .tn-map-guard__shield {
    position: absolute;
    inset: 0;
    z-index: 1000;
    background: transparent;
    cursor: default;
    touch-action: pan-x pan-y;
    -webkit-tap-highlight-color: transparent;
  }
  .tn-map-guard--active .tn-map-guard__shield {
    display: none;
    pointer-events: none;
  }
  .tn-map-guard:not(.tn-map-guard--active) > :not(.tn-map-guard__shield) {
    pointer-events: none !important;
  }
}

#reteMap {
  width: 100%;
  height: 100%;
}

.rete-cat {
  margin-bottom: 14px;
}

.rete-cat h2 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--rete-accent);
}

.rete-metric-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rete-metric-btn {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--rete-text);
  cursor: pointer;
  font-size: 0.88rem;
}

.rete-metric-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.rete-metric-btn.is-active {
  border-color: var(--rete-primary);
  background: rgba(2, 136, 209, 0.2);
}

.rete-legend {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.rete-legend h2 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.rete-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.82rem;
}

.rete-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.rete-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 20px;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}

.rete-marker--offline {
  background: #6b7280 !important;
  color: #fff !important;
}

.rete-marker--stale {
  background: #6b7280 !important;
  color: #fff !important;
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.95);
  opacity: 0.9;
}

.rete-marker--wind {
  min-width: 30px;
  min-height: 30px;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rete-marker-wrap {
  position: relative;
  display: inline-block;
}

.rete-marker-wrap--warn .rete-marker-warn {
  position: absolute;
  top: -7px;
  right: -7px;
  pointer-events: none;
}

.rete-warn-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #e53935;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  flex-shrink: 0;
}

.rete-wind-icon {
  display: block;
  width: 22px;
  height: 22px;
  line-height: 0;
}

.rete-wind-icon svg,
.rete-wind-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.rete-legend-swatch--wind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 22px;
  padding: 1px;
  box-sizing: border-box;
}

.rete-legend-swatch--wind svg {
  width: 18px;
  height: 18px;
}

.rete-popup h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.rete-popup p {
  margin: 4px 0;
  font-size: 0.88rem;
}

.rete-popup-stale {
  color: #f4d03f !important;
}

.rete-popup a {
  color: var(--rete-primary);
}

@media (max-width: 1100px) {
  .rete-header {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .rete-header__brand,
  .rete-header__nav,
  .rete-header__status {
    justify-self: stretch;
  }

  .rete-header__nav {
    order: 2;
    padding: 4px 0;
  }

  .rete-header__status {
    order: 3;
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .rete-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .rete-sidebar {
    max-height: 38vh;
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .rete-map-wrap {
    height: 55vh;
  }
}
