/* ============================================
 * 小黔电商 - Mobile-First Stylesheet
 * ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #FF6B35;
    --primary-dark: #E55A2B;
    --primary-light: #FFF0EB;
    --accent: #FF4757;
    --bg: #F5F5F5;
    --card: #FFFFFF;
    --text: #333333;
    --text-secondary: #999999;
    --text-light: #BBBBBB;
    --border: #EEEEEE;
    --success: #2ED573;
    --warning: #FFA502;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --nav-height: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; height: auto; display: block; }
input, button, select, textarea { font-family: inherit; font-size: inherit; outline: none; border: none; }
button { cursor: pointer; }

/* --- App Container --- */
.app-container {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
}

.main-content {
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
}

/* --- Bottom Navigation --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 12px;
    transition: all 0.2s;
    position: relative;
}

.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 10px; color: var(--text-secondary); }
.nav-item.active .nav-label { color: var(--primary); font-weight: 600; }
.nav-item.active .nav-icon { transform: scale(1.1); }

.nav-icon-wrapper { position: relative; display: inline-block; line-height: 1; }

.cart-badge {
    position: absolute;
    top: -8px;
    right: -10px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    border: 2px solid var(--card);
}

/* --- Header --- */
.page-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 16px 16px 20px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-header.simple {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}

.page-header.simple h1 { font-size: 18px; }

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 18px;
    color: #fff;
}

/* --- Search Bar --- */
.search-bar {
    position: relative;
    margin: 0 16px;
}

.search-bar input {
    width: 100%;
    height: 40px;
    border-radius: 20px;
    background: rgba(255,255,255,0.2);
    color: #fff;
    padding: 0 44px 0 16px;
    font-size: 14px;
    transition: all 0.3s;
}

.search-bar input::placeholder { color: rgba(255,255,255,0.7); }
.search-bar input:focus { background: rgba(255,255,255,0.3); }

.search-bar .search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: rgba(255,255,255,0.8);
}

/* Search Results Overlay */
.search-results {
    display: none;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: 100vh;
    background: var(--bg);
    z-index: 200;
    overflow-y: auto;
}

.search-results.active { display: block; }

.search-results-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--card);
}

.search-results-header input {
    flex: 1;
    height: 36px;
    border-radius: 18px;
    background: var(--bg);
    padding: 0 16px;
    font-size: 14px;
}

.search-cancel {
    color: var(--primary);
    font-size: 14px;
    white-space: nowrap;
    padding: 4px 8px;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.search-result-item img {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--bg);
}

.search-result-info { flex: 1; }
.search-result-name { font-size: 14px; margin-bottom: 4px; }
.search-result-price { color: var(--accent); font-weight: 700; font-size: 15px; }
.search-result-sales { font-size: 12px; color: var(--text-secondary); }

/* --- Category Chips --- */
.category-chips {
    display: flex;
    gap: 8px;
    padding: 14px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: #fff;
}

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

.category-chip {
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--bg);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.3s;
    white-space: nowrap;
}

.category-chip.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

/* --- Section Title --- */
.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 8px;
    font-size: 16px;
    font-weight: 700;
}

.section-title .subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* --- Product Grid (3 columns) --- */
.product-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px 16px;
}

.product-card {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
}

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

.product-card-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: #F8F8F8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    color: #DDD;
}

.product-card-body {
    padding: 8px 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.product-card-name {
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

.product-card-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 2px;
}

.product-card-price .unit {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 400;
    margin-left: 2px;
}

.product-card-sales {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.product-card-add {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    transition: all 0.2s;
    border: none;
    cursor: pointer;
    margin-top: auto;
}

.product-card-add:active { background: var(--primary-dark); transform: scale(0.9); }

/* --- Product List (2 columns, for products page) --- */
.product-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 12px 16px;
}

.product-list .product-card-name { font-size: 14px; }
.product-list .product-card-price { font-size: 16px; }

/* --- Product Page Category Tabs --- */
.product-category-tabs {
    display: flex;
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}

.product-category-tab {
    flex: 1;
    text-align: center;
    padding: 12px 4px;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.3s;
    white-space: nowrap;
}

.product-category-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* --- Cart Page --- */
.cart-tabs {
    display: flex;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.cart-tab {
    flex: 1;
    text-align: center;
    padding: 14px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all 0.3s;
}

.cart-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 700;
}

.cart-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.cart-item-img {
    width: 70px;
    height: 70px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
    background: #F8F8F8;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: #DDD;
}

.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.cart-item-price { font-size: 15px; font-weight: 700; color: var(--accent); }

.cart-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.qty-btn {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
}

.qty-input {
    width: 40px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    background: var(--bg);
    border-radius: 4px;
    padding: 2px 0;
}

.cart-item-delete {
    color: var(--text-secondary);
    font-size: 12px;
    padding: 4px 8px;
}

.cart-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.cart-empty-icon { font-size: 60px; margin-bottom: 16px; }
.cart-empty-text { font-size: 14px; }

/* --- Confirm Bar --- */
.cart-confirm-bar {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.cart-total {
    font-size: 14px;
}

.cart-total .amount {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.btn-confirm {
    padding: 10px 28px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border-radius: 22px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255,107,53,0.3);
    transition: all 0.2s;
}

.btn-confirm:active { transform: scale(0.96); opacity: 0.9; }

/* --- Modal --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    animation: fadeIn 0.3s;
}

.modal-overlay.active { display: flex; align-items: flex-end; justify-content: center; }

.modal-sheet {
    width: 100%;
    max-width: 480px;
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 20px 16px calc(20px + var(--safe-bottom));
    animation: slideUp 0.3s ease-out;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-title {
    font-size: 17px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 20px;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 20px;
    color: var(--text-secondary);
    background: none;
    border: none;
}

/* --- Form --- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 14px;
    font-size: 15px;
    background: #FAFAFA;
    transition: all 0.3s;
}

.form-input:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255,107,53,0.1);
}

.form-select {
    width: 100%;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 14px;
    font-size: 15px;
    background: #FAFAFA;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    color: #666;
}

.form-select:disabled {
    background: #EEEEEE;
    color: #999;
}

.btn-primary {
    width: 100%;
    height: 44px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border-radius: 22px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255,107,53,0.3);
    transition: all 0.2s;
}

.btn-primary:active { transform: scale(0.97); opacity: 0.9; }

.btn-outline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 20px;
    border: 1px solid var(--primary);
    color: var(--primary);
    border-radius: 20px;
    font-size: 13px;
    background: transparent;
    transition: all 0.2s;
}

/* --- Login Page --- */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 24px;
    min-height: 80vh;
    justify-content: center;
}

.login-logo {
    font-size: 64px;
    margin-bottom: 8px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-form {
    width: 100%;
}

.login-form .form-input {
    text-align: center;
    font-size: 18px;
    letter-spacing: 2px;
}

.login-form .hint {
    font-size: 12px;
    color: var(--text-light);
    text-align: center;
    margin-top: 8px;
}

/* --- My Page --- */
.my-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 30px 20px 24px;
    text-align: center;
}

.my-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(255,255,255,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin: 0 auto 10px;
}

.my-name { font-size: 18px; font-weight: 600; }
.my-phone { font-size: 13px; opacity: 0.8; }

.my-menu {
    margin: 12px 16px;
    background: #fff;
    border-radius: var(--radius);
    overflow: hidden;
}

.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
    transition: background 0.2s;
}

.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: #FAFAFA; }

.menu-item-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-item-icon { font-size: 20px; width: 24px; text-align: center; }
.menu-item-arrow { color: var(--text-light); }

.menu-item-right {
    font-size: 13px;
    color: var(--text-secondary);
}

/* --- Address Page --- */
.address-item {
    background: #fff;
    margin: 8px 16px;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.address-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.address-name { font-weight: 600; font-size: 15px; }
.address-phone { color: var(--text-secondary); font-size: 14px; margin-left: 12px; }
.address-tag {
    background: var(--primary-light);
    color: var(--primary);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
}

.address-detail {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.address-actions {
    display: flex;
    gap: 16px;
    margin-top: 10px;
    font-size: 13px;
}

.address-edit { color: var(--primary); }
.address-delete { color: var(--text-secondary); }
.address-default { color: var(--success); }

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    pointer-events: none;
}

.toast {
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 14px;
    animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in 1.7s forwards;
    text-align: center;
    white-space: nowrap;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--accent); }

/* --- Company Info Footer --- */
.company-footer {
    text-align: center;
    padding: 20px 16px;
    background: #fff;
    margin-top: 12px;
    border-top: 1px solid var(--border);
}

.company-footer .brand {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.company-footer .info {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* --- No Product Image Placeholder --- */
.img-placeholder {
    width: 100%;
    aspect-ratio: 1;
    background: linear-gradient(135deg, #F8F8F8, #EEE);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    color: #CCC;
}

/* --- Order Item --- */
.order-card {
    background: #fff;
    margin: 8px 16px;
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.order-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 13px;
}

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

.order-status {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.order-status.pending { background: #FFF3E0; color: #E65100; }
.order-status.delivering { background: #E3F2FD; color: #1565C0; }
.order-status.completed { background: #E8F5E9; color: #2E7D32; }
.order-status.cancelled { background: #FFEBEE; color: #C62828; }

.order-body { font-size: 13px; }
.order-product { color: var(--text); margin-bottom: 2px; }
.order-total { font-weight: 600; margin-top: 6px; text-align: right; }

/* --- Login Required --- */
.login-required {
    text-align: center;
    padding: 60px 20px;
}

.login-required-icon { font-size: 60px; margin-bottom: 16px; }
.login-required-text { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; }

/* --- Warning Text --- */
.warning-text {
    color: var(--accent);
    font-size: 13px;
    text-align: center;
    padding: 10px 16px;
    background: #FFF5F5;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

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

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

/* --- Responsive tweaks --- */
@media (min-width: 480px) {
    .product-grid { gap: 10px; padding: 10px 16px; }
    .product-card-name { font-size: 14px; }
}

@media (max-width: 340px) {
    .product-card-name { font-size: 12px; }
    .product-card-price { font-size: 13px; }
    .product-card-add { width: 24px; height: 24px; font-size: 16px; }
}
