:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --panel-2: #f8f9f6;
  --line: #e2e5df;
  --text: #1d2420;
  --muted: #69726c;
  --brand: #128c5e;
  --brand-ink: #ffffff;
  --brand-soft: #e3f4ec;
  --agent: #2f6fd6;
  --agent-soft: #e6eefb;
  --warn: #a8640a;
  --warn-soft: #fff1dc;
  --danger: #c23b33;
  --danger-soft: #fdecea;
  --hot: #d9480f;
  --night: #6b4fbb;
  --night-soft: #efeafb;
  --bubble-in: #ffffff;
  --bubble-ai: #dcf5e7;
  --bubble-agent: #e3ecfb;
  --chat-bg: #eef0eb;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --panel: #1a1f1c; --panel-2: #202622; --line: #2c3430; --text: #e6ebe7; --muted: #95a09a;
    --brand: #25b07b; --brand-ink: #0b130f; --brand-soft: #16362a; --agent: #6b9cf0; --agent-soft: #1b2a44;
    --warn: #f0a640; --warn-soft: #3a2a10; --danger: #ef6b62; --danger-soft: #3a1714; --hot: #ff8a50;
    --night: #b29cf5; --night-soft: #2a2340;
    --bubble-in: #232a26; --bubble-ai: #1d3b2d; --bubble-agent: #1f2d47; --chat-bg: #151a17;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
#appView { height: 100%; display: flex; flex-direction: column; overflow-x: hidden; }
.hidden { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=search], input[type=password], input[type=url], input[type=time], input[type=number], textarea, select {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; width: 100%; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); }
select { width: auto; }
small { color: var(--muted); font-weight: normal; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.spacer { flex: 1; }

/* 登录 */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card button { padding: 9px; }

header { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.pill.ok { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }
.pill.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.stats { display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.stats b { color: var(--text); font-size: 14px; margin-left: 3px; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 600; font-size: 13px; }
.switch input { display: none; }
.switch .track { width: 38px; height: 22px; border-radius: 99px; background: var(--line); position: relative; transition: .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { left: 19px; }
.me { display: flex; gap: 4px; align-items: center; }
.me button { padding: 4px 8px; font-size: 13px; }
#dutyBtn.on { color: var(--brand); border-color: var(--brand); }
#dutyBtn.off { color: var(--warn); border-color: var(--warn); }

nav { display: flex; gap: 2px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
nav button { border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 9px 12px; background: none; color: var(--muted); }
nav button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

#banner { display: none; margin: 12px 16px 0; padding: 14px 16px; border-radius: var(--radius); background: var(--warn-soft); border: 1px solid var(--warn); gap: 16px; align-items: center; flex-wrap: wrap; }
#banner.show { display: flex; }
#banner img { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }
#banner .code { font-size: 28px; letter-spacing: 4px; font-weight: 700; font-family: ui-monospace, monospace; }

main { flex: 1; min-height: 0; min-width: 0; display: flex; }
.view { display: none; flex: 1; min-height: 0; min-width: 0; }
.view.active { display: flex; }

/* 会话列表 */
.list-pane { width: 360px; flex-shrink: 0; min-width: 0; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-tools { padding: 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filters button { padding: 2px 10px; font-size: 12px; border-radius: 99px; }
.filters select { font-size: 12px; padding: 2px 6px; border-radius: 99px; }
.filters button.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.holiday-strip { font-size: 12px; background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 6px 10px; line-height: 1.6; cursor: pointer; }
.holiday-strip.soft { background: var(--warn-soft); color: var(--warn); }
#convList { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--brand-soft); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 700; color: var(--muted); flex-shrink: 0; position: relative; font-size: 15px; }
.avatar .fl { position: absolute; right: -4px; bottom: -4px; font-size: 16px; line-height: 1; }
.conv .body { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv .time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.conv .last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 4px; line-height: 18px; white-space: nowrap; }
.tag.ai { background: var(--brand-soft); color: var(--brand); }
.tag.human { background: var(--warn-soft); color: var(--warn); }
.tag.hot { background: var(--hot); color: #fff; }
.tag.warm { background: var(--warn-soft); color: var(--warn); }
.tag.muted { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.tag.agent { background: var(--agent-soft); color: var(--agent); }
.tag.holiday { background: var(--danger-soft); color: var(--danger); }
.tag.none { background: var(--danger-soft); color: var(--danger); }
.lt { font-size: 11px; white-space: nowrap; padding: 0 5px; border-radius: 4px; }
.st-work { color: var(--brand); background: var(--brand-soft); }
.st-off { color: var(--muted); background: var(--panel-2); }
.st-night { color: var(--night); background: var(--night-soft); }
.st-weekend { color: var(--warn); background: var(--warn-soft); }
.st-holiday { color: var(--danger); background: var(--danger-soft); }
.unread { background: var(--brand); color: var(--brand-ink); border-radius: 99px; font-size: 11px; padding: 0 6px; font-weight: 700; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

/* 聊天 */
.chat-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-head .title { flex: 1; min-width: 200px; }
.chat-head .title b { font-size: 15px; }
.chat-head .sub { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chat-head .tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chat-head select { font-size: 13px; padding: 4px 6px; }
.linkbtn { border: none; background: none; color: var(--agent); padding: 0 2px; font-size: 12px; cursor: pointer; }
.back { display: none; }
.local-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 14px; background: var(--panel-2); border-bottom: 1px solid var(--line); font-size: 13px; }
.local-bar .clock { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.notice { padding: 6px 14px; font-size: 12px; border-bottom: 1px solid var(--line); }
.notice.red { background: var(--danger-soft); color: var(--danger); }
.notice.amber { background: var(--warn-soft); color: var(--warn); }
.notice.green { background: var(--brand-soft); color: var(--brand); }
.notice.gray { background: var(--panel-2); color: var(--muted); }
.lead { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 14px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); font-size: 12px; }
.lead div span { color: var(--muted); margin-right: 4px; }
#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: min(78%, 640px); min-width: 0; padding: 7px 10px 5px; border-radius: 10px; box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; }
.msg.customer { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.msg.ai { align-self: flex-end; background: var(--bubble-ai); border-top-right-radius: 2px; }
.msg.agent { align-self: flex-end; background: var(--bubble-agent); border-top-right-radius: 2px; }
.msg.system { align-self: center; background: transparent; box-shadow: none; color: var(--muted); font-size: 12px; padding: 2px 8px; text-align: center; }
.msg .tr { margin-top: 5px; padding-top: 5px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 13px; }
.msg .tr b { font-weight: 600; font-size: 11px; margin-right: 4px; color: var(--brand); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; }
.composer { display: flex; gap: 8px; padding: 10px 14px; background: var(--panel); border-top: 1px solid var(--line); align-items: flex-end; }
.composer .box { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.composer textarea { resize: none; height: 64px; }
.composer .opts { display: flex; gap: 12px; align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.composer .btns { display: flex; flex-direction: column; gap: 6px; }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }

/* 通用页面 */
.page { flex: 1; overflow-y: auto; padding: 16px; }
.page-inner { max-width: 1280px; margin: 0 auto; }
.page h2 { font-size: 16px; margin: 0 0 4px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 8px; font-size: 14px; }
.editors { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.editors textarea { height: calc(100vh - 300px); min-height: 360px; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.6; resize: vertical; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.saved { color: var(--brand); font-size: 13px; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 10px; font-size: 13px; margin-bottom: 10px; }
.kv > span:nth-child(odd) { color: var(--muted); }

/* 节假日 */
.hol-day { margin-bottom: 14px; }
.hol-day h4 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.hol-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.hol-item.today { border-color: var(--danger); background: var(--danger-soft); }
.hol-item .c { min-width: 120px; font-weight: 600; }
.hol-item .n { flex: 1; min-width: 160px; }
.hol-item .n small { display: block; }
.hol-item .cs { display: flex; gap: 4px; flex-wrap: wrap; max-width: 420px; }
.hol-item .cs button { font-size: 12px; padding: 1px 8px; border-radius: 99px; }

/* 话术测试 */
.sandbox { display: grid; grid-template-columns: 1fr 340px; gap: 14px; }
.sb-chat { display: flex; flex-direction: column; height: calc(100vh - 230px); min-height: 420px; background: var(--chat-bg); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
#sbMessages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.sb-chat .composer textarea { height: 48px; }
pre.json { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12px; white-space: pre-wrap; word-break: break-all; max-height: 360px; overflow: auto; margin: 0; }

/* 业务员表格 */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; background: var(--panel-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.dotst { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; background: var(--line); }
.dotst.on { background: var(--brand); }

/* 设置 */
.modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-bottom: 16px; }
.mode-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; background: var(--panel); cursor: pointer; display: flex; gap: 10px; }
.mode-card.active { border-color: var(--brand); background: var(--brand-soft); }
.mode-card b { display: block; margin-bottom: 2px; }
.mode-card p { margin: 0; font-size: 12px; color: var(--muted); }

/* 弹窗 */
dialog { border: none; border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.25); width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; max-height: 85vh; overflow-y: auto; }
.dialog-body.narrow { max-width: 420px; }
dialog:has(.narrow) { width: min(420px, calc(100vw - 32px)); }
.dialog-body h3 { margin: 0; }
.dialog-body label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.dialog-body label.check { flex-direction: row; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.inline { display: flex; align-items: center; gap: 6px; }
.field .label { font-size: 13px; margin-bottom: 6px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; user-select: none; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.chip .x { margin-left: 6px; opacity: .6; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 10; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; }

@media (max-width: 900px) {
  .stats { display: none; }
  .list-pane { width: 100%; border-right: none; }
  .chat-pane { display: none; }
  #view-chats.open .list-pane { display: none; }
  #view-chats.open .chat-pane { display: flex; }
  .back { display: inline-block; }
  .editors, .sandbox, .grid2 { grid-template-columns: 1fr; }
  .editors textarea { height: 50vh; }
  .msg { max-width: 88%; }
  .chat-head .title { min-width: 0; }
}

/* 参数设置 */
h3.sec { font-size: 14px; margin: 14px 0 8px; }
.cfg h3 { margin-bottom: 10px; }
.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
.cfg fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 12px; margin: 0; min-width: 0; }
.cfg legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
.cfg-row { display: grid; grid-template-columns: 150px 1fr; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; }
.cfg-row > span:first-child { color: var(--muted); }
.cfg-row.col { grid-template-columns: 1fr; gap: 4px; }
.cfg-row.check { display: flex; align-items: flex-start; gap: 8px; }
.cfg-row.check > span:first-child, .cfg-row.check span { color: var(--text); }
.cfg-row.check small { display: block; color: var(--muted); }
.cfg-row input[type=number] { width: 90px; }
.cfg-row input[type=time] { width: 120px; }
.cfg-row select { max-width: 100%; }
.cfg-row textarea { resize: vertical; }
.cfg .inline { flex-wrap: wrap; color: var(--muted); }
.cfg .inline label.check { display: inline-flex; gap: 4px; align-items: center; }
@media (max-width: 900px) {
  .cfg-grid { grid-template-columns: 1fr; }
  .cfg-row { grid-template-columns: 1fr; gap: 4px; }
}
.cfg .inline input[type=text] { width: 160px; }
#baseForm, #accountForm { margin-bottom: 14px; }
.cfg fieldset.dim { opacity: .55; }
.cfg code { font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; word-break: break-all; }
.ok-text { color: var(--brand); }
.cfg-row input[type=password] { width: 100%; }
.load-more { text-align: center; margin-bottom: 6px; }
#diagOut { margin-top: 10px; }
