.htwcg-widget {
    --htwcg-columns: 8;
    position: relative;
    --htwcg-accent: #dc9a0e;
    width: 100%;
    box-sizing: border-box;
}

.htwcg-widget *,
.htwcg-widget *::before,
.htwcg-widget *::after {
    box-sizing: border-box;
}

.htwcg-grid,
.ali-category-grid-pro {
    display: grid;
    grid-template-columns: repeat(var(--htwcg-columns, 8), minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.htwcg-item,
.ali-category-item {
    margin: 0 0 20px;
    overflow: hidden;
    border-radius: 6px;
    opacity: 0;
    transform: translateY(14px);
    animation: htwcgFadeInUp 0.35s ease forwards;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
    contain: layout paint;
}

.htwcg-item:hover,
.ali-category-item:hover {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.htwcg-link {
    display: block;
    color: inherit;
    text-decoration: none;
    height: 100%;
    overflow: hidden;
}

.htwcg-link:hover,
.htwcg-link:focus {
    color: inherit;
    text-decoration: none;
}

.htwcg-image-wrapper,
.ali-category-image-wrapper {
    overflow: hidden;
    border-radius: 5px;
    border: 1px solid #e1e1e1;
    padding: 10px;
    background: #fff;
}

.htwcg-image-wrapper img,
.htwcg-image {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.45s ease;
}

.htwcg-item:hover .htwcg-image,
.ali-category-item.ali-category-image-zoom:hover .ali-category-image-wrapper img {
    transform: scale(1.1);
}

.htwcg-no-image,
.no-category-image {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    width: 100%;
    min-height: 72px;
    border-radius: inherit;
    background: #f6f6f6;
    color: #9a9a9a;
    font-size: 28px;
    font-weight: 700;
}

.htwcg-title-wrap,
.title-category-wrap {
    text-align: center;
    padding: 10px 15px 15px;
}

.htwcg-title,
.title-category-wrap h3 {
    font-size: 14px;
    line-height: 22px;
    margin: 0;
    text-transform: uppercase;
    font-weight: 500;
    transition: color 0.3s ease;
}

.htwcg-item:hover .htwcg-title {
    color: var(--htwcg-accent);
}

.htwcg-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 22px;
    margin-top: 7px;
    padding: 0 8px;
    border-radius: 999px;
    background: #f3f3f3;
    color: #666;
    font-size: 12px;
    line-height: 1;
}

.htwcg-search-wrap,
.ali-category-search-wrap {
    margin-bottom: 20px;
    text-align: center;
}

.htwcg-search,
.ali-category-search {
    width: 100%;
    max-width: 300px;
    padding: 9px 13px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    transition: border 0.25s ease, box-shadow 0.25s ease;
}

.htwcg-search:focus,
.ali-category-search:focus {
    outline: none;
    border-color: var(--htwcg-accent);
    box-shadow: 0 0 0 3px rgba(220, 154, 14, 0.12);
}

.htwcg-counter,
.ali-load-counter {
    text-align: center;
    font-size: 13px;
    margin-bottom: 15px;
    color: #666;
}

.htwcg-load-more-wrap,
.ali-load-more-wrap {
    text-align: center;
    margin-top: 12px;
}

.htwcg-scroll-sentinel {
    display: block;
    width: 100%;
    height: 1px;
}

.htwcg-load-more,
.ali-load-more-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 12px 25px;
    background: var(--htwcg-accent);
    color: #fff;
    border: 0;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    transition: filter 0.25s ease, transform 0.25s ease, opacity 0.25s ease;
}

.htwcg-load-more:hover,
.ali-load-more-btn:hover {
    filter: brightness(0.92);
    color: #fff;
}

.htwcg-load-more:disabled {
    cursor: progress;
    opacity: 0.65;
}

.htwcg-empty {
    text-align: center;
    padding: 20px 10px;
    color: #777;
    font-size: 14px;
}

.htwcg-widget.is-loading .htwcg-grid {
    opacity: 0.72;
}

@keyframes htwcgFadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1024px) {
    .htwcg-grid,
    .ali-category-grid-pro {
        grid-template-columns: repeat(var(--htwcg-columns, 5), minmax(0, 1fr));
    }
}

@media (max-width: 767px) {
    .htwcg-grid,
    .ali-category-grid-pro {
        grid-template-columns: repeat(var(--htwcg-columns, 3), minmax(0, 1fr));
        gap: 15px;
    }
}


/* Uniform image box: count badge is positioned relative to the bordered image box, not the actual image size. */
.htwcg-image-wrapper,
.ali-category-image-wrapper {
    position: relative;
    isolation: isolate;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 1 / 1;
    min-height: 0;
}

.htwcg-image-wrapper > img,
.ali-category-image-wrapper > img,
.htwcg-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

.htwcg-no-image,
.no-category-image {
    height: 100%;
    min-height: 0;
    aspect-ratio: auto;
}

/* Product count badge placement */
.htwcg-image-wrapper,
.ali-category-image-wrapper {
    position: relative;
    isolation: isolate;
    --htwcg-count-offset: 15px;
}

.htwcg-count {
    position: relative;
    z-index: 2;
    min-width: 28px;
    height: auto;
    min-height: 24px;
    margin-top: 8px;
    padding: 5px 9px;
    border-radius: 999px;
    background: #1f2937;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(6px);
}

.htwcg-count--on-image {
    position: absolute;
    margin: 0;
    pointer-events: none;
}

.htwcg-count--image_top_left {
    top: var(--htwcg-count-offset, 15px);
    left: var(--htwcg-count-offset, 15px);
}

.htwcg-count--image_top_right {
    top: var(--htwcg-count-offset, 15px);
    right: var(--htwcg-count-offset, 15px);
}

.htwcg-count--image_bottom_right {
    right: var(--htwcg-count-offset, 15px);
    bottom: var(--htwcg-count-offset, 15px);
}

.htwcg-count--image_bottom_left {
    bottom: var(--htwcg-count-offset, 15px);
    left: var(--htwcg-count-offset, 15px);
}


@supports (content-visibility: auto) {
    .htwcg-item {
        content-visibility: auto;
        contain-intrinsic-size: 180px 220px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .htwcg-item,
    .htwcg-image,
    .htwcg-load-more,
    .htwcg-title {
        animation: none !important;
        transition: none !important;
    }

    .htwcg-item {
        opacity: 1;
        transform: none;
    }
}


/* SEO Safe Mode: lightweight category links exist in the initial HTML for crawlers without changing the visual layout. */
.htwcg-seo-links {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
}

.htwcg-seo-links ul {
    margin: 0;
    padding: 0;
    list-style: none;
}
