:root {
  --primary: #1e40af;
  --primary-soft: #eff6ff;
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --ok: #059669;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "PingFang SC", "Hiragino Sans GB", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #1d4ed8 100%); }
.login-box { background: #fff; width: 380px; padding: 38px 34px; border-radius: 14px; box-shadow: 0 20px 40px rgba(15,23,42,.3); }
.login-box h1 { font-size: 22px; margin-bottom: 6px; }
.login-box .sub { color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.login-box label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login-box input { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; outline: none; }
.login-box input:focus { border-color: var(--primary); }
.login-box button { width: 100%; margin-top: 22px; padding: 12px; background: var(--primary); color: #fff;
  border: none; border-radius: 8px; font-size: 15px; cursor: pointer; }
.login-box .err { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }
.login-box .langs { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 8px; }
.login-box .langs button { width: auto; margin: 0; padding: 4px 10px; background: #f1f5f9; color: var(--muted); font-size: 12px; }
.login-box .langs button.on { background: var(--primary-soft); color: var(--primary); }

/* ---------- 主框架 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 216px; background: #0f172a; color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { padding: 22px 20px 18px; font-size: 16px; font-weight: 700; color: #fff; letter-spacing: .5px; }
.brand small { display: block; font-size: 11px; color: #64748b; font-weight: 400; margin-top: 4px; letter-spacing: 1px; }
.nav { padding: 8px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 8px; color: #cbd5e1;
  font-size: 14px; margin-bottom: 2px; cursor: pointer; }
.nav a:hover { background: #1e293b; color: #fff; }
.nav a.on { background: var(--primary); color: #fff; }
.nav .badge { margin-left: auto; background: #dc2626; color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 9px; }
.side-foot { padding: 14px 16px; border-top: 1px solid #1e293b; font-size: 12px; color: #64748b; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 58px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center;
  padding: 0 22px; gap: 14px; }
.topbar .title { font-size: 17px; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.topbar .role { background: var(--primary-soft); color: var(--primary); padding: 3px 9px; border-radius: 20px; font-size: 12px; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 6px 10px; cursor: pointer; color: var(--muted); }
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }

.content { padding: 20px 22px 40px; }

/* ---------- 卡片 / 表格 ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border-radius: var(--radius); padding: 16px 18px; border: 1px solid var(--line); cursor: pointer; }
.stat:hover { border-color: #bfdbfe; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat.warn .n { color: var(--warn); }
.stat.danger .n { color: var(--danger); }
.stat.ok .n { color: var(--ok); }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.panel-h { padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.panel-h h3 { font-size: 15px; font-weight: 600; }
.panel-h .spacer { flex: 1; }
.panel-b { padding: 0; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 500; padding: 10px 12px;
  background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tbody tr:hover { background: #f8fafc; }
tr.clickable { cursor: pointer; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.empty { padding: 34px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.s-pending_confirm { background: #fef3c7; color: #92400e; }
.s-confirmed { background: #dbeafe; color: #1e40af; }
.s-shipped { background: #ede9fe; color: #5b21b6; }
.s-delivering { background: #cffafe; color: #0e7490; }
.s-delivered { background: #dcfce7; color: #166534; }
.s-cancelled { background: #f1f5f9; color: #475569; }
.s-returned { background: #fee2e2; color: #991b1b; }
.h-unassigned { background: #f1f5f9; color: #475569; }
.h-assigned { background: #e0e7ff; color: #3730a3; }
.h-following { background: #d1fae5; color: #065f46; }
.h-duplicate { background: #fee2e2; color: #991b1b; }
.h-invalid { background: #f3f4f6; color: #6b7280; }
.due-soon { color: var(--warn); font-weight: 600; }
.due-over { color: var(--danger); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); align-items: center; }
.toolbar input, .toolbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.toolbar input[type=search] { min-width: 220px; }
.btn { padding: 8px 14px; border-radius: 7px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--text); }
.btn:hover { border-color: #cbd5e1; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.bulkbar { display: none; padding: 10px 16px; background: var(--primary-soft); border-bottom: 1px solid #bfdbfe;
  align-items: center; gap: 10px; font-size: 13px; }
.bulkbar.on { display: flex; }

.pagebar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; justify-content: flex-end; color: var(--muted); font-size: 13px; }

/* ---------- 抽屉 ---------- */
.drawer-mask { position: fixed; inset: 0; background: rgba(15,23,42,.35); opacity: 0; pointer-events: none;
  transition: opacity .18s; z-index: 40; }
.drawer-mask.on { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; width: 620px; max-width: 92vw; height: 100%; background: #fff;
  transform: translateX(100%); transition: transform .22s; z-index: 50; display: flex; flex-direction: column; }
.drawer.on { transform: translateX(0); }
.drawer-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.drawer-h .spacer { flex: 1; }
.drawer-b { overflow-y: auto; padding: 18px 20px 40px; flex: 1; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 10px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { word-break: break-word; }
.section-t { font-size: 13px; font-weight: 600; color: var(--muted); margin: 22px 0 10px; text-transform: uppercase; letter-spacing: .6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.timeline { border-left: 2px solid var(--line); padding-left: 14px; display: flex; flex-direction: column; gap: 12px; }
.tl-item { position: relative; font-size: 13px; }
.tl-item::before { content: ""; position: absolute; left: -20px; top: 4px; width: 8px; height: 8px;
  border-radius: 50%; background: #cbd5e1; }
.tl-item.ok::before { background: var(--ok); }
.tl-item .t { color: var(--muted); font-size: 12px; }
.note-box { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-height: 72px; resize: vertical; }

/* ---------- 弹窗 ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.4); display: none; align-items: center; justify-content: center; z-index: 60; }
.modal-mask.on { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 420px; max-width: 92vw; padding: 22px; }
.modal h3 { font-size: 16px; margin-bottom: 16px; }
.modal .row { margin-bottom: 12px; }
.modal label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.modal input, .modal select, .modal textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 7px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal .foot .spacer { flex: 1; }
.modal.wide { width: 560px; }
.modal label.perm-row { display: grid; grid-template-columns: 20px minmax(120px,1fr) auto 64px;
            gap: 10px; align-items: center; padding: 7px 0; font-size: 14px; color: var(--text); margin: 0; }
.modal label.perm-row input[type=checkbox] { width: 16px; height: 16px; margin: 0; }
.modal label.perm-row .pl { white-space: nowrap; }
.modal label.perm-row .pk { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.modal label.perm-row .pb { font-size: 11px; color: var(--muted); text-align: right; }
.topbar .user { cursor: pointer; border-radius: 8px; padding: 4px 6px; }
.topbar .user:hover { background: #f1f5f9; }

/* ---------- 统计 ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding: 14px 16px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; justify-content: flex-end; }
.bars .b i { display: block; width: 100%; background: #93c5fd; border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b span { font-size: 11px; color: var(--muted); }

/* ---------- 导入 ---------- */
.drop { border: 2px dashed #cbd5e1; border-radius: 12px; padding: 34px; text-align: center; color: var(--muted);
  background: #fff; cursor: pointer; }
.drop:hover { border-color: var(--primary); color: var(--primary); }
.import-sum { display: flex; gap: 22px; padding: 14px 16px; font-size: 13.5px; }
.chip { background: #f1f5f9; border-radius: 6px; padding: 4px 8px; font-size: 12px; }

@media (max-width: 900px) {
  .sidebar { width: 62px; }
  .brand { font-size: 0; padding: 16px 8px; }
  .nav a span { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---- 角色下拉（自绘，替代原生外观） ---- */
.btn.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn.ghost:hover { color: var(--text); background: #f1f5f9; border-color: transparent; }

.sel-wrap { position: relative; display: inline-flex; align-items: center; }
.sel-wrap select { appearance: none; -webkit-appearance: none; -moz-appearance: none;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
  font-size: 13.5px; font-family: inherit; line-height: 1.2;
  padding: 6px 28px 6px 12px; cursor: pointer; min-width: 104px;
  transition: border-color .15s, box-shadow .15s, background .15s; }
.sel-wrap select:hover { border-color: #cbd5e1; }
.sel-wrap select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.sel-wrap .chev { position: absolute; right: 9px; width: 12px; height: 12px; pointer-events: none;
  color: var(--muted); }
.sel-wrap.r-admin    select { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.sel-wrap.r-analyst  select { background: #ecfeff; border-color: #a5f3fc; color: #0e7490; }
.sel-wrap.r-importer select { background: #f5f3ff; border-color: #ddd6fe; color: #6d28d9; }
.sel-wrap.r-agent    select { background: #ecfdf5; border-color: #bbf7d0; color: #047857; }

/* ---- 启用开关 ---- */
.switch { display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 38px; height: 22px; border-radius: 11px; background: #e2e8f0;
  display: inline-block; position: relative; transition: background .18s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(15,23,42,.25); transition: transform .18s; }
.switch input:checked + .track { background: #22c55e; }
.switch input:checked + .track .knob { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.switch.is-self { cursor: not-allowed; opacity: .45; }

/* ---- 导入列识别 ---- */
.cm-box { margin:14px 18px 0; padding:12px 14px; background:#f8fafc; border:1px solid #eef2f7; border-radius:10px; }
.cm-head { font-size:13px; color:#475569; margin-bottom:9px; }
.cm-head .bad-t { color:#b91c1c; }
.cm-list { display:flex; flex-wrap:wrap; gap:6px; }
.cm { font-size:12px; color:#334155; background:#fff; border:1px solid #e2e8f0; border-radius:6px;
      padding:3px 8px; white-space:nowrap; }
.cm i { font-style:normal; color:#94a3b8; margin-left:5px; font-family:Consolas,monospace; font-size:11px; }
.cm.bad { background:#fef2f2; border-color:#fecaca; color:#991b1b; }

/* ---- 订单编辑表单 ---- */
.ef-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.ef-full { margin-top: 10px; }
.modal .ef label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.modal .ef input { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px; }
.modal .ef input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
@media (max-width: 640px) { .ef-grid { grid-template-columns: 1fr; } }
