/* =========================================
   JE Upsell Pro - Frontend Styles
   Modern, Responsive, RTL-ready
   ========================================= */

/* === CSS Variables (defaults, overridden by inline styles) === */
:root {
    --jeup-accent: #7C3AED;
    --jeup-btn: #7C3AED;
    --jeup-btn-text: #ffffff;
    --jeup-bg: #ffffff;
    --jeup-text: #333333;
    --jeup-radius: 16px;
    --jeup-width: 600px;
    --jeup-overlay: rgba(0, 0, 0, 0.6);
    --jeup-success: #10B981;
    --jeup-danger: #EF4444;
    --jeup-warning: #F59E0B;
    --jeup-muted: #9CA3AF;
    --jeup-border: #E5E7EB;
    --jeup-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.25);
    --jeup-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === POPUP OVERLAY === */
.jeup-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--jeup-overlay);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.jeup-popup-overlay.jeup-active {
    display: flex;
    opacity: 1;
}

/* Popup positions */
.jeup-popup-overlay.jeup-pos-center {
    align-items: center;
    justify-content: center;
}

.jeup-popup-overlay.jeup-pos-top {
    align-items: flex-start;
    padding-top: 60px;
}

.jeup-popup-overlay.jeup-pos-bottom {
    align-items: flex-end;
    padding-bottom: 40px;
}

.jeup-popup-overlay.jeup-pos-right {
    justify-content: flex-end;
    padding-right: 20px;
}

.jeup-popup-overlay.jeup-pos-left {
    justify-content: flex-start;
    padding-left: 20px;
}

/* === POPUP CONTAINER === */
.jeup-popup-container {
    background: var(--jeup-bg);
    border-radius: var(--jeup-radius);
    max-width: var(--jeup-width);
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    box-shadow: var(--jeup-shadow);
    color: var(--jeup-text);
}

/* Custom scrollbar */
.jeup-popup-container::-webkit-scrollbar {
    width: 4px;
}

.jeup-popup-container::-webkit-scrollbar-track {
    background: transparent;
}

.jeup-popup-container::-webkit-scrollbar-thumb {
    background: var(--jeup-muted);
    border-radius: 4px;
}

/* === CLOSE BUTTON === */
.jeup-popup-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.06);
    color: var(--jeup-text);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--jeup-transition);
    z-index: 10;
    padding: 0;
}

.jeup-popup-close:hover {
    background: rgba(0, 0, 0, 0.12);
    transform: rotate(90deg);
}

/* RTL close button */
[dir="rtl"] .jeup-popup-close,
.rtl .jeup-popup-close {
    right: auto;
    left: 12px;
}

/* === POPUP CONTENT === */
.jeup-popup-content {
    padding: 32px;
}

/* === OFFER HEADER === */
.jeup-offer-header {
    text-align: center;
    margin-bottom: 24px;
}

.jeup-offer-title {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 8px;
    color: var(--jeup-text);
    line-height: 1.3;
}

.jeup-offer-subtitle {
    font-size: 15px;
    color: var(--jeup-muted);
    margin: 0;
    line-height: 1.5;
}

/* === COUNTDOWN TIMER === */
.jeup-countdown {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #FEF3C7, #FDE68A);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #92400E;
}

.jeup-countdown .jeup-timer-icon {
    font-size: 18px;
}

.jeup-countdown .jeup-timer-value {
    font-family: 'Courier New', monospace;
    font-size: 16px;
    letter-spacing: 1px;
}

/* === PRODUCT CARDS === */
.jeup-offer-products {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.jeup-product-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #F9FAFB;
    border-radius: 12px;
    border: 1px solid var(--jeup-border);
    position: relative;
    transition: var(--jeup-transition);
}

.jeup-product-card:hover {
    border-color: var(--jeup-accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* Badge */
.jeup-badge {
    position: absolute;
    top: -8px;
    left: -8px;
    background: var(--jeup-danger);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    z-index: 2;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.3);
}

[dir="rtl"] .jeup-badge,
.rtl .jeup-badge {
    left: auto;
    right: -8px;
}

/* Product Image */
.jeup-product-image {
    flex-shrink: 0;
    width: 90px;
    height: 90px;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}

.jeup-product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.jeup-product-card:hover .jeup-product-image img {
    transform: scale(1.05);
}

/* Product Info */
.jeup-product-info {
    flex: 1;
    min-width: 0;
}

.jeup-product-name {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 6px;
    line-height: 1.3;
}

.jeup-product-name a {
    color: var(--jeup-text);
    text-decoration: none;
}

.jeup-product-name a:hover {
    color: var(--jeup-accent);
}

/* Rating */
.jeup-product-rating {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 6px;
}

.jeup-star {
    font-size: 13px;
    line-height: 1;
}

.jeup-star.filled {
    color: #FBBF24;
}

.jeup-star.half {
    color: #FBBF24;
    opacity: 0.6;
}

.jeup-star.empty {
    color: #D1D5DB;
}

.jeup-rating-count {
    font-size: 12px;
    color: var(--jeup-muted);
    margin-left: 4px;
}

[dir="rtl"] .jeup-rating-count,
.rtl .jeup-rating-count {
    margin-left: 0;
    margin-right: 4px;
}

/* Price */
.jeup-product-price {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.jeup-price-original {
    text-decoration: line-through;
    color: var(--jeup-muted);
    font-size: 14px;
}

.jeup-price-current {
    font-size: 17px;
    font-weight: 700;
    color: var(--jeup-accent);
}

/* Savings */
.jeup-savings {
    font-size: 13px;
    color: var(--jeup-success);
    font-weight: 600;
    margin-bottom: 2px;
}

/* Short Description */
.jeup-product-desc {
    font-size: 13px;
    color: var(--jeup-muted);
    margin: 4px 0 0;
    line-height: 1.4;
}

/* === ADD TO CART BUTTON === */
.jeup-product-actions {
    flex-shrink: 0;
}

.jeup-add-to-cart-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    background: var(--jeup-btn);
    color: var(--jeup-btn-text);
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--jeup-transition);
    white-space: nowrap;
    min-width: 100px;
    position: relative;
    overflow: hidden;
}

.jeup-add-to-cart-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.jeup-add-to-cart-btn:active {
    transform: translateY(0);
}

.jeup-add-to-cart-btn.jeup-loading {
    pointer-events: none;
    opacity: 0.8;
}

.jeup-add-to-cart-btn.jeup-loading::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: jeup-spin 0.6s linear infinite;
}

.jeup-add-to-cart-btn.jeup-added {
    background: var(--jeup-success);
}

.jeup-add-to-cart-btn.jeup-added::before {
    content: '✓';
    margin-inline-end: 4px;
}

.jeup-out-of-stock {
    font-size: 13px;
    color: var(--jeup-danger);
    font-weight: 500;
}

/* === POPUP FOOTER === */
.jeup-popup-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px 24px;
    gap: 12px;
}

.jeup-no-thanks {
    background: none;
    border: none;
    color: var(--jeup-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 8px 12px;
    transition: var(--jeup-transition);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.jeup-no-thanks:hover {
    color: var(--jeup-text);
}

.jeup-view-cart-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--jeup-accent);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: var(--jeup-transition);
}

.jeup-view-cart-link:hover {
    opacity: 0.8;
}

/* === SUCCESS STATE === */
.jeup-success-message {
    display: none;
    text-align: center;
    padding: 40px 20px;
    animation: jeup-fadeInUp 0.4s ease;
}

.jeup-success-message.jeup-show {
    display: block;
}

.jeup-success-icon {
    width: 64px;
    height: 64px;
    background: var(--jeup-success);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin: 0 auto 16px;
    animation: jeup-scaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.jeup-success-text {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}

.jeup-success-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.jeup-success-actions a {
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: var(--jeup-transition);
}

.jeup-success-actions .jeup-btn-primary {
    background: var(--jeup-btn);
    color: var(--jeup-btn-text);
}

.jeup-success-actions .jeup-btn-secondary {
    background: transparent;
    color: var(--jeup-text);
    border: 1px solid var(--jeup-border);
}

/* =========================================
   LAYOUT VARIANTS
   ========================================= */

/* === HORIZONTAL LAYOUT === */
.jeup-layout-horizontal .jeup-offer-products {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.jeup-layout-horizontal .jeup-product-card {
    flex-direction: column;
    min-width: 180px;
    max-width: 200px;
    text-align: center;
    scroll-snap-align: start;
}

.jeup-layout-horizontal .jeup-product-image {
    width: 100%;
    height: 140px;
}

.jeup-layout-horizontal .jeup-product-price {
    justify-content: center;
}

/* === GRID LAYOUT === */
.jeup-layout-grid .jeup-offer-products {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
}

.jeup-layout-grid .jeup-product-card {
    flex-direction: column;
    text-align: center;
}

.jeup-layout-grid .jeup-product-image {
    width: 100%;
    height: 130px;
}

.jeup-layout-grid .jeup-product-price {
    justify-content: center;
}

/* === MINIMAL LAYOUT === */
.jeup-layout-minimal .jeup-product-card {
    background: transparent;
    border: none;
    padding: 10px 0;
    border-bottom: 1px solid var(--jeup-border);
}

.jeup-layout-minimal .jeup-product-card:last-child {
    border-bottom: none;
}

.jeup-layout-minimal .jeup-product-image {
    width: 60px;
    height: 60px;
    border-radius: 8px;
}

/* === FULL IMAGE LAYOUT === */
.jeup-layout-full_image .jeup-product-card {
    flex-direction: column;
    text-align: center;
    padding: 0;
    overflow: hidden;
}

.jeup-layout-full_image .jeup-product-image {
    width: 100%;
    height: 200px;
    border-radius: 0;
}

.jeup-layout-full_image .jeup-product-info {
    padding: 16px;
}

.jeup-layout-full_image .jeup-product-actions {
    padding: 0 16px 16px;
    width: 100%;
}

.jeup-layout-full_image .jeup-add-to-cart-btn {
    width: 100%;
}

/* === CAROUSEL LAYOUT === */
.jeup-layout-carousel .jeup-offer-products {
    flex-direction: row;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 16px;
    padding-bottom: 12px;
    -webkit-overflow-scrolling: touch;
}

.jeup-layout-carousel .jeup-product-card {
    flex: 0 0 260px;
    flex-direction: column;
    scroll-snap-align: center;
}

.jeup-layout-carousel .jeup-product-image {
    width: 100%;
    height: 160px;
}

/* Carousel scrollbar */
.jeup-layout-carousel .jeup-offer-products::-webkit-scrollbar {
    height: 4px;
}

.jeup-layout-carousel .jeup-offer-products::-webkit-scrollbar-thumb {
    background: var(--jeup-accent);
    border-radius: 4px;
}

/* =========================================
   INLINE OFFER (Shortcode)
   ========================================= */
.jeup-inline-offer {
    margin: 24px 0;
    padding: 24px;
    background: var(--jeup-bg);
    border: 1px solid var(--jeup-border);
    border-radius: var(--jeup-radius);
}

.jeup-inline-offer .jeup-offer-header {
    text-align: start;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--jeup-accent);
}

.jeup-inline-offer .jeup-offer-title {
    font-size: 20px;
}

/* Offers Grid (shortcode) */
.jeup-offers-grid {
    display: grid;
    gap: 20px;
}

.jeup-offers-grid.jeup-cols-2 { grid-template-columns: repeat(2, 1fr); }
.jeup-offers-grid.jeup-cols-3 { grid-template-columns: repeat(3, 1fr); }
.jeup-offers-grid.jeup-cols-4 { grid-template-columns: repeat(4, 1fr); }

.jeup-product-upsells .jeup-inline-offer {
    border: none;
    padding: 0;
    margin: 0;
}

/* =========================================
   SLIDE-IN DISPLAY
   ========================================= */
.jeup-popup-overlay.jeup-slide-in {
    background: transparent;
    pointer-events: none;
    align-items: flex-end;
    justify-content: flex-end;
}

.jeup-popup-overlay.jeup-slide-in .jeup-popup-container {
    pointer-events: all;
    max-width: 380px;
    margin: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

/* =========================================
   TOP BAR DISPLAY
   ========================================= */
.jeup-top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99998;
    background: var(--jeup-accent);
    color: #fff;
    padding: 12px 20px;
    display: none;
    align-items: center;
    justify-content: center;
    gap: 16px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
    animation: jeup-slideDown 0.5s ease;
}

.jeup-top-bar.jeup-active {
    display: flex;
}

.jeup-top-bar .jeup-bar-text {
    font-size: 15px;
    font-weight: 600;
}

.jeup-top-bar .jeup-bar-btn {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--jeup-transition);
}

.jeup-top-bar .jeup-bar-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.jeup-top-bar .jeup-bar-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    line-height: 1;
}

/* =========================================
   ANIMATIONS
   ========================================= */
@keyframes jeup-fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes jeup-fadeInDown {
    from { opacity: 0; transform: translateY(-30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes jeup-slideInRight {
    from { opacity: 0; transform: translateX(60px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes jeup-slideInLeft {
    from { opacity: 0; transform: translateX(-60px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes jeup-zoomIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes jeup-bounceIn {
    0% { opacity: 0; transform: scale(0.3); }
    50% { opacity: 1; transform: scale(1.05); }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

@keyframes jeup-flipInX {
    from { opacity: 0; transform: perspective(400px) rotateX(90deg); }
    40% { transform: perspective(400px) rotateX(-20deg); }
    60% { opacity: 1; transform: perspective(400px) rotateX(10deg); }
    80% { transform: perspective(400px) rotateX(-5deg); }
    to { transform: perspective(400px); }
}

@keyframes jeup-slideDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

@keyframes jeup-spin {
    to { transform: rotate(360deg); }
}

@keyframes jeup-scaleIn {
    from { transform: scale(0); }
    to { transform: scale(1); }
}

@keyframes jeup-fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Animation classes applied to popup container */
.jeup-anim-fadeInUp { animation: jeup-fadeInUp 0.4s ease-out; }
.jeup-anim-fadeInDown { animation: jeup-fadeInDown 0.4s ease-out; }
.jeup-anim-slideInRight { animation: jeup-slideInRight 0.4s ease-out; }
.jeup-anim-slideInLeft { animation: jeup-slideInLeft 0.4s ease-out; }
.jeup-anim-zoomIn { animation: jeup-zoomIn 0.4s ease-out; }
.jeup-anim-bounceIn { animation: jeup-bounceIn 0.6s ease-out; }
.jeup-anim-flipInX { animation: jeup-flipInX 0.6s ease-out; }

/* Close animation */
.jeup-closing .jeup-popup-container {
    animation: jeup-fadeOut 0.25s ease forwards;
}

/* =========================================
   MOBILE RESPONSIVE
   ========================================= */
@media (max-width: 768px) {
    .jeup-popup-overlay {
        padding: 0;
        align-items: flex-end !important;
    }

    /* Bottom Sheet Mode (default on mobile) */
    .jeup-popup-container {
        max-width: 100%;
        border-radius: var(--jeup-radius) var(--jeup-radius) 0 0;
        max-height: 85vh;
    }

    /* Bottom sheet handle */
    .jeup-popup-container::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #D1D5DB;
        border-radius: 4px;
        margin: 12px auto 0;
    }

    .jeup-popup-content {
        padding: 20px;
    }

    .jeup-popup-footer {
        padding: 12px 20px 20px;
        flex-direction: column-reverse;
    }

    .jeup-offer-title {
        font-size: 18px;
    }

    .jeup-product-card {
        padding: 12px;
        gap: 12px;
    }

    .jeup-product-image {
        width: 70px;
        height: 70px;
    }

    .jeup-add-to-cart-btn {
        padding: 8px 14px;
        font-size: 13px;
        min-width: auto;
    }

    /* Mobile fullscreen mode */
    .jeup-mobile-fullscreen .jeup-popup-container {
        max-height: 100vh;
        border-radius: 0;
        height: 100%;
    }

    /* Mobile slide-up mode */
    .jeup-mobile-slide_up .jeup-popup-container {
        animation: jeup-fadeInUp 0.35s ease-out;
    }

    /* Grid layouts stack on mobile */
    .jeup-offers-grid.jeup-cols-3,
    .jeup-offers-grid.jeup-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .jeup-layout-horizontal .jeup-product-card {
        min-width: 160px;
    }

    .jeup-layout-carousel .jeup-product-card {
        flex: 0 0 220px;
    }

    /* Top bar mobile */
    .jeup-top-bar {
        flex-wrap: wrap;
        padding: 10px 14px;
        gap: 8px;
    }

    .jeup-top-bar .jeup-bar-text {
        font-size: 13px;
        flex: 1;
    }
}

@media (max-width: 480px) {
    .jeup-offers-grid.jeup-cols-2,
    .jeup-offers-grid.jeup-cols-3,
    .jeup-offers-grid.jeup-cols-4 {
        grid-template-columns: 1fr;
    }

    .jeup-layout-grid .jeup-offer-products {
        grid-template-columns: 1fr;
    }

    .jeup-product-card {
        flex-direction: column;
        text-align: center;
    }

    .jeup-product-image {
        width: 100%;
        height: 140px;
    }

    .jeup-product-price {
        justify-content: center;
    }

    .jeup-success-actions {
        flex-direction: column;
    }

    .jeup-success-actions a {
        width: 100%;
        text-align: center;
    }
}

/* =========================================
   TABLET
   ========================================= */
@media (min-width: 769px) and (max-width: 1024px) {
    .jeup-offers-grid.jeup-cols-4 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* =========================================
   RTL SUPPORT
   ========================================= */
[dir="rtl"] .jeup-popup-content,
.rtl .jeup-popup-content {
    direction: rtl;
    text-align: right;
}

[dir="rtl"] .jeup-offer-header,
.rtl .jeup-offer-header {
    text-align: center;
}

[dir="rtl"] .jeup-inline-offer .jeup-offer-header,
.rtl .jeup-inline-offer .jeup-offer-header {
    text-align: right;
}

[dir="rtl"] .jeup-product-card,
.rtl .jeup-product-card {
    direction: rtl;
}

[dir="rtl"] .jeup-countdown,
.rtl .jeup-countdown {
    direction: ltr;
}

/* =========================================
   ACCESSIBILITY
   ========================================= */
@media (prefers-reduced-motion: reduce) {
    .jeup-popup-container,
    .jeup-product-card,
    .jeup-add-to-cart-btn,
    .jeup-popup-close {
        transition: none !important;
        animation-duration: 0.01s !important;
    }
}

/* Focus styles */
.jeup-popup-close:focus-visible,
.jeup-add-to-cart-btn:focus-visible,
.jeup-no-thanks:focus-visible {
    outline: 2px solid var(--jeup-accent);
    outline-offset: 2px;
}

/* =========================================
   PRINT
   ========================================= */
@media print {
    .jeup-popup-overlay,
    .jeup-top-bar {
        display: none !important;
    }
}
