/**
 * =====================================================================================
 * HIGHLIGHT SECTION - UNIFIED STYLES
 * =====================================================================================
 * 
 * Consistent highlight product display across all pages:
 * - Homepage
 * - Category pages
 * - Landing pages
 * 
 * Desktop: 5x2 Grid (10 products max)
 * Mobile: Horizontal carousel (same as homepage category blocks)
 * 
 * @version 1.0.0
 * @date 2025-12-20
 * =====================================================================================
 */

/* =====================================================================================
   SECTION CONTAINER
   ===================================================================================== */
.highlight-section {
    position: relative;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto 12px auto;
    padding: 0 16px;
    --highlight-card-width: 219px;
    --highlight-card-height: 320px;
    --highlight-card-image-height: 219px;
}

/* =====================================================================================
   HEADER - Title + View All CTA
   ===================================================================================== */
.highlight-section .highlight-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 0;
}

.highlight-section .highlight-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #1a1a1a);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.highlight-section .highlight-header h2 i {
    color: var(--secondary-color, #e74c3c);
    font-size: 16px;
}

/* Header actions container (View All + Close Button) */
.highlight-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* View All CTA - Always visible */
.highlight-view-all {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--secondary-color, #e74c3c);
    text-decoration: none;
    padding: 8px 16px;
    border: 1px solid var(--secondary-color, #e74c3c);
    border-radius: 8px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.highlight-view-all:hover {
    background: var(--secondary-color, #e74c3c);
    color: #fff;
}

.highlight-view-all i,
.highlight-view-all svg {
    font-size: 12px;
    width: 12px;
    height: 12px;
    transition: transform 0.2s ease;
}

.highlight-view-all:hover i,
.highlight-view-all:hover svg {
    transform: translateX(-4px);
}

/* Close button for AJAX highlight containers */
.highlight-section .btn-close-highlight {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 50%;
    background: var(--bg-white, #fff);
    color: var(--text-secondary, #64748b);
    cursor: pointer;
    transition: all 0.2s ease;
}

.highlight-section .btn-close-highlight:hover {
    background: #fee2e2;
    border-color: #fecaca;
    color: #dc2626;
}

.highlight-section .btn-close-highlight svg {
    width: 16px;
    height: 16px;
}

/* Hidden state for AJAX containers */
.highlight-products-section[aria-hidden="true"] {
    display: none;
}

.highlight-products-section[aria-hidden="false"] {
    display: block;
}

/* =====================================================================================
   UNIFIED CARD SIZE (Highlight section only)
   Target size: 219w x 320h
   ===================================================================================== */
.highlight-products .product-card {
    width: var(--highlight-card-width);
    min-width: var(--highlight-card-width);
    max-width: var(--highlight-card-width);
    height: var(--highlight-card-height);
    background: var(--bg-white, #fff);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}

.highlight-products .product-card .product-link {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    height: 100%;
}

.highlight-products .product-card .product-image {
    position: relative;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    padding-top: 0;
    background: #fff;
    overflow: hidden;
}

.highlight-products .product-card .product-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    box-sizing: border-box;
    padding: 0;
}

.highlight-products .product-card .product-info {
    padding: 6px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow: hidden;
}

.highlight-products .product-card .product-name {
    font-size: 12.5px;
    line-height: 1.2;
    min-height: 2.4em;
    max-height: 2.4em;
    overflow: hidden;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
}

.highlight-products .product-card .product-description {
    font-size: 10.5px;
    line-height: 1.2;
    min-height: 1.2em;
    max-height: 1.2em;
    overflow: hidden;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    white-space: normal;
}

.highlight-products .product-card .product-price {
    margin-top: auto;
    font-size: 13px;
    line-height: 1.2;
    gap: 0.25rem;
    align-items: center;
}

.highlight-products .product-card .product-price--original {
    font-size: 11px;
}

.highlight-products .product-card .product-price--current {
    font-size: 13px;
}

.highlight-products {
    align-content: start;
    transition: opacity 0.2s ease;
}

.highlight-products.is-loading {
    opacity: 0.55;
}

.highlight-products .product-card.is-skeleton {
    border-color: #eceff3;
    pointer-events: none;
}

.highlight-products .product-card.is-skeleton .product-image,
.highlight-products .product-card.is-skeleton .sk-line {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
    background-size: 220% 100%;
    animation: highlight-skeleton 1.2s ease-in-out infinite;
}

.highlight-products .product-card.is-skeleton .product-info {
    gap: 8px;
}

.highlight-products .product-card.is-skeleton .sk-line {
    display: block;
    border-radius: 8px;
}

.highlight-products .product-card.is-skeleton .sk-line-title {
    height: 14px;
    width: 88%;
}

.highlight-products .product-card.is-skeleton .sk-line-subtitle {
    height: 11px;
    width: 72%;
}

.highlight-products .product-card.is-skeleton .sk-line-price {
    height: 13px;
    width: 46%;
    margin-top: auto;
}

@keyframes highlight-skeleton {
    0% { background-position: 220% 0; }
    100% { background-position: -220% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .highlight-products .product-card.is-skeleton .product-image,
    .highlight-products .product-card.is-skeleton .sk-line {
        animation: none;
        background: #e5eaf1;
    }
}

/* =====================================================================================
   DESKTOP LAYOUT: 5x2 Grid (10 products)
   ===================================================================================== */
@media (min-width: 1024px) {
    .highlight-section {
        padding: 0 24px;
    }

    .highlight-section .highlight-header {
        margin-bottom: 20px;
    }

    .highlight-section .highlight-header h2 {
        font-size: 22px;
    }

    .highlight-products {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(var(--highlight-card-width), var(--highlight-card-width)));
        justify-content: start;
        gap: 16px;
    }

    .highlight-section:not(.highlight-story-panel) .highlight-products.is-loading {
        min-height: var(--highlight-card-height);
    }

    /* Limit to 10 products (2 rows of 5) */
    .highlight-section:not(.highlight-story-panel) .highlight-products > .product-card:nth-child(n+11) {
        display: none !important;
    }

    /* Product card in highlight - uses existing .product-card styles */
    .highlight-products .product-card {
        transition: border-color 0.2s ease;
    }

    .highlight-products .product-card:hover {
        border-color: #d1d5db;
    }
}

/* =====================================================================================
   TABLET LAYOUT: 4x2 Grid (8 products visible)
   ===================================================================================== */
@media (min-width: 768px) and (max-width: 1023px) {
    .highlight-section {
        padding: 0 20px;
    }

    .highlight-products {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(var(--highlight-card-width), var(--highlight-card-width)));
        justify-content: start;
        gap: 14px;
    }

    .highlight-section:not(.highlight-story-panel) .highlight-products.is-loading {
        min-height: var(--highlight-card-height);
    }

    /* Limit to 8 products on tablet */
    .highlight-section:not(.highlight-story-panel) .highlight-products > .product-card:nth-child(n+9) {
        display: none !important;
    }
}

/* =====================================================================================
   MOBILE LAYOUT: Horizontal Carousel (matches homepage category blocks)
   ===================================================================================== */
@media (max-width: 767px) {
    .highlight-section {
        --highlight-card-width: 160px;
        --highlight-card-height: 252px;
        --highlight-card-image-height: 160px;
        padding: 0;
        margin-bottom: 8px;
    }

    .highlight-section .highlight-header {
        padding: 0 16px;
        margin-bottom: 12px;
    }

    .highlight-section .highlight-header h2 {
        font-size: 16px;
    }

    .highlight-view-all {
        font-size: 12px;
        padding: 6px 12px;
    }

    /* Carousel container - matches homepage */
    .highlight-products {
        display: flex;
        gap: 12px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 16px 8px 16px;
        scroll-padding-right: 16px;
    }

    .highlight-products::-webkit-scrollbar {
        display: none;
    }

    /* Product cards in carousel - same sizing as homepage */
    .highlight-products .product-card {
        flex: 0 0 var(--highlight-card-width);
        min-width: var(--highlight-card-width);
        max-width: var(--highlight-card-width);
        height: var(--highlight-card-height);
        scroll-snap-align: start;
    }

    .highlight-products .product-card .product-image::before {
        content: '';
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0);
        transition: background 0.3s ease;
        z-index: 1;
        pointer-events: none;
    }

    .highlight-products .product-card .product-name {
        font-size: 12px;
        font-weight: 600;
        color: var(--text-primary);
        margin: 0;
        line-height: 1.2;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        white-space: normal;
    }

    .highlight-products .product-card .product-description {
        font-size: 10px;
        color: var(--text-secondary);
        margin: 0;
        line-height: 1.2;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
        white-space: normal;
    }

    .highlight-products .product-card .product-price {
        font-size: 12px;
        font-weight: bold;
        color: var(--secondary-color, #e74c3c);
        margin-top: auto;
    }

    /* Show only first 10 items in carousel */
    .highlight-section:not(.highlight-story-panel) .highlight-products > .product-card:nth-child(n+11) {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .highlight-section {
        --highlight-card-width: 148px;
        --highlight-card-height: 236px;
        --highlight-card-image-height: 148px;
    }

    .highlight-products {
        gap: 10px;
        padding: 0 12px 8px 12px;
        scroll-padding-right: 12px;
    }

    .highlight-section .highlight-header {
        padding: 0 12px;
    }
}

/* =====================================================================================
   LOADING STATE
   ===================================================================================== */
.highlight-section .highlight-loading {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(1px);
    gap: 12px;
    color: var(--text-secondary, #64748b);
    font-size: 14px;
    pointer-events: none;
}

.highlight-section .highlight-loading .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--secondary-color, #e74c3c);
    border-radius: 50%;
    animation: highlight-spin 0.8s linear infinite;
}

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

/* =====================================================================================
   EMPTY STATE
   ===================================================================================== */
.highlight-section .highlight-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    gap: 12px;
    color: var(--text-secondary, #64748b);
    text-align: center;
}

.highlight-section .highlight-empty i {
    font-size: 48px;
    opacity: 0.3;
}

.highlight-section .highlight-empty p {
    margin: 0;
    font-size: 14px;
}

/* =====================================================================================
   DARK THEME SUPPORT
   ===================================================================================== */
body.theme-dark .highlight-section .highlight-header h2 {
    color: var(--text-primary);
}

body.theme-dark .highlight-products .product-card {
    background: var(--bg-white);
    border-color: var(--border-color);
}

body.theme-dark .highlight-view-all {
    border-color: var(--secondary-color);
}

/* =====================================================================================
   STORY PANEL UX (Idea 1)
   Mobile-first overlay panel for highlight content
   ===================================================================================== */
html.highlight-story-open,
body.highlight-story-open {
    overflow: hidden;
}

.highlight-story-overlay {
    position: fixed;
    inset: 0;
    z-index: 100050;
    display: block;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.highlight-story-overlay.is-mounted {
    visibility: visible;
}

.highlight-story-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

.highlight-story-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}

.highlight-story-panel {
    position: absolute;
    right: 0;
    left: 0;
    bottom: 0;
    margin: 0;
    width: 100%;
    max-height: 92vh;
    padding: 0;
    border-radius: 22px 22px 0 0;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    box-shadow: 0 -12px 36px rgba(15, 23, 42, 0.2);
    transform: translateY(28px);
    opacity: 0;
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    will-change: transform, opacity;
}

.highlight-story-panel[aria-hidden="false"] {
    display: flex;
}

.highlight-story-panel.is-open-panel {
    transform: translateY(0);
    opacity: 1;
}

.highlight-story-handle {
    width: 52px;
    height: 5px;
    border-radius: 999px;
    background: #cbd5e1;
    margin: 10px auto 6px;
}

.highlight-story-close {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: #f1f5f9;
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 3;
}

.highlight-story-top {
    padding: 6px 14px 7px;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.highlight-story-progress {
    display: none;
    margin: 0;
}

.story-progress-segment {
    display: block;
    height: 3px;
    border-radius: 999px;
    background: #e2e8f0;
}

.story-progress-segment.is-filled {
    background: linear-gradient(90deg, #ef4444 0%, #f97316 100%);
}

.highlight-story-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-left: 44px;
}

.highlight-story-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.highlight-story-nav {
    display: none;
    align-items: center;
    gap: 6px;
}

.highlight-story-nav-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid #dbe3ee;
    background: #ffffff;
    color: #0f172a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.highlight-story-nav-btn:hover:not(:disabled) {
    border-color: #cbd5e1;
    background: #f8fafc;
}

.highlight-story-nav-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.highlight-story-title {
    margin: 0;
    font-size: 13px;
    line-height: 1.2;
    font-weight: 800;
    color: #dc2626;
}

.highlight-story-panel .highlight-products {
    --story-card-size: calc((100vw - 60px) / 3);
    --story-card-info-height: 86px;
    --story-card-height: calc(var(--story-card-size) + var(--story-card-info-height));
    flex: 1;
    min-height: 0;
    padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 16px);
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.highlight-story-panel .highlight-products.is-loading {
    min-height: var(--story-card-height);
}

.highlight-story-panel .highlight-products::-webkit-scrollbar {
    display: none;
}

.highlight-story-panel .highlight-products .product-card {
    flex: 0 0 var(--story-card-size);
    width: var(--story-card-size);
    min-width: var(--story-card-size);
    max-width: var(--story-card-size);
    height: var(--story-card-height);
    min-height: var(--story-card-height);
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    scroll-snap-align: start;
    box-shadow: none;
}

.highlight-story-panel .highlight-products .product-card .product-image {
    height: var(--story-card-size);
    background: #fff;
}

.highlight-story-panel .highlight-products .product-card .product-image img {
    padding: 0;
}

.highlight-story-panel .highlight-products .product-card .product-info {
    min-height: var(--story-card-info-height);
    padding: 8px 8px 10px;
    gap: 4px;
}

.highlight-story-panel .highlight-products .product-card .product-name {
    font-size: 11px;
    line-height: 1.3;
    min-height: 2.6em;
    max-height: 2.6em;
}

.highlight-story-panel .highlight-products .product-card .product-description {
    font-size: 10px;
    min-height: 1.2em;
    max-height: 1.2em;
    -webkit-line-clamp: 1;
}

.highlight-story-panel .highlight-products .product-card .product-price {
    font-size: 11px;
    font-weight: 700;
}

.highlight-story-panel .highlight-products .highlight-endcap-card {
    border: 1px dashed #f97316;
    background: linear-gradient(165deg, #fff7ed 0%, #ffedd5 100%);
    color: #9a3412;
}

.highlight-story-panel .highlight-products .highlight-endcap-card .product-link {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-decoration: none;
    padding: 14px 10px;
    text-align: center;
    gap: 10px;
}

.highlight-endcap-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid #fdba74;
    background: #ffffff;
    color: #ea580c;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.highlight-endcap-kicker {
    font-size: 11px;
    font-weight: 700;
    color: #c2410c;
}

.highlight-endcap-title {
    font-size: 13px;
    font-weight: 800;
    line-height: 1.45;
    color: #9a3412;
}

.highlight-endcap-meta {
    font-size: 11px;
    line-height: 1.35;
    color: #7c2d12;
}

.highlight-story-panel.is-near-end .highlight-endcap-card {
    border-color: #fb923c;
    box-shadow: 0 10px 24px rgba(249, 115, 22, 0.2);
}

.highlight-story-panel .highlight-products > .product-card:nth-child(n+17) {
    display: none !important;
}

.highlight-story-panel .highlight-loading {
    background: rgba(248, 250, 252, 0.86);
}

@media (min-width: 768px) {
    .highlight-story-overlay {
        transition: opacity 0.16s ease;
    }

    .highlight-story-panel {
        right: 50%;
        left: auto;
        bottom: 22px;
        width: min(940px, calc(100vw - 34px));
        max-height: min(90vh, 820px);
        border-radius: 24px;
        transform: translate(50%, 0) scale(1);
        transition: opacity 0.14s ease;
    }

    .highlight-story-panel.is-open-panel {
        transform: translate(50%, 0) scale(1);
    }

    .highlight-story-top {
        padding: 9px 18px 8px;
    }

    .highlight-story-meta {
        padding-left: 0;
    }

    .highlight-story-controls {
        display: contents;
    }

    .highlight-story-nav {
        display: flex;
        position: absolute;
        top: 50%;
        left: 12px;
        right: 12px;
        transform: translateY(-50%);
        justify-content: space-between;
        pointer-events: none;
        z-index: 6;
    }

    .highlight-story-nav-btn {
        width: 36px;
        height: 36px;
        box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
        pointer-events: auto;
    }

    .highlight-story-title {
        font-size: 15px;
    }

    .highlight-story-close {
        top: 18px;
        left: 18px;
    }

    .highlight-story-panel .highlight-products {
        --story-card-size: 178px;
        --story-card-height: calc(var(--story-card-size) + var(--story-card-info-height));
        padding: 16px 22px 22px;
        display: flex;
        flex-wrap: nowrap;
        gap: 12px;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scroll-padding-right: 22px;
    }

    .highlight-story-panel .highlight-products.is-loading {
        min-height: var(--story-card-height);
    }

    .highlight-story-panel .highlight-products .product-card {
        flex: 0 0 var(--story-card-size);
        width: var(--story-card-size);
        min-width: var(--story-card-size);
        max-width: var(--story-card-size);
        height: var(--story-card-height);
        min-height: var(--story-card-height);
        scroll-snap-align: start;
    }

    .highlight-story-panel .highlight-products .product-card .product-image {
        height: var(--story-card-size);
    }

    .highlight-story-panel .highlight-products .product-card .product-name {
        font-size: 13px;
    }

    .highlight-story-panel .highlight-products .product-card .product-price {
        font-size: 13px;
    }

    .highlight-endcap-kicker {
        font-size: 11px;
    }

    .highlight-endcap-title {
        font-size: 14px;
    }

    .highlight-endcap-meta {
        font-size: 12px;
    }
}

@media (max-width: 390px) {
    .highlight-story-panel .highlight-products {
        --story-card-size: calc((100vw - 52px) / 3);
    }

    .highlight-story-panel .highlight-products .product-card {
        flex-basis: var(--story-card-size);
        width: var(--story-card-size);
        min-width: var(--story-card-size);
        max-width: var(--story-card-size);
    }

    .highlight-story-panel .highlight-products .product-card .product-image {
        height: var(--story-card-size);
    }
}
