/* ============ 设计令牌 ============ */
:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #17202e;
  --ink-2: #3b4657;
  --muted: #5b6478;
  --line: #e3e8f2;
  --line-strong: #cfd7e6;
  --accent: #2559d6;
  --accent-soft: #e9effd;
  --zx: #7048e8;
  --dg: #0e8f8f;
  --zf: #c2740b;
  --g0: #c0433a;
  --ok: #147d4f;
  --shadow: 0 1px 2px rgba(23, 32, 46, .06), 0 8px 24px rgba(23, 32, 46, .06);
  --radius: 14px;
  --font: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  font-size: 15px;
}

.wrap {
  width: min(1440px, 100% - 40px);
  margin-inline: auto;
}

h1, h2, h3 { line-height: 1.3; margin: 0; }
p { margin: 0; }
ul { margin: 0; padding-left: 1.15em; }
li { margin: 4px 0; }
code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .86em;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 6px;
}

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

.skip-link {
  position: absolute; left: 12px; top: -60px;
  background: var(--accent); color: #fff;
  padding: 10px 16px; border-radius: 10px; z-index: 30;
  text-decoration: none; transition: top .2s ease;
}
.skip-link:focus { top: 12px; }

:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
  border-radius: 8px;
}

/* ============ 头部 ============ */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 14px 0; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-title { font-size: 20px; font-weight: 700; letter-spacing: .2px; }
.brand-sub { font-size: 13px; color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ============ 按钮 ============ */
.btn {
  font: inherit; cursor: pointer;
  border-radius: 10px; border: 1px solid transparent;
  padding: 9px 16px; font-weight: 600; font-size: 14px;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .06s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1c48b8; }
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-soft:hover { background: #d9e4fb; }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line-strong); }
.btn-ghost:hover { background: #eef2f9; }

.seg {
  display: inline-flex; background: #eef1f8;
  border-radius: 12px; padding: 4px; gap: 4px;
}
.seg-btn {
  font: inherit; font-size: 13.5px; font-weight: 600;
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 9px; cursor: pointer;
}
.seg-btn.is-active {
  background: #fff; color: var(--accent);
  box-shadow: 0 1px 3px rgba(23, 32, 46, .12);
}

/* ============ 面板 ============ */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-top: 20px;
}
.panel-head { margin-bottom: 16px; }
.panel-head h2 { font-size: 17px; }
.panel-desc { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.panel-head-row {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.filters { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }

.mini-label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12.5px; color: var(--muted); font-weight: 600;
}
.mini-label input, .mini-label select {
  font: inherit; font-size: 14px; color: var(--ink);
  padding: 8px 11px; border: 1px solid var(--line-strong);
  border-radius: 10px; background: #fff; min-width: 190px;
}
.mini-label input::placeholder { color: #94a0b3; }

/* ============ 上传区 ============ */
.upload-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.up-card {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 16px 18px; background: #fbfcfe;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.up-card.is-drag { border-color: var(--accent); background: var(--accent-soft); }
.up-card.is-ok { border-style: solid; border-color: #bfe3cf; background: #f5fbf7; }
.up-card.is-err { border-style: solid; border-color: #f0c2bd; background: #fdf6f5; }
.up-card-head { display: flex; align-items: center; gap: 9px; }
.up-card-head h3 { font-size: 15.5px; }
.up-hint { font-size: 12.5px; color: var(--muted); margin: 8px 0 6px; }
.up-file {
  font-size: 13px; color: var(--ink-2); font-weight: 600;
  word-break: break-all; min-height: 20px;
}
.up-actions {
  display: flex; align-items: center; gap: 12px;
  margin-top: 12px; flex-wrap: wrap;
}
.up-actions select {
  font: inherit; font-size: 13px; padding: 5px 8px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
}
.upload-foot {
  display: flex; align-items: center; gap: 14px;
  margin-top: 16px; flex-wrap: wrap;
}
.foot-note { font-size: 12.5px; color: var(--muted); }

/* 数据导入入口：默认页面仅一个按钮 */
.import-entry { display: flex; justify-content: flex-start; align-items: center; gap: 14px; flex-wrap: wrap; }
.btn-lg {
  font-size: 15px; padding: 11px 30px; border-radius: 12px;
  font-weight: 700; letter-spacing: .02em;
}

/* 云同步状态徽标 */
.cloud-status {
  display: inline-flex; align-items: center;
  font-size: 12px; font-weight: 700;
  padding: 4px 12px; border-radius: 999px;
  background: #eef1f8; color: var(--muted);
}
.cloud-status.is-online { background: #e2f4ea; color: var(--ok); }
.cloud-status.is-busy { background: var(--accent-soft); color: var(--accent); }
.cloud-status.is-offline { background: #fdeeea; color: var(--g0); }

/* 公告栏 */
.notice-panel { border-left: 4px solid var(--accent); }
.notice-edit textarea {
  width: 100%; resize: vertical; min-height: 72px;
  font: inherit; color: var(--ink);
  padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--panel);
}
.notice-edit textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
.notice-actions { display: flex; align-items: center; gap: 14px; margin-top: 10px; flex-wrap: wrap; }
.notice-meta { font-size: 12px; color: var(--muted); }

.badge {
  margin-left: auto; font-size: 11.5px; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  background: #eef1f8; color: var(--muted);
}
.badge.is-ok { background: #dff3e7; color: var(--ok); }
.badge.is-err { background: #fbe3e0; color: var(--g0); }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-zx { background: var(--zx); }
.dot-dg { background: var(--dg); }
.dot-zf { background: var(--zf); }

/* ============ KPI ============ */
.kpi-grid {
  display: grid; gap: 16px; margin-top: 20px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.kpi {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-formula {
  display: block; font-size: 11.5px; font-weight: 400;
  color: #8b95a8; margin-top: 2px;
}
.kpi-num {
  font-size: 32px; font-weight: 800; letter-spacing: -.5px;
  margin: 8px 0 2px; font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: 13.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.kpi-alert { border-color: #f0d2ce; background: #fffbfa; }
.kpi-alert .kpi-num { color: var(--g0); }

/* ============ 表格 ============ */
.table-scroll {
  overflow-x: auto; border: 1px solid var(--line);
  border-radius: 12px; background: #fff;
}
.data-table {
  border-collapse: separate; border-spacing: 0;
  width: 100%; font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}
.data-table th, .data-table td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.data-table thead th {
  background: #f7f9fd; color: var(--ink-2);
  font-weight: 700; font-size: 12.5px; position: sticky; top: 0; z-index: 2;
}
.data-table tbody tr:hover { background: #f6f9ff; }
.data-table tbody tr.is-selected { background: var(--accent-soft); }
.data-table td.num, .data-table th.num { text-align: right; }
.data-table tfoot td {
  background: #f7f9fd; font-weight: 800;
  border-top: 2px solid var(--line-strong); border-bottom: 0;
}
.col-name {
  position: sticky; left: 0; z-index: 3;
  background: #f7f9fd; min-width: 96px;
}
tbody .col-name { background: #fff; z-index: 1; }
tbody tr:hover .col-name { background: #f6f9ff; }
tbody tr.is-selected .col-name { background: var(--accent-soft); }
tfoot .col-name { background: #f7f9fd; z-index: 3; }

.group-row th {
  text-align: center; font-size: 12px; letter-spacing: .4px;
  border-bottom: 1px solid var(--line);
}
.grp-total { background: #eef2fb !important; color: var(--accent) !important; }
.grp-zx { background: #f2eefe !important; color: var(--zx) !important; }
.grp-zf { background: #fdf4e6 !important; color: var(--zf) !important; }
.grp-dg { background: #e8f6f6 !important; color: var(--dg) !important; }
.grp-g0 { background: #fdeeed !important; color: var(--g0) !important; }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
.th-btn {
  font: inherit; font-size: inherit; font-weight: inherit;
  color: inherit; background: none; border: 0;
  padding: 0; cursor: pointer; display: inline-flex; align-items: center;
}
th .sort-mark { font-size: 10px; margin-left: 3px; opacity: .55; }
th[aria-sort="descending"] .sort-mark,
th[aria-sort="ascending"] .sort-mark { opacity: 1; color: var(--accent); }

.metric-cell { min-width: 92px; }
.metric-cell .m-amount { font-weight: 700; }
.metric-cell .m-count { display: block; font-size: 11.5px; color: var(--muted); }
.cell-zero { color: #a4adbd; }
.cell-note {
  display: block; font-size: 11px; color: var(--muted);
  font-weight: 400; margin-top: 1px;
}

/* 汇总表：整行可点击展开 + 销售名称按钮 + 行内订单详情 */
tr.sales-row { cursor: pointer; }
tr.sales-row:hover .name-btn { color: var(--accent); }
.name-btn {
  font: inherit; font-size: 13.5px; font-weight: 600;
  color: var(--ink); background: none; border: 0;
  padding: 2px 6px 2px 2px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.name-btn:hover { color: var(--accent); background: var(--accent-soft); }
.name-btn.is-open { color: var(--accent); }
.name-btn .caret { font-size: 10px; color: var(--muted); }
.name-btn.is-open .caret { color: var(--accent); }

.expand-row > td {
  background: #f7f9fd; padding: 0;
  border-bottom: 1px solid var(--line-strong);
}
.expand-panel {
  padding: 14px 16px 16px;
  border-left: 3px solid var(--accent);
  margin: 0;
}
.expand-head {
  font-size: 12.5px; font-weight: 700; color: var(--ink-2);
  margin-bottom: 10px;
}
.table-scroll.inner {
  border: 1px solid var(--line); border-radius: 10px;
  max-height: 420px; overflow: auto; background: #fff;
}
.mini-table { font-size: 12.5px; }
.mini-table th, .mini-table td { padding: 8px 10px; }
.mini-table thead th { background: #eef2fb; }

/* 展开面板：卡种数量总览 */
.ov-block { margin-bottom: 12px; }
.ov-title {
  font-size: 12px; font-weight: 700; color: var(--muted);
  letter-spacing: .4px; margin-bottom: 6px;
}
.table-scroll.ov-scroll { max-height: 300px; }
.ov-table td:first-child {
  max-width: 380px; overflow: hidden; text-overflow: ellipsis;
}
.ov-bar {
  display: inline-block; width: 110px; height: 8px;
  border-radius: 999px; background: #e6ebf7;
  overflow: hidden; vertical-align: middle; margin-right: 8px;
}
.ov-bar-fill {
  display: block; height: 100%;
  background: var(--accent); border-radius: 999px;
}

.empty-line {
  color: var(--muted); font-size: 13px;
  padding: 18px 4px; text-align: center;
}

.table-note { font-size: 12.5px; color: var(--muted); margin-top: 10px; }

/* ============ 部门维度：层级视觉 ============ */
/* 层级标签（弹窗与统计表通用） */
.lvl-tag {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  margin-right: 6px; vertical-align: middle;
}
.lvl-tag.lvl-2 { background: #eef1f8; color: var(--muted); }

/* 1级部门行：浅蓝底 + 左侧强调条 + 加粗 */
tr.dept-row-1 > th.col-name {
  border-left: 3px solid var(--accent);
  background: #e9effb;
}
tr.dept-row-1 > td { background: #f3f7fe; }
tr.dept-row-1 .name-btn { font-weight: 700; font-size: 14px; }
tr.dept-row-1:hover > td, tr.dept-row-1:hover > th.col-name { background: #dfe9fa; }
tr.dept-row-1.is-selected > td,
tr.dept-row-1.is-selected > th.col-name { background: var(--accent-soft); }

/* 2级部门行：缩进 + 树形虚线引导 + 弱化白底 */
tr.dept-row-2 > th.col-name {
  border-left: 3px solid var(--line-strong);
  padding-left: 38px;
  position: relative;
  background: #fbfcfe;
}
tr.dept-row-2 > th.col-name::before { /* 树枝横线 */
  content: ""; position: absolute; left: 3px; top: 50%;
  width: 14px; border-top: 2px dotted var(--line-strong);
}
tr.dept-row-2 > td { background: #fbfcfe; }
tr.dept-row-2:hover > td, tr.dept-row-2:hover > th.col-name { background: #f2f6fd; }
.lvl2-name {
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  display: inline-flex; align-items: center;
}
.dept-badge {
  display: inline-block; margin-left: 8px; padding: 1px 8px;
  border-radius: 999px; background: #eef1f8; color: var(--muted);
  font-size: 11px; font-weight: 700; vertical-align: middle;
}

/* 未分配部门：警示色 */
tr.dept-row-unassigned > th.col-name {
  border-left-color: var(--g0); background: #fbeceb;
}
tr.dept-row-unassigned > td { background: #fdf4f3; }
tr.dept-row-unassigned:hover > td, tr.dept-row-unassigned:hover > th.col-name { background: #f8e2e0; }
tr.dept-row-unassigned .name-btn { color: var(--g0); }
tr.dept-row-unassigned .dept-badge { background: #f6d4d0; color: var(--g0); }

/* ============ 弹窗：部门设置 ============ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(23, 32, 46, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff; border-radius: var(--radius);
  width: min(760px, 100%); max-height: 84vh; max-height: 84dvh;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 64px rgba(23, 32, 46, .28);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 16px 20px; overflow: auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px; border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

/* 弹窗尺寸变体 + 右上角关闭 */
.modal-sm { width: min(420px, 100%); }
.modal-lg { width: min(1020px, 100%); }
.modal-x {
  border: 0; background: transparent; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--muted);
  padding: 4px 10px; border-radius: 8px;
}
.modal-x:hover { background: var(--accent-soft); color: var(--ink); }
.modal-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cfg-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.cfg-toolbar input {
  font: inherit; font-size: 13.5px; padding: 7px 10px;
  border: 1px solid var(--line-strong); border-radius: 9px; min-width: 200px;
}
.cfg-dept1 {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 12px; background: #fbfcfe;
}
.cfg-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cfg-row input {
  font: inherit; font-size: 13.5px; padding: 6px 10px;
  border: 1px solid var(--line-strong); border-radius: 9px; min-width: 160px;
}
.cfg-dept2 {
  margin: 10px 0 0 18px; padding: 10px 12px;
  border-left: 2px solid var(--line-strong); background: #fff;
  border-radius: 0 10px 10px 0;
}
.cfg-members { margin-top: 8px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cfg-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; padding: 3px 6px 3px 10px;
  border-radius: 999px; background: var(--accent-soft); color: var(--ink-2);
}
.cfg-chip button {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 50%;
}
.cfg-chip button:hover { color: var(--g0); background: #fbe7e5; }
.cfg-empty { font-size: 12px; color: var(--muted); }
.btn-danger { background: #fbe7e5; color: var(--g0); }
.btn-danger:hover { background: #f6d4d0; }

/* 来源标签（销售详情订单明细在用） */
.tag {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; margin: 1px 3px 1px 0;
}
.tag-zx { background: #f2eefe; color: var(--zx); }
.tag-dg { background: #e4f4f4; color: var(--dg); }
.tag-zf { background: #fdf1de; color: var(--zf); }

.site-foot {
  margin: 26px 0 34px; text-align: center;
  color: var(--muted); font-size: 12.5px;
}

/* ============ 响应式 ============ */
@media (max-width: 720px) {
  .wrap { width: min(1440px, 100% - 24px); }
  .panel { padding: 18px 16px; }
  .brand-title { font-size: 17px; }
  .kpi-num { font-size: 26px; }
  .header-inner { padding: 12px 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
