/**
 * Elga Category Builder - Enhanced Archive & Shop Styles
 * Premium product grid with sorting, view toggle, scroll-to-top, better responsive.
 *
 * @package ElgaCategoryBuilder
 */

/* === Archive Container === */
.elga-archive {
    --elga-columns-desktop: 4;
    --elga-columns-tablet: 3;
    --elga-columns-mobile: 2;
    --elga-spacing: 20px;
    --elga-card-radius: 14px;
    --elga-button-radius: 25px;
    --elga-button-color: #2563eb;
    --elga-button-text-color: #ffffff;
    --elga-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.06);
    --elga-shadow-hover: 0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
    --elga-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --elga-bg: #f8fafc;
    --elga-card-bg: #ffffff;
    --elga-text: #1e293b;
    --elga-text-muted: #64748b;
    --elga-border: #e2e8f0;

    box-sizing: border-box;
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    color: var(--elga-text);
    -webkit-font-smoothing: antialiased;
}

.elga-archive *,
.elga-archive *::before,
.elga-archive *::after {
    box-sizing: border-box;
}

/* === Breadcrumb === */
.elga-archive__breadcrumb {
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--elga-card-bg);
    border-radius: 8px;
    border: 1px solid var(--elga-border);
}

.elga-archive__breadcrumb-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 13px;
}

.elga-archive__breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.elga-archive__breadcrumb-item::after {
    content: "";
    width: 5px;
    height: 5px;
    border-right: 1.5px solid #94a3b8;
    border-bottom: 1.5px solid #94a3b8;
    transform: rotate(-45deg);
}

.elga-archive__breadcrumb-item:last-child::after {
    content: none;
}

.elga-archive__breadcrumb-item a {
    color: var(--elga-button-color);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--elga-transition);
}

.elga-archive__breadcrumb-item a:hover {
    color: color-mix(in srgb, var(--elga-button-color) 80%, black);
    text-decoration: underline;
}

.elga-archive__breadcrumb-current {
    color: var(--elga-text-muted);
    font-weight: 600;
}

/* === Header === */
.elga-archive__header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--elga-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.elga-archive__header-left {
    flex: 1;
    min-width: 200px;
}

.elga-archive__title {
    font-size: 30px;
    font-weight: 800;
    color: var(--elga-text);
    margin: 0 0 6px;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.elga-archive__description {
    color: var(--elga-text-muted);
    font-size: 15px;
    line-height: 1.6;
    margin-bottom: 8px;
    max-width: 600px;
}

.elga-archive__count {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--elga-button-color);
    border: 1px solid #bfdbfe;
}

.elga-archive__count::before {
    content: "";
    width: 6px;
    height: 6px;
    background: var(--elga-button-color);
    border-radius: 50%;
}

/* === Toolbar (Sort + View Toggle) === */
.elga-archive__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: var(--elga-card-bg);
    border-radius: 10px;
    border: 1px solid var(--elga-border);
    flex-wrap: wrap;
}

.elga-archive__toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.elga-archive__sort-select {
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--elga-border);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--elga-text);
    background: #f8fafc;
    cursor: pointer;
    outline: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color var(--elga-transition);
}

.elga-archive__sort-select:focus {
    border-color: var(--elga-button-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.elga-archive__view-toggle {
    display: flex;
    gap: 4px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 8px;
}

.elga-archive__view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    color: var(--elga-text-muted);
    transition: all var(--elga-transition);
}

.elga-archive__view-btn:hover {
    background: #e2e8f0;
    color: var(--elga-text);
}

.elga-archive__view-btn.is-active {
    background: var(--elga-card-bg);
    color: var(--elga-button-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.elga-archive__view-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.elga-archive__results-info {
    font-size: 13px;
    color: var(--elga-text-muted);
    font-weight: 500;
}

/* === Subcategories / Category Chips === */
.elga-archive__subcategories {
    margin-bottom: 24px;
}

.elga-archive__section-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--elga-text);
    margin: 0 0 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 12px;
}

.elga-archive__subcategories-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.elga-archive__subcat-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--elga-card-bg);
    border: 1.5px solid var(--elga-border);
    border-radius: 25px;
    text-decoration: none;
    color: var(--elga-text);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--elga-transition);
    white-space: nowrap;
}

.elga-archive__subcat-chip:hover {
    background: var(--elga-button-color);
    color: var(--elga-button-text-color);
    border-color: var(--elga-button-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.elga-archive__subcat-chip:focus-visible {
    outline: 3px solid var(--elga-button-color);
    outline-offset: 2px;
}

.elga-archive__subcat-chip img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--elga-border);
}

.elga-archive__subcat-chip:hover img {
    border-color: rgba(255,255,255,0.4);
}

/* === Search === */
.elga-archive__search {
    margin-bottom: 24px;
    position: relative;
    max-width: 480px;
}

.elga-archive__search-input {
    width: 100%;
    padding: 14px 18px 14px 44px;
    border: 2px solid var(--elga-border);
    border-radius: var(--elga-button-radius);
    font-size: 14px;
    line-height: 1.5;
    transition: all var(--elga-transition);
    background: var(--elga-card-bg);
    color: var(--elga-text);
    outline: none;
}

.elga-archive__search-input:focus {
    border-color: var(--elga-button-color);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.elga-archive__search-input::placeholder {
    color: #94a3b8;
}

.elga-archive__search::before {
    content: "";
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'/%3E%3C/svg%3E");
    background-size: contain;
    pointer-events: none;
}

/* === Products Grid === */
.elga-archive__grid {
    display: grid;
    grid-template-columns: repeat(var(--elga-columns-desktop), 1fr);
    gap: var(--elga-spacing);
}

/* List view */
.elga-archive__grid.elga-view--list {
    grid-template-columns: 1fr;
    gap: 12px;
}

.elga-archive__grid.elga-view--list .elga-product-card {
    flex-direction: row;
    max-height: 140px;
}

.elga-archive__grid.elga-view--list .elga-product-card .elga-card__link {
    flex-direction: row;
}

.elga-archive__grid.elga-view--list .elga-product-card .elga-card__image-wrapper {
    width: 140px;
    min-width: 140px;
    padding-top: 0;
    height: 140px;
}

.elga-archive__grid.elga-view--list .elga-product-card .elga-card__content {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    text-align: left;
    padding: 12px 20px;
}

.elga-archive__grid.elga-view--list .elga-product-card .elga-card__title {
    flex: 1;
    -webkit-line-clamp: 1;
}

/* === Product Card === */
.elga-product-card {
    background: var(--elga-card-bg);
    border-radius: var(--elga-card-radius);
    box-shadow: var(--elga-shadow);
    overflow: hidden;
    transition: transform var(--elga-transition), box-shadow var(--elga-transition);
    display: flex;
    flex-direction: column;
    border: 1px solid transparent;
    position: relative;
}

.elga-product-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--elga-shadow-hover);
    border-color: rgba(37, 99, 235, 0.1);
}

.elga-product-card .elga-card__link {
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
    color: inherit;
    outline: none;
}

.elga-product-card .elga-card__link:focus-visible {
    outline: 3px solid var(--elga-button-color);
    outline-offset: 2px;
    border-radius: var(--elga-card-radius);
}

.elga-product-card .elga-card__image-wrapper {
    position: relative;
    width: 100%;
    padding-top: 100%;
    overflow: hidden;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.elga-product-card .elga-card__image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.elga-product-card:hover .elga-card__image {
    transform: scale(1.08);
}

.elga-product-card .elga-card__content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 14px 20px;
    flex: 1;
    justify-content: space-between;
    text-align: center;
    gap: 8px;
}

.elga-product-card .elga-card__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--elga-text);
    margin: 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* === Card Button === */
.elga-product-card .elga-card__button {
    display: inline-block;
    padding: 9px 22px;
    background: var(--elga-button-color);
    color: var(--elga-button-text-color);
    border-radius: var(--elga-button-radius);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    transition: all var(--elga-transition);
    white-space: nowrap;
    margin-top: auto;
    letter-spacing: 0.2px;
}

.elga-product-card:hover .elga-card__button {
    background: color-mix(in srgb, var(--elga-button-color) 85%, black);
    transform: scale(1.04);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

/* === Sale Badge === */
.elga-product-card__badge {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 2;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

/* === New Badge === */
.elga-product-card__badge--new {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

/* === Stock Status === */
.elga-product-card__stock {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}

.elga-product-card__stock--instock {
    background: #d1fae5;
    color: #065f46;
}

.elga-product-card__stock--outofstock {
    background: #fee2e2;
    color: #991b1b;
}

/* === Price === */
.elga-product-card__price {
    font-size: 16px;
    font-weight: 700;
    color: var(--elga-text);
}

.elga-product-card__price del {
    color: #94a3b8;
    font-weight: 400;
    font-size: 13px;
    margin-right: 4px;
}

.elga-product-card__price ins {
    text-decoration: none;
    color: #dc2626;
    font-weight: 700;
}

/* === Rating === */
.elga-product-card__rating {
    display: flex;
    align-items: center;
    gap: 1px;
    font-size: 14px;
}

.elga-product-card__star {
    color: #e2e8f0;
    font-size: 13px;
}

.elga-product-card__star--filled {
    color: #f59e0b;
}

.elga-product-card__review-count {
    font-size: 11px;
    color: var(--elga-text-muted);
    margin-left: 4px;
}

/* === Pagination === */
.elga-archive__pagination {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-top: 40px;
    gap: 16px;
}

.elga-archive__load-more {
    padding: 14px 40px;
    background: var(--elga-button-color);
    color: var(--elga-button-text-color);
    border: none;
    border-radius: var(--elga-button-radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--elga-transition);
    letter-spacing: 0.3px;
}

.elga-archive__load-more:hover {
    background: color-mix(in srgb, var(--elga-button-color) 85%, black);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.3);
}

.elga-archive__load-more:focus-visible {
    outline: 3px solid var(--elga-button-color);
    outline-offset: 3px;
}

.elga-archive__load-more:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.elga-archive__progress {
    font-size: 12px;
    color: var(--elga-text-muted);
    font-weight: 500;
}

/* === Spinner === */
.elga-builder__spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--elga-border);
    border-top-color: var(--elga-button-color);
    border-radius: 50%;
    animation: elga-spin 0.7s linear infinite;
}

@keyframes elga-spin {
    to { transform: rotate(360deg); }
}

/* === Scroll to Top Button === */
.elga-archive__scroll-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--elga-button-color);
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--elga-transition);
    z-index: 999;
}

.elga-archive__scroll-top.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.elga-archive__scroll-top:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5);
}

.elga-archive__scroll-top svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* === No results === */
.elga-archive__no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--elga-text-muted);
    font-size: 15px;
}

.elga-builder__empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--elga-text-muted);
    font-size: 15px;
}

/* === Loading Skeleton === */
.elga-product-card--skeleton {
    pointer-events: none;
}

.elga-product-card--skeleton .elga-card__image-wrapper {
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: elga-shimmer 1.5s infinite;
}

.elga-skeleton-line {
    height: 14px;
    width: 70%;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: elga-shimmer 1.5s infinite;
    border-radius: 4px;
    margin: 4px auto;
}

.elga-skeleton-line--short { width: 50%; }
.elga-skeleton-line--btn { width: 100px; height: 32px; border-radius: 25px; }

@keyframes elga-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* === Responsive: Large Desktop (1280+) === */
@media (min-width: 1281px) {
    .elga-archive {
        padding: 40px 32px;
    }
}

/* === Responsive: Tablet Landscape (1024px) === */
@media (max-width: 1024px) {
    .elga-archive__grid {
        grid-template-columns: repeat(var(--elga-columns-tablet), 1fr);
    }

    .elga-archive__title {
        font-size: 26px;
    }

    .elga-archive__toolbar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* === Responsive: Tablet Portrait (768px) === */
@media (max-width: 768px) {
    .elga-archive__grid {
        grid-template-columns: repeat(var(--elga-columns-mobile), 1fr);
        gap: 14px;
    }

    .elga-archive {
        padding: 20px 16px;
    }

    .elga-archive__header {
        flex-direction: column;
        align-items: flex-start;
    }

    .elga-archive__title {
        font-size: 22px;
    }

    .elga-archive__search {
        max-width: 100%;
    }

    .elga-product-card .elga-card__title {
        font-size: 13px;
    }

    .elga-product-card .elga-card__button {
        padding: 7px 16px;
        font-size: 12px;
    }

    .elga-product-card__price {
        font-size: 14px;
    }

    .elga-archive__view-toggle {
        display: none;
    }

    .elga-archive__subcategories-grid {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 4px;
    }

    .elga-archive__subcategories-grid::-webkit-scrollbar {
        display: none;
    }

    /* List view revert on mobile */
    .elga-archive__grid.elga-view--list {
        grid-template-columns: repeat(var(--elga-columns-mobile), 1fr);
    }

    .elga-archive__grid.elga-view--list .elga-product-card {
        flex-direction: column;
        max-height: none;
    }

    .elga-archive__grid.elga-view--list .elga-product-card .elga-card__link {
        flex-direction: column;
    }

    .elga-archive__grid.elga-view--list .elga-product-card .elga-card__image-wrapper {
        width: 100%;
        padding-top: 100%;
        height: auto;
        min-width: 0;
    }

    .elga-archive__grid.elga-view--list .elga-product-card .elga-card__content {
        flex-direction: column;
        text-align: center;
        align-items: center;
    }
}

/* === Responsive: Small Mobile (480px) === */
@media (max-width: 480px) {
    .elga-archive__grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .elga-archive {
        padding: 16px 10px;
    }

    .elga-product-card .elga-card__content {
        padding: 10px 8px 14px;
    }

    .elga-product-card .elga-card__title {
        font-size: 12px;
    }

    .elga-product-card .elga-card__button {
        padding: 6px 12px;
        font-size: 11px;
    }

    .elga-archive__subcat-chip {
        font-size: 11px;
        padding: 6px 10px;
    }

    .elga-archive__breadcrumb {
        padding: 8px 12px;
    }

    .elga-archive__scroll-top {
        bottom: 20px;
        right: 16px;
        width: 38px;
        height: 38px;
    }
}

/* === Responsive: Very Small (360px) === */
@media (max-width: 360px) {
    .elga-archive__grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .elga-archive__title {
        font-size: 20px;
    }
}

/* === Accessibility === */
.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
    .elga-product-card,
    .elga-product-card .elga-card__image,
    .elga-product-card .elga-card__button,
    .elga-archive__subcat-chip,
    .elga-archive__scroll-top,
    .elga-archive__load-more {
        transition: none;
    }

    .elga-product-card:hover {
        transform: none;
    }

    .elga-product-card:hover .elga-card__image {
        transform: none;
    }

    .elga-product-card--skeleton .elga-card__image-wrapper,
    .elga-skeleton-line {
        animation: none;
        background: #e2e8f0;
    }
}

/* === Print === */
@media print {
    .elga-archive__search,
    .elga-archive__toolbar,
    .elga-archive__pagination,
    .elga-archive__scroll-top {
        display: none;
    }

    .elga-product-card {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }
}
