/* CSS Variables for Light Theme */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-input: #ffffff;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border-color: #e5e7eb;
  --border-light: #d1d5db;
  --accent-color: #4f46e5;
  --accent-hover: #4338ca;
  --chip-bg: #f8fafc;
  --chip-border: #d1d5db;
  --bubble-bot: #ffffff;
  --bubble-user: #4f46e5;
  --shadow-light: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-medium: 0 4px 12px rgba(0,0,0,0.15);
}

/* Dark Theme Variables */
[data-theme="dark"] {
  --bg-primary: #1f2937;
  --bg-secondary: #111827;
  --bg-input: #374151;
  --text-primary: #f9fafb;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;
  --border-color: #374151;
  --border-light: #4b5563;
  --chip-bg: #374151;
  --chip-border: #4b5563;
  --bubble-bot: #374151;
  --bubble-user: #4f46e5;
  --shadow-light: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-medium: 0 4px 12px rgba(0,0,0,0.4);
}

/* Reset for iframe embedding */
html, body {
  margin: 0;
  padding: 0;
}

/* General Container - NO WHITE SPACE */
#chat-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 420px;
  height: 550px;
  margin: 0; /* Remove margin for iframe embedding */
  background: var(--bg-primary);
  border-radius: 16px;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.10);
  transition: all 0.3s ease;
}

/* Only add margin when NOT embedded (standalone mode) */
body:not(.widget-embedded) #chat-container {
  margin: 20px auto;
}

/* Header with theme toggle - Always stays fixed */
#chat-header {
  background: var(--accent-color);
  color: white;
  padding: 14px;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  min-height: 56px;
  box-sizing: border-box;
}

.bot-info {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bot-status {
  font-size: 12px;
  color: #e0e7ff;
}

.theme-toggle {
  position: absolute;
  right: 14px;
  background: rgba(255,255,255,0.2);
  border: none;
  border-radius: 8px;
  color: white;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.05);
}

/* Breadcrumb */
.breadcrumb {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 8px 16px;
  font-size: 12px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 500;
  flex-shrink: 0;
}

/* Messages Area */
#messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-secondary);
  scroll-behavior: smooth;
}

/* Message row */
.row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 90%;
  animation: slideInMessage 0.4s ease;
}

.row.bot { justify-content: flex-start; }
.row.user { justify-content: flex-end; margin-left: auto; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: 0 0 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  box-shadow: var(--shadow-light);
  animation: avatarPulse 2s ease-in-out infinite;
}

.avatar--bot { background: var(--accent-color); }
.avatar--user { background: #e5e7eb; color: #374151; }

@keyframes avatarPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Message bubbles */
.message {
  padding: 12px 16px;
  border-radius: 16px;
  max-width: 75%;
  font-size: 14px;
  line-height: 1.4;
  animation: fadeIn 0.3s ease;
  box-shadow: var(--shadow-light);
}

.message.user {
  background: var(--bubble-user);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  animation: slideInRight 0.3s ease;
}

.message.bot {
  background: var(--bubble-bot);
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  animation: slideInLeft 0.3s ease;
  border: 1px solid var(--border-color);
}

/* Refined bubble inside .row */
.row .bubble {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: var(--shadow-light);
  background: var(--bubble-bot);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.row.user .bubble {
  background: var(--bubble-user);
  color: #fff;
  border-color: transparent;
}

/* Chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 0;
  margin: 0;
  background: transparent;
  border: none;
  animation: slideInChips 0.5s ease;
}
@keyframes slideInChips {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.chip {
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-light);
  position: relative;
  overflow: hidden;
}
.chip:hover {
  border-color: var(--accent-color);
  background: #eef2ff;
  color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: var(--shadow-medium);
}
.chip:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}
.chip:active {
  transform: translateY(0);
  box-shadow: var(--shadow-light);
}

/* Input area */
.input-area {
  display: flex;
  padding: 12px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.attachment-btn {
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  color: var(--text-secondary);
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 16px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attachment-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  background: #f8fafc;
}
#input {
  flex: 1;
  border: 1px solid var(--border-light);
  border-radius: 20px;
  padding: 12px 16px;
  outline: none;
  font-size: 14px;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: all 0.2s ease;
  min-height: 20px;
  max-height: 120px;
  resize: none;
  font-family: inherit;
  line-height: 1.4;
}
#input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
#input::placeholder { color: var(--text-muted); }
#send {
  border: none;
  background: var(--accent-color);
  color: white;
  padding: 12px;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#send:hover {
  background: var(--accent-hover);
  transform: translateY(-1px) scale(1.05);
  box-shadow: var(--shadow-medium);
}
#send:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}
#send:active { transform: translateY(0) scale(1); }

/* Typing indicator */
.typing {
  display: flex;
  gap: 8px;
  margin: 8px 36px;
  align-items: center;
  color: var(--text-muted);
  font-size: 12px;
}
.typing-text { font-style: italic; }
.typing span.dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: blink 1.4s infinite ease-in-out both;
}
.typing span.dot:nth-child(3) { animation-delay: 0.2s; }
.typing span.dot:nth-child(4) { animation-delay: 0.4s; }

/* Animations */
@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}
@keyframes slideInLeft {
  from { transform: translateX(-20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideInRight {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInMessage {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Mobile responsiveness rules omitted here for brevity (unchanged) ---- */

/* Mobile-specific widget embedded styles */
.widget-embedded {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}
.widget-embedded #chat-container {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
  margin: 0 !important;
  /* ✅ FIX: keep rounded corners inside iframe */
  border-radius: 16px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1) !important;
  padding-left: 8px !important;
  padding-right: 8px !important;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
@media (prefers-contrast: high) {
  #chat-container { border: 2px solid; }
  .chip { border-width: 2px; }
}

/* Utility */
.hidden { display: none !important; }
