:root {
  --ink: #101b2d;
  --ink-2: #2b3a52;
  --muted: #6d7b93;
  --line: #e3e9f2;
  --bg: #f3f5f9;
  --card: #ffffff;
  --brand: #0e7c74;
  --brand-soft: #e6f4f2;
  --accent: #c8862b;
  --danger: #cf4a3f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 27, 45, .04), 0 8px 24px rgba(16, 27, 45, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Microsoft YaHei UI", "PingFang SC", "Hiragino Sans GB", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 216px; flex: 0 0 216px; background: #0d1728; color: #c8d3e4;
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
  background-image: radial-gradient(circle at 20% 0%, #17304f 0%, #0d1728 55%);
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 18px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(140deg, #16a394, #0e7c74);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px;
}
.brand-name { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.brand-sub { font-size: 10px; color: #7d8ea8; margin-top: 2px; letter-spacing: .4px; }

#nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
#nav a {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px;
  color: #a9b7cc; text-decoration: none; font-size: 13px; cursor: pointer; transition: .15s;
}
#nav a .dot { width: 3px; height: 14px; border-radius: 2px; background: transparent; }
#nav a:hover { background: rgba(255,255,255,.06); color: #e8eef8; }
#nav a.active { background: rgba(22,163,148,.16); color: #fff; font-weight: 600; }
#nav a.active .dot { background: #16a394; }
.nav-count {
  margin-left: auto; font-style: normal; font-size: 10px; background: #cf4a3f; color: #fff;
  border-radius: 9px; padding: 1px 6px; min-width: 18px; text-align: center;
}
.nav-count:empty { display: none; }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.08); }
.side-company { font-size: 11.5px; color: #dbe4f2; line-height: 1.5; }
.side-note { font-size: 10px; color: #6d7f99; margin-top: 4px; }
.side-actions { display: flex; gap: 6px; margin-top: 10px; }
details.batch-legacy > summary {
  cursor: pointer; font-size: 12px; color: var(--muted); padding: 9px 12px; background: #fff;
  border: 1px solid var(--line); border-radius: 9px; margin-bottom: 10px; list-style: none;
}
details.batch-legacy > summary::-webkit-details-marker { display: none; }
details.batch-legacy > summary::before { content: '▸ '; }
details.batch-legacy[open] > summary::before { content: '▾ '; }
details.batch-legacy[open] > summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.st-line input { padding: 6px 8px; font-size: 12px; }
.side-logout {
  flex: 1; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.06); color: #c8d3e4;
  border-radius: 7px; padding: 6px 0; font-size: 11.5px; font-family: inherit; cursor: pointer; transition: .15s;
}
.side-logout:hover { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.28); }

/* ---------- layout ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  padding: 20px 26px 16px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
h1 { font-size: 19px; margin: 0; letter-spacing: .3px; }
.subtitle { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.pill {
  font-size: 11.5px; color: var(--ink-2); background: #f1f4f9; border: 1px solid var(--line);
  border-radius: 20px; padding: 6px 12px;
}
.identity {
  display: flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line);
  border-radius: 9px; padding: 4px 8px;
}
.identity-label { font-size: 10px; color: var(--muted); letter-spacing: .3px; }
.identity select {
  border: none; background: transparent; padding: 2px; font-size: 12.5px; font-weight: 600; color: var(--ink); max-width: 150px;
}
.identity select:focus { box-shadow: none; }

td select.assign { padding: 3px 6px; font-size: 11.5px; border-radius: 6px; width: 100%; max-width: 160px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink-2); border-radius: 8px;
  padding: 7px 13px; font-size: 12.5px; cursor: pointer; font-family: inherit; transition: .15s;
}
.btn:hover { border-color: #c4cfdf; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #0b6a63; }
.btn.danger { color: var(--danger); border-color: #f0cfcb; background: #fff8f7; }
.btn.sm { padding: 4px 9px; font-size: 11.5px; }
.icon-btn { border: none; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }

main#view { padding: 20px 26px 46px; }

/* ---------- cards & grid ---------- */
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(6, 1fr); }
.two { grid-template-columns: 1.45fr 1fr; }
.three { grid-template-columns: repeat(3, 1fr); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; gap: 8px; }
.card-head h3 { font-size: 13.5px; margin: 0; font-weight: 600; }
.card-head .hint { font-size: 11px; color: var(--muted); }
.kpi { position: relative; overflow: hidden; }
.kpi .k-label { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.kpi .k-value { font-size: 24px; font-weight: 700; margin-top: 7px; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.kpi .k-value small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kpi .k-foot { font-size: 11px; color: var(--muted); margin-top: 6px; }
.kpi.alert .k-value { color: var(--danger); }
.kpi::after { content: ""; position: absolute; right: -24px; top: -24px; width: 72px; height: 72px; border-radius: 50%; background: rgba(14,124,116,.06); }
.kpi.alert::after { background: rgba(207,74,63,.07); }

/* ---------- table ---------- */
.table-wrap { overflow: auto; border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 11px; letter-spacing: .3px;
  padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fbfcfe;
  position: sticky; top: 0;
}
tbody td { padding: 10px; border-bottom: 1px solid #f0f3f8; vertical-align: middle; }
tbody tr:hover { background: #f8fafd; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.link { color: var(--brand); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.tiny { font-size: 11px; }

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge.low { color: #12806f; background: #e6f7f4; }
.badge.mid { color: #9a6a12; background: #fdf5e3; }
.badge.high { color: #b4472f; background: #fdeeea; }
.badge.extreme { color: #932a2a; background: #f9e0e0; }
.badge.gray { color: #5c6a80; background: #eef1f6; }
.badge.overdue { color: #b4472f; background: #fdeeea; }
.badge.ok { color: #12806f; background: #e6f7f4; }

.legend-chip {
  display: inline-block; padding: 2px 8px; border-radius: 5px; font-size: 11px;
  border: 1px solid transparent; margin-right: 4px;
}

.bar { height: 5px; border-radius: 3px; background: #eef1f7; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }

/* ---------- charts ---------- */
.chart { width: 100%; display: block; }
.chart text { font-family: inherit; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  font-family: inherit; font-size: 12.5px; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,124,116,.1); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- timeline ---------- */
.timeline { border-left: 2px solid #eef1f7; margin-left: 6px; padding-left: 14px; display: flex; flex-direction: column; gap: 14px; }
.tl-item { position: relative; }
.tl-item::before {
  content: ""; position: absolute; left: -21px; top: 3px; width: 8px; height: 8px; border-radius: 50%;
  background: #fff; border: 2px solid var(--brand);
}
.tl-item .tl-date { font-size: 11px; color: var(--muted); }
.tl-item .tl-title { font-size: 12.5px; font-weight: 600; margin: 2px 0; }
.tl-item .tl-note { font-size: 12px; color: var(--ink-2); line-height: 1.6; }

/* ---------- drawer / modal ---------- */
.drawer-mask, .modal-mask {
  position: fixed; inset: 0; background: rgba(16,27,45,.32); opacity: 0; pointer-events: none;
  transition: .2s; z-index: 40; backdrop-filter: blur(1px);
}
.drawer-mask.show, .modal-mask.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 560px; max-width: 94vw; background: #fff;
  z-index: 50; transform: translateX(100%); transition: .24s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; box-shadow: -12px 0 40px rgba(16,27,45,.14);
}
.drawer.show { transform: none; }
/* 弹窗必须盖住右侧客户详情抽屉 */
.modal-mask { z-index: 70; }
.modal { z-index: 80; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 15px; margin: 0; }
.drawer-body { padding: 18px 20px 40px; overflow: auto; }
.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -46%) scale(.98); width: 560px; max-width: 94vw;
  background: #fff; border-radius: 14px; z-index: 60; padding: 20px 22px; opacity: 0; transition: .18s;
  box-shadow: 0 24px 60px rgba(16,27,45,.24); max-height: 90vh; overflow: auto;
}
.modal-mask.show .modal { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.modal h2 { font-size: 15px; margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- misc ---------- */
.section { margin-bottom: 18px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 0 0 8px; letter-spacing: .3px; }
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(20px);
  background: #101b2d; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 12.5px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 80;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.empty { padding: 34px 10px; text-align: center; color: var(--muted); font-size: 12.5px; }
.split { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; }

.alert-row {
  display: flex; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  align-items: flex-start; background: #fff;
}
.alert-row .a-bar { width: 3px; align-self: stretch; border-radius: 2px; }
.alert-row.high .a-bar { background: var(--danger); }
.alert-row.mid .a-bar { background: var(--accent); }
.alert-row.low .a-bar { background: #4b7bec; }
.alert-row .a-title { font-size: 12.5px; font-weight: 600; }
.alert-row .a-detail { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.6; }
.alert-row .a-act { font-size: 11.5px; color: var(--brand); margin-top: 4px; }

@media (max-width: 1280px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .two { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  main#view, .topbar { padding-left: 14px; padding-right: 14px; }
  .three { grid-template-columns: 1fr; }
}

/* ---------- 手机版（<=900px） ---------- */
.mobilebar, .moresheet { display: none; }

@media (max-width: 900px) {
  body { font-size: 13.5px; }
  #app { min-height: 100vh; }
  main#view { padding: 12px 10px calc(72px + env(safe-area-inset-bottom)); }

  /* 顶栏：两行，标题一行、操作一行横向滑动 */
  .topbar { padding: 12px 12px 10px; flex-wrap: wrap; align-items: flex-start; gap: 8px; }
  .topbar h1 { font-size: 17px; }
  .subtitle { font-size: 11px; line-height: 1.5; }
  .top-actions {
    width: 100%; flex-wrap: nowrap; overflow-x: auto; gap: 6px;
    padding-bottom: 2px; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .top-actions::-webkit-scrollbar { display: none; }
  .top-actions > * { flex: 0 0 auto; }
  .identity { padding: 3px 7px; }
  .identity-label { display: none; }
  .identity select { max-width: 96px; font-size: 12px; }
  .btn { padding: 8px 12px; font-size: 13px; }
  .btn.sm { padding: 6px 10px; font-size: 12px; }

  /* 底部标签栏 */
  .mobilebar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: rgba(255,255,255,.97); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    backdrop-filter: blur(8px);
  }
  .mobilebar a {
    flex: 1; text-align: center; font-size: 11.5px; color: var(--muted);
    text-decoration: none; padding: 7px 0 5px; border-radius: 9px; position: relative;
  }
  .mobilebar a.active { color: var(--brand); font-weight: 700; background: var(--brand-soft); }

  /* 全部功能面板 */
  .moresheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; background: #fff;
    border-radius: 16px 16px 0 0; padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
    box-shadow: 0 -12px 40px rgba(16,27,45,.2); max-height: 76vh; overflow: auto;
    transform: translateY(102%); transition: transform .22s cubic-bezier(.4,0,.2,1);
  }
  .moresheet.show { display: block; transform: none; }
  .ms-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 14px; }
  .ms-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .ms-list button {
    text-align: left; padding: 13px 12px; border: 1px solid var(--line); background: #fff;
    border-radius: 10px; font-family: inherit; font-size: 13.5px; color: var(--ink-2); cursor: pointer;
  }
  .ms-list button.on { border-color: var(--brand); color: var(--brand); font-weight: 600; background: var(--brand-soft); }

  /* 卡片与栅格 */
  .grid { gap: 10px; }
  .kpis, .three { grid-template-columns: repeat(2, 1fr); }
  .two { grid-template-columns: 1fr; }
  .card { padding: 13px 13px; border-radius: 11px; }
  .kpi .k-value { font-size: 20px; }
  .kpi .k-foot { font-size: 10.5px; }

  /* 表格：横向滑动 + 首列固定 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 12px; }
  thead th { padding: 8px 8px; }
  tbody td { padding: 9px 8px; }
  table th:first-child, table td:first-child {
    position: sticky; left: 0; z-index: 2; background: #fff;
    box-shadow: 1px 0 0 var(--line);
  }
  thead th:first-child { background: #fbfcfe; z-index: 3; }
  tbody tr:hover td:first-child { background: #f8fafd; }

  /* 应收报表：序号列让它滑走，固定第二列「客户」 */
  table.rtable th:nth-child(1), table.rtable td:nth-child(1) { position: static; box-shadow: none; }
  table.rtable th:nth-child(2), table.rtable td:nth-child(2) {
    position: sticky; left: 0; z-index: 2; background: #fff; box-shadow: 1px 0 0 var(--line);
  }
  table.rtable thead th:nth-child(2) { background: #fbfcfe; z-index: 3; }
  table.rtable tbody tr:hover td:nth-child(2) { background: #f8fafd; }

  /* 表单与弹窗 */
  input[type="text"], input[type="number"], input[type="date"], select, textarea { font-size: 16px; padding: 9px 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .drawer { width: 100%; max-width: 100%; }
  .modal {
    left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-width: 100%;
    transform: translateY(100%); border-radius: 16px 16px 0 0; max-height: 92vh;
    padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .modal-mask.show .modal { transform: none; }
  .modal-actions { gap: 8px; }
  .modal-actions .btn { flex: 1; padding: 11px 0; font-size: 14px; }
  .toolbar { gap: 6px; }
  .toolbar select, .toolbar input { flex: 1 1 46%; min-width: 0; }
  .toast { bottom: calc(78px + env(safe-area-inset-bottom)); max-width: 86vw; text-align: center; }
  .legend { font-size: 10.5px; gap: 10px; }
}

/* 任务派发的截止日状态 */
.late { color: #b4472f; font-weight: 600; }
.today { color: #9a6a12; font-weight: 600; }
