/* ====================================================
 * Sticky Product Bar Widget for Elementor v2.6.1
 *
 * 桌面端:单 Bar(滚动时吸顶)
 * 移动端:上下双 Bar(顶部仅 Tab,底部始终吸底)
 * 头部菜单:页面顶部显示,向下滚隐藏,向上滚显示
 * ==================================================== */

/* ---- 通用 wrap ---- */
.wcspb-wrap {
    width: 100%;
    position: relative;
}

/* 桌面端 Bar 吸顶 */
.wcspb-wrap.wcspb-stuck .wcspb-bar-desktop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 666;
    transition: top 0.3s ease;
    margin-top: 15px;
}

/* ---- 通用 Bar 样式 ---- */
.wcspb-bar {
    width: 100%;
    border-radius: 24px;
    box-sizing: border-box;
}
.wcspb-bar.wcspb-is-stuck {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.wcspb-bar-inner {
    background-color: #1a1a1a;
    max-width: 1240px !important;
    margin: 0 auto;
    height: 100%;
    padding: 0 30px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-sizing: border-box;
    border-radius: 24px;
}

.wcspb-bar.wcspb-floating {
    margin: 12px;
    width: calc(100% - 24px);
}

/* ---- 左侧:图标+价格+评分 ---- */
.wcspb-bar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1 1 280px;
    min-width: 0;
}

.wcspb-icon {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
}
.wcspb-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.wcspb-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.wcspb-price {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.wcspb-price del { opacity: 0.55; font-weight: 400; font-size: 13px; }
.wcspb-price ins { text-decoration: none; font-weight: 700; }
.wcspb-price .woocommerce-Price-amount { font-weight: inherit; }
.wcspb-price .screen-reader-text { display: none; }

.wcspb-rating {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    line-height: 1;
}
.wcspb-stars { display: inline-flex; line-height: 0; }
.wcspb-review-count { opacity: 0.85; }

/* ---- 中间 Tab ---- */
.wcspb-bar-center {
    display: flex;
    justify-content: center;
    flex: 0 0 auto;
}

.wcspb-tabs-nav {
    position: relative;
    display: inline-flex;
    border-radius: 50px;
    padding: 4px;
    min-width: 320px;
    box-sizing: border-box;
}

.wcspb-tab-indicator {
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 4px;
    border-radius: 50px;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
    pointer-events: none;
    width: 0;
    opacity: 0;
}
.wcspb-tab-indicator.wcspb-ready { opacity: 1; }

.wcspb-tab-btn {
    position: relative;
    flex: 1 1 auto;
    z-index: 1;
    background: transparent;
    border: 0;
    padding: 10px 28px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: color 0.25s ease;
    font-family: inherit;
    line-height: 1.2;
    appearance: none;
    outline: none;
}

/* ---- 右侧:加购按钮 ---- */
.wcspb-bar-right {
    display: flex;
    align-items: center;
    flex: 1 1 100px;
    justify-content: flex-end;
}

.wcspb-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border: 0;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease, filter 0.2s ease;
    line-height: 1;
}
.wcspb-add-btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.wcspb-add-btn:active { transform: translateY(0); }
.wcspb-add-btn.loading { opacity: 0.7; pointer-events: none; }
.wcspb-add-btn .wcspb-add-icon svg { display: block; }
.wcspb-add-btn.wcspb-just-added { animation: wcspb-pulse 0.6s ease; }

@keyframes wcspb-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* ---- Toast ---- */
.wcspb-toast {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: #111;
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 10001;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}
.wcspb-toast.wcspb-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

/* ---- Tab 内容控制 ---- */
.wcspb-tab-hidden { display: none !important; }

/* ====================================================
 * 头部菜单滑入滑出
 *
 * 工作方式:
 *   - 页面顶部:头部在文档流原位(主题原生位置)
 *   - 离开顶部时:JS 给头部加 .wcspb-header-fixed,变 fixed 吸顶
 *   - 向下滚:同时加 .wcspb-header-hidden,滑出隐藏
 *   - 向上滚:移除 .wcspb-header-hidden,滑入显示
 *
 * 不使用 will-change(避免 stacking context 引起遮挡 bug)
 * z-index 强制高于 Bar
 * ==================================================== */
.ct-sticky-container,
#header, #masthead, .site-header, header.ct-header {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* 强制头部菜单的 z-index 高于 Bar */
.ct-sticky-container {
    z-index: 777;
    position: relative;
}

/* JS 给头部加 fixed 类后:吸顶定位 */
.ct-sticky-container.wcspb-header-fixed,
#header.wcspb-header-fixed,
#masthead.wcspb-header-fixed,
.site-header.wcspb-header-fixed {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 777 !important;
}

/* 向下滚时:加 hidden 类滑出 */
.ct-sticky-container.wcspb-header-hidden,
#header.wcspb-header-hidden,
#masthead.wcspb-header-hidden,
.site-header.wcspb-header-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

/* ====================================================
 * 桌面端 vs 移动端布局切换
 * ==================================================== */

/* 默认(桌面端):显示 desktop bar,隐藏 mobile bars */
.wcspb-bar-mobile-top,
.wcspb-bar-mobile-bottom {
    display: none;
}

/* 移动端 ≤ 768px */
@media (max-width: 768px) {
    /* 隐藏桌面 Bar */
    .wcspb-bar-desktop {
        display: none !important;
    }
    .wcspb-wrap.wcspb-stuck .wcspb-bar-desktop {
        position: static !important;
    }

    /* ===== 顶部 Bar:仅 Tab 切换 ===== */
    .wcspb-bar-mobile-top {
        display: block;
        background: #1a1a1a !important;
        padding: 8px 12px;
        border-radius: 0;
        transition: transform 0.3s ease;
    }
    /* 在页面顶部时:relative(跟随文档流,在头部菜单下方) */
    .wcspb-bar-mobile-top.wcspb-at-top {
        position: relative;
    }
    /* 滚出顶部:fixed 在屏幕顶部 */
    .wcspb-bar-mobile-top.wcspb-fixed {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 666;       /* 低于头部菜单 9995 */
    }
    .ct-elementor-default-template .e-con>.e-con-inner{
        width: 100% !important;
    }
        .wcspb-bar-inner-mobile-top {
        padding: 0;
        max-width: none;
        justify-content: center;
        height: auto;
        border-radius: 0;
    }
    .wcspb-bar-mobile-top .wcspb-tabs-nav {
        width: 100%;
        min-width: 0;
        justify-content: stretch;
    }
    .wcspb-bar-mobile-top .wcspb-tab-btn {
        flex: 1;
        padding: 5px 16px;
        font-size: 14px;
    }

    /* ===== 底部 Bar:始终吸底 ===== */
    .wcspb-bar-mobile-bottom {
        display: block;
        position: fixed;
        bottom: 27px;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 666;
        background: #1a1a1a;
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.2);
    }
    .wcspb-bar-inner-mobile-bottom {
        padding: 10px 12px;
        padding-left: 20px !important;
        padding-right: 20px !important;
        max-width: none;
        gap: 10px;
        height: auto;
        margin: 0 10px;
        border: 1px solid #737373;
        border-radius: 50px;
    }
    .wcspb-bar-mobile-bottom .wcspb-bar-left {
        flex: 1 1 auto;
        gap: 10px;
    }
    .wcspb-bar-mobile-bottom .wcspb-icon {
        width: 40px;
        height: 40px;
    }
    .wcspb-bar-mobile-bottom .wcspb-price { font-size: 14px; }
    .wcspb-bar-mobile-bottom .wcspb-rating { font-size: 11px; }
    .wcspb-bar-mobile-bottom .wcspb-add-btn {
        padding: 10px 18px;
        font-size: 13px;
    }

    /* 给页面底部留位,避免内容被 bottom Bar 遮挡 */
    body.wcspb-product-page {
        padding-bottom: 70px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .wcspb-bar-mobile-top,
    .wcspb-tab-indicator,
    .ct-sticky-container,
    #header, #masthead, .site-header, header.ct-header {
        transition: none !important;
    }
}

/* ====================================================
 * Elementor 编辑器:bar 在原位预览
 * ==================================================== */
.elementor-editor-active .wcspb-wrap,
.elementor-edit-mode .wcspb-wrap {
    position: relative !important;
}
.elementor-editor-active .wcspb-bar-desktop,
.elementor-edit-mode .wcspb-bar-desktop {
    position: relative !important;
    transform: none !important;
}
.elementor-editor-active .wcspb-bar-mobile-top,
.elementor-editor-active .wcspb-bar-mobile-bottom,
.elementor-edit-mode .wcspb-bar-mobile-top,
.elementor-edit-mode .wcspb-bar-mobile-bottom {
    display: none !important;
}
.elementor-editor-active .wcspb-wrap::before,
.elementor-edit-mode .wcspb-wrap::before {
    content: 'Sticky Product Bar (desktop preview — mobile shows 2 split bars on frontend)';
    display: block;
    background: #f0f6fc;
    border-left: 4px solid #2271b1;
    color: #135e96;
    padding: 6px 12px;
    font-size: 12px;
    font-family: sans-serif;
    margin-bottom: 8px;
}
