/**
 * @file
 * Products search/listing page (/products) — the search_api "products" view
 * (block_1) with facets 3.0 exposed filters, plus the JS toolbar built by
 * js/products-search.js.
 *
 * Scope: facet rules target the exposed form by id
 * (#views-exposed-form-products-block-1); card/toolbar/list rules target
 * .view-products. Nothing here is global.
 *
 * The 3-column card grid itself comes from the existing `.threecolumn
 * .view-content` rule in global.css — this file only styles the cards, the
 * facet sidebar, the toolbar, and the list-view variant.
 */

/* ==========================================================================
 * FACET SIDEBAR (the exposed form, left column)
 * ========================================================================== */

/* On desktop the fulltext search is relocated into the content toolbar by JS;
   hide the copy that stays in the sidebar form (it remains in the form for
   AJAX). On mobile (< 768px) custom.js collapses the whole filter column into
   the "Search & Filters" block, so the search belongs there with the facets —
   the responsive rules further down flip this. */
#views-exposed-form-products-block-1 .form-item-search {
    display: none;
}
#views-exposed-form-products-block-1 .form-actions {
    display: none;
}
#views-exposed-form-products-block-1 .form--inline {
    display: block;
}

/* Each facet is a fieldset group. Strip the theme's fieldset chrome (border,
   grey legend background, inner padding) and give it a clean section divider. */
#views-exposed-form-products-block-1 fieldset,
#views-exposed-form-products-block-1 .fieldgroup {
    border: 0;
    background: none;
    margin: 0 0 1rem;
    /* Facet fieldsets pick up a float from the theme's form styles, which makes
       them sit side-by-side inside the mobile collapse. Force them to stack. */
    float: none;
    width: 100%;
    display: block;
}
#views-exposed-form-products-block-1 fieldset:last-of-type {
    border-bottom: 0;
    margin-bottom: 0;
    padding-bottom: 0;
}
#views-exposed-form-products-block-1 legend,
#views-exposed-form-products-block-1 legend > span,
#views-exposed-form-products-block-1 legend > * {
    background: none;      /* remove the grey block behind the title */
    border: 0;             /* remove the underline under the title */
    box-shadow: none;
}
#views-exposed-form-products-block-1 legend {
    display: block;
    width: 100%;
    float: none;
    margin: 0 0 0.5rem;
    padding: 0;
    font-family: var(--display-font);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--phi-gray-400);
    border-bottom: 1px solid var(--phi-gray-200);
}

/* Checkbox rows — tight, even spacing. */
#views-exposed-form-products-block-1 .form-checkboxes { margin: 0; }
#views-exposed-form-products-block-1 .form-check,
#views-exposed-form-products-block-1 .js-form-type-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 5px 8px;
    border-radius: 7px;
    transition: background 0.15s ease;
}
#views-exposed-form-products-block-1 .form-check:hover,
#views-exposed-form-products-block-1 .js-form-type-checkbox:hover {
    background: var(--phi-secondary);
}

/* The box is a Bootstrap .form-check-input (appearance:none + checkmark image),
   so accent-color has no effect — recolour the checked background directly.
   The id + :checked selector (1,1,1) beats Bootstrap's .form-check-input:checked
   (0,2,0), so no !important needed. */
#views-exposed-form-products-block-1 input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    flex-shrink: 0;
    border: 1px solid var(--phi-gray-400);
    cursor: pointer;
}
#views-exposed-form-products-block-1 input[type="checkbox"]:checked {
    background-color: var(--phi-orange);
    border-color: var(--phi-orange);
}
#views-exposed-form-products-block-1 input[type="checkbox"]:focus {
    box-shadow: 0 0 0 3px rgba(245, 120, 32, 0.25);
    border-color: var(--phi-orange);
}

#views-exposed-form-products-block-1 .form-check label,
#views-exposed-form-products-block-1 .js-form-type-checkbox label {
    display: flex;
    flex: 1;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin: 0;
    font-size: 0.9375rem;
    color: var(--phi-gray-800);
    cursor: pointer;
    line-height: 1.35;
}
/* A checked facet colours its label. */
#views-exposed-form-products-block-1 input[type="checkbox"]:checked + label {
    color: var(--phi-orange);
    font-weight: 600;
}

/* ==========================================================================
 * RESET FILTERS link (built by products-search.js when a filter/search is on)
 * ========================================================================== */
/* Uses .orange-link for the colour/type treatment; this only drops the arrow
   and adds the leading reset icon. !important because .orange-link's arrow rule
   (custom-classes.css) loads later and would otherwise win the specificity tie. */
.products-reset::after { content: none !important; }
.products-reset {
    /* Sits at the bottom of the facet list, so space it above. */
    margin-top: 1.25rem;
}
.products-reset svg {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
}
.products-reset[hidden] { display: none; }

/* ==========================================================================
 * PRODUCT TAG CHIPS (.product-tags-con / .product-tag inside a card)
 * ========================================================================== */
.product-tags-con {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}
.product-tag {
    border-bottom: none;
    font-size: 0.875rem;
    line-height: 1.3;
    border-radius: 4px;
    /* Light grey chip with darker grey text (design), not the dark header colour. */
    background: var(--phi-secondary);
    color: var(--phi-gray-600);
    padding: 3px 8px;
}
/* The chip may wrap a taxonomy link; keep it the same grey (beat .region-content
   a, which is (0,1,1) and loads later — hence the extra class in the selector). */
.product-tags-con .product-tag a {
    color: var(--phi-gray-600);
    border-bottom: none;
    text-decoration: none;
}
.product-tags-con .product-tag a:hover { color: var(--phi-dark); }

/* ==========================================================================
 * CONTENT TOOLBAR (built by products-search.js — count | search | switch)
 * ========================================================================== */
.products-toolbar {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    /* Clears the fixed header when the Reset link scrolls here (utility bar +
       header + a little breathing room). */
    scroll-margin-top: 140px;
}
.products-toolbar__count {
    font-size: 0.9375rem;
    color: var(--phi-gray-600);
    white-space: nowrap;
}
.products-toolbar__count strong {
    color: var(--phi-dark);
    font-weight: 700;
}

/* Search pill. */
.products-toolbar__search {
    flex: 1;
    min-width: 220px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    height: 44px;
    background: var(--phi-secondary);
    border: 1px solid transparent;
    border-radius: 8px;
    transition: border-color 0.2s ease, background 0.2s ease;
}
.products-toolbar__search:focus-within {
    background: var(--white);
    border-color: var(--phi-orange);
}
.products-toolbar__search svg {
    width: 18px;
    height: 18px;
    color: var(--phi-gray-400);
    flex-shrink: 0;
}
.products-toolbar__search input {
    flex: 1;
    border: 0;
    background: none;
    outline: none;
    font-size: 0.9375rem;
    font-family: 'Inter', sans-serif;
    color: var(--phi-dark);
    min-width: 0;
}
.products-toolbar__search input::placeholder { color: var(--phi-gray-400); }

/* Grid/list switch. */
.products-toolbar__switch {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: var(--phi-secondary);
    border-radius: 8px;
    flex-shrink: 0;
}
.products-toolbar__switch button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--phi-gray-600);
    cursor: pointer;
    transition: all 0.18s ease;
}
.products-toolbar__switch button svg { width: 18px; height: 18px; }
.products-toolbar__switch button:hover { color: var(--phi-dark); }
.products-toolbar__switch button.is-active {
    background: var(--white);
    color: var(--phi-orange);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* The view's own header (result count) is mirrored into the toolbar, so hide
   the original once JS has taken over. */
.view-products.js-toolbar-ready .view-header { display: none; }

/* ==========================================================================
 * PRODUCT CARDS (grid view — grid columns come from .threecolumn in global.css)
 * ========================================================================== */
.view-products .views-row {
    display: flex;
    flex-direction: column;
    background: var(--white);
    border: 1px solid var(--phi-gray-200);
    border-radius: 12px;
    overflow: hidden;
    transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
}
.view-products .views-row:hover {
    border-color: var(--phi-orange);
    box-shadow: 0 8px 24px rgba(245, 120, 32, 0.10);
    transform: translateY(-3px);
}

/* Image (3:2, grey placeholder background for missing images). */
.view-products .views-field-field-product-images,
.view-products .views-field-field-product-images .field-content {
    display: block;
}
.view-products .views-field-field-product-images img {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: cover;
    background: var(--phi-gray-200);
}

/* Card body (the rewritten "nothing" field: h4 > title, p, hr, view-details). */
.view-products .views-field-nothing {
    padding: 22px 22px 24px;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.view-products .views-field-nothing .field-content {
    display: flex;
    flex-direction: column;
    flex: 1;
}
/* Optional orange category eyebrow, if the view adds one. */
.view-products .views-field-nothing .card-category,
.view-products .card-category {
    font-family: var(--display-font);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--phi-orange);
    margin-bottom: 8px;
}
.view-products .views-field-nothing h4 {
    margin: 0 0 10px;
    font-family: var(--display-font);
    font-size: 1.0625rem;
    font-weight: 700;
    line-height: 1.3;
}
.view-products .views-field-nothing h4 a {
    color: var(--phi-dark);
    border-bottom: 0;
}
.view-products .views-row:hover .views-field-nothing h4 a { color: var(--phi-orange); }
.view-products .views-field-nothing p {
    margin: 0 0 16px;
    font-size: 0.9375rem;
    line-height: 1.55;
    color: var(--phi-gray-600);
}
/* Optional tag chips, if the view adds them. */
.view-products .card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}
.view-products .card-tags .card-tag {
    font-size: 0.75rem;
    color: var(--phi-gray-600);
    background: var(--phi-secondary);
    padding: 3px 9px;
    border-radius: 4px;
}
.view-products .views-field-nothing .hrline {
    border-top: 1px solid var(--phi-gray-200);
    margin: auto 0 14px;
}
/* "View Details" uses the existing .orange-link (arrow + hover handled there). */

/* ==========================================================================
 * LIST VIEW (toggled on by JS: .view-products.products-list-view)
 * ========================================================================== */
.view-products.products-list-view .view-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.view-products.products-list-view .views-row {
    flex-direction: row;
    align-items: stretch;
}
.view-products.products-list-view .views-field-field-product-images {
    flex: 0 0 240px;
    max-width: 240px;
}
.view-products.products-list-view .views-field-field-product-images img {
    height: 100%;
    aspect-ratio: auto;
}
.view-products.products-list-view .views-field-nothing {
    justify-content: center;
}
.view-products.products-list-view .views-field-nothing .hrline { display: none; }

#views-exposed-form-products-block-1 .fieldset-wrapper{
    padding: 0;
}


/* ==========================================================================
 * RESPONSIVE (< 768px)
 *
 * custom.js collapses the whole filter column (.filter-col — the exposed form)
 * into a "Search & Filters" toggle. So on mobile the search moves out of the
 * content toolbar and back into that form, sitting above the facets.
 * ========================================================================== */
@media (max-width: 767px) {
    /* Search lives in the collapsible filter block with the facets, separated
       from them by a divider so it reads as its own section. */
    #views-exposed-form-products-block-1 .form-item-search {
        display: block;
        margin: 0 0 1.25rem;
        padding: 0 0 1.25rem;
        border-bottom: 1px solid var(--phi-gray-200);
    }
    /* Label styled to match the facet legends (uppercase micro-heading). */
    #views-exposed-form-products-block-1 .form-item-search label {
        display: block;
        margin: 0 0 0.5rem;
        font-family: var(--display-font);
        font-size: 0.6875rem;
        font-weight: 700;
        letter-spacing: 0.1em;
        text-transform: uppercase;
        color: var(--phi-gray-400);
    }
    #views-exposed-form-products-block-1 .form-item-search input {
        width: 100%;
        height: 44px;
        padding: 0 14px;
        border: 1px solid var(--phi-gray-200);
        border-radius: 8px;
        background: var(--white);
        font-size: 0.9375rem;
        color: var(--phi-dark);
        transition: border-color 0.15s ease, box-shadow 0.15s ease;
    }
    #views-exposed-form-products-block-1 .form-item-search input::placeholder {
        color: var(--phi-gray-400);
    }
    #views-exposed-form-products-block-1 .form-item-search input:focus {
        outline: none;
        border-color: var(--phi-orange);
        box-shadow: 0 0 0 3px rgba(245, 120, 32, 0.15);
    }
    /* The toolbar proxy is redundant on mobile — hide it (count + switch stay). */
    .products-toolbar__search { display: none; }

    .products-toolbar { gap: 12px; }
    .products-toolbar__count { width: 100%; order: -1; }
    .view-products.products-list-view .views-row { flex-direction: column; }
    .view-products.products-list-view .views-field-field-product-images {
        flex-basis: auto;
        max-width: none;
    }
    .view-products.products-list-view .views-field-field-product-images img { aspect-ratio: 3 / 2; }
}
