:root {
  --bg: #f6f7f9; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e4e7ec;
  --brand: #2f5bea; --brand-weak: #e8eeff; --ok: #16803c; --ok-weak: #e3f5e9;
  --warn: #b45309; --warn-weak: #fdf1e1; --bad: #c0262d; --bad-weak: #fde8e8;
  --side: #121826; --side-text: #c9d1e3; --side-muted: #7d879c;
  --sans: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sidew: 208px; --panelw: 380px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14.5px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01", "tnum"; letter-spacing: -0.005em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono, .kpi b, .stat b, .ptable td.n, .badge-n { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: 0; }

/* ---------- 框架 ---------- */
#shell { display: flex; min-height: 100%; }
#side { width: var(--sidew); flex: 0 0 var(--sidew); background: var(--side); color: var(--side-text);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 14px 10px; }
#side[hidden] { display: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: #fff; padding: 4px 8px 16px; letter-spacing: 0.02em; }
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--brand), #6a8cff);
  color: #fff; display: grid; place-items: center; font-family: var(--mono); font-weight: 700; font-size: 14px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--side-muted); padding: 14px 10px 4px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--side-text); font-size: 14px; }
nav a .ic { width: 18px; text-align: center; opacity: .85; }
nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
nav a.on { background: var(--brand); color: #fff; }
.me { border-top: 1px solid rgba(255,255,255,.08); padding: 10px 8px 2px; font-size: 13px; color: var(--side-muted); }
.me a { color: var(--side-text); }
#mainwrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 8px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; }
#topbar[hidden] { display: none; }
#quick { display: flex; gap: 6px; flex-wrap: wrap; }
#quick a { font-size: 13px; padding: 5px 11px; border: 1px solid var(--line); border-radius: 7px; color: var(--text); background: var(--card); white-space: nowrap; }
#quick a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
#quick a.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
#ptoggle { position: relative; font-size: 13px; }
#ptoggle.on { border-color: var(--brand); color: var(--brand); }
#badge { position: absolute; top: -6px; right: -6px; background: var(--bad); color: #fff; border-radius: 99px; font: 700 11px/18px var(--mono); min-width: 18px; padding: 0 5px; text-align: center; }
.mobile-only { display: none; }
main { width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px 20px 60px; }
#panel { width: var(--panelw); flex: 0 0 var(--panelw); background: var(--card); border-left: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
#panel[hidden] { display: none; }
.ptabs { display: flex; align-items: center; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.ptabs a { padding: 5px 12px; border-radius: 7px; color: var(--text); font-weight: 500; }
.ptabs a.on { background: var(--brand-weak); color: var(--brand); }
.ptabs a:hover { text-decoration: none; }
#pclose { border: 0; padding: 4px 8px; }
#pbody { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- 通用 ---------- */
h1 { font-size: 21px; font-weight: 650; letter-spacing: -0.015em; margin: 2px 0 14px; }
h2, .h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 22px 0 8px; }
h2 .n { color: var(--text); font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.b { font-weight: 700; }
.okc { color: var(--ok); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.cols > div > h2:first-child { margin-top: 4px; }
.stat { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; }
.sub { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 10px 0 2px; border-top: 1px dashed var(--line); padding-top: 6px; }
.alert { background: var(--warn-weak); color: var(--warn); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
button, .btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 7px; cursor: pointer; display: inline-block; }
button:hover, .btn:hover { border-color: #c5cad3; text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
button.bad { color: var(--bad); }
button.mini { font-size: 12px; padding: 3px 9px; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--text); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand-weak); border-color: var(--brand); }
textarea { min-height: 100px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.form { max-width: 640px; }
.narrow { max-width: 380px; margin: 60px auto; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 6px 0; color: var(--text); font-size: 13px; }
.inline input { width: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs a { padding: 4px 11px; border-radius: 99px; border: 1px solid var(--line); color: var(--text); font-size: 13px; background: var(--card); }
.tabs a.on { background: var(--text); color: #fff; border-color: var(--text); }
.tabs a:hover { text-decoration: none; }
.list { padding: 0; overflow: hidden; }
.list .it { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--text); }
.list .it:last-child { border-bottom: 0; }
.list .it:hover { background: #fafbfc; text-decoration: none; }
.it .t { flex: 1; min-width: 0; }
.it .t div:first-child { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.tag.task { background: var(--brand-weak); color: var(--brand); }
.tag.review { background: #f1e8ff; color: #6d28d9; }
.tag.request { background: var(--warn-weak); color: var(--warn); }
.st { font-size: 12px; padding: 2px 9px; border-radius: 6px; white-space: nowrap; background: var(--bg); color: var(--muted); }
.st.todo, .st.pending { background: var(--bg); color: var(--text); }
.st.doing { background: var(--brand-weak); color: var(--brand); }
.st.submitted { background: var(--warn-weak); color: var(--warn); }
.st.returned { background: var(--bad-weak); color: var(--bad); }
.st.done { background: var(--ok-weak); color: var(--ok); }
.ps-signed, .ps-active, .cs-approved, .cs-handed { background: var(--ok-weak); color: var(--ok); }
.ps-talking, .ps-sent, .cs-filed, .cs-collecting, .cs-categorized { background: var(--brand-weak); color: var(--brand); }
.ps-paused, .ps-lost, .cs-denied, .cs-dropped { background: var(--bg); color: var(--muted); }
.overdue { color: var(--bad); }
.body { white-space: pre-wrap; word-break: break-word; }
.meta { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.files { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.files a { font-size: 14px; }
.timeline .c { border-left: 3px solid var(--line); padding: 4px 0 10px 14px; margin-left: 4px; }
.timeline .c.submit { border-color: var(--warn); }
.timeline .c.approve, .timeline .c.done { border-color: var(--ok); }
.timeline .c.return { border-color: var(--bad); }
.timeline .c .h { font-size: 13px; color: var(--muted); }
.timeline .c .h b { color: var(--text); }
.bot { background: #f3f0ff; border-radius: 6px; padding: 1px 6px; color: #5b21b6; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.feed .f { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.feed .f:last-child { border-bottom: 0; }
.copy { display: flex; gap: 8px; }
.copy input { font-size: 13px; font-family: var(--mono); }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff;
  padding: 10px 18px; border-radius: 8px; z-index: 30; max-width: 90vw; }
#toast.err { background: var(--bad); }
.empty { padding: 20px; text-align: center; color: var(--muted); }

/* ---------- 总览 ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 6px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--text); }
.kpi:hover { text-decoration: none; border-color: var(--brand); }
.kpi b { display: block; font-size: 26px; font-weight: 600; line-height: 1.1; }
.kpi span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.ptable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.ptable th { text-align: right; font-weight: 500; font-size: 11.5px; color: var(--muted); padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ptable th:first-child, .ptable td:first-child { text-align: left; }
.ptable td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.ptable tr:last-child td { border-bottom: 0; }
.ptable td.n.hot { color: var(--bad); font-weight: 700; }
.ptable td.n.zero { color: #b8bec9; }
.ptable .grp { text-align: center; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); border-bottom: 0; padding-bottom: 0; }
.scroll-x { overflow-x: auto; }

/* ---------- 客户资料 ---------- */
.ck { border-bottom: 1px solid var(--line); padding: 10px 0; }
.ck:last-of-type { border-bottom: 0; }
.ck .t { flex: 1; font-weight: 500; }
.st.ck-missing { background: var(--bg); color: var(--muted); }
.st.ck-uploaded { background: var(--warn-weak); color: var(--warn); }
.st.ck-ok { background: var(--ok-weak); color: var(--ok); }
.st.ck-redo { background: var(--bad-weak); color: var(--bad); }
.file { font-size: 14px; margin-top: 4px; word-break: break-all; }
.ckact { margin-top: 6px; gap: 8px; }
label.btn { color: var(--text); margin: 0; font-size: 14px; }
label.btn.up { background: var(--brand-weak); border-color: var(--brand-weak); color: var(--brand); }
#stageSel { width: auto; }
#progress { position: sticky; top: 60px; z-index: 4; }

/* ---------- AI 与消息 ---------- */
.ai { display: grid; grid-template-columns: 260px 1fr; gap: 12px; align-items: start; }
.convs { max-height: 70vh; overflow: auto; }
.convs .it.on { background: var(--brand-weak); }
#msgs { max-height: 62vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.msg { padding: 9px 12px; border-radius: 10px; max-width: 92%; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--brand-weak); white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--bg); }
.msg h3, .msg h4, .doc h3, .doc h4 { margin: 8px 0 4px; font-size: 15px; }
.msg ul, .doc ul { margin: 4px 0; padding-left: 20px; }
.msg pre, .doc pre { background: #fff; border: 1px solid var(--line); padding: 8px; border-radius: 6px; overflow: auto; white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; }
.msg table, .doc table { border-collapse: collapse; font-size: 13px; margin: 6px 0; }
.msg td, .doc td { border: 1px solid var(--line); padding: 4px 8px; }
code { background: var(--bg); padding: 0 4px; border-radius: 4px; font-family: var(--mono); font-size: .92em; }
.compose { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fafbfc; }
.compose textarea { min-height: 70px; }
.who-pick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.who-pick label { margin: 0; display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: 13px; color: var(--text); background: #fff; cursor: pointer; }
.who-pick input { width: auto; margin: 0; }
.who-pick label:has(input:checked) { background: var(--brand); color: #fff; border-color: var(--brand); }
.mbox { display: flex; gap: 6px; }
.mbox a { font-size: 13px; padding: 3px 10px; border-radius: 99px; color: var(--muted); }
.mbox a.on { background: var(--text); color: #fff; }
.mbox a:hover { text-decoration: none; }
.m { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
.m.unread { border-color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); }
.m.todo { box-shadow: inset 3px 0 0 var(--warn); }
.m.hl { outline: 2px solid var(--brand); }
.m .h { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.m .h b { color: var(--text); }
.m .body { margin: 4px 0 6px; }
.m .rcp { font-size: 12px; color: var(--muted); }
.m .rcp .d { color: var(--ok); }
.pai #msgs { max-height: none; flex: 1; border: 0; padding: 0; }
.pai { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.pai textarea { min-height: 70px; }

/* ---------- 手机 ---------- */
@media (max-width: 1100px) {
  #panel:not([hidden]) { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
}
@media (max-width: 860px) {
  body { font-size: 16px; }
  #shell { display: block; }
  #side { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; width: auto; z-index: 15; padding: 0;
    flex-direction: row; border-top: 1px solid rgba(255,255,255,.08); padding-bottom: env(safe-area-inset-bottom); }
  #side .brand, #side .me, nav .grp { display: none; }
  nav { flex-direction: row; overflow-x: auto; gap: 0; -webkit-overflow-scrolling: touch; }
  nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 7px 12px; border-radius: 0; white-space: nowrap; min-width: 64px; align-items: center; }
  nav a .ic { font-size: 18px; width: auto; }
  nav a.on { background: transparent; color: #fff; box-shadow: inset 0 2px 0 var(--brand); }
  .mobile-only { display: flex; }
  #topbar { padding: 8px 12px; }
  #quick { flex-wrap: nowrap; overflow-x: auto; }
  #ptxt { display: none; }
  main { padding: 14px 12px 90px; }
  h1 { font-size: 19px; }
  .two, .cols { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi b { font-size: 20px; }
  .ai { grid-template-columns: 1fr; }
  .convs { max-height: 160px; order: 2; }
  .grid { grid-template-columns: 1fr; }
  .it { flex-wrap: wrap; }
  input, textarea, select { font-size: 16px; }
  button, .btn, label.btn { padding: 10px 14px; }
  .narrow { margin: 20px auto; }
  #panel:not([hidden]) { width: 100%; left: 0; }
}

/* 面板打开时主区变窄：按主区宽度自动改成单列 */
main { container-type: inline-size; }
@container (max-width: 920px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@container (max-width: 560px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.ptable td:first-child { white-space: nowrap; }

html, body { overflow-x: hidden; }
#mainwrap, main { max-width: 100%; }

/* 提意见 */
#fbbtn { position: fixed; right: 18px; bottom: 18px; z-index: 12; border-radius: 99px; padding: 8px 14px; box-shadow: 0 4px 14px rgba(0,0,0,.12); font-size: 13px; }
#fbbtn[hidden], #fbmodal[hidden] { display: none; }
#fbmodal { position: fixed; inset: 0; background: rgba(15,20,30,.35); z-index: 40; display: grid; place-items: center; padding: 16px; }
.fbbox { width: min(520px, 100%); max-height: 86vh; overflow: auto; margin: 0; }
.fb { border-top: 1px solid var(--line); padding: 8px 0; font-size: 13.5px; }
.fbst { font-size: 12px; padding: 1px 8px; border-radius: 6px; }
.fbst.open { background: var(--warn-weak); color: var(--warn); } .fbst.doing { background: var(--brand-weak); color: var(--brand); }
.fbst.done { background: var(--ok-weak); color: var(--ok); } .fbst.wontfix { background: var(--bg); color: var(--muted); }
@media (max-width: 860px) { #fbbtn { bottom: 76px; right: 12px; } }
