/* ========================================
   PRODUCT / CATALOG / DETAIL
   Base -> Layout -> descendants -> states -> compounds
   Media queries at the bottom.
   ======================================== */

/* ----- Base / single-class selectors ----- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
}

.product-card {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 220ms ease, transform 220ms ease;
}

.product-media {
    aspect-ratio: 1 / 1;
    border: none;
    border-radius: 0;
    background: #f1f3f5;
}

.product-media-compact {
    aspect-ratio: 16 / 10;
}

.product-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: auto;
    padding: 0.75rem 1rem 1rem;
}

.product-price-stack {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sale-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    background: #dc2626;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.price-original {
    color: var(--muted);
    font-size: 0.9rem;
    text-decoration: line-through;
}

.category-card {
    display: grid;
    -webkit-backdrop-filter: blur(12px);
    background: var(--surface);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    gap: 0.75rem;
    align-content: start;
    min-width: 0;
}

.category-pills {
    margin-top: 0.25rem;
}

.category-pill {
    padding: 0.55rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.55);
}

.breadcrumb {
    color: var(--muted);
    font-size: 0.95rem;
}

.detail-sidebar,
.detail-section {
    display: grid;
    gap: 1rem;
}

.detail-stock {
    color: var(--muted);
}

.detail-features {
    margin: 0;
    padding-left: 1.25rem;
}

.detail-section {
    padding: 1.25rem 1.5rem;
    border-radius: 24px;
    -webkit-backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(12px);
    border: 1px solid var(--line);
}

.detail-stat {
    padding: 1rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--line);
}

.catalog-pagination {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
}

.catalog-page-links {
    grid-column: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    justify-content: center;
}

.catalog-page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: 0 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.6);
}

.catalog-region {
    display: grid;
    gap: 1.5rem;
    transition: opacity 220ms ease, transform 220ms ease;
}

.product-actions {
    justify-content: flex-start;
}

.catalog-toolbar {
    justify-content: space-between;
    align-items: end;
}

.catalog-sort-form {
    margin-left: auto;
}

.catalog-results-summary {
    margin: 0;
    color: var(--muted);
}

.catalog-sort-form select,
.search-form input {
    min-height: 2.75rem;
    padding: 0.7rem 0.9rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface-strong);
}

.catalog-sort-form select {
    min-width: 13rem;
}

.catalog-sort-form label,
.search-form label {
    font-weight: 700;
}

.search-form input {
    flex: 1 1 240px;
}

.hero-panel,
.panel,
.category-card,
.detail-sidebar {
    border-radius: 28px;
    padding: 1.5rem;
}

.about-page h1,
.not-found h1 {
    margin: 0;
    font-size: clamp(1.6rem, 3vw, 3.8rem);
    line-height: 0.95;
}

.hero-actions,
.product-meta,
.section-heading,
.search-form,
.catalog-toolbar,
.catalog-sort-form,
.product-actions,
.category-pills,
.breadcrumb,
.detail-highlights {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    align-items: center;
}

/* ----- pseudo-states on base selectors ----- */
.product-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.category-pill.is-active {
    background: var(--accent-deep);
    color: #fff;
    border-color: var(--accent-deep);
}

.catalog-page-link.is-active {
    background: linear-gradient(135deg, var(--accent), var(--accent-deep));
    border-color: transparent;
    color: #fff;
}

.catalog-region.is-fetching {
    opacity: 0.35;
    transform: translateY(0.65rem);
    pointer-events: none;
}

/* ----- descendants (class + element) ----- */
.product-card h2,
.product-card h3 {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.35;
    margin: 0;
    padding: 0.75rem 1rem 0;
}

.product-card p {
    font-size: 0.9rem;
    color: var(--muted);
    margin: 0;
    padding: 0.25rem 1rem;
}

.product-media img {
    transition: transform 400ms ease;
}

.product-price-stack strong {
    font-size: 1.1rem;
    font-weight: 700;
}

.hero-panel li,
.not-found p,
.category-card p,
.detail-section p,
.detail-features li {
    line-height: 1.6;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.category-card h3,
.detail-sidebar h2,
.detail-section h2 {
    margin: 0;
    font-size: 1.4rem;
}

.breadcrumb a {
    text-decoration: underline;
    text-underline-offset: 0.15rem;
}

.product-media img,
.detail-media-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-media {
    position: relative;
    overflow: hidden;
    border-radius: 22px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.55);
}

.product-media {
    aspect-ratio: 4 / 3;
}

.detail-stat strong,
.detail-stat span {
    display: block;
}

.detail-stat strong {
    font-size: 1.35rem;
}

.catalog-pagination > a:first-child {
    grid-column: 1;
    justify-self: start;
}

.catalog-pagination > a:last-child {
    grid-column: 3;
    justify-self: end;
}

/* ----- compound / multi-class & pseudo-descendants ----- */
.product-card:hover .product-media img {
    transform: scale(1.04);
}

.product-price-stack.is-discounted {
    grid-template-columns: auto auto auto;
    align-items: center;
    gap: 0.55rem;
    justify-content: start;
}

.product-category-link,
.product-card h2 a,
.product-card h3 a,
.category-card h3 a {
    width: fit-content;
}

.product-actions form {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin: 0;
}

.category-card {
    min-height: 180px;
}

/* card actions (higher specificity) */
.product-card .product-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
}

.product-card .product-actions form {
    display: grid;
    gap: 0.45rem;
    align-content: start;
    min-width: 0;
}

.product-card .product-actions .button {
    width: 100%;
}

.product-card .product-actions > .button {
    min-height: 2.75rem;
}

/* ========================================
   PRODUCT DETAIL PAGE (higher specificity)
   ======================================== */
.product-detail-page {
    display: grid;
    gap: 2.5rem;
}

.product-detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    gap: 3rem;
    align-items: start;
}

/* Gallery */
.product-detail-gallery {
    display: grid;
    gap: 1rem;
}

.product-detail-main-image {
    margin: 0;
    padding: 0;
    border-radius: 12px;
    overflow: hidden;
    background: #f1f3f5;
    aspect-ratio: 4 / 3;
    max-height: 420px;
}

.product-detail-main-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-detail-thumbs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 0.6rem;
}

.product-detail-thumb {
    margin: 0;
    padding: 0;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    background: #f1f3f5;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 180ms;
}

.product-detail-thumb:hover,
.product-detail-thumb.is-active {
    border-color: var(--accent);
}

.product-detail-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Info Panel */
.product-detail-info {
    display: grid;
    gap: 1.25rem;
    align-content: start;
}

.product-detail-category {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.product-detail-info h1 {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
    letter-spacing: -0.02em;
}

.product-detail-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.product-detail-separator {
    color: var(--line);
}

.product-detail-stock.in-stock {
    color: #15803d;
}

.product-detail-stock.out-of-stock {
    color: #dc2626;
}

/* Price */
.product-detail-price {
    padding: 1rem 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.product-detail-price .product-price-stack strong {
    font-size: 1.6rem;
}

.product-detail-sale-price {
    color: #dc2626;
}

.product-detail-price .sale-badge {
    margin-left: 0.5rem;
    vertical-align: middle;
}

/* Form */
.product-detail-form {
    display: grid;
    gap: 1rem;
}

.product-detail-options {
    display: grid;
    gap: 0.75rem;
}

.product-detail-qty-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.product-detail-qty-row label {
    font-size: 0.9rem;
    font-weight: 600;
}

.product-detail-qty-row input {
    width: 5rem;
    min-height: 2.75rem;
    padding: 0.65rem;
    border-radius: 10px;
    border: 1px solid var(--line);
    text-align: center;
    font-size: 1rem;
}

/* Trust */
.product-detail-trust {
    display: grid;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 10px;
    font-size: 0.85rem;
    color: var(--muted);
}

/* Tabs */
.product-detail-tabs {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
}

.product-detail-tabs-nav {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
}

.product-detail-tabs-nav button {
    padding: 0.9rem 1.25rem;
    border: none;
    background: transparent;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 180ms, border-color 180ms;
}

.product-detail-tabs-nav button:hover {
    color: var(--ink);
}

.product-detail-tabs-nav button.is-active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: var(--surface);
}

.product-detail-tab-panel {
    display: none;
    padding: 1.5rem;
}

.product-detail-tab-panel.is-active {
    display: block;
}

.product-detail-tab-panel p {
    line-height: 1.7;
    margin: 0;
}

.detail-features-list {
    margin: 0;
    padding-left: 1.25rem;
    display: grid;
    gap: 0.5rem;
}

.detail-features-list li {
    line-height: 1.6;
}

.detail-specs-list {
    display: grid;
    gap: 0.75rem;
    margin: 0;
}

.detail-specs-list div {
    display: grid;
    grid-template-columns: minmax(0, 0.4fr) minmax(0, 1fr);
    gap: 1rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--line);
}

.detail-specs-list div:last-child {
    border-bottom: none;
}

.detail-specs-list dt {
    font-weight: 600;
    color: var(--muted);
    font-size: 0.9rem;
}

.detail-specs-list dd {
    margin: 0;
}

/* Related Products */
.product-detail-related {
    padding-top: 1rem;
}

.product-detail-related h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 1.25rem;
}

.product-card-swatches {
    display: flex;
    gap: .4rem;
    margin: .4rem 0;
}

.product-swatch {
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,.12);
    cursor: pointer;
    padding: 0;
    appearance: none;
    background-clip: padding-box;
}

.product-swatch.is-selected {
    box-shadow: 0 0 0 2px #fff, 0 0 0 3px currentColor;
}

.product-color-variants {
    margin: .75rem 0;
}

.product-color-swatches {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    margin-top: .35rem;
}

.product-detail-options-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
}

/* ========================================
   MEDIA QUERIES — always last
   ======================================== */
@media (max-width: 920px) {
    .product-grid,
    .category-grid,
    .cart-layout,
    .checkout-layout,
    .order-status-layout,
    .cart-item-row,
    .checkout-grid-2,
    .checkout-grid-3 {
        grid-template-columns: 1fr;
    }

    .catalog-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .catalog-sort-form {
        width: 100%;
        margin-left: 0;
    }

    .catalog-sort-form select {
        width: 100%;
    }

    .mini-cart-drawer {
        width: 100%;
    }

    .hero-banner {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 2rem 1rem;
    }

    .trust-bar {
        grid-template-columns: repeat(2, 1fr);
    }

    .footer-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .sub-nav {
        padding: 0 1rem;
    }
}

@media (max-width: 640px) {
    .catalog-header h1,
    .about-page h1,
    .not-found h1 {
        font-size: 2.4rem;
    }

    .chat-widget {
        right: 0.75rem;
        left: 0.75rem;
        bottom: max(0.75rem, env(safe-area-inset-bottom));
        justify-items: stretch;
    }

    .chat-launcher {
        width: 100%;
        min-height: 4.25rem;
        padding: 1rem 1.1rem;
        font-size: 1rem;
        touch-action: manipulation;
    }

    .chat-panel {
        width: 100%;
        max-height: min(36rem, calc(100vh - 6.25rem));
        padding: 1rem;
        border-radius: 24px 24px 20px 20px;
    }

    .chat-panel-body {
        min-height: 10rem;
    }

    .chat-panel-header {
        gap: 0.65rem;
    }

    .chat-messages {
        max-height: min(14rem, calc(100vh - 18rem));
    }

    .chat-field input,
    .chat-field textarea,
    .chat-form .button {
        font-size: 16px;
    }

    .chat-field textarea {
        min-height: 4rem;
    }
}