/**
 * Taxonomy Page Styles.
 *
 * Mobile-first, RTL-optimized, performance-focused styles.
 *
 * @package Dandiran
 * @since 1.0.0
 */

/* ==========================================================================
   Base & Reset
   ========================================================================== */

.taxonomy-page {
  padding: 20px 0;
  min-height: 60vh;
}

/* ==========================================================================
   Breadcrumb
   ========================================================================== */

.taxonomy-page .woocommerce-breadcrumb {
  font-size: 13px;
  color: #666;
  margin-bottom: 20px;
  padding: 10px 0;
}

.taxonomy-page .woocommerce-breadcrumb a {
  color: #666;
  text-decoration: none;
  transition: color 0.2s ease;
}

.taxonomy-page .woocommerce-breadcrumb a:hover {
  color: #000;
}

.taxonomy-page .woocommerce-breadcrumb .separator {
  margin: 0 8px;
  color: #999;
}

/* ==========================================================================
   Header & Description
   ========================================================================== */

.taxonomy-header {
  margin-bottom: 30px;
}

.taxonomy-title {
  font-size: 28px;
  font-weight: 700;
  color: #000;
  margin: 0 0 15px 0;
  line-height: 1.3;
}

.taxonomy-description {
  font-size: 15px;
  line-height: 1.7;
  color: #555;
  max-width: 800px;
}

.taxonomy-description p {
  margin: 0 0 10px 0;
}

/* ==========================================================================
   Child Categories Grid
   ========================================================================== */

.taxonomy-children {
  margin-bottom: 40px;
}

.children-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 15px;
}

.child-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 15px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  text-decoration: none;
  color: #333;
  transition: all 0.2s ease;
}

.child-card:hover {
  border-color: #000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.child-image {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  overflow: hidden;
}

.child-image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid #e5e5e5;
}

.child-image svg {
  color: #ccc;
}

.child-card span:not(.child-image):not(.child-count) {
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  line-height: 1.4;
}

.child-count {
  font-size: 12px;
  color: #888;
  margin-top: 6px;
}

/* ==========================================================================
   Toolbar
   ========================================================================== */

.taxonomy-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  margin-bottom: 20px;
  border-bottom: 1px solid #e5e5e5;
  flex-wrap: wrap;
  gap: 15px;
  width: 100vw;
  margin-right: -12px;
  margin-left: -12px;
  position: sticky;
  top: 60px;
  z-index: 499;
  background: #fff;
}

.toolbar-left {
  font-size: 14px;
  color: #ffffff;
  font-weight: 500;
  background-color: #000;
  padding: 8px 16px;
  border-radius: 6px;
  min-width: fit-content;
}

.toolbar-right {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
  scroll-padding: 0 12px;
  padding: 0 12px;
}

.toolbar-right::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.filter-button {
  display: inline-flex;
  min-width: fit-content;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.filter-button:hover {
  border-color: #000;
  background: #f9f9f9;
}

.filter-button[aria-pressed="true"] {
  background: #000;
  color: #fff;
  border-color: #000;
}

.filter-button svg {
  flex-shrink: 0;
}

/* ==========================================================================
   Filter Modal
   ========================================================================== */

.taxonomy-filter-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.taxonomy-filter-modal[hidden] {
  display: none;
}

.taxonomy-filter-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.taxonomy-filter-modal:not([hidden]) .taxonomy-filter-backdrop {
  opacity: 1;
}

.taxonomy-filter-sheet {
  position: relative;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  background: #fff;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  overflow: hidden;
}

.taxonomy-filter-modal:not([hidden]) .taxonomy-filter-sheet {
  transform: translateY(0);
}

.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #e5e5e5;
}

.filter-header h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  color: #000;
}

.filter-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  color: #666;
  transition: all 0.2s ease;
}

.filter-close:hover {
  background: #e5e5e5;
  color: #000;
}

.filter-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.filter-content[aria-busy="true"] {
  opacity: 0.6;
  /*pointer-events: none;*/
}

.filter-footer {
  padding: 20px;
  border-top: 1px solid #e5e5e5;
}

.filter-apply {
  width: 100%;
  padding: 14px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
  font-family: inherit;
}

.filter-apply:hover {
  background: #333;
}

/* Filter Options */

.filter-option {
  margin-bottom: 15px;
}

.filter-checkbox-label,
.filter-radio-label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s ease;
}

.filter-checkbox-label:hover,
.filter-radio-label:hover {
  background: #f9f9f9;
}

.filter-checkbox-input,
.filter-radio-input {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.filter-checkbox-text,
.filter-radio-text {
  font-size: 14px;
  color: #333;
}

/* Price Inputs */

.filter-price-inputs {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.filter-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-input-group label {
  font-size: 13px;
  color: #666;
  font-weight: 500;
}

.filter-number-input {
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.filter-number-input:focus {
  outline: none;
  border-color: #000;
}

/* Loading State */

.filter-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 15px;
}

.filter-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e5e5;
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.filter-loading p {
  font-size: 14px;
  color: #666;
  margin: 0;
}

/* ==========================================================================
   Products Grid
   ========================================================================== */

.taxonomy-products-wrapper {
  position: relative;
}

.woocommerce .products ul::after,
.woocommerce .products ul::before,
.woocommerce ul.products::after,
.woocommerce ul.products::before {
  content: unset !important;
  display: table;
}

.taxonomy-products ul.products {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.taxonomy-products ul.products li.product {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
}

.product-image {
  position: relative;
  width: 100%;
  padding-top: 100%;
  overflow: hidden;
  background: #f9f9f9;
}

.product-image img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.woocommerce-loop-product__title {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-price {
  padding: 0 12px 12px;
  font-size: 15px;
  font-weight: 600;
  color: #000;
}

.product-price del {
  color: #999;
  font-weight: 400;
  font-size: 13px;
  margin-left: 8px;
}

.product-price ins {
  text-decoration: none;
  color: #e74c3c;
}

.product_type_simple {
  display: block;
  margin: 0 12px 12px;
  padding: 10px;
  background: #000;
  color: #fff;
  text-align: center;
  text-decoration: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s ease;
}

.product_type_simple:hover {
  background: #333;
}

.product_type_simple.outofstock {
  background: #ccc;
  cursor: not-allowed;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.taxonomy-pagination {
  margin: 40px 0;
  text-align: center;
}

.taxonomy-pagination ul.page-numbers {
  display: flex;
  justify-content: center;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 0;
  flex-wrap: wrap;
  border: none;
}

.taxonomy-pagination .page-numbers {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  text-decoration: none;
  color: #333;
  font-size: 14px;
  transition: all 0.2s ease;
}

.taxonomy-pagination .page-numbers:hover {
  border-color: #000;
  background: #f9f9f9;
}

.taxonomy-pagination .page-numbers.current {
  background: #000;
  color: #fff;
  border-color: #000;
}

.taxonomy-pagination .page-numbers.dots {
  border: none;
  background: transparent;
  cursor: default;
}

/* ==========================================================================
   Loading & Error States
   ========================================================================== */

.taxonomy-loading {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 30px 0;
}

.taxonomy-loading span {
  width: 12px;
  height: 12px;
  background: #000;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.taxonomy-loading span:nth-child(1) {
  animation-delay: -0.32s;
}

.taxonomy-loading span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

.taxonomy-error {
  padding: 20px;
  background: #fee;
  border: 1px solid #fcc;
  border-radius: 8px;
  color: #c00;
  text-align: center;
  margin: 20px 0;
  font-size: 14px;
}

/* ==========================================================================
   Responsive: Mobile (<768px) — horizontal scroll instead of wrap
   ========================================================================== */

@media (max-width: 767.98px) {
  .children-grid {
    width: 100vw;
    display: flex;
    flex-wrap: nowrap;
    gap: 12px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -ms-overflow-style: none;
    scrollbar-width: none;
    margin-right: -12px;
    margin-left: -12px;
    scroll-padding: 12px;
    padding: 0 12px;
  }

  .children-grid::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
  }

  .child-card {
    flex: 0 0 27%;
    width: 27%;
    scroll-snap-align: start;
  }
}

/* ==========================================================================
   Responsive: Tablet (768px+)
   ========================================================================== */

@media (min-width: 768px) {
  .taxonomy-title {
    font-size: 36px;
  }

  .children-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
  }

  .taxonomy-products ul.products {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  /* Desktop: Modal becomes dropdown */
  .taxonomy-filter-modal {
    align-items: center;
    justify-content: center;
    padding: 80px 20px 20px;
  }

  .taxonomy-filter-sheet {
    max-width: 400px;
    max-height: 600px;
    border-radius: 12px;
    transform: translateY(-20px);
    opacity: 0;
    transition: all 0.3s ease;
  }

  .taxonomy-filter-modal:not([hidden]) .taxonomy-filter-sheet {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ==========================================================================
   Responsive: Desktop (1024px+)
   ========================================================================== */

@media (min-width: 1024px) {
  .taxonomy-toolbar {
    width: 100%;
    margin-left: unset;
    margin-right: unset;
    top: 0;
  }

  .toolbar-right {
    padding: unset;
  }

  .taxonomy-products ul.products {
    grid-template-columns: repeat(4, 1fr);
    gap: 25px;
  }

  .toolbar-right {
    gap: 12px;
  }

  .filter-button {
    padding: 10px 20px;
  }
}

/* ==========================================================================
   Accessibility: Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Accessibility: High Contrast
   ========================================================================== */

@media (prefers-contrast: high) {
  .filter-button,
  .taxonomy-pagination .page-numbers {
    border-width: 2px;
  }

  .child-card {
    border-width: 2px;
  }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
  .taxonomy-toolbar,
  .taxonomy-filter-modal,
  .taxonomy-pagination,
  .taxonomy-loading {
    display: none !important;
  }

  .taxonomy-products ul.products {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ==========================================================================
   Active Filter Chips
   ========================================================================== */

.taxonomy-active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 0 0 20px;
}

.taxonomy-active-filters[hidden] {
  display: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 6px 6px;
  background: #f5f5f5;
  border: 1px solid #e5e5e5;
  border-radius: 20px;
  font-size: 13px;
  color: #333;
  animation: chip-in 0.15s ease;
}

.filter-chip-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #666;
  flex-shrink: 0;
  transition:
    background 0.2s ease,
    color 0.2s ease;
}

.filter-chip-remove:hover {
  background: #000;
  color: #fff;
}

.filter-chip-remove svg {
  width: 12px;
  height: 12px;
}

.taxonomy-clear-all {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  background: transparent;
  border: none;
  color: #c00;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
}

@keyframes chip-in {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
