:root {
  color-scheme: light;
  --primary: #2f6fed;
  --text: #263140;
  --muted: #697586;
  --line: #e5e7eb;
  --surface: #fff;
  --background: #f5f6f8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--text);
  background: var(--background);
  -webkit-text-size-adjust: 100%;
}
body.drawer-open { overflow: hidden; }
button, input, select { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid rgba(47, 111, 237, 0.28);
  outline-offset: 2px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
header h1 { margin: 0; font-size: 19px; }
.health { color: var(--muted); font-size: 12px; text-align: right; }
#tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
#tabs button {
  min-height: 42px;
  border: none;
  background: none;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  color: #555;
  border-bottom: 2px solid transparent;
}
#tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
main { padding: 16px 24px 40px; max-width: 1200px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.filter-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.filter-group { display: flex; align-items: center; gap: 6px; }
.group-label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.filters input, .filters select {
  min-width: 0;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}
.filter-group input[type="date"] { width: 138px; }
.filter-search { flex: 0 1 190px; min-width: 0; }
.order-no-input { width: 150px; }
.filters select { width: auto; max-width: 200px; }
/* 客户下拉存的是全名（可到 16 字），状态只有几个字，两者宽度分开给 */
#f-customer, #s-customer { max-width: 248px; }
.filters button {
  min-height: 34px;
  padding: 5px 16px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
}
.filters button.ghost { background: #fff; color: var(--primary); }
/* 快捷查询胶囊 */
.quick-row { gap: 6px; }
.quick-label { color: var(--muted); font-size: 12px; white-space: nowrap; margin-right: 2px; }
.filters .chip {
  min-height: 28px;
  padding: 3px 11px;
  border: 1px solid #dde3ec;
  border-radius: 999px;
  background: #fff;
  color: #4b5563;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: nowrap;
}
.filters .chip:hover { border-color: var(--primary); color: var(--primary); }
.filters .chip.active {
  border-color: var(--primary);
  background: #eaf1ff;
  color: #1f4fae;
  font-weight: 600;
}
.filters .link-btn {
  min-height: 28px;
  margin-left: 2px;
  padding: 2px 6px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.filters .link-btn:hover { color: var(--primary); }
.sep { color: #9aa4b2; font-size: 12px; }
.table-scroll {
  overflow-x: auto;
  background: var(--surface);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}
table { width: 100%; min-width: 880px; border-collapse: collapse; background: var(--surface); border-radius: 8px; overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #eef0f3; font-size: 13px; }
th { background: #fafbfc; color: #666; font-weight: 600; white-space: nowrap; }
/* 单号/日期/状态不允许折行：客户名放长后若被压缩，这几列会被拆成两行很难看 */
td.nowrap { white-space: nowrap; }
/* 客户列完整展示（不截断成省略号），过长时在列内折行；
   min-width 防止表格变窄时被压成「每行 3-4 个字」的竖排 */
td.col-customer { min-width: 150px; max-width: 200px; line-height: 1.45; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.items-col {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #555;
}
td.items-col.muted { color: #aaa; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f0f5ff; }
.order-list { display: none; }
.empty { text-align: center; color: #999; padding: 24px; }
.err { color: #c0392b; }
.badge {
  display: inline-block;
  max-width: 100%;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 12px;
  background: #eef0f3;
  color: #555;
  overflow-wrap: anywhere;
}
.badge.warn { background: #fff3e0; color: #9a5b00; }
.badge.info { background: #e3efff; color: #2f6fed; }
.badge.ok { background: #e6f6ec; color: #1e8e4e; }
.badge.muted { background: #f0f0f0; color: #999; text-decoration: line-through; }
.pager {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 12px;
  font-size: 13px;
  color: #666;
}
.pager span { font-variant-numeric: tabular-nums; }
.pager button {
  min-height: 34px;
  padding: 5px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.pager button:disabled { opacity: 0.4; cursor: default; }
#drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.36);
  z-index: 40;
}
#drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(820px, 94vw);
  background: #fff;
  z-index: 41;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
}
#drawer.hidden, #drawer-mask.hidden { display: none; }
.drawer-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 17px; overflow-wrap: anywhere; }
.drawer-kicker { margin: 0 0 2px; color: var(--muted); font-size: 12px; }
#d-close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #f3f4f6;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
  color: #666;
}
#d-body { padding: 16px 20px calc(20px + env(safe-area-inset-bottom)); }
.d-meta { background: #f7f8fa; border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.d-meta p { margin: 4px 0; }
.d-customer span, .d-meta-grid span { display: block; color: var(--muted); font-size: 12px; }
.d-customer b { font-size: 16px; }
.d-meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.d-meta-grid strong { display: block; margin-top: 2px; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.d-note { color: #999; font-size: 12px; margin-top: 14px; }
/* 抽屉商品明细：行式卡片，一屏铺开品名/编码/型号规格货位+数量，不横向滚动（不含金额，发货岗不需要） */
.d-items-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 2px 8px;
  color: #33405a;
  font-size: 13px;
  font-weight: 600;
}
.d-items-head .details-count { color: var(--muted); font-size: 12px; font-weight: 500; }
.d-items { display: grid; gap: 8px; }
.d-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(88px, auto);
  align-items: center;
  gap: 6px 16px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid #e5eaf3;
  border-radius: 9px;
}
.d-item-main { min-width: 0; }
.d-item-name { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
/* 同单同商品多行时的行序号（1/2、2/2），避免两行看起来一模一样 */
.dup-tag {
  display: inline-block;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 4px;
  background: #eaf1ff;
  color: #1f4fae;
  font-size: 11px;
  font-weight: 600;
  vertical-align: 1px;
  font-variant-numeric: tabular-nums;
}
.d-item-sub { display: flex; flex-wrap: wrap; gap: 2px 10px; margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.d-item-code { color: #5b7bb5; font-variant-numeric: tabular-nums; }
.d-item-sub .is-empty { color: #c2cad8; }
.d-item-cell { text-align: right; white-space: nowrap; }
.d-item-cell span { display: block; color: var(--muted); font-size: 11px; }
.d-item-cell b { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.d-item-cell i { margin-left: 4px; color: var(--muted); font-size: 12px; font-style: normal; }
.mobile-items { display: none; }
.detail-loading { padding: 28px 12px; color: var(--muted); text-align: center; }
.detail-error { padding: 16px; color: #b42318; background: #fff4f2; border-radius: 8px; text-align: center; }
.detail-error button {
  display: block;
  min-height: 38px;
  margin: 10px auto 0;
  padding: 6px 16px;
  border: 1px solid currentColor;
  border-radius: 6px;
  background: #fff;
  color: inherit;
  cursor: pointer;
}
.footnote { text-align: center; color: #aaa; font-size: 12px; padding: 16px 16px 24px; }

/* 中等宽度（笔记本 1024~1200）：客户全名要占位，把摘要/商品列收窄，
   否则浏览器会从客户列抢宽度，把公司名压成一列一个字 */
@media (max-width: 1200px) {
  td.items-col { max-width: 160px; }
}

@media (max-width: 720px) {
  body { font-size: 15px; }
  header { flex-direction: column; gap: 3px; align-items: flex-start; padding: 14px 16px 12px; }
  header h1 { font-size: 20px; }
  .health { font-size: 12px; text-align: left; }
  #tabs { position: sticky; top: 0; z-index: 20; padding: 0 12px; }
  #tabs button { flex: 1; min-height: 46px; padding: 10px 12px; font-size: 15px; }
  main { padding: 12px 12px 28px; }
  .filters { gap: 8px; padding: 10px; margin-bottom: 10px; }
  .quick-row {
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .quick-row::-webkit-scrollbar { display: none; }
  .quick-label { display: none; }
  .filters .chip { flex: 0 0 auto; min-height: 34px; padding: 5px 12px; font-size: 13px; }
  .filters .link-btn { flex: 0 0 auto; min-height: 34px; padding: 5px 8px; font-size: 13px; }
  .filter-group { flex: 1 1 100%; min-width: 0; gap: 4px; }
  .filter-group .group-label { flex: 0 0 auto; font-size: 12px; }
  .filter-group input[type="date"] { flex: 1 1 0; width: auto; min-width: 0; padding: 8px 6px; font-size: 15px; }
  .filter-search, .filters select { flex: 1 1 calc(50% - 4px); width: auto; max-width: none; min-width: 0; }
  .filters .order-no-input { flex: 1 1 auto; width: auto; min-width: 0; }
  .filter-row-bottom { gap: 8px; }
  .filters input, .filters select { width: auto; min-height: 42px; padding: 8px 10px; font-size: 16px; }
  .filters button { min-height: 42px; font-size: 15px; }
  .tab > .table-scroll { display: none; }
  .order-list { display: grid; gap: 12px; }
  .order-card {
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
  }
  .order-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px 14px 0; }
  .order-ident { min-width: 0; }
  .order-label, .order-summary > span { display: block; color: var(--muted); font-size: 12px; }
  .order-no { display: block; margin-top: 1px; font-size: 15px; overflow-wrap: anywhere; }
  .order-customer { margin: 10px 14px 0; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
  .order-tags { margin: 7px 14px 0; }
  .order-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 14px 0; padding: 10px; background: #f7f8fa; border-radius: 8px; }
  .order-facts dt { color: var(--muted); font-size: 12px; }
  .order-facts dd { margin: 2px 0 0; font-size: 14px; font-variant-numeric: tabular-nums; }
  .order-summary { margin: 12px 14px 0; }
  .order-summary p {
    display: -webkit-box;
    margin: 4px 0 0;
    overflow: hidden;
    color: #4b5563;
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
  .detail-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 46px;
    margin-top: 12px;
    padding: 10px 14px;
    border: none;
    border-top: 1px solid #e8eefb;
    background: #f8faff;
    color: var(--primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }
  .detail-toggle:disabled { cursor: wait; opacity: 0.7; }
  .detail-toggle[aria-expanded="true"] { background: #e7efff; border-top-color: #cddffb; }
  .chevron {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    margin-top: -4px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.18s ease;
  }
  .detail-toggle[aria-expanded="true"] .chevron { margin-top: 4px; transform: rotate(-135deg); }
  .inline-details {
    margin-top: 12px;
    padding: 12px;
    background: #e7efff;
    border-top: 1px solid #cddffb;
    box-shadow: inset 3px 0 0 var(--primary);
  }
  .inline-details[hidden] { display: none; }
  .inline-details-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin: 0 0 10px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.2px;
  }
  .inline-details-head .details-count { color: #5b7bb5; font-size: 12px; font-weight: 500; }
  .mobile-items { display: grid; gap: 10px; }
  .mobile-item { padding: 12px; background: #fff; border: 1px solid #e5eaf3; border-radius: 9px; }
  .mobile-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
  .mobile-item-head h3 { margin: 0; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
  .item-qty { flex: 0 0 auto; display: inline-flex; align-items: baseline; gap: 3px; padding: 2px 8px; border-radius: 6px; background: #eaf1ff; color: #1f4fae; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .item-qty .qty-label { font-size: 12px; font-weight: 500; color: #5b7bb5; }
  .item-qty .qty-unit { font-size: 12px; font-weight: 500; color: #5b7bb5; }
  .item-code { margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
  .item-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; margin: 10px 0 0; }
  .item-facts dt { color: var(--muted); font-size: 12px; }
  .item-facts dd { margin: 1px 0 0; font-size: 14px; overflow-wrap: anywhere; }
  .pager { justify-content: space-between; gap: 6px; font-size: 12px; }
  .pager span { flex: 1; text-align: center; }
  .pager button { min-height: 42px; padding: 7px 12px; font-size: 13px; }
  #drawer-mask { background: rgba(15, 23, 42, 0.48); }
  #drawer {
    top: auto;
    left: 0;
    width: 100%;
    height: 92vh;
    height: 92dvh;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(15, 23, 42, 0.18);
    animation: sheet-in 0.2s ease-out;
  }
  .drawer-head { padding: calc(18px + env(safe-area-inset-top)) 16px 12px; }
  .drawer-head h2 { font-size: 16px; }
  #d-close { width: 44px; height: 44px; }
  #d-body { padding: 14px 14px calc(20px + env(safe-area-inset-bottom)); }
  .d-meta { padding: 12px; }
  .d-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* 窄屏：品名占整行，数量单独一行（不展示单价金额） */
  .d-item { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; }
  .d-item-main { grid-column: 1 / -1; }
  .d-item-cell { text-align: left; }
  .d-item-cell span { display: inline; margin-right: 4px; }
  .footnote { padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); }
}

@media (max-width: 360px) {
  main { padding-right: 8px; padding-left: 8px; }
  .order-card-top { gap: 8px; }
  .order-no { font-size: 14px; }
  .item-facts { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0.7; }
  to { transform: translateY(0); opacity: 1; }
}
