/* ===== 基础重置 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #3a7bd5;
  --primary-dark: #2c5fa8;
  --primary-light: #e8f0fb;
  --accent: #ff8a3a;
  --danger: #e54848;
  --text: #2a2d34;
  --text-light: #6b7280;
  --border: #e3e6eb;
  --bg: #f5f6f8;
  --card: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --radius: 14px;
  --base-size: 18px;
  --label-size: 16px;
  --btn-size: 18px;
  --btn-height: 54px;
  --input-height: 52px;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: var(--base-size);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: var(--base-size);
  color: inherit;
}

a { text-decoration: none; color: inherit; }

/* ===== 页面结构 ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--primary);
  color: #fff;
  padding: 16px 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  text-align: center;
  box-shadow: 0 2px 6px rgba(58,123,213,.25);
}
.app-header h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .5px;
}

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 14px 110px;
  min-height: calc(100vh - 60px);
}

/* ===== 底部 tab 栏 ===== */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 680px;
  margin: 0 auto;
  box-shadow: 0 -2px 8px rgba(0,0,0,.04);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  color: var(--text-light);
  font-size: 14px;
  gap: 3px;
  transition: color .15s;
}
.tab .tab-icon {
  font-size: 24px;
  line-height: 1;
}
.tab .tab-label {
  font-size: 14px;
}
.tab.active {
  color: var(--primary);
  font-weight: 500;
}

/* ===== 通用组件 ===== */
.section-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-light);
  margin: 20px 4px 12px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--btn-height);
  padding: 0 22px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: var(--btn-size);
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .05s;
  letter-spacing: .3px;
}
.btn:active { transform: scale(.98); }
.btn-block {
  width: 100%;
}
.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-ghost {
  background: transparent;
  color: var(--text-light);
}
.btn-danger {
  background: var(--danger);
}
.btn-accent {
  background: var(--accent);
}

.field {
  margin-bottom: 16px;
}
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: var(--label-size);
  color: var(--text-light);
  margin-bottom: 8px;
  font-weight: 500;
}
.input, .textarea, .select {
  width: 100%;
  min-height: var(--input-height);
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font-size: var(--base-size);
  transition: border-color .15s;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
}
.textarea {
  min-height: 88px;
  resize: vertical;
}

/* ===== 开单页面 ===== */
.order-meta {
  display: flex;
  gap: 12px;
}
.order-meta .field { flex: 1; margin-bottom: 0; }

.customer-pick {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.customer-pick .select { flex: 1; }
.customer-pick .btn { white-space: nowrap; padding: 0 16px; }

.items-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px 4px 12px;
}
.items-header .section-title { margin: 0; }

.item-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.item-card .item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.item-card .item-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--primary);
}
.item-card .item-del {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 24px;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
}

.field-row {
  display: flex;
  gap: 12px;
}
.field-row .field { flex: 1; }

.item-subtotal {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--primary-light);
  padding: 12px 14px;
  border-radius: 10px;
  margin-top: 6px;
}
.item-subtotal .label {
  font-size: 16px;
  color: var(--primary-dark);
}
.item-subtotal .amount {
  font-size: 21px;
  font-weight: 700;
  color: var(--primary-dark);
}

.img-picker {
  margin-top: 6px;
}
.img-preview {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 10px;
  background: #f0f1f3;
}
.img-input {
  display: none;
}
.img-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  width: 100%;
  padding: 0 16px;
  border: 1.5px dashed var(--primary);
  border-radius: 12px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 17px;
  cursor: pointer;
}
.img-btn.has-img {
  border-style: solid;
}

.order-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--primary);
  color: #fff;
  padding: 18px 16px;
  border-radius: var(--radius);
  margin: 18px 0;
}
.order-total .label { font-size: 19px; }
.order-total .amount { font-size: 24px; font-weight: 700; }

/* 订单数量合计栏（与金额合计同款蓝底白字） */
.order-qty-total {
  background: var(--primary);
  color: #fff;
  margin-bottom: 10px;
}

/* 订单详情表格（紧凑，便于发送核对） */
.order-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
  margin-top: 10px;
  background: #fff;
}
.order-table th,
.order-table td {
  border: 1px solid var(--border);
  padding: 10px 10px;
  text-align: left;
  vertical-align: top;
}
.order-table th {
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 600;
  font-size: 15px;
}
.order-table .ot-num { text-align: right; white-space: nowrap; }
.order-table .ot-style { min-width: 30%; }
.order-table .ot-remark { font-size: 14px; color: var(--text-light); margin-top: 4px; }
.order-table tfoot td { font-weight: 700; background: #fafbfc; }
.order-table .ot-total-label { text-align: right; }
.order-table .ot-total-amt { text-align: right; color: var(--primary-dark); }

.empty-hint {
  text-align: center;
  color: var(--text-light);
  padding: 48px 20px;
  font-size: 17px;
}

/* ===== 列表页 ===== */
.list-search {
  margin-bottom: 14px;
}
.list-item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.list-item:active { background: #fafbfc; }
.list-item .li-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.list-item .li-name {
  font-size: 20px;
  font-weight: 600;
}
.list-item .li-sub {
  font-size: 16px;
  color: var(--text-light);
  margin-top: 3px;
}
.list-item .li-amount {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-dark);
}
.list-item .li-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 15px;
  color: var(--text-light);
  margin-top: 10px;
}
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 8px;
  font-size: 14px;
  background: var(--primary-light);
  color: var(--primary-dark);
}

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 32px;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(255,138,58,.4);
  cursor: pointer;
  z-index: 25;
}

/* ===== 弹窗 ===== */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal {
  background: #fff;
  width: 100%;
  max-width: 680px;
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 21px; }
.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  color: var(--text-light);
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.modal-actions .btn { flex: 1; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(42,45,52,.92);
  color: #fff;
  padding: 14px 24px;
  border-radius: 26px;
  font-size: 17px;
  z-index: 50;
  max-width: 80%;
  text-align: center;
}

/* ===== 详情 ===== */
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 17px;
}
.detail-row .k { color: var(--text-light); }
.detail-row .v { font-weight: 500; text-align: right; }
.detail-row.total .v { font-size: 21px; font-weight: 700; color: var(--primary-dark); }

.thumb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}
.thumb-grid img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.qty-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qty-stepper button {
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 22px;
  cursor: pointer;
}

/* ===== 适配小屏安卓（横屏或窄屏） ===== */
@media (max-width: 360px) {
  :root {
    --base-size: 17px;
    --label-size: 15px;
    --btn-size: 17px;
  }
  .app-header h1 { font-size: 20px; }
  .order-meta { flex-direction: column; gap: 0; }
  .order-meta .field { margin-bottom: 14px; }
  .field-row { flex-direction: column; gap: 0; }
}
