/**
 * MG-04.5A — Global Commerce Components Foundation
 * Presentation primitives only. No WooCommerce template replacement.
 */

.mg-section-heading {
    max-width: 760px;
    margin-bottom: clamp(1.25rem, 2vw, 2rem);
}

.mg-section-heading--center {
    margin-inline: auto;
    text-align: center;
}

.mg-section-heading__eyebrow {
    margin: 0 0 0.45rem;
    color: var(--mg-color-secondary);
    font-size: 0.78rem;
    font-weight: var(--mg-font-weight-bold);
    letter-spacing: 0.08em;
    line-height: 1.4;
    text-transform: uppercase;
}

.mg-section-heading__title {
    margin: 0;
    color: var(--mg-text-heading);
    font-size: clamp(1.55rem, 2.4vw, 2.2rem);
    line-height: 1.16;
}

.mg-section-heading__description {
    margin: 0.7rem 0 0;
    color: var(--mg-text-muted);
    line-height: 1.65;
}

.mg-commerce-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0.25rem 0.55rem;
    border: 1px solid var(--mg-border);
    border-radius: 999px;
    background: var(--mg-surface-alt);
    color: var(--mg-text);
    font-size: 0.75rem;
    font-weight: var(--mg-font-weight-semibold);
    line-height: 1.2;
    white-space: nowrap;
}

.mg-commerce-badge--sale,
.mg-commerce-badge--new {
    border-color: color-mix(in srgb, var(--mg-color-secondary) 24%, transparent);
    background: color-mix(in srgb, var(--mg-color-secondary) 10%, #fff);
    color: var(--mg-color-secondary);
}

.mg-commerce-badge--stock {
    border-color: color-mix(in srgb, var(--mg-success) 24%, transparent);
    background: color-mix(in srgb, var(--mg-success) 9%, #fff);
    color: var(--mg-success);
}

.mg-commerce-badge--warning {
    border-color: color-mix(in srgb, var(--mg-warning) 26%, transparent);
    background: color-mix(in srgb, var(--mg-warning) 8%, #fff);
    color: var(--mg-warning);
}

.mg-commerce-badge--muted {
    color: var(--mg-text-muted);
}

.mg-product-price {
    color: var(--mg-price);
    font-size: 1.05rem;
    font-weight: var(--mg-font-weight-bold);
    line-height: 1.35;
}

.mg-product-price del {
    margin-right: 0.35rem;
    color: var(--mg-text-muted);
    font-size: 0.9em;
    font-weight: var(--mg-font-weight-regular);
    opacity: 0.8;
}

.mg-product-price ins {
    color: var(--mg-price-sale);
    text-decoration: none;
}

.mg-stock-status {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--mg-text-muted);
    font-size: 0.84rem;
    font-weight: var(--mg-font-weight-semibold);
    line-height: 1.35;
}

.mg-stock-status__dot {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: currentColor;
}

.mg-stock-status.is-in-stock {
    color: var(--mg-success);
}

.mg-stock-status.is-low-stock {
    color: var(--mg-warning);
}

.mg-stock-status.is-out-of-stock {
    color: var(--mg-error);
}

.mg-breadcrumbs {
    width: 100%;
    border-bottom: 1px solid var(--mg-border);
    background: var(--mg-surface-soft);
}

.mg-breadcrumbs__inner,
.mg-breadcrumbs .woocommerce-breadcrumb {
    width: min(100% - (2 * var(--mg-gutter)), var(--mg-container));
    margin-inline: auto;
    padding-block: 0.72rem;
    color: var(--mg-text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.mg-breadcrumbs a {
    color: var(--mg-text);
    text-decoration: none;
}

.mg-breadcrumbs a:hover,
.mg-breadcrumbs a:focus-visible {
    color: var(--mg-color-secondary);
    text-decoration: underline;
    text-underline-offset: 0.18em;
}

.mg-breadcrumbs a:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--mg-color-secondary) 45%, transparent);
    outline-offset: 3px;
}

.mg-breadcrumbs__separator {
    display: inline-block;
    margin-inline: 0.45rem;
    color: var(--mg-border-strong);
}

.mg-breadcrumbs__current {
    color: var(--mg-text-muted);
}

@media (max-width: 767px) {
    .mg-commerce-badge {
        white-space: normal;
    }

    .mg-breadcrumbs__inner,
    .mg-breadcrumbs .woocommerce-breadcrumb {
        font-size: 0.78rem;
    }
}


/**
 * MG-04.5B — Product Card Component V1
 */

.mg-product-card {
    position: relative;
    display: flex;
    min-width: 0;
    height: 100%;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--mg-border);
    border-radius: var(--mg-radius-lg);
    background: var(--mg-surface);
    box-shadow: 0 1px 2px rgba(15, 33, 59, 0.04);
}

.mg-product-card__media {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-bottom: 1px solid var(--mg-border);
    background: var(--mg-surface-soft);
}

.mg-product-card__image-link {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    padding: 0.9rem;
}

.mg-product-card__image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 180ms ease;
}

.mg-product-card:hover .mg-product-card__image {
    transform: scale(1.025);
}

.mg-product-card__badges {
    position: absolute;
    z-index: 2;
    top: 0.75rem;
    left: 0.75rem;
    display: flex;
    max-width: calc(100% - 1.5rem);
    flex-wrap: wrap;
    gap: 0.4rem;
    pointer-events: none;
}

.mg-product-card__body {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    padding: 1rem;
}

.mg-product-card__category {
    margin: 0 0 0.4rem;
    color: var(--mg-text-muted);
    font-size: 0.76rem;
    font-weight: var(--mg-font-weight-semibold);
    line-height: 1.35;
}

.mg-product-card__title {
    margin: 0 0 0.7rem;
    color: var(--mg-text-heading);
    font-size: 0.98rem;
    font-weight: var(--mg-font-weight-semibold);
    line-height: 1.42;
}

.mg-product-card__title a {
    display: block;
    color: inherit;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.mg-product-card__title a:hover,
.mg-product-card__title a:focus-visible {
    color: var(--mg-color-secondary);
}

.mg-product-card__title a:focus-visible,
.mg-product-card__button:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--mg-color-secondary) 45%, transparent);
    outline-offset: 3px;
}

.mg-product-card .mg-product-price {
    margin-top: auto;
    padding-top: 0.15rem;
}

.mg-product-card__stock {
    margin-top: 0.6rem;
}

.mg-product-card__actions {
    margin-top: 0.9rem;
}

.mg-product-card__button {
    width: 100%;
    min-height: 44px;
    justify-content: center;
    text-align: center;
}

.mg-product-card.is-out-of-stock .mg-product-card__image {
    opacity: 0.72;
}

@media (max-width: 767px) {
    .mg-product-card__body {
        padding: 0.9rem;
    }

    .mg-product-card__image-link {
        padding: 0.75rem;
    }

    .mg-product-card__badges {
        top: 0.6rem;
        left: 0.6rem;
        max-width: calc(100% - 1.2rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .mg-product-card__image {
        transition: none;
    }

    .mg-product-card:hover .mg-product-card__image {
        transform: none;
    }
}


/* Staging validation wrapper used only when preview shortcode is inserted. */
.mg-component-preview {
    width: min(100% - (2 * var(--mg-gutter)), var(--mg-container));
    margin: 2rem auto;
}

.mg-component-preview__card {
    width: min(100%, 320px);
}


/**
 * MG-04.5C — Category Card Component V1
 */

.mg-category-card {
    display: flex;
    min-width: 0;
    height: 100%;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--mg-border);
    border-radius: var(--mg-radius-lg);
    background: var(--mg-surface);
    box-shadow: 0 1px 2px rgba(15, 33, 59, 0.04);
}

.mg-category-card__media {
    display: flex;
    aspect-ratio: 4 / 3;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-bottom: 1px solid var(--mg-border);
    background: var(--mg-surface-soft);
    padding: 1rem;
}

.mg-category-card__image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 180ms ease;
}

.mg-category-card:hover .mg-category-card__image {
    transform: scale(1.025);
}

.mg-category-card__body {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    padding: 1rem;
}

.mg-category-card__title {
    margin: 0;
    color: var(--mg-text-heading);
    font-size: 1rem;
    font-weight: var(--mg-font-weight-bold);
    line-height: 1.35;
}

.mg-category-card__title a {
    display: block;
    color: inherit;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.mg-category-card__title a:hover,
.mg-category-card__title a:focus-visible {
    color: var(--mg-color-secondary);
}

.mg-category-card__count {
    margin: 0.45rem 0 0;
    color: var(--mg-text-muted);
    font-size: 0.8rem;
    line-height: 1.4;
}

.mg-category-card__intro {
    margin: 0.65rem 0 0;
    color: var(--mg-text-muted);
    font-size: 0.85rem;
    line-height: 1.55;
}

.mg-category-card__link {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: auto;
    padding-top: 0.9rem;
    color: var(--mg-color-primary);
    font-size: 0.86rem;
    font-weight: var(--mg-font-weight-semibold);
    text-decoration: none;
}

.mg-category-card__arrow {
    flex: 0 0 auto;
    color: var(--mg-color-secondary);
    font-size: 1.05rem;
    transition: transform 160ms ease;
}

.mg-category-card__link:hover,
.mg-category-card__link:focus-visible {
    color: var(--mg-color-secondary);
}

.mg-category-card__link:hover .mg-category-card__arrow,
.mg-category-card__link:focus-visible .mg-category-card__arrow {
    transform: translateX(3px);
}

.mg-category-card__title a:focus-visible,
.mg-category-card__link:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--mg-color-secondary) 45%, transparent);
    outline-offset: 3px;
    border-radius: var(--mg-radius-sm);
}

@media (max-width: 767px) {
    .mg-category-card__media {
        padding: 0.8rem;
    }

    .mg-category-card__body {
        padding: 0.9rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mg-category-card__image,
    .mg-category-card__arrow {
        transition: none;
    }

    .mg-category-card:hover .mg-category-card__image,
    .mg-category-card__link:hover .mg-category-card__arrow,
    .mg-category-card__link:focus-visible .mg-category-card__arrow {
        transform: none;
    }
}


/**
 * MG-04.5D — Commerce Grid & Card Consistency V1
 */

.mg-commerce-grid {
    --mg-grid-columns: 4;
    display: grid;
    grid-template-columns: repeat(var(--mg-grid-columns), minmax(0, 1fr));
    gap: clamp(1rem, 2vw, 1.5rem);
    width: 100%;
    min-width: 0;
}

.mg-commerce-grid--cols-1 { --mg-grid-columns: 1; }
.mg-commerce-grid--cols-2 { --mg-grid-columns: 2; }
.mg-commerce-grid--cols-3 { --mg-grid-columns: 3; }
.mg-commerce-grid--cols-4 { --mg-grid-columns: 4; }
.mg-commerce-grid--cols-5 { --mg-grid-columns: 5; }
.mg-commerce-grid--cols-6 { --mg-grid-columns: 6; }

.mg-commerce-grid__item {
    display: flex;
    min-width: 0;
    height: 100%;
}

.mg-commerce-grid__item > .mg-product-card,
.mg-commerce-grid__item > .mg-category-card {
    width: 100%;
}

/* Shared visual rhythm between product and category cards. */
.mg-product-card,
.mg-category-card {
    border-color: var(--mg-border);
    background: var(--mg-surface);
    box-shadow: 0 1px 2px rgba(15, 33, 59, 0.04);
}

.mg-product-card__body,
.mg-category-card__body {
    min-height: 0;
}

.mg-product-card__title,
.mg-category-card__title {
    letter-spacing: 0;
}

.mg-product-card__button,
.mg-category-card__link {
    margin-top: auto;
}

/* Keep product-card CTAs aligned when titles vary in length. */
.mg-commerce-grid--product .mg-product-card__title {
    min-height: 2.8em;
}

/* Keep category-card titles visually aligned without forcing excessive height. */
.mg-commerce-grid--category .mg-category-card__title {
    min-height: 1.35em;
}

/* Balanced desktop reductions for 5–6 column grids. */
.mg-commerce-grid--cols-5 .mg-product-card__body,
.mg-commerce-grid--cols-6 .mg-product-card__body,
.mg-commerce-grid--cols-5 .mg-category-card__body,
.mg-commerce-grid--cols-6 .mg-category-card__body {
    padding-inline: 0.85rem;
}

@media (max-width: 1199px) {
    .mg-commerce-grid--cols-5,
    .mg-commerce-grid--cols-6 {
        --mg-grid-columns: 4;
    }
}

@media (max-width: 959px) {
    .mg-commerce-grid--cols-4,
    .mg-commerce-grid--cols-5,
    .mg-commerce-grid--cols-6 {
        --mg-grid-columns: 3;
    }
}

@media (max-width: 767px) {
    .mg-commerce-grid--cols-3,
    .mg-commerce-grid--cols-4,
    .mg-commerce-grid--cols-5,
    .mg-commerce-grid--cols-6 {
        --mg-grid-columns: 2;
    }

    .mg-commerce-grid {
        gap: 1rem;
    }
}

@media (max-width: 479px) {
    .mg-commerce-grid {
        --mg-grid-columns: 1;
    }

    .mg-commerce-grid--product .mg-product-card__title,
    .mg-commerce-grid--category .mg-category-card__title {
        min-height: 0;
    }
}


/**
 * MG-04.5E — Commerce States & Empty/Error UI V1
 */

.mg-commerce-state {
    display: flex;
    width: 100%;
    min-width: 0;
    align-items: flex-start;
    gap: 1rem;
    padding: clamp(1.15rem, 2.5vw, 1.75rem);
    border: 1px solid var(--mg-border);
    border-radius: var(--mg-radius-lg);
    background: var(--mg-surface-soft);
    color: var(--mg-text);
}

.mg-commerce-state__icon {
    display: inline-flex;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--mg-surface);
    color: var(--mg-color-primary);
}

.mg-commerce-state__icon svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mg-commerce-state__content {
    min-width: 0;
    flex: 1;
}

.mg-commerce-state__title {
    margin: 0;
    color: var(--mg-text-heading);
    font-size: 1.05rem;
    line-height: 1.35;
}

.mg-commerce-state__message {
    max-width: 680px;
    margin: 0.45rem 0 0;
    color: var(--mg-text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.mg-commerce-state__actions {
    margin-top: 0.9rem;
}

.mg-commerce-state__action {
    min-height: 44px;
}

.mg-commerce-state--unavailable .mg-commerce-state__icon {
    color: var(--mg-warning);
}

.mg-commerce-state--error {
    border-color: color-mix(in srgb, var(--mg-error) 25%, var(--mg-border));
}

.mg-commerce-state--error .mg-commerce-state__icon {
    color: var(--mg-error);
}

.mg-commerce-state--info .mg-commerce-state__icon {
    color: var(--mg-color-secondary);
}

@media (max-width: 479px) {
    .mg-commerce-state {
        flex-direction: column;
    }

    .mg-commerce-state__actions,
    .mg-commerce-state__action {
        width: 100%;
    }

    .mg-commerce-state__action {
        justify-content: center;
        text-align: center;
    }
}


/**
 * MG-04.5F — Global Commerce Components Final Validation
 * Defensive hardening only. No component architecture changes.
 */

.mg-product-card,
.mg-category-card,
.mg-commerce-grid,
.mg-commerce-grid__item,
.mg-commerce-state {
    box-sizing: border-box;
}

.mg-product-card *,
.mg-category-card *,
.mg-commerce-state * {
    box-sizing: border-box;
}

.mg-product-card__title,
.mg-category-card__title,
.mg-commerce-state__title,
.mg-commerce-state__message {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: normal;
}

.mg-product-card__image,
.mg-category-card__image {
    max-width: 100%;
}

.mg-product-card__button,
.mg-category-card__link,
.mg-commerce-state__action {
    touch-action: manipulation;
}

@media (max-width: 359px) {
    .mg-product-card__body,
    .mg-category-card__body,
    .mg-commerce-state {
        padding-left: 0.8rem;
        padding-right: 0.8rem;
    }

    .mg-commerce-grid {
        gap: 0.85rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mg-product-card *,
    .mg-category-card *,
    .mg-commerce-state * {
        scroll-behavior: auto !important;
    }
}


.mg-component-preview--final {
    width: min(100% - (2 * var(--mg-gutter)), var(--mg-container));
}

.mg-component-preview--final .mg-commerce-state {
    height: 100%;
}


/**
 * MG-04.5F v0.4.7 — Touch Target Hotfix
 *
 * Diagnostic v0.4.6 confirmed the remaining sub-44px targets were card-title
 * links. Increase their usable hit area without changing queries, card
 * architecture, CTA styling, header/footer, or WooCommerce logic.
 */

.mg-product-card__title a,
.mg-category-card__title a {
    display: flex;
    min-height: 44px;
    align-items: center;
}

/* Preserve compact vertical rhythm when titles naturally wrap beyond 44px. */
.mg-product-card__title a,
.mg-category-card__title a {
    padding-block: 0;
}
