/* ============================================================
   Alice Chat Widget · Styles v1.0
   Inherits host page CSS variables when present:
     --ink   (text / panel bg) · --bone (light bg) · --signal (accent)
     --steel · --rule · --ink-2 · --paper
   Falls back to neutral defaults so the widget works on ANY host page.
   ============================================================ */

#alice-chat-root {
  /* CSS variable fallbacks — read host palette if present, else neutral */
  --ac-ink:     var(--ink,     #14233a);
  --ac-ink-2:   var(--ink-2,   #1d3052);
  --ac-bone:    var(--bone,    #ffffff);
  --ac-paper:   var(--paper,   #f7f4ec);
  --ac-signal:  var(--signal,  #2563eb);
  --ac-signal-h:var(--signal-2,#1d4ed8);
  --ac-steel:   var(--steel,   #5a6c7d);
  --ac-rule:    var(--rule,    #e2dccb);
  --ac-radius:  16px;
  --ac-shadow:  0 10px 30px -10px rgba(0,0,0,0.25), 0 4px 12px -4px rgba(0,0,0,0.1);
  --ac-font:    'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;

  position: fixed;
  z-index: 99998;
  font-family: var(--ac-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ac-ink);
}

/* ─── BUBBLE (closed state) ─── */
/* Uses accent (--signal) so it pops on dark and light sites alike.
   Text in --ink for AA contrast against the bright accent. */
#alice-bubble {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem 0.85rem 0.95rem;
  background: var(--ac-signal);
  color: var(--ac-ink);
  border: none;
  border-radius: 999px;
  font-family: var(--ac-font);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.005em;
  cursor: pointer;
  box-shadow: 0 12px 32px -8px rgba(0,0,0,0.35), 0 4px 12px -2px rgba(0,0,0,0.15);
  transition: transform 0.18s ease-out, box-shadow 0.18s ease-out, background 0.18s ease-out;
  z-index: 99998;
  animation: alice-bubble-attention 6s ease-in-out 1.5s 2;
}
#alice-bubble:hover {
  transform: translateY(-2px) scale(1.03);
  background: var(--ac-signal-h);
  box-shadow: 0 18px 42px -10px rgba(0,0,0,0.4);
}
@keyframes alice-bubble-attention {
  0%, 92%, 100% { transform: translateY(0) scale(1); }
  94%           { transform: translateY(-6px) scale(1.04); }
  96%           { transform: translateY(0) scale(1); }
  98%           { transform: translateY(-3px) scale(1.02); }
}
#alice-bubble:focus-visible {
  outline: 2px solid var(--ac-signal);
  outline-offset: 3px;
}
#alice-bubble.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}
#alice-bubble svg { flex-shrink: 0; }

/* When mobile sticky CTA is visible, lift the bubble so they don't overlap.
   Detects #sticky-cta.is-visible on the host page.
   Sticky CTA bar ≈ 5rem tall + safe-area-inset on iPhones with notch ≈ up to 7rem total.
   Lift the bubble to clear it cleanly. */
body:has(#sticky-cta.is-visible) #alice-bubble {
  bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
}

/* ─── PANEL (open state) ─── */
#alice-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: min(380px, calc(100vw - 2rem));
  height: min(560px, calc(100vh - 3rem));
  background: var(--ac-bone);
  border-radius: var(--ac-radius);
  box-shadow: var(--ac-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.22s ease-out, transform 0.22s ease-out;
  z-index: 99999;
}
#alice-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* ─── HEADER ─── */
#alice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  background: var(--ac-ink);
  color: var(--ac-bone);
  flex-shrink: 0;
}
.alice-header-info {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}
.alice-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ac-signal);
  color: var(--ac-bone);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.alice-header-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}
.alice-header-text strong {
  font-weight: 600;
  font-size: 15px;
}
.alice-header-sub {
  font-size: 12px;
  opacity: 0.78;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#alice-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ac-bone);
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0.78;
  transition: opacity 0.15s, background 0.15s;
}
#alice-close:hover { opacity: 1; background: rgba(255,255,255,0.1); }
#alice-close:focus-visible { outline: 2px solid var(--ac-bone); outline-offset: 2px; }

/* ─── MESSAGES ─── */
#alice-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  background: var(--ac-paper);
  scroll-behavior: smooth;
}
#alice-messages::-webkit-scrollbar { width: 6px; }
#alice-messages::-webkit-scrollbar-thumb { background: var(--ac-rule); border-radius: 3px; }

.alice-msg {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  animation: alice-msg-in 0.22s ease-out;
}
@keyframes alice-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.alice-msg--user {
  align-self: flex-end;
  background: var(--ac-ink);
  color: var(--ac-bone);
  border-bottom-right-radius: 4px;
}
.alice-msg--assistant {
  align-self: flex-start;
  background: var(--ac-bone);
  color: var(--ac-ink);
  border: 1px solid var(--ac-rule);
  border-bottom-left-radius: 4px;
}
.alice-msg--assistant a {
  color: var(--ac-signal);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
.alice-msg--assistant a:hover { color: var(--ac-signal-h); }

/* Typing indicator */
.alice-typing {
  display: inline-flex;
  gap: 4px;
  padding: 0.75rem 0.875rem;
}
.alice-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ac-steel);
  opacity: 0.5;
  animation: alice-bounce 1.2s infinite ease-in-out;
}
.alice-typing span:nth-child(2) { animation-delay: 0.15s; }
.alice-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes alice-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ─── INPUT ─── */
#alice-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--ac-bone);
  border-top: 1px solid var(--ac-rule);
  flex-shrink: 0;
}
#alice-input {
  flex: 1;
  padding: 0.625rem 0.875rem;
  border-radius: 999px;
  border: 1px solid var(--ac-rule);
  background: var(--ac-paper);
  color: var(--ac-ink);
  font-family: var(--ac-font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
#alice-input:focus {
  border-color: var(--ac-signal);
  background: var(--ac-bone);
}
#alice-input::placeholder { color: var(--ac-steel); }
#alice-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--ac-signal);
  color: var(--ac-bone);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.15s;
  flex-shrink: 0;
}
#alice-send:hover { background: var(--ac-signal-h); transform: scale(1.05); }
#alice-send:focus-visible { outline: 2px solid var(--ac-ink); outline-offset: 2px; }
#alice-send:active { transform: scale(0.95); }

/* ─── FOOTER ─── */
#alice-footer {
  padding: 0.5rem 0.875rem;
  font-size: 11px;
  color: var(--ac-steel);
  text-align: center;
  background: var(--ac-bone);
  border-top: 1px solid var(--ac-rule);
  flex-shrink: 0;
}
#alice-footer a {
  color: var(--ac-steel);
  text-decoration: none;
  border-bottom: 1px solid var(--ac-rule);
}
#alice-footer a:hover { color: var(--ac-ink); }

/* ─── MOBILE (< 480px) ─── */
@media (max-width: 480px) {
  #alice-panel {
    right: 0.625rem;
    bottom: 0.625rem;
    width: calc(100vw - 1.25rem);
    height: calc(100vh - 1.25rem);
    max-height: calc(100dvh - 1.25rem);
    border-radius: 12px;
  }
  #alice-bubble {
    right: 0.875rem;
    bottom: 0.875rem;
  }
  body:has(#sticky-cta.is-visible) #alice-bubble {
    bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
  }
  /* When sticky CTA is visible, also lift the panel so its bottom edge clears the CTA */
  body:has(#sticky-cta.is-visible) #alice-panel {
    bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    height: calc(100vh - 7rem);
    max-height: calc(100dvh - 7rem);
  }
}

/* ─── REDUCED MOTION ─── */
@media (prefers-reduced-motion: reduce) {
  #alice-bubble,
  #alice-panel,
  .alice-msg,
  .alice-typing span,
  #alice-send {
    transition: none !important;
    animation: none !important;
  }
}
