:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1d2433; --muted: #6b7385; --line: #e3e6ec;
  --brand: #2f5bea; --brand-soft: #e8eefe; --ok: #1f9d55; --warn: #c27c0e; --bad: #d64545;
  --nav-bg: #161b26; --nav-ink: #c9cfdb; --nav-active: #2f5bea;
  --radius: 10px; --shadow: 0 1px 3px rgba(20, 30, 60, .08), 0 6px 24px rgba(20, 30, 60, .06);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.bad { color: var(--bad); }
.late { color: var(--bad); font-weight: 600; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 10px; display: flex; align-items: center; gap: 10px; }
h4 { margin: 14px 0 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

#app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
#nav { background: var(--nav-bg); color: var(--nav-ink); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow: auto; }
#nav .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 6px 10px 16px; }
#nav a { display: flex; align-items: center; gap: 8px; color: var(--nav-ink); padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
#nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; }
#nav a.active { background: var(--nav-active); color: #fff; }
#nav .ico { width: 20px; text-align: center; }
#nav .count { margin-left: auto; font-size: 11px; opacity: .7; }

main { min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
#globalSearch { flex: 1; max-width: 420px; }
#saveStatus { margin-left: auto; font-size: 12px; color: var(--muted); }
#view { padding: 20px 24px 60px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .search { min-width: 260px; flex: 1; max-width: 420px; }
label.inline { display: flex; gap: 6px; align-items: center; color: var(--muted); }

input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; width: 100%; }
.toolbar select, .toolbar input { width: auto; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c7ccd6; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger.ghost { color: var(--bad); background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; cursor: pointer; user-select: none; white-space: nowrap; position: sticky; top: 0; }
table.grid tbody tr, table.grid tr[data-open] { cursor: pointer; }
table.grid tbody tr:hover, table.grid tr[data-open]:hover { background: #f3f6ff; }
table.grid.small th, table.grid.small td { padding: 6px 8px; font-size: 13px; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: #eef0f4; color: #3c4456; margin: 1px 0; white-space: nowrap; }
.chip.tag { background: var(--brand-soft); color: #2546b8; }
.act-Active { background: #dcf5e6; color: #146c3a; }
.act-Passive { background: #fff2d6; color: #8a5a00; }
.act-NotLooking { background: #eceef2; color: #5c6372; }
.act-DoNotContact { background: #fde2e2; color: #a12b2b; }
.js-Hot { background: #fde2e2; color: #a12b2b; }
.js-Normal { background: #dcf5e6; color: #146c3a; }
.js-Hold { background: #fff2d6; color: #8a5a00; }
.tier-1 { background: #dcf5e6; color: #146c3a; }
.tier-2 { background: #e8eefe; color: #2546b8; }
.tier-3 { background: #eceef2; color: #5c6372; }
.st-offer, .st-onboard { background: #dcf5e6; color: #146c3a; }
.st-guaranteed { background: #c9eed8; color: #0e5a2f; }
.st-rejected, .st-withdrawn { background: #fde2e2; color: #a12b2b; }
.inv-已回款 { background: #dcf5e6; color: #146c3a; }
.inv-已开票 { background: #fff2d6; color: #8a5a00; }

.empty { padding: 40px; text-align: center; color: var(--muted); background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty.small { padding: 16px; box-shadow: none; }

.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; color: var(--ink); display: flex; flex-direction: column; gap: 4px; }
.kpi:hover { text-decoration: none; }
.kpi b { font-size: 22px; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi.bad b { color: var(--bad); }
.two-col { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; }
.rem { padding: 8px 10px; border-left: 3px solid var(--line); background: #fafbfc; border-radius: 6px; margin-bottom: 6px; cursor: pointer; }
.rem:hover { background: #f3f6ff; }
.rem.sev-high { border-color: var(--bad); }
.rem.sev-mid { border-color: var(--warn); }
.rem.sev-low { border-color: #9aa3b5; }
.result { padding: 6px 0; cursor: pointer; border-bottom: 1px dashed var(--line); }

.funnel { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 6px; }
.fstep { background: #f1f3f7; border-radius: 8px; padding: 8px; text-align: center; }
.fstep b { display: block; font-size: 18px; }
.fstep span { font-size: 11px; color: inherit; opacity: .8; }

/* 看板 */
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.lane { min-width: 190px; flex: 1; background: #eceff4; border-radius: var(--radius); padding: 8px; min-height: 200px; }
.lane.over { outline: 2px dashed var(--brand); }
.lane-head { font-weight: 600; font-size: 13px; padding: 6px 8px; border-radius: 6px; margin-bottom: 8px; display: flex; justify-content: space-between; background: #fff; }
.kcard { background: #fff; border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); cursor: grab; position: relative; }
.kcard.dragging { opacity: .5; }
.kcard .muted { font-size: 12px; }
.kcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 6px; min-height: 18px; }
.kcard .age { font-size: 11px; color: var(--muted); margin-left: auto; }

/* AI 匹配度 */
.pct { display: inline-block; min-width: 42px; text-align: center; padding: 1px 7px; border-radius: 99px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pct.pct-hi { background: #dcf5e6; color: #146c3a; }
.pct.pct-mid { background: #fff2d6; color: #8a5a00; }
.pct.pct-lo { background: #eceef2; color: #5c6372; }
.pct-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 120px; }
.pct-bar { flex: 1; height: 6px; background: #eceef2; border-radius: 99px; overflow: hidden; }
.pct-bar i { display: block; height: 100%; border-radius: 99px; }
.pct-bar i.pct-hi { background: var(--ok); }
.pct-bar i.pct-mid { background: var(--warn); }
.pct-bar i.pct-lo { background: #9aa3b5; }
.match { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.match-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.match-head > a:first-child { min-width: 140px; }
.match-why, .match-risk { font-size: 13px; margin-top: 6px; line-height: 1.5; }
.match-risk { color: #7a4e00; }
.match-bd { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.small-note { font-size: 11px; margin-top: 4px; }
.kcard .age.late { color: var(--bad); font-weight: 600; }

/* 抽屉 */
#drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 96vw); background: var(--bg); box-shadow: -10px 0 40px rgba(0, 0, 0, .18); z-index: 20; display: flex; flex-direction: column; }
#drawer.hidden { display: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 2px 0; font-size: 18px; }
.drawer-kicker { font-size: 12px; color: var(--muted); }
.drawer-body { overflow: auto; padding: 16px 20px 60px; }
fieldset { border: none; background: var(--panel); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 14px; box-shadow: var(--shadow); }
legend { font-weight: 700; padding: 0; margin-bottom: 8px; float: left; width: 100%; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; clear: both; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.req { color: var(--bad); }
.help { font-size: 11px; color: var(--muted); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { font-weight: 400; color: var(--ink); font-size: 13px; display: flex; gap: 4px; align-items: center; }
.checks input { width: auto; }
.path-row { display: flex; gap: 6px; }

.rel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; background: var(--brand-soft); margin: 2px; }
.act { border-top: 1px solid var(--line); padding: 8px 0; }
.act.done { opacity: .6; }
.act-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 3px; }
.act-new { background: #fafbfc; padding: 10px; border-radius: 8px; margin-bottom: 8px; align-items: end; }
.fb { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.fb.new { background: #fafbfc; }
.fb-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.fb-head .btn { margin-left: auto; }
.fb-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fb-cols label { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.file { padding: 4px 0; }
.drop { display: block; border: 2px dashed var(--line); border-radius: 8px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; margin-top: 8px; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }

.warnings { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.warnings > div { padding: 8px 12px; border-radius: 8px; }
.w-block { background: #fde2e2; color: #8b1f1f; }
.w-warn { background: #fff2d6; color: #7a4e00; }
.w-info { background: #e8eefe; color: #2546b8; }
.w-ok { background: #dcf5e6; color: #146c3a; }
td .w-warn { padding: 4px 8px; border-radius: 6px; margin-top: 4px; font-size: 12px; }

.file-status { padding: 10px 12px; background: #fafbfc; border-radius: 8px; margin: 8px 0; }
.danger-zone { border: 1px solid #f3c4c4; }

/* 服务器版登录页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--bg); }
.login-card { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 24px; width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-card h2 { margin: 0; font-size: 18px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.login-card .btn { justify-content: center; padding: 10px; }
.brand-dark { font-weight: 800; font-size: 20px; color: var(--ink); }

/* 弹窗与提示 */
#modal { position: fixed; inset: 0; background: rgba(15, 20, 35, .45); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
#modal.hidden { display: none; }
.modal-card { background: var(--panel); border-radius: 12px; padding: 20px 22px; width: min(520px, 100%); box-shadow: var(--shadow); }
.modal-card h3 { font-size: 17px; }
.modal-body { line-height: 1.6; max-height: 60vh; overflow-y: auto; overflow-x: hidden; overflow-wrap: anywhere; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px); background: #1d2433; color: #fff; padding: 10px 18px; border-radius: 8px; transition: transform .25s; z-index: 50; max-width: 90vw; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.ok { background: #146c3a; }
#toast.err { background: #a12b2b; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; }
  /* 手机：菜单变成顶部一条可以左右滑动的横条 */
  #nav { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 6; height: auto; display: flex; flex-wrap: nowrap; gap: 4px; overflow-x: auto; padding: 8px max(12px, env(safe-area-inset-left, 0px)); -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #nav::-webkit-scrollbar { display: none; }
  #nav .brand { display: none; }
  #nav a { white-space: nowrap; flex: 0 0 auto; padding: 7px 10px; margin: 0; font-size: 13px; }
  #nav .count { display: none; }
  #topbar { position: static; padding: 8px max(16px, env(safe-area-inset-left, 0px)); flex-wrap: wrap; gap: 6px; }
  #globalSearch { max-width: none; width: 100%; }
  #saveStatus { margin-left: 0; }
  .two-col, .form-grid, .fb-cols { grid-template-columns: 1fr; }
  #view { padding: 16px max(16px, env(safe-area-inset-left, 0px)) 60px; }
  #drawer { width: 100vw; }
  .drawer-head { padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); flex-wrap: wrap; }
  .drawer-body { padding: 12px 12px 80px; }
  .toolbar .search { min-width: 0; width: 100%; max-width: none; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .lane { min-width: 160px; }
  h1 { font-size: 18px; }
}
