:root {
  --bg: #f2f5fa;
  --card: #ffffff;
  --text: #1f2a44;
  --text-soft: #6b7793;
  --line: #e7ebf3;
  --primary: #3b6ef5;
  --primary-soft: #eaf0ff;
  --primary-deep: #2a54d6;
  --accent: #ff7a45;
  --ok: #12b76a;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(31, 42, 68, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

/* 移动端基础：禁止系统字体自动放大、去除点击高亮 */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
input,
select,
label,
.switch-row {
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(1200px 500px at 100% -10%, #e5ecff 0%, rgba(229, 236, 255, 0) 60%),
    radial-gradient(900px 400px at -10% 0%, #e9f7f1 0%, rgba(233, 247, 241, 0) 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #4a7bff, #2a54d6);
  box-shadow: 0 8px 20px rgba(59, 110, 245, 0.35);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.5px;
}

.brand .sub {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-soft);
}

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 22px;
  align-items: start;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  border: 1px solid rgba(231, 235, 243, 0.8);
}

.card-title {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 600;
  position: relative;
  padding-left: 12px;
}

.card-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(180deg, #4a7bff, #2a54d6);
}

/* ---------- 表单 ---------- */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-soft);
  margin-bottom: 7px;
  font-weight: 500;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrap .unit {
  position: absolute;
  right: 14px;
  font-size: 13px;
  color: var(--text-soft);
  pointer-events: none;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  padding: 11px 14px;
  font-size: 15px;
  color: var(--text);
  background: #f7f9fd;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
  font-family: inherit;
  appearance: none;
}

.input-wrap input[type="number"] { padding-right: 40px; }

select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7793' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
  cursor: pointer;
}

input:focus,
select:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(59, 110, 245, 0.12);
}

/* 泡货开关 */
.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1.5px dashed #d5deee;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 16px;
  transition: border-color 0.18s, background 0.18s;
  user-select: none;
}

.switch-row:hover { border-color: #b9c8e8; }
.switch-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}
.switch-text { font-size: 14px; font-weight: 500; }

/* 尺寸子面板 */
.sub-panel {
  background: var(--primary-soft);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
  animation: fade 0.22s ease;
}

@keyframes fade {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 货物清单（多件累加） ---------- */
.pieces-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.pieces-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.piece-cols {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 58px;
  gap: 6px;
  padding: 0 2px;
  font-size: 11.5px;
  color: var(--text-soft);
}

.piece-cols .ta-right { grid-column: 1 / 4; }
.piece-cols span:last-child { grid-column: 4; }

.piece-list {
  max-height: 208px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.piece-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 58px;
  gap: 6px;
  align-items: center;
  padding: 8px 2px;
  border-bottom: 1px dashed rgba(59, 110, 245, 0.18);
}

.piece-row:last-child { border-bottom: none; }

.piece-list .piece-input {
  width: 100%;
  padding: 8px 6px;
  font-size: 13px;
  text-align: center;
  border-radius: 9px;
}

.piece-input::-webkit-outer-spin-button,
.piece-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.piece-input[type="number"] { -moz-appearance: textfield; }

.piece-list .piece-count {
  text-align: center;
  font-weight: 600;
  color: var(--primary-deep);
}

.piece-sum {
  grid-column: 1 / 4;
  text-align: right;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--primary-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-del {
  grid-column: 4;
  width: 100%;
  padding: 8px 0;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  color: #a6b0c6;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.18s;
}

.btn-del:hover {
  color: var(--accent);
  background: #fff4ef;
  border-color: #ffb59a;
}

.field.small { margin-bottom: 0; }
.field.small label { font-size: 12px; }
.field.small input { padding: 9px 10px; font-size: 14px; }

.hint {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--primary-deep);
  font-weight: 600;
}

.formula-note {
  margin-top: 4px;
  padding: 13px 15px;
  background: #f7f9fd;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.formula-note p {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-soft);
  line-height: 1.9;
}
.formula-note strong { color: var(--text); }

/* ---------- 指标 ---------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  background: #f7f9fd;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.metric-label { font-size: 12.5px; color: var(--text-soft); }

.metric-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.metric-value.accent { color: var(--primary); }

/* 折前原价（仅折扣 < 100% 时显示） */
.metric-orig {
  font-size: 12.5px;
  color: var(--text-soft);
  text-decoration: line-through;
  margin-top: -4px;
}

/* ---------- 折扣率 ---------- */
.discount-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  min-height: 40px;
}

.discount-label {
  font-size: 13px;
  color: var(--text-soft);
  white-space: nowrap;
  flex: 0 0 auto;
  cursor: pointer;
}

input[type="range"].discount-range {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  height: 26px;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}

input[type="range"].discount-range:focus { outline: none; }
input[type="range"].discount-range:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(59, 110, 245, 0.12);
  border-radius: 8px;
}

/* WebKit / Blink：自绘轨道 + 滑块 */
input[type="range"].discount-range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    var(--primary) 0 var(--fill, 100%),
    #e3e8f3 var(--fill, 100%) 100%
  );
}

input[type="range"].discount-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary);
  box-shadow: 0 2px 6px rgba(31, 42, 68, 0.2);
  transition: transform 0.15s ease;
}

input[type="range"].discount-range:active::-webkit-slider-thumb {
  transform: scale(1.12);
}

/* Firefox */
input[type="range"].discount-range::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: #e3e8f3;
}

input[type="range"].discount-range::-moz-range-progress {
  height: 6px;
  border-radius: 3px;
  background: var(--primary);
}

input[type="range"].discount-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary);
  box-shadow: 0 2px 6px rgba(31, 42, 68, 0.2);
}

.discount-value {
  flex: 0 0 auto;
  min-width: 48px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-deep);
  font-variant-numeric: tabular-nums;
}

/* ---------- 筛选 ---------- */
.filter-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.filter-row .grow { flex: 1; }

.btn-ghost {
  padding: 0 18px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--text-soft);
  border-radius: 11px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
}
.btn-ghost:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: 9px;
  white-space: nowrap;
}

/* ---------- 表格 ---------- */
.table-wrap {
  max-height: 520px;
  overflow: auto;
  border-radius: 13px;
  border: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.price-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.price-table thead th {
  position: sticky;
  top: 0;
  background: #f4f7fd;
  color: var(--text-soft);
  font-weight: 600;
  font-size: 12.5px;
  text-align: left;
  padding: 12px 16px;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
  z-index: 1;
}

.price-table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid #f0f3f9;
  vertical-align: middle;
}

.price-table tbody tr:last-child td { border-bottom: none; }
.price-table tbody tr:hover { background: #f9fbff; }

.province-cell { font-weight: 600; white-space: nowrap; }
.province-cell .tag {
  display: inline-block;
  font-size: 11px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 6px;
  padding: 1px 7px;
  margin-left: 8px;
  font-weight: 600;
}

.detail { font-size: 12.5px; color: var(--text-soft); line-height: 1.5; }

.ta-right { text-align: right !important; }

.price-cell {
  text-align: right;
  font-weight: 700;
  font-size: 16px;
  color: var(--accent);
  white-space: nowrap;
}

.price-cell.best { color: var(--ok); }

.weight-cell { white-space: nowrap; color: var(--text); font-weight: 500; }

.empty {
  text-align: center;
  padding: 40px 0;
  color: var(--text-soft);
  font-size: 14px;
  margin: 0;
}

.footer {
  margin-top: 26px;
  text-align: center;
  font-size: 12.5px;
  color: #9aa5bd;
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .table-wrap {
    max-height: 70vh;
    max-height: 70dvh;
  }
  /* 输入控件字号 ≥16px，避免 iOS 聚焦时自动放大整页 */
  input[type="number"],
  input[type="text"],
  select,
  .field.small input,
  .piece-list .piece-input { font-size: 16px; }
}

@media (max-width: 560px) {
  .app { padding: 16px 12px 28px; }
  .topbar { margin-bottom: 16px; }
  .logo { width: 44px; height: 44px; font-size: 21px; border-radius: 13px; }
  .brand { gap: 11px; }
  .brand h1 { font-size: 18px; }
  .brand .sub { font-size: 12px; }
  .layout { gap: 16px; }
  .card { padding: 14px; }
  .card-title { font-size: 15px; margin-bottom: 14px; }
  .sub-panel { padding: 12px; }
  .switch-row { padding: 11px 12px; }

  /* 指标改为紧凑横排，避免手机上占满一屏 */
  .metrics {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 16px;
  }
  .metric {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    gap: 10px;
  }
  .metric-value { font-size: 20px; }

  /* 筛选行 */
  .filter-row { gap: 8px; margin-bottom: 12px; }
  .btn-ghost { padding: 0 14px; font-size: 13.5px; }
  .btn-sm { padding: 9px 12px; font-size: 13px; }

  /* 货物清单：加大触控与字号，仍保持一行四列 */
  .pieces-title { font-size: 12.5px; }
  .piece-cols,
  .piece-row { grid-template-columns: 1fr 1fr 1fr 56px; gap: 5px; }
  .piece-list { max-height: 190px; }
  .piece-list .piece-input { padding: 9px 4px; font-size: 16px; }
  .piece-sum { font-size: 11.5px; }
  .btn-del { font-size: 16px; min-height: 38px; }

  /* 表格：收紧留白，仅保留省份 / 计费重量 / 运费 */
  .price-table { font-size: 13.5px; }
  .price-table thead th { padding: 10px 12px; }
  .price-table tbody td { padding: 11px 12px; }
  .price-cell { font-size: 15px; }
  .detail,
  .price-table thead th:nth-child(3) { display: none; }
  .empty { padding: 28px 0; }

  .formula-note { padding: 11px 12px; }
  .formula-note p { font-size: 12px; line-height: 1.8; }
  .footer { margin-top: 18px; font-size: 12px; }
}

/* 刘海屏 / 手势条机型：预留底部安全区 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 900px) {
    .app {
      padding-left: calc(12px + env(safe-area-inset-left));
      padding-right: calc(12px + env(safe-area-inset-right));
      padding-bottom: calc(28px + env(safe-area-inset-bottom));
    }
  }
}