/* ---------- 设计令牌 ---------- */
:root {
  color-scheme: light;

  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --line: #e2e8e5;
  --line-strong: #cbd5d0;

  --text: #17211e;
  --text-2: #5b6b65;
  --text-3: #8a9a94;

  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-weak: #e6f2f0;
  --accent-ink: #06403a;
  --danger: #b42318;
  --danger-weak: #fdecea;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  --shadow-1: 0 1px 2px rgba(16, 32, 28, 0.06), 0 1px 3px rgba(16, 32, 28, 0.04);
  --shadow-2: 0 10px 28px rgba(16, 32, 28, 0.12);

  --header-h: 60px;
  --tap: 44px;
  --maxw: 1440px;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1513;
    --surface: #161e1b;
    --surface-2: #1b2421;
    --line: #26312d;
    --line-strong: #36443f;
    --text: #e7eeeb;
    --text-2: #a0b0a9;
    --text-3: #74867e;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-weak: rgba(45, 212, 191, 0.12);
    --accent-ink: #99f6e4;
    --danger: #fca5a5;
    --danger-weak: rgba(248, 113, 113, 0.14);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 10px 28px rgba(0, 0, 0, 0.5);
  }
}

/* ---------- 基础 ---------- */
* {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 17px;
}

h2 {
  font-size: 19px;
}

h3 {
  font-size: 15px;
}

p {
  margin: 0;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- 控件 ---------- */
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  min-height: var(--tap);
  padding: 0 var(--s4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.06s;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.btn-primary,
button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

button.btn-primary:hover,
button.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

button.btn-ghost,
button.ghost {
  background: transparent;
}

button.btn-ghost:hover {
  background: var(--surface-2);
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  /* 16px 是硬要求：iOS Safari 对小于 16px 的输入框会强制放大页面 */
  font-size: 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  padding: 10px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-3);
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

textarea {
  min-height: 84px;
  resize: vertical;
  line-height: 1.5;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%235b6b65' stroke-width='1.6'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
}

/* ---------- 头部 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  min-height: var(--header-h);
  padding: var(--s2) var(--s4);
  padding-top: calc(var(--s2) + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.brand-text {
  min-width: 0;
}

.brand-text p {
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}

.nav-tab {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
  min-height: 38px;
  padding: 0 var(--s3);
  font-size: 14px;
}

.nav-tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-tab.active {
  background: var(--accent-weak);
  border-color: transparent;
  color: var(--accent-ink);
  font-weight: 600;
}

/* ---------- 视图容器 ---------- */
.view {
  flex: 1;
  min-height: 0;
}

.view-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--s4) var(--s4) var(--s6);
}

.page-head {
  margin-bottom: var(--s4);
}

.page-head h2 {
  font-size: 18px;
}

.page-head p {
  margin-top: 2px;
  color: var(--text-2);
  font-size: 13px;
}

/* ---------- 工具栏 ---------- */
.catalog-toolbar,
.toolbar {
  display: grid;
  gap: var(--s2);
  margin-bottom: var(--s3);
}

.search-field {
  position: relative;
  display: block;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  color: var(--text-3);
  pointer-events: none;
}

.search-field input {
  padding-left: 36px;
}

.search-field input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.filter-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
}

.toolbar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
}

.result-meta {
  min-height: 18px;
  margin-bottom: var(--s2);
  color: var(--text-2);
  font-size: 12px;
}

/* ---------- 商品网格 ---------- */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s2);
}

.product-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.product-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-1);
}

.product-image {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.02em;
  overflow: hidden;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.product-card-body {
  display: grid;
  gap: 5px;
  padding: 10px 12px 12px;
}

.product-card h3 {
  font-size: 15px;
  font-weight: 600;
}

.meta {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.45;
}

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

.price {
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 600;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1);
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  padding: 2px 6px;
  color: var(--text-2);
  font-size: 11px;
  line-height: 1.6;
}

/* ---------- 面板 ---------- */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: var(--s4);
  margin-bottom: var(--s3);
}

.panel h3 {
  margin-bottom: var(--s3);
  color: var(--text);
}

.split {
  display: grid;
  gap: var(--s3);
}

/* ---------- 骨架屏 ---------- */
.skeleton {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
}

.skeleton-img {
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
}

.skeleton-body {
  display: grid;
  gap: var(--s2);
  padding: 12px;
}

.skeleton-line {
  height: 10px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
}

.skeleton-line.short {
  width: 55%;
}

@media (prefers-reduced-motion: no-preference) {
  .skeleton-img,
  .skeleton-line {
    animation: skeleton-pulse 1.4s ease-in-out infinite;
  }
}

@keyframes skeleton-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

/* ---------- 加载更多 / 空态 ---------- */
.more-wrap {
  padding: var(--s4) 0 0;
  text-align: center;
}

.more-wrap button {
  min-width: 160px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 200px;
  padding: var(--s5) var(--s4);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
}

/* ---------- 运输计算 ---------- */
.calculator-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s3);
}

/* 手机下单列顺序：先录入，再结果，最后已录清单 */
.calc-entry-panel {
  order: 1;
}

.calc-result-panel {
  order: 2;
}

.calc-lines-panel {
  order: 3;
}

.calc-entry {
  display: grid;
  gap: var(--s3);
}

.calc-filters,
.calc-values {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
}

.combo {
  position: relative;
}

.suggestions {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

.suggestion {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.suggestion:last-child {
  border-bottom: 0;
}

.suggestion:hover {
  background: var(--surface-2);
}

.suggestion strong {
  font-size: 14px;
}

.suggestion .muted {
  font-size: 12px;
}

.calc-actions {
  display: flex;
  gap: var(--s2);
}

.calc-actions .btn-primary {
  flex: 1;
}

.calc-hint {
  margin: var(--s3) 0 0;
  color: var(--text-3);
  font-size: 12px;
}

/* 底/盖配套提示：固定在视口上端。
   手机上输入法弹出会占据下半屏，内联在录入区下方会被遮住、点不到按钮，
   所以做成顶部浮层；桌面同样适用，不打断布局。 */
.companion-prompt {
  position: fixed;
  top: calc(var(--header-h) + env(safe-area-inset-top) + var(--s2));
  left: var(--s4);
  right: var(--s4);
  z-index: 60;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
  background: var(--accent-weak);
  box-shadow: var(--shadow-2);
  animation: companion-in 0.18s ease-out;
}

.companion-prompt p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.companion-prompt p + p {
  margin-top: 2px;
}

.companion-prompt strong {
  color: var(--accent-ink);
}

.companion-actions {
  display: flex;
  gap: var(--s2);
  margin-top: var(--s2);
}

.companion-actions button {
  flex: 1;
  min-height: var(--tap);
  font-size: 14px;
}

@keyframes companion-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.line-list {
  display: grid;
  gap: var(--s2);
  margin-top: var(--s3);
}

.calc-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s2);
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}

.calc-line strong {
  font-size: 14px;
}

.inline-field {
  display: grid;
  grid-template-columns: auto 84px;
  align-items: center;
  gap: var(--s2);
  color: var(--text-2);
  font-size: 12px;
}

.result-grid {
  display: grid;
  gap: var(--s3);
}

.summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s2);
}

.summary > div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
}

.summary strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- 登录 ---------- */
.auth-screen {
  display: grid;
  place-items: center;
  padding: var(--s5) var(--s4);
}

.auth-panel {
  width: min(420px, 100%);
  padding: var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

.auth-panel h2 {
  font-size: 18px;
}

.auth-panel > p {
  margin: 6px 0 var(--s4);
  color: var(--text-2);
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: var(--s3);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
  margin-top: var(--s1);
}

/* ---------- 后台 ---------- */
.admin-shell {
  display: flex;
  flex-direction: column;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  flex-wrap: wrap;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  padding: var(--s3) var(--s4);
}

.admin-title {
  display: flex;
  align-items: baseline;
  gap: var(--s3);
  flex-wrap: wrap;
}

.admin-title span {
  color: var(--text-2);
  font-size: 12px;
}

.toolbar {
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  padding: 0 var(--s4) var(--s3);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  flex: 1;
  min-height: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.product-list {
  overflow: auto;
  border-bottom: 1px solid var(--line);
}

.list-title {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--s4);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.list-title span {
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.product-item {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 10px var(--s4);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
}

.product-item:hover {
  background: var(--surface-2);
}

.product-item.active {
  background: var(--accent-weak);
  box-shadow: inset 3px 0 0 var(--accent);
}

.product-item strong {
  font-size: 14px;
}

.product-item span {
  color: var(--text-2);
  font-size: 12px;
}

.detail {
  min-width: 0;
  padding: var(--s4);
  background: var(--bg);
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-bottom: var(--s4);
}

.detail-head h2 {
  font-size: 20px;
}

.detail-head p {
  color: var(--text-2);
  font-size: 13px;
}

.columns-4 {
  grid-template-columns: 1fr;
}

/* 表单分组折叠：手机上一屏放不下 14 个字段，把装箱/图片两组收起，
   摘要直接给出关键数字，需要修改时再展开。 */
.form-section {
  margin-top: var(--s4);
  padding-top: var(--s3);
  border-top: 1px solid var(--line);
}

.form-section > summary {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-height: var(--tap);
  cursor: pointer;
  list-style: none;
  font-weight: 500;
}

.form-section > summary::-webkit-details-marker {
  display: none;
}

.form-section > summary::marker {
  content: "";
}

.form-section > summary em {
  flex: 1;
  min-width: 0;
  font-style: normal;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-3);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-section .chev {
  flex: none;
  color: var(--text-3);
  transition: transform 0.15s;
}

.form-section[open] .chev {
  transform: rotate(90deg);
}

.form-section > .form-grid {
  margin-top: var(--s3);
}

.wide {
  grid-column: span 1;
}

.inline-form,
.stock-form {
  display: grid;
  gap: var(--s2);
}

.stock-form {
  grid-template-columns: 1fr;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s3);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: 4px 4px 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
}

.chip button {
  display: grid;
  place-items: center;
  min-height: 28px;
  width: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--danger);
  font-size: 15px;
  line-height: 1;
}

.chip button:hover {
  background: var(--danger-weak);
}

.back-to-list {
  display: none;
  width: 100%;
  min-height: var(--tap);
  margin-bottom: var(--s3);
  padding: 0 var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--accent);
  font-weight: 500;
  text-align: left;
}

/* ---------- 表格 ---------- */
.table {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

th {
  color: var(--text-2);
  font-weight: 500;
  font-size: 12px;
  background: var(--surface-2);
}

td {
  font-variant-numeric: tabular-nums;
}

tbody tr:last-child td {
  border-bottom: 0;
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  z-index: 50;
  left: var(--s4);
  right: var(--s4);
  bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: #1f2a2e;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-2);
}

body.has-bottom-nav .toast {
  bottom: calc(78px + env(safe-area-inset-bottom));
}

/* ---------- 底部导航 ---------- */
.bottom-nav {
  display: none;
  position: fixed;
  z-index: 40;
  left: 0;
  right: 0;
  bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.bnav-item {
  flex: 1;
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 56px;
  padding: 6px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 11px;
}

.bnav-item.active {
  color: var(--accent);
}

body.has-bottom-nav {
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

/* 手机端底部常驻汇总条，仅运输计算页在有数据时显示 */
.calc-bar {
  display: none;
}

.calc-bar b {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---------- 响应式：平板 ---------- */
@media (min-width: 641px) {
  body {
    font-size: 15px;
  }

  .site-header {
    padding: var(--s3) var(--s5);
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  h1 {
    font-size: 18px;
  }

  .view-inner {
    padding: var(--s5) var(--s5) var(--s6);
  }

  .catalog-toolbar {
    grid-template-columns: minmax(240px, 1fr) auto;
    align-items: center;
  }

  .filter-group {
    grid-template-columns: 160px 160px;
  }

  .catalog-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--s3);
  }

  .calculator-layout {
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    grid-template-areas:
      "entry result"
      "lines result";
    align-items: start;
  }

  .calc-entry-panel {
    grid-area: entry;
  }

  .calc-lines-panel {
    grid-area: lines;
  }

  .calc-result-panel {
    grid-area: result;
    position: sticky;
    top: calc(var(--header-h) + var(--s4));
    margin-bottom: 0;
  }

  .summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .split {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .columns-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .wide {
    grid-column: span 2;
  }

  .stock-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stock-form button {
    grid-column: span 2;
  }

  .toolbar {
    grid-template-columns: minmax(240px, 1fr) auto auto;
    align-items: center;
  }

  .toolbar .filter-group {
    grid-template-columns: 140px 140px;
  }

  .toolbar-actions {
    display: flex;
  }
}

/* ---------- 响应式：桌面 ---------- */
@media (min-width: 1025px) {
  .site-header {
    padding: var(--s3) var(--s6);
  }

  .view-inner {
    padding: var(--s6);
  }

  .catalog-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--s4);
  }

  .page-head h2 {
    font-size: 20px;
  }

  .admin-header,
  .toolbar {
    padding-left: var(--s6);
    padding-right: var(--s6);
  }

  .workspace {
    grid-template-columns: 340px minmax(0, 1fr);
    max-width: var(--maxw);
    width: 100%;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-1);
  }

  .product-list {
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }

  .detail {
    padding: var(--s5);
  }

  .columns-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .split {
    gap: var(--s4);
  }

  .stock-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toast {
    left: auto;
    right: var(--s5);
    max-width: 380px;
  }

  table {
    min-width: 0;
  }

  th,
  td {
    white-space: normal;
  }
}

/* ---------- 手机专有：底部导航 + 后台单步切换 ---------- */
@media (max-width: 640px) {
  .site-header .nav-actions {
    display: none;
  }

  .bottom-nav:not(.hidden) {
    display: flex;
  }

  /* 手机是主场景：卡片信息减负，只留型号、图、价格、装箱与外箱 */
  .product-card-body {
    gap: 4px;
    padding: 8px 10px 10px;
  }

  .product-card h3 {
    font-size: 14px;
  }

  .product-card .product-size,
  .product-card .tag-weight {
    display: none;
  }

  .product-card .meta {
    font-size: 11px;
  }

  .product-card .price {
    font-size: 14px;
  }

  .product-image {
    font-size: 16px;
  }

  .chip {
    padding: 2px 2px 2px 10px;
  }

  .chip button {
    width: 32px;
    min-height: 32px;
  }

  .suggestions {
    max-height: min(280px, 45dvh);
    overscroll-behavior: contain;
  }

  /* 表格转卡片，彻底消除横向滚动 */
  .table table,
  .table tbody,
  .table tr,
  .table td {
    display: block;
  }

  .table thead {
    display: none;
  }

  .table tr {
    margin-bottom: var(--s2);
    padding: var(--s1) 0;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface);
  }

  .table tr:last-child {
    margin-bottom: 0;
  }

  .table td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s3);
    padding: 6px 12px;
    border: 0;
    white-space: normal;
    text-align: right;
  }

  .table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--text-3);
    font-size: 12px;
    text-align: left;
  }

  /* 后台：列表与详情单步切换 */
  .back-to-list {
    display: block;
  }

  .admin-shell .detail {
    display: none;
  }

  body.admin-detail-open .product-list {
    display: none;
  }

  body.admin-detail-open .detail {
    display: block;
  }

  .detail {
    padding: var(--s3);
  }

  .detail-head {
    gap: var(--s2);
    margin-bottom: var(--s3);
  }

  .detail-head .btn-primary {
    width: 100%;
  }

  .calc-bar:not(.hidden) {
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: var(--s2);
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(56px + env(safe-area-inset-bottom));
    z-index: 35;
    min-height: 46px;
    padding: 0 var(--s3);
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 0;
    background: var(--surface);
    color: var(--text-2);
    font-size: 12px;
    box-shadow: 0 -2px 10px rgba(16, 32, 28, 0.06);
  }

  .calc-bar b {
    color: var(--text);
    font-size: 15px;
  }

  /* 手机端提示改到顶部，避免与底部导航、汇总条叠在一起 */
  .toast {
    top: calc(var(--header-h) + var(--s2));
    bottom: auto;
    left: var(--s3);
    right: var(--s3);
  }
}

/* 手机上商品表单改两列：短字段（型号/类别/品牌/材质/单位/售价）并排，
   长字段用 .wide 占满整行，14 个字段的纵向长度几乎减半。 */
@media (max-width: 640px) {
  .form-grid.form-2col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s2) var(--s3);
  }

  .form-grid.form-2col .wide {
    grid-column: span 2;
  }
}
