:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --text: #101828;
  --muted: #667085;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --header-h: 56px;
}

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

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }

/* ------------------------------- 通用组件 ------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:active { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; height: 46px; font-size: 16px; }

.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}
.field .req { color: var(--danger); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.textarea { min-height: 74px; resize: vertical; line-height: 1.5; }
/* 自动变高的输入框：高度由 JS 按内容算，不需要手动拖 */
/* 没量到高度时（例如脚本没跑起来）宁可有滚动条，也不要把内容裁掉 */
.auto-grow { resize: none; }
.input.is-error, .select.is-error, .textarea.is-error { border-color: var(--danger); }
.err-msg { color: var(--danger); font-size: 12px; margin-top: 4px; min-height: 0; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.5; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* 快递识别结果提示（文字与候选按钮混排，所以不能用 flex 的 gap，否则文字会被拆开） */
.courier-hint {
  margin-top: 7px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}
.courier-hint.is-ok { color: var(--success); }
.courier-hint b { color: inherit; }
.pick-chip {
  display: inline-flex; align-items: center;
  height: 28px; padding: 0 10px;
  margin: 3px 6px 0 0;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12.5px;
  font-weight: 500;
  vertical-align: middle;
}
.pick-chip:active { background: #dbe6fd; }

/* 输入框 + 单位后缀 */
.input-group { display: flex; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.unit-chip {
  flex: 0 0 auto;
  min-width: 46px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}
.unit-chip.is-empty { color: var(--muted); font-weight: 400; font-size: 12px; }

/* 小计 */
.total-line {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}
.total-line strong { color: var(--danger); font-size: 16px; }

/* 表单顶部的「快速导入」入口 */
.import-cta {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px dashed var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary-dark);
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
}
.import-cta:active { background: #e3ebfd; }
.import-cta .ico { font-size: 17px; }
.import-cta .txt { flex: 1; }
.import-cta .arrow { font-size: 18px; opacity: .6; }

.inline-hint { font-size: 12.5px; color: var(--warn); margin-top: 6px; }
.link-btn {
  border: 0; background: none; padding: 0;
  color: var(--primary); font-size: 12.5px; text-decoration: underline;
}

/* 导入弹层 */
#import-mask { z-index: 70; }
/* 粘贴区给足高度：这里要放的是从微信里复制的一整段收货信息 */
#import-raw { min-height: 168px; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 10px; line-height: 1.6; }
.recap {
  background: var(--primary-soft);
  border: 1px solid #c7d7fe;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--primary-dark);
  margin-bottom: 12px;
  word-break: break-all;
}
.notes { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.note {
  display: flex; align-items: flex-start; gap: 7px;
  font-size: 12.5px; line-height: 1.55;
  padding: 7px 10px;
  border-radius: 8px;
}
.note.ok { background: var(--success-soft); color: var(--success); }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.info { background: var(--surface-2); color: var(--muted); }
.tip {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.tip summary { cursor: pointer; color: var(--primary); font-weight: 500; }
.tip ol { margin: 8px 0 6px; padding-left: 20px; line-height: 1.9; }
.tip p { margin: 0; }

/* --------------------------------- 登录页 -------------------------------- */

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
  background: linear-gradient(160deg, #eef2ff 0%, #f2f4f7 46%, #f2f4f7 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 28px 22px 24px;
}
.login-logo {
  width: 52px; height: 52px;
  border-radius: 15px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  margin-bottom: 16px;
}
.login-card h1 { font-size: 21px; margin: 0 0 4px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }

/* --------------------------------- 布局 --------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.app-header-inner {
  height: var(--header-h);
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-title { font-size: 16px; font-weight: 600; flex: 1; min-width: 0; }
.app-title .who {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.2;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
}
.icon-btn:active { background: var(--surface-2); }

.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: 11px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px;
}
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 14px calc(96px + env(safe-area-inset-bottom));
}

/* -------------------------------- 搜索栏 -------------------------------- */

.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.search-box { position: relative; flex: 1; }
.search-box .ic {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 15px; pointer-events: none;
}
.search-input {
  width: 100%; height: 46px;
  padding: 0 40px 0 36px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface);
  outline: none;
}
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
/* 隐藏浏览器自带的清除按钮，避免与自定义的重复 */
.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: var(--surface-2); color: var(--muted);
  display: none; align-items: center; justify-content: center; font-size: 15px;
}
.search-clear.is-show { display: flex; }

.chips { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  height: 32px; padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}
.chip.is-active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 500; }

/* --------------------------------- 统计条 -------------------------------- */

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.summary-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
}
.summary-item .k { font-size: 11px; color: var(--muted); }
.summary-item .v { font-size: 16px; font-weight: 600; margin-top: 2px; }
.summary-item .v.amount { color: var(--danger); }
.summary-item .v.pending { color: var(--warn); }

/* -------------------------------- 订单卡片 ------------------------------- */

.list { display: grid; grid-template-columns: 1fr; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 13px 14px;
}
.card-head {
  display: flex; align-items: flex-start; gap: 8px;
  padding-bottom: 9px; border-bottom: 1px dashed var(--border);
  margin-bottom: 9px;
}
.card-head .name { font-size: 16px; font-weight: 600; }
.card-head .name .idx { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 4px; }
.card-head .grow { flex: 1; min-width: 0; }
.card-head .product { font-size: 12px; color: var(--muted); margin-top: 1px; }

.badge {
  flex: 0 0 auto;
  font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid transparent;
}
.badge.s-pending { background: var(--warn-soft); color: var(--warn); border-color: #fde68a; }
.badge.s-shipped { background: var(--primary-soft); color: var(--primary-dark); border-color: #c7d7fe; }
.badge.s-done { background: var(--success-soft); color: var(--success); border-color: #bbf7d0; }

.kv { display: flex; gap: 9px; font-size: 13.5px; margin-bottom: 6px; }
.kv .k { flex: 0 0 62px; color: var(--muted); font-size: 13px; }
.kv .v { flex: 1; min-width: 0; word-break: break-word; }
.kv .v.money { color: var(--danger); font-weight: 600; }
.kv .v.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .2px; }

.copy-btn {
  border: 0; background: var(--surface-2); color: var(--muted);
  border-radius: 6px; padding: 2px 7px; font-size: 12px; margin-left: 6px;
}
.copy-btn:active { background: #e9ecf1; }

.card-actions {
  display: flex; gap: 8px;
  margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--border);
}
.card-actions .btn { flex: 1; height: 36px; font-size: 13.5px; }
.card-actions .btn-del { flex: 0 0 72px; color: var(--danger); border-color: #fecaca; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty .big { font-size: 42px; opacity: .5; }
.empty p { margin: 10px 0 0; font-size: 14px; }

/* ------------------------------- FAB / 悬浮 ------------------------------ */

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 40;
  height: 52px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: flex; align-items: center; gap: 7px;
  box-shadow: 0 8px 22px rgba(37, 99, 235, .38);
}
.fab:active { background: var(--primary-dark); }

/* --------------------------------- 弹层 --------------------------------- */

.sheet-mask {
  position: fixed; inset: 0;
  background: rgba(16, 24, 40, .45);
  z-index: 60;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.sheet-mask.is-open { display: flex; }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  max-height: 92dvh;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.sheet-head h2 { font-size: 16px; margin: 0; flex: 1; }
.sheet-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex; gap: 10px;
  flex: 0 0 auto;
  background: var(--surface);
  border-radius: 0 0 18px 18px;
}
.sheet-foot .btn { flex: 1; height: 46px; font-size: 15px; }
.sheet-foot .btn-cancel { flex: 0 0 92px; }

.confirm-text { font-size: 14px; color: var(--muted); line-height: 1.7; }
.confirm-text b { color: var(--text); }

/* --------------------------------- Toast -------------------------------- */

.toast-layer {
  position: fixed;
  left: 50%; top: 20px;
  transform: translateX(-50%);
  z-index: 90;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
  width: max-content; max-width: 90vw;
}
.toast {
  background: rgba(16, 24, 40, .92);
  color: #fff;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
.toast.is-err { background: rgba(185, 28, 28, .95); }
.toast.is-ok { background: rgba(21, 128, 61, .95); }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.loading { text-align: center; padding: 26px; color: var(--muted); font-size: 13.5px; }
.spin {
  width: 18px; height: 18px; margin: 0 auto 8px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.more-wrap { text-align: center; padding: 14px 0 4px; }

/* -------------------------------- 产品库 -------------------------------- */

.product-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}
.product-row + .product-row { margin-top: 8px; }
.product-row .grow { flex: 1; min-width: 0; }
.product-row .pname { font-size: 15px; font-weight: 500; }
.product-row .pmeta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.unit-tag {
  font-size: 11px; font-weight: 600;
  padding: 2px 7px; border-radius: 6px;
  background: var(--primary-soft); color: var(--primary-dark);
}

/* ------------------------------ 桌面端适配 ------------------------------ */

@media (min-width: 700px) {
  body { font-size: 15px; }
  .list { grid-template-columns: 1fr 1fr; }
  .container { padding: 16px 20px 110px; }
  .sheet-mask { align-items: center; padding: 20px; }
  .sheet { border-radius: 18px; max-height: 88vh; animation: sheet-pop .18s ease-out; }
  .sheet-foot { border-radius: 0 0 18px 18px; }
  @keyframes sheet-pop { from { transform: scale(.97); opacity: .5; } to { transform: scale(1); opacity: 1; } }
  .card-actions .btn { flex: 0 0 auto; min-width: 84px; }
  .card-actions .btn-edit { margin-left: auto; }
  .fab { right: 24px; bottom: 24px; }
}

@media (min-width: 1024px) {
  .summary { grid-template-columns: repeat(4, 1fr); }
}
