/* =========================================
   CATALOGUE.CSS - MASTER V5.3 (Decoupled Radius & Variants)
   ========================================= */

:root {
    /* DEFAULT VARIABLES */
    --primary-color: #007bff;
    --border-color: #dddddd;
    --header-color: #333333;
    --body-color: #555555;
    
    --border-radius: 8px;   /* For Cards */
    --btn-radius: 4px;      /* [NEW] For Buttons */
    --img-radius: 0px;
    --hero-img-radius: 0px;

    /* LAYOUT & APPEARANCE */
    --grid-columns: 3;
    --img-height: 200px;
    
    --font-header: inherit;
    --font-body: inherit;
    
    --size-grid-title: 1.2rem;
    --size-detail-title: 2rem;
    --size-body: 1rem;

    /* DYNAMIC BUTTONS */
    --btn-bg: transparent;
    --btn-text: var(--primary-color);
    --btn-border: 1px solid var(--primary-color);
    --btn-hover-bg: var(--primary-color);
    --btn-hover-text: #fff;
}

/* =========================================
   SCOPED TYPOGRAPHY (Fixes CSS Bleed)
   ========================================= */

/* 1. Body Text - Scoped to ProductDeck containers only */
#product-catalogue, 
.product-detail, 
#product-detail-container,
.cat-filters-container, 
.cat-controls, 
#pagination {
    font-family: var(--font-body, sans-serif) !important;
    font-size: var(--size-body, 1rem) !important;
    color: var(--body-color, #333) !important;
    line-height: 1.6 !important;
}

/* 2. Headings - Scoped to ProductDeck containers only */
/* This replaces the global h1, h2, h3... selector */
#product-catalogue h1, #product-catalogue h2, #product-catalogue h3,
#product-detail-container h1, #product-detail-container h2, #product-detail-container h3, #product-detail-container h4,
.product-card h3 {
    font-family: var(--font-header, sans-serif) !important;
    color: var(--header-color, #000) !important;
    margin-top: 0;
    line-height: 1.2;
}

/* =========================================
   1. MAIN GRID & CONTAINER
   ========================================= */
#product-catalogue {
    display: grid !important;
    grid-template-columns: repeat(var(--grid-columns, 3), 1fr) !important;
    gap: 30px !important;
    
    /* [FIX] Hover Crop: Add padding to container so hover shadows don't get cut off */
    padding: 10px !important; 
    
    margin-bottom: 40px !important;
    box-sizing: border-box !important; 
    width: 100% !important;
}

@media (max-width: 900px) {
    #product-catalogue {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
    }
}

@media (max-width: 600px) {
    #product-catalogue {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
}

/* =========================================
   2. PRODUCT CARD (FULL BLEED UPDATE)
   ========================================= */
.product-card {
    border: 1px solid var(--border-color) !important;
    border-radius: var(--border-radius) !important;
    
    /* REMOVED PADDING to allow full bleed images */
    padding: 0 !important; 
    overflow: hidden !important; /* Clips image if card has radius */
    
    display: flex !important;
    flex-direction: column !important;
    text-decoration: none !important;
    color: inherit !important;
    background: #fff !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
    box-sizing: border-box !important;
    position: relative;
}

.product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.08) !important;
    text-decoration: none !important;
}

.product-card a {
    text-decoration: none !important;
    color: inherit !important;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.product-card img {
    width: 100% !important;
    height: var(--img-height, 200px) !important; 
    object-fit: cover !important;
    border-radius: var(--img-radius) !important;
    
    /* Support for admin margins (defaults to 0 if not set) */
    margin: var(--grid-img-margins, 0px 0px 0px 0px) !important;
    
    display: block !important;
    border: none !important;
    padding: 0 !important;
}

.product-card .info {
    /* MOVED PADDING HERE so text doesn't hit edges */
    padding: 15px !important;
    
    padding-top: 15px !important; /* Explicit top padding for breathing room */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.product-card h3 {
    font-size: var(--size-grid-title) !important;
    margin-bottom: 10px !important;
}

.product-card .summary {
    font-size: 0.9em !important;
    color: var(--body-color) !important;
    flex-grow: 1;
    margin-bottom: 15px !important;
}

.product-card .price-single,
.product-card .price-our {
    font-weight: bold !important;
    margin-top: auto !important;
    color: var(--primary-color) !important;
    font-size: 1.1em !important;
}

.product-card .price-rrp {
    font-size: 0.9em !important;
    color: #999 !important;
    text-decoration: line-through !important;
    margin-right: 5px;
}

.read-more-ghost {
    margin-top: 15px !important;
    text-align: center !important;
    padding: 8px 12px !important;
    
    /* [CHANGED] Use Button Radius Setting */
    border-radius: var(--btn-radius) !important;
    
    display: block !important;
    font-weight: normal !important;
    text-decoration: none !important;
    cursor: pointer;
    background: var(--btn-bg) !important;
    color: var(--btn-text) !important;
    border: var(--btn-border) !important;
    transition: all 0.2s ease !important;
}

.product-card:hover .read-more-ghost {
    background: var(--btn-hover-bg) !important;
    color: var(--btn-hover-text) !important;
}

.featured-banner {
    position: absolute; top: 10px; right: 10px;
    background-color: #28a745; color: white;
    font-size: 0.75em; font-weight: bold;
    padding: 4px 8px; border-radius: 4px; z-index: 2;
}

/* [NEW] Variant Preview Text on Grid */
.variant-preview {
    font-size: 0.8em !important;
    color: #888 !important;
    margin-top: 5px !important;
    display: block !important;
    font-style: italic;
}

/* =========================================
   3. FILTERS, SEARCH & SORT (SMART LAYOUT)
   ========================================= */

/* MAIN CONTAINER (FLEXBOX) */
.cat-controls {
    margin-bottom: 30px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    
    /* Using Flexbox instead of Grid for smart wrapping */
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 15px !important;
}

/* 1. FILTERS (Categories) */
.cat-filters-container {
    /* Always take full width on top */
    width: 100% !important;
    order: 1 !important; /* Force to Top */
    
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 10px !important;
}

/* 2. SEARCH & SORT (Smart Columns) */
.cat-search-container, 
.cat-sort-container {
    /* MAGIC FORMULA: 
       Grow to fill space (flex-grow: 1), 
       but if you get squashed below 220px (flex-basis), wrap to next line. */
    flex: 1 1 220px !important; 
    min-width: 0 !important;
}

.cat-search-container { order: 2 !important; } /* Left side (or Middle) */
.cat-sort-container { order: 3 !important; }    /* Right side (or Bottom) */


/* --- INPUT STYLING --- */
/* Selects & Inputs */
.cat-filters-container select, .cat-sort-select, .cat-search-input {
    -webkit-appearance: none !important; appearance: none !important;
    display: block !important; 
    width: 100% !important;
    /* Removed max-width restriction so they look good in sidebar */
    max-width: 100% !important; 
    height: 42px !important; padding: 0 10px !important;
    line-height: 40px !important; margin: 0 !important;
    box-sizing: border-box !important; background-color: #fff !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--border-radius) !important;
    color: var(--body-color) !important;
    font-family: var(--font-body) !important; font-size: 0.9em !important;
    box-shadow: none !important;
}

/* Dropdown Chevons */
.cat-filters-container select, .cat-sort-select {
    padding-right: 30px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3c.org/2000/svg' width='16' height='16' fill='%23333' class='bi bi-chevron-down' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
    background-size: 10px !important;
    cursor: pointer !important;
}

/* Labels */
.filter-group, .control-group { display: flex; flex-direction: column; min-width: 0 !important; }

.filter-group label, .cat-controls label {
    font-size: 0.85em; font-weight: bold; margin-bottom: 5px !important;
    color: var(--body-color);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    line-height: 1.2; display: block;
}

.cat-filters-container select:focus, .cat-sort-select:focus, .cat-search-input:focus {
    outline: none !important; border-color: var(--primary-color) !important;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1) !important;
}

/* Reset Button */
.btn-reset {
    margin-top: auto; padding: 0 15px !important;
    height: 42px !important; line-height: 40px !important;
    background: #f8f9fa !important; border: 1px solid var(--border-color) !important;
    border-radius: var(--border-radius) !important;
    cursor: pointer !important;
    font-family: var(--font-body) !important; font-weight: bold !important;
    color: #555 !important; text-decoration: none;
    display: inline-block; text-align: center;
}
.btn-reset:hover { background: #e2e6ea !important; }

/* =========================================
   4. PAGINATION
   ========================================= */
#pagination { display: flex !important; justify-content: center !important; gap: 5px !important; margin-top: 30px !important; margin-bottom: 40px !important; }
.page-link { padding: 8px 12px !important; border: 1px solid var(--border-color) !important; background: #fff !important; cursor: pointer !important; border-radius: var(--border-radius) !important; font-family: var(--font-body) !important; color: var(--body-color) !important; text-decoration: none !important; }
.page-link.active { background: var(--primary-color) !important; color: #fff !important; border-color: var(--primary-color) !important; }

/* =========================================
   5. PRODUCT DETAIL PAGE
   ========================================= */
.product-detail h1 { font-size: var(--size-detail-title) !important; margin-bottom: 20px !important; }
.product-detail img { max-width: 100% !important; border-radius: var(--hero-img-radius) !important; }

/* PRICING */
.product-detail .price-single { font-size: 1.3em !important; font-weight: bold !important; color: var(--primary-color) !important; }
.product-detail .price-rrp { font-size: 1.1em !important; color: #999 !important; text-decoration: line-through !important; display: block !important; margin-bottom: 5px !important; }
.product-detail .price-our { font-size: 1.3em !important; font-weight: bold !important; color: #dc3545 !important; display: block !important; margin-bottom: 5px !important; }
.product-detail .price-saving { display: inline-block !important; padding: 5px 10px !important; background-color: #d1e7dd !important; color: #0f5132 !important; font-weight: bold !important; border-radius: 4px !important; margin-top: 5px !important; margin-bottom: 15px !important; }

/* =========================================
   6. GALLERY & BODY
   ========================================= */
.virtual-gallery-grid { display: grid !important; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important; gap: 10px !important; margin-top: 15px !important; margin-bottom: 20px !important; }
.gallery-thumbnail { width: 100% !important; height: 80px !important; object-fit: cover !important; border-radius: var(--img-radius, 4px) !important; border: 1px solid var(--border-color, #ddd) !important; cursor: pointer !important; transition: opacity 0.2s ease !important; }
.gallery-thumbnail:hover { opacity: 0.8 !important; }
#product-content-area img { max-width: 500px !important; width: 100% !important; height: auto !important; border-radius: var(--img-radius, 4px) !important; display: block !important; margin: 0 auto 1.5rem auto !important; box-shadow: 0 2px 5px rgba(0,0,0,0.05) !important; }
.content-image-grid { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 15px !important; max-width: 800px !important; margin: 0 auto 1.5rem auto !important; }
.content-image-grid img { max-width: 100% !important; width: 100% !important; margin: 0 !important; height: 100% !important; object-fit: cover !important; display: block !important; }
@media (max-width: 600px) { .content-image-grid { grid-template-columns: 1fr !important; } }

/* =========================================
   7. BUTTON RADIUS OVERRIDES (GLOBAL)
   ========================================= */

/* Force Snipcart "Add to Cart" & "Checkout" buttons to use the setting */
.snipcart-add-item,
.snipcart-checkout,
button.snipcart-add-item,
a.snipcart-checkout {
    border-radius: var(--btn-radius) !important;
}

/* Ensure the "Buy Now" button on the detail page matches */
.product-detail .btn, 
.product-detail button {
    border-radius: var(--btn-radius) !important;
}

/* ========================================= */
/* STORE VISIBILITY TOGGLES                  */
/* ========================================= */

/* If the store is disabled in settings, hide these elements */
body.pd-store-inactive .snipcart-checkout,
body.pd-store-inactive .snipcart-summary,
body.pd-store-inactive .pd-store-only {
    display: none !important;
}

/* ========================================= */
/* STORE VISIBILITY TOGGLES (THE SWITCH)     */
/* ========================================= */

/* 1. STORE IS OFF (Catalogue Mode) */
/* Hide the cart buttons and checkout logic */
body.pd-store-inactive .snipcart-checkout,
body.pd-store-inactive .snipcart-summary,
body.pd-store-inactive .snipcart-add-item,
body.pd-store-inactive .pd-store-only {
    display: none !important;
}

/* 2. STORE IS ON (E-Commerce Mode) */
/* Hide the "Offline" content (e.g. "Call to Order" text) */
body.pd-store-active .snipcart-checkout-disabled,
body.pd-store-active .pd-store-offline-only {
    display: none !important;
}