/* ===== 全局变量 ===== */
:root {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #3730a3;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --text-lighter: #94a3b8;
  --border: #e2e8f0;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
  --radius: 12px;
  --radius-sm: 8px;
  --max-width: 480px;
  --header-h: 52px;
  --bottom-nav-h: 56px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  max-width: var(--max-width);
  margin: 0 auto;
  position: relative;
  padding-bottom: calc(var(--bottom-nav-h) + 8px);
}
img { display: block; max-width: 100%; height: auto; }
button { cursor: pointer; font-family: inherit; font-size: inherit; border: none; background: none; }
input, textarea, select { font-family: inherit; font-size: inherit; }
a { color: var(--primary); text-decoration: none; }

/* ===== 顶部导航 ===== */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 16px; gap: 12px;
}
.app-header .logo { font-size: 18px; font-weight: 700; color: var(--primary); }
.app-header .back-btn { font-size: 22px; color: var(--text); padding: 4px; }
.app-header .spacer { flex: 1; }

/* ===== 底部导航 ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max-width);
  height: var(--bottom-nav-h);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex; z-index: 100;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-lighter); font-size: 11px; gap: 2px; transition: color .2s;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a svg { width: 22px; height: 22px; }
.bottom-nav .badge {
  position: absolute; top: 4px; right: calc(50% - 20px);
  background: var(--danger); color: #fff; font-size: 10px;
  min-width: 16px; height: 16px; border-radius: 8px; display: flex;
  align-items: center; justify-content: center; padding: 0 4px;
}

/* ===== 搜索栏 ===== */
.search-bar {
  padding: 12px 16px; background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.search-bar input {
  width: 100%; height: 38px; border: 1px solid var(--border);
  border-radius: 20px; padding: 0 16px 0 38px; background: var(--bg);
  outline: none; transition: border-color .2s;
}
.search-bar { position: relative; }
.search-bar .icon { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); color: var(--text-lighter); }

/* ===== 分类标签 ===== */
.category-tabs {
  display: flex; gap: 8px; padding: 12px 16px; overflow-x: auto;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }
.category-tabs button {
  white-space: nowrap; padding: 6px 14px; border-radius: 16px;
  background: var(--card-bg); border: 1px solid var(--border);
  color: var(--text-light); font-size: 13px; transition: all .2s;
}
.category-tabs button.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

/* ===== 商品网格 ===== */
.product-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 12px 16px;
}
.product-card {
  background: var(--card-bg); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.product-card:active { transform: scale(.97); }
.product-card .img-wrap { position: relative; aspect-ratio: 1; background: var(--bg); }
.product-card .img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.product-card .preorder-tag {
  position: absolute; top: 8px; left: 8px; background: var(--warning);
  color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 4px;
}
.product-card .info { padding: 10px 12px; }
.product-card .name { font-size: 14px; font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 42px; }
.product-card .price { color: var(--danger); font-size: 17px; font-weight: 700; margin-top: 6px; }
.product-card .price small { font-size: 12px; font-weight: 400; }
.product-card .stock { font-size: 12px; color: var(--text-lighter); margin-top: 2px; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 24px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; transition: opacity .2s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:disabled { opacity: .5; }
.btn-outline { border: 1px solid var(--border); color: var(--text); background: var(--card-bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { display: flex; width: 100%; }

/* ===== 表单 ===== */
.form-section { padding: 16px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; color: var(--text-light); margin-bottom: 6px; }
.form-group input, .form-group textarea {
  width: 100%; height: 44px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 14px; background: var(--card-bg);
  outline: none; transition: border-color .2s;
}
.form-group input:focus { border-color: var(--primary-light); }
.form-group textarea { height: auto; padding: 10px 14px; resize: vertical; }

/* ===== 商品详情 ===== */
.product-detail .hero { aspect-ratio: 1; background: var(--bg); }
.product-detail .hero img { width: 100%; height: 100%; object-fit: cover; }
.product-detail .body { padding: 16px; }
.product-detail .price { color: var(--danger); font-size: 28px; font-weight: 800; margin: 8px 0; }
.product-detail .price small { font-size: 14px; font-weight: 400; }
.product-detail .desc { color: var(--text-light); line-height: 1.6; margin-top: 12px; }
.product-detail .meta { display: flex; gap: 8px; margin-top: 12px; }
.product-detail .tag { padding: 3px 10px; border-radius: 4px; font-size: 12px; }
.product-detail .tag.in-stock { background: var(--success-light); color: var(--success); }
.product-detail .tag.preorder { background: var(--warning-light); color: var(--warning); }
.product-detail .tag.cat { background: var(--bg); color: var(--text-light); }
.qty-selector { display: flex; align-items: center; gap: 12px; margin: 16px 0; }
.qty-selector button {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card-bg); font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.qty-selector .num { font-size: 18px; font-weight: 600; min-width: 30px; text-align: center; }

/* ===== 底部操作栏 ===== */
.action-bar {
  position: fixed; bottom: var(--bottom-nav-h); left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max-width);
  background: var(--card-bg); border-top: 1px solid var(--border);
  padding: 10px 16px; display: flex; gap: 12px; z-index: 99;
}
.action-bar .btn { flex: 1; }

/* ===== 购物车 ===== */
.cart-item {
  display: flex; gap: 12px; padding: 12px 16px; background: var(--card-bg);
  border-bottom: 1px solid var(--border); align-items: center;
}
.cart-item img { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; background: var(--bg); }
.cart-item .info { flex: 1; }
.cart-item .name { font-size: 14px; font-weight: 500; }
.cart-item .price { color: var(--danger); font-weight: 700; font-size: 15px; }
.cart-item .remove { color: var(--text-lighter); font-size: 20px; padding: 4px 8px; }
.cart-summary {
  padding: 16px; background: var(--card-bg); border-top: 1px solid var(--border);
}
.cart-summary .total { display: flex; justify-content: space-between; font-size: 16px; }
.cart-summary .total .amount { color: var(--danger); font-size: 22px; font-weight: 800; }

/* ===== 订单列表 ===== */
.order-card {
  margin: 12px 16px; background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.order-card .head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.order-card .head .id { font-size: 13px; color: var(--text-light); }
.order-card .head .status { font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 4px; }
.order-card .head .status.pending { background: var(--warning-light); color: var(--warning); }
.order-card .head .status.paid { background: var(--success-light); color: var(--success); }
.order-card .head .status.cancelled { background: var(--danger-light); color: var(--danger); }
.order-card .items { padding: 8px 16px; }
.order-card .item { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.order-card .item .qty { color: var(--text-light); }
.order-card .foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); }
.order-card .foot .total { color: var(--danger); font-weight: 700; font-size: 17px; }
.order-card .foot .time { font-size: 12px; color: var(--text-lighter); }

/* ===== 提示信息 ===== */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(30,41,59,.92); color: #fff; padding: 10px 20px;
  border-radius: 8px; font-size: 14px; z-index: 200;
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
.toast.show { opacity: 1; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-lighter); }
.empty-state svg { width: 56px; height: 56px; margin-bottom: 12px; opacity: .4; }

/* ===== 用户信息 ===== */
.profile-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; padding: 24px 16px; text-align: center;
}
.profile-header .avatar {
  width: 60px; height: 60px; border-radius: 50%; background: rgba(255,255,255,.2);
  margin: 0 auto 8px; display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
}
.profile-header .name { font-size: 18px; font-weight: 600; }
.profile-header .email { font-size: 13px; opacity: .8; margin-top: 2px; }
.profile-menu { background: var(--card-bg); margin-top: 8px; }
.profile-menu a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--text);
}
.profile-menu a:active { background: var(--bg); }

/* ===== 加载状态 ===== */
.loading { text-align: center; padding: 40px; color: var(--text-lighter); }
.loading .spinner {
  width: 28px; height: 28px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite; margin: 0 auto 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 管理员后台 ===== */
.admin-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: #1e293b;
  color: #fff;
  display: flex; align-items: center; padding: 0 16px; gap: 12px;
}
.admin-header .logo { font-size: 16px; font-weight: 700; }
.admin-header .spacer { flex: 1; }
.admin-header a { color: rgba(255,255,255,.8); font-size: 13px; }
.admin-header a:active { color: #fff; }

.admin-nav {
  display: flex; gap: 0; background: var(--card-bg);
  border-bottom: 1px solid var(--border); overflow-x: auto;
  scrollbar-width: none;
}
.admin-nav::-webkit-scrollbar { display: none; }
.admin-nav a {
  flex: 1; min-width: auto; text-align: center; padding: 12px 8px;
  font-size: 13px; color: var(--text-light); border-bottom: 2px solid transparent;
  transition: all .2s; white-space: nowrap; display: flex;
  flex-direction: column; align-items: center; gap: 4px;
}
.admin-nav a svg { width: 20px; height: 20px; }
.admin-nav a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* 统计卡片 */
.stat-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 16px;
}
.stat-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card .label { font-size: 12px; color: var(--text-light); }
.stat-card .value { font-size: 24px; font-weight: 800; margin-top: 4px; }
.stat-card .value.danger { color: var(--danger); }
.stat-card .value.success { color: var(--success); }
.stat-card .value.warning { color: var(--warning); }
.stat-card .value.primary { color: var(--primary); }

/* 管理员商品列表 */
.admin-product-list { padding: 0 0 80px; }
.admin-product-item {
  display: flex; gap: 12px; padding: 12px 16px; background: var(--card-bg);
  border-bottom: 1px solid var(--border); align-items: center;
}
.admin-product-item img { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--bg); flex-shrink: 0; }
.admin-product-item .info { flex: 1; min-width: 0; }
.admin-product-item .name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-product-item .meta { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.admin-product-item .meta .price { color: var(--danger); font-weight: 600; }
.admin-product-item .actions { display: flex; gap: 8px; flex-shrink: 0; }
.admin-product-item .actions button {
  width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--card-bg); display: flex; align-items: center; justify-content: center;
  color: var(--text-light); transition: all .2s;
}
.admin-product-item .actions button:active { background: var(--bg); }
.admin-product-item .actions button.danger { color: var(--danger); border-color: var(--danger); }

/* FAB 浮动按钮 */
.fab {
  position: fixed; bottom: 24px; right: 24px; width: 52px; height: 52px;
  border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(79,70,229,.4); z-index: 50;
  transition: transform .15s;
}
.fab:active { transform: scale(.9); }

/* 管理员表单 */
.admin-form { padding: 16px; padding-bottom: 80px; }
.admin-form .form-group label { font-size: 14px; font-weight: 500; color: var(--text); }
.admin-form .form-group input, .admin-form .form-group textarea, .admin-form .form-group select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; background: var(--card-bg);
}
.admin-form .form-group select { height: 44px; }

/* 图片上传区 */
.image-upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 24px; text-align: center; background: var(--bg); cursor: pointer;
  transition: border-color .2s, background .2s;
}
.image-upload-area:active { border-color: var(--primary); background: #eef2ff; }
.image-upload-area.has-image { padding: 0; border-style: solid; border: none; }
.image-upload-area .preview-img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius);
}
.image-upload-area .upload-icon { color: var(--text-lighter); margin-bottom: 8px; }
.image-upload-area .upload-icon svg { width: 36px; height: 36px; }
.image-upload-area .hint { font-size: 13px; color: var(--text-light); }
.image-upload-area .url-input {
  margin-top: 12px; display: flex; gap: 8px;
}
.image-upload-area .url-input input {
  flex: 1; height: 38px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0 12px; background: var(--card-bg);
}

/* 开关 */
.switch { display: flex; align-items: center; gap: 12px; }
.switch input { display: none; }
.switch .track {
  width: 44px; height: 24px; border-radius: 12px; background: var(--border);
  position: relative; transition: background .2s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch .label { font-size: 14px; color: var(--text); }

/* 管理员订单列表 */
.admin-order-card {
  margin: 12px 16px; background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.admin-order-card .head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.admin-order-card .head .id { font-size: 13px; color: var(--text-light); }
.admin-order-card .head .user { font-size: 13px; color: var(--text); font-weight: 500; }
.admin-order-card .head .status-select {
  font-size: 12px; padding: 2px 8px; border-radius: 4px; border: 1px solid var(--border);
  background: var(--card-bg); color: var(--text); font-weight: 600;
}
.admin-order-card .items { padding: 8px 16px; }
.admin-order-card .item { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.admin-order-card .item .qty { color: var(--text-light); }
.admin-order-card .foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); }
.admin-order-card .foot .total { color: var(--danger); font-weight: 700; font-size: 17px; }
.admin-order-card .foot .time { font-size: 12px; color: var(--text-lighter); }

/* 管理员登录页 */
.admin-login {
  max-width: 400px; margin: 60px auto; padding: 0 16px;
}
.admin-login .icon-wrap {
  width: 64px; height: 64px; border-radius: 16px; margin: 0 auto 16px;
  background: #1e293b; display: flex; align-items: center; justify-content: center;
  color: #fff;
}
.admin-login .icon-wrap svg { width: 32px; height: 32px; }
.admin-login h2 { text-align: center; font-size: 20px; margin-bottom: 8px; }
.admin-login .subtitle { text-align: center; font-size: 14px; color: var(--text-light); margin-bottom: 24px; }
.admin-login .hint-box {
  background: var(--warning-light); border-radius: var(--radius-sm);
  padding: 12px 16px; font-size: 13px; color: var(--warning); margin-top: 16px;
}

/* 确认弹窗 */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--card-bg); border-radius: var(--radius); padding: 24px;
  max-width: 320px; width: 100%; text-align: center;
}
.modal-box h3 { font-size: 17px; margin-bottom: 8px; }
.modal-box p { font-size: 14px; color: var(--text-light); margin-bottom: 20px; }
.modal-box .actions { display: flex; gap: 12px; }
.modal-box .actions .btn { flex: 1; height: 40px; font-size: 14px; }

/* 底部操作栏（管理端） */
.admin-action-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max-width);
  background: var(--card-bg); border-top: 1px solid var(--border);
  padding: 10px 16px; display: flex; gap: 12px; z-index: 99;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}
.admin-action-bar .btn { flex: 1; }
