/* ==========================================================================
   LAICA — guards.css
   Difese di rendering per blocchi Gutenberg "liberi" (inseriti dal cliente)
   sulle pagine con template laica-full.php, dove il contenuto esce SENZA
   wrapper .entry-content.

   CONTESTO ACCERTATO NEL TEMA
   - laica-full.php stampa the_content() nudo: NESSUN <main> nel template.
     I blocchi diventano figli diretti di <body> (dopo header fisso e
     .menu-overlay), oppure fratelli del <main> contenuto nel blocco wp:html
     delle 60 pagine esistenti. Le guardie coprono ENTRAMBI gli scope:
       main > …                              (contenuto dentro un main)
       body.page-template-laica-full > …     (blocchi sciolti a livello body)
   - style.css ha reset universale * { margin:0; padding:0 } e ul{list-style:none}:
     senza queste guardie i blocchi sciolti escono attaccati, a tutta
     larghezza viewport e le liste senza puntini.
   - I wrapper dei pattern Laica a primo livello sono SEMPRE <section
     class="wp-block-group section|page-hero|cta-band|band|hero|line-hero|quality">:
     le guardie li escludono e usano SOLO il combinatore figlio diretto (>),
     quindi i figli interni dei pattern non vengono mai toccati.
   - Specificità: tutto in :where() (specificità 0) tranne dove serve battere
     i global styles, che nei temi classici CON theme.json vengono stampati
     nel FOOTER (dopo questo file) e per i preset usano !important.
   - Caricare DOPO wp-extra.css:
     wp_enqueue_style('laica-guards', $t.'/assets/css/guards.css',
                      ['laica-extra'], LAICA_VER);

   Lista di scope "blocco sciolto" (ripetuta più volte perché i CSS non hanno
   alias di selettori):
     p, h1..h6, ul, ol, blockquote, figure, table, hr, pre,
     .wp-block-columns, .wp-block-buttons,
     div.wp-block-group:not(.section,.page-hero,.cta-band,.band,.hero,
                            .line-hero,.quality,.container)
   NOTE: figure copre image/gallery/table/embed; il gruppo è "div." perché i
   pattern usano tagName section; .wp-block-spacer è ESCLUSO di proposito
   (niente margini doppi, la sua altezza è inline); i marker (<!--more--> ecc.)
   non producono elementi e non sono toccati.
   ========================================================================== */


/* --------------------------------------------------------------------------
   PUNTO 1 — CONTENITORE, LARGHEZZA E RITMO DEI BLOCCHI SCIOLTI
   Reset * {margin:0} + niente .entry-content = testo incollato al viewport.
   Qui: colonna di lettura 760px centrata (come .entry-content > *), con
   gutter garantito via width:min(...) — niente padding, così margin-inline
   auto centra davvero. Solo figli DIRETTI di main/body.
   -------------------------------------------------------------------------- */
:where(main, body.page-template-laica-full) >
:where(p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote, figure, table, hr, pre,
       .wp-block-columns, .wp-block-buttons,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)) {
  width: min(760px, 100% - 2 * var(--gutter));
  max-width: none;
  margin-inline: auto;
}

/* Ritmo verticale (il reset universale ha azzerato tutti i margini). */
:where(main, body.page-template-laica-full) > :where(p)              { margin-block: 0 1.2rem; }
:where(main, body.page-template-laica-full) > :where(ul, ol)         { margin-block: 0 1.2rem; }
:where(main, body.page-template-laica-full) > :where(h1, h2, h3, h4, h5, h6) { margin-block: 2.2rem 0.9rem; }
:where(main, body.page-template-laica-full) > :where(figure)         { margin-block: 2rem; }
:where(main, body.page-template-laica-full) > :where(blockquote)     { margin-block: 2rem; }
:where(main, body.page-template-laica-full) > :where(.wp-block-buttons) { margin-block: 1.6rem 2rem; }

/* Primo blocco sciolto in cima alla pagina: l'header è position:fixed alto
   var(--header-h) — senza offset il contenuto ci finisce SOTTO.
   (Se la pagina inizia con un pattern, il pattern è escluso dallo scope e
   provvede da sé: .page-hero ha già padding-top con --header-h.) */
:where(main) >
:where(p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote, figure, table, hr, pre,
       .wp-block-columns, .wp-block-buttons,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)):first-child,
body.page-template-laica-full > :where(.menu-overlay) +
:where(p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote, figure, table, hr, pre,
       .wp-block-columns, .wp-block-buttons,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)) {
  margin-block-start: calc(var(--header-h) + 2.5rem);
}

/* Ultimo blocco sciolto prima del footer: aria sotto. */
:where(main, body.page-template-laica-full) >
:where(p, h1, h2, h3, h4, ul, ol, blockquote, figure, table,
       .wp-block-columns, .wp-block-buttons):last-child {
  margin-block-end: clamp(2.5rem, 6vw, 4.5rem);
}

/* Ancore sotto header fisso. */
:where(main, body.page-template-laica-full) :where([id]) {
  scroll-margin-top: calc(var(--header-h) + 1rem);
}

/* wpautop / classic content: paragrafi vuoti residui non devono creare buchi. */
:where(main, body.page-template-laica-full) > :where(p):empty { display: none; }


/* --------------------------------------------------------------------------
   PUNTO 1b — TIPOGRAFIA DEI BLOCCHI SCIOLTI
   Vale per il blocco sciolto stesso E per i discendenti di colonne/gruppi
   sciolti (che sfuggirebbero alle regole "figlio diretto").
   Allineata a .entry-content di wp-extra.css.
   -------------------------------------------------------------------------- */
:where(main, body.page-template-laica-full) > :where(h2),
:where(main, body.page-template-laica-full) > :where(.wp-block-columns,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)) :where(h2) {
  font-family: var(--serif);
  font-weight: 400;
  color: var(--cocoa);
  font-size: clamp(1.5rem, 2.6vw, 2rem);
  line-height: 1.15;
}
:where(main, body.page-template-laica-full) > :where(h3),
:where(main, body.page-template-laica-full) > :where(.wp-block-columns,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)) :where(h3) {
  font-family: var(--serif);
  font-weight: 400;
  color: var(--cocoa);
  font-size: 1.25rem;
}
:where(main, body.page-template-laica-full) > :where(h1) {
  font-family: var(--serif);
  font-weight: 400;
  color: var(--cocoa);
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.1;
}
:where(main, body.page-template-laica-full) > :where(h4, h5, h6),
:where(main, body.page-template-laica-full) > :where(.wp-block-columns,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)) :where(h4, h5, h6) {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.9rem;
  color: var(--toast);
}
:where(main, body.page-template-laica-full) > :where(p),
:where(main, body.page-template-laica-full) > :where(.wp-block-columns,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)) :where(p) {
  color: var(--ink-soft);
  line-height: 1.75;
  font-size: 1.02rem;
}
:where(main, body.page-template-laica-full) > :where(.wp-block-columns,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)) :where(p) {
  margin-block: 0 1.1rem;
}

/* Liste: il reset del tema fa ul{list-style:none} — i puntini vanno
   ripristinati per i contenuti (i pattern con liste "pulite" non sono
   figli diretti e non vengono toccati). */
main > ul, body.page-template-laica-full > ul,
main ul.wp-block-list, body.page-template-laica-full ul.wp-block-list,
.entry-content ul.wp-block-list {
  list-style: disc;
  padding-inline-start: 1.4rem;
  color: var(--ink-soft);
}
main > ol, body.page-template-laica-full > ol,
main ol.wp-block-list, body.page-template-laica-full ol.wp-block-list,
.entry-content ol.wp-block-list {
  list-style: decimal;
  padding-inline-start: 1.4rem;
  color: var(--ink-soft);
}
/* Le liste dei PATTERN (tag/prodotti) hanno classi proprie e restano pulite. */
ul.product-card__tags { list-style: none; padding-inline-start: 0; }
:where(main, body.page-template-laica-full) :where(li) { margin-block-end: 0.35rem; }

/* NB: stessa mina esiste dentro .entry-content (page.php): wp-extra.css non
   ripristina list-style. Guardia anche lì: */
.entry-content :where(ul:not([class])) { list-style: disc; }
.entry-content :where(ol) { list-style: decimal; }

/* Link nel testo sciolto: il tema fa a{color:inherit;text-decoration:none} —
   i link nei paragrafi del cliente diventerebbero invisibili. */
:where(main, body.page-template-laica-full) > :where(p, ul, ol) :where(a),
:where(main, body.page-template-laica-full) > :where(.wp-block-columns,
       div.wp-block-group:not(.section, .page-hero, .cta-band, .band, .hero,
                              .line-hero, .quality, .container)) :where(p a, li a) {
  color: var(--toast);
  text-decoration: underline;
  text-underline-offset: 2px;
}


/* --------------------------------------------------------------------------
   PUNTO 4 — ALIGN WIDE / FULL SU LAICA-FULL
   Il tema dichiara add_theme_support('align-wide') ma theme.json non ha
   settings.layout (contentSize/wideSize): il core NON emette alcun CSS per
   .alignwide/.alignfull fuori dai layout constrained. Qui i figli di
   main/body sono già full-bleed (body senza padding), quindi:
   - alignwide = colonna 1080px centrata (coerente con .entry-content > .alignwide)
   - alignfull = annullare il contenimento (niente trucco 100vw/margin calc:
     serve solo dentro contenitori con padding).
   Vanno DOPO il contenimento (stessa specificità 0, vince l'ordine).
   -------------------------------------------------------------------------- */
:where(main, body.page-template-laica-full) > :where(.alignwide) {
  width: min(1080px, 100% - 2 * var(--gutter));
  max-width: none;
}
:where(main, body.page-template-laica-full) > :where(.alignfull) {
  width: 100%;
  max-width: none;
  margin-inline: 0;
}
/* Immagine full-bleed: niente raggio sugli angoli a filo viewport. */
figure.wp-block-image.alignfull img {
  border-radius: 0;
}
/* Dentro .entry-content (page.php) alignfull resta oggi confinato nel
   .container (max-width:none non basta a uscire dal padding). Full-bleed
   vero — sicuro perché body ha overflow-x:clip che assorbe i 100vw con
   scrollbar: */
.entry-content > .alignfull {
  width: 100vw;
  max-width: none;
  margin-inline: calc(50% - 50vw);
}


/* --------------------------------------------------------------------------
   PUNTO 5 — MINIMI PER COLUMNS / SPACER / SEPARATOR / TABLE / QUOTE / IMAGE
   fuori da .entry-content. Il CSS core di wp-block-library (caricato anche
   nei temi classici) dà già: flex+stacking mobile alle columns (<782px),
   overflow-x:auto e border-collapse alle table, clear:both allo spacer.
   Qui solo l'innesto nel design system.
   -------------------------------------------------------------------------- */

/* Columns: blockGap è null in theme.json → il gap core cade sul fallback 2em;
   il design usa 1.6rem (come .entry-content .wp-block-columns). */
:where(main, body.page-template-laica-full) > :where(.wp-block-columns) {
  gap: 1.6rem;
}

/* Spacer: nessuna regola di margine/larghezza (altezza inline, aria-hidden).
   È escluso dallo scope apposta: aggiungergli margini raddoppierebbe lo
   spazio voluto dal cliente. */

/* Separator: l'hr sciolto uscirebbe col bordo inset del browser a tutta
   larghezza. Stile Laica (come .entry-content .wp-block-separator). */
main > hr, body.page-template-laica-full > hr {
  width: min(200px, 100% - 2 * var(--gutter));
  border: none;
  border-top: 1px solid rgba(60, 37, 31, 0.15);
  margin-block: 2.5rem;
}
hr.wp-block-separator.has-alpha-channel-opacity { opacity: 1; }
main > hr.is-style-wide, body.page-template-laica-full > hr.is-style-wide {
  width: min(760px, 100% - 2 * var(--gutter));
}

/* Table (figure.wp-block-table > table) */
:where(main, body.page-template-laica-full) > :where(figure.wp-block-table) table {
  width: 100%;
  border-collapse: collapse;
}
:where(main, body.page-template-laica-full) > :where(figure.wp-block-table) :where(td, th) {
  border-bottom: 1px solid rgba(60, 37, 31, 0.12);
  padding: 0.6rem 0.4rem;
  text-align: left;
  font-size: 0.92rem;
  color: var(--ink-soft);
}
:where(main, body.page-template-laica-full) > :where(figure.wp-block-table) th {
  font-weight: 600;
  color: var(--cocoa);
}

/* Quote */
:where(main, body.page-template-laica-full) > :where(blockquote) {
  border-left: 3px solid var(--gold);
  padding: 0.4rem 0 0.4rem 1.4rem;
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--cocoa);
}
:where(main, body.page-template-laica-full) > :where(blockquote) cite {
  display: block;
  margin-top: 0.6rem;
  font-family: var(--sans);
  font-style: normal;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Image / gallery */
:where(main, body.page-template-laica-full) > :where(figure.wp-block-image) img {
  border-radius: var(--r-m);
  height: auto;
}
:where(main, body.page-template-laica-full) > :where(figure) figcaption {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.5rem;
}
:where(main, body.page-template-laica-full) > :where(figure.wp-block-gallery) {
  gap: 10px;
}

/* Bottoni sciolti SENZA classe btn--X: il filtro PHP render_block_core/button
   aggiunge .btn solo se il cliente scrive btn--solid/ghost/gold. Un Pulsante
   nudo uscirebbe con lo stile dei global styles core (grigio scuro, stampato
   nel footer, specificità .wp-element-button = 0,1,0). Qui SPECIFICITÀ REALE
   (0,2,1) per batterlo indipendentemente dall'ordine: look = .btn--solid. */
main .wp-block-button__link:not(.btn),
body.page-template-laica-full .wp-block-button__link:not(.btn) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  background: var(--cocoa);
  color: var(--white);
  border: none;
  border-radius: var(--r-s);
  padding: 1.05rem 2.1rem;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  transition: background-color 0.45s var(--ease-out), transform 0.45s var(--ease-out);
}
main .wp-block-button__link:not(.btn):hover,
body.page-template-laica-full .wp-block-button__link:not(.btn):hover {
  background: var(--cocoa-deep);
  transform: translateY(-2px);
}
main .is-style-outline .wp-block-button__link:not(.btn),
body.page-template-laica-full .is-style-outline .wp-block-button__link:not(.btn) {
  background: transparent;
  color: var(--cocoa);
  border: 1px solid rgba(60, 37, 31, 0.35);
}


/* --------------------------------------------------------------------------
   PUNTO 2 — CLASSI PALETTE has-X-color / has-X-background-color
   Le classi colore sono già coperte due volte: wp-extra.css (var(--x)) e i
   preset dei global styles (hex + !important, stampati nel footer — vincono
   loro, stessi valori: innocuo). I buchi reali sono i CONTENITORI:
   - il core dà padding solo via :where(p.has-background){padding:1.25em 2.375em}
     e regole analoghe per heading/list del block-library; il gruppo con
     sfondo ha il :where core ma resta un rettangolo spigoloso fuori design;
   - testo di default (--ink) su sfondi scuri della palette = illeggibile.
   -------------------------------------------------------------------------- */

/* Contenitori con sfondo: padding pieno + raggio del design system.
   (Specificità 0: un padding custom del cliente via editor vince sempre.) */
:where(main, body.page-template-laica-full) :where(p, h1, h2, h3, h4, h5, h6, ul, ol):where(.has-background) {
  padding: 1.1em 1.4em;
  border-radius: var(--r-s);
}
:where(main, body.page-template-laica-full) :where(div.wp-block-group.has-background) {
  padding: clamp(1.6rem, 4vw, 2.5rem);
  border-radius: var(--r-m);
}

/* Liste con sfondo: i puntini non devono uscire dal box. */
:where(main, body.page-template-laica-full) :where(ul.has-background, ol.has-background) {
  list-style-position: inside;
}

/* Sfondi scuri della palette senza colore testo esplicito: default leggibile.
   :not dentro :where = specificità ancora 0, quindi un has-X-color scelto
   dal cliente (preset !important nel footer) vince sempre. */
:where(.has-cocoa-background-color:not(.has-text-color),
       .has-cocoa-deep-background-color:not(.has-text-color),
       .has-toast-background-color:not(.has-text-color),
       .has-seal-background-color:not(.has-text-color)) {
  color: var(--surface);
}
/* Dentro un GRUPPO scuro anche i discendenti (che le guardie tipografiche
   sopra colorerebbero cocoa/ink-soft): ereditano il chiaro.
   Dopo le regole tipografiche → a pari specificità 0 vince questa. */
:is(.has-cocoa-background-color, .has-cocoa-deep-background-color,
    .has-toast-background-color, .has-seal-background-color)
:is(h1, h2, h3, h4, h5, h6, p, li):not([class*="has-"][class*="-color"]) {
  color: inherit;
}


/* --------------------------------------------------------------------------
   PUNTO 3 — PRESET FONT-SIZE CORE (has-small|medium|large|x-large-font-size)
   theme.json attuale: customFontSize:false (ok, niente px liberi) ma NON
   azzera i preset → l'editor offre S/M/L/XL core (13/20/36/42px, fuori
   scala) e i global styles stampano nel footer le classi con !important.

   FIX STRUTTURALE (theme.json, settings.typography):
       "typography": {
         "customFontSize": false,
         "dropCap": false,
         "defaultFontSizes": false,   <- WP 6.6+, toglie i preset core
         "fontSizes": []              <- nessun preset proprio: UI dimensioni sparita
       }
   Dopo il fix il core smette di stampare classi e variabili preset: le
   classi has-*-font-size GIÀ SALVATE diventano inerti (il testo torna alla
   scala del design). Le regole qui sotto sono il ponte per i contenuti
   legacy E la rete di sicurezza finché il fix non è deployato: servono
   !important + prefisso body perché i preset core stanno nel footer con
   !important.
   -------------------------------------------------------------------------- */
body .has-small-font-size   { font-size: 0.92rem !important; }
body .has-medium-font-size  { font-size: 1.0625rem !important; }
body .has-large-font-size   { font-size: 1.35rem !important; line-height: 1.4 !important; }
body .has-x-large-font-size { font-size: clamp(1.7rem, 3vw, 2.4rem) !important; line-height: 1.2 !important; }
body .has-xx-large-font-size{ font-size: clamp(2rem, 4vw, 3rem) !important; line-height: 1.15 !important; }


/* --------------------------------------------------------------------------
   PUNTO 6 — wpautop (promemoria PHP, nessun CSS)
   do_blocks() (priorità 9) rimuove da sé wpautop quando il contenuto
   contiene QUALSIASI blocco → le pagine solo-native su laica-full sono già
   al riparo dal doppio-wrapping. Il filtro attuale del tema
   (is_page() && has_block('core/html')) è quindi quasi ridondante e ha un
   effetto collaterale: toglie wpautop GLOBALMENTE per il resto della
   request. Il rischio residuo concreto è il contenuto CLASSIC (senza
   delimitatori di blocco, es. HTML incollato senza wp:html): lì wpautop
   corre e sparge <p> a tutta larghezza. Difese consigliate:
     1) escludere core/freeform dalla whitelist (vedi punto 7);
     2) in functions.php, rimozione mirata per template:
          add_filter('the_content', function ($c) {
              if (is_page_template('laica-full.php')) {
                  remove_filter('the_content', 'wpautop');
              }
              return $c;
          }, 0);
     3) la guardia CSS "p:empty { display:none }" del punto 1 assorbe i
        paragrafi vuoti residui.
   -------------------------------------------------------------------------- */


/* --------------------------------------------------------------------------
   PUNTO 7 — WHITELIST BLOCCHI (promemoria PHP, nessun CSS)
   add_filter('allowed_block_types_all', function ($allowed, $ctx) {
       if ($ctx->post && 'page' === $ctx->post->post_type) {
           $list = [
               'core/paragraph', 'core/heading', 'core/list', 'core/list-item',
               'core/image', 'core/gallery', 'core/quote', 'core/table',
               'core/separator', 'core/spacer', 'core/buttons', 'core/button',
               'core/group', 'core/columns', 'core/column', 'core/embed',
               'core/block',
           ];
           if (current_user_can('unfiltered_html')) $list[] = 'core/html';
           return $list;
       }
       return $allowed;
   }, 10, 2);

   Esclusioni motivate:
   - core/freeform (Classic): unico vero vettore wpautop → mina n.1;
   - core/cover: hero coperti dai pattern; overlay/contrasto e CSS core
     pesante fuori design;
   - core/media-text: esiste il pattern immagine-testo/testo-immagine;
   - core/pullquote, verse, code, preformatted, details: nessuna resa nel
     design system;
   - core/query, latest-posts, latest-comments, rss: le liste news/prodotti
     sono dei template PHP;
   - core/site-*, template-part, navigation, post-*: blocchi da tema a
     blocchi, qui header/footer sono PHP;
   - core/social-links, search, calendar, archives, tag-cloud: fuori scope;
   - core/shortcode, core/more: inutili sulle pagine;
   - core/html riservato a chi ha unfiltered_html (gli editor non possono
     comunque salvarne il markup integro).
   ========================================================================== */
