:root {
  --primary: #2563eb;
  --danger: #ef4444;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1a1a1a;
  --text-sub: #6b7280;
  --bubble-agent: #eff6ff;
  --bubble-visitor: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif; color: var(--text); background: var(--bg); }

/*
 * 所有带 hidden 属性的视图必须始终隐藏。
 * 浏览器的默认 [hidden] { display: none } 会被后面的 .workbench、.modal-mask
 * 等带 display 属性的类规则覆盖；使用 !important 保证登录态切换和弹窗状态正确。
 */
[hidden] { display: none !important; }

button { cursor: pointer; font-family: inherit; }

/* 登录 */
.login { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  display: flex; flex-direction: column; gap: 12px;
  width: 320px; padding: 28px;
  background: var(--panel); border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.08);
}
.login-card h2 { text-align: center; }
.login-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; }
.login-card input:focus { border-color: var(--primary); }
.login-card button { padding: 10px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 15px; }
.error { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* 工作台布局 */
.workbench { display: flex; height: 100vh; }
.sidebar { width: 300px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.me { display: flex; align-items: center; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); }
.me-name { font-weight: 600; }
.me-status { font-size: 12px; color: var(--text-sub); }
.logout { margin-left: auto; border: none; background: none; color: var(--text-sub); font-size: 12px; }

.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab { flex: 1; padding: 10px; border: none; background: none; font-size: 14px; color: var(--text-sub); }
.tab.active { color: var(--primary); font-weight: 600; border-bottom: 2px solid var(--primary); }

.conv-list { flex: 1; overflow-y: auto; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.conv-item:hover { background: #fafafa; }
.conv-item.active { background: #eff6ff; }
.conv-item .row1 { display: flex; justify-content: space-between; align-items: center; }
.conv-item .name { font-size: 14px; font-weight: 500; }
.conv-item .time { font-size: 11px; color: var(--text-sub); }
.conv-item .preview { font-size: 12px; color: var(--text-sub); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .badge { display: inline-block; background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; margin-left: 6px; }

/* 右栏 */
.main { flex: 1; display: flex; flex-direction: column; }
.empty-hint { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-sub); }
.chat-view { flex: 1; display: flex; flex-direction: column; }

.chat-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.visitor-name { font-weight: 600; }
.visitor-sub { font-size: 12px; color: var(--text-sub); }
.actions { display: flex; gap: 8px; }
.ghost { padding: 6px 12px; border: 1px solid var(--border); background: var(--panel); border-radius: 6px; font-size: 13px; }
.ghost.danger { color: var(--danger); border-color: #fca5a5; }
.primary { padding: 6px 14px; border: none; background: var(--primary); color: #fff; border-radius: 6px; font-size: 13px; }

.profile-card { padding: 12px 16px; background: #fafbfc; border-bottom: 1px solid var(--border); font-size: 13px; }
.profile-row { display: flex; gap: 12px; padding: 3px 0; }
.profile-row b { width: 70px; flex-shrink: 0; color: var(--text-sub); }
.profile-row input { flex: 1; border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; font-size: 13px; outline: none; }

.chat-messages { flex: 1; overflow-y: auto; padding: 16px; }
.msg { display: flex; margin-bottom: 12px; }
.msg.agent { justify-content: flex-end; }
.msg.visitor { justify-content: flex-start; }
.bubble { max-width: 70%; padding: 9px 12px; border-radius: 8px; font-size: 14px; line-height: 1.5; word-break: break-word; white-space: pre-wrap; }
.msg.agent .bubble { background: var(--bubble-agent); }
.msg.visitor .bubble { background: var(--bubble-visitor); border: 1px solid var(--border); }
.msg.system { justify-content: center; }
.msg.system .bubble { background: #f0f1f3; color: var(--text-sub); font-size: 12px; }
.bubble .quote { font-size: 13px; color: #666; background: rgba(0,0,0,.06); padding: 4px 8px; border-left: 3px solid #ccc; border-radius: 3px; margin-bottom: 6px; }
.bubble img { max-width: 220px; border-radius: 4px; cursor: zoom-in; display: block; }
.bubble .time { font-size: 11px; color: #b3b3b3; margin-top: 4px; text-align: right; }

.canned-panel { max-height: 160px; overflow-y: auto; background: var(--panel); border-top: 1px solid var(--border); padding: 8px; }
.canned-panel .item { padding: 6px 10px; font-size: 13px; border-radius: 6px; cursor: pointer; }
.canned-panel .item:hover { background: #f0f1f3; }

.emoji-panel { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; padding: 8px; background: var(--panel); border-top: 1px solid var(--border); max-height: 180px; overflow-y: auto; }
.emoji-panel span { font-size: 22px; text-align: center; cursor: pointer; padding: 4px; border-radius: 6px; }
.emoji-panel span:hover { background: #f0f1f3; }

.quote-bar { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: #fafbfc; border-top: 1px solid var(--border); font-size: 13px; color: #666; }
.quote-bar button { border: none; background: none; font-size: 18px; color: #999; }

.input-area { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--border); }
.tool-btn { border: none; background: none; font-size: 20px; padding: 4px; }
#input { flex: 1; border: 1px solid var(--border); border-radius: 6px; resize: none; outline: none; padding: 8px; font-size: 14px; max-height: 96px; }
.send-btn { border: none; background: var(--primary); color: #fff; padding: 8px 16px; border-radius: 6px; font-size: 14px; }

/* 转接弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 99; }
.modal { display: flex; flex-direction: column; gap: 12px; width: 360px; background: #fff; border-radius: 12px; padding: 20px; }
.modal h3 { font-size: 16px; }
.modal select, .modal input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; outline: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.preview-mask { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: flex; align-items: center; justify-content: center; z-index: 99; }
.preview-mask img { max-width: 92%; max-height: 92%; border-radius: 6px; }

/* 平板与窄屏：保持对话列表和输入区可用，避免工具按钮被挤压。 */
@media (max-width: 760px) {
  .sidebar { width: 220px; flex: 0 0 220px; }
  .me { padding: 12px 10px; }
  .chat-header { padding: 10px 12px; }
  .actions { gap: 4px; }
  .ghost { padding: 6px 8px; font-size: 12px; }
  .chat-messages { padding: 12px; }
  .bubble { max-width: 82%; }
  .input-area { gap: 4px; padding: 8px; }
  .send-btn { padding: 8px 11px; }
}

/* 手机端默认展示会话列表；打开会话后仅展示聊天窗口，避免两栏互相挤压。 */
@media (max-width: 560px) {
  .workbench { min-width: 0; }
  .sidebar { width: 100%; flex-basis: 100%; border-right: none; }
  .main { display: none; min-width: 0; }
  .workbench:has(.chat-view:not([hidden])) .sidebar { display: none; }
  .workbench:has(.chat-view:not([hidden])) .main { display: flex; width: 100%; }
  .chat-header { align-items: flex-start; gap: 8px; }
  .actions { flex-wrap: wrap; justify-content: flex-end; }
  .visitor-info { min-width: 0; }
  .visitor-name, .visitor-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tool-btn { font-size: 18px; }
  .modal { width: calc(100vw - 32px); }
}
