/* VIVA AI Floating Chat Widget — loads on any page */
:root {
  --viva-red: #E30613;
  --viva-red-600: #C70510;
  --ink-900: #0A0A0B;
  --ink-200: #E4E4E8;
  --ink-500: #6B6B72;
}

/* Hide on pages that already have the hero chat (avoid double widget) */
body.has-hero-chat .viva-widget { display: none !important; }

.viva-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  font-family: 'Inter', 'Manrope', system-ui, -apple-system, sans-serif;
}

/* Floating launcher button (collapsed state) */
.viva-widget-launcher {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--viva-red);
  border: none;
  color: white;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(227,6,19,.35), 0 4px 10px rgba(10,10,11,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, box-shadow .2s, background .18s;
  position: relative;
}
.viva-widget-launcher:hover {
  background: var(--viva-red-600);
  transform: scale(1.05);
  box-shadow: 0 16px 40px rgba(227,6,19,.45), 0 6px 14px rgba(10,10,11,.2);
}
.viva-widget-launcher:focus-visible {
  outline: 3px solid rgba(227,6,19,.4);
  outline-offset: 3px;
}
.viva-widget-launcher svg {
  width: 28px;
  height: 28px;
}
.viva-widget-launcher .pulse-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--viva-red);
  opacity: 0;
  animation: viva-pulse 2.4s infinite;
  pointer-events: none;
}
@keyframes viva-pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* Expanded panel */
.viva-widget-panel {
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 48px);
  background: var(--ink-900);
  border-radius: 20px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  color: white;
  box-shadow: 0 30px 60px rgba(10,10,11,.28), 0 10px 24px rgba(227,6,19,.14);
  border: 1px solid rgba(255,255,255,.08);
}
.viva-widget[data-open="true"] .viva-widget-panel { display: flex; }
.viva-widget[data-open="true"] .viva-widget-launcher { display: none; }

.viva-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.viva-widget-brand { display: flex; align-items: center; gap: 10px; }
.viva-widget-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--viva-red); color: white;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Manrope', sans-serif; font-weight: 800; font-size: 14px;
}
.viva-widget-title { font-weight: 700; font-size: 13px; }
.viva-widget-subtitle { font-size: 11px; color: rgba(255,255,255,.5); display: flex; align-items: center; gap: 6px; }
.viva-widget-subtitle .live-dot { width: 6px; height: 6px; background: #10B981; border-radius: 50%; box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.viva-widget-actions { display: flex; gap: 6px; }
.viva-widget-btn {
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08);
  color: rgba(255,255,255,.7); width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background .15s;
}
.viva-widget-btn:hover { background: rgba(255,255,255,.12); color: white; }

.viva-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.viva-widget-messages::-webkit-scrollbar { width: 6px; }
.viva-widget-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.08); border-radius: 3px; }

.viva-widget-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.viva-widget-bubble-bot {
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.06);
  color: white;
  align-self: flex-start;
  border-top-left-radius: 4px;
}
.viva-widget-bubble-user {
  background: var(--viva-red);
  color: white;
  align-self: flex-end;
  border-top-right-radius: 4px;
}
.viva-widget-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.viva-widget-suggest {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.08);
  color: white; font-size: 11.5px; padding: 5px 9px; border-radius: 7px;
  cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.viva-widget-suggest:hover { background: rgba(255,255,255,.14); }

.viva-widget-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.viva-widget-typing span {
  width: 6px; height: 6px;
  background: rgba(255,255,255,.4);
  border-radius: 50%;
  animation: viva-bounce 1.4s infinite ease-in-out both;
}
.viva-widget-typing span:nth-child(1) { animation-delay: -0.32s; }
.viva-widget-typing span:nth-child(2) { animation-delay: -0.16s; }
@keyframes viva-bounce {
  0%, 80%, 100% { transform: scale(0.3); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.viva-widget-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02);
}
.viva-widget-input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  color: white;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, background .15s;
}
.viva-widget-input::placeholder { color: rgba(255,255,255,.4); }
.viva-widget-input:focus { border-color: var(--viva-red); background: rgba(255,255,255,.08); }
.viva-widget-send {
  background: var(--viva-red); color: white;
  border: none; width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s;
}
.viva-widget-send:hover { background: #FF1B2A; }
.viva-widget-send:disabled { opacity: 0.5; cursor: not-allowed; }

.viva-widget-error {
  background: rgba(227,6,19,.1);
  border: 1px solid rgba(227,6,19,.3);
  color: #FF5864;
  font-size: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  margin: 10px 16px;
  text-align: center;
}

/* Mobile: full-screen modal <640px */
@media (max-width: 640px) {
  .viva-widget {
    bottom: 16px;
    right: 16px;
  }
  .viva-widget[data-open="true"] {
    inset: 0;
    bottom: 0;
    right: 0;
  }
  .viva-widget[data-open="true"] .viva-widget-panel {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }
}

/* Tool use pills */
.viva-tool-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  font-size: 11px; color: rgba(255,255,255,.7);
  margin: 4px 16px;
  animation: viva-fadeIn .3s;
  align-self: flex-start;
}
.viva-tool-pill.ok { border-color: rgba(16,185,129,.3); color: #10B981; }
.viva-tool-pill.err { border-color: rgba(239,68,68,.3); color: #EF4444; }
@keyframes viva-fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .viva-widget-launcher .pulse-ring { animation: none; }
  .viva-widget-typing span { animation: none; opacity: 0.5; }
  .viva-widget-launcher { transition: none; }
  .viva-tool-pill { animation: none; }
}
