/* ============================================
   PREMIUM CHAT WIDGET - BIG BRAND STYLE
   Inspired by Intercom, Drift, Zendesk
   ============================================ */

:root {
  --aibot-primary: #6366f1;
  --aibot-secondary: #8b5cf6;
  --aibot-primary-grad: linear-gradient(135deg, var(--aibot-primary), var(--aibot-secondary));
  
  --aibot-bg: #ffffff;
  --aibot-surface: #f8fafc;
  --aibot-text: #1e293b;
  --aibot-text-secondary: #64748b;
  --aibot-border: #e2e8f0;
  --aibot-border-light: #f1f5f9;
  
  --aibot-shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --aibot-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --aibot-shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --aibot-shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
  --aibot-shadow-2xl: 0 25px 50px -12px rgba(0,0,0,0.25);
  
  --aibot-radius-sm: 8px;
  --aibot-radius-md: 12px;
  --aibot-radius-lg: 16px;
  --aibot-radius-xl: 24px;
  --aibot-radius-full: 9999px;
  
  --aibot-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  
  --aibot-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== BASE RESET ===== */
#aibot-root,
#aibot-root * {
  box-sizing: border-box !important;
  margin: 0;
  padding: 0;
}

#aibot-root {
  position: fixed !important;
  right: 20px !important;
  bottom: 20px !important;
  z-index: 2147483647 !important;
  font-family: var(--aibot-font) !important;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== LAUNCHER BUTTON ===== */
#aibot-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 18px;
  
  background: var(--aibot-primary-grad);
  color: #ffffff;
  border: none;
  border-radius: var(--aibot-radius-full);
  
  box-shadow: var(--aibot-shadow-lg);
  
  cursor: pointer;
  transition: var(--aibot-transition);
}

#aibot-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: var(--aibot-shadow-xl);
}

#aibot-btn:active {
  transform: translateY(0) scale(0.98);
}

#aibot-btn .aibot-launcher-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

#aibot-btn .aibot-launcher-ico {
  width: 20px;
  height: 20px;
  color: #ffffff;
}

#aibot-btn .aibot-launcher-text {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
}

/* Launcher Shapes */
#aibot-btn[data-shape="pill"] {
  border-radius: var(--aibot-radius-full);
  padding: 0 18px;
  height: 48px;
}

#aibot-btn[data-shape="circle"] {
  border-radius: var(--aibot-radius-full);
  width: 48px;
  height: 48px;
  padding: 0;
}

#aibot-btn[data-shape="square"] {
  border-radius: var(--aibot-radius-md);
  width: 48px;
  height: 48px;
  padding: 0;
}

/* ===== CHAT PANEL ===== */
#aibot-panel {
  position: fixed !important;
  right: 20px !important;
  bottom: 70px !important;
  left: auto !important;
  top: auto !important;
  margin: 0 !important;
  
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 550px;
  max-height: calc(100vh - 100px);
  
  background: var(--aibot-bg);
  border: 1px solid var(--aibot-border);
  border-radius: var(--aibot-radius-xl);
  
  box-shadow: var(--aibot-shadow-2xl);
  overflow: hidden;
  
  display: none;
  flex-direction: column;
  
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: 
    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#aibot-panel.open {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ===== HEADER ===== */
#aibot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  
  background: var(--aibot-bg);
  border-bottom: 1px solid var(--aibot-border);
}

#aibot-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

#aibot-title img {
  width: 40px;
  height: 40px;
  border-radius: var(--aibot-radius-md);
  object-fit: cover;
  background: var(--aibot-surface);
  border: 1px solid var(--aibot-border-light);
}

#aibot-title .t1 {
  font-weight: 700;
  font-size: 16px;
  color: var(--aibot-text);
  letter-spacing: -0.02em;
}

#aibot-title .t2 {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--aibot-text-secondary);
  margin-top: 2px;
}

#aibot-title .t2::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
  animation: aibot-online 2s ease-in-out infinite;
}

@keyframes aibot-online {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.aibot-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

#aibot-newchat,
#aibot-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  
  background: var(--aibot-surface);
  border: 1px solid var(--aibot-border);
  border-radius: var(--aibot-radius-sm);
  
  color: var(--aibot-text-secondary);
  cursor: pointer;
  transition: var(--aibot-transition);
}

#aibot-newchat:hover,
#aibot-close:hover {
  background: var(--aibot-border-light);
  color: var(--aibot-text);
  border-color: var(--aibot-border);
}

#aibot-newchat .aibot-ico {
  width: 18px;
  height: 18px;
}

#aibot-close {
  font-size: 18px;
  font-weight: 300;
}

/* ===== TABS ===== */
#aibot-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px;
  background: var(--aibot-bg);
  border-bottom: 1px solid var(--aibot-border);
}

.aibot-tab {
  flex: 1;
  padding: 10px 16px;
  
  background: transparent;
  border: none;
  border-radius: var(--aibot-radius-sm);
  
  font-weight: 600;
  font-size: 13px;
  color: var(--aibot-text-secondary);
  
  cursor: pointer;
  transition: var(--aibot-transition);
}

.aibot-tab:hover {
  background: var(--aibot-surface);
  color: var(--aibot-text);
}

.aibot-tab.active {
  background: var(--aibot-primary);
  color: #ffffff;
}

/* ===== BODY ===== */
#aibot-body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
  background: var(--aibot-surface);
}

#aibot-chatview,
#aibot-historyview {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
}

#aibot-chatview.active,
#aibot-historyview.active {
  display: flex;
}

/* ===== MESSAGES ===== */
#aibot-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#aibot-messages::-webkit-scrollbar {
  width: 6px;
}

#aibot-messages::-webkit-scrollbar-track {
  background: transparent;
}

#aibot-messages::-webkit-scrollbar-thumb {
  background: var(--aibot-border);
  border-radius: 3px;
}

#aibot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--aibot-text-secondary);
}

.aibot-bubble {
  max-width: 90%;
  padding: 20px 24px;
  border-radius: 20px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: aibot-bubble-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes aibot-bubble-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.aibot-bot {
  align-self: flex-start;
  background: #ffffff;
  color: var(--aibot-text);
  border: 1px solid #e5e7eb;
  border-radius: 16px 16px 16px 4px;
}

.aibot-user {
  align-self: flex-end;
  background: var(--aibot-primary);
  color: #ffffff;
  border: none;
  border-radius: 18px 18px 4px 18px;
}

/* ===== TYPING INDICATOR ===== */
#aibot-typing {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 0 20px 12px;
  font-size: 13px;
  color: var(--aibot-text-secondary);
}

#aibot-typing.show {
  display: flex;
}

#aibot-typing::before {
  content: '';
  display: flex;
  gap: 4px;
}

.aibot-typing-dots {
  display: flex;
  gap: 4px;
}

.aibot-typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--aibot-text-secondary);
  border-radius: 50%;
  animation: aibot-typing 1.4s ease-in-out infinite;
}

.aibot-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.aibot-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aibot-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ===== HISTORY ===== */
#aibot-historylist {
  padding: 16px;
  overflow-y: auto;
}

.aibot-hitem {
  padding: 14px 16px;
  margin-bottom: 8px;
  
  background: var(--aibot-bg);
  border: 1px solid var(--aibot-border);
  border-radius: var(--aibot-radius-md);
  
  cursor: pointer;
  transition: var(--aibot-transition);
}

.aibot-hitem:hover {
  border-color: var(--aibot-primary);
  box-shadow: var(--aibot-shadow-sm);
}

.aibot-hitem.aibot-hcurrent {
  border-color: var(--aibot-primary);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.05), rgba(139, 92, 246, 0.05));
}

.aibot-hrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.aibot-htitle {
  font-weight: 600;
  font-size: 14px;
  color: var(--aibot-text);
}

.aibot-htime {
  font-size: 12px;
  color: var(--aibot-text-secondary);
}

.aibot-hpreview {
  margin-top: 6px;
  font-size: 13px;
  color: var(--aibot-text-secondary);
  line-height: 1.4;
  
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== FOOTER ===== */
#aibot-footer {
  padding: 16px 20px;
  background: var(--aibot-bg);
  border-top: 1px solid var(--aibot-border);
  flex-shrink: 0;
}

#aibot-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#aibot-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 16px;
  
  background: var(--aibot-surface);
  border: 1px solid var(--aibot-border);
  border-radius: var(--aibot-radius-md);
  
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  color: var(--aibot-text);
  
  resize: none;
  outline: none;
  transition: var(--aibot-transition);
}

#aibot-input::placeholder {
  color: var(--aibot-text-secondary);
}

#aibot-input:focus {
  border-color: var(--aibot-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Action Buttons */
#aibot-mic,
#aibot-whatsapp,
#aibot-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  border: 1px solid var(--aibot-border);
  border-radius: var(--aibot-radius-md);
  
  cursor: pointer;
  transition: var(--aibot-transition);
}

#aibot-mic,
#aibot-whatsapp {
  background: var(--aibot-surface);
  color: var(--aibot-text-secondary);
}

#aibot-mic:hover,
#aibot-whatsapp:hover {
  background: var(--aibot-border-light);
  color: var(--aibot-text);
  border-color: var(--aibot-border);
}

#aibot-mic .aibot-mic-ico,
#aibot-whatsapp svg {
  width: 20px;
  height: 20px;
}

#aibot-mic.listening {
  background: var(--aibot-primary-grad);
  border-color: transparent;
  color: #ffffff;
  animation: aibot-mic-pulse 1.5s ease-in-out infinite;
}

@keyframes aibot-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(99, 102, 241, 0); }
}

#aibot-whatsapp:hover {
  background: #dcfce7;
  border-color: #22c55e;
  color: #22c55e;
}

#aibot-whatsapp svg path {
  transition: var(--aibot-transition);
}

#aibot-whatsapp:hover svg path {
  fill: #22c55e;
}

#aibot-send {
  background: var(--aibot-primary-grad);
  border: none;
  color: #ffffff;
}

#aibot-send:hover {
  transform: scale(1.05);
  box-shadow: var(--aibot-shadow-md);
}

#aibot-send:active {
  transform: scale(0.95);
}

#aibot-send svg {
  width: 20px;
  height: 20px;
}

#aibot-send:disabled,
#aibot-mic:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== WHATSAPP MODAL ===== */
.aibot-modal {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  
  align-items: center;
  justify-content: center;
  padding: 20px;
  
  border-radius: inherit;
  animation: aibot-modal-bg 0.2s ease;
}

@keyframes aibot-modal-bg {
  from { opacity: 0; }
  to { opacity: 1; }
}

.aibot-modal.show {
  display: flex;
}

.aibot-modal-content {
  background: var(--aibot-bg);
  border-radius: var(--aibot-radius-xl);
  padding: 32px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  
  box-shadow: var(--aibot-shadow-2xl);
  animation: aibot-modal-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes aibot-modal-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.aibot-modal-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  
  display: flex;
  align-items: center;
  justify-content: center;
  
  background: linear-gradient(135deg, #dcfce7, #bbf7d0);
  border-radius: var(--aibot-radius-full);
}

.aibot-modal-icon svg {
  width: 32px;
  height: 32px;
}

.aibot-modal-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--aibot-text);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.aibot-modal-subtitle {
  font-size: 14px;
  color: var(--aibot-text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.aibot-modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.aibot-modal-btn {
  padding: 14px 24px;
  border-radius: var(--aibot-radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--aibot-transition);
  border: none;
}

.aibot-modal-yes {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #ffffff;
}

.aibot-modal-yes:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.3);
}

.aibot-modal-no {
  background: var(--aibot-surface);
  color: var(--aibot-text-secondary);
  border: 1px solid var(--aibot-border);
}

.aibot-modal-no:hover {
  background: var(--aibot-border-light);
  color: var(--aibot-text);
}

/* ===== LEAD FORM ===== */
#aibot-lead {
  display: none;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--aibot-border);
}

#aibot-lead.show {
  display: flex;
}

#aibot-lead input,
#aibot-lead textarea {
  width: 100%;
  padding: 12px 16px;
  
  background: var(--aibot-surface);
  border: 1px solid var(--aibot-border);
  border-radius: var(--aibot-radius-md);
  
  font-family: inherit;
  font-size: 14px;
  color: var(--aibot-text);
  
  outline: none;
  transition: var(--aibot-transition);
}

#aibot-lead input:focus,
#aibot-lead textarea:focus {
  border-color: var(--aibot-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

#aibot-lead textarea {
  min-height: 80px;
  resize: vertical;
}

#aibot-lead button {
  width: 100%;
  padding: 14px;
  
  background: var(--aibot-primary-grad);
  border: none;
  border-radius: var(--aibot-radius-md);
  
  font-weight: 600;
  font-size: 14px;
  color: #ffffff;
  
  cursor: pointer;
  transition: var(--aibot-transition);
}

#aibot-lead button:hover {
  transform: translateY(-1px);
  box-shadow: var(--aibot-shadow-md);
}

/* ===== WHATSAPP BUTTON IN CHAT ===== */
.aibot-btn-wrapper {
  margin-top: 12px;
}

.aibot-whatsapp-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border-radius: var(--aibot-radius-md);
  border: none;
  
  font-weight: 600;
  font-size: 14px;
  color: #ffffff !important;
  text-decoration: none;
  
  cursor: pointer;
  transition: var(--aibot-transition);
}

.aibot-whatsapp-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.3);
}

/* ===== POWERED BY ===== */
#aibot-powered {
  padding: 12px 20px;
  display: flex;
  justify-content: center;
  background: var(--aibot-bg);
  border-top: 1px solid var(--aibot-border);
}

#aibot-powered .aibot-powered-link {
  display: flex;
  align-items: center;
  gap: 6px;
  
  font-size: 12px;
  font-weight: 500;
  color: var(--aibot-text-secondary);
  text-decoration: none;
  
  transition: var(--aibot-transition);
}

#aibot-powered .aibot-powered-link:hover {
  color: var(--aibot-text);
}

#aibot-powered img {
  height: 14px;
  width: auto;
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 480px) {
  #aibot-root {
    right: 16px !important;
    bottom: 16px !important;
  }
  
  #aibot-btn {
    height: 44px;
    padding: 0 14px;
  }
  
  #aibot-btn .aibot-launcher-ico {
    width: 18px;
    height: 18px;
  }
  
  #aibot-btn .aibot-launcher-text {
    font-size: 13px;
  }
  
  #aibot-btn[data-shape="circle"],
  #aibot-btn[data-shape="square"] {
    width: 44px;
    height: 44px;
  }
  
#aibot-panel {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: none !important;
    z-index: 2147483647 !important;
  }
  
  #aibot-header {
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
  }
  
  #aibot-tabs {
    padding: 10px 16px;
  }
  
  #aibot-messages {
    padding: 16px;
  }
  
  .aibot-bubble {
    max-width: 88%;
    font-size: 15px;
    padding: 10px 14px;
  }
  
  #aibot-footer {
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  
  #aibot-input {
    font-size: 16px; /* Prevent iOS zoom */
  }
  
  #aibot-mic,
  #aibot-whatsapp,
  #aibot-send {
    width: 44px;
    height: 44px;
  }
  
  .aibot-modal-content {
    padding: 24px;
    margin: 16px;
    max-width: calc(100% - 32px);
  }
  
  #aibot-newchat,
  #aibot-close {
    width: 40px;
    height: 40px;
  }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --aibot-bg: #1e1e2e;
    --aibot-surface: #2a2a3e;
    --aibot-text: #f1f5f9;
    --aibot-text-secondary: #94a3b8;
    --aibot-border: #3f3f5a;
    --aibot-border-light: #2f2f44;
  }
  
  #aibot-input {
    background: var(--aibot-surface);
    color: var(--aibot-text);
  }
  
  .aibot-bot {
    background: var(--aibot-surface);
    border-color: var(--aibot-border);
  }
}