:root {
  --bg: #0a0e16;
  --panel: #111827;
  --panel-2: #162032;
  --panel-3: #1b2740;
  --line: #223049;
  --line-soft: #1a2437;
  --text: #e7eefa;
  --muted: #8d9cb5;
  --muted-2: #64748b;
  --accent: #4c7dff;
  --accent-soft: rgba(76, 125, 255, 0.14);
  --ok: #2ecc9b;
  --warn: #f0b23c;
  --danger: #ef6b6b;
  --purple: #a78bfa;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(2, 6, 18, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #24314a; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100vh; }
.rail {
  width: 60px; flex: 0 0 60px; background: #0c111c; border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 8px;
}
.brand {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(140deg, #4c7dff, #2f5fd0); color: #fff; margin-bottom: 6px;
  box-shadow: 0 6px 16px rgba(76, 125, 255, .35);
}
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item, .rail-btn {
  width: 40px; height: 38px; border-radius: 10px; border: 1px solid transparent; background: transparent;
  color: var(--muted); display: grid; place-items: center; cursor: pointer; position: relative; transition: .15s;
}
.nav-item:hover, .rail-btn:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #9dbbff; border-color: rgba(76,125,255,.32); }
.nav-item .badge {
  position: absolute; top: 2px; right: 1px; min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px;
  background: var(--danger); color: #fff; font-size: 10px; line-height: 15px; text-align: center; font-weight: 600;
}
.rail-foot { display: flex; flex-direction: column; gap: 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; flex: 0 0 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; border-bottom: 1px solid var(--line-soft); background: #0d1320;
}
.topbar-left { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.topbar h1 { font-size: 15px; margin: 0; font-weight: 600; letter-spacing: .3px; }
.topbar .sub { color: var(--muted-2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.stats { display: flex; gap: 14px; margin-right: 4px; }
.stat { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.stat b { color: var(--text); font-size: 13px; font-weight: 600; }
.stat i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }
.stat.warn i { background: var(--warn); }
.me { display: flex; align-items: center; gap: 8px; padding-left: 10px; border-left: 1px solid var(--line); }
.me .avatar { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: #08101d; }
.me .who { font-size: 12px; line-height: 1.25; }
.me .who span { display: block; color: var(--muted-2); font-size: 11px; }

.view { flex: 1; min-height: 0; overflow: hidden; }

/* ---------- 通用组件 ---------- */
.btn {
  height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); cursor: pointer; display: inline-flex; align-items: center;
  gap: 6px; transition: .15s; white-space: nowrap;
}
.btn:hover { background: var(--panel-3); border-color: #2c3d5c; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { height: 27px; padding: 0 9px; font-size: 12px; }
.btn.tiny { height: 23px; padding: 0 7px; font-size: 11px; border-radius: 6px; }
.btn.danger { color: #ffdada; border-color: #5b2a33; background: #2a1620; }
.btn.danger:hover { background: #381a26; }
.btn.ok { color: #05231a; background: var(--ok); border-color: var(--ok); font-weight: 600; }
.btn.block { width: 100%; justify-content: center; height: 38px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 6px;
  font-size: 11px; background: var(--panel-3); color: var(--muted); border: 1px solid var(--line);
}
.tag.blue { background: var(--accent-soft); color: #a7c2ff; border-color: rgba(76,125,255,.3); }
.tag.green { background: rgba(46,204,155,.13); color: #6fe3bd; border-color: rgba(46,204,155,.3); }
.tag.warn { background: rgba(240,178,60,.13); color: #f5cb7c; border-color: rgba(240,178,60,.3); }
.tag.red { background: rgba(239,107,107,.13); color: #ffa3a3; border-color: rgba(239,107,107,.3); }
.tag.purple { background: rgba(167,139,250,.14); color: #c4b1ff; border-color: rgba(167,139,250,.3); }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,204,155,.14); }
.dot.off { background: var(--muted-2); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(240,178,60,.14); }

.card { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--radius); }
.pad { padding: 16px; }
.muted { color: var(--muted); }
.tiny { font-size: 11px; color: var(--muted-2); }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.empty { color: var(--muted-2); text-align: center; padding: 40px 10px; font-size: 13px; }
.section-title { font-size: 12px; color: var(--muted-2); letter-spacing: .6px; text-transform: uppercase; margin: 0 0 10px; }

/* ---------- 会话工作台 ---------- */
.workbench { display: grid; grid-template-columns: 300px minmax(0, 1fr) 318px; height: 100%; }
.col { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line-soft); }
.col:last-child { border-right: none; }
.col-head { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 8px; }
.filters { display: flex; gap: 4px; overflow-x: auto; }
.chip {
  padding: 4px 9px; border-radius: 7px; font-size: 12px; background: transparent; border: 1px solid transparent;
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.chip:hover { background: var(--panel-2); }
.chip.active { background: var(--panel-3); color: var(--text); border-color: var(--line); }
.search { display: flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; }
.search input { flex: 1; height: 30px; background: transparent; border: none; outline: none; font-size: 12.5px; }
.search svg { color: var(--muted-2); flex: 0 0 auto; }

.conv-list { flex: 1; overflow-y: auto; }
.conv { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); cursor: pointer; display: flex; gap: 10px; transition: .12s; }
.conv:hover { background: #131c2b; }
.conv.active { background: #17233a; box-shadow: inset 2px 0 0 var(--accent); }
.conv .cav {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 34px; display: grid; place-items: center;
  background: var(--panel-3); color: #b9c8e4; font-size: 13px; font-weight: 600;
}
.conv .cbody { min-width: 0; flex: 1; }
.conv .c1 { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.conv .cname { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .ctime { font-size: 10.5px; color: var(--muted-2); flex: 0 0 auto; }
.conv .c2 { display: flex; justify-content: space-between; gap: 6px; align-items: center; margin-top: 2px; }
.conv .cprev { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .count {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff;
  font-size: 10px; line-height: 16px; text-align: center; font-weight: 600; flex: 0 0 auto;
}
.conv .c3 { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { height: 52px; flex: 0 0 52px; border-bottom: 1px solid var(--line-soft); display: flex; align-items: center; justify-content: space-between; padding: 0 14px; gap: 10px; }
.chat-head .title { font-size: 13.5px; font-weight: 600; }
.chat-head .meta { font-size: 11px; color: var(--muted-2); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: radial-gradient(1200px 400px at 50% -10%, rgba(76,125,255,.06), transparent 60%); }
.msg { display: flex; gap: 8px; max-width: 78%; }
.msg .mav { width: 26px; height: 26px; border-radius: 7px; flex: 0 0 26px; display: grid; place-items: center; font-size: 11px; font-weight: 600; background: var(--panel-3); color: #b9c8e4; }
.msg .bubble { background: var(--panel-2); border: 1px solid var(--line-soft); padding: 8px 11px; border-radius: 10px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.msg .mtime { font-size: 10px; color: var(--muted-2); margin-top: 4px; }
.msg.out { align-self: flex-end; flex-direction: row-reverse; }
.msg.out .bubble { background: rgba(76,125,255,.16); border-color: rgba(76,125,255,.3); }
.msg.out .mav { background: rgba(76,125,255,.3); color: #cfe0ff; }
.msg.sys { align-self: center; max-width: 90%; }
.msg.sys .bubble { background: transparent; border: 1px dashed var(--line); color: var(--muted-2); font-size: 11.5px; padding: 5px 10px; }
.msg.sys .mav { display: none; }

.composer { border-top: 1px solid var(--line-soft); padding: 10px 12px; background: #0d1320; }
.phrase-bar { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.phrase-bar .p {
  font-size: 11.5px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.phrase-bar .p:hover { color: var(--text); border-color: #33507c; }
.composer textarea {
  width: 100%; min-height: 60px; max-height: 140px; resize: none; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; outline: none; font-size: 13px;
}
.composer textarea:focus { border-color: #37538a; }
.composer .send-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }

.side { border-left: 1px solid var(--line-soft); background: #0d1320; display: flex; flex-direction: column; }
.side-head { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; }
.side-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.kv { display: grid; grid-template-columns: 78px 1fr; gap: 6px 8px; font-size: 12.5px; }
.kv dt { color: var(--muted-2); }
.kv dd { margin: 0; color: var(--text); }
.price-line { display: flex; justify-content: space-between; font-size: 12.5px; padding: 4px 0; border-bottom: 1px dashed var(--line-soft); }
.price-line b { font-variant-numeric: tabular-nums; }
.panel-note { font-size: 11.5px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 8px; padding: 8px 10px; }

/* ---------- 表格/列表页 ---------- */
.page { height: 100%; overflow-y: auto; padding: 18px 20px 40px; }
.page-grid { display: grid; gap: 14px; }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.side-split { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 14px; height: 100%; min-height: 0; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th {
  text-align: left; font-weight: 500; color: var(--muted-2); font-size: 11.5px; padding: 8px 10px;
  border-bottom: 1px solid var(--line); background: #0f1725; position: sticky; top: 0; z-index: 1;
}
table.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tr:hover td { background: #121b2a; }
table.tbl tr.sel td { background: #16233a; }
.num { font-variant-numeric: tabular-nums; }

.group-card { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.group-card .gname { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.group-card .gscope { font-size: 12px; color: var(--muted); line-height: 1.7; }
.member-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.member-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 2px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line-soft); }

.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: grid; grid-template-columns: 74px 1fr; gap: 10px; position: relative; padding-bottom: 12px; }
.tl-item::before {
  content: ''; position: absolute; left: 78px; top: 15px; bottom: 0; width: 1px; background: var(--line);
}
.tl-item:last-child::before { display: none; }
.tl-item .t { font-size: 11px; color: var(--muted-2); text-align: right; padding-top: 2px; }
.tl-item .c { padding-left: 12px; position: relative; }
.tl-item .c::before {
  content: ''; position: absolute; left: -4px; top: 6px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--line); border: 1px solid #2b3a55;
}
.tl-item.buyer .c::before { background: #7f8ea8; }
.tl-item.seller .c::before { background: var(--accent); }
.tl-item.accept .c::before { background: var(--ok); }
.tl-item.reject .c::before { background: var(--danger); }
.tl-item .lbl { font-size: 12.5px; }
.tl-item .amt { font-weight: 600; font-variant-numeric: tabular-nums; }

.calc-box { background: #0b1220; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; }
.calc-box pre { margin: 0; font-size: 11.5px; color: #9fb2cf; white-space: pre-wrap; word-break: break-all; }

.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.kpi { padding: 13px 14px; }
.kpi .k { font-size: 11.5px; color: var(--muted-2); }
.kpi .v { font-size: 22px; font-weight: 600; margin-top: 4px; letter-spacing: .5px; }
.kpi .s { font-size: 11px; color: var(--muted-2); margin-top: 2px; }

.field-row { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 12.5px; }
.field-row > span { color: var(--muted); }
input.inp, select.inp, textarea.inp {
  width: 100%; height: 31px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  padding: 0 9px; outline: none; font-size: 12.5px;
}
textarea.inp { height: auto; padding: 7px 9px; resize: vertical; }
input.inp:focus, select.inp:focus { border-color: #3a5a95; }
.inp-unit { display: flex; align-items: center; gap: 6px; }
.inp-unit .u { color: var(--muted-2); font-size: 11.5px; white-space: nowrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line-soft); margin-bottom: 14px; }
.tab { padding: 8px 12px; font-size: 12.5px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- 模态 ---------- */
.modal-layer {
  position: fixed; inset: 0; background: rgba(4, 8, 16, .62); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 60; padding: 20px;
}
.modal { width: 460px; max-width: 100%; max-height: 86vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.modal-head { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; font-weight: 600; }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 8px; }
.modal .close { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; }

/* ---------- 登录 ---------- */
.login-layer {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 80;
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(76,125,255,.16), transparent 60%),
    radial-gradient(700px 500px at 85% 90%, rgba(46,204,155,.1), transparent 60%),
    #070b12;
}
.login-card { width: 372px; background: rgba(17,24,39,.92); border: 1px solid var(--line); border-radius: 16px; padding: 26px; box-shadow: var(--shadow); }
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login-logo { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; font-weight: 700; color: #fff; background: linear-gradient(140deg, #4c7dff, #2f5fd0); }
.login-brand h2 { margin: 0; font-size: 17px; }
.login-brand p { margin: 3px 0 0; font-size: 11.5px; color: var(--muted-2); }
.field { display: block; margin-bottom: 13px; }
.field span { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.field input { width: 100%; height: 38px; background: #0d1523; border: 1px solid var(--line); border-radius: 9px; padding: 0 11px; outline: none; }
.field input:focus { border-color: #3a5a95; }
.login-err { color: #ffa3a3; font-size: 12px; margin-top: 10px; min-height: 16px; }
.login-hint { margin-top: 14px; font-size: 11px; color: var(--muted-2); line-height: 1.7; }
.login-hint code { background: #0d1523; border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; color: #9fb2cf; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1b2740; border: 1px solid var(--line); color: var(--text); padding: 9px 16px; border-radius: 9px;
  font-size: 12.5px; opacity: 0; pointer-events: none; transition: .22s; z-index: 90; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: #5b2a33; background: #2a1620; color: #ffd0d0; }

/* ---------- 响应式 ---------- */
@media (max-width: 1280px) {
  .workbench { grid-template-columns: 264px minmax(0, 1fr) 288px; }
  .kpi-row { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .cols-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 980px) {
  .workbench { grid-template-columns: 1fr; }
  .col.side, .col.list { display: none; }
  .workbench.show-list { grid-template-columns: 1fr; }
  .side-split, .cols-2, .cols-3 { grid-template-columns: 1fr; }
}
