/**
 * 移动端优先CSS框架
 * 设计理念：移动优先，渐进增强
 */

/* ===== CSS变量 ===== */
:root {
    /* 主题色 */
    --primary: #ff4757;
    --primary-dark: #ff3838;
    --primary-light: #ff6b81;
    --secondary: #747d8c;
    --success: #2ed573;
    --warning: #ffa502;
    --danger: #ff4757;
    --info: #1e90ff;
    
    /* 文字颜色 */
    --text-primary: #2f3542;
    --text-secondary: #747d8c;
    --text-muted: #a4b0be;
    --text-white: #ffffff;
    
    /* 背景色 */
    --bg-body: #f1f2f6;
    --bg-white: #ffffff;
    --bg-gray: #f8f9fa;
    --bg-dark: #2f3542;
    
    /* 边框 */
    --border-color: #e4e7ed;
    --border-radius: 8px;
    --border-radius-lg: 12px;
    --border-radius-sm: 4px;
    
    /* 阴影 */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.05);
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    
    /* 间距 */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    
    /* 字体 */
    --font-size-xs: 12px;
    --font-size-sm: 13px;
    --font-size-md: 15px;
    --font-size-lg: 18px;
    --font-size-xl: 22px;
    
    /* 安全区域 */
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

/* ===== 基础重置 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: calc(60px + var(--safe-bottom));
}

/* ===== 布局系统 ===== */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-content {
    flex: 1;
    padding: var(--space-md);
}

/* ===== 顶部导航栏 ===== */
.navbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--bg-white);
    box-shadow: var(--shadow-sm);
    padding-top: var(--safe-top);
}

.navbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 50px;
    padding: 0 var(--space-md);
}

.navbar-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    flex: 1;
    text-align: center;
}

.navbar-left,
.navbar-right {
    width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.navbar-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text-primary);
}

/* ===== 底部导航栏 ===== */
.tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    padding-bottom: var(--safe-bottom);
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.03);
}

.tabbar-inner {
    display: flex;
    height: 55px;
}

.tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--font-size-xs);
    transition: all 0.2s;
    position: relative; /* 为徽章添加定位基准 */
}

.tabbar-item.active {
    color: var(--primary);
}

.tabbar-icon {
    font-size: 22px;
    margin-bottom: 2px;
}

.tabbar-badge {
    position: absolute;
    top: 5px;
    right: calc(50% - 20px);
    background: var(--primary);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* ===== 卡片组件 ===== */
.card {
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    margin-bottom: var(--space-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.card-body {
    padding: var(--space-md);
}

.card-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
    background: var(--bg-gray);
}

/* ===== 按钮组件 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
    -webkit-appearance: none;
    appearance: none;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--text-white);
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.3);
}

.btn-secondary {
    background: var(--bg-gray);
    color: var(--text-secondary);
}

.btn-success {
    background: var(--success);
    color: var(--text-white);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}

.btn-block {
    width: 100%;
}

.btn-lg {
    padding: 14px 32px;
    font-size: var(--font-size-lg);
    border-radius: var(--border-radius-lg);
}

.btn-sm {
    padding: 8px 16px;
    font-size: var(--font-size-sm);
}

/* ===== 底部固定操作栏 ===== */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    padding: var(--space-md);
    padding-bottom: calc(var(--space-md) + var(--safe-bottom));
    z-index: 999;
    display: flex;
    gap: var(--space-md);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
}

.action-bar .btn {
    flex: 1;
}

/* ===== 表单组件 ===== */
.form-group {
    margin-bottom: var(--space-md);
}

.form-label {
    display: block;
    margin-bottom: var(--space-sm);
    font-size: var(--font-size-md);
    color: var(--text-primary);
    font-weight: 500;
}

.form-control {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    background: var(--bg-white);
    transition: all 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 71, 87, 0.1);
}

.form-control::placeholder {
    color: var(--text-muted);
}

/* ===== 列表组件 ===== */
.list-group {
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

.list-item {
    display: flex;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-primary);
    transition: background 0.2s;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:active {
    background: var(--bg-gray);
}

.list-item-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius);
    background: var(--bg-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: var(--space-md);
    font-size: 20px;
}

.list-item-content {
    flex: 1;
}

.list-item-title {
    font-size: var(--font-size-md);
    margin-bottom: 2px;
}

.list-item-desc {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.list-item-arrow {
    color: var(--text-muted);
    font-size: 18px;
}

/* ===== 商品卡片 ===== */
.product-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.product-card {
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s;
}

.product-card:active {
    transform: scale(0.98);
}

.product-image-wrap {
    position: relative;
    padding-bottom: 100%;
    background: var(--bg-gray);
}

.product-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-info {
    padding: var(--space-md);
}

.product-name {
    font-size: var(--font-size-md);
    color: var(--text-primary);
    margin-bottom: var(--space-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.4;
    min-height: 2.8em;
    text-decoration: none;
}

.product-price-row {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.product-price {
    font-size: var(--font-size-lg);
    color: var(--primary);
    font-weight: 700;
}

.product-original-price {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-decoration: line-through;
}

/* ===== 购物车项 ===== */
.cart-item {
    display: flex;
    padding: var(--space-md);
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    margin-bottom: var(--space-md);
    box-shadow: var(--shadow-sm);
}

.cart-item-image {
    width: 90px;
    height: 90px;
    border-radius: var(--border-radius);
    object-fit: cover;
    margin-right: var(--space-md);
    background: var(--bg-gray);
}

.cart-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.cart-item-title {
    font-size: var(--font-size-md);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.cart-item-price {
    font-size: var(--font-size-lg);
    color: var(--primary);
    font-weight: 700;
}

/* ===== 数量选择器 ===== */
.quantity-selector {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    width: fit-content;
}

.quantity-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-gray);
    font-size: 18px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.quantity-btn:active {
    background: var(--border-color);
}

.quantity-input {
    width: 50px;
    height: 36px;
    border: none;
    text-align: center;
    font-size: var(--font-size-md);
    -webkit-appearance: none;
    appearance: none;
}

/* ===== 订单卡片 ===== */
.order-card {
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    margin-bottom: var(--space-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.order-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-gray);
}

.order-no {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.order-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: var(--font-size-xs);
    font-weight: 500;
}

.order-status-pending { background: #fff3cd; color: #856404; }
.order-status-paid { background: #d1ecf1; color: #0c5460; }
.order-status-shipping { background: #d4edda; color: #155724; }
.order-status-completed { background: #d1ecf1; color: #0c5460; }
.order-status-cancelled { background: #f8d7da; color: #721c24; }

.order-body {
    padding: var(--space-md);
}

.order-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.order-total {
    font-size: var(--font-size-md);
}

.order-total-price {
    color: var(--primary);
    font-size: var(--font-size-lg);
    font-weight: 700;
}

/* ===== 标签 ===== */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: var(--font-size-xs);
    font-weight: 500;
}

.tag-primary {
    background: rgba(255, 71, 87, 0.1);
    color: var(--primary);
}

.tag-success {
    background: rgba(46, 213, 115, 0.1);
    color: var(--success);
}

/* ===== 空状态 ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl) var(--space-md);
    text-align: center;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: var(--space-md);
    opacity: 0.3;
}

.empty-title {
    font-size: var(--font-size-lg);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.empty-desc {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* ===== 提示消息 ===== */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--border-radius);
    font-size: var(--font-size-md);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

/* ===== 加载动画 ===== */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== 分类导航 ===== */
.category-nav {
    display: flex;
    gap: var(--space-sm);
    overflow-x: auto;
    padding: var(--space-md);
    background: transparent;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-bottom: var(--space-md);
    flex: 1;
}

.category-nav::-webkit-scrollbar {
    display: none;
}

.category-item {
    flex-shrink: 0;
    padding: 8px 20px;
    border-radius: 24px;
    background: var(--bg-white);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--font-size-xs);
    white-space: nowrap;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.category-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.category-item:hover::before {
    left: 100%;
}

.category-item.active,
.category-item:active {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--text-white);
    box-shadow: 0 4px 12px rgba(255, 71, 87, 0.3);
    transform: translateY(-2px);
    border-color: var(--primary);
}

/* ===== 轮播图 ===== */
.swiper {
    position: relative;
    overflow: hidden;
    border-radius: var(--border-radius-lg);
}

.swiper-wrapper {
    display: flex;
    transition: transform 0.3s;
}

.swiper-slide {
    flex-shrink: 0;
    width: 100%;
}

.swiper-slide img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.swiper-pagination {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
}

.swiper-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    transition: all 0.3s;
}

.swiper-dot.active {
    width: 16px;
    border-radius: 4px;
    background: var(--primary);
}

/* ===== 用户信息卡片 ===== */
.user-card {
    background: linear-gradient(135deg, #48dbfb 0%, #0abde3 100%);
    border-radius: var(--border-radius-lg);
    padding: var(--space-lg);
    color: var(--text-white);
    margin-bottom: var(--space-md);
}

.user-avatar {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.3);
    margin-bottom: var(--space-md);
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.user-name {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.user-phone {
    font-size: var(--font-size-sm);
    opacity: 0.9;
}

/* ===== 网格菜单 ===== */
.grid-menu {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
}

.grid-menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-primary);
}

.grid-menu-icon {
    width: 50px;
    height: 50px;
    border-radius: var(--border-radius);
    background: var(--bg-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin-bottom: var(--space-sm);
}

.grid-menu-text {
    font-size: var(--font-size-sm);
}

/* ===== 工具类 ===== */
.text-primary { color: var(--primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }

.bg-white { background: var(--bg-white); }
.bg-gray { background: var(--bg-gray); }

.mt-md { margin-top: var(--space-md); }
.mb-md { margin-bottom: var(--space-md); }
.p-md { padding: var(--space-md); }

.flex { display: flex; }
.flex-between { justify-content: space-between; }
.flex-center { align-items: center; }
.flex-1 { flex: 1; }

/* ===== Toast 提示 ===== */
.toast-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

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

.toast-success {
    background: rgba(46, 213, 115, 0.9);
}

.toast-error {
    background: rgba(255, 71, 87, 0.9);
}

.toast-info {
    background: rgba(30, 144, 255, 0.9);
}

/* ===== 自定义对话框 ===== */
.custom-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.custom-dialog-overlay.show {
    opacity: 1;
}

.custom-dialog {
    background: var(--bg-white);
    border-radius: var(--border-radius-lg);
    width: 80%;
    max-width: 300px;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.custom-dialog-overlay.show .custom-dialog {
    transform: scale(1);
}

.custom-dialog-content {
    padding: 24px 20px;
    text-align: center;
    font-size: var(--font-size-md);
    color: var(--text-primary);
    line-height: 1.5;
}

.custom-dialog-buttons {
    display: flex;
    border-top: 1px solid var(--border-color);
}

.custom-dialog-btn {
    flex: 1;
    padding: 14px 0;
    border: none;
    background: none;
    font-size: var(--font-size-md);
    cursor: pointer;
    transition: background 0.2s;
}

.custom-dialog-btn:active {
    background: var(--bg-gray);
}

.custom-dialog-btn-cancel {
    color: var(--text-secondary);
    border-right: 1px solid var(--border-color);
}

.custom-dialog-btn-confirm {
    color: var(--primary);
    font-weight: 500;
}

/* ===== 平板适配 ===== */
@media (min-width: 768px) {
    .page-content {
        max-width: 600px;
        margin: 0 auto;
    }
    
    .product-list {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .grid-menu {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ===== 横屏手机适配 ===== */
@media (max-height: 500px) and (orientation: landscape) {
    .tabbar {
        display: none;
    }
    
    body {
        padding-bottom: var(--space-md);
    }
}

/* ===== 安全区域适配 ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .action-bar {
        padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
    }
    
    .tabbar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}