/**
 * Presentazione dei blocchi Gutenberg nel contenuto editoriale.
 *
 * Il foglio viene caricato sia nel front-end sia nell'editor. Tutte le regole
 * sono circoscritte al contenuto della pagina per non modificare i componenti
 * storici del tema.
 */

:where(.article-wrapper, .editor-styles-wrapper) {
  --dli-block-primary: var(--wp--preset--color--rosso-istituzionale, #b32d4a);
  --dli-block-primary-dark: #8f243b;
  --dli-block-primary-light: var(--wp--preset--color--sfondo-rosa-chiaro, #ffeaef);
  --dli-block-text: var(--wp--preset--color--nero-profondo, #1a1a1a);
  --dli-block-muted: #5c6670;
  --dli-block-border: #d9d9d9;
  --dli-block-surface: #f5f5f5;
  --dli-block-radius: 0.25rem;
}

/* Ritmo verticale e leggibilita` di base. */
:where(.article-wrapper, .editor-styles-wrapper)
  :where(
    .wp-block-quote,
    .wp-block-details,
    .wp-block-table,
    .wp-block-image,
    .wp-block-gallery,
    .wp-block-audio,
    .wp-block-file,
    .wp-block-media-text,
    .wp-block-video,
    .wp-block-buttons,
    .wp-block-columns,
    .wp-block-group,
    .wp-block-separator,
    .wp-block-unipv-card,
    .box-item
  ) {
  margin-block: 1.5rem;
}

:where(.article-wrapper, .editor-styles-wrapper) :where(ul.wp-block-list, ol.wp-block-list) {
  margin-block: 1rem 1.5rem;
  padding-inline-start: 1.5rem;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-list li + li {
  margin-top: 0.35rem;
}

/* Citazione. */
:where(.article-wrapper, .editor-styles-wrapper) .wp-block-quote {
  border-left: 0.3rem solid var(--dli-block-primary);
  border-radius: 0 var(--dli-block-radius) var(--dli-block-radius) 0;
  background: var(--dli-block-surface);
  padding: 1.25rem 1.5rem;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-quote > :last-child {
  margin-bottom: 0;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-quote cite {
  display: block;
  margin-top: 0.75rem;
  color: var(--dli-block-muted);
  font-size: 0.875rem;
  font-style: normal;
}

/* Pattern testimonianza. */
.unipv-testimonial > .wp-block-image {
  margin-inline: auto;
}

.unipv-testimonial .wp-block-quote p {
  font-size: 1.125rem;
  line-height: 1.5;
}

.unipv-testimonial .wp-block-quote cite {
  font-size: 0.875rem;
  line-height: 1.5;
}

/* Dettagli / apri-chiudi: riprende l'accordion storico del tema. */
:where(.article-wrapper, .editor-styles-wrapper) .wp-block-details {
  overflow: hidden;
  border: 1px solid var(--dli-block-border);
  border-radius: var(--dli-block-radius);
  background: #fff;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-details > summary {
  position: relative;
  display: block;
  cursor: pointer;
  list-style: none;
  padding: 0.85rem 3rem 0.85rem 1rem;
  background: var(--dli-block-primary);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
  user-select: none;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details.is-style-grigio
  > summary {
  background: #f6f6f6;
  color: #212529;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details
  > summary::-webkit-details-marker {
  display: none;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-details > summary::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 1.1rem;
  width: 0.65rem;
  height: 0.65rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-65%) rotate(45deg);
  transition: transform 0.2s ease;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details[open]
  > summary::after {
  transform: translateY(-35%) rotate(-135deg);
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details
  > summary:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -5px;
  box-shadow: 0 0 0 3px var(--dli-block-primary-dark);
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details.is-style-grigio
  > summary:focus-visible {
  outline-color: var(--dli-block-primary);
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details
  > :not(summary) {
  margin-inline: 1rem;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details
  > :not(summary):first-of-type {
  margin-top: 1rem;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details
  > :not(summary):last-child {
  margin-bottom: 1rem;
}

/* Riproduce il distacco di 0.4rem usato dall'accordion storico. */
:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details:has(+ .wp-block-details) {
  margin-bottom: 0;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-details
  + .wp-block-details {
  margin-top: 0.4rem;
}

/* Tabelle. */
:where(.article-wrapper, .editor-styles-wrapper) .wp-block-table {
  overflow-x: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-table table {
  width: 100%;
  margin: 0;
  border: 0;
  border-collapse: collapse;
  border-color: var(--bs-border-color, var(--dli-block-border));
  color: var(--dli-block-text);
  font-size: 1.125rem;
  vertical-align: top;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-table table th,
:where(.article-wrapper, .editor-styles-wrapper) .wp-block-table table td {
  border: 0;
  border-bottom: 1px solid var(--bs-border-color, var(--dli-block-border));
  padding: 0.75rem;
  text-align: left;
  vertical-align: top;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-table table th {
  border: 0;
  border-bottom: 2px solid #333;
  background: transparent;
  color: var(--dli-block-text);
  font-weight: 700;
  vertical-align: bottom;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-table caption {
  padding: 0.75rem 0;
  color: var(--dli-block-muted);
  font-size: 0.875rem;
  line-height: 1.45;
  text-align: left;
}

/* Immagini, gallerie e didascalie. */
.wp-block-image.aligncenter,
.wp-block-image > .aligncenter {
  display: table;
  margin-right: auto;
  margin-left: auto;
}

:where(.article-wrapper, .editor-styles-wrapper)
  :where(.wp-block-image img, .wp-block-gallery img, .wp-block-video video) {
  display: block;
  max-width: 100%;
  height: auto;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-gallery {
  gap: 0.75rem;
}

:where(.article-wrapper, .editor-styles-wrapper)
  :where(.wp-block-gallery, .wp-block-media-text, .wp-block-unipv-card, .box-item)
  .wp-block-image {
  margin-block: 0;
}

:where(.article-wrapper, .editor-styles-wrapper)
  :where(figcaption, .wp-element-caption) {
  margin-top: 0.5rem;
  color: var(--dli-block-muted);
  font-size: 0.875rem;
  line-height: 1.45;
  text-align: left;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-audio audio {
  display: block;
  width: 100%;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-video video {
  width: 100%;
  border-radius: var(--dli-block-radius);
  background: #000;
}

/* Allegato. */
.article-wrapper .wp-block-file,
.editor-styles-wrapper .wp-block-file {
  display: flex;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--dli-block-border);
  border-radius: var(--dli-block-radius);
  background: var(--dli-block-surface);
  font-size: 1rem;
  padding: 0.75rem 1rem;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-file > a:first-child {
  overflow-wrap: anywhere;
  font-weight: 600;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-file .wp-block-file__button {
  flex: 0 0 auto;
  margin-left: auto;
  border-radius: var(--dli-block-radius);
  background: var(--dli-block-primary);
  padding: 0.65rem 1rem;
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-file
  .wp-block-file__button:hover {
  background: var(--dli-block-primary-dark);
  color: #fff;
}

/* Media e testo. */
:where(.article-wrapper, .editor-styles-wrapper) .wp-block-media-text {
  overflow: hidden;
  gap: 0;
  border: 1px solid var(--dli-block-border);
  border-radius: var(--dli-block-radius);
  background: #fff;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-media-text
  .wp-block-media-text__media {
  align-self: stretch;
  min-height: 100%;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-media-text
  .wp-block-media-text__media
  img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-media-text
  .wp-block-media-text__content {
  padding: clamp(1.25rem, 4vw, 2.5rem);
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-media-text
  .wp-block-media-text__content
  > :last-child {
  margin-bottom: 0;
}

/* Pulsanti e layout. */
:where(.article-wrapper, .editor-styles-wrapper) .wp-block-buttons {
  gap: 0.75rem;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-button__link {
  border: 2px solid var(--dli-block-primary);
  border-radius: var(--dli-block-radius);
  background: var(--dli-block-primary);
  padding: 0.7rem 1.25rem;
  color: #fff;
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-button__link:hover {
  border-color: var(--dli-block-primary-dark);
  background: var(--dli-block-primary-dark);
  color: #fff;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-button.is-style-outline
  > .wp-block-button__link {
  background: transparent;
  color: var(--dli-block-primary);
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-button.is-style-outline
  > .wp-block-button__link:hover {
  background: var(--dli-block-primary-light);
  color: var(--dli-block-primary-dark);
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-columns {
  align-items: flex-start;
  gap: clamp(1.25rem, 4vw, 2.5rem);
}

/* Le colonne che contengono Card CPT hanno quote uguali e card della stessa altezza. */
@media (min-width: 782px) {
  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-columns:has(
      > .wp-block-column
        > :is(
            .unipv-cpt-card-wrapper,
            .unipv-evento-block-wrapper,
            .unipv-linea-ricerca-block-wrapper,
            .unipv-progetto-ricerca-block-wrapper,
            .unipv-struttura-block-wrapper
          )
    ) {
    align-items: stretch;
  }

  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-columns:has(
      > .wp-block-column
        > :is(
            .unipv-cpt-card-wrapper,
            .unipv-evento-block-wrapper,
            .unipv-linea-ricerca-block-wrapper,
            .unipv-progetto-ricerca-block-wrapper,
            .unipv-struttura-block-wrapper
          )
    ):has(> .wp-block-column:nth-child(2):last-child)
    > .wp-block-column {
    flex: 1 1 0 !important;
    min-width: 0;
  }

  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-column:has(
      > :is(
          .unipv-cpt-card-wrapper,
          .unipv-evento-block-wrapper,
          .unipv-linea-ricerca-block-wrapper,
          .unipv-progetto-ricerca-block-wrapper,
          .unipv-struttura-block-wrapper
        )
    ) {
    display: flex;
    min-width: 0;
    flex-direction: column;
  }

  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-column
    > :is(
        .unipv-cpt-card-wrapper,
        .unipv-evento-block-wrapper,
        .unipv-linea-ricerca-block-wrapper,
        .unipv-progetto-ricerca-block-wrapper,
        .unipv-struttura-block-wrapper
      ) {
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    margin-block: 0 !important;
  }

  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-column
    > :is(
        .unipv-cpt-card-wrapper,
        .unipv-evento-block-wrapper,
        .unipv-linea-ricerca-block-wrapper,
        .unipv-progetto-ricerca-block-wrapper,
        .unipv-struttura-block-wrapper
      )
    > :is(
        .unipv-cpt-card,
        .unipv-evento-card,
        .unipv-linea-ricerca-card,
        .unipv-progetto-ricerca-card,
        .unipv-struttura-card
      ) {
    width: 100%;
    height: 100%;
  }
}

:where(.article-wrapper, .editor-styles-wrapper)
  :where(.wp-block-columns, .wp-block-group)
  > :first-child {
  margin-top: 0;
}

:where(.article-wrapper, .editor-styles-wrapper)
  :where(.wp-block-columns, .wp-block-group)
  > :last-child {
  margin-bottom: 0;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-group:is(.is-layout-flex, .is-layout-grid) {
  gap: 0.75rem;
}

:where(.article-wrapper, .editor-styles-wrapper)
  .wp-block-group.is-layout-flex
  > .wp-block-details {
  flex: 1 1 18rem;
}

:where(.article-wrapper, .editor-styles-wrapper) .wp-block-separator {
  border-top: 1px solid var(--dli-block-border);
  border-bottom: 0;
  opacity: 1;
}

/* Card personalizzata UNIPV. */
.article-wrapper .box-item,
.editor-styles-wrapper .box-item {
  --dli-card-padding: clamp(1.25rem, 2vw, 1.5rem);
  border-radius: var(--dli-block-radius);
  padding: var(--dli-card-padding);
}

.article-wrapper .box-item.classic,
.editor-styles-wrapper .box-item.classic {
  border: 1px solid var(--dli-block-border);
  border-top: 0.3rem solid var(--dli-block-primary);
  box-shadow: 0 0.25rem 1rem rgba(0, 0, 0, 0.08);
}

.article-wrapper .box-item .box-image.image-full,
.editor-styles-wrapper .box-item .box-image.image-full {
  margin: calc(0px - var(--dli-card-padding))
    calc(0px - var(--dli-card-padding)) 0;
}

.article-wrapper .box-item .box-content-title,
.editor-styles-wrapper .box-item .box-content-title {
  margin-block: 1rem 0.75rem;
  color: var(--dli-block-text);
  font-family: "Roboto Slab", serif;
  font-size: 1.25rem;
  line-height: 1.35;
}

.article-wrapper .box-item .box-content-text,
.editor-styles-wrapper .box-item .box-content-text {
  margin-block: 0 1rem;
  font-size: 1rem;
  line-height: 1.6;
}

.article-wrapper .box-item .card-link,
.editor-styles-wrapper .box-item .card-link {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  justify-content: center;
}

@media (max-width: 781px) {
  :where(.article-wrapper, .editor-styles-wrapper) .wp-block-columns:not(.is-not-stacked-on-mobile) {
    flex-direction: column;
  }

  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-columns:not(.is-not-stacked-on-mobile)
    > .wp-block-column {
    flex-basis: 100% !important;
    width: 100%;
  }
}

@media (max-width: 600px) {
  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-media-text.is-stacked-on-mobile {
    grid-template-columns: 100% !important;
  }

  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-media-text.is-stacked-on-mobile
    .wp-block-media-text__media {
    grid-column: 1;
    grid-row: 1;
  }

  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-media-text.is-stacked-on-mobile
    .wp-block-media-text__content {
    grid-column: 1;
    grid-row: 2;
  }

  :where(.article-wrapper, .editor-styles-wrapper) .wp-block-file {
    align-items: flex-start;
    flex-direction: column;
  }

  :where(.article-wrapper, .editor-styles-wrapper)
    .wp-block-file
    .wp-block-file__button {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  :where(.article-wrapper, .editor-styles-wrapper) .wp-block-details > summary::after,
  :where(.article-wrapper, .editor-styles-wrapper) .wp-block-button__link {
    transition: none;
  }
}
