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

:root {
  --primary: #132146;
  --primary-light: #1e3264;
  --secondary: #8e9b77;
  --secondary-light: #a3b08c;
  --cream: rgba(239, 225, 214, 0.3);
  --bg: #f7f6f3;
  --white: #ffffff;
  --text: #1a1a1a;
  --text-light: #555555;
  --border: #e5e2dc;
  --shadow: 0 2px 16px rgba(19, 33, 70, 0.08);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.chat-header {
  background: var(--primary);
  color: var(--white);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.chat-header .logo {
  width: 44px;
  height: 44px;
  background: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-header .logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
}

.chat-header .info { flex: 1; }
.chat-header .info h1 { font-size: 16px; font-weight: 600; }
.chat-header .info p { font-size: 12px; opacity: 0.8; }

/* Hotline button */
.hotline-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--secondary);
  color: var(--white);
  border-radius: 24px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.hotline-btn:hover { background: var(--secondary-light); }

/* New chat button */
.new-chat-btn {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  background: transparent;
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.new-chat-btn:hover { background: rgba(255,255,255,0.15); }

/* Connection status */
.connection-status {
  text-align: center;
  font-size: 12px;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: all 0.3s;
}

.connection-status.connecting {
  padding: 6px;
  max-height: 30px;
  background: #fff3cd;
  color: #856404;
}

.connection-status.error {
  padding: 6px;
  max-height: 30px;
  background: #f8d7da;
  color: #721c24;
}

.connection-status.success {
  padding: 6px;
  max-height: 30px;
  background: #d4edda;
  color: #155724;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.message {
  display: flex;
  gap: 8px;
  max-width: 82%;
  animation: fadeIn 0.3s ease;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  align-self: flex-end;
}

.message .avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 3px;
}

.message.bot .avatar {
  background: var(--white);
  border: 1px solid var(--border);
}

.message.user .avatar {
  background: var(--primary);
  color: var(--white);
}

/* Bubble wrap for timestamp */
.message .bubble-wrap {
  display: flex;
  flex-direction: column;
}

.message.user .bubble-wrap { align-items: flex-end; }

.msg-time {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 3px;
  padding: 0 4px;
  opacity: 0.7;
}

/* Bubble */
.message .bubble {
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 14px;
  word-break: break-word;
}

/* Markdown content inside bubbles */
.message .bubble p { margin: 0 0 6px; }
.message .bubble p:last-child { margin-bottom: 0; }
.message .bubble strong { font-weight: 600; color: var(--primary); }
.message .bubble em { font-style: italic; }
.message .bubble ul { margin: 4px 0; padding-left: 18px; list-style: disc; }
.message .bubble ul li { margin: 2px 0; }
.message .bubble ul li.numbered { list-style: decimal; }
.message .bubble h3, .message .bubble h4 { margin: 6px 0 3px; font-weight: 600; }
.message .bubble a { color: var(--secondary); text-decoration: underline; word-break: break-all; }
.message.user .bubble strong { color: inherit; }
.message.user .bubble a { color: #c8d8c0; }

/* Chat images */
.chat-image {
  margin-bottom: 6px;
  border-radius: 12px;
  overflow: hidden;
  max-width: 240px;
}

.chat-image img {
  width: 100%;
  display: block;
  border-radius: 12px;
}

/* Streaming cursor */
.streaming-bubble::after {
  content: '▊';
  animation: blink 0.8s infinite;
  color: var(--secondary);
  font-weight: 300;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.message.bot .bubble {
  background: var(--cream);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.user .bubble {
  background: var(--primary);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

/* Scroll to bottom */
.scroll-bottom {
  position: fixed;
  bottom: 160px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--white);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  z-index: 5;
  color: var(--text);
}

.scroll-bottom.visible {
  opacity: 1;
  transform: translateY(0);
}

.scroll-bottom:hover {
  background: var(--secondary);
  color: var(--white);
  border-color: var(--secondary);
}

/* Typing indicator */
.typing {
  display: none;
  align-items: center;
  gap: 8px;
  max-width: 80%;
  padding: 0 16px;
}

.typing.active { display: flex; }

.typing .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--white);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.typing .avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 3px;
}

.typing .dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.typing .dots span {
  width: 7px;
  height: 7px;
  background: var(--text-light);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing .dots span:nth-child(2) { animation-delay: 0.2s; }
.typing .dots span:nth-child(3) { animation-delay: 0.4s; }

/* Input area */
.chat-input {
  padding: 10px 16px;
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-actions {
  display: flex;
  gap: 2px;
  align-self: center;
}

.action-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-light);
  transition: background 0.2s;
}

.action-btn:hover { background: var(--bg); }

.chat-input textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.2s;
}

.chat-input textarea:focus { border-color: var(--secondary); }

.chat-input > button {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.chat-input > button:hover { background: var(--secondary); }
.chat-input > button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Image preview */
.image-preview {
  display: none;
  padding: 8px 16px 0;
  background: var(--white);
  position: relative;
}

.image-preview.active { display: block; }

.image-preview img {
  max-height: 80px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.image-preview button {
  position: absolute;
  top: 4px;
  left: 80px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Suggestions */
.suggestions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 16px 8px;
  background: var(--white);
  animation: fadeIn 0.3s ease;
}

.suggestions button {
  padding: 7px 12px;
  border: 1px solid var(--secondary);
  border-radius: 18px;
  background: var(--white);
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.suggestions button:hover {
  background: var(--secondary);
  color: var(--white);
  border-color: var(--secondary);
}

/* Payment QR */
.payment-qr { margin-top: 10px; }

.qr-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.qr-card h4 { color: var(--primary); margin-bottom: 10px; }

.qr-image {
  width: 200px;
  height: 200px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

.qr-info {
  text-align: left;
  font-size: 13px;
  line-height: 1.8;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 10px;
}

.qr-info code {
  background: var(--primary);
  color: var(--white);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
}

.qr-note {
  font-size: 12px;
  color: var(--text-light);
  line-height: 1.5;
  margin-bottom: 10px;
}

.check-payment-btn {
  padding: 8px 20px;
  background: var(--secondary);
  color: var(--white);
  border: none;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.check-payment-btn:hover { background: var(--primary); }

.payment-success {
  margin-top: 10px;
  padding: 10px;
  background: #d4edda;
  color: #155724;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}

/* Powered by */
.powered-by {
  text-align: center;
  padding: 6px;
  font-size: 11px;
  color: var(--text-light);
  background: var(--white);
  border-top: 1px solid var(--border);
}

.powered-by a {
  color: var(--secondary);
  text-decoration: none;
  font-weight: 600;
}

.powered-by a:hover { text-decoration: underline; }

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Mobile responsive */
@media (max-width: 600px) {
  .message { max-width: 90%; }
  .chat-header { padding: 10px 12px; }
  .chat-header .info h1 { font-size: 14px; }
  .hotline-btn span { display: none; }
  .hotline-btn { padding: 8px; }
  .chat-messages { padding: 10px; }
  .chat-input { padding: 8px 10px; }
  .suggestions { padding: 4px 10px 6px; }
  .scroll-bottom { bottom: 140px; right: 12px; }
}

/* Widget mode */
body.widget-mode { border-radius: 12px; overflow: hidden; }
body.widget-mode .chat-header { padding: 10px 14px; }
body.widget-mode .chat-header .logo { width: 34px; height: 34px; }
body.widget-mode .chat-header .info h1 { font-size: 14px; }
body.widget-mode .hotline-btn span { display: none; }
body.widget-mode .hotline-btn { padding: 7px; }
body.widget-mode .powered-by { padding: 4px; font-size: 10px; }
