:root {
  --green: #2f7d5b;
  --green-dark: #246547;
  --green-soft: #eaf4ee;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e9e7;
  --danger: #c0392b;
  --shadow: 0 2px 10px rgba(31, 41, 55, .06);
}

* { box-sizing: border-box; }

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

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}

.topbar-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
}

.brand { display: flex; align-items: center; gap: 10px; flex: 1; }

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--green);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo {
  height: 28px;
  width: auto;
  display: block;
  border-radius: 6px;
}

.brand h1 { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.2; }
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--muted); }

.badge {
  font-size: 11px;
  color: var(--green);
  background: var(--green-soft);
  border: 1px solid #cfe6d9;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}

.back { color: var(--green); font-size: 15px; white-space: nowrap; padding: 6px 0; }
.topbar h1.page-title { margin: 0; font-size: 17px; flex: 1; text-align: center; font-weight: 700; }

.container { max-width: 760px; margin: 0 auto; padding: 16px 16px 40px; }

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

.panel > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }

.filter-row { display: flex; gap: 10px; flex-wrap: wrap; }

input[type="date"] {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

input[type="date"]:focus { outline: 2px solid #bcdcc9; border-color: var(--green); }

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  height: 42px;
  padding: 0 18px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: opacity .15s, background .15s, transform .12s, box-shadow .15s;
}

.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-sm { height: 36px; padding: 0 14px; font-size: 14px; }
.btn-ghost { background: var(--green-soft); color: var(--green); border-color: #cfe6d9; }
.btn-ghost:hover { background: #dcefe3; }
.btn-ding { background: #1677ff; color: #fff; border-color: #1677ff; }
.btn-ding:hover { background: #0e63e6; }
.btn-ico { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.hint { margin: 10px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }

.stat {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border-radius: 10px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 600;
}

.state {
  padding: 28px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.state:empty { display: none; }
.state.is-error { color: var(--danger); }
.state.is-error a { color: var(--green); text-decoration: underline; }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  vertical-align: -3px;
  border: 2px solid #cfe6d9;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.order-list { display: flex; flex-direction: column; gap: 12px; }

.order-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 15px 16px;
  transition: transform .12s, border-color .12s;
}

.order-card:active { transform: scale(.995); border-color: #bcdcc9; }
.order-card:hover { border-color: #bcdcc9; }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.customer { font-size: 17px; font-weight: 700; }
.amount { color: var(--green); font-size: 17px; font-weight: 700; white-space: nowrap; }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.card-meta .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.card-address { margin-top: 8px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card-foot {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.card-foot .arrow { color: var(--green); font-weight: 600; }

.bill-card .bill-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  padding-bottom: 12px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  font-size: 13px;
  line-height: 1.5;
}

.kv span { color: var(--muted); white-space: nowrap; }
.kv b { font-weight: 600; text-align: right; word-break: break-all; }
.kv b.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 500; }

.table-panel { padding: 0; overflow: hidden; }

.table-head {
  display: flex;
  justify-content: space-between;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
}

.table-head span { color: var(--muted); font-weight: 500; font-size: 12px; }

/* 商品明细上方单独一行：金额核对结果 */
.check-row {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--green-soft);
  color: var(--green-dark);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.6;
  word-break: break-word;
}

.check-row.is-warn { background: #fff4e5; color: #a15c00; }
.check-row[hidden] { display: none; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 340px; }

th, td {
  padding: 9px 6px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th { background: #f0f3f1; font-weight: 700; color: #374151; }
td:nth-child(2) { min-width: 96px; }
tbody tr:nth-child(even) { background: #fafbfa; }
tfoot td { background: var(--green-soft); font-weight: 700; color: var(--green-dark); }
tfoot td:first-child { text-align: left; padding-left: 14px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  max-width: 88vw;
  padding: 10px 18px;
  border-radius: 22px;
  background: #24312b;
  color: #fff;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 30;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--danger); }

@media (max-width: 420px) {
  .container { padding: 12px 12px 32px; }
  .filter-row { flex-direction: column; }
  .btn { width: 100%; }
  .topbar-inner .btn-sm { width: auto; }
  th, td { padding: 8px 3px; font-size: 12px; }
  td:nth-child(2) { min-width: 80px; }
}

/* ===== 日期范围 / 分页 ===== */
.range-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.range-row input[type="date"] { flex: 1; min-width: 0; }
.range-sep { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.filter-row .btn { flex: 1; }
.btn-block { display: flex; width: 100%; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 18px 0 6px; }
.pager .btn { width: auto; flex: 0 0 auto; }
.pager-info { flex: 1; text-align: center; font-size: 13px; color: var(--muted); }
.pager[hidden] { display: none; }

/* ===== 仓储详情页操作区 ===== */
.action-row { display: flex; gap: 10px; margin: 0 0 14px; }
.action-row .btn { flex: 1; }
.save-msg { margin: 0 0 12px; font-size: 13px; line-height: 1.6; }
.save-msg:empty { display: none; }
.save-msg.is-ok { color: var(--green); }
.save-msg.is-warn { color: #a15c00; }

/* ===== 底部 Tab（四个入口 + 退出） ===== */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: rgba(255, 255, 255, .97);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar:empty { display: none; }
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 48px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.tab-item.is-active { color: var(--green); font-weight: 700; }
.tab-dot { width: 16px; height: 16px; border: 2px solid currentColor; border-radius: 5px; opacity: .75; }
.tab-item.is-active .tab-dot { background: var(--green); opacity: 1; }
/* 退出：红色描边胶囊 + 图标，与导航项明显区分 */
.tab-exit {
  flex: 0 0 60px;
  color: var(--danger);
  background: #fff5f4;
  border: 1px solid #f0c9c4;
  border-radius: 10px;
  height: 42px;
  margin: 3px 4px 3px 0;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .12s;
}
.tab-exit:hover { background: #ffe9e6; border-color: #e5a9a1; }
.tab-exit:active { transform: scale(.94); }
.tab-exit-ico {
  width: 16px; height: 16px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
body.has-tab { padding-bottom: 72px; }
body.has-tab .toast { bottom: 84px; }

/* ===== 登录页 ===== */
body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 380px; padding: 0 20px; text-align: center; }
.login-logo {
  display: block;
  height: 52px;
  width: auto;
  margin: 0 auto 14px;
  border-radius: 12px;
}
.login-wrap h1 { margin: 0 0 6px; font-size: 20px; }
.login-sub { margin: 0 0 22px; font-size: 13px; color: var(--muted); }
.login-card { text-align: left; padding: 18px; }
.login-card label { display: block; margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.login-card input[type="text"],
.login-card input[type="password"] {
  display: block;
  width: 100%;
  height: 44px;
  margin-bottom: 16px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.login-card input:focus { outline: 2px solid #bcdcc9; border-color: var(--green); }
.login-msg { min-height: 20px; margin: 12px 0 0; font-size: 13px; color: var(--danger); text-align: center; }

@media (max-width: 420px) {
  .range-row input[type="date"] { padding: 0 6px; font-size: 13px; }
  .pager-info { font-size: 12px; }
  .brand-logo { height: 22px; }
}

/* ===== 商品库 ===== */
.goods-toolbar { padding: 14px; }
.goods-search { display: flex; align-items: center; gap: 8px; }
.goods-field { position: relative; flex: 1; min-width: 0; }
.goods-search-ico {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; fill: none; stroke: #9ca3af;
  stroke-width: 2; stroke-linecap: round; pointer-events: none;
}
.goods-field input[type="text"] {
  display: block; width: 100%; height: 44px;
  padding: 0 34px 0 36px;
  border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--text); font-size: 15px; font-family: inherit;
  appearance: none; -webkit-appearance: none;
}
.goods-field input[type="text"]:focus { outline: 2px solid #bcdcc9; border-color: var(--green); }
.goods-clear {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%;
  background: #eef1ef; color: var(--muted); font-size: 17px; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.goods-clear[hidden] { display: none; }

/* 主操作只有一个主色按钮：搜索降为次要，避免两个按钮抢焦点 */
.btn-soft { background: var(--green-soft); color: var(--green-dark); border-color: #cfe6d9; }
.btn-soft:hover { background: #dcefe3; }
.goods-search-btn { height: 44px; padding: 0 16px; flex: 0 0 auto; }
.btn-refresh, .btn-export {
  display: flex; width: 100%; height: 46px; margin-top: 12px;
  background: linear-gradient(180deg, #348866 0%, var(--green) 100%);
  color: #fff; font-size: 15px; letter-spacing: .3px;
  box-shadow: 0 3px 9px rgba(47, 125, 91, .22);
}
.btn-refresh:hover, .btn-export:hover { box-shadow: 0 4px 12px rgba(47, 125, 91, .3); }
.btn-refresh.is-loading .btn-ico { animation: spin .8s linear infinite; }
.goods-toolbar .save-msg { margin-top: 10px; }
.goods-help { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.goods-help summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--green-dark);
  -webkit-tap-highlight-color: transparent;
}
.goods-help summary::-webkit-details-marker { display: none; }
.goods-help summary::before {
  content: ''; width: 0; height: 0;
  border: 4px solid transparent; border-left-color: var(--green);
  transition: transform .15s;
}
.goods-help[open] summary::before { transform: rotate(90deg) translateX(1px); }
.goods-help .hint { margin: 8px 0 0; }
.panel .hint b { color: var(--green-dark); }

.goods-stat { display: flex; align-items: baseline; gap: 7px; margin: 2px 2px 12px; font-size: 12px; color: var(--muted); }
.goods-stat[hidden] { display: none; }
.goods-stat b { color: var(--green-dark); font-size: 15px; }
.goods-stat-sep { color: #c3cbc6; }
.goods-stat-tail { margin-left: auto; }

.goods-list { display: flex; flex-direction: column; gap: 10px; }
.goods-item {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px; align-items: start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 13px 14px;
}
.goods-no {
  width: 26px; height: 26px; margin-top: 1px; border-radius: 8px;
  background: var(--green-soft); color: var(--green-dark);
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: center;
}
.goods-main { min-width: 0; }
.goods-name { font-size: 15px; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; }
.goods-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.goods-tags span { padding: 2px 7px; border-radius: 6px; font-size: 11px; line-height: 1.5; }
.tag-id { background: #f2f5f3; color: var(--muted); word-break: break-all; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.goods-time { margin-top: 8px; font-size: 11px; color: #9ca3af; }
.goods-side { text-align: right; white-space: nowrap; }
.goods-price { font-size: 19px; font-weight: 800; color: var(--green); letter-spacing: -.3px; white-space: nowrap; }
.goods-price-unit { margin-left: 3px; font-size: 11px; font-weight: 600; color: var(--green-dark); letter-spacing: 0; }
.goods-price-note { margin-top: 3px; font-size: 11px; color: var(--muted); }
.pager-btn { min-width: 84px; }

/* 四个 Tab 时收窄「退出」，避免挤压入口 */
.tab-exit { flex: 0 0 60px; }
@media (max-width: 420px) {
  .goods-search .btn { width: auto; }
  .goods-item { grid-template-columns: 26px minmax(0, 1fr) auto; gap: 8px; padding: 12px; }
  .goods-price { font-size: 17px; }
  .goods-tags span { font-size: 10.5px; }
}
@media (max-width: 360px) {
  .tab-item { font-size: 11px; }
  .tab-exit { flex: 0 0 52px; font-size: 10px; margin-right: 2px; }
  .goods-search-btn { padding: 0 12px; font-size: 14px; }
  .goods-price { font-size: 16px; }
  .goods-price-unit { font-size: 10px; }
  .stat-item-metrics b { font-size: 15px; }
}

/* ===== 订单统计 ===== */
.stat-overview { margin-bottom: 16px; }
.stat-hero {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 18px; border-radius: 14px;
  background: linear-gradient(135deg, #2f7d5b 0%, #246547 100%);
  color: #fff; box-shadow: 0 4px 14px rgba(36, 101, 71, .2);
}
.stat-hero-label { font-size: 12px; opacity: .85; }
.stat-hero b { font-size: 30px; font-weight: 800; line-height: 1.2; letter-spacing: -.5px; }
.stat-hero-foot { font-size: 12px; opacity: .85; }
.stat-hero-foot i { font-style: normal; font-weight: 700; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px; }
.stat-cell {
  display: flex; flex-direction: column; gap: 3px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); box-shadow: var(--shadow);
}
.stat-cell > span { font-size: 12px; color: var(--muted); }
.stat-cell b { font-size: 20px; font-weight: 700; color: var(--green-dark); }
.stat-cell small { font-size: 10.5px; color: #9ca3af; }

.stat-list-head {
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: 12px 12px 0 0; background: var(--card);
}
.stat-list { display: flex; flex-direction: column; gap: 10px; }
.stat-item {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.stat-item-head { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px 10px; }
.stat-no {
  width: 26px; height: 26px; flex-shrink: 0; margin-top: 1px; border-radius: 8px;
  background: var(--green-soft); color: var(--green-dark);
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: center;
}
.stat-name { min-width: 0; flex: 1; }
.stat-name-main { font-size: 15px; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; }
.stat-name-meta { margin-top: 5px; font-size: 10.5px; color: var(--muted); word-break: break-all; }
.stat-item-metrics {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px dashed var(--line); background: #fafbfa;
}
.stat-item-metrics > div {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 4px; font-size: 11px; color: var(--muted);
  border-right: 1px solid var(--line);
}
.stat-item-metrics > div:last-child { border-right: 0; }
.stat-item-metrics b { font-size: 17px; font-weight: 700; color: var(--text); }
.stat-item-metrics .is-amount b { color: var(--green); }

@media (max-width: 420px) {
  .stat-hero b { font-size: 26px; }
  .stat-cell { padding: 10px 12px; }
  .stat-cell b { font-size: 18px; }
}
