/**
 * Starkup OpenSearch Frontend Styles - Simplified
 */

/* Product Grid - 3 Columns */
.products.columns-3,
#opensearch-products-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    list-style: none;
    margin: 0;
    padding: 0;
}

#opensearch-products-grid li.product {
    margin: 0;
    padding: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    transition: box-shadow 0.3s;
    min-width: 0;
}

#opensearch-products-grid li.product:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#opensearch-products-grid li.product > .woocommerce-LoopProduct-link > img {
    width: 100%;
    height: auto;
    margin-bottom: 10px;
}

#opensearch-products-grid li.product h2 {
    font-size: 16px;
    margin: 10px 0;
}

#opensearch-products-grid li.product .price {
    display: block;
    margin: 10px 0;
    font-weight: 600;
}

/* Filter Styles */
.starkup-opensearch-filters {
    margin-bottom: 30px;
}

.starkup-opensearch-filters .filter-group {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.starkup-opensearch-filters .filter-group:last-child {
    border-bottom: none;
}

.starkup-opensearch-filters h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 15px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.starkup-opensearch-filters .filter-option {
    display: flex;
    margin-bottom: 8px;
    cursor: pointer;
}

.starkup-opensearch-filters .filter-option span {
    font-size: 14px;
}

/* Price Filter */
.price-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
}

.price-inputs input[type="number"] {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
}

/* Loading States */
.opensearch-loading {
    text-align: center;
    padding: 40px 20px;
}

.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #333;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#opensearch-products-grid.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* Pagination */
#opensearch-pagination {
    margin-top: 30px;
    text-align: center;
}

#opensearch-pagination .page-numbers {
    display: inline-block;
    padding: 8px 12px;
    margin: 0 3px;
    border: 1px solid #ddd;
    text-decoration: none;
    color: #333;
    border-radius: 3px;
    transition: all 0.3s;
    cursor: pointer;
}

#opensearch-pagination .page-numbers:hover {
    background: #333;
    color: #fff;
    border-color: #333;
}

#opensearch-pagination .page-numbers.current {
    background: #333;
    color: #fff;
    border-color: #333;
}


/* Active filters bar */
.starkup-active-filters {
  margin-bottom: 15px;
}

.os-active-filters-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.os-active-filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid #ddd;
  text-decoration: none;
  color: inherit;
  background: #fff;
  font-weight: 700;
}

.os-active-filter-remove {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  margin: 0;
  padding: 0;
}

.os-clear-all {
  padding: 6px 10px;
}

button#os-clear-all-filters {
    margin-bottom: 0;
}

/* Price slider (two ranges) */
.os-price-slider-wrap {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}
.os-price-slider-wrap input[type="range"] {
  width: 100%;
}

.os-price-slider {
  margin: 12px 4px 14px;
}

.os-price-slider.ui-slider {
  height: 6px;
  border-radius: 999px;
  background: #e5e7eb;
  border: 0;
}

.os-price-slider .ui-slider-range {
  background: #111827;
  border-radius: 999px;
}

.os-price-slider .ui-slider-handle {
  width: 16px;
  height: 16px;
  top: -5px;
  border-radius: 999px;
  border: 2px solid #111827;
  background: #fff;
  cursor: pointer;
}

#os-price-slider.ui-slider { position: relative; height: 6px; background:#e5e7eb; border:0; border-radius:999px; }
#os-price-slider .ui-slider-range { background:#111827; border-radius:999px; }
#os-price-slider .ui-slider-handle {
  display:block !important;
  position:absolute !important;
  top:-6px !important;
  width:16px !important;
  height:16px !important;
  border-radius:999px !important;
  border:2px solid #111827 !important;
  background:#fff !important;
  z-index:5 !important;
}
/* Filter Search and Accordion */
.filter-search-wrapper {
    margin-bottom: 15px;
}

.os-filter-search {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 14px;
}

.filter-options-list.collapsible {
    max-height: 200px; /* Approx 8 items */
    overflow-y: auto;
    -webkit-transition: max-height 0.3s ease-out;
    -moz-transition: max-height 0.3s ease-out;
    -o-transition: max-height 0.3s ease-out;
    transition: max-height 0.3s ease-out;
    border: 1px solid #e5e5e5;
    padding: 10px 5px;
}

.filter-options-list.collapsible.expanded {
    max-height: 1000px; /* A large enough value */
    overflow-y: auto;
}

.filter-option .filter-option-name {
    font-size: 14px;
    margin-left: 8px;
}

.filter-option .filter-option-count {
    color: #888;
    font-size: 13px;
}

.filter-option {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  gap: 3px;
  user-select: none;
}

.filter-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.checkmark {
  width: 20px;
  height: 20px;
  border: 2px solid #01285f;
  border-radius: 4px;
  display: inline-block;
  position: relative;
  transition: all 0.2s ease;
}

.checkmark::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 6px;
  height: 12px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.2s ease;
}

.filter-option input:checked + .checkmark {
  background-color: #01285f;
}

.filter-option input:checked + .checkmark::after {
  transform: rotate(45deg) scale(1);
}

.filter-option:hover .checkmark {
  box-shadow: 0 0 0 3px rgba(1, 40, 95, 0.15);
}

/* --- New UX Features --- */

/* Skeleton Loading States */
.skeleton-product {
    border-color: #f0f0f0 !important;
    box-shadow: none !important;
}

.skeleton-image, .skeleton-text {
    background: #f0f0f0;
    border-radius: 4px;
}

.skeleton-image {
    width: 100%;
    padding-top: 100%; /* 1:1 Aspect Ratio */
    margin-bottom: 15px;
}

.skeleton-text {
    height: 1.2em;
    margin-top: 10px;
    margin-bottom: 10px;
}

.skeleton-text.short {
    width: 60%;
}

/* Shimmer Animation */
.skeleton-product > div {
    background-image: linear-gradient(90deg, #f0f0f0 0px, #f8f8f8 40px, #f0f0f0 80px);
    background-size: 600px;
    animation: shimmer 1.5s infinite linear;
}

@keyframes shimmer {
    from {
        background-position: -200px 0;
    }
    to {
        background-position: calc(100% + 200px) 0;
    }
}

/* Filter Interaction Feedback */
#starkup-filters.filtering {
    position: relative;
    opacity: 0.6;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
}

#starkup-filters.filtering::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 10;
}


/* Toolbar & Active Filters */
.opensearch-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5em;
    flex-wrap: wrap;
    gap: 1em;
}

#opensearch-active-filters-container {
    /* The active filters bar will appear here */
    margin-bottom: 1.5em;
}

/* Adjustments for new active filters location */
.starkup-active-filters {
  margin-bottom: 0;
}

.os-active-filters-inner {
  padding: 0.75em 1em;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 4px;
}

/* Product List Item - New Design */
#opensearch-products-grid li.product {
    position: relative; /* For discount badge positioning */
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Pushes add to cart to bottom */
}

#opensearch-products-grid li.product .woocommerce-LoopProduct-link {
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Allows it to take up available space */
}

.product-image-wrapper {
    position: relative;
    margin-bottom: 10px;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.product-details-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Align text to top */
    margin-top: 10px; /* Space between image and details */
    flex-grow: 1; /* Allows details to fill vertical space before add to cart */
}

.product-info-left {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.product-category-name {
    font-size: .8rem;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 5px;
    font-weight: 500;
}

#opensearch-products-grid li.product h2.woocommerce-loop-product__title {
    font-size: 1rem;
    margin: 0 0 5px 0; /* Adjust spacing */
    line-height: 1.2;
}

.product-stock-status {
    font-size: .9rem;
    color: #2eae2e;
    margin-bottom: 10px;
}

.product-stock-status.listing-stock {
    color: #011b46;
}

.product-prices-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    margin-left: 10px;
    border: 3px solid #000;
}

.product-prices-right .regular-price {
    font-size: .9rem;
    color: #011b46;
    border-bottom: 3px solid #000;
    width: 100%;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    padding: 1px 3px;
}

.product-prices-right .sale-price-red {
    font-size: .9rem;
    font-weight: 700;
    color: #fff;
    background-color: #dc3545;
    padding: 2px 3px;
    white-space: nowrap;
    width: 100%;
    text-align: center;
}

/* Discount Badge */
.discount-badge {
    position: absolute;
    top: 5px;
    left: 0;
    background-color: #e2001a;
    color: #fff;
    padding: 10px 4px;
    font-size: 1.25rem;
    font-weight: 700;
    z-index: 10;
}

/* Ensure add to cart button is below the product details */
#opensearch-products-grid li.product .button.add_to_cart_button {
    margin-top: auto;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    transition: transform 0.15s ease, box-shadow 0.3s ease;
}

/* Shimmer sweep overlay */
#opensearch-products-grid li.product .button.add_to_cart_button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
    transition: none;
    pointer-events: none;
}

#opensearch-products-grid li.product .button.add_to_cart_button.loading {
    pointer-events: none;
    transform: scale(0.97);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.2);
}

#opensearch-products-grid li.product .button.add_to_cart_button.loading::before {
    animation: os-shimmer 1s ease infinite;
}

#opensearch-products-grid li.product .button.add_to_cart_button.loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 8px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: middle;
    animation: os-spin 0.6s linear infinite;
}

/* After add to cart button */
#opensearch-products-grid a.added_to_cart {
    padding: 0 0 20px;
    text-align: center;
}

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

@keyframes os-shimmer {
    0%   { left: -100%; }
    100% { left: 100%; }
}

#opensearch-products-grid li.product .button.add_to_cart_button.added {
    animation: os-pop 0.35s ease;
}

#opensearch-products-grid li.product .button.add_to_cart_button.added::after {
    content: ' \2713';
    margin-left: 4px;
}

@keyframes os-pop {
    0%   { transform: scale(0.97); }
    50%  { transform: scale(1.04); }
    100% { transform: scale(1); }
}

/* Shortcode Layout */
.starkup-opensearch-shortcode-wrapper {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.starkup-opensearch-shortcode-sidebar {
    flex: 0 0 280px;
    max-width: 280px;
}

.starkup-opensearch-shortcode-content {
    flex: 1;
    min-width: 0;
}

@media (max-width: 768px) {
    .starkup-opensearch-shortcode-wrapper {
        flex-direction: column;
    }

    .starkup-opensearch-shortcode-sidebar {
        flex: none;
        max-width: 100%;
        width: 100%;
    }
}


/* Responsive - 2 columns on tablet */
@media (max-width: 1100px) {
    .products.columns-3,
    #opensearch-products-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Responsive - 2 columns on mobile */
@media (min-width: 345px) and (max-width: 550px) {
    .products.columns-3,
    #opensearch-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }
    #opensearch-products-grid .product-details-flex {
        flex-direction: column;
    }
    #opensearch-products-grid .product-prices-right {
        margin-left: 0;
        margin-bottom: 10px;
    }
    #opensearch-products-grid li.product {
        padding: 8px;
    }
    #opensearch-products-grid li.product h2.woocommerce-loop-product__title {
        font-size: .9rem;
        word-break: break-word;
    } 
    .discount-badge {
        font-size: 1rem;
    } 
}

@media (max-width: 345px) {
    #opensearch-products-grid .product-details-flex {
        flex-direction: row;
    }
    .products.columns-3,
    #opensearch-products-grid {
        grid-template-columns: 1fr;
    }
}