:root {
  --dvly-products-filter-color: 3, 169, 244;
  --dvly-products-filter-color-border: 212, 212, 212;
  --dvly-products-filter-color-muted: 168, 168, 168;
  --dvly-products-filter-color-success: 76, 175, 80;
  --dvly-products-filter-color-danger: 244, 81, 30;
}

.products {
  transition: opacity 0.3s ease-in-out;
}

/* Products grid */

#dvly-products {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.dvly-products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
}

@media (min-width: 768px) {
  .dvly-products-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
  }

  .dvly-products-grid.dvly-products-grid-3-cols {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dvly-products-grid.dvly-products-grid-4-cols {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .dvly-products-grid.dvly-products-grid-5-cols {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

/* Products grid counter */

.dvly-product-counter {
  margin-bottom: 10px;
}

/* Products grid pagination */

#dvly-products .dvly-pagination {
  display: flex;
  justify-content: center;
  gap: 10px;
}
#dvly-products a.dvly-page-btn {
  padding: 8px 12px;
  border: 1px solid rgba(var(--dvly-products-filter-color-border), 1);
  background-color: transparent;
  color: black;
  cursor: pointer;
}
#dvly-products a.dvly-page-btn.active {
  background-color: rgba(var(--dvly-products-filter-color), 1);
  color: white;
  border-color: rgba(var(--dvly-products-filter-color-border), 1);
}

/* Products no results message */

.dvly-no-results {
  color: rgba(var(--dvly-products-filter-color-muted), 1);
}

/* Products grid header */

#dvly-products-head {
  display: flex;
  flex-direction: column;
  align-items: start;
}

@media (min-width: 768px) {
  #dvly-products-head {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

#dvly-products-head .dvly-sorting-dropdown {
  display: flex;
  align-items: center;
  gap: 10px;
}

/*
* Product item styles
*/

.dvly-product-item {
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(var(--dvly-products-filter-color-border), 1);
  position: relative;
}

.dvly-product-item :is(a, a:hover, a.button, a.button:hover) {
  text-decoration: none !important;
}

.dvly-product-item .product-details {
  padding: 16px;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dvly-product-item .product-details .product-title {
  font-size: 16px;
  font-weight: 700;
}

.dvly-product-item .product-image {
  border-bottom: 1px solid rgba(var(--dvly-products-filter-color-border), 1);
  aspect-ratio: 1;
}

.dvly-product-item .product-image a:has(i) {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(var(--dvly-products-filter-color-border), 1);
}

.dvly-product-item .product-image img {
  aspect-ratio: 1;
  object-fit: contain;
  object-position: center center;
  height: auto !important;
}

.dvly-product-item .product-details .product-add-to-cart {
  flex-grow: 1;
  display: flex;
  justify-content: end;
  flex-direction: column;
  gap: 12px;
}

.dvly-product-item .product-details .product-add-to-cart a {
  background: rgba(var(--dvly-products-filter-color), 1);
  padding: 12px;
  width: 100%;
  color: white;
  font-weight: 700;
  text-align: center;
}

.dvly-product-item .product-details .product-add-to-cart a.added_to_cart {
  background: rgba(var(--dvly-products-filter-color-success), 1);
  padding: 12px;
  width: 100%;
  color: white;
  font-weight: 700;
  text-align: center;
}

.dvly-product-item:has(.out-of-stock-badge)
  .product-details
  .product-add-to-cart
  a {
  background: rgba(var(--dvly-products-filter-color-muted), 1);
  padding: 12px;
  width: 100%;
  color: white;
  font-weight: 700;
}

/* Regular Price with Line-through */
.regular-price {
  color: rgba(var(--dvly-products-filter-color-muted), 1);
  text-decoration: line-through;
}

/* Sale Price */
.sale-price {
  color: black;
  font-weight: bold;
}

/* Sale Badge */
.sale-badge {
  background-color: rgba(var(--dvly-products-filter-color-success), 1);
  color: white;
  padding: 5px 10px;
  font-size: 14px;
  position: absolute;
  top: 10px;
  right: 10px;
  border-radius: 5px;
}

/* Out of Stock Badge */
.out-of-stock-badge {
  background-color: rgba(var(--dvly-products-filter-color-danger), 1);
  color: white;
  padding: 5px 10px;
  font-size: 14px;
  position: absolute;
  top: 10px;
  left: 10px;
  border-radius: 5px;
}

/* Filter block */

.dvly-filter-block:not(:first-child) {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(var(--dvly-products-filter-color-border), 1);
}

.dvly-filter-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 8px;
}

/* Search filter */

.dvly-search-wrapper {
  position: relative;
  display: inline-block;
  width: 100%;
}

.dvly-search-wrapper input {
  width: 100%;
  padding-right: 30px; /* Add space for the clear button */
  margin: 0 !important;
}

.dvly-search-wrapper #dvly-clear-search {
  position: absolute;
  right: 0;
  top: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: rgba(var(--dvly-products-filter-color-muted), 1);
  height: 100%;
  aspect-ratio: 1;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.dvly-search-wrapper #dvly-clear-search:hover {
  color: black;
}

.dvly-search-wrapper:has(#dvly-search-button) #dvly-clear-search {
  right: 50px;
}

.dvly-search-wrapper #dvly-search-button {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  border: none;
  padding: 0px;
  aspect-ratio: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: black;
  color: white;
}

.dvly-search-wrapper #dvly-search-button:hover {
  background: rgba(var(--dvly-products-filter-color), 1);
}

/*
* Category filter
*/

#dvly-category-filters ul.dvly-category-list li {
  margin-bottom: 4px;
}

#dvly-category-filters ul.dvly-category-list .dvly-subcategories {
  margin-top: 4px;
}

.dvly-filter-block input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.dvly-filter-block input[type="checkbox"]:after {
  left: 5px;
  top: 1px;
  width: 7px;
  height: 12px;
}

.dvly-pagination-ellipsis {
  padding: 8px 12px;
  color: rgba(var(--dvly-products-filter-color-muted), 1);
  pointer-events: none;
}

/* Global search */

#dvly-global-search-wrapper {
  position: relative;
  max-width: 100%;
}

#dvly-global-search {
  width: 100%;
  padding: 8px;
  margin: 0;
}

#dvly-global-search-wrapper button {
  position: absolute;
  top: 1px;
  right: 1px;
  height: calc(100% - 2px);
  border: none;
  background-color: black;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
}

#dvly-global-search-wrapper button:hover {
  background-color: rgba(var(--dvly-products-filter-color), 1);
  color: white;
}

#dvly-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  background: white;
  border: 1px solid #ddd;
  z-index: 1000;
  max-height: 300px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  padding: 10px;
  text-align: center;
}

.dvly-search-results-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.dvly-search-results-list li {
  padding: 8px;
  border-bottom: 1px solid rgba(var(--dvly-products-filter-color-border), 1);
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.dvly-search-results-list li a {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: black;
  width: 100%;
  gap: 12px;
}

.dvly-search-results-list li img {
  width: 60px;
  min-width: 60px;
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  background: rgba(var(--dvly-products-filter-color-border), 1);
  padding: 5px;
  margin-right: 0;
  border-radius: 0;
}

.dvly-product-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.dvly-product-title {
  font-size: 14px;
  font-weight: bold;
  text-align: left;
}

.dvly-product-price {
  font-size: 13px;
  font-weight: bold;
  color: black;
  text-align: left;
  margin-top: 2px;
}

.dvly-product-price del {
  color: rgba(var(--dvly-products-filter-color-muted), 1);
}

.dvly-product-price ins {
  text-decoration: none;
}

.dvly-search-results-list li:hover {
  background: rgba(var(--dvly-products-filter-color-border), 0.25);
}

.dvly-no-results {
  padding: 8px;
  color: rgba(var(--dvly-products-filter-color-muted), 1);
}

.dvly-show-all {
  display: block;
  text-align: center;
  padding: 8px;
  background: rgba(var(--dvly-products-filter-color), 1);
  color: white;
  text-decoration: none;
  margin-top: 5px;
  border-radius: 0;
}

.dvly-show-all:hover {
  background: rgba(var(--dvly-products-filter-color), 0.75);
}

.loading-spinner {
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-left-color: #000;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  animation: spin 1s linear infinite;
  margin: 10px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
