:root {
  --navy: #0f2a4a;
  --navy-2: #173a63;
  --accent: #1f5fae;
  --accent-soft: #e6eef9;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --line: #e2e6ec;
  --text: #1c2430;
  --text-2: #536070;
  --muted: #8592a3;
  --green: #1a7f4b;
  --green-soft: #e3f4ea;
  --red: #c62f2f;
  --amber: #a56200;
  --amber-soft: #fff3dc;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --bubble-out: #dff3e6;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* 登录 */
.login { min-height: 100%; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy), #1d4c86); padding: 20px; }
.login-card { background: #fff; padding: 28px; border-radius: 14px; width: 100%; max-width: 360px; display: grid; gap: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.brand-big { font-weight: 800; font-size: 26px; letter-spacing: 1px; color: var(--navy); }
.brand-big span { display: block; font-size: 14px; font-weight: 500; color: var(--text-2); letter-spacing: 0; margin-top: 2px; }
.login-card label { display: grid; gap: 6px; color: var(--text-2); font-size: 13px; }
.form-err { color: var(--red); min-height: 18px; font-size: 13px; }

/* 外框 */
.app { display: flex; height: 100vh; height: 100dvh; }
.side { width: 200px; flex: none; background: var(--navy); color: #cfdaea; display: flex; flex-direction: column; padding: 16px 10px; gap: 4px; }
.brand { color: #fff; font-weight: 800; font-size: 20px; padding: 4px 10px 16px; letter-spacing: .5px; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: #9fb3cf; letter-spacing: 0; }
.side a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #cfdaea; text-decoration: none; position: relative; }
.side a:hover { background: rgba(255,255,255,.06); }
.side a.active { background: var(--navy-2); color: #fff; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.side .ico { width: 18px; text-align: center; opacity: .85; }
.badge { margin-left: auto; background: #e5484d; color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; min-width: 20px; text-align: center; }
.badge:empty { display: none; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; display: grid; gap: 8px; }
.conn { color: #9fb3cf; line-height: 1.5; }
.conn .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #8592a3; }
.conn .dot.ok { background: #34c47c; }
.linkbtn { background: none; border: 0; color: #9fb3cf; text-align: left; padding: 0; cursor: pointer; }
.linkbtn:hover { color: #fff; }

.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.demo-bar { background: var(--amber-soft); color: #6b4a00; padding: 7px 18px; font-size: 13px; border-bottom: 1px solid #f0dcae; }
.demo-bar a { margin-left: 8px; color: #6b4a00; font-weight: 600; }
.view { flex: 1; min-height: 0; overflow: auto; }
.page { padding: 20px 24px 40px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 22px; }
.sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

/* 通用控件 */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c5cdd8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #194f92; }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=password], input[type=tel], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b9d0ee; border-color: var(--accent); }
textarea { resize: vertical; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip .n { opacity: .7; margin-left: 4px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; }
.filters .grow { flex: 1; min-width: 180px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.muted { color: var(--muted); }
.pill { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: #eef1f5; color: var(--text-2); white-space: nowrap; }
.pill.s0 { background: #e6eef9; color: #1d4f91; }
.pill.s1 { background: #f1e8fb; color: #6a3aa0; }
.pill.s2 { background: var(--amber-soft); color: var(--amber); }
.pill.won { background: var(--green-soft); color: var(--green); }
.pill.lost { background: #f1f2f4; color: #6b7583; }
.pill.ad { background: #fdeee6; color: #a4421a; }
.pill.unread { background: #e5484d; color: #fff; font-weight: 700; }
.pill.wait { background: #fff0f0; color: var(--red); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* 总览 */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; display: block; }
a.kpi:hover { border-color: #b9c6d8; }
.kpi .label { color: var(--text-2); font-size: 13px; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.alert .val { color: var(--red); }
.grid2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid2 > *, .settings-grid > * { min-width: 0; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: #eef1f5; }
.tip { position: absolute; pointer-events: none; background: #1c2430; color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; z-index: 5; }
.tip.on { opacity: 1; }
.bars-h { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 64px 1fr 120px; gap: 8px; align-items: center; font-size: 13px; }
.bar-track { height: 14px; background: #f1f3f6; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-row .num { text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }
.todo-list { display: grid; }
.todo-list > * { min-width: 0; }
.todo { display: flex; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid #f0f2f5; text-decoration: none; color: inherit; }
.todo:last-child { border-bottom: 0; }
.todo:hover { background: #f8fafc; }
.todo .who { font-weight: 600; }
.todo .txt { color: var(--text-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.todo .grow { flex: 1; min-width: 0; }

/* 表格 */
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
td { padding: 9px 12px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td .name { font-weight: 600; cursor: pointer; color: var(--text); }
td .name:hover { color: var(--accent); }
td .phone { color: var(--muted); font-size: 12px; }
td select { padding: 4px 6px; font-size: 13px; width: auto; }
td .ellip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.ad-edit input { padding: 5px 8px; font-size: 13px; }

/* 收件箱 */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 320px; height: 100%; min-height: 0; }
.inbox > * { min-height: 0; }
.ilist { border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; }
.ilist-head { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.ilist-items { overflow: auto; flex: 1; }
.iitem { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid #f1f3f6; cursor: pointer; text-decoration: none; color: inherit; }
.iitem:hover { background: #f8fafc; }
.iitem.active { background: var(--accent-soft); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--navy-2); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.iitem .grow { flex: 1; min-width: 0; }
.iitem .top { display: flex; justify-content: space-between; gap: 6px; }
.iitem .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iitem .tm { font-size: 11.5px; color: var(--muted); flex: none; }
.iitem .last { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 2px 0 4px; }
.iitem.unread .last { color: var(--text); font-weight: 600; }
.iitem .pills { display: flex; gap: 4px; flex-wrap: wrap; }

.chat { display: flex; flex-direction: column; background: #eef2f6; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.chat-head .grow { flex: 1; min-width: 0; }
.chat-head .nm { font-weight: 700; }
.chat-head .ph { font-size: 12px; color: var(--muted); }
.back-btn, .profile-btn, .profile-close { display: none; }
.msgs { flex: 1; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.day-sep { align-self: center; background: #fff; color: var(--text-2); font-size: 11.5px; padding: 3px 10px; border-radius: 8px; margin: 8px 0; box-shadow: 0 1px 0 rgba(0,0,0,.04); }
.bubble { max-width: min(560px, 78%); padding: 8px 11px 5px; border-radius: 10px; background: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.06); white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); }
.bubble .meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 3px; }
.bubble a { word-break: break-all; }
.composer { background: #fff; border-top: 1px solid var(--line); padding: 10px 12px; display: grid; gap: 8px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; }
.window-note { font-size: 12px; color: var(--amber); background: var(--amber-soft); padding: 6px 10px; border-radius: 6px; }
.window-note.closed { color: var(--red); background: #fff0f0; }
.ai-row { display: flex; gap: 8px; }
.ai-row input { flex: 1; }

.profile { background: #fff; border-left: 1px solid var(--line); overflow: auto; padding: 14px; display: grid; gap: 12px; align-content: start; }
.src-card { background: #fff7f2; border: 1px solid #f6d9c7; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; }
.src-card.direct { background: #f4f6f9; border-color: var(--line); }
.src-card b { display: block; font-size: 13.5px; margin: 2px 0; }
.src-card .k { color: var(--muted); }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12px; color: var(--text-2); font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.saved { font-size: 12px; color: var(--muted); }
.sizes { display: flex; gap: 6px; flex-wrap: wrap; }
.size-chip { background: var(--accent-soft); color: #1d4f91; border-radius: 6px; padding: 3px 8px; font-size: 12.5px; font-weight: 600; }
.nochat { display: grid; place-items: center; color: var(--muted); height: 100%; text-align: center; padding: 20px; }

/* 设置 */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.status-line { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed #eef0f3; font-size: 13px; }
.status-line:last-child { border-bottom: 0; }
.ok-tag { color: var(--green); font-weight: 600; }
.no-tag { color: var(--red); font-weight: 600; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; background: #f3f5f8; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12.5px; word-break: break-all; }
.steps { padding-left: 18px; margin: 0; line-height: 1.7; font-size: 13px; color: var(--text-2); }
.form-grid { display: grid; gap: 10px; }

/* 弹窗 + 提示 */
.modal { position: fixed; inset: 0; background: rgba(15, 25, 40, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 440px; max-height: 90vh; overflow: auto; display: grid; gap: 12px; }
.modal-card h3 { margin: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: all .2s; z-index: 60; pointer-events: none; max-width: 90vw; }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--red); }

/* 平板 */
@media (max-width: 1180px) {
  .inbox { grid-template-columns: 290px minmax(0, 1fr); }
  .inbox .profile { display: none; }
  .inbox.show-profile .profile { display: grid; position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 92vw); z-index: 30; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
  .profile-btn { display: inline-block; }
  .profile-close { display: inline-block; justify-self: end; }
  .grid2 { grid-template-columns: 1fr; }
}
/* 手机 */
@media (max-width: 760px) {
  .app { flex-direction: column-reverse; }
  .side { width: auto; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 0; justify-content: space-around; }
  .brand, .side-foot { display: none; }
  .side a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; justify-content: center; text-align: center; }
  .side .ico { font-size: 16px; }
  .badge { position: absolute; top: 2px; right: 12%; margin: 0; font-size: 10px; padding: 0 5px; }
  .page { padding: 14px 12px 30px; }
  .settings-grid { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .inbox .chat { display: none; }
  .inbox.has-chat .ilist { display: none; }
  .inbox.has-chat .chat { display: flex; }
  .back-btn { display: inline-block; }
  .kpi .val { font-size: 22px; }
  .bubble { max-width: 88%; }
  .filters input, .filters select { flex: 1 1 140px; }
  .hide-m { display: none; }
}
