/* 济钢产品客服 - 聊天页样式 */
:root {
  --primary: #3053a4;
  --primary-dark: #243f7e;
  --primary-light: #4c70bf;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #2c3e50;
  --text-soft: #6b7280;
  --border: #e5e7eb;
  --user-bubble: linear-gradient(135deg, #3053a4 0%, #4c70bf 100%);
  --bot-bubble: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 14px rgba(48,83,164,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.kefu-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  min-width: 280px;
  background: var(--bg);
}

/* ===== 顶部 Header ===== */
.kefu-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  box-shadow: var(--shadow-md);
  z-index: 10;
}
.kefu-avatar {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  font-size: 20px;
  flex-shrink: 0;
}
.kefu-title-wrap { flex: 1; min-width: 0; }
.kefu-name { font-size: 15px; font-weight: 600; line-height: 1.2; }
.kefu-subtitle { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.kefu-status {
  width: 8px; height: 8px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.3);
  flex-shrink: 0;
}

/* ===== 消息区 ===== */
.kefu-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.kefu-messages::-webkit-scrollbar { width: 6px; }
.kefu-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 3px; }

.msg {
  display: flex;
  gap: 8px;
  max-width: 90%;
  animation: fade-in 0.3s ease;
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot { align-self: flex-start; }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.msg.user .msg-avatar { background: var(--primary); color: white; }
.msg.bot .msg-avatar { background: #fff7e6; border: 1px solid #ffd700; }

.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.user .msg-bubble {
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg.bot .msg-bubble {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

/* markdown 简化样式 */
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; color: var(--primary); }
.msg-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.92em;
}
.msg-bubble a { color: var(--primary); text-decoration: underline; }
.msg-bubble img {
  max-width: 200px;
  max-height: 150px;
  width: auto;
  height: auto;
  object-fit: cover;
  border-radius: 6px;
  margin: 6px 6px 6px 0;
  cursor: zoom-in;
  border: 1px solid #e5e7eb;
  transition: transform 0.15s, box-shadow 0.15s;
  display: inline-block;
  vertical-align: middle;
}
.msg-bubble img:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 16px rgba(48,83,164,0.18);
}

/* ===== Lightbox 蒙层 ===== */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
  animation: fade-in 0.18s ease;
  padding: 20px;
}
.lightbox img {
  max-width: 95vw;
  max-height: 92vh;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 26px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.3); }
.lightbox-caption {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  max-width: 80vw;
  text-align: center;
}
.msg-bubble h2 {
  font-size: 15px; font-weight: 600; margin: 6px 0 4px;
  color: var(--primary);
}
.msg-bubble h3 {
  font-size: 14px; font-weight: 600; margin: 5px 0 3px;
  color: var(--text);
}
.msg-bubble ol, .msg-bubble ul { padding-left: 1.4em; margin: 4px 0; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble li::marker { color: var(--primary); }

/* 思考中动画 */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.thinking > span:not(.thinking-label) {
  width: 6px; height: 6px;
  background: var(--text-soft);
  border-radius: 50%;
  animation: pulse 1.4s infinite;
  display: inline-block;
}
.thinking > span:not(.thinking-label):nth-child(2) { animation-delay: 0.2s; }
.thinking > span:not(.thinking-label):nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}
.thinking-bubble {
  padding: 6px 10px !important;
  line-height: 1 !important;
  white-space: normal !important;
  min-height: 0;
}
.thinking-label {
  margin-left: 6px;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1;
}


.msg-sources {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 4px;
}

/* ===== 快捷问题 chips ===== */
.kefu-quick {
  flex: 0 0 auto;
  padding: 0 16px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 80px;
  overflow-y: auto;
}
.kefu-quick:empty { display: none; }
.chip {
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--primary);
  cursor: pointer;
  transition: all 0.15s;
}
.chip:hover { background: var(--primary); color: white; }

/* ===== 底部输入 ===== */
.kefu-input-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: white;
  border-top: 1px solid var(--border);
}
#input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  max-height: 100px;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}
#input:focus { border-color: var(--primary); background: white; }
#send-btn {
  width: 36px; height: 36px;
  flex-shrink: 0;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
#send-btn:hover { background: var(--primary-dark); }
#send-btn:active { transform: scale(0.92); }
#send-btn:disabled { background: #c7d3e6; cursor: not-allowed; }

/* ===== 错误提示条 ===== */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(220, 38, 38, 0.92);
  color: white;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 100;
  animation: fade-in 0.2s ease;
}

/* ===== 小屏适配 ===== */
@media (max-width: 360px) {
  .kefu-header { padding: 10px 12px; gap: 8px; }
  .kefu-avatar { width: 32px; height: 32px; font-size: 17px; }
  .kefu-messages { padding: 10px; }
  .msg { max-width: 95%; }
  .kefu-input-bar { padding: 8px; }
}
