/* ============================================
   移动端通用优化样式
   适用于所有页面
   ============================================ */

/* 基础设置 */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 允许文本选择（输入框和可编辑区域） */
input, textarea, [contenteditable] {
    -webkit-user-select: text;
    user-select: text;
}

body {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overflow-x: hidden;
}

/* 防止水平滚动 */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* ============================================
   触摸设备优化
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* 增大按钮点击区域 */
    button, .btn, a.btn {
        min-height: 44px;
        padding: 12px 16px;
    }
    
    /* 增大链接点击区域 */
    a {
        padding: 8px 0;
        display: inline-block;
    }
    
    /* 移除hover效果，改用active */
    .btn:hover, a:hover {
        transform: none !important;
    }
    
    .btn:active, a:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    /* 表单元素优化 */
    input, select, textarea {
        font-size: 16px !important; /* 防止iOS自动缩放 */
        min-height: 44px;
        padding: 12px;
    }
    
    /* 下拉菜单优化 */
    select {
        -webkit-appearance: none;
        appearance: none;
    }
}

/* ============================================
   通用响应式布局
   ============================================ */

/* 平板和手机通用 */
@media (max-width: 992px) {
    .container {
        padding: 0 15px !important;
    }
    
    /* 网格布局调整 */
    .grid, .row {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
    }
    
    /* 商品网格优化 */
    .items-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
}

/* 手机横屏和小平板 */
@media (max-width: 768px) {
    /* 容器内边距 */
    .container {
        padding: 0 10px !important;
    }
    
    /* 标题字体调整 */
    h1 { font-size: 22px !important; margin: 15px 0 !important; }
    h2 { font-size: 19px !important; margin: 12px 0 !important; }
    h3 { font-size: 17px !important; margin: 10px 0 !important; }
    
    /* 正文字体 */
    body, p {
        font-size: 14px !important;
        line-height: 1.6 !important;
    }
    
    /* 卡片圆角减小 */
    .card {
        border-radius: 8px !important;
        margin-bottom: 10px !important;
        padding: 12px !important;
    }
    
    /* 按钮全宽 */
    .btn-full-mobile, .btn-block-mobile {
        width: 100% !important;
        display: block !important;
    }
    
    /* 隐藏桌面端元素 */
    .hide-mobile, .desktop-only {
        display: none !important;
    }
    
    /* 显示移动端专属元素 */
    .show-mobile, .mobile-only {
        display: block !important;
    }
    
    /* 表格横向滚动 */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px;
    }
    
    /* 图片自适应 */
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* 视频容器 */
    .video-container {
        position: relative;
        padding-bottom: 56.25%; /* 16:9 */
        height: 0;
        overflow: hidden;
    }
    
    .video-container iframe,
    .video-container video {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
    
    /* 筛选器优化 */
    .filter-options {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .filter-option {
        flex: 0 0 calc(50% - 4px);
        font-size: 13px;
        padding: 8px 12px;
    }
}

/* 小屏幕手机 */
@media (max-width: 576px) {
    /* 更小的字体 */
    h1 { font-size: 20px !important; margin: 12px 0 !important; }
    h2 { font-size: 18px !important; margin: 10px 0 !important; }
    h3 { font-size: 16px !important; margin: 8px 0 !important; }
    
    body, p {
        font-size: 14px !important;
        line-height: 1.5 !important;
    }
    
    /* 单列布局 */
    .grid, .row {
        grid-template-columns: 1fr !important;
    }
    
    .items-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    /* 减少间距 */
    .card {
        padding: 12px !important;
        margin-bottom: 10px !important;
    }
    
    /* 导航简化 */
    nav ul {
        flex-direction: column;
    }
    
    nav li {
        width: 100%;
    }
    
    /* 搜索框优化 */
    .search-input {
        font-size: 14px !important;
        padding: 10px 12px !important;
    }
    
    /* 按钮优化 */
    .btn {
        padding: 10px 16px !important;
        font-size: 14px !important;
        min-height: 44px;
    }
    
    /* 商品卡片优化 */
    .item-card {
        padding: 10px !important;
    }
    
    .item-image-container {
        height: 200px !important;
    }
    
    .item-title {
        font-size: 15px !important;
        margin: 8px 0 !important;
    }
    
    .item-price {
        font-size: 18px !important;
        font-weight: 700 !important;
    }
    
    /* 筛选器全宽 */
    .filter-option {
        flex: 0 0 100% !important;
        font-size: 14px !important;
    }
}

/* 超小屏幕 (iPhone SE等) */
@media (max-width: 375px) {
    .container {
        padding: 0 8px !important;
    }
    
    h1 { font-size: 18px !important; }
    h2 { font-size: 16px !important; }
    h3 { font-size: 15px !important; }
    
    body, p {
        font-size: 13px !important;
    }
    
    .item-image-container {
        height: 180px !important;
    }
    
    .item-title {
        font-size: 14px !important;
    }
    
    .item-price {
        font-size: 16px !important;
    }
    
    .logo span {
        font-size: 0.85rem !important;
    }
}

/* 超小屏幕 */
@media (max-width: 375px) {
    .container {
        padding: 0 8px !important;
    }
    
    h1 { font-size: 20px !important; }
    h2 { font-size: 17px !important; }
    
    body, p {
        font-size: 13px !important;
    }
}

/* ============================================
   微信浏览器特殊处理
   ============================================ */
.wechat-browser {
    /* 微信中的基础样式调整 */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/* 微信中隐藏不必要的元素 */
.wechat-browser .no-wechat {
    display: none !important;
}

/* 微信中显示专属元素 */
.wechat-browser .wechat-only {
    display: block !important;
}

/* 微信中禁用某些功能 */
.wechat-browser .disable-in-wechat {
    pointer-events: none;
    opacity: 0.5;
}

/* 微信顶部安全区域（iPhone X+） */
@supports (padding-top: env(safe-area-inset-top)) {
    .wechat-browser {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* 微信中的导航栏适配 */
.wechat-browser header,
.wechat-browser .header,
.wechat-browser nav {
    /* 为微信顶部留出空间 */
    padding-top: max(10px, env(safe-area-inset-top));
}

/* 微信中的底部导航适配 */
.wechat-browser footer,
.wechat-browser .bottom-nav {
    /* 为微信底部留出空间 */
    padding-bottom: max(10px, env(safe-area-inset-bottom));
}

/* 微信中优化字体渲染 */
.wechat-browser {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* 微信中防止文本选择（提升体验） */
.wechat-browser body {
    -webkit-user-select: none;
    user-select: none;
}

/* 允许输入框选择文本 */
.wechat-browser input,
.wechat-browser textarea,
.wechat-browser [contenteditable] {
    -webkit-user-select: text;
    user-select: text;
}

/* 微信中优化链接点击效果 */
.wechat-browser a:active {
    opacity: 0.7;
    transition: opacity 0.2s;
}

/* 微信中按钮点击反馈 */
.wechat-browser button:active,
.wechat-browser .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* 微信中图片优化 */
.wechat-browser img {
    -webkit-touch-callout: none; /* 禁用长按菜单 */
    pointer-events: none; /* 防止误触 */
}

/* 允许特定图片长按 */
.wechat-browser img.allow-long-press {
    -webkit-touch-callout: default;
    pointer-events: auto;
}

/* 微信中模态框优化 */
.wechat-browser .modal {
    /* 确保模态框在微信中正确显示 */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* 微信中Toast提示优化 */
.wechat-browser .toast {
    /* 避免被微信原生UI遮挡 */
    z-index: 10000;
    bottom: max(20px, env(safe-area-inset-bottom));
}

/* 微信中下拉刷新指示器（如果需要） */
.wechat-browser .pull-refresh-indicator {
    display: none; /* 微信有自己的下拉刷新 */
}

/* 微信中滚动条美化 */
.wechat-browser ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

.wechat-browser ::-webkit-scrollbar-track {
    background: transparent;
}

.wechat-browser ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

.wechat-browser ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* ============================================
   汉堡菜单样式
   ============================================ */
.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 10px;
    color: inherit;
}

.mobile-menu {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    max-height: 80vh;
    overflow-y: auto;
}

.mobile-menu.show {
    display: block;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.mobile-menu a {
    display: block;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    color: #333;
    text-decoration: none;
}

.mobile-menu a:hover,
.mobile-menu a:active {
    background: #f5f5f5;
}

.mobile-menu a i {
    margin-right: 10px;
    width: 20px;
    text-align: center;
}

@media (max-width: 768px) {
    .hamburger {
        display: block;
    }
    
    .desktop-nav {
        display: none;
    }
}

/* ============================================
   加载动画优化
   ============================================ */
.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   Toast提示优化
   ============================================ */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 9999;
    font-size: 14px;
    max-width: 80%;
    text-align: center;
}

@media (max-width: 768px) {
    .toast {
        bottom: 10px;
        padding: 10px 20px;
        font-size: 13px;
    }
}

/* ============================================
   模态框优化
   ============================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 10px;
        max-height: 85vh;
    }
}

/* ============================================
   图片懒加载占位符
   ============================================ */
.lazy-image {
    opacity: 0;
    transition: opacity 0.3s;
}

.lazy-image.loaded {
    opacity: 1;
}

/* 骨架屏基础样式 */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 图片骨架屏 */
img.skeleton {
    min-height: 200px;
    width: 100%;
}

/* 文本骨架屏 */
.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
    border-radius: 4px;
}

.skeleton-text.short {
    width: 40%;
}

.skeleton-text.medium {
    width: 70%;
}

.skeleton-text.long {
    width: 100%;
}

/* 卡片骨架屏 */
.skeleton-card {
    padding: 16px;
    border-radius: 8px;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.skeleton-card .skeleton-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin-bottom: 12px;
}

.skeleton-card .skeleton-title {
    height: 20px;
    width: 60%;
    margin-bottom: 8px;
}

.skeleton-card .skeleton-content {
    height: 14px;
    width: 100%;
    margin-bottom: 6px;
}

/* 列表项骨架屏 */
.skeleton-list-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
}

.skeleton-list-item .skeleton-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    margin-right: 12px;
}

.skeleton-list-item .skeleton-info {
    flex: 1;
}

/* 按钮骨架屏 */
.skeleton-button {
    height: 44px;
    width: 120px;
    border-radius: 8px;
    display: inline-block;
}

/* ============================================
   下拉刷新指示器
   ============================================ */
.pull-refresh-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 100;
    pointer-events: none;
}

.pull-refresh-indicator.visible {
    opacity: 1;
}

.pull-refresh-icon {
    font-size: 18px;
    color: #10b981;
    transition: transform 0.3s ease;
}

.pull-refresh-icon.rotating {
    animation: rotate 1s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.pull-refresh-text {
    font-size: 14px;
    color: #666;
}

.pull-refresh-indicator.ready .pull-refresh-text {
    color: #10b981;
    font-weight: bold;
}

/* 触摸反馈 */
.touch-active {
    opacity: 0.7;
    transform: scale(0.98);
    transition: all 0.1s ease;
}

button.touch-active, .btn.touch-active {
    background-color: rgba(0, 0, 0, 0.05);
}

a.touch-active {
    color: rgba(0, 0, 0, 0.6);
}

/* ============================================
   辅助类
   ============================================ */
.text-center-mobile {
    text-align: center;
}

@media (min-width: 769px) {
    .text-center-mobile {
        text-align: inherit;
    }
}

.flex-mobile {
    display: flex;
}

@media (max-width: 768px) {
    .flex-mobile {
        flex-direction: column;
    }
}

.gap-mobile {
    gap: 10px;
}

@media (max-width: 768px) {
    .gap-mobile {
        gap: 5px;
    }
}
