/* ========== HORIZONTAL CATEGORY FILTER BAR ========== */
/* This bar sits under the main navbar and shows product categories */

/* Global CSS variables for layout coordination */
:root {
  --navbar-height: 87px; /* Logo 55px + padding 32px */
  --category-bar-height: 46px;
  --total-header-height: 133px; /* navbar + category bar */
}

.category-filter-bar {
  position: fixed;
  top: var(--navbar-height);
  left: 0;
  right: 0;
  height: var(--category-bar-height);
  z-index: 999; /* Just below navbar (1000) but high enough for dropdowns */
  background: var(--bg-card, #ffffff);
  border-bottom: 1px solid var(--border-primary, rgba(0,0,0,0.06));
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  padding: 0;
  display: flex;
  align-items: center;
  overflow: visible;
}

/* Hide on scroll down, show on scroll up */
.category-filter-bar.hidden {
  transform: translateY(-100%);
  opacity: 0;
}

.category-filter-container {
  max-width: 1400px;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow: visible; /* Required for dropdowns to show */
}

/* ========== CATEGORY ITEMS ========== */
.category-filter-item {
  position: relative;
  flex-shrink: 0;
  overflow: visible; /* Allow dropdown to overflow */
  height: 100%; /* Full height of parent for proper positioning */
  display: flex;
  align-items: center;
}

/* Subtle separator between categories */
.category-filter-item:not(:last-child)::before {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 20px;
  background: var(--border-primary, rgba(0,0,0,0.1));
  opacity: 0.5;
}

.category-filter-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 1rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  position: relative;
  height: 100%;
}

.category-filter-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 3px;
  background: var(--accent-primary, #e02020);
  border-radius: 3px 3px 0 0;
  transition: width 0.25s ease;
}

/* Desktop: Link buttons act like buttons - prevent default link behavior for dropdown trigger */
a.category-filter-btn.category-btn-link {
  text-decoration: none;
}

/* On desktop, prevent link navigation to show dropdown instead */
@media (min-width: 769px) {
  a.category-filter-btn.category-btn-link {
    pointer-events: none;
  }

  .category-filter-item:hover a.category-filter-btn.category-btn-link {
    pointer-events: none;
  }

  /* Make the whole item hoverable for dropdown */
  .category-filter-item {
    cursor: pointer;
  }
}

.category-filter-btn:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.03);
}

.category-filter-btn:hover::after {
  width: 70%;
}

.category-filter-btn.active {
  color: var(--accent-primary);
  font-weight: 700;
}

.category-filter-btn.active::after {
  width: 100%;
}

.category-filter-btn i {
  font-size: 0.95rem;
  transition: transform 0.2s ease, color 0.2s ease;
}

.category-filter-btn:hover i {
  color: var(--accent-primary);
}

.category-filter-btn.active i {
  color: var(--accent-primary);
}

/* Dropdown arrow for categories with subcategories */
.category-filter-btn .dropdown-arrow {
  font-size: 0.7rem;
  margin-left: 0.25rem;
  transition: transform 0.3s ease;
}

.category-filter-item:hover .dropdown-arrow {
  transform: rotate(180deg);
}

/* ========== SUBCATEGORY DROPDOWN ========== */
.subcategory-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-primary, rgba(0,0,0,0.1));
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
  z-index: 10000; /* Much higher than everything to ensure visibility */
  padding: 0.5rem 0;
  margin-top: 0;
  pointer-events: none; /* Prevent interaction when hidden */
}

/* Invisible bridge to maintain hover when moving to dropdown */
.subcategory-dropdown::before {
  content: '';
  position: absolute;
  top: -15px; /* Bridge the gap between button and dropdown */
  left: 0;
  right: 0;
  height: 15px;
  background: transparent;
}

/* Show dropdown on hover - DESKTOP ONLY */
@media (min-width: 769px) {
  .category-filter-item:hover > .subcategory-dropdown {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: translateY(0) !important;
  }

  /* Keep dropdown visible when hovering over it */
  .subcategory-dropdown:hover {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: translateY(0) !important;
  }
}

.subcategory-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.subcategory-link:hover {
  background: var(--bg-secondary);
  color: var(--accent-primary);
  padding-left: 1.5rem;
}

.subcategory-link i {
  font-size: 1rem;
  color: var(--text-tertiary);
  transition: color 0.2s ease;
}

.subcategory-link:hover i {
  color: var(--accent-primary);
}

.subcategory-link.active {
  background: rgba(var(--accent-primary-rgb), 0.1);
  color: var(--accent-primary);
}

/* Divider in dropdown */
.subcategory-divider {
  height: 1px;
  background: var(--border-primary);
  margin: 0.5rem 0;
}

/* View all link */
.subcategory-link.view-all {
  font-weight: 600;
  color: var(--accent-primary);
  border-top: 1px solid var(--border-primary);
  margin-top: 0.5rem;
  padding-top: 0.875rem;
}

.subcategory-link.view-all:hover {
  background: rgba(var(--accent-primary-rgb), 0.1);
}

/* ========== RESPONSIVE ========== */

/* Large tablets and small desktops - enable horizontal scroll */
@media (max-width: 1200px) {
  .category-filter-bar {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .category-filter-bar::-webkit-scrollbar {
    display: none;
  }

  .category-filter-container {
    overflow: visible;
    min-width: max-content; /* Prevent wrapping, allow scroll */
    padding: 0 1rem;
  }

  /* Hide separator on smaller screens */
  .category-filter-item:not(:last-child)::before {
    display: none;
  }
}

@media (max-width: 992px) {
  :root {
    --navbar-height: 60px;
    --category-bar-height: 44px;
    --total-header-height: 104px;
  }

  .category-filter-bar {
    position: fixed;
    top: 60px !important; /* Force position below navbar */
    left: 0;
    right: 0;
    z-index: 998;
  }

  .category-filter-btn {
    padding: 0 0.75rem;
    font-size: 0.8rem;
  }

  .category-filter-btn i {
    font-size: 0.85rem;
  }
}

@media (max-width: 768px) {
  :root {
    --navbar-height: 60px;
    --category-bar-height: 50px;
    --total-header-height: 110px;
  }

  .category-filter-bar {
    position: fixed;
    top: 60px !important;
    left: 0;
    right: 0;
    z-index: 998;
    display: flex;
    height: var(--category-bar-height);
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    background: var(--bg-card, #ffffff);
    border-bottom: 1px solid var(--border-primary, rgba(0,0,0,0.06));
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
  }

  .category-filter-bar::-webkit-scrollbar {
    display: none;
  }

  .category-filter-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    width: 100%;
  }

  .category-filter-item {
    flex-shrink: 0;
    height: auto;
  }

  /* Hide separator on mobile */
  .category-filter-item:not(:last-child)::before {
    display: none;
  }

  /* MOBILE: Hide dropdown completely - links navigate directly to category pages */
  .category-filter-item .subcategory-dropdown {
    display: none !important;
  }

  /* MOBILE: Hide overlay completely */
  .mobile-category-overlay {
    display: none !important;
  }

  /* MOBILE: Hide dropdown arrow on buttons */
  .category-filter-btn .dropdown-arrow {
    display: none !important;
  }

  /* Enable link clicks on mobile - ALL category buttons should be clickable */
  a.category-filter-btn,
  a.category-filter-btn.category-btn-link {
    pointer-events: auto !important;
  }

  .category-filter-btn {
    padding: 0.5rem 0.875rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 24px;
    background: var(--bg-secondary, #f5f5f5);
    border: 1px solid var(--border-primary, rgba(0,0,0,0.08));
    height: auto;
    white-space: nowrap;
    color: var(--text-secondary, #666);
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
  }

  .category-filter-btn i:first-child {
    font-size: 0.9rem;
    color: var(--accent-primary, #e02020);
  }

  .category-filter-btn span {
    font-size: 0.75rem;
    font-weight: 500;
  }

  .category-filter-btn .dropdown-arrow {
    display: none;
  }

  .category-filter-btn::after {
    display: none;
  }

  .category-filter-btn:active {
    transform: scale(0.97);
  }

  .category-filter-btn.active {
    background: linear-gradient(135deg, var(--accent-primary, #e02020), var(--accent-dark, #c01818));
    border-color: transparent;
    color: #fff;
    box-shadow: 0 2px 8px rgba(224, 32, 32, 0.3);
  }

  .category-filter-btn.active i:first-child {
    color: #fff;
  }

  /* Mobile count badges */
  .category-count-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.65rem;
    margin-left: 2px;
    background: var(--accent-primary, #e02020);
  }

  .category-filter-btn.active .category-count-badge {
    background: rgba(255, 255, 255, 0.25);
  }
}

/* Very small mobile */
@media (max-width: 576px) {
  :root {
    --navbar-height: 56px;
    --category-bar-height: 46px;
    --total-header-height: 102px;
  }

  .category-filter-bar {
    top: 56px !important;
  }
}

@media (max-width: 480px) {
  :root {
    --category-bar-height: 44px;
    --total-header-height: 100px;
  }

  .category-filter-container {
    gap: 0.375rem;
    padding: 0.375rem 0.5rem;
  }

  .category-filter-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.7rem;
    gap: 0.25rem;
    border-radius: 18px;
  }

  .category-filter-btn i:first-child {
    font-size: 0.75rem;
  }

  .category-filter-btn span {
    font-size: 0.65rem;
  }

  .category-count-badge {
    min-width: 15px;
    height: 15px;
    font-size: 0.55rem;
    padding: 0 3px;
  }
}

/* ========== LIGHT/DARK THEME ========== */
html[data-theme="light"] .category-filter-bar {
  background: #ffffff;
  border-bottom-color: rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

html[data-theme="light"] .subcategory-dropdown {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

html[data-theme="dark"] .category-filter-bar {
  background: var(--bg-card);
  border-bottom-color: var(--border-primary);
}

html[data-theme="dark"] .subcategory-dropdown {
  background: var(--bg-card, #1e1e1e);
  border-color: var(--border-primary);
}

/* Dark theme mobile dropdown - must be more specific */
html[data-theme="dark"] .category-filter-item .subcategory-dropdown {
  background: var(--bg-card, #1e1e1e) !important;
}

html[data-theme="dark"] .mobile-dropdown-header {
  border-bottom-color: var(--border-primary);
}

html[data-theme="dark"] .mobile-dropdown-close {
  background: var(--bg-secondary, #2d2d2d);
  color: var(--text-secondary, #aaa);
}

/* ========== COUNT BADGES ========== */
.category-count-badge,
.subcategory-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-dark, #c25400));
  border-radius: 10px;
  margin-left: 6px;
  line-height: 1;
}

.category-count-badge:empty,
.subcategory-count-badge:empty {
  display: none;
}

.subcategory-count-badge {
  font-size: 0.65rem;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--accent-secondary, #6c757d);
}

.subcategory-link:hover .subcategory-count-badge {
  background: var(--accent-primary);
}

.subcategory-link.active .subcategory-count-badge {
  background: var(--accent-primary);
}

/* Light theme adjustments */
html[data-theme="light"] .category-count-badge {
  background: linear-gradient(135deg, #e85a00, #c25400);
}

html[data-theme="light"] .subcategory-count-badge {
  background: #6c757d;
}

html[data-theme="light"] .subcategory-link:hover .subcategory-count-badge,
html[data-theme="light"] .subcategory-link.active .subcategory-count-badge {
  background: #e85a00;
}
