/* =============================================
   PLANIFICADOR WP ADDITIONS
   Estils addicionals per la integracio WordPress:
   patrimoni, avisos, i links a fitxes WP.

   IMPORTANT: Afegir aquest contingut al FINAL
   de planificador-override.css
   ============================================= */

/* ---- MAP HEIGHT FALLBACK (WordPress) ---- */
.mapa-sec {
    position: relative;
    min-height: calc(100vh - 80px);
    height: calc(100vh - 80px);
}

#map {
    height: 100%;
    width: 100%;
}

/* ---- TRAM POPUP WITH RUTA CARDS (llistat-trams style) ---- */
.tram-rutes-popup .leaflet-popup-content {
    padding: 0 !important;
    min-width: 320px;
    max-width: 420px;
}

.tram-popup-cards {
    max-height: 450px;
    overflow-y: auto;
}

/* Each group: image left + ruta items right */
.tram-popup-cards .exp-main {
    display: flex;
    flex-direction: row;
    border-bottom: 1px solid #eee;
}

.tram-popup-cards .exp-main:last-child {
    border-bottom: none;
}

.tram-popup-cards .exp-img {
    width: 120px;
    min-width: 120px;
    flex-shrink: 0;
}

.tram-popup-cards .exp-img img {
    width: 120px;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tram-popup-cards .exp-txt {
    flex: 1;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Each ruta direction item */
.tram-popup-ruta-item {
    padding: 6px 0;
	border-bottom: none;
}

.tram-popup-ruta-item:last-child {
    border-bottom: none;
}

.tram-popup-ruta-item h2 {
    font-size: 13px !important;
    line-height: 1.3 !important;
    margin-bottom: 2px !important;
}

.tram-popup-ruta-item .veure-ext-link {
    font-size: 11px !important;
    height: auto !important;
    padding: 0 !important;
    background: none !important;
    color: #007F6F !important;
    width: auto !important;
    display: inline !important;
    text-decoration: none;
}

.tram-popup-ruta-item .veure-ext-link:hover {
    text-decoration: underline;
    background: none !important;
}

/* Municipality at bottom of card */
.tram-popup-cards .exp-txt > h3 {
    margin-top: 0px;
    padding-top: 0px;
    margin-bottom: 0px;
}

/* ---- EXP-MAIN CARD (popups & sidebar) ---- */
.exp-main {
    overflow: hidden;
}

.exp-img {
    width: 100%;
    overflow: hidden;
}

.exp-img img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
}

.exp-txt {
    padding: 12px 14px;
}

.exp-txt h2 {
    font-family: 'Poppins-Semibold', system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.3;
    color: #1A1A1A;
    margin-bottom: 4px;
}

.exp-txt h3 {
    font-family: 'Poppins-Regular', system-ui, sans-serif;
    font-size: 12px;
    color: #888;
    margin-bottom: 10px;
    font-weight: normal;
}

.exp-txt h3 span {
    color: #007F6F;
}

/* Popup-specific: remove default padding since card handles it */
.leaflet-popup-content:has(.exp-main) {
    padding: 0 !important;
    min-width: 240px;
}

/* ---- GALLERY SLIDER POPUP ---- */
.gallery-slider-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-slider-box {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.gallery-slider-img-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-slider-img {
    max-width: 85vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
}

.gallery-slider-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    z-index: 10;
}

.gallery-slider-prev,
.gallery-slider-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    font-size: 28px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s;
}

.gallery-slider-prev:hover,
.gallery-slider-next:hover {
    background: rgba(255, 255, 255, 0.4);
}

.gallery-slider-prev { left: -54px; }
.gallery-slider-next { right: -54px; }

.gallery-slider-counter {
    text-align: center;
    color: #fff;
    font-size: 14px;
    margin-top: 12px;
    font-family: 'Poppins-Regular', system-ui, sans-serif;
}

@media (max-width: 600px) {
    .alert-btn-mobile {
        left: auto;
        right: 10px;
        top: 75px;
    }

    a.alert-btn {
        font-size: 12px;
        height: 37px;
    }

    .rightsidebar .tag-lst a {
        height: auto;
    }

    .gallery-slider-prev { left: 8px; }
    .gallery-slider-next { right: 8px; }
}

/* ---- ROUTE POIs & GALLERY SECTIONS ---- */
.route-pois-section,
.route-gallery-section {
    padding: 12px;
    background: rgba(0, 127, 111, 0.04);
    border-radius: 10px;
    border: 1px solid rgba(0, 127, 111, 0.1);
}

.route-pois-list { text-align: left; }

.route-poi-item {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    align-items: center;
    text-align: left;
}

.route-poi-item:last-child { border-bottom: none; }

.route-poi-thumb {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.route-poi-info {
    font-size: 13px;
    line-height: 1.4;
    text-align: left;
    flex: 1;
}

.route-poi-item-compact {
    padding: 4px 0;
    font-size: 13px;
    border-bottom: 1px solid #f0f0f0;
    text-align: left;
}

.route-poi-item-compact:last-child { border-bottom: none; }

.route-poi-link {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.route-poi-link:hover {
    color: #007F6F;
    text-decoration: underline;
}

.route-poi-item .route-poi-link img {
    display: block;
}

.route-gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.route-gallery-thumb {
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
}

.route-gallery-thumb img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    display: block;
    transition: transform 0.2s;
}

#routeGalleryContent .route-gallery-thumb:hover img { transform: scale(1.05); }

#previewGallery .route-gallery-grid { grid-template-columns: repeat(4, 1fr); }
#previewGallery .route-gallery-thumb img { height: 80px; cursor: default; }

/* ---- PATRIMONI MARKERS ---- */
.patrimoni-marker {
    background: transparent !important;
    border: none !important;
}

.patrimoni-marker svg {
    filter: drop-shadow(0 2px 4px rgba(0, 127, 111, 0.3));
}

/* ---- ALERT TIPOLOGIA TAG (sidebar) ---- */
.alert-tipologia {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 6px;
    background: rgba(213, 68, 107, 0.1);
    color: #D5446B;
    font-size: 11px;
    font-family: 'Poppins-Medium', system-ui, sans-serif;
    vertical-align: middle;
}

/* ---- AVIS (ALERT) MARKERS ---- */
.avis-marker {
    background: transparent !important;
    border: none !important;
}

.avis-marker svg {
    filter: drop-shadow(0 2px 6px rgba(198, 40, 40, 0.35));
    animation: avis-pulse 2s ease-in-out infinite;
}

@keyframes avis-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* ---- RUTA CARD IN TRAM DETAILS (.exp-main) ---- */
#tramWpLink:empty {
    display: none;
}

/* ---- SIDEBAR RUTA DETAILS ---- */
.rightsidebar .tag-lst a {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'Poppins-Medium', system-ui, sans-serif;
    background: rgba(0, 127, 111, 0.08);
    color: #007F6F;
    border: 1px solid rgba(0, 127, 111, 0.15);
    text-decoration: none;
}

.rightsidebar .tag-lst a.active {
    background: #007F6F;
    color: #fff;
}

.rightsidebar .area-details h4 {
    font-family: 'Poppins-Semibold', system-ui, sans-serif;
}

.rightsidebar .fitxa-btn:hover {
    background: #005E52 !important;
}

#tramWpLink {
    margin-top: 14px;
    border-top: 1px solid #eee;
    padding-top: 14px;
}

#tramWpLink .exp-main {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(0, 127, 111, 0.12);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

#tramWpLink .exp-img {
    width: 100%;
    overflow: hidden;
}

#tramWpLink .exp-img img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}

#tramWpLink .exp-txt {
    padding: 14px 16px;
}

#tramWpLink .exp-txt h2 {
    font-family: 'Poppins-Semibold', system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.3;
    color: #1A1A1A;
    margin-bottom: 4px;
}

#tramWpLink .exp-txt h3 {
    font-family: 'Poppins-Regular', system-ui, sans-serif;
    font-size: 12px;
    color: #888;
    margin-bottom: 10px;
}

#tramWpLink .exp-txt h3 span {
    color: #007F6F;
}

#tramWpLink .veure-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    height: 34px;
    border-radius: 50px;
    background: #007F6F;
    color: #fff;
    font-size: 13px;
    font-family: 'Poppins-Semibold', system-ui, sans-serif;
    text-decoration: none;
    transition: background 0.3s ease;
    width: 100%;
}

#tramWpLink .veure-link:hover {
    background: #005E52;
    color: #fff;
}

/* =============================================
   FLOATING DOCK while planner is collapsed mid-planning.
   Has two actions:
     - "Tornar al planificador" → re-opens the sidebar
     - "✕" → exits planning mode entirely (so feature clicks can again
       show predefined tram cards / consult mode).
   Lives outside the .planificia-sidebar (which uses translateX to hide)
   so it stays visible when the sidebar is collapsed but the user is
   still in planning mode.
   ============================================= */
#returnToPlanner {
    display: none;
    position: fixed;
    top: 78px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    /* Amplada segons el contingut: amb left:50% + translateX el navegador
       només li deixa mitja pantalla i el text es partia en 2 línies. */
    width: max-content;
    max-width: calc(100vw - 24px);
    align-items: stretch;
    gap: 8px;
    font-family: 'Poppins-Semibold', system-ui, sans-serif;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
#returnToPlanner .rtp-open {
    display: inline-flex;
    white-space: nowrap; /* sempre en una sola línia */
    align-items: center;
    padding: 0 18px;
    height: 40px;
    background: #007F6F;
    color: #fff;
    border-radius: 20px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    text-decoration: none;
    transition: background 0.2s ease;
}
#returnToPlanner .rtp-open:hover {
    background: #006658;
}
#returnToPlanner .rtp-exit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: #fff;
    color: #333;
    border: 2px solid rgba(51, 51, 51, 0.45);
    border-radius: 50%;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
    font-size: 16px;
    text-decoration: none;
    transition: background 0.2s ease, border-color 0.2s ease;
}
#returnToPlanner .rtp-exit:hover {
    background: #fde6ea;
    border-color: #c62828;
    color: #c62828;
}
/* Show only when planning mode is active AND the sidebar is collapsed.
   A JS toggle keeps body.planner-collapsed in sync with the sidebar. */
body.planning-active.planner-collapsed #returnToPlanner {
    display: flex;
}

/* =============================================
   MÒBIL: "Marca al mapa", franja d'avís i targeta de resum de la ruta.
   Només a ≤991px (a l'ordinador el mapa ja es veu al costat del formulari).
   ============================================= */
.plan-map-pick,
#mapPickBanner,
#routeMobileCard {
    display: none;
}

@media (max-width: 991px) {
    /* Botó sota cada camp del formulari */
    .plan-map-pick {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        margin: 6px 0 2px;
        padding: 6px 12px;
        background: #e6f2f0;
        color: #007F6F;
        border: 1px solid rgba(0, 127, 111, 0.35);
        border-radius: 16px;
        font-family: 'Poppins-Semibold', system-ui, sans-serif;
        font-size: 12.5px;
        line-height: 1.2;
        cursor: pointer;
    }
    .plan-map-pick:active { background: #cfe7e3; }

    /* Franja "Toca el mapa per situar…" mentre es marca un punt */
    #mapPickBanner.visible {
        display: flex;
        align-items: center;
        gap: 10px;
        position: fixed;
        top: 78px;
        left: 12px;
        right: 12px;
        z-index: 2100;
        padding: 10px 12px 10px 14px;
        background: #007F6F;
        color: #fff;
        border-radius: 12px;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
        font-family: 'Poppins-Semibold', system-ui, sans-serif;
        font-size: 13.5px;
        line-height: 1.3;
    }
    #mapPickBanner .mpb-text { flex: 1 1 auto; }
    #mapPickBanner .mpb-cancel {
        flex: 0 0 auto;
        background: #fff;
        color: #007F6F;
        border: 0;
        border-radius: 16px;
        padding: 7px 12px;
        font: inherit;
        font-size: 12.5px;
        cursor: pointer;
    }

    /* Mentre es marca un punt o hi ha la targeta, el dock "Tornar al
       planificador" sobra (la franja i la targeta ja hi donen accés). */
    body.map-picking #returnToPlanner,
    body.route-card-visible #returnToPlanner {
        display: none !important;
    }
    /* Amb un modal obert (p. ex. previsualització del PDF) s'amaguen, i
       tornen a sortir en tancar-lo. */
    body:has(.custom-modal-overlay.active) #routeMobileCard,
    body:has(.custom-modal-overlay.active) #mapPickBanner {
        display: none !important;
    }

    /* Targeta de resum de la ruta, a baix del mapa */
    #routeMobileCard.visible {
        display: block;
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: 10px;
        z-index: 2100;
        max-height: 60vh;
        overflow: auto;
        padding: 12px 14px;
        background: #fff;
        border-radius: 14px;
        box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.22);
        font-family: 'Poppins-Regular', system-ui, sans-serif;
        color: #222;
    }
    #routeMobileCard .rmc-head {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    #routeMobileCard .rmc-title {
        flex: 1 1 auto;
        min-width: 0;
        font-family: 'Poppins-Semibold', system-ui, sans-serif;
        font-size: 14px;
        color: #007F6F;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    #routeMobileCard .rmc-sub {
        display: none;
        font-size: 13px;
        color: #555;
        white-space: nowrap;
    }
    #routeMobileCard .rmc-min,
    #routeMobileCard .rmc-close {
        flex: 0 0 auto;
        width: 32px;
        height: 32px;
        padding: 0;
        border: 0;
        border-radius: 50%;
        background: #f1f4f3;
        color: #333;
        font-size: 16px;
        line-height: 32px;
        cursor: pointer;
    }
    #routeMobileCard .rmc-stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        margin: 10px 0 12px;
    }
    #routeMobileCard .rmc-stats > div {
        min-width: 0;
        padding: 8px;
        background: #f7faf9;
        border-radius: 10px;
    }
    #routeMobileCard .rmc-l {
        display: block;
        margin-bottom: 2px;
        font-size: 11px;
        color: #6d7a77;
    }
    #routeMobileCard .rmc-v {
        display: block;
        font-family: 'Poppins-Semibold', system-ui, sans-serif;
        font-size: 13px;
        color: #11221f;
        overflow-wrap: anywhere;
    }
    #routeMobileCard .rmc-actions {
        display: flex;
        gap: 8px;
    }
    #routeMobileCard .rmc-details,
    #routeMobileCard .rmc-pdf {
        height: 40px;
        border-radius: 20px;
        font-family: 'Poppins-Semibold', system-ui, sans-serif;
        font-size: 13px;
        cursor: pointer;
    }
    #routeMobileCard .rmc-details {
        flex: 1 1 auto;
        background: #007F6F;
        color: #fff;
        border: 0;
    }
    #routeMobileCard .rmc-pdf {
        flex: 0 0 90px;
        background: #fff;
        color: #007F6F;
        border: 2px solid #007F6F;
    }
    /* Minimitzada: només la capçalera amb la distància */
    #routeMobileCard.min .rmc-body { display: none; }
    #routeMobileCard.min .rmc-sub { display: inline; }
    #routeMobileCard.min .rmc-head { cursor: pointer; }
}

/* =============================================
   LANG SELECTOR (planificador header)
   Uses the same WPML link+submenu pattern as template-parts/header-main.php.
   ============================================= */
/* Direct child only — otherwise the !important would also apply to the
   nested .sub-menu-langs <ul> and keep it permanently visible. */
.planificador-lang-sec > ul {
    display: flex !important;
    flex-wrap: nowrap;
    align-items: center;
    column-gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}
.planificador-lang-sec .planificador-lang-selector {
    display: inline-flex !important;
    position: relative;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
}
.planificador-lang-sec .planificador-lang-selector a.lang {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    color: #222;
    font-family: 'Poppins-Bold', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    letter-spacing: 0.5px;
    border: 2px solid rgba(51, 51, 51, 0.27);
    border-radius: 21px;
    height: 42px;
    box-sizing: border-box;
    background: #fff;
    transition: border-color 0.2s ease, color 0.2s ease;
}
.planificador-lang-sec .planificador-lang-selector a.lang:hover {
    color: #007F6F;
    border-color: #007F6F;
}
.planificador-lang-sec .lang-arrow {
    font-size: 11px;
    margin-left: 2px;
}
.planificador-lang-sec .sub-menu-langs {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 130px;
    margin: 0;
    padding: 6px 0;
    list-style: none;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
    z-index: 10000;
}
.planificador-lang-sec .planificador-lang-selector.is-open .sub-menu-langs {
    display: block;
}
.planificador-lang-sec .sub-menu-langs li {
    list-style: none;
    margin: 0;
}
.planificador-lang-sec .sub-menu-langs li a {
    display: block;
    padding: 8px 16px;
    color: #222;
    font-family: 'Poppins-Semibold', system-ui, sans-serif;
    font-size: 14px;
    text-decoration: none;
    text-transform: none;
    transition: background 0.15s ease, color 0.15s ease;
}
.planificador-lang-sec .sub-menu-langs li a:hover {
    background: #f5f8f7;
    color: #007F6F;
}

/* =============================================
   RESPONSIVE FIXES (mobile / tablet)
   ============================================= */
@media (max-width: 991px) {
    /* The right-sidebar (tram details "veure més") was cut off because the
       inner scroller didn't always pick up its parent's height. Anchor
       the panel to the viewport explicitly so the inner scroll works
       regardless of how the outer .mapa-sec is sized at runtime. */
    .rightsidebar {
        position: fixed !important;
        top: 105px !important;
        right: 0 !important;
        height: calc(100vh - 60px) !important;
        max-height: calc(100vh - 60px) !important;
        width: 100% !important;
        overflow: hidden !important;
    }
    .rightsidebar .right-scroll-div {
        height: 100% !important;
        max-height: 100% !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 100px !important;
        box-sizing: border-box;
    }

    /* Same anchoring for the planificia-sidebar so the route summary /
       elevation / POI list don't get cut off. */
    .planificia-sidebar {
        position: fixed !important;
        top: 60px !important;
        left: 0 !important;
        height: calc(100vh - 60px) !important;
        max-height: calc(100vh - 60px) !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden !important;
    }
    .planificia-sidebar .planificia-scroll-div {
        height: 100% !important;
        max-height: calc(100vh - 130px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 80px !important;
        box-sizing: border-box;
    }

    /* Show a clear "Veure mapa" pill instead of the tiny floating icon, so
       the user can hide the planner and click the map (this is the only way
       to place A/B points on the map on mobile, where the planner covers it). */
    a.apliar-mapa-btn {
        width: auto !important;
        min-width: 130px;
        height: 38px !important;
        padding: 0 14px 0 14px !important;
        font-size: 13px !important;
        font-family: 'Poppins-Semibold', system-ui, sans-serif;
        font-weight: 600;
        text-transform: uppercase;
        color: #007F6F;
        background: #fff !important;
        border: 2px solid #007F6F !important;
        border-radius: 20px !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22) !important;
        z-index: 1001;
        text-indent: 0 !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 12px;
        right: 12px;
    }
    /* Read the localized label from the data-label attribute JS sets on
       the button so this stays translatable via WPML. */
    a.apliar-mapa-btn::before {
        content: attr(data-label);
    }
    /* Hide the original "Planificador" text node + the two icon spans —
       we replace them with the CSS ::before label sourced from data-label. */
    a.apliar-mapa-btn {
        font-size: 0 !important;
    }
    a.apliar-mapa-btn::before {
        font-size: 13px;
    }
    a.apliar-mapa-btn .apliar-desk-ico,
    a.apliar-mapa-btn .apliar-mob-ico {
        display: none !important;
    }

    /* Don't hide the (only) lang <li> just because it's last-child. */
    .lang-sec ul li:last-child {
        display: flex !important;
    }
}
