:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1a1f2e;
  --text-muted: #6b7280;
  --primary: #1d5bd8;
  --primary-hover: #1749b0;
  --danger: #d92d20;
  --success: #12a150;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* 顶部统计范围提示 banner */
.scope-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: linear-gradient(90deg, #fff4e6, #fff8ed);
  border-bottom: 1px solid #ffd591;
  font-size: 13px;
  color: #874d00;
  position: relative;
}
.scope-banner strong { color: #d4380d; }
.scope-banner .banner-icon { font-size: 16px; }
.scope-banner .banner-text { flex: 1; }
.scope-banner .banner-toggle {
  background: none;
  border: none;
  font-size: 18px;
  color: #874d00;
  cursor: pointer;
  padding: 0 8px;
  line-height: 1;
}
.scope-banner.collapsed {
  padding: 4px 20px;
  font-size: 11px;
  background: #f0f0f0;
  color: #888;
  border-bottom: 1px solid #e0e0e0;
}
.scope-banner.collapsed .banner-text::before { content: "ℹ️ "; }
.scope-banner.collapsed .banner-text { font-weight: normal; }
.scope-banner.collapsed strong { color: #555; }

body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* 登录页 */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f1d40 0%, #1d5bd8 100%);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  text-align: center;
}
.login-logo {
  width: 56px; height: 56px;
  background: var(--primary);
  color: #fff;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  margin: 0 auto 16px;
  letter-spacing: 0.5px;
}
.login-card h1 { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-card input {
  width: 100%; padding: 11px 14px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 20px; }

/* 主界面布局 */
.main-app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}
.scope-banner { grid-column: 2; grid-row: 1; }
.sidebar {
  grid-column: 1; grid-row: 1 / span 2;
  background: #101828; color: #fff;
  display: flex; flex-direction: column;
  min-height: 100vh;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 20px 18px; }
.logo-badge {
  background: var(--primary); color: #fff; padding: 4px 8px;
  border-radius: 6px; font-weight: 700; font-size: 13px; letter-spacing: 0.5px;
}
.logo-text { font-size: 15px; font-weight: 600; }
.nav { flex: 1; padding: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin-bottom: 4px;
  color: #cbd5e1; border-radius: 8px; cursor: pointer; text-decoration: none;
  transition: background 0.15s;
}
.nav-item:hover { background: #1d2939; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon { width: 20px; text-align: center; font-size: 15px; }
.sidebar-footer { padding: 16px; border-top: 1px solid #1d2939; }
.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: #94a3b8; }

/* 内容区 */
.content { grid-column: 2; grid-row: 2; padding: 24px 28px; overflow-x: auto; }
.view { animation: fadein 0.2s; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }
.page-title { font-size: 20px; font-weight: 600; margin-bottom: 20px; }
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.view-header .page-title { margin-bottom: 0; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* 卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card .card-label { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.card .card-value { font-size: 26px; font-weight: 600; }
.card .card-sub { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.card .card-value.red { color: var(--danger); }
.card .card-value.amber { color: var(--warning); }
.card .card-value.green { color: var(--success); }
.card .card-value.blue { color: var(--primary); }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

/* 面板 */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel h3 { font-size: 15px; font-weight: 600; padding: 14px 18px; border-bottom: 1px solid var(--border); }

/* 表格 */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: #f9fafb; color: var(--text-muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
.table td { font-size: 13px; }
.table tr:hover td { background: #fafbfc; }
.table .text-right { text-align: right; }
.table .overdue { color: var(--danger); font-weight: 600; }
.table .row-delay { color: var(--warning); }
.table .tfoot-row td { background: #f0f4f8; border-top: 2px solid #d0d7de; font-size: 13px; }

/* 透视表行配色：主产品浅绿，配件浅灰 */
.table .row-main td { background: #d4f4c5; }
.table .row-other td { background: #f1f3f5; color: #555; }
#unshipped-pivot-table tfoot td { background: #e3f2fd; font-weight: 600; border-top: 2px solid #1976d2; }
#unshipped-pivot-table thead tr:first-child th { background: #bbdefb; color: #0d47a1; }

/* 未到货透视表专用样式 */
#unshipped-pivot-table { font-size: 12px; border-collapse: collapse; }
#unshipped-pivot-table th, #unshipped-pivot-table td { padding: 4px 8px; line-height: 1.4; }
#unshipped-pivot-table td.col-product,
#unshipped-pivot-table th.col-product { position: sticky; left: 0; z-index: 1; min-width: 240px; }
#unshipped-pivot-table .row-main-pivot td.col-product { background: #c8e6a0; box-shadow: 2px 0 4px rgba(0,0,0,0.06); }
#unshipped-pivot-table .row-other-pivot td.col-product { background: #e9ecef; color: #777; box-shadow: 2px 0 4px rgba(0,0,0,0.06); }
#unshipped-pivot-table .row-main-pivot td { background: #e8f5d8; }
#unshipped-pivot-table .row-other-pivot td { background: #f8f9fa; color: #666; }
#unshipped-pivot-table .prod-code { font-size: 11px; color: #888; font-family: monospace; }
#unshipped-pivot-table .prod-name { font-size: 12px; font-weight: 600; color: #1a3a17; }
#unshipped-pivot-table tfoot td { background: #d1e7f7 !important; font-weight: 700; color: #0d47a1; border-top: 2px solid #1976d2; }

/* 状态标签 */
.tag { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; white-space: nowrap; }
.tag-blue { background: #eef4ff; color: var(--primary); }
.tag-green { background: #ecfdf3; color: var(--success); }
.tag-red { background: #fef3f2; color: var(--danger); }
.tag-amber { background: #fffaeb; color: var(--warning); }
.tag-gray { background: #f2f4f7; color: var(--text-muted); }

/* 按钮 */
.btn {
  display: inline-block; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  cursor: pointer; font-size: 13px; transition: all 0.15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-block { width: 100%; padding: 11px; }
.btn-wecom { background: #07C160; border-color: #07C160; color: #fff; margin-top: 8px; }
.btn-wecom:hover { background: #06AD56; border-color: #06AD56; color: #fff; }
.btn-ghost { background: transparent; border-color: #344054; color: #cbd5e1; }
.btn-ghost:hover { border-color: #fff; color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { color: var(--danger); border-color: #fecdca; }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }

/* 表单 */
.input, .input-select, .input-search {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff;
}
.input:focus, .input-select:focus, .input-search:focus { outline: none; border-color: var(--primary); }
.input-search { min-width: 200px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-item { display: flex; flex-direction: column; gap: 4px; }
.form-item label { font-size: 12px; color: var(--text-muted); }
.due-preview {
  margin: 14px 0; padding: 10px 14px; background: #fffaeb;
  border: 1px solid #fde68a; border-radius: 8px; font-size: 13px; color: var(--warning);
}
.muted { color: var(--text-muted); font-size: 13px; }

/* 弹窗 */
.modal {
  position: fixed; inset: 0; background: rgba(16,24,40,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal-card {
  background: #fff; border-radius: 14px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-lg { max-width: 860px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { font-size: 24px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 20px; }
.modal-body h4 { font-size: 14px; margin: 18px 0 10px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

.import-result { margin-top: 14px; font-size: 13px; }

/* Toast */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: #101828; color: #fff; padding: 12px 20px; border-radius: 8px;
  z-index: 200; display: none; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

/* ===== 表格增强：滚动容器 + 固定表头 + 固定滚动条 + 列宽拖拽 ===== */
.table-scroll {
  overflow: auto;
  max-height: 72vh;
  border-radius: 0 0 var(--radius) var(--radius);
}
.table-scroll > .table {
  table-layout: fixed;
  width: 100%;
}
.table-scroll > .table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f4f6f8;
}
.table-scroll > .table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 3;
  background: #f0f4f8;
  border-top: 2px solid #d0d7de;
}
.table-scroll > .table th,
.table-scroll > .table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-resizer {
  position: absolute;
  top: 0; right: 0;
  width: 9px; height: 100%;
  cursor: col-resize;
  z-index: 5;
  user-select: none;
  touch-action: none;
}
.col-resizer::after {
  content: "";
  position: absolute;
  top: 25%; bottom: 25%; right: 3px;
  width: 2px;
  background: #cbd5e1;
  border-radius: 1px;
}
.col-resizer:hover { background: rgba(29, 91, 216, 0.15); }
.col-resizer:hover::after, .col-resizer.active::after { background: var(--primary); }
.col-resizer.active { background: rgba(29, 91, 216, 0.22); }

/* 透视表列宽拖拽支持 */
#unshipped-pivot-table { table-layout: fixed; width: 100%; }
#unshipped-pivot-table th { position: relative; }

/* ===== 表头下拉筛选 ===== */
.table-scroll > .table th .th-label {
  display: inline-block;
  max-width: calc(100% - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
.th-filter {
  display: inline-block;
  margin-left: 3px;
  margin-right: 6px;
  padding: 1px 4px;
  cursor: pointer;
  color: #b0b8c4;
  font-size: 11px;
  border-radius: 3px;
  line-height: 1;
  vertical-align: middle;
  user-select: none;
}
.th-filter:hover { background: #e8eef7; color: var(--primary); }
.th-filter.active { background: var(--primary); color: #fff; }

.filter-panel {
  position: fixed;
  z-index: 400;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
  min-width: 170px;
  max-width: 280px;
  display: none;
}
.filter-panel .fp-head {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.filter-panel .fp-head button {
  flex: 1;
  padding: 4px 0;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #f9fafb;
  cursor: pointer;
  color: var(--text);
}
.filter-panel .fp-head button:hover { border-color: var(--primary); color: var(--primary); }
.filter-panel .fp-search { padding: 8px 10px 4px; }
.filter-panel .fp-search input {
  width: 100%;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  outline: none;
}
.filter-panel .fp-search input:focus { border-color: var(--primary); }
.filter-panel .fp-body {
  max-height: 280px;
  overflow-y: auto;
  padding: 6px 8px;
}
.filter-panel .fp-opt {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.filter-panel .fp-opt:hover { background: #f4f6f8; }
.filter-panel .fp-opt input { cursor: pointer; flex: none; }
.filter-panel .fp-empty { padding: 10px; font-size: 12px; color: var(--text-muted); text-align: center; }

/* ===== 数据来源标签 ===== */
.src-badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  vertical-align: middle;
  margin-left: 8px;
  white-space: nowrap;
  cursor: default;
  letter-spacing: 0.2px;
}
.src-k3    { background: #eef4ff; color: #1d5bd8; border: 1px solid #c7dbff; }  /* 金蝶取数 */
.src-upload { background: #ecfdf3; color: #12a150; border: 1px solid #b6ebc8; } /* 用户上传 */
.src-ship  { background: #fffaeb; color: #d97706; border: 1px solid #fde68a; }  /* 发货通知 */
.src-manual{ background: #f2f4f7; color: #6b7280; border: 1px solid #e4e7ec; }  /* 手填/Excel */
.src-mixed { background: #f0f6ff; color: #2456b8; border: 1px solid #c9d9f5; }  /* 多来源混合 */

/* 卡片内来源标签（跟随 label 行，缩小间距） */
.card .src-badge { margin-left: 6px; font-size: 10px; padding: 0 7px; }

/* ===== 移动端顶栏 + 抽屉侧边栏（默认隐藏，桌面端不显示） ===== */
.mobile-topbar { display: none; }
.sidebar-mask { display: none; }

/* ===== 手机端适配（≤768px）：侧边栏收起为抽屉，点 ☰ 展开 ===== */
@media (max-width: 768px) {
  body { font-size: 13px; }

  /* 布局：顶栏 → banner → 内容 三行单列 */
  .main-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }

  /* 移动端顶栏：三点按钮 + 标题 + 退出 */
  .mobile-topbar {
    display: flex;
    grid-column: 1; grid-row: 1;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    height: 48px;
    background: #101828;
    color: #fff;
    position: sticky; top: 0; z-index: 60;
  }
  .mobile-menu-btn {
    background: none; border: none; color: #fff;
    font-size: 22px; line-height: 1;
    padding: 6px 10px; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-brand { font-weight: 600; font-size: 15px; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .mobile-logout {
    background: none; border: 1px solid #344054; color: #cbd5e1;
    padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer;
    flex: none;
  }

  .scope-banner {
    grid-column: 1; grid-row: 2;
    flex-wrap: wrap;
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.5;
  }
  .scope-banner .banner-text { flex: 1 1 100%; order: 3; }
  .scope-banner.collapsed { padding: 4px 12px; }

  /* 侧边栏变抽屉：默认滑出屏幕，.open 滑入 */
  .sidebar {
    position: fixed;
    left: 0; top: 48px; bottom: 0;
    width: 240px; max-width: 82vw;
    z-index: 70;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
    min-height: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-logo { padding: 16px 18px; }
  .sidebar .nav { padding: 8px; }
  .sidebar .nav-item { padding: 11px 14px; margin-bottom: 4px; }
  .sidebar-footer { display: flex; }

  .sidebar-mask {
    position: fixed;
    inset: 48px 0 0 0;
    background: rgba(15,23,42,.45);
    z-index: 65;
  }

  /* 内容区占满全宽 */
  .content { grid-column: 1; grid-row: 3; padding: 14px 12px 28px; }
  .page-title { font-size: 18px; margin-bottom: 14px; }
  .view-header { margin-bottom: 14px; }
  .toolbar { width: 100%; }
  .input-search { min-width: 0; flex: 1 1 120px; }

  /* 卡片两列 */
  .cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
  .card { padding: 14px 12px; }
  .card .card-value { font-size: 20px; }
  .card .card-label { font-size: 12px; }

  .dash-grid { grid-template-columns: 1fr; gap: 14px; }

  /* 弹窗改底部抽屉式 */
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { max-width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .modal-body { padding: 14px 14px 20px; }
  .form-grid { grid-template-columns: 1fr; }

  /* 表格滚动区稍矮，给底部留空间 */
  .table-scroll { max-height: 62vh; }

  /* 登录卡片不溢出 */
  .login-card { max-width: calc(100vw - 24px); padding: 32px 22px; }
}
