/* ========================================
   MSM Progetti - Main Styles
   ======================================== */

:root {
    --msm-primary: #2c5f8d;
    --msm-secondary: #e67e22;
    --msm-dark: #1a1a1a;
    --msm-gray: #6c757d;
    --msm-light-gray: #f8f9fa;
    --msm-border: #dee2e6;
    --msm-spacing: 1.5rem;
    --msm-radius: 8px;
    --msm-shadow: 0 2px 8px rgba(0,0,0,0.1);
    --msm-shadow-hover: 0 8px 24px rgba(0,0,0,0.15);
}

/* ========================================
   Container
   ======================================== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--msm-spacing);
}

/* ========================================
   Project Card
   ======================================== */
.msm-progetti-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
    margin: 2rem 0;
}

.msm-progetti-grid--small {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.msm-progetto-card {
    background: white;
    border-radius: var(--msm-radius);
    overflow: hidden;
    box-shadow: var(--msm-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
}

.msm-progetto-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--msm-shadow-hover);
}

.msm-progetto-card__image {
    position: relative;
    padding-top: 60%;
    overflow: hidden;
    background: var(--msm-light-gray);
}

.msm-progetto-card__image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.msm-progetto-card:hover .msm-progetto-card__image img {
    transform: scale(1.05);
}

.msm-progetto-card__badge {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--msm-primary);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.msm-progetto-card__content {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.msm-progetto-card__title {
    margin: 0 0 0.75rem;
    font-size: 1.25rem;
    line-height: 1.4;
}

.msm-progetto-card__title a {
    color: var(--msm-dark);
    text-decoration: none;
    transition: color 0.2s ease;
}

.msm-progetto-card__title a:hover {
    color: var(--msm-primary);
}

.msm-progetto-card__meta {
    color: var(--msm-gray);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.msm-meta-icon {
    font-size: 1rem;
}

.msm-progetto-card__excerpt {
    color: var(--msm-gray);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    flex: 1;
}

.msm-progetto-card__link {
    color: var(--msm-primary);
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: gap 0.2s ease;
}

.msm-progetto-card__link:hover {
    gap: 0.5rem;
}

/* ========================================
   Filters
   ======================================== */
.msm-progetti-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: white;
    border-radius: var(--msm-radius);
    box-shadow: var(--msm-shadow);
}

.msm-filter-btn {
    padding: 0.6rem 1.2rem;
    background: var(--msm-light-gray);
    border: 2px solid transparent;
    border-radius: var(--msm-radius);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--msm-dark);
    cursor: pointer;
    transition: all 0.2s ease;
}

.msm-filter-btn:hover {
    background: #e9ecef;
}

.msm-filter-btn.active {
    background: var(--msm-primary);
    color: white;
    border-color: var(--msm-primary);
}

/* ========================================
   Loading State
   ======================================== */
.msm-loading {
    text-align: center;
    padding: 3rem;
    color: var(--msm-gray);
    font-size: 1.1rem;
}

.msm-no-results {
    text-align: center;
    padding: 3rem;
    color: var(--msm-gray);
}

/* ========================================
   Single Project - Hero FULL WIDTH
   ======================================== */
.msm-progetto-hero {
    position: relative;
    margin-bottom: 3rem;
    /* Breakout dal container del tema (Astra .entry-content) — applicato al primo paint */
    width: 100vw;
    max-width: 100vw;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
}

/* Previene scrollbar orizzontale causata dal breakout 100vw */
body.single-progetto {
    overflow-x: clip;
}

.msm-progetto-hero__image {
    height: 500px;
    overflow: hidden;
    background: var(--msm-light-gray);
    width: 100%;
}

.msm-progetto-hero__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.msm-progetto-hero__content {
    background: linear-gradient(to top, rgba(0,0,0,0.85), rgba(0,0,0,0.4) 60%, transparent);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 3rem 0;
    color: white;
}

/* Container SOLO per il contenuto del testo hero */
.msm-progetto-hero__content .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
}

.msm-progetto-hero__category {
    display: inline-block;
    background: var(--msm-secondary);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 1rem;
}

.msm-progetto-hero__title {
    font-size: 2.5rem;
    margin: 0 0 1rem;
    line-height: 1.2;
    color: white;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.msm-progetto-hero__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    font-size: 1rem;
}

.msm-meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.msm-meta-item svg {
    opacity: 0.9;
}

/* ========================================
   Single Project - Layout
   ======================================== */
.msm-progetto-content {
    padding: 3rem 0;
}

.msm-progetto-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 3rem;
}

@media (max-width: 968px) {
    .msm-progetto-layout {
        grid-template-columns: 1fr;
    }
    
    .msm-progetto-sidebar {
        order: 2;
    }
    
    .msm-progetto-main {
        order: 1;
    }
}

/* ========================================
   Scheda Tecnica - STICKY
   ======================================== */
.msm-scheda-tecnica {
    background: white;
    border-radius: var(--msm-radius);
    box-shadow: var(--msm-shadow);
    position: sticky;
    top: 2rem;
    align-self: flex-start; /* Importante per sticky funzionante */
}

.msm-scheda-tecnica__title {
    background: var(--msm-primary);
    color: white;
    padding: 1.25rem;
    margin: 0;
    font-size: 1.25rem;
    border-radius: var(--msm-radius) var(--msm-radius) 0 0;
}

.msm-scheda-tecnica__content {
    padding: 1.5rem;
}

.msm-scheda-item {
    padding: 1rem 0;
    border-bottom: 1px solid var(--msm-border);
}

.msm-scheda-item:last-child {
    border-bottom: none;
}

.msm-scheda-item__label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--msm-gray);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.msm-scheda-item__value {
    color: var(--msm-dark);
    font-size: 1rem;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.msm-scheda-item__value--highlight {
    color: var(--msm-secondary);
    font-weight: 700;
    font-size: 1.1rem;
}

/* .msm-servizi-list: DEPRECATO in v3.6.0, sostituito da .msm-servizi-inline
   (rendering comma-separated dalla tassonomia area_competenza).
   Lasciato per compatibilità nel caso venga riusato altrove, ma la spunta
   "✓" fuorviante non viene più applicata da nessun rendering attivo. */
.msm-servizi-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.msm-servizi-list li {
    padding: 0.4rem 0;
}

/* NEW v3.6.0 — rendering pulito servizi offerti (comma-separated) */
.msm-servizi-inline {
    line-height: 1.6;
}

/* NEW v3.6.0 — dropdown filtro Area di Competenza, stile coerente
   con i pulsanti .msm-filter-btn già esistenti */
.msm-progetti-filters-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 12px;
}
.msm-progetti-filters-row label {
    font-weight: 600;
    color: var(--msm-dark, #1a3a5c);
    font-size: 0.92rem;
}
.msm-area-select {
    padding: 8px 14px;
    border: 1px solid #d5dbe2;
    border-radius: 6px;
    font-size: 0.92rem;
    background: #fff;
    color: var(--msm-dark, #1a3a5c);
    cursor: pointer;
}
.msm-area-select:focus {
    outline: 2px solid var(--msm-secondary, #f5a623);
    outline-offset: 1px;
}

/* NEW v3.6.0 — pulsante "torna all'elenco progetti" */
.msm-progetto-back-link {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 20px 48px;
}
.msm-btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--msm-dark, #1a3a5c);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: opacity 0.2s ease;
}
.msm-btn-back:hover {
    opacity: 0.7;
}

/* ========================================
   Project Description
   ======================================== */
.msm-progetto-description h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--msm-dark);
}

.msm-content-text {
    font-size: 1.05rem;
    line-height: 1.8;
    color: #333;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Spaziatura paragrafi Gutenberg - normalizzata */
.msm-content-text p,
.msm-content-text .wp-block-paragraph {
    margin-top: 0;
    margin-bottom: 1rem;
}

.msm-content-text > *:first-child {
    margin-top: 0;
}

.msm-content-text > *:last-child {
    margin-bottom: 0;
}

/* Headings interni alla descrizione */
.msm-content-text h2,
.msm-content-text h3,
.msm-content-text h4 {
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    line-height: 1.3;
}

/* Liste */
.msm-content-text ul,
.msm-content-text ol {
    margin-top: 0;
    margin-bottom: 1rem;
}

/* Blocchi Gutenberg generici (immagini, quote, ecc.) */
.msm-content-text .wp-block-image,
.msm-content-text .wp-block-quote,
.msm-content-text .wp-block-separator {
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
}

.msm-content-text ul,
.msm-content-text ol {
    margin-bottom: 1.25rem;
    padding-left: 2rem;
    line-height: 1.8;
}

.msm-content-text li {
    margin-bottom: 0.5rem;
}

.msm-content-text li:last-child {
    margin-bottom: 0;
}

/* ========================================
   Gallery Full Width Section
   ======================================== */
.msm-progetto-gallery-section {
    width: 100%;
    margin: 4rem 0;
}

.msm-progetto-gallery-section h2 {
    font-size: 1.75rem;
    margin-bottom: 2rem;
    color: var(--msm-dark);
}

/* ========================================
   Gallery
   ======================================== */
.msm-progetto-gallery {
    margin-top: 0;
}

.msm-progetto-gallery h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--msm-dark);
}

.gallery {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.gallery-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: var(--msm-radius);
}

/* ========================================
   Related Projects
   ======================================== */
.msm-related-progetti {
    background: var(--msm-light-gray);
    padding: 3rem 0;
    margin-top: 4rem;
}

.msm-related-progetti__title {
    font-size: 1.75rem;
    margin-bottom: 2rem;
    color: var(--msm-dark);
}

/* ========================================
   Archive Page
   ======================================== */
.msm-archive-header {
    background: linear-gradient(135deg, var(--msm-primary) 0%, #1e4a6f 100%);
    color: white;
    padding: 3rem 0;
    margin-bottom: 3rem;
}

.msm-archive-title {
    font-size: 2.5rem;
    margin: 0 0 1rem;
}

.msm-archive-description {
    font-size: 1.1rem;
    opacity: 0.9;
    max-width: 600px;
}

/* ========================================
   Gallery Multiple con Tabs
   ======================================== */
.msm-progetto-gallery-tabs {
    margin-top: 3rem;
    background: white;
    border-radius: var(--msm-radius);
    overflow: hidden;
}

.msm-progetto-gallery-tabs h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--msm-dark);
    padding: 0 1.5rem;
    padding-top: 1.5rem;
}

.msm-gallery-tabs__nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-bottom: 2px solid var(--msm-border);
    padding: 0 1.5rem;
    background: var(--msm-light-gray);
}

.msm-gallery-tab {
    padding: 1rem 1.5rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 1rem;
    font-weight: 600;
    color: var(--msm-gray);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    bottom: -2px;
    white-space: nowrap;
}

.msm-gallery-tab:hover {
    color: var(--msm-primary);
    background: rgba(44, 95, 141, 0.05);
}

.msm-gallery-tab.active {
    color: var(--msm-primary);
    border-bottom-color: var(--msm-primary);
    background: white;
}

.msm-gallery-tab__count {
    font-size: 0.85rem;
    color: var(--msm-gray);
    font-weight: 400;
    margin-left: 0.5rem;
}

.msm-gallery-tabs__content {
    padding: 2rem 1.5rem;
}

/* ========================================
   Gallery Grid Desktop + Slider Mobile
   ======================================== */

/* Desktop Grid - nascosto su mobile */
.msm-gallery-desktop {
    display: grid;
}

.msm-gallery-mobile {
    display: none;
}

.msm-gallery-grid {
    grid-template-columns: repeat(2, 1fr); /* 2 colonne fisse su desktop */
    gap: 1.5rem;
    margin-top: 1rem;
}

.msm-gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: var(--msm-radius);
    background: var(--msm-light-gray);
    cursor: zoom-in;
    display: block;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.msm-gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.msm-gallery-item img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
}

.msm-gallery-item:hover img {
    transform: scale(1.05);
}

/* Mobile Slider */
.msm-gallery-slider .swiper {
    padding-bottom: 40px;
    overflow: hidden;
    max-width: 100vw;
}

.msm-gallery-slider .swiper-slide {
    height: auto;
    max-width: 100%;
}

.msm-gallery-slider .swiper-slide a {
    display: block;
    border-radius: var(--msm-radius);
    overflow: hidden;
    background: var(--msm-light-gray);
    max-width: 100%;
}

.msm-gallery-slider .swiper-slide img {
    width: 100%;
    height: auto;
    display: block;
    max-width: 100%;
}

.msm-gallery-slider .swiper-pagination {
    bottom: 10px;
}

.msm-gallery-slider .swiper-pagination-bullet {
    background: var(--msm-gray);
    opacity: 0.5;
}

.msm-gallery-slider .swiper-pagination-bullet-active {
    background: var(--msm-primary);
    opacity: 1;
}

/* Responsive - Switch to slider on mobile - HIGH SPECIFICITY for Astra */
@media (max-width: 768px) {
    .msm-progetto-gallery-tabs .msm-gallery-desktop,
    .msm-gallery-tabs__content .msm-gallery-desktop,
    div.msm-gallery-desktop {
        display: none !important; /* Nascondi grid - FORZA con alta specificità */
    }
    
    .msm-progetto-gallery-tabs .msm-gallery-mobile,
    .msm-gallery-tabs__content .msm-gallery-mobile,
    div.msm-gallery-mobile {
        display: block !important; /* Mostra slider - FORZA con alta specificità */
        overflow: hidden !important;
        max-width: 100% !important;
    }
    
    .msm-gallery-tabs__content {
        overflow: hidden !important;
        max-width: 100% !important;
    }
    
    .msm-progetto-gallery-tabs {
        overflow: hidden !important;
        max-width: 100% !important;
    }
    
    .msm-gallery-grid {
        grid-template-columns: 1fr !important; /* 1 colonna su mobile */
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .msm-gallery-grid {
        grid-template-columns: repeat(2, 1fr); /* 2 colonne su tablet */
        gap: 1.25rem;
    }
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
    .msm-progetti-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .msm-progetto-hero__title {
        font-size: 1.75rem;
    }
    
    .msm-progetto-hero__image {
        height: 300px;
    }
    
    .msm-archive-title {
        font-size: 1.75rem;
    }
    
    /* Gallery Tabs Mobile */
    .msm-gallery-tabs__nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .msm-gallery-tab {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    /* ========================================
       FIX MOBILE - TUTTI I FIX APPLICATI
       ======================================== */
    
    /* FIX: Prevent horizontal scroll */
    body.single-progetto,
    .site-content,
    .entry-content {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    /* FIX: Titolo hero - parole intere senza sillabazione */
    .msm-progetto-hero__title {
        font-size: 1.75rem;
        hyphens: none !important;
        word-break: keep-all !important;
        overflow-wrap: normal !important;
    }
    
    /* FIX: Container con meno padding per più spazio al testo */
    .container {
        padding: 0 0.75rem;
    }
    
    /* FIX: Testo descrizione - meno padding laterale */
    .msm-content-text {
        padding-left: 0;
        padding-right: 0;
    }
    
    /* FIX: Scheda tecnica non sborda */
    .msm-scheda-tecnica {
        margin-left: 0;
        margin-right: 0;
    }
    
    .msm-scheda-item__value {
        word-break: break-word;
        hyphens: auto;
    }
    
    /* FIX: Gallery full width - esce completamente dal container */
    .msm-progetto-gallery-tabs {
        position: relative;
        left: 50%;
        right: 50%;
        margin-left: -50vw !important;
        margin-right: -50vw !important;
        width: 100vw !important;
        max-width: 100vw !important;
    }
    
    .msm-gallery-slider {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .msm-gallery-tabs__nav {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .msm-progetto-gallery-tabs h2 {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

/* ========================================
   CSS Scroll Snap Gallery
   ======================================== */
.msm-scroll-gallery {
    width: 100%;
    margin: 4rem 0;
    position: relative;
    background: #1a1a1a;
}

.msm-scroll-container {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

.msm-scroll-container::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

.msm-scroll-slide {
    flex: 0 0 100%;
    scroll-snap-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 600px;
    background: #1a1a1a;
}

.msm-scroll-slide img {
    max-width: 100%;
    max-height: 600px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

/* Navigation Buttons */
.msm-scroll-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
    font-size: 48px;
    line-height: 1;
    font-weight: 300;
    padding: 0;
}

.msm-scroll-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: translateY(-50%) scale(1.1);
}

.msm-scroll-prev {
    left: 20px;
}

.msm-scroll-next {
    right: 20px;
}

/* Mobile */
@media (max-width: 768px) {
    .msm-scroll-slide {
        min-height: 400px;
    }
    
    .msm-scroll-slide img {
        max-height: 400px;
    }
    
    .msm-scroll-btn {
        width: 40px;
        height: 40px;
    }
    
    .msm-scroll-prev {
        left: 10px;
    }
    
    .msm-scroll-next {
        right: 10px;
    }
}

/* ========================================
   Grid 2 Colonne (per progetti selezionati)
   ======================================== */
.msm-grid-2-cols {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 2rem;
}

@media (max-width: 768px) {
    .msm-grid-2-cols {
        grid-template-columns: 1fr !important;
    }
}
