/**
 * BH Product Categories Tree View Styles
 *
 * @package GroupeBH
 */

.bh-product-categories-tree-widget {
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.20);
  background: rgba(255, 255, 255, 0.05);
  padding: 32px 18px;
}

/* Tree View Container */
.bh-categories-tree {
  @apply bg-gray-900 border border-gray-700 rounded-lg p-4;
  font-family: system-ui, -apple-system, sans-serif;
}

/* Category Item */
.bh-category-item {
  @apply flex items-center mb-2 relative;
  position: relative;
  transition: all 0.2s ease;
}

.bh-category-item.opened {
  > .bh-category-link .bh-category-name {
    color: #E22415;
  }
  .bh-toggle-icon svg path {
    fill: #E22415;
  }
  .bh-category-icon svg path {
    fill: #E22415;
  }
}

.bh-category-item.opened[data-id="104"], .bh-category-item.opened[data-id="97"] {
  .bh-category-icon svg path {
    fill: none;
    stroke: #E22415;
  }
}

.bh-category-item:last-child {
  @apply mb-0;
}

.bh-category-item[data-level="1"] {
  @apply ml-4;
}

.bh-category-item[data-level="2"] {
  @apply ml-8;
}

.bh-category-item[data-level="3"] {
  @apply ml-12;
}

/* Toggle Button */
.bh-category-toggle {
  @apply w-6 h-6 flex items-center justify-center text-gray-400 hover:text-white bg-transparent border-0 cursor-pointer mr-1;
  transition: transform 0.2s ease, color 0.2s ease;
  background: none;
  outline: none;
}

.bh-category-toggle:hover {
  @apply text-white;
}

.bh-category-toggle[aria-expanded="true"] .bh-toggle-icon {
  transform: rotate(180deg);
}

.bh-category-toggle {
  @apply text-xs;
  position: absolute;
  top: -2px;
  right: -7px;
  padding: 7px;
  transition: transform 0.2s ease;
}

/* Spacer for items without children */
.bh-category-spacer {
  @apply w-6 h-6 mr-1;
}

/* Category Link */
.bh-category-link {
  @apply flex items-center flex-1 text-gray-300 hover:text-white no-underline py-2 px-3 rounded-md;
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
}

.bh-category-link:hover {
  @apply bg-gray-800 text-white no-underline;
}

.bh-category-item.active .bh-category-link {
  @apply bg-red-600 text-white;
}

.bh-category-item.active .bh-category-link:hover {
  @apply bg-red-500;
}

/* Category Icon */
.bh-category-icon {
  @apply mr-3 text-base;
  min-width: 20px;
  margin-right: 6px;
  svg {
    width: 20px;
    height: 20px;
  }
}

/* Category Name */
.bh-category-item[data-level="0"] > .bh-category-link .bh-category-name, .bh-category-all {
  font-size: 16px;
  letter-spacing: -0.18px;
  @apply flex-1 font-medium;
}
.bh-categories-tree > .bh-category-item:not(:last-child) {
  margin-bottom: 16px;
}

/* Product Count */
.bh-category-count {
  @apply text-xs text-gray-500 font-normal ml-2;
}

.bh-category-item.active .bh-category-count {
  @apply text-gray-200;
}

/* Children Container */
.bh-category-children {
  @apply w-full;
  margin: 8px 0 0;
}

/* Expanded children by default */
/*.bh-category-item[data-level="0"] > .bh-category-children {*/
/*  display: block !important;*/
/*}*/

.bh-category-children .bh-category-item {
  @apply border-l border-gray-700 ml-3 pl-3;
  position: relative;
  padding-left: 28px;
  .bh-category-icon {
    display: none;
  }
}

.bh-category-children .bh-category-item:not(:last-child) {
  margin-bottom: 5px;
}

.bh-category-children .bh-category-item::before {
  content: "";
  @apply absolute w-3 border-b border-gray-700;
  left: -3px;
  top: 50%;
  transform: translateY(-50%);
}

/* Special styling for "All Products" */
.bh-category-all .bh-category-link {
  @apply font-semibold;
}

/* Parent categories styling */
.bh-category-item[data-level="0"] > .bh-category-link {
  @apply font-semibold text-gray-200;
}

.bh-category-item[data-level="0"]:not(.active) > .bh-category-link:hover {
  @apply bg-gray-800 text-white;
}

/* Loading state */
.bh-categories-tree.loading {
  @apply opacity-50 pointer-events-none;
}

.bh-category-link.loading {
  @apply opacity-50;
  position: relative;
}

.bh-category-link.loading::after {
  content: "";
  @apply absolute right-2 w-4 h-4 border-2 border-gray-400 border-t-white rounded-full;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .bh-categories-tree {
    @apply p-3;
  }

  .bh-category-item[data-level="0"] > .bh-category-link .bh-category-name, .bh-category-all {
    font-size: 16px;
  }

  .bh-category-children .bh-category-name {
    font-size: 14px;
  }

  .bh-category-link {
    @apply py-3 px-2;
  }

  .bh-category-icon {
    @apply mr-2;
  }

  .bh-category-item[data-level="1"] {
    @apply ml-2;
  }

  .bh-category-item[data-level="2"] {
    @apply ml-4;
  }

  .bh-category-item[data-level="3"] {
    @apply ml-6;
  }
}

/* Widget Title */
.bh-product-categories-tree-widget .widgettitle {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.54px;
  text-transform: uppercase;
  margin-bottom: 20px;
  @apply text-white text-lg font-bold mb-4 uppercase tracking-wider;
}

/* Smooth animations */
.bh-category-children {
  display: none;
  overflow: hidden;
}

/* Focus states for accessibility */
.bh-category-toggle:focus,
.bh-category-link:focus {
  @apply outline-none ring-2 ring-red-500 ring-opacity-50;
}

/* Filter section integration */
.bh-shop-products aside .bh-categories-tree {
  @apply mb-6;
}
