/* =========================================================
   AVANI CHAT WIDGET — Digital Operations Concierge
   Locked spec: headshot trigger, bottom-right, never hero.
   Theme-aware (uses the shared --color-* tokens so it matches
   whichever page/theme it's rendered on — including the
   forced-dark Uniform Lab tokens for free).
   ========================================================= */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#avani-chat-root {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 400;
}

/* ---------- Trigger ---------- */
.avani-chat-trigger {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  padding: 0;
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: 0 10px 30px -10px var(--color-shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.avani-chat-trigger:hover { transform: scale(1.06); border-color: var(--color-accent); }
.avani-chat-trigger img { width: 100%; height: 100%; object-fit: cover; display: block; }

.avani-chat-trigger .avani-chat-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-accent-light);
  border: 2px solid var(--color-bg);
}

#avani-chat-root.is-open .avani-chat-trigger { display: none; }

/* ---------- Panel ---------- */
.avani-chat-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: min(370px, calc(100vw - 32px));
  max-height: min(600px, 74vh);
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 18px;
  box-shadow: 0 24px 60px -20px var(--color-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity var(--dur-med) var(--ease-out), transform var(--dur-med) var(--ease-out);
}

#avani-chat-root.is-open .avani-chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.avani-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.avani-chat-avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avani-chat-header-text { flex: 1; min-width: 0; }

.avani-chat-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  margin: 0;
}

.avani-chat-subtitle {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin: 2px 0 0;
}

.avani-chat-close {
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 100px;
  flex-shrink: 0;
}
.avani-chat-close:hover { color: var(--color-text); background: var(--color-surface-2); }

.avani-chat-voice {
  background: transparent;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 100px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s ease, background 0.15s ease;
}
.avani-chat-voice svg { width: 18px; height: 18px; display: block; }
.avani-chat-voice:hover { color: var(--color-text); background: var(--color-surface-2); }
.avani-chat-voice .avani-voice-wave { opacity: 0; transition: opacity 0.15s ease; }
.avani-chat-voice.is-on { color: var(--color-accent); }
.avani-chat-voice.is-on .avani-voice-wave { opacity: 1; }

.avani-msg-speak {
  margin-left: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  opacity: 0.5;
  padding: 0;
  vertical-align: middle;
  transition: opacity 0.15s ease;
}
.avani-msg-speak:hover { opacity: 1; }

.avani-chat-intro {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--color-text-secondary);
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.avani-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 120px;
}

.avani-msg {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
}
.avani-msg a { color: inherit; text-decoration: underline; }

.avani-msg.from-user {
  align-self: flex-end;
  background: var(--color-accent);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}

.avani-msg.from-avani {
  align-self: flex-start;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

.avani-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  margin: 0 16px 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  width: fit-content;
}
.avani-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  animation: avani-typing-bounce 1.2s infinite ease-in-out;
}
.avani-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.avani-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes avani-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .avani-chat-typing span { animation: none; opacity: 0.8; }
}

.avani-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.avani-chat-form input {
  flex: 1;
  border-radius: 100px;
  padding: 10px 16px;
  font-size: 13.5px;
}

.avani-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--color-cta-bg);
  color: var(--color-cta-text);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease-out);
}
.avani-chat-send:hover { background: var(--color-cta-bg-hover); }
.avani-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Mobile: full-width bottom sheet ---------- */
@media (max-width: 640px) {
  #avani-chat-root { right: 14px; bottom: 14px; }

  .avani-chat-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 82vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
  }
  #avani-chat-root.is-open .avani-chat-panel { transform: translateY(0); }
}
