/* 又见小店 Mini App — 主题色跟随 Telegram 风格 */
:root {
    --bg: #fff;
    --bg-card: #f5f5f7;
    --text: #1d1d1f;
    --text-secondary: #86868b;
    --accent: #007aff;
    --accent-hover: #0062cc;
    --danger: #ff3b30;
    --success: #34c759;
    --border: #e5e5ea;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --radius: 12px;
    --nav-height: 50px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1c1c1e;
        --bg-card: #2c2c2e;
        --text: #f5f5f7;
        --text-secondary: #98989d;
        --accent: #0a84ff;
        --border: #38383a;
        --shadow: 0 2px 12px rgba(0,0,0,0.3);
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
}
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; display: block; }

/* ─── 顶部栏 ─── */
.header {
    position: sticky; top: 0; z-index: 100;
    background: var(--bg);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
}
.header h1 {
    font-size: 18px; font-weight: 700;
    flex: 1;
}
.header .back-btn {
    background: none; border: none; color: var(--accent);
    font-size: 16px; cursor: pointer; padding: 4px 8px;
    display: none;
}

/* ─── 分类网格 ─── */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    padding: 16px;
}
.category-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px 12px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.15s;
}
.category-card:active { transform: scale(0.96); }
.category-card .icon { font-size: 32px; margin-bottom: 8px; }
.category-card .name { font-size: 14px; font-weight: 600; }
.category-card .count { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ─── 商品列表 ─── */
.products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 16px;
}
.product-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s;
}
.product-card:active { transform: scale(0.97); }
.product-card .img-wrap {
    width: 100%; aspect-ratio: 1;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.product-card .img-wrap img {
    width: 100%; height: 100%; object-fit: cover;
}
.product-card .img-wrap .placeholder {
    font-size: 48px; opacity: 0.3;
}
.product-card .info {
    padding: 10px 12px 14px;
}
.product-card .name {
    font-size: 13px; font-weight: 600;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; line-height: 1.3;
}
.product-card .price {
    font-size: 16px; font-weight: 700; color: var(--danger);
    margin-top: 6px;
}
.product-card .price .currency {
    font-size: 12px; font-weight: 400;
}

/* ─── 商品详情 ─── */
.detail-page {
    padding: 0;
}
.detail-page .img-hero {
    width: 100%; aspect-ratio: 1;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
}
.detail-page .img-hero img {
    width: 100%; height: 100%; object-fit: contain;
}
.detail-page .body {
    padding: 16px;
}
.detail-page h2 {
    font-size: 20px; font-weight: 700;
    margin-bottom: 8px;
}
.detail-page .price-big {
    font-size: 24px; font-weight: 700; color: var(--danger);
    margin-bottom: 12px;
}
.detail-page .desc {
    font-size: 14px; color: var(--text-secondary);
    line-height: 1.6; margin-bottom: 20px;
}
.detail-page .add-btn {
    width: 100%;
    background: var(--accent); color: #fff;
    border: none; border-radius: var(--radius);
    padding: 14px; font-size: 16px; font-weight: 600;
    cursor: pointer; transition: opacity 0.15s;
}
.detail-page .add-btn:active { opacity: 0.8; }

/* ─── 购物车 ─── */
.cart-list { padding: 16px; }
.cart-item {
    display: flex; align-items: center; gap: 12px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 10px;
}
.cart-item .img-wrap {
    width: 60px; height: 60px; border-radius: 8px;
    background: var(--bg); overflow: hidden; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.cart-item .img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.cart-item .img-wrap .placeholder { font-size: 24px; opacity: 0.3; }
.cart-item .meta { flex: 1; min-width: 0; }
.cart-item .meta .name { font-size: 14px; font-weight: 600; }
.cart-item .meta .price { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.cart-item .controls {
    display: flex; align-items: center; gap: 8px;
}
.cart-item .controls button {
    width: 30px; height: 30px; border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg); color: var(--text);
    font-size: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.cart-item .controls .qty {
    font-size: 15px; font-weight: 600; min-width: 20px;
    text-align: center;
}

.cart-summary {
    padding: 16px;
    border-top: 1px solid var(--border);
}
.cart-summary .row {
    display: flex; justify-content: space-between;
    padding: 6px 0; font-size: 14px;
}
.cart-summary .total {
    font-size: 18px; font-weight: 700; padding-top: 8px;
    border-top: 1px solid var(--border); margin-top: 8px;
}
.cart-summary .checkout-btn {
    width: 100%;
    background: var(--accent); color: #fff;
    border: none; border-radius: var(--radius);
    padding: 14px; font-size: 16px; font-weight: 600;
    cursor: pointer; margin-top: 12px;
}
.cart-summary .checkout-btn:disabled {
    opacity: 0.4; cursor: not-allowed;
}

/* ─── 结算表单 ─── */
.checkout-form {
    padding: 16px;
}
.checkout-form .label {
    font-size: 13px; color: var(--text-secondary); margin-bottom: 4px;
}
.checkout-form input, .checkout-form select {
    width: 100%;
    padding: 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 15px;
    background: var(--bg); color: var(--text);
    margin-bottom: 16px;
}
.checkout-form .order-summary {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px; margin-bottom: 16px;
}
.checkout-form .order-item {
    margin-bottom: 10px;
}
.checkout-form .order-item .product-name {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 2px;
}
.checkout-form .order-item .line-detail {
    font-size: 13px;
    color: var(--text-secondary);
}
.checkout-form .fee-line {
    display: flex; justify-content: space-between;
    font-size: 14px; padding: 4px 0;
}
.checkout-form .fee-total {
    display: flex; justify-content: space-between;
    font-size: 18px; font-weight: 700;
    border-top: 1px solid var(--border);
    padding-top: 8px; margin-top: 8px;
}
.checkout-form .submit-btn {
    width: 100%;
    background: var(--success); color: #fff;
    border: none; border-radius: var(--radius);
    padding: 14px; font-size: 16px; font-weight: 600;
    cursor: pointer;
}

/* ─── 订单列表 ─── */
.order-list { padding: 16px; }
.order-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px; margin-bottom: 12px;
}
.order-card .order-header {
    display: flex; justify-content: space-between;
    margin-bottom: 8px;
}
.order-card .order-id { font-size: 12px; color: var(--text-secondary); }
.order-card .order-status {
    font-size: 12px; font-weight: 600; padding: 2px 8px;
    border-radius: 10px;
}
.order-card .status-pending { background: #fff3cd; color: #856404; }
.order-card .status-completed { background: #d4edda; color: #155724; }
.order-card .status-cancelled { background: #f8d7da; color: #721c24; }
.order-card .order-total { font-size: 16px; font-weight: 700; margin-top: 6px; }
.order-card .order-items { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* ─── 空状态 ─── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ─── 底部导航 ─── */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 100;
}
.bottom-nav .nav-item {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    border: none; background: none;
    color: var(--text-secondary); font-size: 10px;
    cursor: pointer;
}
.bottom-nav .nav-item.active {
    color: var(--accent);
}
.bottom-nav .nav-item .nav-icon {
    font-size: 22px;
}
.bottom-nav .nav-item .badge {
    background: var(--danger); color: #fff;
    font-size: 10px; min-width: 16px; height: 16px;
    border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    margin-left: -8px; margin-top: -18px;
}

/* ─── 页面切换动画 ─── */
.page { display: none; }
.page.active { display: block; }

/* ─── 首页公告横幅 ─── */
.announcement-banner {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    padding: 14px 16px;
    font-size: 13px;
    line-height: 1.5;
}
@media (prefers-color-scheme: dark) {
    .announcement-banner {
        background: linear-gradient(135deg, #5a67d8 0%, #6b3fa0 100%);
    }
}

/* ─── Loading ─── */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}
.loading::after {
    content: "加载中...";
}
.spinner {
    display: inline-block;
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── 结算页商品明细 ─── */
.checkout-form .order-item .product-name {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 2px;
}
.checkout-form .order-item .line-detail {
    font-size: 13px;
    color: var(--text-secondary);
}