:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --line: #eff0f1;
  --primary: #2f6bff;
  --primary-weak: #eaf0ff;
  --cost: #e0554d;
  --sale: #0a8f3c;
  --radius: 14px;
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

[hidden] { display: none !important; }

.view { max-width: 520px; margin: 0 auto; min-height: 100dvh; }

.muted { color: var(--text-3); font-size: 13px; }

/* ---------- 登录 ---------- */
#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box { width: 100%; max-width: 360px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 22px; margin: 12px 0 4px; }
.logo-circle {
  width: 64px; height: 64px; margin: 0 auto;
  border-radius: 20px;
  background: linear-gradient(135deg, #2f6bff, #6c8dff);
  color: #fff; font-size: 30px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(47, 107, 255, .35);
}
.field { margin-bottom: 14px; }
.field input {
  width: 100%; padding: 13px 14px;
  border: 1px solid #e2e3e5; border-radius: 12px;
  font-size: 16px; background: #fff; color: var(--text);
  outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--primary); }
.btn-primary {
  width: 100%; padding: 13px; margin-top: 6px;
  border: 0; border-radius: 12px;
  background: var(--primary); color: #fff;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
}
.btn-primary:active { opacity: .85; }
.btn-primary[disabled] { opacity: .6; }
.login-error { color: var(--cost); font-size: 13px; text-align: center; margin: 12px 0 0; }

/* ---------- 顶栏 / 标签 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(242, 243, 245, .92);
  backdrop-filter: blur(10px);
}
.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.store-select {
  max-width: 110px; padding: 5px 26px 5px 10px;
  border: 1px solid #e2e3e5; border-radius: 9px;
  background: #fff url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23646a73' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E") no-repeat right 9px center;
  -webkit-appearance: none; appearance: none;
  font-size: 13px; color: var(--text); font-family: inherit;
  outline: none;
}
.store-tag {
  flex: none; font-size: 11px; font-weight: 400;
  color: var(--primary); background: var(--primary-weak);
  border-radius: 5px; padding: 1px 6px; margin-left: 6px; vertical-align: 1px;
}
.btn-ghost {
  border: 0; background: transparent; color: var(--primary);
  font-size: 14px; cursor: pointer; padding: 4px 6px;
}
.tabs {
  position: sticky; top: 49px; z-index: 9;
  display: flex; gap: 6px;
  padding: 0 16px 10px;
  background: rgba(242, 243, 245, .92);
  backdrop-filter: blur(10px);
}
.tab {
  flex: 1; padding: 9px 0;
  border: 0; border-radius: 10px;
  background: #e8e9eb; color: var(--text-2);
  font-size: 15px; font-weight: 500; cursor: pointer;
  transition: all .15s;
}
.tab.active { background: var(--primary); color: #fff; font-weight: 600; }

/* ---------- 搜索框 ---------- */
.search-wrap { padding: 4px 16px 10px; }
.search-box {
  display: flex; align-items: center; gap: 6px;
  background: #e8e9eb; border-radius: 12px; padding: 0 10px;
}
.search-box:focus-within { outline: 2px solid var(--primary-weak); background: #fff; box-shadow: 0 0 0 1px var(--primary); }
.icon-search { width: 18px; height: 18px; color: var(--text-3); flex: none; }
.search-box input {
  flex: 1; min-width: 0;
  border: 0; background: transparent; outline: none;
  padding: 11px 0; font-size: 16px; color: var(--text);
  -webkit-appearance: none; appearance: none;
}
.search-box input::-webkit-search-cancel-button { display: none; }
.btn-clear {
  border: 0; background: #c9ccd1; color: #fff;
  width: 18px; height: 18px; border-radius: 50%;
  line-height: 1; font-size: 14px; cursor: pointer; flex: none;
}

/* ---------- 列表 / 卡片 ---------- */
.list { padding: 0 16px calc(24px + var(--sab)); }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 13px 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(31, 35, 41, .05);
}
.card-title { font-weight: 600; font-size: 15px; margin-bottom: 6px; word-break: break-all; }

.sku-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.sku-row:first-of-type { border-top: 0; }
.sku-name { flex: 1; min-width: 0; color: var(--text-2); font-size: 14px; word-break: break-all; }
.price-tag { flex: none; text-align: right; line-height: 1.35; }
.price-cost { color: var(--cost); font-size: 13px; }
.price-sale { color: var(--sale); font-size: 14px; font-weight: 600; }
.price-label { font-size: 11px; color: var(--text-3); margin-right: 3px; }
.stock-tag { flex: none; font-size: 12px; color: var(--text-3); background: #f2f3f5; border-radius: 6px; padding: 1px 6px; }
.stock-out { color: #fff; background: #c9ccd1; }
.ref-price { float: right; font-size: 12px; font-weight: 400; color: var(--text-3); }
.vip-no { font-size: 11px; color: var(--primary); background: var(--primary-weak); border-radius: 5px; padding: 1px 5px; vertical-align: 1px; }
.gift-tag { flex: none; font-size: 11px; color: #fff; background: #f59e0b; border-radius: 5px; padding: 1px 5px; margin-left: 6px; }
.yuan { font-size: 11px; font-weight: 400; }

.empty { text-align: center; color: var(--text-3); padding: 48px 0; }
.empty .empty-icon { font-size: 34px; margin-bottom: 8px; }

/* ---------- 客户列表 ---------- */
.customer-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  border: 0; background: var(--card); cursor: pointer;
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(31, 35, 41, .05);
  font-size: 15px; color: var(--text); font-family: inherit;
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: var(--primary-weak); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600;
}
.customer-info { flex: 1; min-width: 0; }
.customer-name { font-weight: 600; }
.customer-phone { color: var(--text-3); font-size: 13px; }
.arrow { color: var(--text-3); flex: none; }

/* ---------- 订单卡片 ---------- */
.order-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}
.order-time { color: var(--text-2); font-size: 13px; }
.order-status { flex: none; font-size: 12px; color: var(--primary); background: var(--primary-weak); border-radius: 6px; padding: 2px 7px; }
.order-item-row {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 7px 0; font-size: 14px;
}
.oi-name { flex: 1; min-width: 0; word-break: break-all; }
.oi-sku { color: var(--text-3); font-size: 12px; }
.oi-right { flex: none; text-align: right; color: var(--text-2); }
.oi-qty { color: var(--text-3); font-size: 12px; }
.order-total {
  display: flex; justify-content: flex-end; gap: 4px;
  padding-top: 8px; border-top: 1px solid var(--line);
  font-size: 14px;
}
.order-total b { color: var(--sale); }
.btn-link {
  border: 0; background: transparent; color: var(--primary);
  font-size: 14px; cursor: pointer; padding: 8px 0; font-family: inherit;
}

/* ---------- 直播数据 ---------- */
.live-filters {
  display: flex; gap: 8px;
}
.live-filters .store-select { flex: 1; min-width: 0; }
.live-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.live-title { font-weight: 600; font-size: 15px; color: var(--text-1); }
.badge-live, .badge-end {
  flex: none; font-size: 11px; padding: 2px 8px; border-radius: 999px;
}
.badge-live { background: rgba(52, 199, 89, .14); color: #248a3d; }
.badge-end { background: #f0f0f2; color: var(--text-3); }
.live-meta {
  display: flex; flex-wrap: wrap; gap: 2px 12px;
  font-size: 12px; color: var(--text-3); margin-top: 6px;
}
.live-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  margin-top: 10px;
}
.live-cell {
  background: #f6f6f8; border-radius: 10px;
  padding: 8px 4px; text-align: center;
}
.live-cell .v { font-size: 15px; font-weight: 600; color: var(--text-1); }
.live-cell .v .yuan { font-size: 11px; font-weight: 400; }
.live-cell .k { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* ---------- 加载 / 提示 ---------- */
.skeleton {
  border-radius: var(--radius); background: var(--card);
  height: 66px; margin-bottom: 10px; position: relative; overflow: hidden;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.7), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

#toast {
  position: fixed; left: 50%; bottom: calc(64px + var(--sab));
  transform: translateX(-50%);
  background: rgba(31, 35, 41, .92); color: #fff;
  padding: 10px 18px; border-radius: 10px; font-size: 14px;
  max-width: 80vw; z-index: 99; text-align: center;
}

@media (min-width: 521px) {
  body { background: #e9eaed; }
  .view { box-shadow: 0 0 30px rgba(0,0,0,.08); background: var(--bg); }
}
