/* DBest WP ChatBot - Frontend CSS */

.dbestwp-widget {
  --dbest-primary: #4f46e5;
  --dbest-primary-dark: #4338ca;
  --dbest-primary-light: #e0e7ff;
  --dbest-text-on-primary: #ffffff;
  --dbest-bg: #ffffff;
  --dbest-bg-alt: #f8f9fb;
  --dbest-text: #1f2937;
  --dbest-text-muted: #6b7280;
  --dbest-border: #e5e7eb;
  --dbest-user-bg: var(--dbest-primary);
  --dbest-user-text: var(--dbest-text-on-primary);
  --dbest-bot-bg: #f1f3f7;
  --dbest-bot-text: var(--dbest-text);
  --dbest-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  --dbest-shadow-bubble: 0 8px 24px rgba(0, 0, 0, 0.18);
  --dbest-radius: 18px;
  --dbest-bubble-size: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  box-sizing: border-box;
}

.dbestwp-widget *,
.dbestwp-widget *::before,
.dbestwp-widget *::after {
  box-sizing: border-box;
}

/* Color theme presets */
.dbestwp-widget.theme-indigo   { --dbest-primary: #4f46e5; --dbest-primary-dark: #4338ca; --dbest-primary-light: #e0e7ff; }
.dbestwp-widget.theme-ocean    { --dbest-primary: #0ea5e9; --dbest-primary-dark: #0284c7; --dbest-primary-light: #e0f2fe; }
.dbestwp-widget.theme-forest   { --dbest-primary: #10b981; --dbest-primary-dark: #059669; --dbest-primary-light: #d1fae5; }
.dbestwp-widget.theme-sunset   { --dbest-primary: #f97316; --dbest-primary-dark: #ea580c; --dbest-primary-light: #ffedd5; }
.dbestwp-widget.theme-rose     { --dbest-primary: #ec4899; --dbest-primary-dark: #db2777; --dbest-primary-light: #fce7f3; }
.dbestwp-widget.theme-violet   { --dbest-primary: #8b5cf6; --dbest-primary-dark: #7c3aed; --dbest-primary-light: #ede9fe; }
.dbestwp-widget.theme-graphite { --dbest-primary: #1f2937; --dbest-primary-dark: #111827; --dbest-primary-light: #e5e7eb; }

/* ============ FLOATING MODE ============ */
.dbestwp-widget.mode-floating {
  position: fixed;
  z-index: 99998;
}

.dbestwp-widget.mode-floating.pos-bottom-right { bottom: 24px; right: 24px; }
.dbestwp-widget.mode-floating.pos-bottom-left  { bottom: 24px; left: 24px; }
.dbestwp-widget.mode-floating.pos-top-right    { top: 24px; right: 24px; }
.dbestwp-widget.mode-floating.pos-top-left     { top: 24px; left: 24px; }

/* Launcher bubble */
.dbestwp-launcher {
  width: var(--dbest-bubble-size);
  height: var(--dbest-bubble-size);
  background: var(--dbest-primary);
  color: var(--dbest-text-on-primary);
  border: none;
  cursor: pointer;
  box-shadow: var(--dbest-shadow-bubble);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  position: relative;
  overflow: hidden;
  padding: 0;
}

.dbestwp-launcher:hover {
  transform: translateY(-2px) scale(1.05);
  background: var(--dbest-primary-dark);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
}

.dbestwp-launcher:active {
  transform: translateY(0) scale(0.98);
}

.dbestwp-widget.shape-circle  .dbestwp-launcher { border-radius: 50%; }
.dbestwp-widget.shape-rounded .dbestwp-launcher { border-radius: 18px; }
.dbestwp-widget.shape-square  .dbestwp-launcher { border-radius: 6px; }

.dbestwp-widget.size-small  { --dbest-bubble-size: 52px; }
.dbestwp-widget.size-medium { --dbest-bubble-size: 64px; }
.dbestwp-widget.size-large  { --dbest-bubble-size: 76px; }

.dbestwp-launcher-icon {
  width: 56%;
  height: 56%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dbestwp-launcher-icon svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dbestwp-launcher-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dbestwp-widget.shape-circle  .dbestwp-launcher-image { border-radius: 50%; }
.dbestwp-widget.shape-rounded .dbestwp-launcher-image { border-radius: 18px; }
.dbestwp-widget.shape-square  .dbestwp-launcher-image { border-radius: 6px; }

/* Pulse ring on launcher */
.dbestwp-launcher::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: inherit;
  border: 2px solid var(--dbest-primary);
  opacity: 0;
  animation: dbestwp-pulse 2.4s ease-out infinite;
}

@keyframes dbestwp-pulse {
  0%   { opacity: 0.6; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.3); }
}

.dbestwp-widget.is-open .dbestwp-launcher::after { display: none; }

/* Close X icon when open */
.dbestwp-launcher .dbestwp-close-icon { display: none; }
.dbestwp-widget.is-open .dbestwp-launcher .dbestwp-launcher-icon,
.dbestwp-widget.is-open .dbestwp-launcher .dbestwp-launcher-image { display: none; }
.dbestwp-widget.is-open .dbestwp-launcher .dbestwp-close-icon { display: flex; }

/* Chat panel */
.dbestwp-panel {
  position: absolute;
  width: 380px;
  height: 580px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  background: var(--dbest-bg);
  border-radius: var(--dbest-radius);
  box-shadow: var(--dbest-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.dbestwp-widget.mode-floating.pos-bottom-right .dbestwp-panel { bottom: calc(var(--dbest-bubble-size) + 16px); right: 0; transform-origin: bottom right; }
.dbestwp-widget.mode-floating.pos-bottom-left  .dbestwp-panel { bottom: calc(var(--dbest-bubble-size) + 16px); left:  0; transform-origin: bottom left; }
.dbestwp-widget.mode-floating.pos-top-right    .dbestwp-panel { top:    calc(var(--dbest-bubble-size) + 16px); right: 0; transform-origin: top right; }
.dbestwp-widget.mode-floating.pos-top-left     .dbestwp-panel { top:    calc(var(--dbest-bubble-size) + 16px); left:  0; transform-origin: top left; }

.dbestwp-widget.is-open .dbestwp-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ============ INLINE MODE ============ */
.dbestwp-widget.mode-inline {
  display: block;
  max-width: 500px;
  margin: 16px 0;
}

.dbestwp-widget.mode-inline .dbestwp-launcher { display: none; }

.dbestwp-widget.mode-inline .dbestwp-panel {
  position: relative;
  opacity: 1;
  transform: none;
  pointer-events: auto;
  width: 100%;
  height: 600px;
  max-width: 100%;
  bottom: auto;
  right: auto;
  top: auto;
  left: auto;
}

/* ============ PANEL CONTENTS ============ */
.dbestwp-header {
  background: var(--dbest-primary);
  color: var(--dbest-text-on-primary);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

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

.dbestwp-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dbestwp-header-avatar svg {
  width: 60%;
  height: 60%;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.dbestwp-header-info {
  flex: 1;
  min-width: 0;
}

.dbestwp-header-name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  margin: 0;
}

.dbestwp-header-status {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dbestwp-header-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.dbestwp-header-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: inherit;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  padding: 0;
}

.dbestwp-header-close:hover { background: rgba(255, 255, 255, 0.25); }
.dbestwp-header-close svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

.dbestwp-widget.mode-inline .dbestwp-header-close { display: none; }

/* Messages */
.dbestwp-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--dbest-bg-alt);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.dbestwp-messages::-webkit-scrollbar { width: 6px; }
.dbestwp-messages::-webkit-scrollbar-track { background: transparent; }
.dbestwp-messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.15); border-radius: 3px; }

.dbestwp-message {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: dbestwp-fade-in 0.3s ease;
}

@keyframes dbestwp-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dbestwp-message.user { justify-content: flex-end; }
.dbestwp-message.assistant { justify-content: flex-start; }

.dbestwp-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--dbest-primary-light);
  color: var(--dbest-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.dbestwp-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.dbestwp-msg-avatar svg { width: 60%; height: 60%; stroke: currentColor; fill: none; stroke-width: 2; }

.dbestwp-message.user .dbestwp-msg-avatar { display: none; }

.dbestwp-message-content {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.dbestwp-message.user .dbestwp-message-content {
  background: var(--dbest-user-bg);
  color: var(--dbest-user-text);
  border-bottom-right-radius: 4px;
}

.dbestwp-message.assistant .dbestwp-message-content {
  background: var(--dbest-bot-bg);
  color: var(--dbest-bot-text);
  border-bottom-left-radius: 4px;
}

.dbestwp-message.error .dbestwp-message-content {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Pre-chat form */
.dbestwp-prechat-form {
  background: var(--dbest-bg);
  border-radius: 16px;
  padding: 18px;
  margin: 8px 0 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  animation: dbestwp-fade-in 0.3s ease;
}

.dbestwp-prechat-intro {
  font-size: 13px;
  color: var(--dbest-text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.dbestwp-prechat-field {
  margin-bottom: 12px;
}

.dbestwp-prechat-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--dbest-text);
  margin-bottom: 4px;
}

.dbestwp-prechat-field input,
.dbestwp-prechat-field textarea,
.dbestwp-prechat-field select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--dbest-border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--dbest-bg);
  color: var(--dbest-text);
  transition: border-color 0.15s ease;
  outline: none;
  box-sizing: border-box;
}

.dbestwp-prechat-field input:focus,
.dbestwp-prechat-field textarea:focus,
.dbestwp-prechat-field select:focus {
  border-color: var(--dbest-primary);
}

.dbestwp-prechat-submit {
  width: 100%;
  background: var(--dbest-primary);
  color: var(--dbest-text-on-primary);
  border: none;
  border-radius: 10px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  margin-top: 4px;
}

.dbestwp-prechat-submit:hover {
  background: var(--dbest-primary-dark);
}

.dbestwp-prechat-submit:active {
  transform: scale(0.98);
}

/* System notice (takeover transitions) */
.dbestwp-system-notice {
  text-align: center;
  font-size: 12px;
  color: var(--dbest-text-muted);
  padding: 8px 12px;
  margin: 8px auto;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 12px;
  max-width: 80%;
  animation: dbestwp-fade-in 0.3s ease;
}

/* Typing indicator */
.dbestwp-typing {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
  background: var(--dbest-bot-bg);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  align-items: center;
}

.dbestwp-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dbest-text-muted);
  animation: dbestwp-bounce 1.4s infinite;
}

.dbestwp-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.dbestwp-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes dbestwp-bounce {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-5px); }
}

/* Input area */
.dbestwp-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  background: var(--dbest-bg);
  border-top: 1px solid var(--dbest-border);
  flex-shrink: 0;
}

.dbestwp-input {
  flex: 1;
  border: 1.5px solid var(--dbest-border);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  background: var(--dbest-bg-alt);
  color: var(--dbest-text);
  transition: border-color 0.15s ease, background 0.15s ease;
  outline: none;
}

.dbestwp-input:focus {
  border-color: var(--dbest-primary);
  background: var(--dbest-bg);
}

.dbestwp-input:disabled { opacity: 0.6; }

.dbestwp-send-btn {
  background: var(--dbest-primary);
  color: var(--dbest-text-on-primary);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.1s ease;
  padding: 0;
}

.dbestwp-send-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }
.dbestwp-send-btn:hover { background: var(--dbest-primary-dark); }
.dbestwp-send-btn:active { transform: scale(0.94); }
.dbestwp-send-btn:disabled { background: #cbd5e1; cursor: not-allowed; }

.dbestwp-footer {
  font-size: 11px;
  text-align: center;
  color: var(--dbest-text-muted);
  padding: 0 16px 12px;
  background: var(--dbest-bg);
}

/* Responsive */
@media (max-width: 480px) {
  .dbestwp-widget.mode-floating .dbestwp-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 120px);
  }
  .dbestwp-widget.mode-floating.pos-bottom-right,
  .dbestwp-widget.mode-floating.pos-bottom-left { bottom: 16px; }
  .dbestwp-widget.mode-floating.pos-bottom-right { right: 12px; }
  .dbestwp-widget.mode-floating.pos-bottom-left  { left:  12px; }
}

/* ============ ADMIN STYLES ============ */
.dbestwp-admin { margin: 20px 0; }
.dbestwp-admin .form-group { margin-bottom: 20px; }
.dbestwp-admin label { display: block; margin-bottom: 5px; font-weight: 500; color: #333; }
.dbestwp-admin input[type="text"],
.dbestwp-admin input[type="email"],
.dbestwp-admin input[type="password"],
.dbestwp-admin input[type="number"],
.dbestwp-admin input[type="url"],
.dbestwp-admin select,
.dbestwp-admin textarea {
  width: 100%;
  max-width: 500px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
}
.dbestwp-admin input[type="color"] { width: 60px; height: 36px; padding: 2px; border: 1px solid #ddd; border-radius: 4px; cursor: pointer; }
.dbestwp-admin textarea { font-family: monospace; resize: vertical; }
.dbestwp-admin input[readonly] { background: #f5f5f5; cursor: not-allowed; }
.dbestwp-admin .description { display: block; margin-top: 5px; color: #666; font-size: 13px; }
.dbestwp-admin #notification_fields,
.dbestwp-admin .dbestwp-section {
  background: #f0f6fc;
  padding: 15px;
  margin: 15px 0;
  border-left: 4px solid #0073aa;
  border-radius: 4px;
}
.dbestwp-admin .dbestwp-section h4 { margin: 0 0 15px; color: #0073aa; }
.dbestwp-admin .submit { margin-top: 30px; }
.dbestwp-admin .submit button,
.dbestwp-admin .submit a { margin-right: 10px; }

/* Theme/icon swatches */
.dbestwp-swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  max-width: 500px;
  margin-top: 6px;
}

.dbestwp-swatch {
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 8px 4px;
  background: #fff;
  cursor: pointer;
  text-align: center;
  font-size: 11px;
  transition: border-color 0.15s ease, transform 0.1s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.dbestwp-swatch:hover { transform: translateY(-2px); }
.dbestwp-swatch.is-selected { border-color: #0073aa; box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.15); }

.dbestwp-swatch-color {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.dbestwp-swatch-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  border-radius: 8px;
  color: #4b5563;
}

.dbestwp-swatch-icon svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
