/* ============================================
   E24 Algolia UI – Stylesheet
   Premium design, consistent across autocomplete & search page
   ============================================ */

/* ----- Design Tokens ----- */
.e24-algolia-autocomplete-wrapper,
.e24-algolia-search-page {
  --e24-primary: #1a3a5c;
  --e24-primary-light: #2b5c8e;
  --e24-accent: #4caf50;
  --e24-accent-hover: #43a047;
  --e24-sale: #d32f2f;
  --e24-border: #e2e6ea;
  --e24-border-light: #f1f3f5;
  --e24-text: #1e293b;
  --e24-muted: #64748b;
  --e24-bg: #ffffff;
  --e24-bg-hover: #f7f9fb;
  --e24-card-bg: #ffffff;
  --e24-radius: 12px;
  --e24-radius-sm: 8px;
  --e24-shadow-sm: 0 1px 3px rgba(0,0,0,.05);
  --e24-shadow-md: 0 4px 14px rgba(0,0,0,.07);
  --e24-shadow-lg: 0 10px 36px rgba(0,0,0,.10);
  --e24-transition: .2s ease;
  color: var(--e24-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  box-sizing: border-box;
}


/* =============================================
   1.  AUTOCOMPLETE – HEADER SEARCH BAR
   ============================================= */
.e24-algolia-autocomplete-wrapper {
  position: relative;
  width: 100%;
  z-index: 99999;
}

/* Hide the perpetual loading spinner */
.aa-LoadingIndicator { display: none !important; }

.aa-Autocomplete { width: 100%; position: relative; }

.aa-Form {
  display: flex;
  align-items: center;
  background: var(--e24-bg);
  border: 2px solid #d0d5db;
  border-radius: 999px;
  box-shadow: var(--e24-shadow-sm);
  transition: border-color var(--e24-transition), box-shadow var(--e24-transition);
  overflow: hidden;
}
.aa-Form:focus-within {
  border-color: var(--e24-accent);
  box-shadow: 0 0 0 3px rgba(76,175,80,.15);
}

.aa-InputWrapperPrefix {
  display: flex; align-items: center; justify-content: center;
  padding-left: 14px; height: 100%;
}
.aa-InputWrapperPrefix .aa-Label,
.aa-InputWrapperPrefix .aa-LoadingIndicator {
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.aa-InputWrapperPrefix svg { width: 18px; height: 18px; color: var(--e24-muted); }

.aa-InputWrapper { flex: 1; }
.aa-Input {
  width: 100%; min-height: 46px; padding: 0 12px;
  border: none; outline: none; background: transparent;
  font-size: 15px; color: var(--e24-text);
}
.aa-Input::placeholder { color: var(--e24-muted); opacity: .7; }

.aa-InputWrapperSuffix { display: flex; align-items: center; padding-right: 8px; }

.aa-ClearButton {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border: none; border-radius: 50%;
  background: var(--e24-border-light); color: var(--e24-muted);
  cursor: pointer; transition: background var(--e24-transition);
}
.aa-ClearButton:hover { background: var(--e24-border); }
.aa-ClearButton svg { width: 14px; height: 14px; }

.aa-SubmitButton {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: #5FAD3A; color: #fff; cursor: pointer;
  transition: background var(--e24-transition); margin-right: 4px;
}
.aa-SubmitButton:hover { background: #4e9a30; }

/* ---------- Dropdown Panel ---------- */
.aa-Panel {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  z-index: 100000; background: #fff !important;
  border: 1px solid var(--e24-border); border-radius: 16px;
  box-shadow: var(--e24-shadow-lg);
  overflow: hidden; max-height: 70vh; overflow-y: auto;
}
.aa-Panel *, .aa-Source, .aa-List, .aa-Item { background-color: #fff; }
.aa-Item[aria-selected="true"], .aa-Item:hover { background-color: var(--e24-bg-hover) !important; }

/* ---------- Autocomplete Items ---------- */
.e24-aa-item {
  display: grid; grid-template-columns: 56px minmax(0,1fr) auto;
  gap: 12px; align-items: center; padding: 10px 16px;
  text-decoration: none; color: inherit; transition: background var(--e24-transition);
  border-bottom: 1px solid var(--e24-border-light);
}
.e24-aa-item:hover { background: var(--e24-bg-hover); }
.e24-aa-item:last-child { border-bottom: none; }

.e24-aa-thumb-wrap {
  width: 56px; height: 56px; display: flex; align-items: center; justify-content: center;
  background: var(--e24-border-light); border-radius: var(--e24-radius-sm);
  overflow: hidden; flex-shrink: 0;
}
.e24-aa-thumb { max-width: 52px; max-height: 52px; object-fit: contain; }

.e24-aa-content { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.e24-aa-title { font-size: 14px; font-weight: 600; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.e24-aa-category { font-size: 12px; color: var(--e24-muted); }
.e24-aa-sku { font-size: 11px; color: var(--e24-muted); font-family: monospace; }

.e24-aa-price { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; white-space: nowrap; padding-left: 8px; }
.e24-price-old { font-size: 12px; color: var(--e24-muted); text-decoration: line-through; }
.e24-price-sale { font-size: 15px; font-weight: 700; color: var(--e24-sale); }
.e24-price-regular { font-size: 15px; font-weight: 700; color: var(--e24-text); }

.e24-aa-footer, .e24-aa-no-results {
  padding: 14px 16px; border-top: 1px solid var(--e24-border);
  background: var(--e24-border-light); text-align: center;
}
.e24-aa-see-all {
  font-size: 14px; font-weight: 600; text-decoration: none; color: var(--e24-primary);
  transition: color var(--e24-transition);
}
.e24-aa-see-all:hover { color: var(--e24-accent); }
.e24-aa-no-results { display: flex; flex-direction: column; gap: 6px; color: var(--e24-muted); }


/* =============================================
   2.  SEARCH RESULTS PAGE
   ============================================= */
.e24-algolia-search-page {
  max-width: 1400px; margin: 0 auto; padding: 10px 24px 30px;
}
.e24-search-page-title {
  font-size: 24px; font-weight: 700; color: var(--e24-primary);
  margin: 0 0 4px; line-height: 1.3;
}

/* ---------- Toolbar ---------- */
.e24-search-toolbar {
  display: flex; flex-direction: column; gap: 14px; margin-bottom: 28px;
}

/* InstantSearch searchbox on search page —
   match the autocomplete header style */
.e24-searchbox-root { width: 100%; }
.e24-searchbox-form {
  display: flex; align-items: center;
  border: 2px solid var(--e24-border);
  border-radius: 999px; background: var(--e24-bg);
  box-shadow: var(--e24-shadow-sm);
  transition: border-color var(--e24-transition), box-shadow var(--e24-transition);
  overflow: hidden;
}
.e24-searchbox-form:focus-within {
  border-color: var(--e24-accent);
  box-shadow: 0 0 0 3px rgba(76,175,80,.15);
}
.e24-searchbox-input {
  flex: 1; min-height: 48px; padding: 0 16px;
  border: none; outline: none; background: transparent;
  font-size: 15px; color: var(--e24-text);
}
.e24-searchbox-input::placeholder { color: var(--e24-muted); opacity: .7; }
.e24-searchbox-submit {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--e24-accent); color: #fff; cursor: pointer;
  margin-right: 4px; transition: background var(--e24-transition);
}
.e24-searchbox-submit:hover { background: var(--e24-accent-hover); }
.e24-searchbox-submit svg { width: 18px; height: 18px; }
.e24-searchbox-reset {
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border: none; border-radius: 50%;
  background: var(--e24-border-light); color: var(--e24-muted);
  cursor: pointer; margin-right: 6px; transition: background var(--e24-transition);
}
.e24-searchbox-reset:hover { background: var(--e24-border); }
.e24-searchbox-reset svg { width: 12px; height: 12px; }
/* hide when input is empty */
.ais-SearchBox-reset--hidden,
.e24-searchbox-reset[hidden] { display: none; }

.e24-search-meta {
  display: flex; flex-wrap: wrap; justify-content: space-between;
  gap: 12px; align-items: center;
}

/* ---------- Layout ---------- */
.e24-search-layout {
  display: grid; grid-template-columns: 260px minmax(0,1fr); gap: 28px;
}

/* ---------- Sidebar ---------- */
.e24-search-sidebar {
  border: 1px solid var(--e24-border); border-radius: var(--e24-radius);
  padding: 20px; background: var(--e24-card-bg);
  align-self: start; position: sticky; top: 80px;
  max-height: calc(100vh - 100px); overflow-y: auto;
}
/* scrollbar styling */
.e24-search-sidebar::-webkit-scrollbar { width: 4px; }
.e24-search-sidebar::-webkit-scrollbar-thumb { background: var(--e24-border); border-radius: 4px; }

.e24-search-sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 16px; padding-bottom: 14px;
  border-bottom: 2px solid var(--e24-border-light);
}
.e24-search-sidebar-header strong {
  font-size: 16px; font-weight: 700; color: var(--e24-primary);
}

.e24-results-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 18px;
}

/* ---------- Buttons ---------- */
.e24-clear-refinements-button,
.e24-refinement-show-more,
.e24-range-submit {
  border: 1px solid var(--e24-border); background: var(--e24-bg);
  color: var(--e24-primary); border-radius: 999px;
  padding: 6px 14px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all var(--e24-transition);
}
.e24-clear-refinements-button:hover,
.e24-refinement-show-more:hover,
.e24-range-submit:hover { background: var(--e24-border-light); border-color: var(--e24-primary-light); }
.e24-clear-refinements-button.is-disabled { opacity: .35; cursor: default; pointer-events: none; }

/* ---------- Facets ---------- */
.e24-facet-panel {
  margin-bottom: 18px; padding-bottom: 16px;
  border-bottom: 1px solid var(--e24-border-light);
}
.e24-facet-panel:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.e24-facet-title {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: 10px; color: var(--e24-primary);
  cursor: pointer; user-select: none;
}

/* +/− collapse toggle */
.e24-facet-collapse-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border: 1px solid var(--e24-border);
  border-radius: 6px; background: var(--e24-bg); color: var(--e24-primary);
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: background var(--e24-transition), border-color var(--e24-transition);
  flex-shrink: 0; margin-left: 8px; line-height: 1;
}
.e24-facet-collapse-btn:hover { background: var(--e24-border-light); border-color: var(--e24-primary-light); }

/* Collapsed body — InstantSearch adds ais-Panel--collapsed on the root */
.ais-Panel--collapsed .ais-Panel-body,
.ais-Panel--collapsed .ais-Panel-footer { display: none !important; }
/* When collapsed, remove bottom margin from title since body is hidden */
.ais-Panel--collapsed .e24-facet-title { margin-bottom: 0; }
/* Hidden panels (no matching facet values) */
.ais-Panel--hidden { display: none; }

/* "Mostra di più / Mostra meno" button — close to its section, spaced from section below */
.e24-refinement-show-more {
  display: inline-block; margin-top: 4px; margin-bottom: 0; padding: 0; border: none;
  background: none; color: var(--e24-primary-light); font-size: 13px;
  font-weight: 600; cursor: pointer; text-decoration: underline;
  transition: color var(--e24-transition);
}
.e24-refinement-show-more:hover {
  color: var(--e24-accent);
}

.e24-refinement-list { list-style: none; padding: 0; margin: 0; }
.e24-refinement-item { margin: 0 0 5px; }
.e24-refinement-label {
  display: grid; grid-template-columns: 18px minmax(0,1fr) auto;
  align-items: center; gap: 8px; cursor: pointer;
  padding: 4px 0; transition: color var(--e24-transition);
  font-size: 13px; line-height: 1.4;
}
.e24-refinement-label:hover { color: var(--e24-accent); }
.e24-refinement-checkbox {
  width: 16px; height: 16px; accent-color: var(--e24-accent); cursor: pointer;
}
.e24-refinement-text { font-size: 13px; }
.e24-refinement-count { font-size: 12px; color: var(--e24-muted); }

.e24-stats { font-size: 14px; color: var(--e24-muted); font-weight: 500; }

.e24-refinement-search-input, .e24-range-input {
  width: 100%; border: 1px solid var(--e24-border); border-radius: var(--e24-radius-sm);
  padding: 7px 10px; font-size: 13px; transition: border-color var(--e24-transition);
  box-sizing: border-box;
}
.e24-refinement-search-input:focus, .e24-range-input:focus {
  outline: none; border-color: var(--e24-accent);
}

.e24-range-form {
  display: grid; grid-template-columns: 1fr 24px 1fr auto; gap: 6px; align-items: center;
}
.e24-range-separator { text-align: center; color: var(--e24-muted); font-weight: 500; font-size: 14px; }

/* ---------- Sort By ---------- */
.e24-sort-by {
  display: flex; align-items: center;
}
.e24-sort-by-select {
  appearance: none; -webkit-appearance: none;
  background: var(--e24-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 1px solid var(--e24-border); border-radius: var(--e24-radius-sm);
  padding: 8px 36px 8px 14px; font-size: 13px; font-weight: 500;
  color: var(--e24-text); cursor: pointer;
  transition: border-color var(--e24-transition);
}
.e24-sort-by-select:hover { border-color: var(--e24-primary-light); }
.e24-sort-by-select:focus { outline: none; border-color: var(--e24-accent); }

/* ---------- Results Header ---------- */
.e24-results-header {
  display: flex; justify-content: flex-end; align-items: center;
  margin-bottom: 12px;
}

/* ---------- Product Grid ---------- */
.e24-hits-grid {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px;
}

.e24-hits-grid-item {
  list-style: none;
}

.e24-hit-card {
  height: 100%; border: 1px solid var(--e24-border-light);
  border-radius: var(--e24-radius-sm); background: var(--e24-card-bg);
  overflow: hidden; transition: box-shadow var(--e24-transition), transform var(--e24-transition);
  display: flex; flex-direction: column;
}
.e24-hit-card:hover { box-shadow: var(--e24-shadow-md); transform: translateY(-2px); }

.e24-hit-link {
  display: flex; flex-direction: column; flex: 1;
  text-decoration: none; color: inherit;
}

/* LARGE IMAGES: fill the card area */
.e24-hit-image-wrap {
  aspect-ratio: 1 / 1; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--e24-card-bg); margin-bottom: 15px;
}
.e24-hit-image {
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  object-fit: contain; transition: transform .25s ease;
}
.e24-hit-card:hover .e24-hit-image { transform: scale(1.04); }

.e24-hit-body {
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; flex: 1;
}
.e24-hit-title {
  font-size: 17px !important; font-weight: 400 !important; line-height: 1.35;
  color: #333333;
}
.e24-hit-category { font-size: 12px; color: var(--e24-muted); margin-bottom: 4px; }
.e24-hit-sku { font-size: 11px; color: var(--e24-muted); font-family: monospace; }
.e24-hit-price-wrap {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px;
  margin-top: auto; padding-top: 10px;
}
.e24-hit-price-old { font-size: 13px; color: var(--e24-muted); text-decoration: line-through; }
.e24-hit-price-sale { font-size: 16px; font-weight: 700; color: var(--e24-sale); }
.e24-hit-price-regular { font-size: 16px; font-weight: 700; color: var(--e24-sale); }

.e24-hit-action {
  margin-top: 14px; width: 100%;
}
.e24-add-to-cart {
  display: block; text-align: center;
  background-color: var(--e24-primary-light); color: #ffffff !important;
  padding: 10px 14px; border-radius: var(--e24-radius-sm);
  font-size: 14px; font-weight: 600; text-decoration: none;
  transition: background-color var(--e24-transition);
}
.e24-add-to-cart:hover {
  background-color: var(--e24-primary); color: #ffffff !important;
}

/* ---------- Current Refinements ---------- */
.e24-current-refinements-list {
  display: flex; flex-wrap: wrap; gap: 8px;
  list-style: none; padding: 0; margin: 0;
}
.e24-current-refinements-item {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--e24-border); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; background: var(--e24-border-light);
  transition: all var(--e24-transition);
}
.e24-current-refinements-item:hover { border-color: var(--e24-muted); }

/* ---------- Pagination ---------- */
.e24-pagination-list {
  display: flex; flex-wrap: wrap; gap: 6px;
  list-style: none; padding: 0; margin: 56px 0 0; justify-content: center;
}
.e24-pagination-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 40px; height: 40px;
  border: 1px solid var(--e24-border); border-radius: 10px;
  text-decoration: none; font-size: 14px; font-weight: 500;
  color: var(--e24-text); transition: all var(--e24-transition);
}
.e24-pagination-link:hover { border-color: var(--e24-accent); color: var(--e24-accent); }
.e24-pagination-item.is-active .e24-pagination-link {
  background: var(--e24-primary); color: #fff; border-color: var(--e24-primary);
}
.e24-pagination-item.is-disabled .e24-pagination-link {
  opacity: .3; pointer-events: none;
}

/* ---------- InstantSearch defaults override ---------- */
.ais-Panel--hidden { display: none; }
.ais-RefinementList-showMore { margin-top: 8px; }
.ais-RefinementList-showMore--disabled { display: none; }

/* Make the entire header area clickable (not just + button) */
.ais-Panel-header { cursor: pointer; }


/* =============================================
   3.  RESPONSIVE
   ============================================= */

/* Mobile filter toggle button — hidden on desktop */
.e24-mobile-filter-toggle {
  display: none;
}

@media (max-width: 1100px) {
  .e24-hits-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 900px) {
  .e24-search-layout { grid-template-columns: 1fr; }

  /* Show the mobile filter button */
  .e24-mobile-filter-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px; border: 2px solid var(--e24-primary);
    border-radius: 999px; background: var(--e24-bg); color: var(--e24-primary);
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: all var(--e24-transition); margin-bottom: 16px;
  }
  .e24-mobile-filter-toggle:hover { background: var(--e24-primary); color: #fff; }
  .e24-mobile-filter-toggle svg { width: 16px; height: 16px; }

  /* Sidebar becomes a full-screen drawer on mobile */
  .e24-search-sidebar {
    position: fixed; top: 0; left: 0; z-index: 100000;
    width: 320px; max-width: 85vw; height: 100vh; max-height: 100vh;
    background: var(--e24-card-bg);
    box-shadow: 4px 0 24px rgba(0,0,0,.18);
    transform: translateX(-100%); transition: transform .3s ease;
    overflow-y: auto; padding: 20px;
    border: none; border-radius: 0;
  }
  .e24-search-sidebar.is-open { transform: translateX(0); }

  /* Backdrop */
  .e24-sidebar-backdrop {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 99999; background: rgba(0,0,0,.45);
  }
  .e24-sidebar-backdrop.is-visible { display: block; }

  /* Close button inside drawer */
  .e24-sidebar-close {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border: none; border-radius: 50%;
    background: var(--e24-border-light); color: var(--e24-text);
    font-size: 18px; cursor: pointer; position: absolute; top: 14px; right: 14px;
    transition: background var(--e24-transition);
  }
  .e24-sidebar-close:hover { background: var(--e24-border); }

  .e24-search-results { order: 1; }
}

@media (min-width: 901px) {
  /* Hide mobile-only elements on desktop */
  .e24-sidebar-close { display: none; }
  .e24-sidebar-backdrop { display: none !important; }
}

@media (max-width: 640px) {
  .e24-hits-grid { grid-template-columns: 1fr; }
  .e24-aa-item { grid-template-columns: 48px minmax(0,1fr); }
  .e24-aa-price { grid-column: 2; align-items: flex-start; }
  .e24-range-form { grid-template-columns: 1fr; }
  .e24-algolia-search-page { padding: 8px 12px 24px; }
}
