#chat-widget {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 320px;
  background: var(--card-bg);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 999;
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 1;
  transform: translateY(0);
}

.chat-hidden {
  opacity: 0 !important;
  transform: translateY(120%) !important;
  pointer-events: none !important;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.chat-header {
  background: var(--accent-color);
  color: white;
  padding: 12px 16px;
  font-weight: bold;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-body {
  padding: 12px;
  max-height: 240px;
  overflow-y: auto;
  background: #f8f9fa;
  /* ✅ Always light */
}

.chat-msg {
  margin-bottom: 10px;
  font-size: 0.92rem;
  line-height: 1.5;
  word-break: break-word;
}

.chat-msg.bot {
  color: #007bff;
}

.chat-msg.user {
  text-align: right;
  color: #333;
}

.chat-input-area {
  display: flex;
  border-top: 1px solid #eee;
  background: #fff;
}

#chat-input {
  flex: 1;
  border: none;
  padding: 10px 12px;
  font-size: 0.9rem;
  outline: none;
  background: white;
  color: #333;
}

#chat-send {
  background: var(--blue);
  color: white;
  border: none;
  padding: 10px 16px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.3s ease;
}

#chat-send:hover {
  background: var(--dark-blue);
}

/* ✅ ปุ่มเดียว toggle ทั้งเปิด/ปิด ไม่แสดง X */
#chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--blue);
  color: white;
  border: none;
  padding: 12px 14px;
  border-radius: 50%;
  font-size: 1.2rem;
  z-index: 999;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.3s ease, background-color 0.3s ease;
}

#chat-toggle.open {
  transform: rotate(180deg);
  background-color: var(--accent-color);
}

#chat-toggle:hover {
  background: var(--dark-blue);
}

/* ✅ Dark Mode Support */
html[data-theme="dark"] .chat-msg.user {
  color: #eee;
}

/* ❌ ไม่ override สีพื้นหลัง .chat-body หรือ input */
html[data-theme="dark"] .chat-body {
  background: #f8f9fa;
  /* ✅ Keep same as light */
}

html[data-theme="dark"] .chat-input-area {
  background: #fff;
  border-top: 1px solid #eee;
}

html[data-theme="dark"] #chat-input {
  background: #fff;
  color: #333;
}

html[data-theme="dark"] #chat-send {
  background: var(--accent-color);
}

html[data-theme="dark"] #chat-toggle {
  background: var(--accent-color);
}
/* Professional World-Class Chat Widget */
.chat-widget-modern {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  z-index: 9999;
  animation: chatSlideUp 0.3s ease-out;
}

@keyframes chatSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-header-modern {
  background: linear-gradient(135deg, #0b74e3 0%, #1a89f5 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-avatar svg {
  width: 22px;
  height: 22px;
}

.chat-title-text {
  display: block;
  font-weight: 600;
  font-size: 16px;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.9;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: pulse 2s infinite;
}

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

.chat-close {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.chat-close:hover {
  background: rgba(255,255,255,0.3);
}

.chat-body-modern {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-welcome {
  text-align: center;
  padding: 20px 0;
}

.welcome-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.chat-welcome h3 {
  margin: 0 0 8px;
  color: #1e293b;
  font-size: 18px;
}

.chat-welcome p {
  margin: 0;
  color: #64748b;
  font-size: 14px;
}

.chat-msg {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-msg.bot {
  background: white;
  color: #1e293b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  align-self: flex-start;
}

.chat-msg.user {
  background: linear-gradient(135deg, #0b74e3 0%, #1a89f5 100%);
  color: white;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

.chat-msg.agent {
  background: #10b981;
  color: white;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

.chat-msg-first {
  margin-top: 8px;
}

.msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-time {
  font-size: 10px;
  opacity: 0.6;
}

.chat-input-area-modern {
  padding: 16px;
  background: white;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 12px;
}

.chat-input-modern {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input-modern:focus {
  border-color: #0b74e3;
}

.chat-send-modern {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, #0b74e3 0%, #1a89f5 100%);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.chat-send-modern:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(11, 116, 227, 0.4);
}

.chat-send-modern svg {
  width: 20px;
  height: 20px;
}

/* Chat Toggle Button */
.chat-toggle-modern {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #0b74e3 0%, #1a89f5 100%);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px rgba(11, 116, 227, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 9998;
}

.chat-toggle-modern:hover {
  transform: scale(1.1);
  box-shadow: 0 15px 35px rgba(11, 116, 227, 0.5);
}

.chat-toggle-modern svg {
  width: 28px;
  height: 28px;
}

.chat-toggle-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #ef4444;
  color: white;
  font-size: 12px;
  font-weight: 600;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: badgePop 0.3s ease-out;
}

@keyframes badgePop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: white;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  width: fit-content;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Mobile responsive */
@media (max-width: 480px) {
  .chat-widget-modern {
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }
  
  .chat-toggle-modern {
    bottom: 80px;
    right: 16px;
  }
}
