/* 
   PORTFOLIO.CSS 
   Isolated Styles specifically for portfolio.php
   Depends ONLY on main.css (Variable definitions)
*/

/* --- Page Setup --- */
body {
    background-color: #f9f9f9;
}

/* --- Hero Section --- */
.portfolio-hero {
    position: relative;
    height: 50vh;
    min-height: 400px;
    background-color: var(--primary-red);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--white);
    overflow: hidden;
}

.portfolio-hero .hero-content {
    position: relative;
    z-index: 2;
    padding: 2rem;
    max-width: 800px;
}

.portfolio-hero h1 {
    font-size: 4rem;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.portfolio-hero .subtitle {
    font-size: 1.5rem;
    font-weight: 300;
    opacity: 0.9;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    animation: fadeInUp 0.8s ease-out forwards;
}

.delay-1 {
    animation-delay: 0.2s;
}

.texture-overlay {
    pointer-events: none;
}

/* --- Lightbox Modal --- */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lightbox-overlay.active {
    display: flex;
    opacity: 1;
}

.lightbox-image {
    max-width: 90%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    animation: lightboxZoomIn 0.3s ease-out;
}

@keyframes lightboxZoomIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 3rem;
    color: var(--white);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 50px;
    height: 50px;
    line-height: 1;
    transition: transform 0.2s ease, color 0.2s ease;
    z-index: 10000;
}

.lightbox-close:hover {
    color: var(--primary-red);
    transform: scale(1.1);
}

/* Lightbox Navigation Buttons */
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: var(--white);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10001;
    padding: 0;
}

.lightbox-prev {
    left: 30px;
}

.lightbox-next {
    right: 30px;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-50%) scale(1.1);
}

.lightbox-nav svg {
    width: 28px;
    height: 28px;
}

/* Lightbox Counter */
.lightbox-counter {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    color: var(--white);
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 500;
    z-index: 10001;
    letter-spacing: 1px;
}

/* --- Advanced Grid Layout --- */
.portfolio-section {
    padding: 4rem 2rem;
    max-width: 1600px;
    margin: 0 auto;
}

.portfolio-grid {
    display: grid;
    /* This creates the logic. Dense flow fills holes. */
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    grid-auto-rows: 400px;
    gap: 2rem;
    grid-auto-flow: dense;
    transition: all 0.5s ease;
}

/* Grid Item Base */
.portfolio-item {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    background-color: var(--white);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1), box-shadow 0.4s ease, opacity 0.3s ease;
    /* Important for the expanded full-width transition to feel simpler */
    display: flex;
    flex-direction: column;
}

.portfolio-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

/* Layout Variations (collapsed state) */
.layout-wide {
    grid-column: span 2;
}

.layout-tall {
    grid-row: span 2;
}

.layout-big {
    grid-column: span 2;
    grid-row: span 2;
}

/* 
   === EXPANDED STATE === 
   When active, the item takes full row width 
*/

.portfolio-item.is-expanded {
    grid-column: 1 / -1;
    /* Span entire grid width */
    grid-row: span auto;
    /* Allow auto height */
    height: auto;
    /* Override fixed height */
    min-height: 400px;
    z-index: 10;
    transition: grid-column 0s;
    /* Instant grid change, animate content instead */
}

/* Disable hover effects for expanded items */
.portfolio-item.is-expanded:hover {
    transform: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

/* Inner Content Structure */
.item-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 400px;
    /* Ensure visual height in collapsed mode */
    flex-shrink: 0;
    /* Keep it fixed */
}

/* When expanded, item inner becomes the hero of the expansion */
.portfolio-item.is-expanded .item-inner {
    height: 400px;
    /* Fixed height for header part */
}

.item-image {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: #ffffff;
    /* Fix: White background */
}

.item-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.6s ease, filter 0.4s ease;
    filter: blur(0px);
}

/* ... (intervening lines omitted to avoid large match block) ... */

/* Gallery Grid */
.project-gallery h3 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    align-items: start;
    /* Fix: prevent stretching */
}

.gallery-item {
    height: auto;
    /* Fix: Natural height */
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    background: #fff;
}

.gallery-item img {
    width: 100%;
    height: auto;
    /* Fix: Natural ratio */
    display: block;
    object-fit: contain;
    transition: transform 0.5s;
}

.gallery-item:hover img {
    transform: scale(1.02);
}

.portfolio-item:hover .item-image img,
.portfolio-item.is-preview .item-image img {
    transform: scale(1.05);
}

/* Expanded state: no hover effect at all */
.portfolio-item.is-expanded .item-image img {
    transform: none;
    filter: none;
}

.portfolio-item.is-expanded:hover .item-image img {
    transform: none;
    filter: none;
}

.item-image .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary-red);
    opacity: 0;
    transition: opacity 0.4s;
}

.portfolio-item:hover .item-image .overlay,
.portfolio-item.is-preview .item-image .overlay {
    opacity: 0.85;
}

/* No overlay in expanded state */
.portfolio-item.is-expanded .item-image .overlay {
    opacity: 0;
}

.portfolio-item.is-expanded:hover .item-image .overlay {
    opacity: 0;
}

/* Content over image */
.item-content {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 2rem;
    color: var(--white);
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.4s ease, opacity 0.4s ease;
    z-index: 2;
    pointer-events: none;
}

.portfolio-item:hover .item-content,
.portfolio-item.is-preview .item-content {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Hide content in expanded state */
.portfolio-item.is-expanded .item-content {
    opacity: 0;
    pointer-events: none;
}

.category-tag {
    font-size: 0.8rem;
    letter-spacing: 1px;
    color: #ffcccb;
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.item-content h2 {
    font-family: var(--font-headline);
    font-size: 2rem;
    margin-bottom: 1rem;
    line-height: 1.1;
}

/* Teaser content (hidden details initially or partially shown) */
.item-teaser p {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    /* Truncate text */
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Button & Tags */
.btn-link {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    background: var(--primary-red);
    color: var(--white);
    text-decoration: none;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: background 0.3s;
    margin-right: 1rem;
}

.btn-link:hover {
    background: var(--dark-red);
}

.tags {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 8px;
    border-radius: 10px;
}

/* 
    === EXPANDABLE DETAILS PANEL === 
*/
.item-details-expandable {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.5s ease-out;
    background: var(--white);
    color: var(--text-color);
}

.portfolio-item.is-expanded .item-details-expandable {
    grid-template-rows: 1fr;
    /* Reveal content */
    border-top: 1px solid #eee;
}

.details-content-wrapper {
    overflow: hidden;
    padding: 0 2rem;
    /* Vertical padding handled by wrapper margins inside to avoid jump */
}

.portfolio-item.is-expanded .details-content-wrapper {
    padding: 3rem 2rem 30px 2rem;
}

.details-text {
    max-width: 800px;
    margin-bottom: 3rem;
}

.details-text h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--primary-red);
}

.details-text p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

/* Gallery Grid */
.project-gallery h3 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    align-items: start;
    /* Fix: prevent stretching */
}

.gallery-item {
    height: auto;
    /* Fix: Natural height */
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    background: #fff;
}

.gallery-item img {
    width: 100%;
    height: auto;
    /* Fix: Natural ratio */
    display: block;
    object-fit: contain;
    transition: transform 0.5s;
}

.gallery-item:hover img {
    transform: scale(1.02);
}

.btn-close-details {
    margin-top: 2rem;
    padding: 3rem 3rem;
    background: #9b1542;
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: bold;
    border-radius: 4px;
}

.btn-close-details:hover {
    background: #000;
}


/* --- Responsive Adjustments --- */

@media (max-width: 900px) {
    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: 350px;
    }

    .layout-wide,
    .layout-big {
        grid-column: span 2;
    }

    .portfolio-item.is-expanded .item-inner {
        height: 300px;
    }
}

@media (max-width: 600px) {
    .portfolio-grid {
        display: flex;
        flex-direction: column;
        gap: 2rem;
    }

    /* Reset grid specific behaviors for stack */
    .layout-wide,
    .layout-tall,
    .layout-big {
        grid-column: auto;
    }

    /* On mobile, standard item size */
    .portfolio-item {
        height: auto;
        min-height: 350px;
    }

    .portfolio-item.is-expanded {
        height: auto;
    }

    .item-inner {
        height: 300px;
    }

    .portfolio-hero h1 {
        font-size: 2.5rem;
    }

    .item-content {
        transform: translateY(0);
        background: rgba(0, 0, 0, 0.3);
        /* better readability on small screens */
    }

    /* Lightbox navigation for mobile */
    .lightbox-nav {
        width: 50px;
        height: 50px;
    }

    .lightbox-nav svg {
        width: 24px;
        height: 24px;
    }

    .lightbox-prev {
        left: 10px;
    }

    .lightbox-next {
        right: 10px;
    }

    .lightbox-counter {
        bottom: 20px;
        font-size: 0.9rem;
        padding: 8px 16px;
    }
}