:root {
  --blu: #173b68;
  --azzurro: #2e75b6;
  --sfondo: #f4f7fb;
  --testo: #18324f;
  --linea: #a8bdd2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--sfondo);
  color: var(--testo);
}

.organigramma {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 30px 24px;
  text-align: center;
}

h1 {
  color: var(--blu);
  margin: 0 0 35px;
}

.albero {
  width: 100%;
  max-width: 1450px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 28px;
}

.nodo {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.figli {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 24px;
  width: 100%;
  margin-top: 42px;
  position: relative;
}

.figli::before {
  content: "";
  position: absolute;
  top: -22px;
  left: 50%;
  width: 2px;
  height: 22px;
  background: var(--linea);
}

.card {
  width: 100%;
  min-width: 0;
  max-width: 290px;
  padding: 18px 16px;
  border: 0;
  border-radius: 14px;
  background: #fff;
  color: var(--testo);
  cursor: pointer;
  box-shadow: 0 8px 22px #1b3e6124;
  transition: 0.2s ease;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 14px 28px #1b3e6138;
}

.card.principale {
  background: var(--blu);
  color: #fff;
}

.card.area {
  background: #e6f0fa;
  border: 2px solid #9fc2e2;
}

.ruolo {
  display: block;
  margin-bottom: 8px;
  color: var(--azzurro);
  font-size: 12px;
  font-weight: bold;
  line-height: 1.15;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  overflow-wrap: break-word;
}

.principale .ruolo {
  color: #bcd8f4;
}

.nome {
  display: block;
  font-size: 16px;
  font-weight: bold;
  line-height: 1.25;
  overflow-wrap: break-word;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #0f233a99;
}

.modal.aperto {
  display: flex;
}

.finestra {
  width: min(440px, 100%);
  position: relative;
  padding: 30px;
  text-align: center;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 18px 50px #00000040;
}

.finestra h2 {
  margin-top: 0;
  color: var(--blu);
}

.finestra p {
  line-height: 1.5;
}

.chiudi {
  position: absolute;
  top: 8px;
  right: 14px;
  border: 0;
  background: transparent;
  color: #6d7f92;
  font-size: 28px;
  cursor: pointer;
}

/* Layout desktop */
@media (min-width: 800px) {
  .albero {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    align-items: start;
    justify-items: center;
    gap: 24px;
  }

  .albero > .nodo {
    width: 100%;
    align-items: center;
  }

  .albero > .nodo:first-child {
    grid-column: 1;
    grid-row: 1;
  }

  .albero > .nodo:nth-child(2) {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
  }

  .albero > .nodo:nth-child(2) > .figli {
    min-width: 0;
  }

  .albero > .nodo:nth-child(2) > .figli::before {
    display: none;
  }

  /* Cinque elementi sulla stessa riga */
  .albero > .nodo:first-child > .figli {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    width: 100%;
  }

  .albero > .nodo:first-child > .figli > .nodo {
    min-width: 0;
    width: 100%;
  }

  .albero > .nodo:first-child > .figli > .nodo > .card {
    min-width: 0;
    width: 100%;
    padding: 16px 8px;
  }

  .albero > .nodo:first-child > .figli > .nodo > .card .nome {
    font-size: 14px;
    line-height: 1.2;
  }
}

/* Layout tablet e smartphone */
@media (max-width: 799px) {
  .albero {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .albero > .nodo {
    width: 100%;
    max-width: 700px;
  }

  .figli {
    width: 100%;
    gap: 16px;
  }

  .card {
    max-width: 280px;
  }
}

@media (max-width: 600px) {
  .organigramma {
    padding: 24px 12px;
  }

  .card {
    max-width: 100%;
  }

  .nome {
    font-size: 15px;
  }
}