/* ==========================================================
   EllieBot Widget – Twice Loved Tales
   Mobile-first, warm bookish aesthetic
   ========================================================== */

:root {
  --ellie-bg: #FFF8F0;
  --ellie-text: #5C3D2E;
  --ellie-accent: #D4A574;
  --ellie-accent-hover: #C4935F;
  --ellie-success: #4CAF50;
  --ellie-danger: #E57373;
  --ellie-muted: #A08070;
  --ellie-border: #E8D5C4;
  --ellie-shadow: rgba(92, 61, 46, 0.15);
  --ellie-radius: 16px;
}

/* ---- Container ---- */
.ellie-widget {
  font-family: 'Georgia', 'Times New Roman', serif;
  color: var(--ellie-text);
  background: var(--ellie-bg);
  border-radius: var(--ellie-radius);
  box-shadow: 0 4px 24px var(--ellie-shadow);
  max-width: 520px;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
  text-align: center;
}

/* ---- Header ---- */
.ellie-header {
  padding: 14px 20px;
  background: linear-gradient(135deg, #5C3D2E 0%, #7A5240 100%);
  color: #FFF8F0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ellie-header h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ellie-header .ellie-status {
  padding: 0;
  background: none;
  border: none;
  border-top: none;
  min-height: auto;
  font-size: 0.75rem;
  color: rgba(255, 248, 240, 0.8);
}

.ellie-header .ellie-status-dot {
  width: 7px;
  height: 7px;
}

/* ---- Video / Avatar Area ---- */
.ellie-stage {
  position: relative;
  width: 100%;
  min-height: 480px;
  background: #2C1E16;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ellie-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
}

/* Static placeholder image */
.ellie-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px 20px;
  z-index: 1;
}

.ellie-placeholder-avatar {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ellie-accent) 0%, #E8C9A8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  animation: ellie-pulse-soft 3s ease-in-out infinite;
}

@keyframes ellie-pulse-soft {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3); }
  50% { transform: scale(1.03); box-shadow: 0 6px 28px rgba(0, 0, 0, 0.4); }
}

.ellie-placeholder-text {
  color: #E8D5C4;
  font-size: 0.95rem;
  font-style: italic;
  max-width: 260px;
  line-height: 1.5;
}

/* ---- Status Bar ---- */
.ellie-status {
  padding: 8px 16px;
  font-size: 0.8rem;
  color: var(--ellie-muted);
  background: var(--ellie-bg);
  border-top: 1px solid var(--ellie-border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
}

.ellie-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ellie-muted);
  flex-shrink: 0;
}

.ellie-status-dot.connected {
  background: var(--ellie-success);
  animation: ellie-blink 2s ease-in-out infinite;
}

.ellie-status-dot.connecting {
  background: var(--ellie-accent);
  animation: ellie-blink 0.8s ease-in-out infinite;
}

.ellie-status-dot.error {
  background: var(--ellie-danger);
}

@keyframes ellie-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---- Controls ---- */
.ellie-controls {
  padding: 16px 20px 20px;
  display: flex;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  background: var(--ellie-bg);
}

/* Shared button base */
.ellie-btn {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.ellie-btn:active {
  transform: scale(0.96);
}

/* Primary CTA – Talk to EllieBot */
.ellie-btn-start {
  padding: 14px 32px;
  background: linear-gradient(135deg, var(--ellie-accent) 0%, #C4935F 100%);
  color: #fff;
  font-size: 1.05rem;
  box-shadow: 0 3px 12px rgba(212, 165, 116, 0.4);
}

.ellie-btn-start:hover {
  background: linear-gradient(135deg, var(--ellie-accent-hover) 0%, #B8874F 100%);
  box-shadow: 0 4px 16px rgba(212, 165, 116, 0.5);
}

/* Mute toggle */
.ellie-btn-mute {
  width: 48px;
  height: 48px;
  padding: 0;
  background: var(--ellie-border);
  color: var(--ellie-text);
  font-size: 1.2rem;
}

.ellie-btn-mute:hover {
  background: var(--ellie-accent);
  color: #fff;
}

.ellie-btn-mute.muted {
  background: var(--ellie-danger);
  color: #fff;
}

/* End call */
.ellie-btn-end {
  width: 48px;
  height: 48px;
  padding: 0;
  background: var(--ellie-danger);
  color: #fff;
  font-size: 1.2rem;
}

.ellie-btn-end:hover {
  background: #D32F2F;
}

/* Bookshelf upload */
.ellie-btn-shelf {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--ellie-bg);
  border: 2px solid var(--ellie-accent);
  font-size: 20px;
}

.ellie-btn-shelf:hover {
  background: var(--ellie-accent);
  color: #fff;
}

/* Restart */
.ellie-btn-restart {
  padding: 12px 28px;
  background: var(--ellie-accent);
  color: #fff;
}

.ellie-btn-restart:hover {
  background: var(--ellie-accent-hover);
}

/* ---- Goodbye Message ---- */
.ellie-goodbye {
  padding: 32px 20px;
  text-align: center;
}

.ellie-goodbye h3 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  color: var(--ellie-text);
}

.ellie-goodbye p {
  margin: 0 0 20px;
  font-size: 0.9rem;
  color: var(--ellie-muted);
  font-style: italic;
}

/* ---- Loading spinner ---- */
.ellie-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--ellie-border);
  border-top-color: var(--ellie-accent);
  border-radius: 50%;
  animation: ellie-spin 0.8s linear infinite;
}

@keyframes ellie-spin {
  to { transform: rotate(360deg); }
}

/* ---- Audio indicator (listening ring) ---- */
.ellie-listening-ring {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--ellie-success);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 2;
}

.ellie-listening-ring.active {
  opacity: 1;
  animation: ellie-ring-pulse 1.5s ease-in-out infinite;
}

@keyframes ellie-ring-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.5; }
}

/* ---- Product Overlay (add_to_cart data message) ---- */
.ellie-product-overlay {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: 90%;
  max-width: 380px;
}

.ellie-product-card {
  background: var(--ellie-bg);
  border-radius: var(--ellie-radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  padding: 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: ellie-slide-up 0.3s ease-out;
}

@keyframes ellie-slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.ellie-product-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ellie-text);
  line-height: 1.3;
}

.ellie-btn-product {
  padding: 12px 24px;
  background: linear-gradient(135deg, #4CAF50 0%, #388E3C 100%);
  color: #fff !important;
  font-size: 1rem;
  text-decoration: none;
  box-shadow: 0 3px 12px rgba(76, 175, 80, 0.4);
}

.ellie-btn-product:hover {
  background: linear-gradient(135deg, #388E3C 0%, #2E7D32 100%);
  box-shadow: 0 4px 16px rgba(76, 175, 80, 0.5);
}

.ellie-btn-dismiss {
  padding: 8px 16px;
  background: transparent;
  color: var(--ellie-muted);
  font-size: 0.8rem;
}

.ellie-btn-dismiss:hover {
  color: var(--ellie-text);
}

/* ---- Hidden utility ---- */
.ellie-hidden {
  display: none !important;
}

/* ==========================================================
   Responsive
   ========================================================== */

/* Tablet and up */
@media (min-width: 600px) {
  .ellie-widget {
    max-width: 560px;
  }

  .ellie-stage {
    min-height: 540px;
  }

  .ellie-header h2 {
    font-size: 1.5rem;
  }
}

/* ---- Start Buttons (idle state) ---- */
.ellie-btn-text-start {
  background: #fff;
  color: var(--ellie-text);
  border: 2px solid var(--ellie-accent);
  margin-top: 8px;
}

.ellie-btn-text-start:active {
  background: var(--ellie-accent);
  color: #fff;
}

/* ---- Chat Messages (WhatsApp-like) ---- */
.ellie-chat {
  max-height: 350px;
  min-height: 80px;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  background: #f0e6d9;
}

.ellie-chat-bubble {
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 82%;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.45;
  position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.ellie-chat-user {
  align-self: flex-end;
  background: #d4a574;
  color: #fff;
  border-bottom-right-radius: 2px;
}

.ellie-chat-ellie {
  align-self: flex-start;
  background: #fff;
  color: var(--ellie-text);
  border-bottom-left-radius: 2px;
}

/* ---- Cart Bubble (inline product links in chat) ---- */
.ellie-chat-cart {
  padding: 12px;
}

.ellie-cart-title {
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 8px;
}

.ellie-cart-buttons {
  display: flex;
  gap: 8px;
}

.ellie-cart-btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: bold;
  text-decoration: none;
  text-align: center;
  min-height: 44px;
  line-height: 28px;
}

.ellie-cart-view {
  background: var(--ellie-border);
  color: var(--ellie-text);
}

.ellie-cart-add {
  background: linear-gradient(135deg, #4CAF50, #388E3C);
  color: #fff;
}

/* ---- Quick Reply Buttons ---- */
.ellie-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0;
  align-self: flex-start;
}

.ellie-quick-btn {
  padding: 8px 16px;
  border: 2px solid var(--ellie-accent);
  border-radius: 20px;
  background: #fff;
  color: var(--ellie-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s, color 0.15s;
}

.ellie-quick-btn:active {
  background: var(--ellie-accent);
  color: #fff;
}

/* Text-only mode: shrink stage, expand chat */
.ellie-stage.ellie-text-mode {
  min-height: 0;
  max-height: 60px;
  overflow: hidden;
}

.ellie-stage.ellie-text-mode .ellie-placeholder {
  display: none;
}

.ellie-stage.ellie-text-mode .ellie-listening-ring {
  display: none;
}

/* ---- Text Input Bar ---- */
.ellie-chat-input {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--ellie-border);
  background: var(--ellie-bg);
}

.ellie-text-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--ellie-border);
  border-radius: 24px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ellie-text);
  background: #fff;
  outline: none;
  min-height: 44px;
}

.ellie-text-input:focus {
  border-color: var(--ellie-accent);
  box-shadow: 0 0 0 2px rgba(212, 165, 116, 0.2);
}

.ellie-btn-send {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  font-size: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Desktop */
@media (min-width: 960px) {
  .ellie-widget {
    max-width: 640px;
  }

  .ellie-stage {
    min-height: 600px;
  }
}
