.ai-chatbot-wp {
  --ai-chatbot-bg: #0f1419;
  --ai-chatbot-surface: #1a2332;
  --ai-chatbot-border: #2d3a4d;
  --ai-chatbot-text: #e8edf4;
  --ai-chatbot-muted: #8b9cb3;
  --ai-chatbot-accent: #3b82f6;
  --ai-chatbot-accent-hover: #2563eb;
  max-width: 560px;
  margin: 1.5rem auto;
  border: 1px solid var(--ai-chatbot-border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--ai-chatbot-bg);
  color: var(--ai-chatbot-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

.ai-chatbot-wp__header {
  padding: 0.85rem 1rem;
  background: var(--ai-chatbot-surface);
  border-bottom: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-wp__header--with-close {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.ai-chatbot-wp__title {
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 0;
}

.ai-chatbot-wp__close {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ai-chatbot-text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chatbot-wp__close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.ai-chatbot-wp__close:focus-visible {
  outline: 2px solid var(--ai-chatbot-accent);
  outline-offset: 2px;
}

.ai-chatbot-wp__messages {
  height: var(--ai-chatbot-height, 480px);
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ai-chatbot-wp__msg {
  max-width: 92%;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chatbot-wp__msg--user {
  align-self: flex-end;
  background: var(--ai-chatbot-accent);
  color: #fff;
}

.ai-chatbot-wp__msg--assistant {
  align-self: flex-start;
  background: var(--ai-chatbot-surface);
  border: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-wp__msg--error {
  align-self: stretch;
  background: #3d1f24;
  border: 1px solid #7f1d1d;
  color: #fecaca;
  font-size: 0.9rem;
}

.ai-chatbot-wp__form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--ai-chatbot-border);
  background: var(--ai-chatbot-surface);
  align-items: flex-end;
}

.ai-chatbot-wp__input {
  flex: 1;
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--ai-chatbot-border);
  border-radius: 8px;
  background: var(--ai-chatbot-bg);
  color: var(--ai-chatbot-text);
  font: inherit;
}

.ai-chatbot-wp__input:focus {
  outline: 2px solid var(--ai-chatbot-accent);
  outline-offset: 1px;
}

.ai-chatbot-wp__send {
  flex-shrink: 0;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--ai-chatbot-accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.ai-chatbot-wp__send:hover:not(:disabled) {
  background: var(--ai-chatbot-accent-hover);
}

.ai-chatbot-wp__send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ai-chatbot-wp.is-loading .ai-chatbot-wp__send {
  opacity: 0.7;
}

@media (prefers-color-scheme: light) {
  .ai-chatbot-wp {
    --ai-chatbot-bg: #f8fafc;
    --ai-chatbot-surface: #fff;
    --ai-chatbot-border: #e2e8f0;
    --ai-chatbot-text: #0f172a;
    --ai-chatbot-muted: #64748b;
  }

  .ai-chatbot-wp__msg--assistant {
    background: #f1f5f9;
  }

  .ai-chatbot-wp__msg--error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
  }
}

/* Widget flotante global */
.ai-chatbot-wp-floating {
  --ai-chatbot-accent: #3b82f6;
  --ai-chatbot-accent-hover: #2563eb;
  position: fixed;
  z-index: 999999;
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.ai-chatbot-wp-floating > * {
  pointer-events: auto;
}

.ai-chatbot-wp-floating--bottom-right {
  right: max(1rem, env(safe-area-inset-right, 0px));
  left: auto;
}

.ai-chatbot-wp-floating--bottom-left {
  left: max(1rem, env(safe-area-inset-left, 0px));
  right: auto;
  align-items: flex-start;
}

.ai-chatbot-wp-floating__toggle {
  position: relative;
  z-index: 2;
  width: 56px;
  height: 56px;
  margin-top: 0;
  border-radius: 50%;
  border: none;
  background: var(--ai-chatbot-accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.ai-chatbot-wp-floating__toggle-icon--close {
  display: none;
}

.ai-chatbot-wp-floating[data-open="1"] .ai-chatbot-wp-floating__toggle-icon--chat {
  display: none;
}

.ai-chatbot-wp-floating[data-open="1"] .ai-chatbot-wp-floating__toggle-icon--close {
  display: flex;
}

.ai-chatbot-wp-floating__toggle:hover {
  background: var(--ai-chatbot-accent-hover);
  transform: scale(1.05);
}

.ai-chatbot-wp-floating__toggle:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.5);
  outline-offset: 3px;
}

.ai-chatbot-wp-floating[data-open="1"] .ai-chatbot-wp-floating__toggle {
  background: #334155;
}

.ai-chatbot-wp-floating__panel {
  position: relative;
  z-index: 1;
  order: -1;
  margin-bottom: 12px;
  width: min(100vw - 2rem, 380px);
  height: min(88vh, 620px);
  max-height: min(88vh, 620px);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35);
  background: #0f1419;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ai-chatbot-wp-floating--bottom-right .ai-chatbot-wp-floating__panel {
  align-self: flex-end;
}

.ai-chatbot-wp-floating--bottom-left .ai-chatbot-wp-floating__panel {
  align-self: flex-start;
}

.ai-chatbot-wp--in-floating {
  max-width: none;
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-shadow: none;
  border-radius: 0;
  border: none;
}

.ai-chatbot-wp--in-floating .ai-chatbot-wp__messages {
  flex: 1;
  min-height: 120px;
  height: auto;
  max-height: none;
}

@media (max-width: 480px) {
  .ai-chatbot-wp-floating__panel {
    width: min(100vw - 1rem, 100%);
    max-height: 90vh;
    height: auto;
  }
}
