:root {
  --primary: #009688;
  --primary-dark: #007f72;
  --primary-light: #5fb878;
  --header-bg: #23262e;
  --side-bg: #393d49;
  --side-hover: #4a4f5c;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --green: #059669;
  --orange: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}

/* ============ 顶部标题栏 ============ */
.header {
  height: 50px; background: var(--header-bg); color: #fff;
  display: flex; align-items: center; padding: 0 16px;
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
}
.header .logo { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; }
.header .logo .icon {
  width: 28px; height: 28px; background: var(--primary); border-radius: 6px;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.header-date { font-size: 12px; color: rgba(255,255,255,.65); }
.header-btn {
  background: transparent; border: 1px solid rgba(255,255,255,.25); color: rgba(255,255,255,.85);
  padding: 5px 12px; border-radius: 6px; font-size: 12px; cursor: pointer;
  text-decoration: none; transition: all .15s; white-space: nowrap;
}
.header-btn:hover { border-color: var(--primary-light); color: #fff; background: rgba(0,150,136,.25); }
.hamburger { display: none; background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; margin-right: 4px; }

/* ============ 布局 ============ */
.body-wrap { display: flex; padding-top: 50px; min-height: 100vh; }

/* ============ 侧边导航（深色可折叠） ============ */
.sidebar {
  width: 200px; background: var(--side-bg); position: fixed;
  top: 50px; bottom: 0; left: 0; overflow-y: auto;
  padding: 10px 8px; transition: transform .2s;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }
.nav { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.nav-item, .nav-group-title, .nav-sub {
  color: rgba(255,255,255,.7); cursor: pointer; border-radius: 6px; transition: all .15s;
  display: block; width: 100%; text-align: left; border: none; background: none;
  font-family: inherit; font-size: 14px;
}
.nav-item { padding: 11px 14px; font-weight: 500; }
.nav-item:hover { background: var(--side-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-group-title {
  padding: 11px 14px; font-weight: 500; color: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: space-between;
}
.nav-group-title::after { content: "▸"; font-size: 12px; transition: transform .15s; opacity: .6; }
.nav-group.open .nav-group-title::after { transform: rotate(90deg); }
.nav-group-title:hover { background: var(--side-hover); color: #fff; }
.nav-children { display: none; padding: 2px 0 6px; }
.nav-group.open .nav-children { display: block; }
.nav-sub {
  padding: 8px 14px 8px 30px; font-size: 13px; color: rgba(255,255,255,.55);
}
.nav-sub:hover { color: #fff; background: var(--side-hover); }
.nav-sub.active { background: rgba(0,150,136,.35); color: #fff; box-shadow: inset 3px 0 0 var(--primary); border-radius: 0 6px 6px 0; }

/* ============ 主区域 & 多标签 ============ */
.main { flex: 1; margin-left: 200px; display: flex; flex-direction: column; min-width: 0; }
.tab-bar {
  display: flex; align-items: flex-end; gap: 2px; background: #e8ebf0;
  padding: 6px 10px 0; position: sticky; top: 50px; z-index: 40;
  overflow-x: auto; white-space: nowrap; min-height: 38px;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 12.5px; color: #4b5563; cursor: pointer;
  background: #dfe3ea; border-radius: 8px 8px 0 0; border: none; font-family: inherit;
  transition: background .15s; flex-shrink: 0;
}
.tab:hover { background: #eaeef4; }
.tab.active { background: #fff; color: var(--primary); font-weight: 600; }
.tab-close {
  font-size: 11px; color: #9ca3af; width: 15px; height: 15px; line-height: 15px;
  text-align: center; border-radius: 50%; display: inline-block;
}
.tab-close:hover { background: #c9cedb; color: #111; }
.page-content { padding: 18px 20px 30px; }
.page-title { font-size: 19px; font-weight: 700; margin-bottom: 16px; display: flex; align-items: center; gap: 12px; }
.page-title .sub { font-size: 13px; color: var(--text-light); font-weight: 400; }

/* ============ 卡片 & 表格 ============ */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h3 { font-size: 15px; margin-bottom: 14px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--text-light); font-weight: 600; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); }
th.sortable .sort-arrow { display: inline-block; margin-left: 4px; font-size: 10px; color: #bbb; }
th.sortable.active { color: var(--primary); }
th.sortable.active .sort-arrow { color: var(--primary); }
td { padding: 10px; border-bottom: 1px solid #f1f3f7; white-space: nowrap; }
tr:hover td { background: #f8fafa; }
.tbl-wrap { overflow-x: auto; }

/* ============ 按钮 ============ */
.btn {
  padding: 7px 14px; border-radius: 7px; border: 1px solid var(--border); background: #fff;
  cursor: pointer; font-size: 13px; transition: all .15s; white-space: nowrap; font-family: inherit;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ============ 表单 ============ */
label { display: block; font-size: 12px; color: var(--text-light); margin-bottom: 5px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }

/* ============ 状态标签 ============ */
.tag { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.tag.s-wait   { background: #fef3c7; color: #b45309; }
.tag.s-ready  { background: #d1f2ee; color: #007f72; }
.tag.s-ship   { background: #ede9fe; color: #6d28d9; }
.tag.s-done   { background: #d1fae5; color: #047857; }
.tag.s-cancel { background: #fee2e2; color: #b91c1c; }
.tag.warn { background: #fee2e2; color: var(--danger); }
.tag.ok   { background: #d1fae5; color: var(--green); }

.dev-tag { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; background: #f3f4f6; color: #4b5563; }
.dev-tag.dev-0 { background: #fef3c7; color: #b45309; }
.dev-tag.dev-1 { background: #dbeafe; color: #1d4ed8; }
.dev-tag.dev-2 { background: #ede9fe; color: #6d28d9; }
.dev-tag.dev-3 { background: #d1fae5; color: #047857; }
.dev-tag.dev-4 { background: #fee2e2; color: #b91c1c; }

/* ============ KPI 卡片 ============ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 18px; }
.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.kpi .label { font-size: 12px; color: var(--text-light); margin-bottom: 8px; }
.kpi .value { font-size: 24px; font-weight: 700; }
.kpi .trend { font-size: 12px; margin-top: 6px; }
.up { color: var(--danger); }   /* 中国市场惯例: 涨红 */
.down { color: var(--green); }  /* 跌绿 */

/* ============ 图表区域 ============ */
.chart-row { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; margin-bottom: 18px; }
@media (max-width: 1000px) { .chart-row { grid-template-columns: 1fr; } }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100;
  display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 14px; width: 640px; max-width: 100%;
  padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal.wide { width: 1032px; }
.modal h3 { font-size: 16px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; }
.modal .close { cursor: pointer; font-size: 20px; color: var(--text-light); background: none; border: none; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* 明细表格 */
.item-table td { padding: 6px 4px; }
.item-table input, .item-table select { padding: 6px 8px; width: 100%; box-sizing: border-box; }
.item-table input[type="number"]::-webkit-inner-spin-button,
.item-table input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none; margin: 0;
}
.item-table input[type="number"] { -moz-appearance: textfield; }
.item-table .del { color: var(--danger); cursor: pointer; background: none; border: none; font-size: 16px; }

/* 隐藏数字输入框的增减按钮 */
.no-spin::-webkit-outer-spin-button,
.no-spin::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.no-spin { -moz-appearance: textfield; }

/* 明细列宽（按新顺序：名称/颜色/克重/门幅/数量/单位/货币/供应商/销售单价/销售放样费/采购单价/采购放样费/小计/删除） */
.item-table th:nth-child(1), .item-table td:nth-child(1) { width: 84px; }   /* 名称：缩小30% */
.item-table th:nth-child(2), .item-table td:nth-child(2) { width: 66px; min-width: 66px; }   /* 款号：再加宽10% */
.item-table td:nth-child(2) input.f-color { min-width: 66px; }
.item-table th:nth-child(3), .item-table td:nth-child(3),
.item-table th:nth-child(4), .item-table td:nth-child(4) { width: 84px; }   /* 克重/门幅：拉长20% */
.item-table th:nth-child(5), .item-table td:nth-child(5) { width: 70px; }   /* 数量 */
.item-table th:nth-child(6), .item-table td:nth-child(6) { width: 70px; }   /* 单位 */
.item-table th:nth-child(7), .item-table td:nth-child(7) { width: 60px; }   /* 货币 */
.item-table th:nth-child(8), .item-table td:nth-child(8) { width: 112px; }  /* 供应商：缩小20% */
.item-table th:nth-child(9), .item-table td:nth-child(9),
.item-table th:nth-child(10), .item-table td:nth-child(10),
.item-table th:nth-child(11), .item-table td:nth-child(11),
.item-table th:nth-child(12), .item-table td:nth-child(12) { width: 70px; } /* 销售单价/销售放样费/采购单价/采购放样费 */

/* 小计：金额 */
.item-table td.f-amount { vertical-align: middle; }
.f-amount .amount-main { font-weight: 600; }

/* 订单列表备注列 */
.tbl-wrap table th:nth-child(10),
.tbl-wrap table td:nth-child(10) { width: 120px; max-width: 180px; white-space: normal; word-break: break-all; }

/* 出运列表品名 */
td.ship-product { white-space: normal; vertical-align: middle; }
td.ship-product > div { line-height: 1.5; }

/* 出运货物明细 */
.ship-item-table th:nth-child(1), .ship-item-table td:nth-child(1) { width: 130px; }  /* 品名 REF */
.ship-item-table th:nth-child(2), .ship-item-table td:nth-child(2) { width: 70px; }   /* ART# */
.ship-item-table th:nth-child(3), .ship-item-table td:nth-child(3) { width: 70px; }   /* 数量 */
.ship-item-table th:nth-child(4), .ship-item-table td:nth-child(4) { width: 56px; }   /* 卷数 */
.ship-item-table th:nth-child(5), .ship-item-table td:nth-child(5) { width: 48px; }   /* 货币 */
.ship-item-table th:nth-child(6), .ship-item-table td:nth-child(6) { width: 70px; }   /* 单价 */
.ship-item-table th:nth-child(7), .ship-item-table td:nth-child(7) { width: 80px; }   /* 总价 */
.ship-item-table th:nth-child(8), .ship-item-table td:nth-child(8),
.ship-item-table th:nth-child(9), .ship-item-table td:nth-child(9),
.ship-item-table th:nth-child(10), .ship-item-table td:nth-child(10) { width: 62px; }  /* 毛重/净重/体积 */
.ship-item-table th:nth-child(11), .ship-item-table td:nth-child(11) { width: 90px; }  /* 备注 */
.ship-item-table input, .ship-item-table th, .ship-item-table td { font-size: 12px; padding: 5px 6px; }
.ship-item-table input[readonly] { background: #f9fafb; color: var(--text-light); }
.ship-item-table td:nth-child(5) { padding: 4px; }
.ship-item-table td:nth-child(5) select.si-currency { width: 100%; padding: 4px; font-size: 12px; }

/* ============ 发票 / 装箱单预览（仿模版） ============ */
.doc-preview {
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  padding: 26px 34px; font-family: Calibri, 'PingFang SC', 'Segoe UI', sans-serif;
  color: #111; max-height: 68vh; overflow: auto; margin-top: 6px;
}
.doc-co { text-align: center; font-size: 22px; font-weight: 700; letter-spacing: .5px; }
.doc-addr { text-align: center; font-size: 11px; font-weight: 700; margin-top: 2px; }
.doc-title { text-align: center; font-size: 22px; font-weight: 700; margin: 16px 0 18px; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; font-size: 13px; align-items: flex-start; }
.doc-to { line-height: 1.7; }
.doc-meta { border-collapse: collapse; font-size: 12px; }
.doc-meta td { padding: 1px 4px; }
.doc-desc { font-size: 10px; font-weight: 700; margin: 14px 0 2px; }
.doc-items { border-collapse: collapse; width: 100%; margin-top: 4px; table-layout: fixed; }
.doc-items th, .doc-items td { border: 1px solid #111; padding: 5px 8px; font-size: 12.5px; text-align: center; }
.doc-items th { font-weight: 700; vertical-align: bottom; }
.doc-items th.u { text-decoration: underline; }
.doc-items .doc-gap td { border: none; height: 10px; padding: 0; }
.doc-items .doc-total-row td { border: none; font-weight: 700; }
.doc-items td.left, .doc-items th.left { text-align: left; }
.doc-items td.right { text-align: right; }
.doc-items .bold, .doc-foot .bold { font-weight: 700; }
.doc-foot { margin-top: 16px; font-size: 12.5px; line-height: 2; }
.doc-foot .doc-sum { padding-left: 4px; }

/* 搜索栏 */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

/* 空状态 */
.empty { text-align: center; color: var(--text-light); padding: 40px 0; }

/* Toast */
#toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 10px 20px; border-radius: 8px;
  z-index: 999; display: none; font-size: 13px;
}
#toast.err { background: var(--danger); }

.amount { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.text-light { color: var(--text-light); }
.mt { margin-top: 14px; }
.detail-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; font-size: 13px; }
.detail-rows .k { color: var(--text-light); }
section.sub { margin-top: 18px; }
section.sub h4 { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }

a.ord-link, a.ship-link { color: var(--primary); font-weight: 600; text-decoration: none; }

/* ============ 手机 / 平板适配（抽屉式侧栏） ============ */
@media (max-width: 768px) {
  .hamburger { display: block; }
  .header .logo div:last-child { font-size: 14px; }
  .header-date { display: none; }

  .sidebar { transform: translateX(-100%); z-index: 80; box-shadow: 4px 0 20px rgba(0,0,0,.25); }
  body.drawer-open .sidebar { transform: translateX(0); }
  body.drawer-open::after {
    content: ""; position: fixed; inset: 0; top: 50px; background: rgba(0,0,0,.35); z-index: 70;
  }
  .main { margin-left: 0; }
  .page-content { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 17px; margin-bottom: 12px; flex-wrap: wrap; }
  .tab-bar { top: 50px; padding: 5px 8px 0; }

  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .value { font-size: 19px; }

  .modal-mask { padding: 16px 10px; align-items: center; }
  .modal { width: 100%; padding: 16px 14px; border-radius: 12px; }
  .modal.wide { width: 100%; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .detail-rows { grid-template-columns: 1fr; }

  .tbl-wrap { -webkit-overflow-scrolling: touch; }
  td, th { padding: 8px; }
  .item-table input, .item-table select { padding: 5px 6px; min-width: 64px; }
  .toolbar input, .toolbar select { min-width: 120px; flex: 1; }
  .toolbar .btn { flex: 1; text-align: center; }
}

@media (max-width: 380px) {
  .form-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ============ 订单操作列按钮分色 ============ */
.btn.op-detail { color: #3b82f6; border-color: #bfdbfe; }
.btn.op-detail:hover { background: #3b82f6; border-color: #3b82f6; color: #fff; }
.btn.op-edit { color: #009688; border-color: #8fdcd5; }
.btn.op-edit:hover { background: #009688; border-color: #009688; color: #fff; }
.btn.op-cancel { color: #f59e0b; border-color: #fde68a; }
.btn.op-cancel:hover { background: #f59e0b; border-color: #f59e0b; color: #fff; }
.btn.op-del { color: var(--danger); }
.btn.op-del:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

/* 状态选择框按状态分色 */
select.st-select { border: none; color: #fff; }
select.st-select:hover { color: #fff; }
select.st-select.s-wait { background: #f59e0b; }
select.st-select.s-wait:hover { background: #d97706; }
select.st-select.s-ready { background: #3b82f6; }
select.st-select.s-ready:hover { background: #2563eb; }
select.st-select.s-ship { background: #8b5cf6; }
select.st-select.s-ship:hover { background: #7c3aed; }
select.st-select.s-done { background: #10b981; }
select.st-select.s-done:hover { background: #059669; }
select.st-select.s-cancel { background: #94a3b8; }
select.st-select.s-cancel:hover { background: #64748b; }

/* ============ 报关单预览 ============ */
.customs-preview { font-family: 'SimSun', '宋体', serif; font-size: 11px; color: #000; }
.cb-title { text-align: center; font-size: 19px; font-weight: 700; margin: 8px 0 14px; letter-spacing: 2px; }
.cb-ids { display: flex; justify-content: space-between; font-size: 11px; font-weight: 700; border-bottom: 1.5px solid #000; padding: 0 2px 2px; }
.cb-band { display: flex; border-left: 1.5px solid #000; border-right: 1.5px solid #000; border-bottom: 1.5px solid #000; }
.cb-cell { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.cb-cell .cb-label { border-bottom: 1px solid #000; padding: 2px 4px; font-weight: 700; white-space: nowrap; }
.cb-cell .cb-value { padding: 3px 4px; min-height: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-5 .cb-cell:nth-child(1) { flex: 2.2; }
.cb-8 .cb-cell:nth-child(1) { flex: 2.2; }
.cb-8 .cb-cell:nth-child(5) { flex: .8; }
.cb-label-row { border-left: 1.5px solid #000; border-right: 1.5px solid #000; border-bottom: 1px solid #000; padding: 3px 4px; font-weight: 700; }
.cb-marks { border-left: 1.5px solid #000; border-right: 1.5px solid #000; border-bottom: 1.5px solid #000; padding: 6px 4px 26px; }
.cb-det-head { border: 1.5px solid #000; border-bottom: none; padding: 4px; font-weight: 700; white-space: nowrap; overflow: hidden; }
.cb-items { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cb-items td { border: none; padding: 4px 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cb-items td:first-child, .cb-items td:last-child { border-left: 1.5px solid #000; }
.cb-items td:first-child { border-right: 1px solid #000; width: 5%; }
.cb-items td:nth-child(2) { width: 10%; border-right: 1px solid #000; }
.cb-items td:nth-child(3) { width: 28%; }
.cb-items td:nth-child(4) { width: 11%; }
.cb-items td:nth-child(5) { width: 12%; }
.cb-items td:nth-child(6) { width: 8%; }
.cb-items td:nth-child(7) { width: 10%; }
.cb-items td:nth-child(8) { width: 11%; }
.cb-items tr:last-child td, .cb-items tr.cb-empty td { border-bottom: 1.5px solid #000; }
.cb-empty td { height: 40px; }
.cb-foot-1 { border-left: 1.5px solid #000; border-right: 1.5px solid #000; border-bottom: 1px solid #000; padding: 5px 4px; }
.cb-foot-2 { border-left: 1.5px solid #000; border-right: 1.5px solid #000; border-bottom: 1px solid #000; padding: 5px 4px; min-height: 44px; }
.cb-foot-3 { display: flex; border: 1.5px solid #000; }
.cb-foot-3 span { padding: 5px 4px 26px; }
.cb-foot-3 .cb-stamp { flex: 1; border-left: 1.5px solid #000; }

/* 订单完成自动归档分隔线 */
.order-archive-divider td { padding: 12px 8px 7px; border: 0; background: #f8fafc; color: #64748b; font-size: 12px; font-weight: 700; }
.order-archive-divider span { display: inline-flex; align-items: center; gap: 8px; }
.order-archive-divider span::before { content: ''; display: inline-block; width: 4px; height: 14px; border-radius: 3px; background: #10b981; }
.completed-order { background: #fbfdfc; }
.completed-order td { color: #64748b; }
.completed-order .ord-link { color: #64748b !important; }
