/* =========================================================
   WP AI Chatbot – Widget Styles
   All colours are driven by CSS custom properties injected
   from the admin settings (see WPAIC_Frontend::inject_dynamic_css).
   ========================================================= */

/* ── CSS Variables (defaults; overridden by PHP-injected vars) ── */
:root {
  --wpaic-widget-bg:        #ffffff;
  --wpaic-header-bg:        #111827;
  --wpaic-header-text:      #ffffff;
  --wpaic-user-bubble-bg:   #2563eb;
  --wpaic-user-bubble-text: #ffffff;
  --wpaic-bot-bubble-bg:    #f3f4f6;
  --wpaic-bot-bubble-text:  #111827;
  --wpaic-send-btn-bg:      #2563eb;
  --wpaic-launcher-bg:      #2563eb;

  /* Non-overridable design tokens */
  --wpaic-radius:           16px;
  --wpaic-radius-sm:        10px;
  --wpaic-shadow:           0 8px 40px rgba(0,0,0,.18), 0 2px 10px rgba(0,0,0,.10);
  --wpaic-font:             -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --wpaic-transition:       .22s cubic-bezier(.4,0,.2,1);
  --wpaic-z:                9999;
  --wpaic-w:                370px;
  --wpaic-h:                560px;
}

/* ── Launcher ─────────────────────────────────────────────────── */
#wpaic-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--wpaic-z);
  font-family: var(--wpaic-font);
  box-sizing: border-box;
}

#wpaic-root *,
#wpaic-root *::before,
#wpaic-root *::after {
  box-sizing: inherit;
}

.wpaic-launcher {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--wpaic-launcher-bg);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.22), 0 2px 6px rgba(0,0,0,.12);
  transition: transform var(--wpaic-transition), box-shadow var(--wpaic-transition);
  outline-offset: 3px;
}

.wpaic-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 32px rgba(0,0,0,.28);
}

.wpaic-launcher:active {
  transform: scale(.96);
}

.wpaic-launcher-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  font-size: 22px;
}

.wpaic-launcher-icon svg {
  display: block;
  fill: currentColor;
}

.wpaic-emoji-chat {
  display: block;
  width: 26px;
  height: 26px;
  font-size: 26px;
  line-height: 26px;
  text-align: center;
}

.wpaic-emoji-clear {
  display: block;
  width: 18px;
  height: 18px;
  font-size: 16px;
  line-height: 18px;
  text-align: center;
}

/* Pulse ring animation when widget is closed */
.wpaic-launcher::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: var(--wpaic-launcher-bg);
  opacity: .25;
  animation: wpaic-pulse 2.4s ease-in-out infinite;
}

.wpaic-launcher[aria-expanded="true"]::before {
  display: none;
}

@keyframes wpaic-pulse {
  0%, 100% { transform: scale(1);   opacity: .25; }
  60%       { transform: scale(1.3); opacity: 0;   }
}

.wpaic-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* ── Widget Container ─────────────────────────────────────────── */
.wpaic-widget {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: var(--wpaic-w);
  max-width: calc(100vw - 32px);
  height: var(--wpaic-h);
  max-height: calc(100vh - 110px);
  background: var(--wpaic-widget-bg);
  border-radius: var(--wpaic-radius);
  box-shadow: var(--wpaic-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Entry animation */
  transform-origin: bottom right;
  animation: wpaic-slide-in var(--wpaic-transition) both;
}

.wpaic-widget[hidden] {
  display: none;
}

@keyframes wpaic-slide-in {
  from { opacity: 0; transform: scale(.88) translateY(14px); }
  to   { opacity: 1; transform: scale(1)  translateY(0);     }
}

/* ── Header ───────────────────────────────────────────────────── */
.wpaic-header {
  background: var(--wpaic-header-bg);
  color: var(--wpaic-header-text);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-radius: var(--wpaic-radius) var(--wpaic-radius) 0 0;
}

.wpaic-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.wpaic-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.wpaic-status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--wpaic-header-bg);
}

.wpaic-bot-name {
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  color: var(--wpaic-header-text);
}

.wpaic-bot-status {
  font-size: 11px;
  opacity: .7;
  color: var(--wpaic-header-text);
  margin-top: 2px;
}

.wpaic-header-actions {
  display: flex;
  gap: 6px;
}

.wpaic-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.12);
  color: var(--wpaic-header-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--wpaic-transition);
}

.wpaic-header-btn:hover {
  background: rgba(255,255,255,.24);
}

.wpaic-header-btn svg,
.wpaic-send-btn svg {
  display: block;
  fill: currentColor;
  pointer-events: none;
}

.wpaic-header-btn {
  font-size: 16px;
}

/* ── Messages ─────────────────────────────────────────────────── */
.wpaic-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.wpaic-messages::-webkit-scrollbar { width: 4px; }
.wpaic-messages::-webkit-scrollbar-track { background: transparent; }
.wpaic-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 2px; }

/* ── Individual Message ───────────────────────────────────────── */
.wpaic-message {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: wpaic-msg-in .2s ease both;
}

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

.wpaic-message.user {
  flex-direction: row-reverse;
}

.wpaic-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  background: rgba(0,0,0,.07);
}

.wpaic-message.user .wpaic-msg-avatar {
  background: var(--wpaic-user-bubble-bg);
  color: var(--wpaic-user-bubble-text);
  font-size: 12px;
  font-weight: 700;
}

.wpaic-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.wpaic-message.bot .wpaic-bubble {
  background: var(--wpaic-bot-bubble-bg);
  color: var(--wpaic-bot-bubble-text);
  border-bottom-left-radius: var(--wpaic-radius-sm);
}

.wpaic-message.user .wpaic-bubble {
  background: var(--wpaic-user-bubble-bg);
  color: var(--wpaic-user-bubble-text);
  border-bottom-right-radius: var(--wpaic-radius-sm);
}

.wpaic-bubble a {
  color: inherit;
  text-decoration: underline;
}

/* Timestamp */
.wpaic-timestamp {
  font-size: 10px;
  opacity: .5;
  margin-top: 3px;
  text-align: right;
}

.wpaic-message.bot .wpaic-timestamp {
  text-align: left;
}

/* ── Typing Indicator ─────────────────────────────────────────── */
.wpaic-typing .wpaic-bubble {
  padding: 12px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.wpaic-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wpaic-bot-bubble-text);
  opacity: .45;
  animation: wpaic-bounce 1.2s ease infinite;
}
.wpaic-dot:nth-child(2) { animation-delay: .2s; }
.wpaic-dot:nth-child(3) { animation-delay: .4s; }

@keyframes wpaic-bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: .45; }
  40%           { transform: translateY(-7px); opacity: 1;   }
}

/* ── Error Message ────────────────────────────────────────────── */
.wpaic-error-msg {
  text-align: center;
  font-size: 12px;
  color: #ef4444;
  padding: 6px 12px;
  background: #fef2f2;
  border-radius: 8px;
  margin: 0 4px;
}

/* ── Input Area ───────────────────────────────────────────────── */
.wpaic-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid rgba(0,0,0,.07);
  background: var(--wpaic-widget-bg);
  flex-shrink: 0;
}

.wpaic-input {
  flex: 1;
  border: 1.5px solid rgba(0,0,0,.12);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: var(--wpaic-font);
  resize: none;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  background: var(--wpaic-widget-bg);
  color: inherit;
  transition: border-color var(--wpaic-transition), box-shadow var(--wpaic-transition);
  outline: none;
}

.wpaic-input:focus {
  border-color: var(--wpaic-send-btn-bg);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--wpaic-send-btn-bg) 18%, transparent);
}

.wpaic-input::placeholder {
  color: rgba(0,0,0,.38);
}

.wpaic-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--wpaic-send-btn-bg);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
  transition: transform var(--wpaic-transition), opacity var(--wpaic-transition);
}

.wpaic-send-btn:hover:not(:disabled) {
  transform: scale(1.08);
}

.wpaic-send-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* ── Footer Note ──────────────────────────────────────────────── */
.wpaic-footer-note {
  text-align: center;
  font-size: 11px;
  color: rgba(0,0,0,.35);
  padding: 4px 0 10px;
  background: var(--wpaic-widget-bg);
}

/* ── Mobile Responsive ────────────────────────────────────────── */
@media (max-width: 480px) {
  #wpaic-root {
    bottom: 16px;
    right: 16px;
  }

  .wpaic-widget {
    width: calc(100vw - 32px);
    right: 0;
    bottom: 70px;
    height: calc(100vh - 110px);
    max-height: calc(100vh - 110px);
  }
}

/* ── Reduced Motion ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .wpaic-launcher::before,
  .wpaic-dot { animation: none; }
  .wpaic-widget { animation: none; }
  .wpaic-message { animation: none; }
}
