/**
 * APF Product Manager - Filter Styles
 * Clean, professional B2B industrial aesthetic
 */

/* CSS Custom Properties */
:root {
    --apf-primary: #1c3a8a;
    --apf-primary-hover: #162f6e;
    --apf-accent: #3f9f44;
    --apf-accent-hover: #358a3a;
    --apf-text: #343434;
    --apf-text-muted: #8B8B8B;
    --apf-text-light: #9ca3af;
    --apf-border: #D6D6D6;
    --apf-border-dark: #d1d5db;
    --apf-bg: #fff;
    --apf-bg-card: #ffffff;
    --apf-bg-image: rgba(156, 176, 199, 0.36);
    --apf-white: #ffffff;
    --apf-shadow-card: 0 2px 8px rgba(0, 0, 0, 0.06);
    --apf-radius: 8px;
    --apf-radius-sm: 8px;
    --apf-radius-lg: 20px;
    --apf-transition: 0.2s ease;
}

/* ==========================================================================
   Layout Container
   ========================================================================== */

.apf-filter-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ==========================================================================
   Filter Sidebar
   ========================================================================== */

.apf-filter-sidebar {
    width: 100%;
    flex-shrink: 0;
}

.apf-filter-panel {
    background: var(--apf-bg-card);
    border-radius: var(--apf-radius-lg);
    padding: 1.25rem;
    box-shadow: var(--apf-shadow-card);
    border: 2px solid #D6D6D6;
}

/* Mobile Toggle (hidden on desktop) */
.apf-mobile-toggle {
    display: none;
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--apf-bg-card);
    border: 1px solid var(--apf-border);
    border-radius: var(--apf-radius);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--apf-text);
    transition: all var(--apf-transition);
}

.apf-mobile-toggle:hover {
    background: var(--apf-bg);
}

.apf-panel-close {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--apf-text-muted);
    padding: 0.25rem;
}

.apf-panel-close:hover {
    color: var(--apf-text);
}

/* Overlay (mobile only) */
.apf-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

/* ==========================================================================
   Search Box
   ========================================================================== */

.apf-search-box {
    position: relative;
    margin-bottom: 1.25rem;
}

.apf-search-icon {
    display: none;
}

.apf-search-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 2px solid var(--apf-border);
    border-radius: var(--apf-radius-sm);
    font-size: 0.875rem;
    color: var(--apf-text);
    background: var(--apf-bg-card);
    transition: border-color var(--apf-transition), box-shadow var(--apf-transition);
}

.apf-search-input:focus {
    outline: none;
    border-color: var(--apf-primary);
    box-shadow: 0 0 0 3px rgba(28, 58, 138, 0.1);
}

.apf-search-input::placeholder {
    color: var(--apf-text-light);
}

/* ==========================================================================
   Filter Groups
   ========================================================================== */

.apf-filter-groups {
    margin: 0;
}

.apf-filter-group {
    border-bottom: 1px solid var(--apf-border);
    padding-bottom: 0.25rem;
}

.apf-filter-group:last-child {
    border-bottom: none;
}

.apf-filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.75rem 0;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
}

.apf-filter-title {
    font-size: 18px;
    font-weight: 700;
    line-height: 30px;
    color: var(--apf-text);
}

.apf-chevron {
    color: var(--apf-text-muted);
    transition: transform var(--apf-transition);
    width: 18px;
    height: 18px;
}

.apf-filter-header[aria-expanded="true"] .apf-chevron {
    transform: rotate(180deg);
}

.apf-filter-content {
    padding-bottom: 0.75rem;
    display: block;
}

.apf-filter-group.apf-collapsed .apf-filter-content {
    display: none;
}

/* ==========================================================================
   Checkboxes - Circular style matching design
   ========================================================================== */

.apf-checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.3125rem 0;
    cursor: pointer;
    user-select: none;
}

.apf-checkbox {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.apf-checkbox-custom {
    flex-shrink: 0;
    width: 17px;
    height: 17px;
    border: 1px solid var(--apf-border-dark);
    border-radius: 5px;
    background: var(--apf-white);
    position: relative;
    transition: all var(--apf-transition);
}

.apf-checkbox:checked + .apf-checkbox-custom {
    background: var(--apf-primary);
    border-color: var(--apf-primary);
}

.apf-checkbox:checked + .apf-checkbox-custom::after {
    content: '';
    position: absolute;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid var(--apf-white);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.apf-checkbox:focus + .apf-checkbox-custom {
    box-shadow: 0 0 0 3px rgba(28, 58, 138, 0.15);
}

.apf-checkbox-label:hover .apf-checkbox-custom {
    border-color: var(--apf-primary);
}

.apf-checkbox-text {
    font-size: 14px;
    color: var(--apf-text);
    font-weight: 400;
    line-height: 29px
}

.apf-term-count {
    color: var(--apf-text-muted);
    font-size: 0.8125rem;
    margin-left: 0.25rem;
}

/* ==========================================================================
   Clear All Button
   ========================================================================== */

.apf-clear-all {
    width: 100%;
    padding: 0.625rem 1rem;
    margin-top: 1rem;
    background: none;
    border: 1px solid var(--apf-border);
    border-radius: var(--apf-radius-sm);
    color: var(--apf-text-muted);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--apf-transition);
}

.apf-clear-all:hover {
    border-color: var(--apf-primary);
    color: var(--apf-primary);
}

/* ==========================================================================
   Product Grid Wrapper
   ========================================================================== */

.apf-product-grid-wrapper {
    flex: 1;
    min-width: 0;
    position: relative;
}

/* ==========================================================================
   Grid Header
   ========================================================================== */

.apf-grid-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.apf-grid-info {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.apf-grid-title {
    font-size: 30px;
    font-style: normal;
    font-weight: 700 !important;
    line-height: 54px; /* 180% */
    letter-spacing: -1.5px;
    color: var(--apf-accent);
    margin: 0;
}

.apf-product-count {
    font-size: 30px;
    font-style: normal;
    line-height: 54px; /* 180% */
    letter-spacing: -1.5px;
    font-weight: 700;
    color: var(--apf-accent);
}

.apf-count-number::before {
    content: '(';
}

.apf-count-number::after {
    content: ' Products)';
}

/* Sort Dropdown */
.apf-sort-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.apf-sort-label {
    font-size: 0.875rem;
    color: var(--apf-text-muted);
}

.apf-sort-select {
    padding: 0.5rem 2.25rem 0.5rem 0.875rem;
    border: 1px solid var(--apf-border);
    border-radius: var(--apf-radius-sm);
    background: var(--apf-bg-card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 0.625rem center;
    background-size: 14px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--apf-text);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.apf-sort-select:focus {
    outline: none;
    border-color: var(--apf-primary);
}

/* ==========================================================================
   Product Grid
   ========================================================================== */

.apf-product-grid {
    display: grid;
    gap: 1.25rem;
}

.apf-columns-1 {
    grid-template-columns: 1fr;
}

.apf-columns-2 {
    grid-template-columns: repeat(2, 1fr);
}

.apf-columns-3 {
    grid-template-columns: repeat(3, 1fr);
}

.apf-columns-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Align: center — uses flexbox so incomplete last row is centered */
.apf-product-grid.apf-align-center {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1.25rem;
}

.apf-align-center > .apf-product-card {
    width: calc(100% / var(--apf-columns) - 1.25rem * (var(--apf-columns) - 1) / var(--apf-columns));
    max-width: 360px;
}

.apf-align-center.apf-columns-1 { --apf-columns: 1; }
.apf-align-center.apf-columns-2 { --apf-columns: 2; }
.apf-align-center.apf-columns-3 { --apf-columns: 3; }
.apf-align-center.apf-columns-4 { --apf-columns: 4; }

/* ==========================================================================
   Product Card
   ========================================================================== */

.apf-product-card {
    background: var(--apf-bg-card);
    border: 2px solid var(--apf-border);
    border-radius: var(--apf-radius-lg);
    overflow: hidden;
    isolation: isolate;
    display: flex;
    flex-direction: column;
    transition: box-shadow var(--apf-transition), transform var(--apf-transition);
}

.apf-product-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

/* Card Image */
.apf-card-image {
    position: relative;
    aspect-ratio: 4/3;
    overflow: hidden;
    background: var(--apf-bg-image);
}

.apf-card-image img,
.elementor .apf-card-image img {
    width: 100%;
    height: 100% !important;
    object-fit: cover !important;
    object-position: center;
    padding: 1rem;
    box-sizing: border-box;
    transition: transform 0.3s ease;
}

/* Desktop: Fixed height with absolute positioning */
@media (min-width: 769px) {
    .apf-card-image {
        height: 200px;
        aspect-ratio: unset;
    }

    .apf-card-image img,
    .elementor .apf-card-image img {
        position: absolute;
        top: 0;
        left: 0;
    }
}

.apf-product-card:hover .apf-card-image img {
    transform: scale(1.03);
}

/* Card Content */
.apf-card-content {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Product Label Tag */
.apf-category-tag {
    display: inline-block;
    font-size: 14px;
    font-style: normal;
    font-weight: 600;
    /* line-height: 54px; */
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--apf-text-muted);
    margin-bottom: 0.375rem;
}

/* Card Title */
.apf-card-title {
    font-size: 18px;
    font-style: normal;
    font-weight: 700 !important;
    line-height: 20px; /* 111.111% */
    margin: 0 0 0.875rem 0;
    color: var(--apf-text);
    min-height: 60px;
}

.apf-card-title a {
    color: inherit;
    text-decoration: none;
}

.apf-card-title a:hover {
    text-decoration: underline;
}

/* Specifications Table */
.apf-specs-table {
    margin: 16px 0 0 0;
    font-size: 0.8125rem;
}

.apf-spec-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.25rem 0;
}

.apf-specs-table dt {
    color: var(--apf-text-muted);
    font-size: 14px;
    font-style: normal;
    font-weight: 600;
    /* line-height: 54px; */
}

.apf-specs-table dd {
    color: var(--apf-text);
    font-size: 14px;
    font-style: normal;
    font-weight: 800;
    /* line-height: 54px; */
    margin: 0;
    text-align: right;
}

/* Card Description (replaces specs table when show_description is enabled) */
.apf-card-description {
    color: #343434;
    font-family: "Open Sans", sans-serif;
    font-size: 16px;
    font-style: normal;
    font-weight: 400;
    line-height: 26px;
    margin: 0 0 1.25rem 0;
}

/* Card Actions */
.apf-card-actions {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    margin-top: auto;
}

.apf-btn {
    width: 100%;
    font-size: 18px;
    font-style: normal;
    font-weight: 700;
    line-height: 40px;
    text-align: center;
    text-decoration: none;
    border-radius: var(--apf-radius-lg);
    cursor: pointer;
    transition: all var(--apf-transition);
    border: 3px solid transparent;
}

.apf-btn-primary {
    background: var(--apf-accent);
    color: var(--apf-white);
    border-color: var(--apf-accent);
}

.apf-btn-primary:hover {
    background: var(--apf-accent-hover);
    border-color: var(--apf-accent-hover);
    color: var(--apf-white);
}

.apf-btn-secondary {
    background: var(--apf-white);
    color: var(--apf-primary);
    border-color: var(--apf-primary);
}

.apf-btn-secondary:hover {
    background: var(--apf-primary);
    color: var(--apf-white);
}

/* ==========================================================================
   No Results
   ========================================================================== */

.apf-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 2rem;
    background: var(--apf-bg-card);
    border-radius: var(--apf-radius-lg);
    border: 1px solid var(--apf-border);
}

.apf-no-results p {
    margin: 0 0 0.5rem 0;
    color: var(--apf-text-muted);
}

.apf-no-results a {
    color: var(--apf-primary);
    text-decoration: underline;
}

.apf-no-results a:hover {
    text-decoration: none;
}

/* ==========================================================================
   Loading Overlay
   ========================================================================== */

.apf-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: var(--apf-radius);
}

.apf-product-grid-wrapper.apf-loading .apf-loading-overlay {
    display: flex;
}

.apf-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--apf-border);
    border-top-color: var(--apf-primary);
    border-radius: 50%;
    animation: apf-spin 0.7s linear infinite;
}

@keyframes apf-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   Tablet & Mobile Responsive
   ========================================================================== */

/* ------ Large Tablet (max-width: 1024px) ------ */
@media (max-width: 1024px) {

    /* Grid: 4-col drops to 3-col */
    .apf-columns-4 {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Layout gap tightens */
    .apf-filter-layout {
        gap: 1.5rem;
        padding: 1.25rem;
    }

    /* Buttons: remove fixed width, go full-width */
    .apf-btn {
        width: 100%;
    }

    /* Cards: tighter content padding */
    .apf-card-content {
        padding: 1rem;
    }

    /* Specs table: tighter top margin */
    .apf-specs-table {
        margin: 12px 0 0 0;
    }

    /* Grid title: slightly smaller */
    .apf-grid-title {
        font-size: 26px;
        line-height: 40px;
        letter-spacing: -1px;
    }

    .apf-product-count {
        font-size: 26px;
        line-height: 40px;
        letter-spacing: -1px;
    }

    /* Align-center: 4-col drops to 3-col */
    .apf-align-center.apf-columns-4 { --apf-columns: 3; }
}

/* ------ Small Tablet (max-width: 900px) ------ */
@media (max-width: 900px) {

    /* Grid: 3-col & 4-col drop to 2-col */
    .apf-columns-3,
    .apf-columns-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Button text: slightly smaller */
    .apf-btn {
        font-size: 16px;
        line-height: 48px;
    }

    /* Card title: slightly smaller */
    .apf-card-title {
        font-size: 16px;
        line-height: 20px;
    }

    /* Align-center: 3-col & 4-col drop to 2-col */
    .apf-align-center.apf-columns-3,
    .apf-align-center.apf-columns-4 { --apf-columns: 2; }
}

/* ------ Mobile (max-width: 768px) ------ */
@media (max-width: 768px) {

    /* Layout: stack vertically */
    .apf-filter-layout {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .apf-filter-sidebar {
        width: 100%;
    }

    /* Mobile Toggle: show */
    .apf-mobile-toggle {
        display: flex;
    }

    /* Filter Panel: slide-in drawer */
    .apf-filter-panel {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 300px;
        max-width: 85vw;
        z-index: 999;
        border-radius: 0;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        padding: 1.25rem 1rem;
    }

    .apf-filter-sidebar.apf-drawer-open .apf-filter-panel {
        transform: translateX(0);
    }

    .apf-filter-sidebar.apf-drawer-open .apf-overlay {
        display: block;
    }

    .apf-panel-close {
        display: block;
    }

    /* Filter title: smaller for drawer */
    .apf-filter-title {
        font-size: 16px;
        line-height: 26px;
    }

    /* Checkboxes: larger touch targets */
    .apf-checkbox-label {
        padding: 0.4375rem 0;
        gap: 0.75rem;
    }

    .apf-checkbox-text {
        font-size: 15px;
        line-height: 26px;
    }

    /* Grid Header: stack */
    .apf-grid-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .apf-grid-title {
        font-size: 22px;
        line-height: 32px;
        letter-spacing: -0.75px;
    }

    .apf-product-count {
        font-size: 22px;
        line-height: 32px;
        letter-spacing: -0.75px;
    }

    /* Sort: full-width */
    .apf-sort-wrapper {
        width: 100%;
    }

    .apf-sort-select {
        flex: 1;
    }

    /* Grid gap: tighter */
    .apf-product-grid {
        gap: 1rem;
    }

    /* Card image: let aspect-ratio drive height */
    .apf-card-image {
        aspect-ratio: 4 / 3;
    }

    /* Card content: compact */
    .apf-card-content {
        padding: 0.875rem;
    }

    /* Category tag */
    .apf-category-tag {
        font-size: 12px;
        margin-bottom: 0.25rem;
    }

    /* Card title */
    .apf-card-title {
        font-size: 16px;
        line-height: 20px;
        margin-bottom: 0.625rem;
    }

    /* Specs table: compact */
    .apf-specs-table {
        margin: 8px 0 16px 0;
    }

    .apf-specs-table dt,
    .apf-specs-table dd {
        font-size: 13px;
    }

    /* Buttons: full-width, compact */
    .apf-btn {
        width: 100%;
        font-size: 15px;
        line-height: 44px;
        border-width: 2px;
    }

    .apf-card-actions {
        gap: 0.5rem;
    }

    /* No results: less padding */
    .apf-no-results {
        padding: 2rem 1.25rem;
    }

    /* Align-center: tighter gap, remove max-width so cards fill space */
    .apf-product-grid.apf-align-center {
        gap: 1rem;
    }
    .apf-align-center > .apf-product-card {
        width: calc(100% / var(--apf-columns) - 1rem * (var(--apf-columns) - 1) / var(--apf-columns));
        max-width: none;
    }
}

/* ------ Small Mobile (max-width: 540px) ------ */
@media (max-width: 540px) {

    /* Grid: everything goes single column */
    .apf-columns-2,
    .apf-columns-3,
    .apf-columns-4 {
        grid-template-columns: 1fr;
    }

    /* Layout: edge-to-edge feel */
    .apf-filter-layout {
        padding: 0.75rem;
    }

    /* Card: full-width optimizations */
    .apf-card-image {
        aspect-ratio: 16 / 10;
    }

    .apf-card-content {
        padding: 1rem;
    }

    .apf-card-title {
        font-size: 17px;
        line-height: 22px;
        margin-bottom: 0.75rem;
    }

    /* Specs table: restore comfortable spacing for single column */
    .apf-specs-table {
        margin: 10px 0 20px 0;
    }

    .apf-specs-table dt,
    .apf-specs-table dd {
        font-size: 14px;
    }

    /* Buttons: full-width, comfortable tap height */
    .apf-btn {
        font-size: 16px;
        line-height: 48px;
    }

    .apf-card-actions {
        gap: 0.5rem;
    }

    /* Grid title */
    .apf-grid-title {
        font-size: 18px;
        line-height: 28px;
    }

    .apf-product-count {
        font-size: 18px;
        line-height: 28px;
    }

    /* Mobile toggle: slightly larger tap target */
    .apf-mobile-toggle {
        padding: 0.875rem 1rem;
        font-size: 1rem;
    }

    /* Align-center: single column */
    .apf-align-center.apf-columns-2,
    .apf-align-center.apf-columns-3,
    .apf-align-center.apf-columns-4 { --apf-columns: 1; }
    .apf-align-center > .apf-product-card {
        width: 100%;
        max-width: 100%;
    }
}

/* ==========================================================================
   Elementor Combined Widget — APF Filters + Grid
   Self-contained 25/75 layout used by `APF_Widget_Filters_Grid_Layout`.
   Scoped under `.apf-elementor-combined` so it doesn't affect raw
   `[product_filters] [product_grid]` shortcode usage.
   ========================================================================== */

.apf-filter-layout.apf-elementor-combined {
    /* Reset the base .apf-filter-layout container styles so the combined
       widget plays nicely inside an Elementor section's own padding/max-width. */
    max-width: none;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: flex-start;
    gap: 2rem;

    /* Per-widget configurable sidebar width via CSS variable.
       Default is 25% — overridden by the widget's slider control via inline style. */
    --apf-sidebar-width: 25%;
}

.apf-filter-layout.apf-elementor-combined .apf-elementor-combined-sidebar,
.apf-filter-layout.apf-elementor-combined .apf-elementor-combined-grid {
    min-width: 0; /* prevent flex children from blowing out */
}

/* Desktop layout: side-by-side with the configured sidebar width. */
@media (min-width: 769px) {
    .apf-filter-layout.apf-elementor-combined .apf-elementor-combined-sidebar {
        flex: 0 0 var(--apf-sidebar-width);
        max-width: var(--apf-sidebar-width);
    }
    .apf-filter-layout.apf-elementor-combined .apf-elementor-combined-grid {
        flex: 1 1 auto;
    }
    /* Sidebar-on-the-right variant. */
    .apf-filter-layout.apf-elementor-combined[data-sidebar-pos="right"] {
        flex-direction: row-reverse;
    }
}

/* Tablet/mobile (≤768px): stack vertically. The existing `[product_filters]`
   shortcode CSS already converts the inner `.apf-filter-sidebar` into a
   slide-in drawer triggered by the mobile toggle button — that behavior
   carries over because we render the same shortcode markup inside the
   combined widget. */
@media (max-width: 768px) {
    .apf-filter-layout.apf-elementor-combined {
        flex-direction: column;
        gap: 1rem;
    }
    .apf-filter-layout.apf-elementor-combined .apf-elementor-combined-sidebar,
    .apf-filter-layout.apf-elementor-combined .apf-elementor-combined-grid {
        flex: 1 1 100%;
        max-width: 100%;
        width: 100%;
    }
}
