/* =====================================================
   Caterware Product Filter — Stylesheet
   Brand colour: #E8682A (orange)
===================================================== */

:root {
    --cpf-orange:      #E8682A;
    --cpf-orange-dark: #c9521a;
    --cpf-orange-pale: #fdf2ec;
    --cpf-border:      #e4e4e4;
    --cpf-text:        #2c2c2c;
    --cpf-muted:       #888;
    --cpf-bg:          #f8f8f8;
    --cpf-white:       #ffffff;
    --cpf-radius:      8px;
    --cpf-shadow:      0 2px 8px rgba(0,0,0,.07);
    --cpf-transition:  .2s ease;
}

/* Layout */
#cpf-wrapper {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 28px;
    align-items: start;
    font-family: inherit;
    color: var(--cpf-text);
}
@media (max-width: 768px) {
    #cpf-wrapper {
        grid-template-columns: 1fr;
    }
}

/* ---- SIDEBAR ---- */
#cpf-sidebar {
    background: var(--cpf-white);
    border: none;
    border-radius: var(--cpf-radius);
    box-shadow: none;
    position: sticky;
    top: 24px;
    overflow: hidden;
}

#cpf-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--cpf-orange);
    color: #fff;
}
#cpf-sidebar-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .3px;
    color: #fff !important;
}

#cpf-clear-all {
    background: rgba(255,255,255,.2);
    border: 1px solid rgba(255,255,255,.4);
    color: #fff;
    border-radius: 20px;
    padding: 3px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background var(--cpf-transition);
    white-space: nowrap;
}
#cpf-clear-all:hover {
    background: rgba(255,255,255,.35);
}

/* Category tree */
#cpf-tree {
    padding: 12px 0;
    max-height: 70vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--cpf-border) transparent;
}

.cpf-cat-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.cpf-cat-list[data-depth="0"] > .cpf-cat-item {
    border-bottom: 1px solid var(--cpf-border);
}
.cpf-cat-list[data-depth="0"] > .cpf-cat-item:last-child {
    border-bottom: none;
}

.cpf-cat-item {
    margin: 0;
}

.cpf-cat-row {
    display: flex;
    align-items: center;
    padding: 9px 20px 9px 20px;
    gap: 6px;
    transition: background var(--cpf-transition);
}
.cpf-cat-row:hover {
    background: var(--cpf-orange-pale);
}

/* Indent children */
.cpf-cat-list[data-depth="1"] .cpf-cat-row { padding-left: 36px; }
.cpf-cat-list[data-depth="2"] .cpf-cat-row { padding-left: 52px; }
.cpf-cat-list[data-depth="3"] .cpf-cat-row { padding-left: 68px; }

.cpf-cat-label {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.4;
    margin: 0;
}

/* Custom checkbox */
.cpf-cat-checkbox {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 16px;
    height: 16px;
    min-width: 16px;
    border: 2px solid var(--cpf-border);
    border-radius: 4px;
    cursor: pointer;
    transition: all var(--cpf-transition);
    position: relative;
    background: var(--cpf-white);
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}
.cpf-cat-checkbox:checked {
    background: var(--cpf-orange);
    border-color: var(--cpf-orange);
}
.cpf-cat-checkbox:checked::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 0px;
    width: 5px;
    height: 9px;
    border: 2px solid #fff;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}
.cpf-cat-checkbox:focus-visible {
    outline: 2px solid var(--cpf-orange);
    outline-offset: 2px;
}

.cpf-cat-name {
    flex: 1;
    color: var(--cpf-text);
    font-weight: 400;
}
.cpf-cat-list[data-depth="0"] > .cpf-cat-item > .cpf-cat-row .cpf-cat-name {
    font-weight: 600;
    font-size: 13.5px;
}

.cpf-cat-count {
    font-size: 11px;
    color: var(--cpf-muted);
    margin-left: 2px;
}

/* Expand toggle */
.cpf-toggle {
    background: none;
    border: 1px solid var(--cpf-border);
    border-radius: 4px;
    width: 22px;
    height: 22px;
    min-width: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    color: var(--cpf-orange);
    transition: all var(--cpf-transition);
    padding: 0;
}
.cpf-toggle:hover {
    background: var(--cpf-orange);
    color: #fff;
    border-color: var(--cpf-orange);
}
.cpf-toggle span {
    display: block;
    transition: transform var(--cpf-transition);
}
.cpf-toggle[aria-expanded="true"] span {
    transform: rotate(45deg);
}

/* Children panel */
.cpf-children {
    background: #fafafa;
}
.cpf-children[hidden] {
    display: none;
}

/* ---- MAIN AREA ---- */
#cpf-main {
    min-height: 200px;
}

/* Toolbar */
#cpf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

#cpf-active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
    margin: 0;
    padding: 0;
}
#cpf-active-filters *,
#cpf-wrapper ul,
#cpf-wrapper li {
    list-style: none !important;
    margin-left: 0 !important;
    padding-left: 0 !important;
}

.cpf-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--cpf-orange-pale);
    border: 1px solid #f0c6ac;
    color: var(--cpf-orange-dark);
    border-radius: 20px;
    padding: 4px 10px 4px 12px;
    font-size: 12px;
    font-weight: 500;
}
.cpf-filter-tag button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--cpf-orange);
    font-size: 15px;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
}
.cpf-filter-tag button:hover {
    color: var(--cpf-orange-dark);
}

#cpf-result-count {
    font-size: 13px;
    color: var(--cpf-muted);
    white-space: nowrap;
}

/* Product Grid */
#cpf-grid {
    display: grid;
    grid-template-columns: repeat(var(--cpf-columns, 3), 1fr);
    gap: 20px;
}
@media (max-width: 1024px) {
    #cpf-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
    #cpf-grid { grid-template-columns: 1fr; }
}

/* Product Card */
.cpf-product-card {
    background: var(--cpf-white);
    border: none;
    border-radius: var(--cpf-radius);
    overflow: hidden;
    box-shadow: none;
    transition: transform var(--cpf-transition);
    display: flex;
    flex-direction: column;
}
.cpf-product-card:hover {
    transform: translateY(-3px);
}

.cpf-product-image-wrap {
    position: relative;
    aspect-ratio: 4/3;
    overflow: hidden;
    background: var(--cpf-bg);
}
.cpf-product-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .4s ease;
}
.cpf-product-card:hover .cpf-product-image-wrap img {
    transform: scale(1.04);
}

.cpf-sale-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--cpf-orange);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    letter-spacing: .5px;
    text-transform: uppercase;
}

.cpf-product-body {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 6px;
}

.cpf-product-cat {
    font-size: 11px;
    color: var(--cpf-text);
    font-weight: 400;
    text-transform: capitalize;
    letter-spacing: 0;
    line-height: 1.2;
}

.cpf-product-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--cpf-orange);
    line-height: 1.4;
    margin: 0;
    text-transform: capitalize;
}
.cpf-product-title a {
    color: var(--cpf-orange);
    text-decoration: none;
}
.cpf-product-title a:hover {
    color: var(--cpf-orange-dark);
}

.cpf-product-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--cpf-orange-dark);
}
.cpf-product-price del {
    color: var(--cpf-muted);
    font-weight: 400;
    font-size: 13px;
    margin-right: 4px;
}

.cpf-product-footer {
    padding: 0 16px 14px;
    display: flex;
    gap: 8px;
}

.cpf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--cpf-transition);
    border: none;
    line-height: 1;
}
.cpf-btn-primary {
    background: var(--cpf-orange);
    color: #fff;
    flex: 1;
}
.cpf-btn-primary:hover {
    background: var(--cpf-orange-dark);
    color: #fff;
}
.cpf-btn-outline {
    background: transparent;
    color: var(--cpf-orange);
    border: 1px solid var(--cpf-orange);
    padding: 8px 12px;
}
.cpf-btn-outline:hover {
    background: var(--cpf-orange-pale);
}

/* Pagination */
#cpf-pagination {
    margin-top: 28px;
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}
.cpf-page-btn {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid var(--cpf-border);
    background: var(--cpf-white);
    color: var(--cpf-text);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--cpf-transition);
    display: flex;
    align-items: center;
    justify-content: center;
}
.cpf-page-btn:hover {
    border-color: var(--cpf-orange);
    color: var(--cpf-orange);
}
.cpf-page-btn.active {
    background: var(--cpf-orange);
    border-color: var(--cpf-orange);
    color: #fff;
}
.cpf-page-btn:disabled {
    opacity: .4;
    cursor: default;
}

/* Loading */
#cpf-loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px;
    font-size: 14px;
    color: var(--cpf-muted);
}
#cpf-loading.visible {
    display: flex;
}
.cpf-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--cpf-border);
    border-top-color: var(--cpf-orange);
    border-radius: 50%;
    animation: cpf-spin .7s linear infinite;
    display: inline-block;
}
@keyframes cpf-spin {
    to { transform: rotate(360deg); }
}

/* Empty state */
#cpf-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--cpf-muted);
    font-size: 15px;
    background: var(--cpf-white);
    border: 1px dashed var(--cpf-border);
    border-radius: var(--cpf-radius);
}

/* =====================================================
   MOBILE — slide-in filter drawer
===================================================== */

/* Mobile filter toggle button — hidden on desktop */
#cpf-mobile-toggle {
    display: none;
    margin-bottom: 16px;
    width: 100%;
}
#cpf-mobile-toggle button {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--cpf-orange);
    color: #fff;
    border: none;
    border-radius: var(--cpf-radius);
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(232,104,42,.35);
}
#cpf-mobile-toggle button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: #fff;
    stroke-width: 2;
    stroke-linecap: round;
}
#cpf-active-badge {
    background: #fff;
    color: var(--cpf-orange);
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    margin-left: 4px;
    display: none;
}
#cpf-active-badge.visible {
    display: inline-block;
}

/* Overlay — hidden until drawer opens */
#cpf-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99998;
    opacity: 0;
    transition: opacity .3s ease;
}
#cpf-overlay.active {
    display: block;
    opacity: 1;
}

/* ---- MOBILE BREAKPOINT ---- */
@media (max-width: 768px) {

    /* Show the toggle button */
    #cpf-mobile-toggle {
        display: block;
    }

    /* Collapse the grid so sidebar doesn't show inline */
    #cpf-wrapper {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
    }

    /* Hide sidebar from page flow entirely on mobile */
    #cpf-sidebar {
        display: none;
    }

    /* Sidebar becomes a fixed off-screen drawer with solid white background */
    #cpf-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -320px !important;
        width: 300px !important;
        height: 100dvh !important;
        z-index: 99999 !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: 4px 0 32px rgba(0,0,0,.2) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        background: #ffffff !important;
        transition: left .3s ease !important;
        -webkit-overflow-scrolling: touch;
        /* Hide completely when off screen */
        visibility: hidden;
    }
    #cpf-sidebar.open {
        left: 0 !important;
        visibility: visible;
    }

    /* Show close button inside drawer */
    #cpf-drawer-close {
        display: flex !important;
    }

    /* 2-column product grid */
    #cpf-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    /* Smaller card text/padding on mobile */
    .cpf-product-title {
        font-size: 12px !important;
        line-height: 1.3 !important;
    }
    .cpf-product-cat {
        font-size: 10px !important;
    }
    .cpf-product-body {
        padding: 8px 8px 4px !important;
        gap: 3px !important;
    }
    .cpf-product-footer {
        padding: 0 8px 8px !important;
    }
    .cpf-btn {
        font-size: 11px !important;
        padding: 7px 8px !important;
    }
    .cpf-product-price {
        font-size: 12px !important;
    }

    #cpf-toolbar {
        margin-bottom: 12px;
    }

    /* Kill any Divi blue + button on images */
    #cpf-grid .et_pb_post_main_image_fullwidth_overlay,
    #cpf-grid .et-pb-icon,
    #cpf-grid [class*="et_pb_extra_overlay"],
    #cpf-grid .et_overlay,
    #cpf-wrapper .et_overlay {
        display: none !important;
    }
}

/* Close X button inside drawer header */
#cpf-drawer-close {
    display: none;
    background: rgba(255,255,255,.2);
    border: 1px solid rgba(255,255,255,.4);
    color: #fff;
    border-radius: 6px;
    width: 30px;
    height: 30px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
    margin-left: auto;
}
#cpf-drawer-close:hover {
    background: rgba(255,255,255,.35);
}
