/* ==========================================================================
   UPOP Upsell Popup – Modal styles
   ========================================================================== */

/* Overlay – CSS max z-index (2^31 - 1). Also set via JS for inline-style overrides. */
#upop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    z-index: 2147483647;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}

/* Force known cart drawers/panels behind the overlay when it's open.
   CheckoutWC, FunnelKit, Astra side-cart, generic patterns. */
body.upop-open #moderncart-slide-out-modal,
body.upop-open .ttt-pnwc-modal,
body.upop-open .fkcart-wrapper,
body.upop-open #cfw-side-cart,
body.upop-open .cfw-side-cart,
body.upop-open [class*="cart-drawer"],
body.upop-open [class*="side-cart"],
body.upop-open [class*="mini-cart"],
body.upop-open .woo-cart-panel,
body.upop-open .cart-panel,
body.upop-open #cfw-cart-flyout,
body.upop-open .cfw-cart-flyout,
body.upop-open [id*="cart-flyout"],
body.upop-open [class*="cart-flyout"] {
    z-index: 1 !important;
}

/* Prevent body scroll when modal is open */
body.upop-open {
    overflow: hidden;
}

/* Modal container. Themeable colors come from CSS variables set per-campaign
   by the JS (with these fallbacks). */
#upop-modal {
    --upop-modal-bg: #ffffff;
    --upop-text: #111111;
    --upop-accent: #c9a84c;
    --upop-btn-bg: #111111;
    --upop-btn-text: #ffffff;
    --upop-desc-bg: #14110a;
    --upop-desc-text: #f5edd8;
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--upop-modal-bg, #ffffff);
    border-radius: 10px;
    width: 100%;
    max-width: 680px;
    max-height: 88vh;
    overflow: hidden;
    padding: 36px 32px 28px;
    box-sizing: border-box;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    animation: upopFadeUp 0.22s ease-out both;
}

@keyframes upopFadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Close button */
#upop-close {
    position: absolute;
    top: 14px;
    right: 18px;
    background: none;
    border: none;
    font-size: 26px;
    line-height: 1;
    color: #666;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
#upop-close:hover {
    color: #111;
    background: #f0f0f0;
}

/* Heading & subtitle */
#upop-title {
    flex-shrink: 0;
    margin: 0 0 6px;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--upop-text, #111);
    line-height: 1.3;
    padding-right: 32px;
}

#upop-subtitle {
    flex-shrink: 0;
    margin: 0 0 20px;
    font-size: 0.95rem;
    color: #555;
}

/* Products list – scrollable area between fixed header and footer */
#upop-products {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    /* breathing room so the scrollbar doesn't overlap the cards */
    padding-right: 6px;
    margin-right: -6px;
}

/* Product card */
.upop-product {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 16px 0;
    border-bottom: 1px solid #ebebeb;
    transition: background 0.15s;
}
.upop-product:last-child {
    border-bottom: none;
}
.upop-product.upop-product-added {
    opacity: 0.75;
}

/* Product image */
.upop-img {
    flex-shrink: 0;
    width: 90px;
    height: 90px;
    border-radius: 6px;
    overflow: hidden;
    background: #f5f5f5;
}
.upop-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Product info */
.upop-info {
    flex: 1;
    min-width: 0;
}

.upop-name {
    margin: 0 0 4px;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.35;
}
.upop-name a {
    color: #111;
    text-decoration: none;
}
.upop-name a:hover {
    color: #007cba;
    text-decoration: underline;
}

.upop-price {
    margin-bottom: 12px;
    font-size: 1rem;
    font-weight: 700;
    color: #333;
}
.upop-price .woocommerce-Price-amount {
    color: #333;
}
.upop-price del {
    color: #999;
    font-weight: 400;
    margin-right: 4px;
}
.upop-price ins {
    text-decoration: none;
}

/* Action buttons */
.upop-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* Primary button – "Añadir al pedido" */
.upop-btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 18px;
    background: #2e7d32;
    color: #fff !important;
    border: none;
    border-radius: 5px;
    font-size: 0.87rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s, opacity 0.18s;
    white-space: nowrap;
}
.upop-btn-primary:hover:not(:disabled) {
    background: #1b5e20;
}
.upop-btn-primary:disabled,
.upop-btn-primary.upop-added {
    background: #4caf50;
    cursor: default;
    opacity: 0.85;
}

/* Secondary button – "Ver más" */
.upop-btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    background: transparent;
    color: #333 !important;
    border: 1.5px solid #ccc;
    border-radius: 5px;
    font-size: 0.87rem;
    font-weight: 500;
    text-decoration: none !important;
    cursor: pointer;
    transition: border-color 0.18s, color 0.18s;
    white-space: nowrap;
}
.upop-btn-secondary:hover {
    border-color: #555;
    color: #111 !important;
}

/* Plain-text preview teaser shown before "Ver más" */
.upop-preview {
    margin: 0 0 10px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #666;
}

/* Inline short description (revealed by "Ver más").
   Product descriptions are usually authored for a DARK background (white text,
   gold accents), so the panel defaults to a dark surface — configurable per
   campaign via the --upop-desc-* variables. */
.upop-desc {
    margin: 4px 0 12px;
    padding: 14px 16px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--upop-desc-bg, #14110a);
    border: 1px solid var(--upop-accent, #c9a84c);
    border-radius: 8px;
    font-size: 0.86rem;
    line-height: 1.6;
    color: var(--upop-desc-text, #f5edd8);
    box-sizing: border-box;
}
.upop-desc p { margin: 0 0 6px; }
.upop-desc p:last-child { margin-bottom: 0; }
/* Keep the embedded HTML (some sets max-width:780px) within the panel width */
.upop-desc > *,
.upop-desc [style*="max-width"] { max-width: 100% !important; }
.upop-desc img { max-width: 100%; height: auto; }
/* Gold scrollbar to match the dark surface */
.upop-desc::-webkit-scrollbar { width: 8px; }
.upop-desc::-webkit-scrollbar-thumb { background: rgba( 201, 168, 76, 0.4 ); border-radius: 4px; }

/* Footer – navigation, pinned to the bottom of the modal */
#upop-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 -32px -28px;
    padding: 18px 32px;
    background: var(--upop-modal-bg, #ffffff);
    border-top: 1px solid #ebebeb;
}

/* Primary nav buttons (Continuar / Proceder al pago) fill the row */
.upop-btn-checkout {
    flex: 1 1 auto;
    display: inline-block;
    padding: 13px 24px;
    background: var(--upop-btn-bg, #111);
    color: var(--upop-btn-text, #fff) !important;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    text-decoration: none !important;
    text-align: center;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: filter 0.18s;
    box-sizing: border-box;
}
.upop-btn-checkout:hover {
    filter: brightness(1.25);
}

/* Back button */
.upop-btn-back {
    flex: 0 0 auto;
    display: inline-block;
    padding: 13px 20px;
    background: transparent;
    color: #444 !important;
    border: 1.5px solid #ccc;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.18s, color 0.18s;
    box-sizing: border-box;
}
.upop-btn-back:hover {
    border-color: #555;
    color: #111 !important;
}

/* ==========================================================================
   Responsive – mobile
   ========================================================================== */
@media ( max-width: 520px ) {
    #upop-modal {
        padding: 28px 18px 20px;
        max-height: 92vh;
    }

    #upop-footer {
        margin: 0 -18px -20px;
        padding: 14px 18px;
    }

    #upop-title {
        font-size: 1.15rem;
    }

    /* Keep the desktop layout on mobile: square image on the left, text on the
       right (avoids the tall cropped images of a stacked layout). */
    .upop-product {
        flex-direction: row;
        gap: 12px;
    }

    .upop-img {
        width: 78px;
        height: 78px;
    }

    .upop-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .upop-actions .upop-qty {
        align-self: flex-start;
    }

    .upop-btn-primary,
    .upop-btn-secondary {
        width: 100%;
        text-align: center;
        justify-content: center;
    }
}

/* ==========================================================================
   Button polish — scoped under #upop-modal + !important so it overrides the
   theme's own button styles (which otherwise turn the toggle button black).
   Fully rounded corners; "Ver más/menos" uses dark-gold when active/expanded.
   ========================================================================== */
#upop-modal .upop-btn-checkout,
#upop-modal .upop-btn-primary,
#upop-modal .upop-btn-secondary,
#upop-modal .upop-btn-back {
    border-radius: 12px !important;
    box-shadow: none !important;
}

/* Primary CTAs (Continuar / Proceder al pago) — themeable, rounded */
#upop-modal .upop-btn-checkout {
    background: var(--upop-btn-bg, #111) !important;
    color: var(--upop-btn-text, #fff) !important;
    border: none !important;
}
#upop-modal .upop-btn-checkout:hover { filter: brightness(1.08); }

/* Add-to-cart — accent (gold) */
#upop-modal .upop-btn-primary {
    background: var(--upop-accent, #c9a84c) !important;
    color: #1a1408 !important;
    border: none !important;
}
#upop-modal .upop-btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
#upop-modal .upop-btn-primary.upop-added,
#upop-modal .upop-btn-primary:disabled { filter: brightness(1.12) saturate(0.6); }

/* Back — rounded outlined */
#upop-modal .upop-btn-back {
    border: 1.5px solid rgba(0,0,0,0.18) !important;
}

/* "Ver más / Ver menos" — never black. Outlined gold by default; dark-gold when
   hovered or expanded (the JS toggles .upop-expanded). */
#upop-modal .upop-btn-secondary,
#upop-modal .upop-btn-secondary:focus,
#upop-modal .upop-btn-secondary:active {
    background: transparent !important;
    color: var(--upop-accent, #c9a84c) !important;
    border: 1.5px solid var(--upop-accent, #c9a84c) !important;
}
#upop-modal .upop-btn-secondary:hover,
#upop-modal .upop-btn-secondary.upop-expanded,
#upop-modal .upop-btn-secondary.upop-expanded:focus,
#upop-modal .upop-btn-secondary.upop-expanded:active {
    background: #6f571f !important;   /* dorado oscuro */
    color: #fff !important;
    border-color: #6f571f !important;
}

/* Quantity stepper — shown for products that allow multiple */
#upop-modal .upop-qty {
    display: inline-flex;
    align-items: stretch;
    height: 40px;
    border: 1.5px solid var(--upop-accent, #c9a84c);
    border-radius: 10px;
    overflow: hidden;
}
#upop-modal .upop-qty-btn {
    width: 34px;
    border: none;
    background: transparent;
    color: var(--upop-accent, #c9a84c);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
}
#upop-modal .upop-qty-btn:hover { background: rgba( 201, 168, 76, 0.14 ); }
#upop-modal .upop-qty-input {
    width: 44px;
    border: none;
    border-left: 1px solid rgba( 201, 168, 76, 0.4 );
    border-right: 1px solid rgba( 201, 168, 76, 0.4 );
    text-align: center;
    font-size: 0.95rem;
    font-weight: 600;
    color: #222;
    background: #fff;
    padding: 0;
    -moz-appearance: textfield;
}
#upop-modal .upop-qty-input::-webkit-outer-spin-button,
#upop-modal .upop-qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
