/* ============================================================
   WC AI Chatbot — Frontend Widget Styles
   ============================================================ */

:root {
  --wcaic-primary: #2563eb;
  --wcaic-primary-dark: #1d4ed8;
  --wcaic-bg: #ffffff;
  --wcaic-surface: #f8fafc;
  --wcaic-border: #e2e8f0;
  --wcaic-text: #1e293b;
  --wcaic-text-muted: #64748b;
  --wcaic-shadow: 0 20px 60px rgba(0,0,0,.15), 0 8px 20px rgba(0,0,0,.08);
  --wcaic-radius: 18px;
  --wcaic-radius-msg: 14px;
  --wcaic-z: 99999;
}

/* ── Floating button ─────────────────────────────────────── */
#wcaic-toggle-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--wcaic-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(37,99,235,.45);
  z-index: var(--wcaic-z);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s ease, box-shadow .2s ease;
  outline: none;
}
#wcaic-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(37,99,235,.55);
}
#wcaic-toggle-btn svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  transition: opacity .2s;
}

/* Unread badge */
#wcaic-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  display: none;
}
#wcaic-badge.visible { display: flex; }

/* ── Chat window ─────────────────────────────────────────── */
#wcaic-chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 120px);
  background: var(--wcaic-bg);
  border-radius: var(--wcaic-radius);
  box-shadow: var(--wcaic-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--wcaic-z);
  transform-origin: bottom right;
  transition: transform .25s cubic-bezier(.34,1.56,.64,1), opacity .2s;
  border: 1px solid var(--wcaic-border);
}
#wcaic-chat-window.wcaic-hidden {
  transform: scale(.85) translateY(16px);
  opacity: 0;
  pointer-events: none;
}

/* ── Header ──────────────────────────────────────────────── */
#wcaic-header {
  background: var(--wcaic-primary);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
#wcaic-avatar {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
#wcaic-header-info { flex: 1; min-width: 0; }
#wcaic-header-title {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#wcaic-header-subtitle {
  font-size: 12px;
  opacity: .8;
  margin-top: 1px;
}
#wcaic-close-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  line-height: 1;
  opacity: .85;
  transition: opacity .15s, background .15s;
}
#wcaic-close-btn:hover { opacity: 1; background: rgba(255,255,255,.15); }
#wcaic-close-btn svg { width: 20px; height: 20px; display: block; }

/* ── Messages area ───────────────────────────────────────── */
#wcaic-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--wcaic-surface);
  scroll-behavior: smooth;
}
#wcaic-messages::-webkit-scrollbar { width: 5px; }
#wcaic-messages::-webkit-scrollbar-track { background: transparent; }
#wcaic-messages::-webkit-scrollbar-thumb { background: var(--wcaic-border); border-radius: 99px; }

/* Messages */
.wcaic-msg {
  display: flex;
  gap: 8px;
  max-width: 90%;
  animation: wcaicFadeIn .25s ease;
}
@keyframes wcaicFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wcaic-msg.wcaic-bot { align-self: flex-start; }
.wcaic-msg.wcaic-user { align-self: flex-end; flex-direction: row-reverse; }

.wcaic-msg-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--wcaic-primary);
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.wcaic-msg.wcaic-user .wcaic-msg-icon { background: #6366f1; }

.wcaic-msg-bubble {
  padding: 10px 14px;
  border-radius: var(--wcaic-radius-msg);
  font-size: 14px;
  line-height: 1.55;
  max-width: 100%;
  word-break: break-word;
}
.wcaic-bot .wcaic-msg-bubble {
  background: var(--wcaic-bg);
  color: var(--wcaic-text);
  border: 1px solid var(--wcaic-border);
  border-bottom-left-radius: 4px;
}
.wcaic-user .wcaic-msg-bubble {
  background: var(--wcaic-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Markdown-ish formatting in bot messages */
.wcaic-bot .wcaic-msg-bubble strong { font-weight: 700; }
.wcaic-bot .wcaic-msg-bubble em { font-style: italic; }
.wcaic-bot .wcaic-msg-bubble code {
  background: var(--wcaic-surface);
  border: 1px solid var(--wcaic-border);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 13px;
}
.wcaic-bot .wcaic-msg-bubble a {
  color: var(--wcaic-primary);
  text-decoration: underline;
}

/* Typing indicator */
.wcaic-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--wcaic-bg);
  border: 1px solid var(--wcaic-border);
  border-radius: var(--wcaic-radius-msg);
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.wcaic-typing span {
  width: 7px;
  height: 7px;
  background: var(--wcaic-text-muted);
  border-radius: 50%;
  animation: wcaicBounce 1.2s ease infinite;
}
.wcaic-typing span:nth-child(2) { animation-delay: .2s; }
.wcaic-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes wcaicBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Input area ──────────────────────────────────────────── */
#wcaic-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--wcaic-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--wcaic-bg);
  flex-shrink: 0;
}
#wcaic-input {
  flex: 1;
  border: 1px solid var(--wcaic-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  color: var(--wcaic-text);
  background: var(--wcaic-surface);
  transition: border-color .15s;
}
#wcaic-input:focus { border-color: var(--wcaic-primary); }
#wcaic-input::placeholder { color: var(--wcaic-text-muted); }

#wcaic-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wcaic-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .15s;
  outline: none;
}
#wcaic-send-btn:hover { background: var(--wcaic-primary-dark); transform: scale(1.05); }
#wcaic-send-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
#wcaic-send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* ── Privacy note ────────────────────────────────────────── */
#wcaic-privacy {
  text-align: center;
  font-size: 11px;
  color: var(--wcaic-text-muted);
  padding: 6px 12px 10px;
  background: var(--wcaic-bg);
  border-top: 1px solid var(--wcaic-border);
}
#wcaic-privacy a { color: var(--wcaic-text-muted); text-decoration: underline; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  #wcaic-chat-window {
    bottom: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  #wcaic-toggle-btn { bottom: 16px; right: 16px; }
}
