/* -----------------------------
    Petruth Smart Gallery — CLEAN & RESPONSIVE
    ----------------------------- */

.psmg-gallery-container {
    max-width: 1200px;
    margin: 40px auto;
    padding: 0 16px;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

/* -----------------------------
    SEARCH BAR
    ----------------------------- */
.psmg-search-container {
    display: flex;
    justify-content: center;
    margin-bottom: 25px;
    width: 100%;
}

.psmg-search-bar {
    width: 100%;
    max-width: 100%;
    padding: 12px 20px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    color: #000;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    transition: all 0.3s ease;
    outline: none;
    box-sizing: border-box;
}

/* Neutralize search focus color, allowing it to be controlled by theme or remain neutral */
.psmg-search-bar:focus {
    border-color: #a0a0a0; /* Changed from hardcoded #8873c3 */
    box-shadow: 0 0 0 2px rgba(160, 160, 160, 0.2); /* Changed from hardcoded rgba(136,115,195,0.2) */
}

.psmg-search-bar::placeholder {
    color: #6b7280;
}

/* -----------------------------
    FILTER BUTTONS (Dynamic Color Handled by Inline Style)
    ----------------------------- */
.psmg-filters {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 30px;
}

.psmg-filters button {
    /* REMOVED: background: #8873c3; */
    color: #fff;
    /* REMOVED: border: 1px solid #8873c3; */
    border: 1px solid transparent; /* Set transparent border to maintain padding consistency */
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.psmg-filters button.active,
.psmg-filters button:hover {
    /* The active/hover background is now handled by the darker color calculated in the PHP inline style */
    color: #fff;
}

/* -----------------------------
    GRID LAYOUT
    ----------------------------- */
.psmg-gallery-grid {
    display: grid;
    gap: 24px;
}

/* Default/fallback */
.psmg-gallery-grid:not([class*="psmg-columns-"]) {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* 2 Columns */
.psmg-columns-2 {
    grid-template-columns: repeat(2, 1fr);
}

/* 3 Columns */
.psmg-columns-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* 4 Columns */
.psmg-columns-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* 5 Columns */
.psmg-columns-5 {
    grid-template-columns: repeat(5, 1fr);
}

/* Responsive behavior for smaller screens */
@media (max-width: 1200px) {
    .psmg-columns-5 {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 992px) {
    .psmg-columns-4,
    .psmg-columns-5 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .psmg-columns-3,
    .psmg-columns-4,
    .psmg-columns-5 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .psmg-gallery-grid {
        grid-template-columns: 1fr;
    }
}

/* ITEM CARD */
.psmg-gallery-grid .psmg-item {
    background: #111 !important;
    border-radius: 14px !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
    padding: 0 !important;
    margin: 0 !important;
}
.psmg-item.psmg-hidden {
    display: none !important;
}


.psmg-gallery-grid .psmg-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15) !important;
}

/* IMAGE */
.psmg-gallery-grid .psmg-item .psmg-image-inner {
    border-top-left-radius: 14px !important;
    border-top-right-radius: 14px !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    position: relative; /* Added for aspect-ratio */
    width: 100%; /* Added for aspect-ratio */
}

/* Default image height when titles are shown */
.psmg-gallery-grid .psmg-item .psmg-image-inner img {
    width: 100% !important;
    height: 220px !important; /* Fixed height for when titles are present */
    object-fit: cover !important;
    display: block !important;
    transition: transform 0.3s ease;
    margin: 0 !important;
    padding: 0 !important;
}

/* NEW: Adjust image aspect ratio when titles are hidden */
.psmg-gallery-container.psmg-no-titles .psmg-gallery-grid .psmg-item .psmg-image-inner {
    aspect-ratio: 1 / 1; /* Makes the image container square */
    height: auto; /* Allow aspect-ratio to control height */
}

.psmg-gallery-container.psmg-no-titles .psmg-gallery-grid .psmg-item .psmg-image-inner img {
    height: 100% !important; /* Image fills the square container */
}


.psmg-gallery-grid .psmg-item:hover .psmg-image-inner img {
    transform: scale(1.05);
}

/* INFO SECTION */
.psmg-gallery-grid .psmg-item .psmg-info {
    padding: 22px 22px 30px 22px !important;
    display: flex !important;
    flex-direction: column !important;
    flex-grow: 1 !important;
    /* background: handled by inline style */
    box-sizing: border-box !important;
    width: 100% !important;
    margin: 0 !important;
    min-height: 0; /* Important for flex items when collapsing */
}

/* When titles are hidden, hide the entire info block completely */
.psmg-gallery-container.psmg-no-titles .psmg-gallery-grid .psmg-item .psmg-info {
    display: none !important;
}

.psmg-gallery-grid .psmg-item .psmg-info .psmg-title {
    margin: 0 !important;
    font-size: 17px !important;
    font-weight: 600 !important;
    color: #fff !important;
    line-height: 1.3 !important;
    padding: 0 !important;
}

/* HIDE DESCRIPTION & TAGS */
.psmg-gallery-grid .psmg-item .psmg-info .psmg-description,
.psmg-gallery-grid .psmg-item .psmg-info .psmg-keywords {
    display: none !important;
}

/* -----------------------------
    RESPONSIVE DESIGN
    ----------------------------- */
@media (max-width: 900px) {
    /* Keep existing heights when titles are present */
    .psmg-gallery-grid .psmg-item .psmg-image-inner img { height: 200px !important; }
    .psmg-gallery-grid .psmg-item .psmg-info { padding: 20px !important; }
    
    /* Ensure aspect-ratio still applies when titles are hidden */
    .psmg-gallery-container.psmg-no-titles .psmg-gallery-grid .psmg-item .psmg-image-inner img { height: 100% !important; }
}

@media (max-width: 768px) {
    /* ... (rest of this block remains the same, but similar logic for .psmg-no-titles) */
    .psmg-gallery-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    .psmg-filters {
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 15px;
        margin-bottom: 20px;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .psmg-filters::-webkit-scrollbar {
        height: 4px;
    }

    .psmg-filters::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 2px;
    }

    .psmg-filters::-webkit-scrollbar-thumb {
        background: #c1c1c1;
        border-radius: 2px;
    }

    .psmg-filters button {
        white-space: nowrap;
        flex-shrink: 0;
        color: #fff !important;
    }

    /* Keep existing heights when titles are present */
    .psmg-gallery-grid .psmg-item .psmg-image-inner img { height: 180px !important; }
    .psmg-gallery-grid .psmg-item .psmg-info { padding: 18px !important; }

    /* Ensure aspect-ratio still applies when titles are hidden on smaller screens */
    .psmg-gallery-container.psmg-no-titles .psmg-gallery-grid .psmg-item .psmg-image-inner img { height: 100% !important; }


    .psmg-gallery-grid .psmg-item .psmg-info .psmg-title {
        margin: 0 !important;
        font-size: 16px !important;
        line-height: 1.4 !important;
    }
}

@media (max-width: 600px) {
    /* ... (rest of this block remains the same) */
    .psmg-gallery-container {
        padding: 0 12px;
        margin: 20px auto;
    }

    /* Keep existing heights when titles are present */
    .psmg-gallery-grid .psmg-item .psmg-image-inner img { height: 160px !important; }
    .psmg-gallery-grid .psmg-item .psmg-info { padding: 16px !important; }

    /* Ensure aspect-ratio still applies when titles are hidden on smallest screens */
    .psmg-gallery-container.psmg-no-titles .psmg-gallery-grid .psmg-item .psmg-image-inner img { height: 100% !important; }

    .psmg-gallery-grid .psmg-item .psmg-info .psmg-title {
        font-size: 15px !important;
    }

    .psmg-filters {
        gap: 6px;
    }

    .psmg-filters button {
        padding: 5px 12px;
        font-size: 12px;
    }
}


/* -----------------------------
    LIGHTBOX (No changes needed here)
    ----------------------------- */
#psmg-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 40px 20px;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}
/* ... (rest of lightbox CSS remains unchanged) ... */
.psmg-lightbox-content {
    background: #fff;
    border-radius: 16px;
    max-width: 1200px;
    max-height: 90vh;
    width: 95vw;
    height: auto;
    padding: 0;
    position: relative;
    display: flex;
    box-shadow: 0 25px 80px rgba(0,0,0,0.4);
    overflow: hidden;
}

#psmg-lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 32px;
    color: #666;
    cursor: pointer;
    background: rgba(255,255,255,0.9);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

#psmg-lightbox-close:hover {
    color: #000;
    background: #fff;
    transform: scale(1.1);
}

/* LIGHTBOX IMAGE */
.psmg-lightbox-image {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    padding: 40px;
    min-height: 500px;
}

#psmg-lightbox-img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 12px;
    object-fit: contain;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

/* LIGHTBOX INFO */
.psmg-lightbox-info {
    flex: 0 0 400px;
    padding: 40px;
    background: #fff;
    border-left: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
    max-height: 80vh;
}

#psmg-lightbox-title {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    color: #111;
    line-height: 1.2;
}

.psmg-lightbox-section h4 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#psmg-lightbox-caption {
    margin: 0;
    font-size: 16px;
    color: #6b7280;
    line-height: 1.6;
}

.psmg-lightbox-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.psmg-lightbox-keyword {
    background: #f3f4f6;
    color: #374151;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid #e5e7eb;
}

.psmg-lightbox-meta {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

.psmg-lightbox-meta-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #6b7280;
}

.psmg-lightbox-download {
    background: #000;
    color: #fff;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    margin-top: auto;
}

.psmg-lightbox-download:hover {
    background: #333;
    transform: translateY(-1px);
}

/* RESPONSIVE LIGHTBOX */
@media (max-width: 968px) {
    .psmg-lightbox-content {
        flex-direction: column;
        max-height: 95vh;
    }

    .psmg-lightbox-image {
        padding: 30px;
        min-height: 300px;
    }

    .psmg-lightbox-info {
        flex: none;
        border-left: none;
        border-top: 1px solid #e5e7eb;
        max-height: 40vh;
    }

    #psmg-lightbox-title {
        font-size: 24px;
    }
}

@media (max-width: 640px) {
    #psmg-lightbox {
        padding: 20px 10px;
    }

    .psmg-lightbox-content {
        width: 100vw;
    }

    .psmg-lightbox-image {
        padding: 20px;
    }

    .psmg-lightbox-info {
        padding: 30px 20px;
    }
}