/* ============================================
   Typesense Faceted Search — Trendyol Style
   Brand Color: #ec1325
   ============================================ */

/* ─── Hide WP sidebar on pages with our shortcode ─────────────────────── */
.tfs-fullwidth-page .widget-area,
.tfs-fullwidth-page #secondary,
.tfs-fullwidth-page .sidebar-container,
.tfs-fullwidth-page .col-lg-3.sidebar-column,
.tfs-fullwidth-page .wd-sidebar {
  display: none !important;
}
.tfs-fullwidth-page .site-content .col-lg-9,
.tfs-fullwidth-page .site-content .col-md-9,
.tfs-fullwidth-page .main-page-wrapper .col-lg-9 {
  flex: 0 0 100% !important;
  max-width: 100% !important;
}

/* ─── Wrapper ─────────────────────────────────────────────────────────── */
#typesense-trendyol-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #333;
}

/* ─── Top Bar ─────────────────────────────────────────────────────────── */
#ts-top-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

/* Search Box */
.ts-searchbox-root { flex: 1; min-width: 200px; }

.ts-searchbox-form {
  display: flex;
  position: relative;
}

.ts-searchbox-input {
  width: 100%;
  padding: 10px 42px 10px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  background: #fff;
}

.ts-searchbox-input:focus {
  border-color: #ec1325;
}

.ts-searchbox-submit,
.ts-searchbox-reset {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.ts-searchbox-submit { right: 10px; }
.ts-searchbox-submit svg { width: 18px; height: 18px; fill: #999; }
.ts-searchbox-reset { right: 36px; }
.ts-searchbox-reset svg { width: 14px; height: 14px; fill: #ccc; }

/* Stats */
.ts-stats-text {
  font-size: 13px;
  color: #888;
  white-space: nowrap;
}

/* Sort */
.ts-sort-root { flex-shrink: 0; }

.ts-sort-select {
  padding: 10px 36px 10px 14px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23666' d='M1.41.59L6 5.17 10.59.59 12 2 6 8 0 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.ts-sort-select:focus {
  border-color: #ec1325;
}

/* ─── Active Filters ──────────────────────────────────────────────────── */
#ts-active-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 0;
  flex-wrap: wrap;
}

.ts-current-root { flex: 1; }

.ts-current-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.ts-current-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ts-current-label {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  margin-right: 2px;
}

.ts-current-category {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ec1325;
  color: #fff;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
}

.ts-current-delete {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 15px;
  padding: 0 1px;
  line-height: 1;
  opacity: 0.8;
}

.ts-current-delete:hover { opacity: 1; }

.ts-clear-btn {
  background: none;
  border: none;
  color: #ec1325;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  white-space: nowrap;
  padding: 4px 0;
}

.ts-clear-btn:hover { color: #c8101e; }

.ts-clear-btn--disabled {
  display: none;
}

/* ─── Main Content Layout ─────────────────────────────────────────────── */
#ts-main-content {
  display: flex;
  gap: 0;
  align-items: flex-start;
  position: relative;
}

/* ─── Mobile Filter Button ────────────────────────────────────────────── */
#ts-mobile-filter-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  margin-bottom: 12px;
  background: #ec1325;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#ts-mobile-filter-btn:hover { background: #c8101e; }

#ts-mobile-filter-btn svg {
  flex-shrink: 0;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────── */
#ts-sidebar {
  width: 250px;
  min-width: 250px;
  padding-right: 24px;
  border-right: 1px solid #e8e8e8;
  position: sticky;
  top: 100px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Thin scrollbar */
#ts-sidebar::-webkit-scrollbar { width: 4px; }
#ts-sidebar::-webkit-scrollbar-track { background: #f5f5f5; }
#ts-sidebar::-webkit-scrollbar-thumb { background: #ec1325; border-radius: 4px; }

.ts-sidebar-mobile-header {
  display: none;
}

/* ─── Filter Sections ─────────────────────────────────────────────────── */
.ts-filter-section {
  border-bottom: 1px solid #f0f0f0;
}

.ts-filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  font-weight: 600;
  font-size: 14px;
  color: #333;
  cursor: pointer;
  user-select: none;
}

.ts-filter-header:hover { color: #000; }

.ts-chevron {
  font-size: 18px;
  color: #999;
  transition: transform 0.2s ease;
  font-weight: 300;
}

/* Closed state: chevron points right */
.ts-filter-section .ts-filter-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0;
}

/* Open state */
.ts-filter-section.open .ts-filter-body {
  max-height: 500px;
  padding: 0 0 12px;
  overflow-y: auto;
}

.ts-filter-section.open .ts-chevron {
  transform: rotate(90deg);
}

/* Filter body scrollbar */
.ts-filter-body::-webkit-scrollbar { width: 4px; }
.ts-filter-body::-webkit-scrollbar-track { background: #f5f5f5; }
.ts-filter-body::-webkit-scrollbar-thumb { background: #ec1325; border-radius: 4px; }

/* ─── Hierarchical Menu (Category) ────────────────────────────────────── */
.ts-hier-root {
  padding: 4px 0;
}

.ts-hier-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.ts-hier-child {
  list-style: none;
  padding-left: 16px;
  margin: 0;
}

.ts-hier-item {
  margin: 0;
  padding: 0;
}

.ts-hier-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 4px;
  font-size: 13px;
  color: #333;
  text-decoration: none;
  border-radius: 4px;
  transition: background 0.15s;
}

.ts-hier-link:hover {
  background: #f8f8f8;
  color: #ec1325;
}

.ts-hier-item--selected > .ts-hier-link {
  color: #ec1325;
  font-weight: 600;
}

.ts-hier-count {
  font-size: 11px;
  color: #999;
  background: #f5f5f5;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 6px;
}

/* ─── Refinement Lists (Brand, Size, Color) ───────────────────────────── */
.ts-refine-root {
  padding: 4px 0;
}

/* Search inside refinement */
.ts-refine-search input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 8px;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.ts-refine-search input:focus {
  border-color: #ec1325;
}

.ts-refine-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.ts-refine-item {
  padding: 0;
  margin: 0;
}

.ts-refine-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}

.ts-refine-label:hover {
  background: #f8f8f8;
}

.ts-refine-checkbox {
  accent-color: #ec1325;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
}

.ts-refine-count {
  margin-left: auto;
  font-size: 11px;
  color: #999;
  background: #f5f5f5;
  padding: 1px 7px;
  border-radius: 10px;
}

.ts-refine-item--selected .ts-refine-label {
  font-weight: 600;
  color: #ec1325;
}

.ts-refine-showmore {
  background: none;
  border: none;
  color: #ec1325;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0 2px;
}

.ts-refine-showmore:hover { opacity: 0.7; }

/* ─── Price Filter ────────────────────────────────────────────────────── */
.ts-price-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.ts-price-input {
  width: 72px;
  padding: 7px 8px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 13px;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  -moz-appearance: textfield;
}

.ts-price-input::-webkit-outer-spin-button,
.ts-price-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.ts-price-input:focus {
  border-color: #ec1325;
}

.ts-price-sep {
  color: #999;
  font-size: 14px;
}

.ts-price-btn {
  padding: 7px 16px;
  background: #ec1325;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.ts-price-btn:hover {
  background: #d4112a;
}

/* ─── Product Area ────────────────────────────────────────────────────── */
#ts-product-area {
  flex: 1;
  min-width: 0;
  padding-left: 24px;
}

/* Loading state */
#typesense-product-grid.ts-loading {
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.2s;
  min-height: 400px;
}

#typesense-product-grid {
  transition: opacity 0.2s;
  min-height: 200px;
}

.ts-initial-loading,
.ts-no-results {
  text-align: center;
  padding: 60px 20px;
  color: #888;
  font-size: 16px;
}

/* Make WoodMart grid fill the area */
#typesense-product-grid .products.wd-products {
  width: 100%;
}

/* Hide product descriptions in grid view (should not appear in cards) */
#typesense-product-grid .woocommerce-product-details__short-description,
#typesense-product-grid .product-excerpt {
  display: none !important;
}

/* WoodMart shortcode wrapper — remove extra margins */
#typesense-product-grid .woocommerce,
#typesense-product-grid .wd-products-element {
  margin: 0;
  padding: 0;
}

/* Ensure product images are properly sized */
#typesense-product-grid .product-image-link img {
  width: 100%;
  height: auto;
}

/* ─── Infinite Scroll Sentinel ────────────────────────── */
.ts-scroll-sentinel {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
}

.ts-scroll-sentinel.ts-sentinel--loading::after {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  border: 3px solid #eee;
  border-top-color: #ec1325;
  border-radius: 50%;
  animation: ts-spin 0.7s linear infinite;
}

@keyframes ts-spin {
  to { transform: rotate(360deg); }
}
/* ─── Overlay (mobile) ────────────────────────────────────────────────── */
#ts-overlay {
  display: none;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 1024px) {
  /* WoodMart grid: 3 columns on tablet */
  #typesense-product-grid .products.wd-products {
    --wd-col-lg: 3 !important;
  }
}

@media (max-width: 768px) {
  /* Show mobile filter button */
  #ts-mobile-filter-btn {
    display: flex;
  }

  /* Top bar stack */
  #ts-top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .ts-sort-root { width: 100%; }
  .ts-sort-select { width: 100%; }

  /* Sidebar: off-canvas */
  #ts-sidebar {
    position: fixed;
    top: 0;
    left: -310px;
    width: 290px;
    min-width: 290px;
    height: 100vh;
    max-height: 100vh;
    z-index: 10000;
    background: #fff;
    border-right: none;
    padding: 0 16px 16px;
    transition: left 0.3s ease;
    box-shadow: none;
    border-radius: 0;
  }

  #ts-sidebar.ts-sidebar--open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .ts-sidebar-mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0 12px;
    border-bottom: 1px solid #e8e8e8;
    margin-bottom: 8px;
    font-weight: 700;
    font-size: 16px;
  }

  #ts-sidebar-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    padding: 0 4px;
    line-height: 1;
  }

  /* Overlay */
  #ts-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
  }

  #ts-overlay.ts-overlay--visible {
    display: block;
  }

  /* Product area full width */
  #ts-product-area {
    padding-left: 0;
  }

  /* WoodMart grid: 2 columns on mobile */
  #typesense-product-grid .products.wd-products {
    --wd-col-lg: 2 !important;
    --wd-col-md: 2 !important;
    --wd-col-sm: 2 !important;
  }
}

@media (max-width: 480px) {
  #typesense-trendyol-wrapper {
    padding: 10px 12px;
  }

  #typesense-product-grid .products.wd-products {
    --wd-gap-sm: 8px !important;
  }
}
