/* ==========================================================================
   ESTILS PER A SUBPÀGINES DE PROJECTES INDIVIDUALS (LEVEL 3)
   Joan Artero Serra - Arquitectura & Disseny CAD
   ========================================================================== */

/* 1. Animacions Clàssiques de la Targeta de Projecte */
@keyframes submenuContentIn {
    0% {
        opacity: 0;
        transform: translateY(18px) scale(0.98);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes galleryItemPop {
    0% {
        opacity: 0;
        transform: translateY(18px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Subtítol de la pàgina (Top Left): format mixt normal (sense majúscules forçades) */
#txt-canviable,
#txt-canviable *,
#txt-canviable a,
#txt-canviable span,
.active-project-crumb,
.project-crumb-prefix,
.project-crumb-prefix a {
    text-transform: none !important;
}

/* 2. Layout Principal de la Subpàgina */
html {
    background-color: var(--bg-color, #f0f1f3);
    color-scheme: light dark;
}

html.mode-fosc,
html.dark,
html[data-theme="dark"] {
    background-color: #161718;
    color-scheme: dark;
}

body[data-project-page="true"],
body.is-level-3 {
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    background: transparent;
    color: var(--text-color, #111111);
}

.project-page-wrapper {
    position: relative;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
    z-index: 10;
}

/* Fons de Graella CAD dinàmica */
.project-page-wrapper .grid-canvas {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    z-index: 1;
    pointer-events: none;
    opacity: 1;
    transform-origin: center center;
    transform: translate3d(0, 0, 0) scale3d(var(--zoom-scale, 1.35), var(--zoom-scale, 1.35), 1);
    background-size: 36px 36px;
    background-position: center center;
    background-repeat: repeat;
    will-change: background-image;
}

/* 3. Contenidor del Detall del Projecte */
.project-detail-container {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 82px 40px 32px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    flex: 1 0 auto;
    justify-content: space-between;
    animation: submenuContentIn 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.project-detail-body {
    display: grid;
    grid-template-columns: 310px 1fr;
    gap: 56px;
    flex: 1;
    min-height: 0;
    align-items: center;
    padding: 10px 0;
}

/* 4. Columna Esquerra: Metadades i Memòria Conceptual */
.project-info-pane {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    height: auto;
    max-height: 100%;
    max-width: 310px;
}

.project-meta-top {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 10.5px;
    letter-spacing: 1px;
    color: var(--ui-muted, #6e6e73);
    margin-bottom: 0px;
}

.project-badge {
    font-weight: 600;
    color: var(--ui-muted, #6e6e73);
}

.project-badge-cat {
    color: var(--ui-muted, #6e6e73);
    font-weight: 600;
    letter-spacing: 0.8px;
}

.project-meta-top .nav-slash {
    color: var(--ui-muted, #6e6e73);
    font-weight: 600;
}

.project-title {
    font-size: clamp(22px, 2.4vw, 30px);
    font-weight: 700;
    letter-spacing: 0.8px;
    margin: 0 0 2px 0;
    line-height: 1.15;
    color: var(--text-color);
    word-break: break-word;
}

.project-subtitle {
    font-size: 11px;
    letter-spacing: 0.6px;
    color: var(--ui-muted, #6e6e73);
    margin: 0 0 4px 0;
    line-height: 1.3;
    opacity: 0.75;
    font-weight: 500;
}

/* Icona de portada en miniatura */
.project-icon-frame {
    position: relative;
    width: 86px;
    aspect-ratio: 4 / 5;
    margin: 0;
    border-radius: 4px;
    overflow: hidden;
    border: none !important;
    flex-shrink: 0;
    cursor: default;
    pointer-events: none;
    user-select: none;
}

:is(html.mode-fosc, body.mode-fosc, [data-theme="dark"]) .project-icon-frame {
    border: none !important;
}

.project-icon-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    border-radius: 4px;
    transition: filter 0.35s ease;
}

:is(html.mode-fosc, body.mode-fosc, [data-theme="dark"]) .project-icon-thumb {
    filter: none !important;
}

.project-desc-box {
    margin: 2px 0 4px 0;
}

/* Tamany de font original de la descripció */
.project-desc-text {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-color);
    opacity: 0.88;
    margin: 0;
    white-space: pre-line;
}

/* Indicador de col·laboració en cursiva (mateixa mida que el text de descripció) */
.project-collab {
    font-style: italic;
    font-size: 12px;
    line-height: 1.5;
    color: var(--ui-muted, #6e6e73);
    margin-top: 6px;
    margin-bottom: 0;
}

.project-collab em,
.project-desc-text em {
    font-style: italic;
}

/* Taula Tècnica CAD */
.project-tech-table {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 10.5px;
    letter-spacing: 0.6px;
    margin-top: 10px;
    padding-top: 2px;
}

.tech-row {
    display: flex;
    justify-content: space-between;
    padding-bottom: 3px;
    border-bottom: 1px dashed var(--border-subtle, rgba(0, 0, 0, 0.1));
}

:is(html.mode-fosc, body.mode-fosc, [data-theme="dark"]) .tech-row {
    border-bottom-color: rgba(255, 255, 255, 0.12);
}

.tech-key {
    color: var(--ui-muted, #6e6e73);
    font-weight: 700;
}

.tech-val {
    color: var(--text-color);
    text-align: right;
}

/* 5. Columna Dreta: Graella 3x2 de Plànols i Renders (Sense Borde) */
.project-gallery-pane {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    width: 100%;
    min-height: 0;
}

.gallery-grid-3x2 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 14px 16px;
    width: 100%;
    box-sizing: border-box;
}

.gallery-grid-3x2.grid-4-items {
    grid-template-columns: repeat(2, calc((100% - 32px) / 3));
    grid-template-rows: repeat(2, auto);
    justify-content: center;
}

/* Caixes de la galeria: vora eliminada completament, cantonades arrodonides recuperades */
.gallery-placeholder-box {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3 !important;
    background: rgba(0, 0, 0, 0.04);
    border: none !important;
    outline: none;
    border-radius: 4px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    overflow: hidden !important;
    cursor: zoom-in;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
    animation: galleryItemPop 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.gallery-placeholder-box:nth-child(1) { animation-delay: 0.08s; }
.gallery-placeholder-box:nth-child(2) { animation-delay: 0.16s; }
.gallery-placeholder-box:nth-child(3) { animation-delay: 0.24s; }
.gallery-placeholder-box:nth-child(4) { animation-delay: 0.32s; }
.gallery-placeholder-box:nth-child(5) { animation-delay: 0.40s; }
.gallery-placeholder-box:nth-child(6) { animation-delay: 0.48s; }

:is(html.mode-fosc, body.mode-fosc, [data-theme="dark"]) .gallery-placeholder-box {
    background: rgba(255, 255, 255, 0.05);
    border: none !important;
}

.gallery-placeholder-box:hover {
    transform: translateY(-4px) scale(1.025);
    border: none !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
    z-index: 10;
}

:is(html.mode-fosc, body.mode-fosc, [data-theme="dark"]) .gallery-placeholder-box:hover {
    border: none !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.gallery-placeholder-box:focus-visible {
    outline: 2px solid var(--text-color) !important;
    outline-offset: 2px !important;
}

.project-gallery-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    border: none !important;
    border-radius: 4px !important;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), filter 0.35s ease, opacity 0.3s ease;
}

.gallery-placeholder-box:hover .project-gallery-img {
    transform: scale(1.04);
}

:is(html.mode-fosc, body.mode-fosc, [data-theme="dark"]) .project-gallery-img {
    filter: none !important;
}

/* 6. Barra Inferior de Navegació Circular (Anterior / Portafoli / Següent) */
.project-bottom-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 14px;
    border-top: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.1));
    margin-top: 10px;
    box-sizing: border-box;
}

:is(html.mode-fosc, body.mode-fosc, [data-theme="dark"]) .project-bottom-nav {
    border-top-color: rgba(255, 255, 255, 0.14);
}

.project-nav-prev-wrap,
.project-nav-center-wrap,
.project-nav-next-wrap {
    display: inline-flex;
    align-items: center;
}

/* Botons de navegació i obrir portafoli idèntics sense vora (Estil Original) */
.project-nav-btn,
.project-portfolio-btn {
    background: transparent !important;
    border: none !important;
    color: var(--text-color) !important;
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.8px;
    cursor: pointer;
    padding: 8px 6px;
    border-radius: 0;
    opacity: 0.85;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: opacity 0.2s ease, transform 0.15s ease;
}

.project-nav-btn:hover,
.project-portfolio-btn:hover {
    opacity: 1;
    transform: translateY(-1px);
    background: transparent !important;
    color: var(--text-color) !important;
}

.project-nav-btn:focus-visible,
.project-portfolio-btn:focus-visible {
    outline: 2px solid var(--text-color) !important;
    outline-offset: 2px !important;
}

.desktop-nav-text {
    display: inline;
}

.mobile-nav-arrow {
    display: none;
}

/* Peu de pàgina: Xarxes Socials & Compartir a subpàgines de projectes */
.page-socials {
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    z-index: 300 !important;
}

/* Botó de retornar als projectes a la barra superior */
.top-return-btn {
    background: transparent;
    border: none;
    color: var(--text-color, #111111);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    cursor: pointer;
    text-decoration: none;
    padding: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-bottom: 1px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
    line-height: inherit;
}

.top-return-btn .desktop-return-text {
    display: inline;
}

.top-return-btn .mobile-return-arrow {
    display: none;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
}

.top-return-btn .icon-mobile-close {
    display: block;
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 1.2;
}

.top-return-btn:hover,
.top-return-btn:focus-visible {
    color: var(--ui-muted);
    border-bottom: 1px solid var(--text-color);
}

.top-return-btn:focus-visible {
    outline: 2px solid var(--text-color) !important;
    outline-offset: 2px !important;
}

/* 7. Visor d'Imatges Lightbox (Definit i mantingut de manera centralitzada a css/styles.css) */


/* Cursor interactiu per obrir la imatge ampliada */
.project-gallery-img {
    cursor: zoom-in;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Animació de sortida suau en tornar a la galeria */
body.leaving-page .project-detail-container {
    opacity: 0 !important;
    transform: translateY(12px) scale(0.985) !important;
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

/* ==========================================================================
   8. ADAPTACIONS PER A ESCRIPTORI (NO PERMETRE LLISCAR CAP ABAIX)
   ========================================================================== */
@media (min-width: 900px) {
    html,
    body[data-project-page="true"],
    body.is-level-3 {
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
    }

    .project-page-wrapper {
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .project-detail-container {
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        padding: 82px 40px 70px !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        box-sizing: border-box !important;
    }

    .project-detail-body {
        display: grid !important;
        grid-template-columns: 310px 1fr !important;
        gap: 56px !important;
        flex: 1 !important;
        min-height: 0 !important;
        align-items: center !important;
        padding: 12px 0 6px 0 !important;
        overflow: hidden !important;
    }

    .project-info-pane {
        display: flex;
        flex-direction: column;
        justify-content: center !important;
        gap: 8px;
        height: auto !important;
        max-height: 100% !important;
        max-width: 310px;
        min-height: 0;
        overflow-y: auto;
        scrollbar-width: none;
        padding-top: 0 !important;
    }

    .project-info-pane::-webkit-scrollbar {
        display: none;
    }

    .project-bottom-nav {
        margin-bottom: 8px !important;
    }

    .project-gallery-pane {
        display: flex;
        flex-direction: column;
        justify-content: center;
        height: 100%;
        width: 100%;
        min-height: 0;
        overflow: hidden;
    }
}

/* ==========================================================================
   9. ADAPTACIONS MÒBIL (< 900px)
   ========================================================================== */
@media (max-width: 899px) {
    /* 1. Bloqueig de desplaçament general: contingut contingut que no permet seguir lliscant un cop s'acaba la galeria */
    html,
    body[data-project-page="true"],
    body.is-level-3 {
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
    }

    .project-page-wrapper {
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .project-detail-container {
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        padding: 68px 16px 0 16px !important;
        max-width: 100% !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    .project-detail-body {
        display: flex !important;
        flex-direction: column !important;
        gap: 22px !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
        width: 100% !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior-y: contain !important;
        padding: 6px 2px 24px 2px !important;
        box-sizing: border-box !important;
    }

    /* Esvaïment superior progressiu a mòbil sota la capçalera */
    .project-top-glass {
        display: block !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 96px !important;
        pointer-events: none !important;
        z-index: 450 !important;
        background: linear-gradient(to bottom,
            var(--bg-color, #f0f1f3) 0%,
            var(--bg-color, #f0f1f3) 44px,
            rgba(240, 241, 243, 0.85) 62px,
            rgba(240, 241, 243, 0.45) 80px,
            transparent 96px
        ) !important;
    }

    body.mode-fosc .project-top-glass,
    html.mode-fosc .project-top-glass,
    [data-theme="dark"] .project-top-glass {
        background: linear-gradient(to bottom,
            var(--bg-color, #161718) 0%,
            var(--bg-color, #161718) 44px,
            rgba(22, 23, 24, 0.85) 62px,
            rgba(22, 23, 24, 0.45) 80px,
            transparent 96px
        ) !important;
    }

    .project-info-pane {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        flex-shrink: 0 !important;
        height: auto !important;
        min-height: auto !important;
        border-bottom: 1px solid var(--border-subtle, rgba(0, 0, 0, 0.1)) !important;
        padding-bottom: 14px !important;
        gap: 6px !important;
    }

    .project-header-row {
        display: flex !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        gap: 12px !important;
        width: 100% !important;
    }

    .project-header-texts {
        flex: 1 !important;
        min-width: 0 !important;
    }

    .project-title {
        font-size: 22px !important;
        margin: 0 0 2px 0 !important;
    }

    .project-subtitle {
        margin: 0 0 2px 0 !important;
        font-size: 11px !important;
    }

    .project-desc-text {
        font-size: 14px !important;
        line-height: 1.55 !important;
        margin-top: 8px !important;
        opacity: 0.95 !important;
    }

    .project-collab {
        font-size: 14px !important;
        line-height: 1.55 !important;
        margin-top: 6px !important;
    }

    .project-tech-table {
        margin-top: 10px !important;
        font-size: 11.5px !important;
        gap: 5px !important;
    }

    .project-gallery-pane {
        width: 100% !important;
        height: auto !important;
        min-height: auto !important;
        flex: none !important;
        display: block !important;
        margin-top: 8px !important;
        padding-bottom: 24px !important;
    }

    /* Imatges apilades en columna a mòbil */
    .gallery-grid-3x2,
    .gallery-grid-3x2.grid-4-items {
        display: flex !important;
        flex-direction: column !important;
        gap: 18px !important;
        width: 100% !important;
        height: auto !important;
        flex: none !important;
    }

    .gallery-placeholder-box {
        width: 100% !important;
        max-width: 100% !important;
        aspect-ratio: 4 / 3 !important;
        height: auto !important;
        flex: none !important;
        border: none !important;
        border-radius: 4px !important;
        overflow: hidden !important;
    }

    /* A mòbil mostrar només el títol del projecte al subtítol (eliminar 'Projectes /') */
    #txt-canviable .project-crumb-prefix,
    #txt-canviable a[data-i18n="sec_title_projectes"],
    #txt-canviable .nav-slash {
        display: none !important;
    }

    #txt-canviable .active-project-crumb {
        display: inline !important;
        margin-left: 0 !important;
        padding-left: 0 !important;
    }

    /* Botó de tornar a la barra superior: creu SVG del mateix tamany que les altres icones (38x38px botó, 22x22px icona) */
    .top-return-btn {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        background: transparent !important;
        line-height: 1 !important;
    }

    .top-return-btn .desktop-return-text {
        display: none !important;
    }

    .top-return-btn .mobile-return-arrow {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        height: 100% !important;
    }

    .top-return-btn .icon-mobile-close,
    .top-return-btn svg {
        width: 22px !important;
        height: 22px !important;
        stroke-width: 1.2 !important;
        display: block !important;
    }

    /* A mòbil eliminar completament els botons de la barra inferior (obrir al portafolis, següent i anterior projecte) */
    .project-bottom-nav {
        display: none !important;
    }

    /* Icones de compartir i xarxes socials amb el mateix marge inferior que la resta de la web */
    body.is-level-3 .page-socials,
    body[data-project-page="true"] .page-socials {
        position: fixed !important;
        right: 14px !important;
        bottom: calc(4px + env(safe-area-inset-bottom, 0px)) !important;
        z-index: 500 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-end !important;
        gap: 6px !important;
    }

}

/* ==========================================================================
   10. ACCESSIBILITAT: PREFERÈNCIA DE MOVIMENT REDUÏT (WCAG 2.3.3)
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    .project-detail-container,
    .gallery-placeholder-box,
    .project-gallery-img,
    .project-portfolio-btn,
    .project-nav-btn {
        animation: none !important;
        transition: none !important;
        transform: none !important;
    }
}
