/**
 * WC Checkout Optimizer — Subscription upsell styles.
 *
 * Loaded site-wide by WCO_Subscription_Upsell::enqueue_assets().
 * Covers: product-page shortcode widget (Phase 28).
 * Cart/checkout banner variants (Phase 29) will add more rules to this file.
 *
 * @package WC_Checkout_Optimizer
 */

/* ==========================================================================
   Base card
   ========================================================================== */

.wco-upsell {
    display:          block;
    box-sizing:       border-box;
    padding:          20px 24px;
    margin:           24px 0;
    background-color: var(--color-surface, #1a1a1a);
    color:            var(--color-text, #e5e5e5);
    border:           1px solid var(--color-border, #2a2a2a);
    border-left:      4px solid var(--color-gold, #d4a437);
    border-radius:    4px;
    font-family:      inherit;
    line-height:      1.5;
}

/* ==========================================================================
   Product-page variant (D-01 compact card, D-02 gold left border)
   ========================================================================== */

.wco-upsell--product {
    max-width: 520px;
}

/* ==========================================================================
   Cart-page variant (D-11 full widget: headline + benefits + CTA)
   Explicit width cap removed — overrides any ancestor cap and the --product
   variant sibling — cart-totals column is a natural full-width context.
   ========================================================================== */

.wco-upsell--cart {
    max-width: none;
    width:     100%;
}

/* ==========================================================================
   Checkout-page variant (D-12 condensed widget: headline + CTA only)
   Inherits natural width from the review-order sidebar container.
   Tightened vertical padding because the checkout sidebar is dense.
   ========================================================================== */

.wco-upsell--checkout {
    max-width: none;
    width:     100%;
    padding:   16px 20px;
    margin:    16px 0;
}

/* ==========================================================================
   Headline
   ========================================================================== */

.wco-upsell__headline {
    margin:      0 0 12px;
    font-size:   1.05rem;
    font-weight: 700;
    color:       var(--color-gold, #d4a437);
}

/* ==========================================================================
   Benefits list
   ========================================================================== */

.wco-upsell__benefits {
    list-style: none;
    padding:    0;
    margin:     0 0 16px;
}

.wco-upsell__benefit {
    position:     relative;
    padding-left: 20px;
    margin:       6px 0;
    font-size:    0.95rem;
}

.wco-upsell__benefit::before {
    content:     "\2666"; /* diamond — matches site gold accent system */
    position:    absolute;
    left:        0;
    top:         0;
    color:       var(--color-gold, #d4a437);
    font-size:   0.9em;
    line-height: 1.6;
}

/* ==========================================================================
   CTA button
   ========================================================================== */

.wco-upsell__cta {
    display:          inline-block;
    padding:          10px 20px;
    background-color: var(--color-gold, #d4a437);
    color:            #000;
    font-weight:      700;
    text-decoration:  none;
    border-radius:    3px;
    letter-spacing:   0.02em;
    transition:       filter 0.15s ease;
}

.wco-upsell__cta:hover,
.wco-upsell__cta:focus {
    filter:          brightness(1.1);
    text-decoration: none;
    color:           #000;
}

/* ==========================================================================
   D-11 Loading spinner — dot-pulse via ::before on aria-disabled CTA
   Attaches automatically when upsell.js setLoading() adds aria-disabled="true".
   ZERO new JS. CSS pseudo-element + attribute selector only.
   First in-plugin spinner (RESEARCH Q5 Finding 1 — no prior precedent).
   ========================================================================== */

.wco-upsell__cta {
    min-width:  160px;   /* Prevent width jitter when label swaps to "Adding…" */
    text-align: center;
}

.wco-upsell__cta[aria-disabled="true"] {
    pointer-events: none;
    opacity:        0.85;
    cursor:         wait;
}

.wco-upsell__cta[aria-disabled="true"]::before {
    content:         "";
    display:         inline-block;
    width:           4px;
    height:          4px;
    margin-right:    10px;
    border-radius:   50%;
    background:      currentColor;                                  /* black on gold CTA */
    box-shadow:      8px 0 0 currentColor, 16px 0 0 currentColor;   /* 3 dots via box-shadow */
    animation:       wco-upsell-dot-pulse 1s infinite ease-in-out;
    vertical-align:  middle;
    transform:       translateY(-1px);                              /* optical alignment */
}

@keyframes wco-upsell-dot-pulse {
    0%, 100% { opacity: 0.3; }
    50%      { opacity: 1;   }
}

/* ==========================================================================
   Reveal state — pending (opacity 0) → ready (150ms fade-in)
   Anti-flash reveal primitive per CONTEXT.md D-08, D-09, D-10.
   ========================================================================== */

.wco-upsell--pending {
    opacity: 0 !important;
}

.wco-upsell--ready {
    opacity:    1;
    transition: opacity 150ms ease-out;
}

/* ==========================================================================
   Dismiss exit animation — collapse + fade over ~200ms
   Per CONTEXT.md D-13: max-height from inline scrollHeight → 0,
   opacity 1 → 0, vertical padding → 0, margin → 0.
   JS listens for transitionend on the max-height property (D-14).
   ========================================================================== */

.wco-upsell {
    transition-property: max-height, opacity, margin-top, margin-bottom, padding-top, padding-bottom;
    transition-duration: 200ms;
    transition-timing-function: ease-in;
    overflow:                   hidden;
}

.wco-upsell--dismissing {
    max-height:     0 !important;
    opacity:        0 !important;
    margin-top:     0 !important;
    margin-bottom:  0 !important;
    padding-top:    0 !important;
    padding-bottom: 0 !important;
}

/* ==========================================================================
   "No thanks" dismiss button — secondary/tertiary affordance
   Per CONTEXT.md D-01 ("No thanks" text, not × icon), D-04 (below CTA).
   Styled as muted link so it does NOT compete with the gold CTA.
   ========================================================================== */

.wco-upsell__dismiss {
    display:          block;
    margin:           10px auto 0;
    padding:          4px 8px;
    background:       transparent;
    border:           0;
    color:            var(--color-text, #e5e5e5);
    opacity:          0.65;
    font-family:      inherit;
    font-size:        0.85rem;
    text-decoration:  underline;
    cursor:           pointer;
    transition:       opacity 0.15s ease;
}

.wco-upsell__dismiss:hover,
.wco-upsell__dismiss:focus {
    opacity:         1;
    text-decoration: underline;
    outline:         none;
}

.wco-upsell__dismiss:focus-visible {
    outline:        2px solid var(--color-gold, #d4a437);
    outline-offset: 2px;
}

/* ==========================================================================
   Reduced-motion override — zero out both reveal and dismiss transitions
   Users who opted out of motion see instant state changes.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .wco-upsell,
    .wco-upsell--ready,
    .wco-upsell__dismiss {
        transition: none !important;
    }

    /* D-11: static loading state — visible affordance, no animation. */
    .wco-upsell__cta[aria-disabled="true"]::before {
        animation: none;
        opacity:   0.6;
    }
}

/* ==========================================================================
   Responsive — mobile
   ========================================================================== */

@media (max-width: 480px) {
    .wco-upsell {
        padding: 16px 18px;
        margin:  16px 0;
    }

    .wco-upsell__headline {
        font-size: 1rem;
    }

    .wco-upsell__cta {
        display:    block;
        width:      100%;
        text-align: center;
    }
}

/* ==========================================================================
   Phase 32.1 GAP-02 G-03 / IN-05: Cart-has-sub widget hide
   Applied by assets/upsell.js hideProductWidgetIfCartHasSub() when the
   wco_cart_has_sub cookie reads '1'. Class-based so a future "un-hide on
   cart mutation" path can undo via classList.remove() alone — inline
   style.display would not compose with pure CSS. !important guards against
   any future .wco-upsell--product rule that raises specificity on display.
   ========================================================================== */

.wco-upsell--hidden-by-cart-sub {
    display: none !important;
}

/* ==========================================================================
   Phase 32.1 D-08 / D-09: Sticky cart-scoped discount banner
   Renders site-wide via wp_footer when WC()->cart contains a WCS product.
   Fixed top. No user-dismiss (passive status chip — R7 research pick).
   Layout-shift-free via body.wco-has-sub-banner { padding-top } reservation.
   Oxygen Builder header z-index typically 9999; banner at 100000 sits above
   without contesting with native <dialog> (browser top-layer always wins).
   ========================================================================== */

.wco-sub-banner {
    position:         fixed;
    top:              0;
    left:             0;
    right:            0;
    z-index:          100000;
    box-sizing:       border-box;
    height:           40px;               /* constant across breakpoints — prevents media-query CLS */
    padding:          0 24px;
    display:          flex;
    align-items:      center;
    justify-content:  center;
    background-color: var(--color-surface, #1a1a1a);
    color:            var(--color-text, #e5e5e5);
    border-bottom:    1px solid var(--color-border, #2a2a2a);
    border-left:      4px solid var(--color-gold, #d4a437);
    font-family:      inherit;
    font-size:        0.9rem;
    line-height:      1.4;
    animation:        wco-sub-banner-slide-in 200ms ease-out;
}

.wco-sub-banner__message {
    margin:        0;
    padding:       0;
    text-align:    center;
    max-width:     100%;
    overflow-wrap: break-word;
}

/* D-09: reserve vertical space before JS evaluates — server-side body_class
   filter emits this class from add_sub_banner_body_class(). */
body.wco-has-sub-banner {
    padding-top: 40px;
}

/* WP admin bar collision — logged-in admins see the admin bar; banner sits
   below it. Admin bar is 32px (desktop) / 46px (mobile ≤782px). */
body.admin-bar.wco-has-sub-banner {
    padding-top: 72px;   /* 40 banner + 32 admin bar */
}

body.admin-bar .wco-sub-banner {
    top: 32px;
}

@media (max-width: 782px) {
    body.admin-bar.wco-has-sub-banner {
        padding-top: 86px;   /* 40 banner + 46 admin bar mobile */
    }

    body.admin-bar .wco-sub-banner {
        top: 46px;
    }
}

/* Responsive — mobile: shrink horizontal padding, allow wrap to 2 lines max
   WITHOUT changing the 40px banner height (CLS prevention). */
@media (max-width: 640px) {
    .wco-sub-banner {
        padding:   6px 16px;
        height:    40px;       /* HOLD — do not change, else CLS on resize */
        font-size: 0.85rem;
    }

    .wco-sub-banner__message {
        line-height: 1.3;
    }
}

/* Reduced-motion — skip slide-in animation. */
@media (prefers-reduced-motion: reduce) {
    .wco-sub-banner {
        animation: none;
    }
}

@keyframes wco-sub-banner-slide-in {
    from {
        transform: translateY(-100%);
        opacity:   0;
    }
    to {
        transform: translateY(0);
        opacity:   1;
    }
}
