/* ============================================
   移动端增强样式
   ============================================ */

/* 防止横向滚动 */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ============================================
   可伸缩分类导航
   ============================================ */
@media (max-width: 768px) {
    .category-sidebar {
        position: fixed !important;
        top: var(--header-height) !important;
        left: 0 !important;
        width: 280px !important;
        height: calc(100vh - var(--header-height)) !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
        z-index: 999 !important;
        overflow-y: auto !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
        background: white !important;
    }

    .category-sidebar.open {
        transform: translateX(0) !important;
    }

    /* 分类遮罩层 */
    .category-overlay {
        position: fixed;
        top: var(--header-height);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .category-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    /* 分类切换按钮 - 移到左上角 */
    .category-toggle {
        position: fixed;
        top: calc(var(--header-height) + 12px);
        left: 12px;
        width: 44px;
        height: 44px;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.95);
        color: #7c3aed;
        border: 1.5px solid rgba(124, 58, 237, 0.2);
        box-shadow: 0 2px 8px rgba(124, 58, 237, 0.15);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        cursor: pointer;
        z-index: 1000;
        transition: all 0.3s ease;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .category-toggle:active {
        transform: scale(0.95);
    }

    .category-toggle .icon {
        transition: transform 0.3s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }

    .category-toggle .icon svg {
        transition: transform 0.3s ease;
    }

    .category-toggle.open {
        background: linear-gradient(135deg, #7c3aed, #ec4899);
        color: white;
        border-color: transparent;
        box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
    }

    .category-toggle.open .icon svg {
        transform: rotate(90deg);
    }

    /* 移除提示文字（左上角不需要） */
    .category-toggle::before {
        display: none;
    }

    /* 添加微妙的呼吸动画 */
    @keyframes breathe {
        0%, 100% {
            box-shadow: 0 2px 8px rgba(124, 58, 237, 0.15);
        }
        50% {
            box-shadow: 0 2px 12px rgba(124, 58, 237, 0.25);
        }
    }

    .category-toggle:not(.open) {
        animation: breathe 3s ease-in-out infinite;
    }

    /* 分类列表垂直布局 */
    #homeView .category-list {
        display: flex;
        flex-direction: column !important;
        overflow-x: visible !important;
        overflow-y: auto;
        gap: 8px;
        padding-bottom: 20px;
    }

    #homeView .category-item {
        flex: none !important;
        width: 100%;
        min-width: auto !important;
    }
}

/* 触摸优化 */
@media (hover: none) and (pointer: coarse) {
    * {
        -webkit-tap-highlight-color: rgba(124, 58, 237, 0.1);
    }
    
    button, a, .goods-card, .category-item, .channel-item {
        touch-action: manipulation;
    }
}

/* 小屏幕优化 */
@media (max-width: 360px) {
    :root {
        --header-height: 56px;
    }
    
    .header-inner {
        padding: 6px 10px;
    }
    
    .logo-icon svg {
        width: 32px;
        height: 32px;
    }
    
    .logo-title {
        font-size: 14px;
    }
    
    .search-box input {
        font-size: 12px;
        padding: 6px 10px 6px 30px;
    }
    
    .btn-order-query {
        min-width: 36px;
        padding: 6px;
    }
    
    .main-content {
        padding: 8px;
    }
    
    #homeView .goods-grid {
        gap: 6px;
    }
    
    .goods-card-body {
        padding: 6px;
    }
    
    .goods-card-name {
        font-size: 11px;
    }
    
    .goods-price {
        font-size: 13px;
    }
    
    .goods-status-badge {
        font-size: 8px;
        padding: 1px 4px;
    }
    
    .goods-tag {
        font-size: 8px;
    }
}

/* 横屏模式优化 */
@media (max-width: 900px) and (orientation: landscape) {
    .header {
        height: 52px;
    }
    
    .header-inner {
        padding: 6px 12px;
    }
    
    .logo-icon svg {
        width: 32px;
        height: 32px;
    }
    
    .main-content {
        padding: 8px 12px;
    }
    
    #homeView .goods-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* 超大屏手机优化 */
@media (min-width: 600px) and (max-width: 768px) {
    #homeView .goods-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;
    }
    
    .goods-card-name {
        font-size: 13px;
    }
    
    .goods-price {
        font-size: 16px;
    }
}

/* 平板竖屏优化 */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .shop-layout {
        grid-template-columns: 1fr;
    }
    
    .category-sidebar {
        position: static;
    }
    
    #homeView .goods-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 16px;
    }
}

/* 平板横屏优化 */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    #homeView .goods-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* iOS 安全区域适配 */
@supports (padding: max(0px)) {
    .header {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .main-content {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    .modal-container {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* 改善滚动性能 */
.category-list,
.goods-grid,
.modal-container {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* 优化图片加载 */
.goods-card-img,
.goods-card-cover,
.goods-card-default-logo {
    will-change: transform;
    backface-visibility: hidden;
}

/* 减少动画在低端设备上的性能影响 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 深色模式支持（可选） */
@media (prefers-color-scheme: dark) {
    /* 如果需要深色模式，可以在这里添加样式 */
}

/* 提升触摸目标大小（仅对独立可交互元素） */
@media (max-width: 768px) {
    .btn-primary,
    .btn-secondary,
    .btn-order-query,
    .btn-icon,
    .card-action-btn,
    .modal-close,
    .channel-item,
    #refreshCaptchaBtn {
        min-height: 44px;
    }

    .form-input,
    .form-select,
    .form-textarea,
    .order-input,
    #captchaCodeInput,
    #captchaModalInput {
        min-height: 44px;
    }
}

/* 优化文本可读性 */
@media (max-width: 768px) {
    body {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
}

/* 修复 iOS 输入框缩放问题 */
@media (max-width: 768px) {
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* 优化模态框在移动端的显示 */
@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end;
    }
    
    .modal-container {
        border-radius: 20px 20px 0 0;
        max-height: 92vh;
        animation: slideUp 0.3s ease;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
}

/* 优化加载状态 */
@media (max-width: 768px) {
    .skeleton-card,
    .skeleton-item {
        animation-duration: 1.2s;
    }
}

/* 优化空状态显示 */
@media (max-width: 768px) {
    .empty-state {
        padding: 40px 20px;
    }
    
    .empty-state svg {
        width: 48px;
        height: 48px;
    }
    
    .empty-state p {
        font-size: 14px;
    }
}

/* 页脚安全区域适配 */
@supports (padding: max(0px)) {
    .footer {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* 手机端商品图片优化 */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    .goods-card-img-wrapper,
    .goods-card-cover {
        width: 100%;
        height: 110px;
        overflow: hidden;
        border-radius: 8px 8px 0 0;
        background: linear-gradient(135deg, #f0f4ff 0%, #e8eeff 100%);
    }
    
    .goods-card-img {
        width: 100%;
        height: 110px;
        object-fit: contain;
        background: linear-gradient(135deg, #f0f4ff 0%, #e8eeff 100%);
        padding: 8px;
    }
    
    /* SVG logo 默认图片样式 */
    .goods-card-default-logo {
        width: 100%;
        height: 110px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #f0f4ff 0%, #e8eeff 100%);
    }
    
    .goods-card-default-logo svg {
        width: 90px;
        height: 90px;
    }

    .goods-card {
        min-width: 0;
        max-width: 100%;
    }

    .goods-card-body {
        padding-top: 12px !important;
    }
}


/* ============================================
   商品排序控件
   ============================================ */
.sort-bar {
    display: flex; /* 移动端显示 */
    gap: 8px;
    padding: 8px 0;
    margin-bottom: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    width: 100%;
    justify-content: center; /* 居中显示 */
}

.sort-bar::-webkit-scrollbar {
    display: none;
}

.sort-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1.5px solid rgba(124, 58, 237, 0.2);
    border-radius: 20px;
    background: white;
    color: #666;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.sort-btn:active {
    transform: scale(0.95);
}

.sort-btn.active {
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
}

.sort-btn .sort-icon {
    transition: transform 0.2s ease;
}

.sort-btn.active .sort-icon {
    stroke: white;
}

/* 移动端优化 */
@media (max-width: 768px) {
    .sort-bar {
        padding: 6px 0;
        margin-bottom: 4px;
        gap: 6px;
        margin-left: 0;
        margin-right: 0;
        width: 100%;
        flex-wrap: nowrap;
        justify-content: center; /* 居中显示 */
    }
    
    .sort-btn {
        padding: 6px 12px;
        font-size: 13px;
        flex-shrink: 0;
        min-width: fit-content;
    }
    
    .sort-btn .sort-icon {
        width: 10px;
        height: 10px;
    }
}

/* 小屏幕优化 */
@media (max-width: 360px) {
    .sort-bar {
        gap: 4px;
    }
    
    .sort-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
}


/* 修复移动端右侧空白 */
@media (max-width: 768px) {
    body, html {
        width: 100%;
        overflow-x: hidden;
    }
    
    .main-content {
        width: 100%;
        max-width: 100%;
        padding-left: 10px;
        padding-right: 10px;
        margin-left: 0;
        margin-right: 0;
    }
    
    .goods-section {
        width: 100%;
        max-width: 100%;
    }
    
    #homeView .goods-grid {
        width: 100%;
        max-width: 100%;
    }
}


/* 强制移动端分类侧边栏样式 */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    #categorySidebar {
        position: fixed !important;
        top: var(--header-height) !important;
        left: 0 !important;
        width: 280px !important;
        height: calc(100vh - var(--header-height)) !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
        z-index: 999 !important;
        overflow-y: auto !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
        background: white !important;
    }

    #categorySidebar.open {
        transform: translateX(0) !important;
    }
}
