.cloth-gallery-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    background: #fff;
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    margin: 0 0 16px 0;
}

.cloth-gallery-controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #444;
}

.cloth-gallery-controls select,
.cloth-gallery-controls input[type="text"] {
    appearance: none;
    -webkit-appearance: none;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 14px;
    min-width: 160px;
}

.cloth-gallery-controls input[type="text"] {
    min-width: 220px;
}

@media (max-width: 480px) {
    .cloth-gallery-controls label { width: 100%; justify-content: space-between; }
    .cloth-gallery-controls select,
    .cloth-gallery-controls input[type="text"] { width: 100%; }
}
.cloth-gallery-wrapper {
    margin: 20px 0;
    clear: both;
}

.cloth-gallery {
    display: grid;
    gap: 20px;
    margin: 0;
    padding: 0;
}

.cloth-no-results {
    text-align: center;
    padding: 40px 20px;
    background: #f9f9f9;
    border-radius: 8px;
    color: #666;
}

.cloth-gallery.columns-2 { grid-template-columns: repeat(2, 1fr); }
.cloth-gallery.columns-3 { grid-template-columns: repeat(3, 1fr); }
.cloth-gallery.columns-4 { grid-template-columns: repeat(4, 1fr); }
/* New wider grids */
.cloth-gallery.columns-5 { grid-template-columns: repeat(5, 1fr); }
.cloth-gallery.columns-6 { grid-template-columns: repeat(6, 1fr); gap: 12px; }

@media (max-width: 768px) {
    .cloth-gallery { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 480px) {
    .cloth-gallery { grid-template-columns: 1fr !important; }
}

.cloth-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.cloth-item:hover {
    transform: translateY(-2px);
}

.cloth-image-container {
    position: relative;
    aspect-ratio: 4/3;
    overflow: hidden;
}

.cloth-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer; /* image opens modal */
}

.cloth-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 2;
    pointer-events: none; /* not clickable until shown */
}

/* Programmatic visibility toggle (used by JS on mobile) */
.cloth-overlay.is-visible { opacity: 1; pointer-events: auto; display: flex; }

/* Show overlay icons on hover for desktop (width-based for touch laptops) */
@media (min-width: 769px) {
    .cloth-item:hover .cloth-overlay { 
        opacity: 1; 
        pointer-events: auto;
    }
    .cloth-item:hover .cloth-overlay .cloth-actions button {
        pointer-events: auto;
    }
}

/* On smaller screens, overlay stays hidden until JS adds .is-visible */
@media (max-width: 768px) {
    /* no display: none; keep it present so transitions/pointer-events can work */
}

.cloth-actions {
    display: flex;
    gap: 10px;
}

/* New placement: actions below the title and centered */
.cloth-actions.below-title {
    justify-content: center;
    padding: 12px 15px 16px;
    background: white;
    border-top: 1px solid #f0f0f0;
}

/* Hide below-title actions on desktop completely; use overlay instead */
@media (min-width: 769px) {
    .cloth-actions.below-title { display: none !important; }
}

/* Always show below-title icons on mobile/touch devices */
@media (hover: none) {
    .cloth-actions.below-title {
        opacity: 1;
    }
}

.cloth-actions button {
    background: white;
    border: none;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    transition: transform 0.2s ease;
    position: relative;
    z-index: 10;
    min-width: 60px;
    justify-content: center;
}

.cloth-actions button:hover { transform: scale(1.05); }

.cloth-title {
    padding: 15px;
    font-weight: bold;
    text-align: center;
    background: white;
}

/* Compact tweaks when many columns */
.cloth-gallery.columns-6 .cloth-item { box-shadow: 0 1px 5px rgba(0,0,0,0.08); }
.cloth-gallery.columns-6 .cloth-title { padding: 10px; font-size: 14px; }
.cloth-gallery.columns-6 .cloth-actions { gap: 8px; }
.cloth-gallery.columns-6 .cloth-actions.below-title { padding: 10px 12px 12px; }
.cloth-gallery.columns-6 .cloth-actions button { padding: 6px 9px; font-size: 12px; }

/* Scale overlay icons based on column count */
.cloth-gallery.columns-4 .cloth-overlay .cloth-actions button { 
    padding: 6px 10px; 
    font-size: 13px; 
    min-width: 50px; 
}
.cloth-gallery.columns-5 .cloth-overlay .cloth-actions button { 
    padding: 5px 8px; 
    font-size: 12px; 
    min-width: 45px; 
}
.cloth-gallery.columns-6 .cloth-overlay .cloth-actions button { 
    padding: 4px 7px; 
    font-size: 11px; 
    min-width: 40px; 
}
.cloth-gallery.columns-6 .cloth-overlay .cloth-actions { gap: 6px; }

.cloth-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    overflow-y: hidden; /* let the inner box handle scroll to avoid sticky left */
    overscroll-behavior: contain;
    touch-action: pan-y; /* ensure vertical scroll gestures are honored */
}

.modal-content {
    position: relative;
    margin: 2% auto;
    width: 90%;
    max-width: 1200px;
    height: 90%;
    background: white;
    border-radius: 10px;
    overflow: hidden;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 25px;
    font-size: 30px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10001;
    color: #666;
    border: none; /* remove default button border */
    background: transparent; /* ensure no background */
}

.modal-body { display: flex; height: 100%; }
.modal-left { flex: 1; position: relative; background: #f5f5f5; }

.image-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* required for zoom so image doesn't spill out */
}

#modal-image { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform 0.15s ease-out; }

.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    padding: 20px 15px;
    font-size: 24px;
    cursor: pointer;
    border-radius: 0 5px 5px 0;
}
.prev-btn { left: 0; }
.next-btn { right: 0; border-radius: 5px 0 0 5px; }

.modal-right { flex: 0 0 400px; padding: 30px; overflow-y: auto; }
#modal-title { margin: 0 0 15px 0; font-size: 24px; }
#modal-description { margin-bottom: 20px; line-height: 1.6; color: #666; }
#modal-sizes { margin-bottom: 25px; }
#modal-sizes:before { content: "Available Sizes: "; font-weight: bold; }

.modal-actions { display: flex; flex-direction: column; gap: 15px; align-items: flex-start; }
.modal-like-btn, .modal-share-btn {
    background: #f8f9fa;
    border: 1px solid #ddd;
    padding: 12px 20px;
    border-radius: 25px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
    width: auto; /* shrink to content */
    align-self: flex-start; /* prevent stretching in column layout */
    white-space: nowrap; /* keep text on one line */
}
.modal-like-btn:hover, .modal-share-btn:hover {
    background: #e9ecef;
    transform: translateY(-1px);
}

.view-count { display: flex; align-items: center; gap: 8px; color: #666; font-size: 14px; }

@media (max-width: 768px) {
    /* Make content adapt to height and allow full scroll */
    .modal-content { width: 95%; height: auto; max-height: 95%; }
    .modal-body { flex-direction: column; height: auto; }
    .modal-left { flex: none; }
    .image-container { height: auto; }
    /* Keep image visible but not overly tall on small screens */
    #modal-image { width: 100%; height: auto; max-height: 55vh; object-fit: contain; display: block; }
    /* Start image at top so user can scroll it up */
    .image-container { align-items: flex-start; justify-content: center; padding-top: 12px; }
    /* Let the whole modal scroll instead of an inner panel */
    .modal-right { flex: none; max-height: none; overflow: visible; }
    .modal-right { padding-bottom: 24px; }
}

/* Apply mobile behavior only to smaller screens */
@media (max-width: 768px) {
    .modal-content { width: 95%; height: auto; max-height: 95%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .modal-body { flex-direction: column; height: auto; }
    .modal-left { flex: none; }
    .image-container { height: auto; align-items: flex-start; padding-top: 12px; }
    #modal-image { width: 100%; height: auto; max-height: 55vh; object-fit: contain; display: block; }
    .modal-right { flex: none; max-height: none; overflow: visible; padding-bottom: 24px; }
}

#cloth-gallery-container .gallery-image {
    display: inline-block;
    margin: 10px;
    position: relative;
    border: 3px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
}
#cloth-gallery-container .gallery-image.primary { border-color: #0073aa; box-shadow: 0 0 10px rgba(0,115,170,0.3); }
#cloth-gallery-container .gallery-image img { width: 150px; height: 150px; object-fit: cover; display: block; }

.primary-badge {
    position: absolute;
    top: 5px;
    left: 5px;
    background: #0073aa;
    color: white;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: bold;
    border-radius: 3px;
    z-index: 10;
}

.image-controls {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}
.gallery-image:hover .image-controls { opacity: 1; }

.image-controls button {
    margin: 5px;
    padding: 8px 12px;
    background: #0073aa;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s;
}
.image-controls button:hover { background: #005a87; }
.image-controls button.is-primary { background: #46b450; }
.image-controls button.is-primary:hover { background: #399946; }
.image-controls .remove-image { background: #dc3232; }
.image-controls .remove-image:hover { background: #c62d2d; }

/* Featured banner above filters */
.cloth-featured-banner {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
margin: 10px 0 16px 0;
text-align: center;
}
.cloth-featured-banner img,
.cloth-featured-banner .cloth-featured-link img {
max-width: 400px;
height: auto;
display: block;
margin: 0 auto;
border-radius: 8px;
}
.cloth-featured-heading {
font-weight: 700;
font-size: 18px;
color: #333;
}
