/* ═══════════════════════════════════════════════════════════════════════════
   Speno AI Chatbot Widget — Spenomatic Brand Theme
   Brand Colors: Navy #281E48 | Red #E11D48 | Blue #2563EB
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── CSS Variables ─────────────────────────────────────────────────────── */
:root {
  /* Primary — deep Spenomatic navy */
  --speno-primary:      #281E48;
  --speno-primary-mid:  #31275C;
  --speno-primary-light:#382B73;

  /* Accent — brand red (CTAs, bubble, key highlights) */
  --speno-red:          #E11D48;
  --speno-red-hover:    #BE123C;
  --speno-red-soft:     #fff0f3;   /* very light red tint — safe background */

  /* Accent — brand blue (links, info, secondary actions) */
  --speno-blue:         #2563EB;
  --speno-blue-hover:   #1D4ED8;
  --speno-blue-soft:    #EFF6FF;   /* light blue tint */

  /* Surfaces */
  --speno-surface:      #ffffff;
  --speno-surface-2:    #F8F7FC;   /* warm off-white tinted purple */
  --speno-bot-bg:       #F1F0F8;   /* very light purple-tinted bg for bot messages */

  /* User bubble: navy gradient */
  --speno-user-bg:      linear-gradient(135deg, #281E48 0%, #382B73 100%);

  /* Typography */
  --speno-text:         #1E1B4B;
  --speno-text-body:    #374151;
  --speno-text-muted:   #6B7280;
  --speno-border:       rgba(40, 30, 72, 0.12);

  /* Shadows */
  --speno-shadow:       0 20px 60px rgba(40, 30, 72, 0.20), 0 4px 16px rgba(40, 30, 72, 0.10);
  --speno-shadow-btn:   0 4px 16px rgba(225, 29, 72, 0.35);

  /* Misc */
  --speno-radius:       18px;
  --speno-radius-sm:    10px;
  --speno-font:         var(--font-body, 'Spenomatic Optima', Optima, Candara, sans-serif);
  --speno-transition:   0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --speno-z:            99999;
}

/* ─── Launcher Bubble ────────────────────────────────────────────────────── */
#speno-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--speno-z);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: var(--speno-font);
}

#speno-bubble {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #E11D48 0%, #BE123C 100%);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--speno-shadow-btn);
  transition: transform var(--speno-transition), box-shadow var(--speno-transition);
  position: relative;
  outline: none;
}

#speno-bubble:hover {
  transform: scale(1.1) translateY(-2px);
  box-shadow: 0 8px 28px rgba(225, 29, 72, 0.50);
}

#speno-bubble:active { transform: scale(0.95); }

#speno-bubble svg {
  width: 28px;
  height: 28px;
  fill: #ffffff;
  transition: transform var(--speno-transition), opacity var(--speno-transition);
}

#speno-bubble .icon-chat  { display: block; }
#speno-bubble .icon-close { display: none; }
#speno-bubble.is-open .icon-chat  { display: none; }
#speno-bubble.is-open .icon-close { display: block; }

/* Pulse ring */
#speno-bubble::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(225, 29, 72, 0.40);
  animation: speno-pulse 2.6s ease-out infinite;
}

@keyframes speno-pulse {
  0%   { transform: scale(1); opacity: 0.8; }
  70%  { transform: scale(1.38); opacity: 0; }
  100% { transform: scale(1.38); opacity: 0; }
}

/* Unread badge */
#speno-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #2563EB;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  opacity: 0;
  transform: scale(0);
  transition: var(--speno-transition);
}

#speno-badge.visible { opacity: 1; transform: scale(1); }

/* Tooltip */
#speno-tooltip {
  background: var(--speno-primary);
  color: #fff;
  font-family: var(--speno-font);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 24px;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(40, 30, 72, 0.28);
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

#speno-tooltip.visible { opacity: 1; transform: translateX(0); }

/* ─── Chat Window ────────────────────────────────────────────────────────── */
#speno-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: var(--speno-z);
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100dvh - 120px);
  background: var(--speno-surface);
  border-radius: var(--speno-radius);
  box-shadow: var(--speno-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--speno-font);
  border: 1px solid var(--speno-border);

  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity var(--speno-transition), transform var(--speno-transition);
}

#speno-window.is-open {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0) scale(1);
}

/* ─── Chat Header ────────────────────────────────────────────────────────── */
#speno-header {
  background: linear-gradient(135deg, #281E48 0%, #31275C 55%, #382B73 100%);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

/* Subtle decorative arc — brand red tint, very soft */
#speno-header::after {
  content: '';
  position: absolute;
  top: -28px; right: -28px;
  width: 90px; height: 90px;
  background: rgba(225, 29, 72, 0.12);
  border-radius: 50%;
  pointer-events: none;
}

.speno-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #E11D48 0%, #BE123C 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
  box-shadow: 0 2px 10px rgba(225, 29, 72, 0.35);
}

.speno-header-info { flex: 1; }

.speno-header-name {
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0 0 2px;
}

.speno-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.68);
}

.speno-status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  animation: speno-blink 2s ease infinite;
}

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

.speno-header-close {
  background: rgba(255, 255, 255, 0.10);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.85);
  transition: background var(--speno-transition);
  flex-shrink: 0;
}

.speno-header-close:hover { background: rgba(255, 255, 255, 0.20); }

.speno-header-close svg {
  width: 16px; height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* ─── Messages Area ──────────────────────────────────────────────────────── */
#speno-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: var(--speno-surface-2);
}

#speno-messages::-webkit-scrollbar { width: 4px; }
#speno-messages::-webkit-scrollbar-track { background: transparent; }
#speno-messages::-webkit-scrollbar-thumb { background: rgba(40, 30, 72, 0.15); border-radius: 4px; }

/* Message row */
.speno-msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: speno-msg-in 0.28s ease both;
}

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

.speno-msg-row.user { flex-direction: row-reverse; }

/* Avatar */
.speno-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Bot avatar: brand red */
  background: linear-gradient(135deg, #E11D48 0%, #BE123C 100%);
}

.speno-msg-row.user .speno-msg-avatar {
  /* User avatar: brand navy */
  background: linear-gradient(135deg, #281E48 0%, #382B73 100%);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

/* Bubble */
.speno-bubble-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
  color: var(--speno-text-body);
}

/* Bot bubble: soft neutral — no red bg (would be jarring) */
.speno-msg-row.bot .speno-bubble-msg {
  background: var(--speno-bot-bg);
  color: var(--speno-text-body);
  border-bottom-left-radius: 4px;
}

/* User bubble: navy gradient — readable white text */
.speno-msg-row.user .speno-bubble-msg {
  background: var(--speno-user-bg);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

/* Markdown-lite inside bubbles */
.speno-bubble-msg p  { margin: 0 0 6px; }
.speno-bubble-msg p:last-child { margin: 0; }
.speno-bubble-msg ul, .speno-bubble-msg ol { margin: 4px 0 4px 16px; padding: 0; }
.speno-bubble-msg li { margin: 2px 0; }
.speno-bubble-msg strong { font-weight: 700; }
.speno-bubble-msg em { font-style: italic; }
.speno-bubble-msg code {
  font-family: monospace;
  background: rgba(40, 30, 72, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}
/* Links in bot bubble: brand blue (legible on light bg) */
.speno-bubble-msg a { color: var(--speno-blue); font-weight: 600; text-decoration: underline; }
/* Links in user bubble: soft blue-white (legible on dark bg) */
.speno-msg-row.user .speno-bubble-msg a { color: #93C5FD; }
.speno-bubble-msg hr { border: none; border-top: 1px solid rgba(0,0,0,0.08); margin: 8px 0; }

/* Timestamp */
.speno-msg-time {
  font-size: 10px;
  color: var(--speno-text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

/* ─── CTA Action Cards ────────────────────────────────────────────────────── */
.speno-cta-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 6px;
  animation: speno-msg-in 0.3s ease both;
}

.speno-cta-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border: 1.5px solid var(--speno-border);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-family: var(--speno-font);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--speno-primary);
  transition: background var(--speno-transition), border-color var(--speno-transition), transform 0.15s;
  text-align: left;
  width: 100%;
}

.speno-cta-btn:hover {
  background: var(--speno-bot-bg);
  border-color: var(--speno-primary-mid);
  transform: translateX(2px);
}

.speno-cta-btn:active { transform: scale(0.98); }

/* Primary CTA: brand red — warm & action-oriented */
.speno-cta-btn.accent {
  background: linear-gradient(135deg, #E11D48 0%, #BE123C 100%);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(225, 29, 72, 0.30);
}

.speno-cta-btn.accent:hover {
  background: linear-gradient(135deg, #F43F5E 0%, #E11D48 100%);
  transform: translateX(2px) translateY(-1px);
  box-shadow: 0 5px 16px rgba(225, 29, 72, 0.42);
}

.speno-cta-icon  { font-size: 17px; flex-shrink: 0; }
.speno-cta-label { flex: 1; }
.speno-cta-arrow { margin-left: auto; opacity: 0.45; font-size: 14px; }

/* ─── Typing Indicator ───────────────────────────────────────────────────── */
#speno-typing {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

#speno-typing.visible { display: flex; }

.speno-typing-dots {
  display: flex;
  gap: 4px;
  background: var(--speno-bot-bg);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
}

.speno-typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--speno-primary-mid);
  border-radius: 50%;
  animation: speno-dot 1.2s ease infinite;
  opacity: 0.45;
}

.speno-typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.speno-typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes speno-dot {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.4; }
  40%            { transform: scale(1.25); opacity: 1; }
}

/* ─── Email Capture Banner ───────────────────────────────────────────────── */
/* Using very soft blue tint — welcoming, not alarming */
#speno-email-capture {
  background: var(--speno-blue-soft);
  border-top: 1px solid rgba(37, 99, 235, 0.18);
  padding: 14px 16px;
  display: none;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

#speno-email-capture.visible { display: flex; }

.speno-email-label {
  font-size: 12.5px;
  font-weight: 600;
  color: #1D4ED8;   /* blue — readable on light blue bg */
  display: flex;
  align-items: center;
  gap: 5px;
}

.speno-email-row { display: flex; gap: 7px; }

.speno-email-row input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid rgba(37, 99, 235, 0.30);
  border-radius: 10px;
  font-family: var(--speno-font);
  font-size: 13px;
  outline: none;
  background: #ffffff;
  color: var(--speno-text);
  transition: border-color var(--speno-transition), box-shadow var(--speno-transition);
}

.speno-email-row input:focus {
  border-color: var(--speno-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* Email submit: brand blue (differentiates from red CTAs — "info/proceed" action) */
.speno-email-row button {
  padding: 9px 14px;
  background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-family: var(--speno-font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--speno-transition), transform 0.15s;
}

.speno-email-row button:hover {
  background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
  transform: translateY(-1px);
}

.speno-email-skip {
  font-size: 11px;
  color: var(--speno-text-muted);
  cursor: pointer;
  text-decoration: underline;
  align-self: flex-start;
}

/* ─── Input Area ─────────────────────────────────────────────────────────── */
#speno-input-area {
  border-top: 1px solid var(--speno-border);
  padding: 12px 14px;
  background: var(--speno-surface);
  flex-shrink: 0;
}

.speno-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#speno-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--speno-border);
  border-radius: 22px;
  font-family: var(--speno-font);
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
  background: var(--speno-surface-2);
  color: var(--speno-text);
  outline: none;
  transition: border-color var(--speno-transition), box-shadow var(--speno-transition);
}

#speno-input:focus {
  border-color: var(--speno-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.10);
  background: #ffffff;
}

#speno-input::placeholder { color: var(--speno-text-muted); }

/* Send button: brand red — calls to action */
#speno-send {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #E11D48 0%, #BE123C 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--speno-transition), transform 0.15s, box-shadow var(--speno-transition);
  box-shadow: 0 2px 8px rgba(225, 29, 72, 0.30);
}

#speno-send:hover {
  background: linear-gradient(135deg, #F43F5E 0%, #E11D48 100%);
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(225, 29, 72, 0.45);
}

#speno-send:active { transform: scale(0.94); }
#speno-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

#speno-send svg {
  width: 18px;
  height: 18px;
  fill: #ffffff;
  transform: translateX(1px);
}

.speno-input-footer {
  display: flex;
  justify-content: center;
  margin-top: 6px;
}

.speno-powered-by {
  font-size: 10px;
  color: var(--speno-text-muted);
  letter-spacing: 0.03em;
}

.speno-powered-by a {
  color: var(--speno-blue);
  text-decoration: none;
  font-weight: 600;
}

/* ─── Welcome Screen ─────────────────────────────────────────────────────── */
#speno-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 20px;
  text-align: center;
  gap: 12px;
  background: var(--speno-surface-2);
  flex: 1;
}

.speno-welcome-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #E11D48 0%, #BE123C 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  box-shadow: 0 6px 20px rgba(225, 29, 72, 0.28);
  margin-bottom: 4px;
}

.speno-welcome-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--speno-primary);
  margin: 0;
}

.speno-welcome-sub {
  font-size: 13px;
  color: var(--speno-text-muted);
  max-width: 260px;
  line-height: 1.65;
  margin: 0;
}

.speno-welcome-starters {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  margin-top: 8px;
}

.speno-starter-btn {
  background: #ffffff;
  border: 1.5px solid var(--speno-border);
  border-radius: 10px;
  padding: 9px 14px;
  font-family: var(--speno-font);
  font-size: 13px;
  color: var(--speno-primary);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--speno-transition), border-color var(--speno-transition);
  text-align: left;
}

.speno-starter-btn:hover {
  background: var(--speno-bot-bg);
  border-color: var(--speno-primary-light);
}

/* ─── Notification Toast ─────────────────────────────────────────────────── */
#speno-toast {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: calc(var(--speno-z) - 1);
  background: var(--speno-primary);
  color: #ffffff;
  padding: 13px 18px;
  border-radius: 14px;
  font-family: var(--speno-font);
  font-size: 13.5px;
  font-weight: 500;
  max-width: 280px;
  box-shadow: var(--speno-shadow);
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
  /* Red left accent bar */
  border-left: 4px solid #E11D48;
}

#speno-toast.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

#speno-toast .toast-emoji { font-size: 18px; flex-shrink: 0; }

/* ─── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #speno-window {
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: var(--speno-radius) var(--speno-radius) 0 0;
  }

  #speno-launcher { bottom: 16px; right: 16px; }
  #speno-toast { right: 16px; bottom: 90px; }
}

/* ─── Reduced Motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #speno-bubble::before,
  .speno-status-dot,
  .speno-typing-dots span { animation: none; }
  #speno-window, #speno-toast { transition: opacity 0.15s ease; }
}
