/*
 * Personal AI Advisor — Frontend Chat Widget
 * Design language: Refined glass + dark depth + indigo accent
 * Font: Outfit (clean, modern, slightly geometric)
 */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600&display=swap');

:root {
  --wpai-accent:       var(--wpai-cfg-bubble, #6366f1);
  --wpai-header-bg:    var(--wpai-cfg-header, #0f172a);
  --wpai-chat-bg:      var(--wpai-cfg-bg, #f8fafc);
  --wpai-user-bubble:  var(--wpai-cfg-bubble, #6366f1);
  --wpai-bot-bubble:   #ffffff;
  --wpai-bot-text:     #0f172a;
  --wpai-input-bg:     #ffffff;
  --wpai-border:       rgba(0,0,0,0.08);
  --wpai-shadow:       0 24px 80px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.1);
  --wpai-radius:       22px;
  --wpai-panel-w:      380px;
  --wpai-panel-h:      580px;
}

/* ─── Container ───────────────────────────────────────────────────────────── */

#wpai-widget,
.wpai-inline-widget {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  box-sizing: border-box;
}

#wpai-widget *,
.wpai-inline-widget * {
  box-sizing: border-box;
}

/* ─── Floating Widget Container ──────────────────────────────────────────── */

#wpai-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* ─── Trigger Button ──────────────────────────────────────────────────────── */

.wpai-trigger {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(99,102,241,0.45), 0 2px 8px rgba(0,0,0,0.15);
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1),
              box-shadow 0.25s ease;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.wpai-trigger::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s;
}

.wpai-trigger:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 40px rgba(99,102,241,0.55), 0 4px 12px rgba(0,0,0,0.2);
}

.wpai-trigger:hover::after { opacity: 1; }
.wpai-trigger:active { transform: scale(0.96); }

.wpai-trigger svg {
  width: 24px; height: 24px;
  color: white;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.2s;
}

/* ─── Chat Panel ──────────────────────────────────────────────────────────── */

.wpai-panel {
  width: var(--wpai-panel-w);
  height: var(--wpai-panel-h);
  background: var(--wpai-chat-bg);
  border-radius: var(--wpai-radius);
  box-shadow: var(--wpai-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  border: 1px solid rgba(255,255,255,0.6);
}

/* Floating bubble mode: panel slides up from trigger */
.wpai-mode-bubble .wpai-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  transform: scale(0.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.35s cubic-bezier(0.34,1.56,0.64,1),
    opacity 0.25s ease;
}

.wpai-mode-bubble.wpai-open .wpai-panel {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Slide panel mode: slides in from right */
.wpai-mode-slide .wpai-panel {
  position: fixed;
  top: 0; right: 0;
  bottom: 0;
  width: 420px;
  height: 100%;
  border-radius: 0;
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.3s ease;
  z-index: 999998;
}

.wpai-mode-slide.wpai-open .wpai-panel {
  transform: translateX(0);
  opacity: 1;
  pointer-events: all;
}

/* Inline mode */
.wpai-panel-inline {
  position: static;
  width: 100%;
  height: 520px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
  border-radius: var(--wpai-radius);
}

/* ─── Panel Header ────────────────────────────────────────────────────────── */

.wpai-panel-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.wpai-panel-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.wpai-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

.wpai-avatar-ring {
  position: relative;
  width: 40px; height: 40px;
}

.wpai-avatar {
  width: 40px; height: 40px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: white;
  border: 2px solid rgba(255,255,255,0.2);
  overflow: hidden;
  flex-shrink: 0;
}

/* When an avatar image is set, it fills the circle */
.wpai-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* Trigger button: custom icon image */
.wpai-trigger-img {
  width: 30px;
  height: 30px;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.wpai-online-dot {
  position: absolute;
  bottom: 1px; right: 1px;
  width: 11px; height: 11px;
  background: #4ade80;
  border-radius: 50%;
  border: 2px solid white;
  animation: wpai-pulse 2s infinite;
}

@keyframes wpai-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0.4); }
  50%       { box-shadow: 0 0 0 5px rgba(74,222,128,0); }
}

.wpai-bot-name {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  color: white;
  letter-spacing: -0.01em;
}

.wpai-bot-status {
  display: block;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.65);
  font-weight: 400;
}

.wpai-close-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 50%;
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: rgba(255,255,255,0.8);
  transition: background 0.2s, color 0.2s;
  position: relative;
}

.wpai-close-btn:hover {
  background: rgba(255,255,255,0.2);
  color: white;
}

/* ─── Messages Container ──────────────────────────────────────────────────── */

.wpai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.wpai-messages::-webkit-scrollbar { width: 4px; }
.wpai-messages::-webkit-scrollbar-track { background: transparent; }
.wpai-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 99px; }

/* ─── Message Bubbles ─────────────────────────────────────────────────────── */

.wpai-msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  animation: wpai-msg-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes wpai-msg-in {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.wpai-msg.wpai-user { align-self: flex-end; align-items: flex-end; }
.wpai-msg.wpai-bot  { align-self: flex-start; align-items: flex-start; }

.wpai-msg-content {
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 0.9rem;
  line-height: 1.55;
  word-break: break-word;
}

.wpai-msg.wpai-user .wpai-msg-content {
  background: var(--wpai-user-bubble);
  color: white;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 4px 16px rgba(99,102,241,0.3);
}

.wpai-msg.wpai-bot .wpai-msg-content {
  background: var(--wpai-bot-bubble);
  color: var(--wpai-bot-text);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  border: 1px solid rgba(0,0,0,0.06);
}

.wpai-msg-time {
  font-size: 0.68rem;
  color: rgba(0,0,0,0.35);
  padding: 3px 6px;
}

/* ─── Typing Indicator ────────────────────────────────────────────────────── */

.wpai-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 8px;
  flex-shrink: 0;
}

.wpai-typing.wpai-hidden { display: none; }

.wpai-typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  background: white;
  border: 1px solid rgba(0,0,0,0.06);
  padding: 10px 14px;
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.wpai-typing-bubble span {
  width: 6px; height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: wpai-bounce 1.2s infinite;
}

.wpai-typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.wpai-typing-bubble span:nth-child(3) { animation-delay: 0.30s; }

@keyframes wpai-bounce {
  0%, 60%, 100% { transform: translateY(0); background: #94a3b8; }
  30%            { transform: translateY(-5px); background: #6366f1; }
}

.wpai-typing-label {
  font-size: 0.72rem;
  color: #94a3b8;
  font-style: italic;
}

/* ─── Input Area ──────────────────────────────────────────────────────────── */

.wpai-input-area {
  padding: 12px 14px 10px;
  background: #f8fafc;
  border-top: 1px solid rgba(0,0,0,0.06);
  flex-shrink: 0;
}

.wpai-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: white;
  border: 2px solid rgba(0,0,0,0.09);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  /* Prevent any inner element from showing its own focus ring */
  isolation: isolate;
}

/* Rich glow on focus — replaces the browser's ugly 1px outline */
.wpai-input-wrapper:focus-within {
  border-color: var(--wpai-accent);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--wpai-accent) 14%, transparent),
    0 2px 12px rgba(0,0,0,0.07);
  outline: none;
}

.wpai-input {
  flex: 1;
  border: none;
  /* Kill ALL browser focus decorations on the raw textarea */
  outline: none !important;
  -webkit-appearance: none;
  box-shadow: none !important;
  background: transparent;
  font-family: 'Outfit', sans-serif;
  font-size: 0.9rem;
  color: #0f172a;
  line-height: 1.5;
  resize: none;
  max-height: 100px;
  overflow-y: auto;
  padding: 2px 0;
  /* Prevent Firefox from adding an extra border on focus */
  -moz-appearance: none;
}

.wpai-input:focus {
  outline: none !important;
  box-shadow: none !important;
  border: none !important;
}

.wpai-input::placeholder { color: #94a3b8; }

.wpai-send-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1),
              opacity 0.2s, box-shadow 0.2s;
  color: white;
}

.wpai-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.wpai-send-btn:not(:disabled):hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(99,102,241,0.4);
}

.wpai-send-btn:not(:disabled):active { transform: scale(0.92); }

.wpai-input-hint {
  text-align: center;
  font-size: 0.68rem;
  color: #94a3b8;
  margin: 6px 0 0;
}

/* ─── Inline Widget ───────────────────────────────────────────────────────── */

.wpai-inline-widget {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.wpai-messages-inline {
  height: 340px;
}

/* ─── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  #wpai-widget { bottom: 16px; right: 16px; }

  .wpai-mode-bubble .wpai-panel {
    width: calc(100vw - 32px);
    height: 75vh;
    right: -8px;
    bottom: 68px;
  }

  .wpai-mode-slide .wpai-panel { width: 100vw; }
}

/* ─── Slide mode backdrop ─────────────────────────────────────────────────── */

.wpai-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999997;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  backdrop-filter: blur(2px);
}

.wpai-backdrop.visible {
  opacity: 1;
  pointer-events: all;
}
