/* UpWiz WooCommerce compatibility overrides
 * Loaded last to reduce conflicts between legacy theme CSS and modern Woo classes.
 */

:root {
    --white: #ffffff;
    --color-primary-dark: var(--color-primary-deep);
    --color-surface: var(--bg-secondary);
    --color-text: var(--text-primary);
    --color-text-muted: var(--text-muted);
    --color-border: var(--border-color);
    --radius-2xl: 32px;
    --upwiz-fixed-header-offset: 72px;
}

/* Keep footer anchored on short Woo pages (empty cart/account gate). */
body.woocommerce-page {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

body.woocommerce-page #content.site-content {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
}

body.woocommerce-page #content.site-content > .site-main {
    flex: 1 0 auto;
}

body.woocommerce-page .site-footer {
    margin-top: auto;
}

/* Keep normal header actions on order-received.
 * style.css hides nav/actions for all checkout states with !important.
 */
body.woocommerce-order-received .site-header .main-navigation,
body.woocommerce-order-received .site-header .header-actions {
    display: flex !important;
}

/* Fixed-header offset on classic Woo pages that do not include their own top spacing. */
body.woocommerce-cart .site-main,
body.woocommerce-account .site-main {
    padding-top: calc(var(--upwiz-admin-bar-offset, 0px) + var(--upwiz-fixed-header-offset) + clamp(1.15rem, 2.8vw, 1.9rem));
    padding-bottom: clamp(2.4rem, 5.6vw, 4rem);
}

body.woocommerce-cart .entry-title,
body.woocommerce-account .entry-title {
    margin-top: 0;
    margin-bottom: 1.25rem;
}

body.woocommerce-account .upwiz-account-main {
    padding-top: calc(var(--upwiz-admin-bar-offset, 0px) + var(--upwiz-fixed-header-offset) + clamp(1.15rem, 2.8vw, 1.9rem));
    padding-bottom: clamp(2.4rem, 5.6vw, 4rem);
}

body.woocommerce-account .upwiz-account-main .entry-header {
    display: none;
}

body.woocommerce-account .upwiz-account-main .entry-content {
    max-width: min(100%, var(--container-width));
    width: 100%;
    margin: 0 auto;
}

body.woocommerce-account .upwiz-account-main .entry-content > :first-child {
    margin-top: 0;
}

/* Avoid double vertical offset from legacy account wrapper + fixed-header spacing. */
body.woocommerce-account .entry-content > .woocommerce {
    margin-top: 0;
    padding-top: 0 !important;
    padding-bottom: 0;
}

/* Checkout already has a custom in-page title; hide the redundant page entry header. */
body.woocommerce-checkout:not(.woocommerce-order-received) .entry-header {
    display: none;
}

/* Remove legacy emoji pseudo-icons from account nav links. */
.woocommerce-account .woocommerce-MyAccount-navigation ul li[class*="woocommerce-MyAccount-navigation-link--"] a::before {
    content: none !important;
    display: none !important;
}

/* Ensure classic + block product templates stay aligned after Woo updates. */
.woocommerce :is(.wc-block-product-template, .wp-block-woocommerce-product-template) {
    list-style: none;
    margin: 0;
    padding: 0;
}

.woocommerce :is(.wc-block-product-template, .wp-block-woocommerce-product-template) :is(li.wc-block-product, .wc-block-product) {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

/* Slightly reduce oversized button text for better scanability on cards. */
.woocommerce ul.products li.product :is(a.button, button.button, .wp-element-button),
.woocommerce :is(.wc-block-product-template, .wp-block-woocommerce-product-template) :is(.wp-element-button, .wp-block-button__link) {
    font-size: 1rem;
    line-height: 1.25;
}

/* Better wrapping in checkout/order summary rows. */
.woocommerce-checkout .woocommerce-checkout-review-order-table .product-name,
.woocommerce-checkout .wc-block-components-order-summary-item__description,
.woocommerce-checkout .wc-block-components-product-metadata {
    overflow-wrap: anywhere;
}

/* Shared focus visibility for Woo controls. */
.woocommerce :is(
    a.button,
    button.button,
    .wp-element-button,
    .wc-block-components-button,
    .wc-block-components-checkout-place-order-button,
    input,
    select,
    textarea
):focus-visible {
    outline: 3px solid rgba(41, 69, 255, 0.3);
    outline-offset: 2px;
}

/* Checkout trust list: semantic icon + tighter spacing. */
.woocommerce-checkout:not(.woocommerce-order-received) .checkout-trust-list {
    list-style: none;
    margin: 1rem 0 0;
    padding: 0.9rem 0 0;
    border-top: 1px solid var(--color-border);
    display: grid;
    gap: 0.55rem;
}

.woocommerce-checkout:not(.woocommerce-order-received) .checkout-trust-list li {
    margin: 0;
    padding: 0;
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    font-size: 0.86rem;
    line-height: 1.45;
    color: var(--color-text-muted);
}

.woocommerce-checkout:not(.woocommerce-order-received) .checkout-trust-list__icon {
    width: 1.1rem;
    height: 1.1rem;
    margin-top: 0.1rem;
    border-radius: 50%;
    border: 1px solid rgba(16, 185, 129, 0.45);
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
    flex: 0 0 1.1rem;
    position: relative;
}

.woocommerce-checkout:not(.woocommerce-order-received) .checkout-trust-list__icon::before {
    content: "";
    position: absolute;
    left: 0.34rem;
    top: 0.2rem;
    width: 0.27rem;
    height: 0.48rem;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(40deg);
}

/* Classic cart coupon row usability. */
body.woocommerce-cart .coupon .input-text {
    min-width: 190px;
    width: clamp(190px, 30vw, 260px) !important;
}

body.woocommerce-cart .coupon .button {
    min-height: 42px;
    padding-inline: 1rem;
}

body.woocommerce-cart .return-to-shop .button {
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid var(--slate-200);
    background: #f4f6fb;
    color: var(--text-primary);
    font-weight: 700;
}

body.woocommerce-cart .return-to-shop .button:hover {
    border-color: rgba(41, 69, 255, 0.35);
    color: var(--color-primary);
    background: #fff;
}

/* Empty cart is no longer a conversion flow; restore full footer links there. */
body.woocommerce-cart:has(.cart-empty) .site-footer .footer-links {
    display: block;
}

body.woocommerce-cart:has(.cart-empty) .site-footer .footer-grid {
    grid-template-columns: 1fr;
    gap: 2.5rem;
}

/* Guest checkout gate */
.upwiz-checkout-gate {
    max-width: 720px;
    margin: 1.1rem auto 0;
    padding: 1.05rem 1.1rem;
    border-radius: 14px;
    border: 1px solid rgba(41, 69, 255, 0.2);
    background: rgba(41, 69, 255, 0.06);
    text-align: center;
}

.upwiz-checkout-gate h3 {
    margin: 0 0 0.45rem;
    font-family: 'Outfit', sans-serif;
    font-size: 1.28rem;
    line-height: 1.2;
    color: var(--color-text);
}

.upwiz-checkout-gate p {
    margin: 0 0 0.85rem;
    color: var(--color-text-muted);
}

.upwiz-checkout-gate .upwiz-checkout-gate__btn {
    min-height: 46px;
    padding: 0.75rem 1.1rem;
}

/* Thank-you success icon: replace emoji with scalable SVG badge. */
.upwiz-thankyou__icon {
    width: 4rem;
    height: 4rem;
    margin: 0 auto 0.7rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(16, 185, 129, 0.12);
    color: #059669;
}

.upwiz-thankyou__icon svg {
    width: 2rem;
    height: 2rem;
    display: block;
    stroke: currentColor;
    stroke-width: 2.25;
    fill: none;
}

/* Guest account fallback CTA */
.upwiz-account-guest-gate {
    margin: 0 auto;
    padding: 1.25rem;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.06);
    width: min(100%, 760px);
}

.upwiz-account-guest-gate .btn {
    min-height: 46px;
    padding-inline: 1.2rem;
}

.upwiz-account-guest-gate h2 {
    margin: 0 0 0.45rem;
    font-size: clamp(1.25rem, 2.2vw, 1.6rem);
    line-height: 1.2;
}

.upwiz-account-guest-gate p {
    margin: 0 0 0.95rem;
    color: var(--color-text-muted);
}

/* Canonical My Account layout: override legacy theme and premium CSS with one stable structure. */
body.woocommerce-account {
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}

body.woocommerce-account .site-main .container {
    width: min(100%, var(--container-width));
}

body.woocommerce-account .entry-content > .woocommerce {
    width: min(100%, var(--container-width));
    margin-inline: auto;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    gap: clamp(1.15rem, 3vw, 2rem);
}

body.woocommerce-account .woocommerce-MyAccount-navigation,
body.woocommerce-account .woocommerce-MyAccount-content {
    float: none !important;
    width: 100% !important;
    margin: 0;
}

body.woocommerce-account .woocommerce-MyAccount-navigation {
    flex: 0 0 280px;
    align-self: flex-start;
    padding: clamp(1rem, 2vw, 1.35rem);
    border-radius: 20px;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.06);
    position: sticky;
    top: calc(var(--upwiz-admin-bar-offset, 0px) + var(--upwiz-fixed-header-offset) + 0.75rem);
}

body.woocommerce-account .woocommerce-MyAccount-navigation ul {
    display: grid;
    gap: 0.35rem;
}

body.woocommerce-account .woocommerce-MyAccount-navigation ul li {
    margin: 0;
}

body.woocommerce-account .woocommerce-MyAccount-navigation ul li a {
    min-height: 48px;
    padding: 0.8rem 1rem;
    border-radius: 14px;
    justify-content: flex-start;
    line-height: 1.3;
    background: transparent;
    color: var(--color-text);
    font-weight: 600;
    box-shadow: none;
}

body.woocommerce-account .woocommerce-MyAccount-navigation ul li:not(.is-active) a:hover {
    background: rgba(41, 69, 255, 0.06);
    color: var(--color-primary);
}

body.woocommerce-account .woocommerce-MyAccount-navigation ul li.is-active a {
    background: var(--color-primary);
    color: #fff;
    box-shadow: none;
}

body.woocommerce-account .woocommerce-MyAccount-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: clamp(1.25rem, 3vw, 2.4rem);
    border-radius: 24px;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 20px 48px rgba(15, 23, 42, 0.06);
}

body.woocommerce-account .woocommerce-MyAccount-content > :first-child {
    margin-top: 0;
}

body.woocommerce-account .woocommerce-MyAccount-content :is(table, .shop_table, form) {
    max-width: 100%;
}

@media (min-width: 992px) {
    body.woocommerce-account .entry-content > .woocommerce {
        flex-direction: row;
        align-items: flex-start;
        gap: clamp(1.5rem, 3vw, 2.5rem);
    }

    body.woocommerce-account .woocommerce-MyAccount-navigation {
        width: min(100%, 280px) !important;
    }
}

/* Account nav touch behavior on narrow screens. */
@media (max-width: 991px) {
    body.woocommerce-cart .site-main,
    body.woocommerce-account .site-main {
        padding-top: calc(var(--upwiz-admin-bar-offset, 0px) + var(--upwiz-fixed-header-offset) + 1.05rem);
    }

    body.woocommerce-account .upwiz-account-main {
        padding-top: calc(var(--upwiz-admin-bar-offset, 0px) + var(--upwiz-fixed-header-offset) + 1.05rem);
    }

    body.woocommerce-account .entry-content > .woocommerce {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 1rem;
    }

    body.woocommerce-account .woocommerce-MyAccount-navigation {
        position: static;
        top: auto;
        width: 100% !important;
        max-width: 100%;
        padding: 0.9rem;
    }

    body.woocommerce-account .woocommerce-MyAccount-content {
        width: 100% !important;
        max-width: 100%;
        overflow-x: hidden;
    }

    body.woocommerce-account .woocommerce-MyAccount-navigation ul {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .woocommerce-account .woocommerce-MyAccount-navigation {
        scrollbar-width: thin;
        scrollbar-color: var(--slate-300) transparent;
    }

    .woocommerce-account .woocommerce-MyAccount-navigation ul li a {
        min-height: 42px;
        justify-content: center;
        text-align: center;
    }

    body.woocommerce-account .woocommerce-MyAccount-content {
        padding: clamp(1rem, 4vw, 1.5rem);
    }

    body.woocommerce-cart .coupon {
        display: flex;
        flex-wrap: wrap;
        gap: 0.55rem;
        align-items: stretch;
    }

    body.woocommerce-cart .coupon .input-text,
    body.woocommerce-cart .coupon .button {
        width: 100% !important;
        min-width: 0;
    }
}

@media (min-width: 768px) {
    body.woocommerce-cart:has(.cart-empty) .site-footer .footer-grid {
        grid-template-columns: 2fr 1fr 1fr;
        gap: 4rem;
    }
}

@media (max-width: 767px) {
    body.woocommerce-account .upwiz-account-main .entry-content {
        width: min(100%, 100%);
    }

    body.woocommerce-account .woocommerce-MyAccount-navigation ul {
        grid-template-columns: 1fr;
    }

    .upwiz-account-guest-gate {
        padding: 1.1rem;
        border-radius: 14px;
    }

    .upwiz-account-guest-gate .btn {
        width: 100%;
        justify-content: center;
    }
}
