/* ==========================================================================
   智能客服 Agent —— 共用样式
   ========================================================================== */

:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --border: #e6e8f0;
  --border-strong: #d5d9e6;
  --text: #16181f;
  --text-2: #4b5162;
  --muted: #878ea1;
  --primary: #2f5bff;
  --primary-dark: #1f45e0;
  --primary-soft: #eef2ff;
  --success: #0f9d6e;
  --success-soft: #e7f7f1;
  --warn: #d97706;
  --warn-soft: #fef4e6;
  --danger: #e5484d;
  --danger-soft: #fdeded;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 40, .05);
  --shadow: 0 6px 24px rgba(20, 24, 40, .07);
  --shadow-lg: 0 18px 48px rgba(20, 24, 40, .12);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d3d7e3; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #bcc2d2; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- 通用组件 ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  cursor: pointer;
  font-weight: 500;
  transition: .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: #b9c0d4; background: #fbfcfe; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(47, 91, 255, .25);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: #f0f2f8; border-color: transparent; }

.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-danger { color: var(--danger); border-color: #f3c9ca; }
.btn-danger:hover { background: var(--danger-soft); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: #f0f2f8;
  color: var(--text-2);
  white-space: nowrap;
}
.chip-primary { background: var(--primary-soft); color: var(--primary-dark); }
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }

.field { display: block; margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; line-height: 1.5; }

.input, textarea.input, select.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  transition: .15s ease;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 91, 255, .12); }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.6; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 13px;
}

.toast-wrap {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #16181f;
  color: #fff;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease;
  max-width: 460px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: #10896b; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(16, 20, 34, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: auto;
  padding: 22px;
}
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ==========================================================================
   访客对话页
   ========================================================================== */

.chat-app {
  height: 100vh;
  display: grid;
  grid-template-columns: 268px 1fr;
  max-width: 1400px;
  margin: 0 auto;
  background: var(--panel);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* 侧栏 */
.cside {
  border-right: 1px solid var(--border);
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.cside-head { padding: 18px 16px 14px; border-bottom: 1px solid var(--border); }
.brand-row { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #2f5bff, #6b8cff);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; flex: none;
  box-shadow: 0 4px 12px rgba(47, 91, 255, .28);
}
.brand-name { font-weight: 650; font-size: 14.5px; letter-spacing: .2px; }
.brand-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

.cside-body { flex: 1; overflow-y: auto; padding: 12px 10px; min-height: 0; }
.cside-label {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  padding: 8px 6px 6px; letter-spacing: .4px;
}
.sess-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 10px; border: 1px solid transparent;
  background: transparent; cursor: pointer; margin-bottom: 3px;
  transition: .12s ease;
}
.sess-item:hover { background: #eff1f8; }
.sess-item.active { background: #fff; border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.sess-item .t { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess-item .m { font-size: 11.5px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; align-items: center; }

.cside-foot { padding: 12px; border-top: 1px solid var(--border); }

/* 主区 */
.cmain { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chead {
  padding: 13px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(1.4) blur(6px);
}
.chead .title { font-weight: 650; font-size: 15px; }
.chead .spacer { flex: 1; }
.online-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--success);
  box-shadow: 0 0 0 3px rgba(15, 157, 110, .16); display: inline-block;
}
.notice-bar {
  padding: 9px 22px; font-size: 12.5px;
  background: var(--warn-soft); color: #8a5a06;
  border-bottom: 1px solid #f6e2c0;
}

.cscroll { flex: 1; overflow-y: auto; padding: 22px; min-height: 0; scroll-behavior: smooth; }
.cinner { max-width: 780px; margin: 0 auto; }

.msg-row { display: flex; gap: 10px; margin-bottom: 18px; align-items: flex-start; }
.msg-row.user { flex-direction: row-reverse; }

.avatar {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}
.avatar.ai { background: linear-gradient(135deg, #2f5bff, #6b8cff); }
.avatar.me { background: #8d93a6; }

.bubble-col { min-width: 0; max-width: 84%; }
.msg-row.user .bubble-col { display: flex; flex-direction: column; align-items: flex-end; }

.bubble {
  padding: 11px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.68;
}
.bubble.ai {
  background: #fff; border: 1px solid var(--border);
  border-top-left-radius: 5px; box-shadow: var(--shadow-sm);
}
.bubble.me {
  background: var(--primary); color: #fff;
  border-top-right-radius: 5px; box-shadow: 0 2px 10px rgba(47, 91, 255, .22);
}
.bubble.error { background: var(--danger-soft); border-color: #f5cdcd; color: #a02b2f; }

.msg-meta {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-bottom: 6px; font-size: 11.5px; color: var(--muted);
}
.msg-row.user .msg-meta { justify-content: flex-end; }

.msg-tools {
  display: flex; gap: 4px; align-items: center; margin-top: 7px;
  opacity: 0; transition: opacity .15s ease;
}
.msg-row:hover .msg-tools, .msg-tools.pin { opacity: 1; }
.icon-btn {
  border: 1px solid var(--border); background: #fff; border-radius: 8px;
  padding: 3px 8px; font-size: 12px; color: var(--text-2); cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
}
.icon-btn:hover { border-color: var(--border-strong); background: #fbfcfe; }
.icon-btn.on { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.kb-refs {
  margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px;
  font-size: 12px; color: var(--muted);
}
.kb-refs summary { cursor: pointer; list-style: none; user-select: none; }
.kb-refs summary::-webkit-details-marker { display: none; }
.kb-refs summary::before { content: "▸ "; }
.kb-refs[open] summary::before { content: "▾ "; }
.kb-refs ul { margin: 6px 0 0; padding-left: 4px; list-style: none; }
.kb-refs li { padding: 3px 0; display: flex; gap: 8px; align-items: baseline; }
.kb-refs .s { color: var(--success); font-weight: 600; flex: none; font-size: 11px; }

.msg-images {
  margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; max-width: 100%;
}
.msg-images img {
  width: 132px; height: 132px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--border); cursor: zoom-in; background: #f6f7fb;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.msg-images img:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(30, 40, 90, 0.14); }

.sys-line { text-align: center; margin: 16px 0; }
.sys-line span {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  background: #f0f2f8; color: var(--text-2); font-size: 12px;
}

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #b8bed0;
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* 快捷问题 */
.quick { padding: 0 22px 4px; }
.quick-inner { max-width: 780px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 8px; }
.quick-btn {
  border: 1px solid var(--border-strong); background: #fff; border-radius: 999px;
  padding: 6px 13px; font-size: 12.5px; color: var(--text-2); cursor: pointer;
  transition: .13s ease;
}
.quick-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* 输入区 */
.composer { padding: 12px 22px 18px; border-top: 1px solid var(--border); background: #fff; }
.composer-inner {
  max-width: 780px; margin: 0 auto;
  border: 1px solid var(--border-strong); border-radius: 16px;
  background: #fff; padding: 8px 8px 8px 14px;
  display: flex; align-items: flex-end; gap: 10px;
  transition: .15s ease; box-shadow: var(--shadow-sm);
}
.composer-inner:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 91, 255, .1); }
.composer textarea {
  flex: 1; border: none; outline: none; resize: none; background: transparent;
  max-height: 132px; min-height: 24px; line-height: 1.6; padding: 5px 0;
}
.composer .send {
  width: 36px; height: 36px; border-radius: 11px; border: none; cursor: pointer;
  background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center;
  flex: none; transition: .15s ease;
}
.composer .send:hover { background: var(--primary-dark); }
.composer .send:disabled { background: #cfd5e6; cursor: not-allowed; }
.composer .stop { background: #40465a; }
.composer .stop:hover { background: #2c3143; }
.composer-foot {
  max-width: 780px; margin: 8px auto 0; display: flex; justify-content: space-between;
  font-size: 11.5px; color: var(--muted); gap: 10px; flex-wrap: wrap;
}

/* 转人工 / 评分卡片 */
.card-inline {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel-2); padding: 16px; margin: 4px 0 18px;
}
.card-inline h4 { margin: 0 0 4px; font-size: 14px; }
.card-inline .sub { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.stars { display: flex; gap: 6px; margin: 4px 0 12px; }
.star {
  font-size: 26px; line-height: 1; cursor: pointer; color: #dfe3ee;
  transition: .12s ease; background: none; border: none; padding: 0;
}
.star:hover, .star.on { color: #f5a623; transform: scale(1.08); }

.radio-row { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-pill {
  border: 1px solid var(--border-strong); background: #fff; border-radius: 999px;
  padding: 5px 13px; font-size: 12.5px; cursor: pointer; color: var(--text-2);
}
.radio-pill.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }

@media (max-width: 900px) {
  .chat-app { grid-template-columns: 1fr; border: none; }
  .cside { display: none; }
  .cside.mobile-open { display: flex; position: fixed; inset: 0; z-index: 800; }
  .bubble-col { max-width: 92%; }
  .cscroll { padding: 16px; }
  .composer { padding: 10px 14px 14px; }
  .chead { padding: 11px 14px; }
  .quick { padding: 0 14px 4px; }
}
