/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    /* 禁止浏览器下拉刷新：顶部横向分类条滑动会链到根滚动，误触发下拉刷新 */
    overscroll-behavior-y: contain;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: #f5f5f5;
    color: #333;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
    font-size: 14px;
    line-height: 1.5;
}

@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
    /* Fixed header expands into notch area */
    header.fixed {
        padding-top: env(safe-area-inset-top, 0px);
    }
    /* Main content clears header height + notch */
    main {
        padding-top: calc(4rem + env(safe-area-inset-top, 0px)) !important;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 动画效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* 通用类 */
.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

.slide-up {
    animation: slideUp 0.3s ease-in-out;
}

.pulse {
    animation: pulse 0.3s ease-in-out;
}

/* 响应式设计 */
/* 超小屏手机 (280px - 360px) */
@media (max-width: 360px) {
    html {
        font-size: 12px;
    }

    .container {
        max-width: 100% !important;
        padding-left: 12px;
        padding-right: 12px;
    }
    
    .hide-mobile {
        display: none !important;
    }
    
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
}

/* 小屏手机 (361px - 480px) */
@media (min-width: 361px) and (max-width: 480px) {
    html {
        font-size: 13px;
    }

    .container {
        max-width: 100% !important;
        padding-left: 14px;
        padding-right: 14px;
    }
    
    .hide-mobile {
        display: none !important;
    }
    
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

/* 标准手机端 (481px - 639px) */
@media (min-width: 481px) and (max-width: 639px) {
    html {
        font-size: 14px;
    }

    .container {
        max-width: 100% !important;
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .hide-mobile {
        display: none !important;
    }
    
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

/* 平板端 (640px - 1023px) */
@media (min-width: 640px) and (max-width: 1023px) {
    html {
        font-size: 15px;
    }

    /* 容器：平板全宽 + 合理内边距 */
    .container {
        max-width: 100% !important;
        padding-left: 24px !important;
        padding-right: 24px !important;
        margin: 0 auto;
    }

    .hide-tablet {
        display: none !important;
    }

    /* 商品网格：3列 */
    .product-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }

    /* 横幅/轮播：更高 */
    .banner-hero {
        height: 260px !important;
    }

    /* 商品详情图片区域 */
    .product-image-container {
        height: 25rem !important;
    }

    /* 商品详情平板两列布局 */
    .pd-tablet-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .pd-tablet-image {
        position: sticky;
        top: 64px;
    }

    .pd-tablet-full {
        grid-column: 1 / span 2;
    }

    /* 底部导航：平板加宽触区 */
    .bottom-nav {
        padding-left: 24px;
        padding-right: 24px;
        height: 64px;
    }

    .bottom-nav-item {
        min-width: 80px;
        padding: 6px 16px;
    }

    .bottom-nav-item i {
        font-size: 24px;
    }

    .bottom-nav-item span {
        font-size: 12px;
    }

    /* 角标稍大 */
    .cart-badge {
        width: 18px;
        height: 18px;
        font-size: 11px;
    }

    /* 模态框居中 */
    .modal-content {
        max-width: 520px;
        margin: 0 auto;
    }

    /* 表单最大宽度 */
    .form-max-tablet {
        max-width: 480px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* iPad 竖屏及以上 (768px+) 追加优化 */
@media (min-width: 768px) and (max-width: 1023px) {
    .container {
        padding-left: 32px !important;
        padding-right: 32px !important;
    }

    .banner-hero {
        height: 300px !important;
    }

    .product-image-container {
        height: 28.75rem !important;
    }
}

/* APP端/桌面端 */
@media (min-width: 1024px) {
    html {
        font-size: 16px;
    }
    
    .container {
        max-width: 100% !important;
        margin: 0 auto;
        padding-left: 32px;
        padding-right: 32px;
    }
    
    .hide-app {
        display: none !important;
    }
    
    .product-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
}

/* 商品卡片样式 */
.product-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 按钮样式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.btn-primary {
    background-color: #FF6B6B;
    color: white;
}

.btn-primary:hover {
    background-color: #ff5252;
}

.btn-secondary {
    background-color: #4ECDC4;
    color: white;
}

.btn-secondary:hover {
    background-color: #26c6da;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid #ddd;
    color: #666;
}

.btn-outline:hover {
    border-color: #FF6B6B;
    color: #FF6B6B;
}

/* 输入框样式 */
.input {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    -webkit-appearance: none;
}

.input:focus {
    outline: none;
    border-color: #FF6B6B;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15);
}

.input::placeholder {
    color: #999;
}

/* 轮播图样式 */
.carousel-container {
    position: relative;
    overflow: hidden;
}

.carousel-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: opacity 0.5s ease;
}

.carousel-indicator {
    cursor: pointer;
    transition: opacity 0.3s ease;
}

/* 商品图片缩放 */
.product-image-zoom {
    transition: transform 0.3s ease;
}

.product-image-zoom.active {
    transform: scale(1.5);
}

/* 购物车数量调整 */
.quantity-control {
    display: flex;
    align-items: center;
}

.quantity-btn {
    width: 32px;
    height: 32px;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: white;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: all 0.2s ease;
}

.quantity-btn:hover {
    background-color: #f5f5f5;
}

.quantity-btn:active {
    transform: scale(0.95);
}

.quantity-input {
    width: 40px;
    height: 32px;
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
    text-align: center;
    border-left: none;
    border-right: none;
    font-size: 14px;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}

/* 详情页折叠面板 */
.detail-tab {
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.detail-tab:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.detail-tab.active i {
    transform: rotate(180deg);
}

.detail-content {
    transition: all 0.3s ease;
}

/* 加载动画 */
.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: #FF6B6B;
    animation: spin 0.8s linear infinite;
}

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

/* 空状态 */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
    color: #999;
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    color: #ddd;
}

/* 底部导航栏 */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 50;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #999;
    transition: color 0.2s ease;
    min-width: 60px;
    padding: 4px 8px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

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

.bottom-nav-item i {
    font-size: 22px;
    margin-bottom: 2px;
    line-height: 1;
}

.bottom-nav-item span {
    font-size: 11px;
    line-height: 1.2;
}

/* 购物车数量角标 */
.cart-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background-color: #1E40AF;
    color: white;
    font-size: 10px;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* 价格样式 */
.price {
    color: #FF6B6B;
    font-weight: bold;
}

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

/* 评分样式 */
.rating {
    display: flex;
    align-items: center;
}

.rating i {
    color: #FFD166;
    font-size: 12px;
}

.rating-text {
    font-size: 12px;
    color: #999;
    margin-left: 4px;
}

/* 标签样式 */
.tag {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 2px;
    font-size: 10px;
    line-height: 1;
}

.tag-primary {
    background-color: #FF6B6B;
    color: white;
}

.tag-secondary {
    background-color: #4ECDC4;
    color: white;
}

.tag-accent {
    background-color: #FFD166;
    color: #333;
}

/* 表单样式 */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 14px;
    margin-bottom: 8px;
    color: #666;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: #FF6B6B;
    box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.1);
}

/* 模态框样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background: white;
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
    -webkit-overflow-scrolling: touch;
}

.modal-header {
    padding: 16px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body {
    padding: 16px;
}

.modal-footer {
    padding: 16px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* 步骤条样式 */
.steps {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 20px 0;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.step-number {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #eee;
    color: #999;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
}

.step-line {
    height: 2px;
    flex: 1;
    background-color: #eee;
    margin: 0 8px;
}

.step.active .step-number {
    background-color: #FF6B6B;
    color: white;
}

.step.active .step-line {
    background-color: #FF6B6B;
}

.step.completed .step-number {
    background-color: #4ECDC4;
    color: white;
}

.step.completed .step-line {
    background-color: #4ECDC4;
}

.step-title {
    font-size: 12px;
    color: #999;
}

.step.active .step-title,
.step.completed .step-title {
    color: #333;
}

/* ===== 汉堡菜单浮层动画 ===== */
#mobile-nav-menu {
    transition: opacity 200ms cubic-bezier(0.4, 0, 0.2, 1),
                transform 200ms cubic-bezier(0.4, 0, 0.2, 1);
}
#mobile-nav-menu.menu-open {
    opacity: 1;
    transform: translateY(0);
}
#mobile-nav-menu.menu-closed {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
}
#nav-menu-backdrop {
    transition: opacity 200ms ease;
}
#nav-menu-backdrop.backdrop-open {
    opacity: 1;
}
#nav-menu-backdrop.backdrop-closed {
    opacity: 0;
    pointer-events: none;
}
.nav-grid-item:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

/* ===== Cursor pointer for interactive elements ===== */
.bottom-nav-item,
.category-filter,
.detail-tab,
.quantity-btn,
.product-card,
.btn,
.cart-item-checkbox {
    cursor: pointer;
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    ::before,
    ::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
