/**
 * Comuni — Info Comune widget
 *
 * Styling derived from the Figma source of truth:
 * https://www.figma.com/design/rrfIqZ6MKwR6MERjY2elqf  (node 162:435)
 *
 * Design tokens:
 *   --co-orient   #00587A   testo principale, bordo tab attivo, link
 *   --co-cerulean #00ACE1   sfondo tab inattivo
 *   --co-white    #FFFFFF
 *   --co-cod-gray #131313   body text
 *
 * Font: Titillium Web (Bold / Regular) — fornito dal tema.
 */

.co-info-comune {
    --co-orient: #00587A;
    --co-cerulean: #00ACE1;
    /* Accessible variants for white text (WCAG AA 4.5:1 minimum) */
    --co-cerulean-accessible: #007799; /* 4.72:1 contrast with white */
    --co-cerulean-hover: #006688;      /* 5.94:1 contrast with white */
    --co-cerulean-active: #005577;     /* 7.44:1 contrast with white */
    --co-white: #FFFFFF;
    --co-cod-gray: #131313;
    --co-card-shadow: 0 0 10px rgba(0, 0, 0, 0.15);

    font-family: "Titillium Web", sans-serif;
    color: var(--co-cod-gray);
}

/* ---------- Comune selector (form sempre visibile) ---------- */

.co-comune-selector {
    background-color: var(--co-orient);
    padding: 16px 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
    color: var(--co-white);
    font-family: "Titillium Web", sans-serif;
}

.co-comune-selector__label {
    font-weight: 700;
    font-size: 16px;
    color: var(--co-white);
}

.co-comune-selector__select {
    flex: 1 1 240px;
    max-width: 360px;
    padding: 10px 14px;
    border: 2px solid var(--co-white);
    border-radius: 8px;
    background-color: var(--co-white);
    color: var(--co-orient);
    font-family: "Titillium Web", sans-serif;
    font-weight: 600;
    font-size: 16px;
    line-height: 1.2;
    appearance: auto;
}

.co-comune-selector__select:focus-visible {
    outline: 3px solid var(--co-cerulean);
    outline-offset: 2px;
}

.co-info-comune .co-comune-selector__submit {
    padding: 10px 22px;
    border: 2px solid var(--co-white, #FFFFFF);
    border-radius: 8px;
    background-color: var(--co-cerulean-accessible, #007799);
    color: var(--co-white, #FFFFFF);
    font-family: "Titillium Web", sans-serif;
    font-weight: 700;
    font-size: 14px;
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 80ms ease;
}

@media (prefers-reduced-motion: reduce) {
    .co-info-comune .co-comune-selector__submit { transition: none; }
}

/* Hover state — always applied. Inverts colours so the user sees a clear cue. */
.co-info-comune .co-comune-selector__submit:hover {
    background-color: var(--co-white, #FFFFFF);
    color: var(--co-orient, #00587A);
}

/* Pressed state — explicit so user gets feedback when clicking.
 * Listed after :hover to win the equal-specificity cascade. */
.co-info-comune .co-comune-selector__submit:active {
    background-color: #00688a;
    color: var(--co-white);
    border-color: var(--co-white);
    transform: translateY(1px);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

@media (prefers-reduced-motion: reduce) {
    .co-info-comune .co-comune-selector__submit:active { transform: none; }
}

/* Focus ring — never replaced by background-only states. */
.co-info-comune .co-comune-selector__submit:focus { outline: none; }
.co-info-comune .co-comune-selector__submit:focus-visible {
    outline: 3px solid var(--co-white, #FFFFFF);
    outline-offset: 2px;
}

.co-info-comune .co-comune-selector__submit[disabled],
.co-info-comune .co-comune-selector__submit[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

@media (max-width: 1024px) {
    .co-comune-selector { padding: 14px 40px; }
}

@media (max-width: 768px) {
    .co-comune-selector { padding: 12px 20px; }
    .co-comune-selector__select { max-width: 100%; }
}

/* ---------- Heading band: "Comune di {Nome}" ---------- */

.co-info-comune__heading-band {
    background-color: var(--co-orient);
    padding: 32px 120px 120px;
    width: 100%;
    box-sizing: border-box;
}

.co-info-comune__heading-inner {
    padding: 0 10px;
}

.co-info-comune,
.co-info-comune .co-info-comune__heading {
    /* High specificity to beat theme h2 color rules. */
}

.co-info-comune .co-info-comune__heading {
    margin: 0;
    font-family: "Titillium Web", sans-serif;
    font-weight: 700;
    font-size: 39.6px;
    line-height: 47.52px;
    color: var(--co-white) !important;
    text-align: center;
}

/* ---------- Tabs wrapper ---------- */

.co-info-comune__tabs-wrap {
    padding: 0 120px 32px;
    width: 100%;
    box-sizing: border-box;
}

.co-tabs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Tab row — slides up to overlap the heading band (Figma effect).
 *
 * .co-tabs__nav is the flex row; it holds the tablist plus the standalone
 * "Tariffe" link (which is not a tab and must stay outside role="tablist").
 * .co-tabs__heading uses display:contents so its four tabs wrap in the same
 * flow as the link — the ARIA role stays intact, the box does not. */

.co-tabs__nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: stretch;
    column-gap: 10px;
    row-gap: 10px;
    width: 100%;
    /* Metà altezza del tab: la riga resta a cavallo del bordo inferiore della
     * banda blu, come nel Figma. Va ricalcolato se cambiano padding/icona. */
    margin-top: -54px;
    position: relative;
    z-index: 2;
}

.co-tabs__heading {
    display: contents;
}

/* Fallback for engines without display:contents — the tabs keep their own
 * flex row and the link wraps below instead of sitting inline. */
@supports not (display: contents) {
    .co-tabs__heading {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: stretch;
        column-gap: 10px;
        row-gap: 10px;
    }
}

/* ---------- Tab buttons ----------
 *
 * Accessible state model. Three coherent visual states + focus ring.
 *
 *   inactive   (default)     bg Cerulean, border 2px white, text white
 *   inactive   :hover        bg darker Cerulean (#0091c0), border white, text white
 *   inactive   :active       bg darkest Cerulean (#0078a0)
 *   selected   (.is-active)  bg white, border 2px Orient, text Orient
 *   selected   :hover        same as selected (no change — already chosen)
 *   :focus-visible           2px Orient outline w/ 3px offset, on top of any state
 *   disabled   reduced opacity (not currently used)
 */

.co-info-comune .co-tab {
    /* Layout — cinque voci su una sola riga.
     * flex-basis 0 significa che la somma delle basi non satura mai la riga:
     * i tab si dividono lo spazio in parti uguali invece di andare a capo.
     * min-width è il pavimento sotto cui non scendono (poi interviene il
     * breakpoint mobile, che li impila). */
    flex: 1 1 0;
    min-width: 138px;
    min-height: 44px; /* WCAG 2.5.5 minimum touch target */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 22px 12px;

    /* Surface */
    border-radius: 15px;
    border: 2px solid var(--co-white, #FFFFFF);
    background-color: var(--co-cerulean-accessible, #007799);
    color: var(--co-white, #FFFFFF);

    /* Typography */
    font-family: "Titillium Web", sans-serif;
    font-weight: 700;
    font-size: 14px;
    line-height: 18px;
    text-align: center;
    text-transform: uppercase;
    /* Le etichette lunghe ("Qualità dell'acqua", nomi di sportello) vanno a
     * capo dentro il tab: è il testo a doversi adattare, non la riga. */
    white-space: normal;
    overflow-wrap: break-word;

    /* Interaction */
    cursor: pointer;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 80ms ease;
}

@media (prefers-reduced-motion: reduce) {
    .co-info-comune .co-tab { transition: none; }
}

/* Hover state — always applied, distinct from active selection. */
.co-info-comune .co-tab:hover {
    background-color: var(--co-cerulean-hover, #006688);
    color: var(--co-white, #FFFFFF);
}

/* Pressed (mouse-down / touch) on inactive */
.co-info-comune .co-tab:active {
    background-color: var(--co-cerulean-active, #005577);
    transform: translateY(1px);
}

/* Selected state — colours inverted.
 * Specificity-boosted with .co-info-comune prefix and listed across all
 * interaction pseudo-classes so the theme's button :focus/:hover rules
 * cannot push it back to the inactive look. */
.co-info-comune .co-tab.is-active,
.co-info-comune .co-tab.is-active:hover,
.co-info-comune .co-tab.is-active:focus,
.co-info-comune .co-tab.is-active:focus-visible,
.co-info-comune .co-tab.is-active:active {
    background-color: var(--co-white);
    border-color: var(--co-orient);
    color: var(--co-orient);
    transform: none;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

/* Keyboard focus ring — visible on top of any visual state, never blue fill. */
.co-info-comune .co-tab:focus { outline: none; }
.co-info-comune .co-tab:focus-visible {
    outline: 2px solid var(--co-orient, #00587A);
    outline-offset: 3px;
}

/* When selected, focus ring uses Cerulean for contrast against the white surface. */
.co-info-comune .co-tab.is-active:focus-visible {
    outline-color: var(--co-cerulean, #00ACE1);
}

/* Forced-colors (high contrast) — make active/inactive distinct without relying on colour. */
@media (forced-colors: active) {
    .co-info-comune .co-tab { border-width: 2px; }
    .co-info-comune .co-tab.is-active { border-width: 4px; }
    .co-info-comune .co-tab:focus-visible { outline: 3px solid CanvasText; }
}

.co-info-comune .co-tab[disabled],
.co-info-comune .co-tab[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
}

/* "Tariffe" — link, non tab: stesso aspetto dei tab inattivi, con i quattro
 * stati (default / hover / focus-visible / active) ereditati dalle regole
 * sopra. Qui si neutralizzano solo gli stili che il tema applica agli <a>:
 * sottolineatura e colore visited, che altrimenti lo staccherebbero dal set. */
.co-info-comune a.co-tab--link,
.co-info-comune a.co-tab--link:link,
.co-info-comune a.co-tab--link:visited,
.co-info-comune a.co-tab--link:hover,
.co-info-comune a.co-tab--link:focus,
.co-info-comune a.co-tab--link:active {
    text-decoration: none;
    color: var(--co-white, #FFFFFF);
}

.co-info-comune a.co-tab--link:hover {
    background-color: var(--co-cerulean-hover, #006688);
}

.co-info-comune a.co-tab--link:active {
    background-color: var(--co-cerulean-active, #005577);
}

.co-tab__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-size: 32px;
    width: 32px;
    height: 32px;
    flex: none;
}

.co-tab__icon i {
    line-height: 1;
}

.co-tab__icon svg {
    width: 42px;
    height: 42px;
    display: block;
    fill: currentColor;
}

.co-tab__label {
    display: inline-block;
}

/* ---------- Tab panels ---------- */

.co-tabs__content {
    width: 100%;
}

.co-tab-panel {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
}

.co-tab-panel[hidden] {
    display: none !important;
}

/* ---------- Avvisi grid (3 col cards) ---------- */

.co-avvisi-grid,
.elementor-posts-container.co-avvisi-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.co-avviso-card {
    background-color: var(--co-white);
    border-radius: 20px;
    box-shadow: var(--co-card-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.co-avviso-card__inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.co-avviso-card__thumbnail-link {
    display: block;
    position: relative;
    width: 100%;
    height: 274.53px;
    overflow: hidden;
    text-decoration: none;
}

.co-avviso-card__thumbnail {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.co-avviso-card__thumbnail::after {
    /* Gradient overlay from Figma: 0 → 35% black bottom. */
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0) 75%);
    pointer-events: none;
}

.co-avviso-card__thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.co-avviso-card__thumbnail--empty {
    height: 4px;
}

.co-avviso-card__text {
    padding: 14px 30px 20px;
    display: flex;
    flex-direction: column;
    gap: 21px;
    flex: 1;
}

.co-avviso-card__title {
    margin: 0;
    font-family: "Titillium Web", sans-serif;
    font-weight: 700;
    font-size: 27px;
    line-height: 32.45px;
    color: var(--co-orient);
}

.co-avviso-card__title a {
    color: inherit;
    text-decoration: none;
}

.co-avviso-card__title a:hover,
.co-avviso-card__title a:focus-visible {
    text-decoration: underline;
}

.co-avviso-card__excerpt {
    font-family: "Titillium Web", sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 24px;
    color: var(--co-cod-gray);
    padding-bottom: 8.67px;
}

.co-avviso-card__excerpt p {
    margin: 0;
}

.co-avviso-card__read-more {
    font-family: "Titillium Web", sans-serif;
    font-weight: 400;
    font-size: 12px;
    line-height: 18px;
    color: var(--co-orient);
    text-transform: capitalize;
    text-decoration: none;
    white-space: nowrap;
    margin-top: auto;
    align-self: flex-start;
}

.co-avviso-card__read-more:hover,
.co-avviso-card__read-more:focus-visible {
    text-decoration: underline;
}

/* ---------- Sportello card ---------- */

.co-sportello {
    background-color: var(--co-white);
    border-radius: 20px;
    box-shadow: var(--co-card-shadow);
    padding: 30px;
}

.co-sportello h3 {
    margin: 0 0 16px;
    font-family: "Titillium Web", sans-serif;
    font-weight: 700;
    font-size: 27px;
    line-height: 32.45px;
    color: var(--co-orient);
}

.co-sportello p {
    margin: 0 0 12px;
    font-family: "Titillium Web", sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 24px;
    color: var(--co-cod-gray);
}

.co-sportello p strong {
    color: var(--co-orient);
    font-weight: 700;
}

.co-sportello a {
    color: var(--co-orient);
    text-decoration: none;
}

.co-sportello a:hover,
.co-sportello a:focus-visible {
    text-decoration: underline;
}

.co-sportello__mappa {
    margin-top: 20px;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16 / 9;
}

.co-sportello__mappa iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* ---------- Analisi link ---------- */

.co-analisi-link {
    margin: 0 0 16px;
    font-family: "Titillium Web", sans-serif;
    font-size: 16px;
    line-height: 24px;
}

.co-analisi-link a {
    color: var(--co-orient);
    text-decoration: underline;
}

/* ---------- Emergenze list inside the combined tab ---------- */

.co-emergenze {
    margin-bottom: 24px;
}

.co-emergenze .em-card-list,
.co-em-card-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ---------- Inline fallback card (used when Emergenze\CardRenderer is not loaded) ---------- */

.co-em-card {
    background-color: var(--co-white);
    border-left: 6px solid var(--co-cerulean);
    border-radius: 12px;
    box-shadow: var(--co-card-shadow);
    padding: 20px 24px;
}

.co-em-card__header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.co-em-card__badge {
    display: inline-block;
    background-color: var(--co-cerulean);
    color: var(--co-white);
    font-family: "Titillium Web", sans-serif;
    font-weight: 700;
    font-size: 12px;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
}

.co-em-card__comune {
    margin: 0;
    font-family: "Titillium Web", sans-serif;
    font-weight: 700;
    font-size: 20px;
    line-height: 24px;
    color: var(--co-orient);
}

.co-em-card__body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.co-em-card__body p {
    margin: 0;
    font-family: "Titillium Web", sans-serif;
    font-size: 15px;
    line-height: 22px;
    color: var(--co-cod-gray);
}

.co-em-card__body strong {
    color: var(--co-orient);
    font-weight: 700;
}

.co-em-card__time {
    color: #555;
    font-size: 13px !important;
    line-height: 18px !important;
    padding-top: 4px;
}

/* ---------- Empty state ---------- */

.co-empty {
    margin: 0;
    padding: 32px 16px;
    text-align: center;
    font-family: "Titillium Web", sans-serif;
    font-size: 16px;
    line-height: 24px;
    color: var(--co-cod-gray);
    opacity: 0.75;
}

/* ---------- Screen reader only (visually hidden, announced by AT) ---------- */

.co-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 1024px) {
    .co-info-comune__heading-band {
        padding: 24px 40px 90px;
    }
    .co-info-comune__tabs-wrap {
        padding: 0 40px 24px;
    }
    .co-info-comune .co-info-comune__heading {
        font-size: 32px;
        line-height: 1.2;
    }
    .co-avvisi-grid,
    .elementor-posts-container.co-avvisi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .co-avviso-card__title {
        font-size: 22px;
        line-height: 26px;
    }
}

@media (max-width: 768px) {
    .co-info-comune__heading-band {
        padding: 20px 20px 48px;
    }
    .co-info-comune__tabs-wrap {
        padding: 0 20px 20px;
    }
    .co-info-comune .co-info-comune__heading {
        font-size: 26px;
    }
    .co-tabs__nav,
    .co-tabs__heading {
        flex-direction: column;
        align-items: stretch;
    }
    .co-tabs__nav {
        margin-top: -24px;
    }
    .co-info-comune .co-tab {
        /* In colonna l'asse principale è verticale: flex-basis 0 farebbe
         * collassare l'altezza (min-height esplicito disattiva il minimo
         * automatico), quindi qui i tab tornano a dimensionarsi sul contenuto. */
        flex: 0 0 auto;
        min-width: 0;
        width: 100%;
        white-space: normal;
        padding: 20px 16px;
    }
    .co-avvisi-grid,
    .elementor-posts-container.co-avvisi-grid {
        grid-template-columns: 1fr;
    }
    .co-avviso-card__thumbnail-link {
        height: 220px;
    }
}
