/**
 * ==========================================
 * 汇森科技 - 移动端 App 级体验优化 v1.0
 * 让 Web 应用像原生 App 一样丝滑
 * ==========================================
 */

/* ========== 基础优化 ========== */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    overscroll-behavior-y: contain;
    /* 性能优化：减少重绘 */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* 性能优化：硬件加速 */
.accelerate {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000;
    perspective: 1000;
}

/* 减少布局抖动 */
.layout-stable {
    contain: layout style paint;
}

/* 禁用长按菜单 */
img, a, button {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* ========== 移动端固定购物车按钮（非详情页）========== */
.mobile-fixed-cart {
    position: fixed;
    bottom: 56px; /* 在底部导航栏上方 */
    right: 16px;
    z-index: 99998; /* 略低于底部导航栏 */
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #e1251b 0%, #ff4d4f 100%);
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(225, 37, 27, 0.3);
    transition: all 0.3s ease;
    animation: fadeInUp 0.3s ease;
}

.mobile-fixed-cart:hover,
.mobile-fixed-cart:active {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(225, 37, 27, 0.4);
}

.mobile-fixed-cart .cart-icon {
    width: 24px;
    height: 24px;
    color: white;
}

.mobile-fixed-cart .cart-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    background: #ffd700;
    color: #e1251b;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* 调整底部导航栏高度以适应新按钮 */
.mobile-bottom-nav {
    height: 64px; /* 增加高度以提供更好的点击区域 */
}

/* ========== 移动端底部导航栏 ========== */
.mobile-bottom-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 64px; /* 增加高度以提供更好的点击区域 */
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-top: 1px solid rgba(0, 0, 0, 0.06) !important;
    z-index: 99999 !important; /* 确保始终在最上层 */
    padding-bottom: env(safe-area-inset-bottom) !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08) !important;
    display: none !important;
}

.mobile-bottom-nav .nav-container {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 56px;
    max-width: 500px;
    margin: 0 auto;
}

.mobile-bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    text-decoration: none;
    color: #666;
    font-size: 10px;
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
    gap: 4px;
}

.mobile-bottom-nav .nav-item svg {
    width: 24px;
    height: 24px;
    stroke-width: 1.8;
    transition: all 0.2s ease;
}

.mobile-bottom-nav .nav-item.active {
    color: #e1251b;
}

.mobile-bottom-nav .nav-item.active svg {
    stroke: #e1251b;
    transform: scale(1.1);
}

.mobile-bottom-nav .nav-item:active {
    transform: scale(0.92);
}

.mobile-bottom-nav .nav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 20px);
    min-width: 16px;
    height: 16px;
    background: #e1251b;
    color: white;
    font-size: 10px;
    font-weight: 700;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ========== 移动端底部操作栏（详情页专用）========== */
.mobile-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    display: none;
    z-index: 9998;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.1);
}

/* ========== 移动端详情页购买操作区域 ========== */
.mobile-action-buttons {
    position: sticky;
    top: 60px;
    z-index: 999;
    margin: 0 -16px;
    padding: 0 16px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.mobile-action-buttons.hidden {
    transform: translateY(-100%);
    opacity: 0;
}

.mobile-action-buttons .touch-feedback:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.mobile-action-bar .action-container {
    display: flex;
    gap: 12px;
    align-items: center;
}

.mobile-action-bar .action-icons {
    display: flex;
    gap: 16px;
}

.mobile-action-bar .action-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: #666;
    font-size: 10px;
    text-decoration: none;
}

.mobile-action-bar .action-icon svg {
    width: 22px;
    height: 22px;
}

.mobile-action-bar .action-icon:active {
    transform: scale(0.9);
}

.mobile-action-bar .action-buttons {
    display: flex;
    flex: 1;
    gap: 10px;
}

.mobile-action-bar .btn-add-cart {
    flex: 1;
    height: 44px;
    border-radius: 22px;
    border: 2px solid #ff6b00;
    background: #fff7ed;
    color: #ff6b00;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.mobile-action-bar .btn-add-cart:active {
    transform: scale(0.96);
    background: #ffedd5;
}

.mobile-action-bar .btn-buy-now {
    flex: 1.5;
    height: 44px;
    border-radius: 22px;
    border: none;
    background: linear-gradient(135deg, #e1251b 0%, #ff4d4f 100%);
    color: white;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(225, 37, 27, 0.4);
    transition: all 0.2s ease;
}

.mobile-action-bar .btn-buy-now:active {
    transform: scale(0.96);
    box-shadow: 0 2px 8px rgba(225, 37, 27, 0.3);
}

/* ========== 移动端图片轮播 ========== */
.mobile-swiper {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: linear-gradient(180deg, #f5f5f5 0%, #fff 100%);
    touch-action: pan-y pinch-zoom;
}

.mobile-swiper-track {
    display: flex;
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

.mobile-swiper-slide {
    flex: 0 0 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.mobile-swiper-slide img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 12px;
    pointer-events: none;
}

/* 轮播指示器 */
.mobile-swiper-pagination {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 20px;
}

.mobile-swiper-bullet {
    width: 6px;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.5);
    transition: all 0.3s ease;
}

.mobile-swiper-bullet.active {
    width: 18px;
    background: white;
}

/* ========== 移动端 SKU 选择器 ========== */
.mobile-sku-panel {
    padding: 16px;
    background: white;
    margin-bottom: 8px;
}

.mobile-sku-section {
    margin-bottom: 20px;
}

.mobile-sku-title {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-sku-title span {
    color: #e1251b;
    font-weight: 700;
}

.mobile-sku-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.mobile-sku-option {
    min-width: 80px;
    height: 40px;
    padding: 0 16px;
    border: 1.5px solid #e0e0e0;
    border-radius: 20px;
    background: white;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.mobile-sku-option:active {
    transform: scale(0.95);
}

.mobile-sku-option.active {
    border-color: #e1251b;
    background: #fff5f5;
    color: #e1251b;
    font-weight: 700;
}

.mobile-sku-option .color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

/* ========== 移动端价格显示 ========== */
.mobile-price-section {
    padding: 20px 16px;
    background: linear-gradient(135deg, #fff9f9 0%, #fff5f0 100%);
}

.mobile-price-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 12px;
}

.mobile-price-current {
    font-size: 28px;
    font-weight: 800;
    color: #e1251b;
    font-family: 'Inter', -apple-system, monospace;
    letter-spacing: -0.5px;
}

.mobile-price-current .symbol {
    font-size: 18px;
    margin-right: 2px;
}

.mobile-price-original {
    font-size: 14px;
    color: #999;
    text-decoration: line-through;
}

.mobile-price-profit {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    background: linear-gradient(135deg, #e6f7ed 0%, #d1f5e0 100%);
    color: #0a8f4a;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

/* ========== 移动端产品标签 ========== */
.mobile-product-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.mobile-product-tag {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.mobile-product-tag.hot {
    background: #fff1f0;
    color: #e1251b;
}

.mobile-product-tag.new {
    background: #e6f7ff;
    color: #1890ff;
}

.mobile-product-tag.stock {
    background: #f6ffed;
    color: #52c41a;
}

/* ========== 移动端信息卡片 ========== */
.mobile-info-card {
    background: white;
    margin-bottom: 8px;
    padding: 16px;
}

.mobile-info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.mobile-info-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-info-title::before {
    content: '';
    width: 4px;
    height: 16px;
    background: #e1251b;
    border-radius: 2px;
}

/* ========== 移动端规格表格 ========== */
.mobile-spec-table {
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #f0f0f0;
}

.mobile-spec-row {
    display: flex;
    border-bottom: 1px solid #f0f0f0;
}

.mobile-spec-row:last-child {
    border-bottom: none;
}

.mobile-spec-label {
    width: 100px;
    flex-shrink: 0;
    padding: 14px 12px;
    background: #fafafa;
    font-size: 13px;
    color: #666;
    font-weight: 500;
}

.mobile-spec-value {
    flex: 1;
    padding: 14px 12px;
    font-size: 13px;
    color: #1a1a1a;
    font-weight: 500;
    line-height: 1.5;
    word-break: break-word;
}

/* ========== 触摸反馈动画 ========== */
.touch-feedback {
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.touch-feedback:active {
    transform: scale(0.97);
    opacity: 0.9;
}

/* 涟漪效果 */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.1);
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease, opacity 0.4s ease;
}

.ripple:active::after {
    width: 200%;
    height: 200%;
    opacity: 0;
}

/* ========== Toast 提示 ========== */
.mobile-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 16px 32px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 99999;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    max-width: 80%;
    text-align: center;
}

.mobile-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.mobile-toast.success {
    background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%);
}

.mobile-toast.error {
    background: linear-gradient(135deg, #ff4d4f 0%, #ff7875 100%);
}

/* ========== 下拉刷新 ========== */
.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 9990;
}

.pull-to-refresh.pulling {
    transform: translateY(0);
}

.pull-to-refresh .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #f0f0f0;
    border-top-color: #e1251b;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========== 骨架屏加载 ========== */
.mobile-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 8px;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========== 平滑滚动容器 ========== */
.smooth-scroll {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

/* 隐藏滚动条但保持功能 */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* ========== 响应式显示控制 ========== */
@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: block !important;
    }

    .mobile-action-bar {
        display: block;
    }

    /* 给页面底部留出空间 */
    body {
        padding-bottom: calc(56px + env(safe-area-inset-bottom));
    }

    /* 详情页底部留更多空间给操作栏 */
    body.detail-page {
        padding-bottom: calc(80px + env(safe-area-inset-bottom));
    }

    /* 隐藏桌面端元素 */
    .desktop-only {
        display: none !important;
    }

    /* 主内容区域全宽 */
    main {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* 隐藏侧边工具栏 */
    .sidebar-tools {
        display: none !important;
    }
}

@media (min-width: 769px) {
    /* 隐藏移动端元素 */
    .mobile-only {
        display: none !important;
    }

    .mobile-bottom-nav {
        display: none !important;
    }

    .mobile-action-bar {
        display: none !important;
    }
}

/* ========== 暗色模式支持 ========== */
@media (prefers-color-scheme: dark) {
    .mobile-bottom-nav {
        background: rgba(30, 30, 30, 0.95);
        border-top-color: rgba(255, 255, 255, 0.1);
    }

    .mobile-bottom-nav .nav-item {
        color: #aaa;
    }

    .mobile-action-bar {
        background: rgba(30, 30, 30, 0.98);
    }
}

/* ========== 动画类 ========== */
.fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

.slide-up {
    animation: slideUp 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.slide-down {
    animation: slideDown 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

/* ========== 弹出层/模态框 ========== */
.mobile-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99990;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.mobile-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.mobile-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 99991;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-modal.active {
    transform: translateY(0);
}

.mobile-modal-header {
    position: sticky;
    top: 0;
    background: white;
    padding: 16px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1;
}

.mobile-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #1a1a1a;
}

.mobile-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #f5f5f5;
    cursor: pointer;
}

.mobile-modal-body {
    padding: 16px;
}

/* ========== 移动端底部操作栏 - 完整修复版 ========== */
.mobile-action-bar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    background: #ffffff !important;
    border-top: 1px solid #e5e5e5;
    padding: 10px 12px !important;
    padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    display: none;
    z-index: 99999 !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    box-sizing: border-box !important;
}

@media (max-width: 768px) {
    .mobile-action-bar {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 10px !important;
    }

    /* 隐藏footer在移动端详情页 */
    footer {
        padding-bottom: 90px !important;
    }
}

.mobile-bar-price {
    display: flex !important;
    flex-direction: column !important;
    min-width: 70px !important;
    flex-shrink: 0 !important;
}

.mobile-bar-label {
    font-size: 10px !important;
    color: #999 !important;
    font-weight: 500 !important;
    line-height: 1.2 !important;
}

.mobile-bar-amount {
    font-size: 20px !important;
    font-weight: 800 !important;
    color: #e1251b !important;
    font-family: 'Inter', -apple-system, sans-serif !important;
    letter-spacing: -0.5px !important;
    line-height: 1.2 !important;
}

.mobile-bar-buttons {
    display: flex !important;
    flex: 1 !important;
    gap: 8px !important;
    min-width: 0 !important;
}

.mobile-btn {
    flex: 1 !important;
    height: 42px !important;
    min-height: 42px !important;
    border-radius: 21px !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    white-space: nowrap !important;
    padding: 0 12px !important;
    box-sizing: border-box !important;
}

.mobile-btn:active {
    transform: scale(0.96) !important;
    opacity: 0.9 !important;
}

.mobile-btn-cart {
    background: #fff7ed !important;
    color: #ff6b00 !important;
    border: 2px solid #ff6b00 !important;
}

.mobile-btn-cart:hover,
.mobile-btn-cart:active {
    background: #ffedd5 !important;
}

.mobile-btn-buy {
    flex: 1.2 !important;
    background: linear-gradient(135deg, #e1251b 0%, #ff4d4f 100%) !important;
    color: #ffffff !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(225, 37, 27, 0.35) !important;
}

.mobile-btn-buy:hover,
.mobile-btn-buy:active {
    box-shadow: 0 2px 8px rgba(225, 37, 27, 0.25) !important;
}

/* ========== 电脑端完全隐藏移动端操作栏 ========== */
@media (min-width: 769px) {
    .mobile-action-bar {
        display: none !important;
        visibility: hidden !important;
    }
}

/* ========== 确保详情页底部有足够空间 ========== */
@media (max-width: 768px) {
    body {
        padding-bottom: 80px !important;
    }

    main {
        padding-bottom: 20px !important;
    }
}
