/* ==========================================================
   AI PANEL STYLES — css/ai-panel.css
   BotChat spec–based redesign
   ========================================================== */

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  --bb-h:           64px;
  --ai-neon:        #16d472;
  --ai-neon-soft:   rgba(22, 212, 114, 0.18);
  --ai-neon-strong: rgba(22, 212, 114, 0.55);
  --icon-blue:      #2bb6e6;
  --icon-blue-dark: #1a9bcb;
}

/* ── Transcript badge ─────────────────────────────────────── */
.ai-transcript {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  max-width: min(520px, 90vw);
  background: rgba(5, 14, 26, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #e2e8f0;
  font-family: 'Be Vietnam Pro', sans-serif;
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 10px 18px;
  border-radius: 24px;
  border: 1px solid rgba(94, 234, 212, 0.2);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
  z-index: 10000;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-transcript--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── AI button — listening state ─────────────────────────── */
.ai-button.ai-connected .ai-ring-outer {
  animation-duration: 0.8s !important;
}
.ai-button.ai-connected .ai-ring-mid {
  animation-duration: 1.1s !important;
}

/* Mic recording dot — appears over the button icon when mic is active */
.ai-button.ai-btn--recording .ai-core::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  background: #ef4444;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.4);
  animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.75); }
}

/* ── Connecting state ─────────────────────────────────────── */
.ai-button.ai-connecting {
  opacity: 0.7;
  pointer-events: none;
}

/* ── Error state ──────────────────────────────────────────── */
.ai-button.ai-error .ai-core {
  background: radial-gradient(
    circle at 50% 40%,
    rgba(239, 68, 68, 0.4) 0%,
    rgba(60, 0, 0, 0.9) 50%,
    rgba(20, 0, 0, 0.98) 100%
  );
  border-color: rgba(239, 68, 68, 0.6);
}

/* ──────────────────────────────────────────────────────────
   FLOAT LAUNCHER BUBBLE
   ────────────────────────────────────────────────────────── */

.ai-chat-bubble {
  position: fixed;
  bottom: 72px;
  right: 20px;
  width: var(--bb-h, 64px);
  height: var(--bb-h, 64px);
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 9600;
  overflow: visible;
  padding: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ai-chat-bubble:hover {
  transform: translateY(-2px);
}

/* Robot avatar SVG fills the circle */
.ai-avatar-svg {
  width: var(--bb-h, 64px);
  height: var(--bb-h, 64px);
  border-radius: 50%;
  display: block;
  filter: drop-shadow(0 6px 22px rgba(0, 0, 0, 0.35));
  transition: filter 0.2s;
}

.ai-chat-bubble:hover .ai-avatar-svg {
  filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.45));
}

/* Mic indicator dot — bottom-right corner */
.ai-bb-mic-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ai-neon, #16d472);
  border: 2.5px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  pointer-events: none;
  transition: background 0.2s;
}

.ai-bb-mic-dot--idle    { background: #94a3b8; }
.ai-bb-mic-dot--error   { background: #ef4444; }
.ai-bb-mic-dot--active  { animation: bbMicPulse 1.2s ease-in-out infinite; }

@keyframes bbMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--ai-neon-soft); }
  50%       { box-shadow: 0 0 0 6px rgba(22, 212, 114, 0); }
}

/* ──────────────────────────────────────────────────────────
   CHAT PANEL — BotChat spec design
   ────────────────────────────────────────────────────────── */

.ai-chat-panel {
  position: fixed;
  bottom: calc(72px + var(--bb-h, 64px) + 12px);
  right: 20px;
  width: 360px;
  height: 480px;
  max-height: calc(100dvh - 120px);
  background: #ffffff;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: 9500;
  transform: translateY(20px) scale(0.96);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transition: transform 0.22s ease, opacity 0.22s ease;
  font-family: 'Be Vietnam Pro', sans-serif;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.22);
}

.ai-chat-panel--open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.ai-chat-panel--expanded {
  width: 420px;
  height: calc(100dvh - 120px);
  max-height: calc(100dvh - 120px);
}

/* ── Panel Header ─────────────────────────────────────────── */

.ai-pn-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #eef0f2;
  background: #ffffff;
  flex-shrink: 0;
}

.ai-pn-orb {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #1a1f2e;
  border: 1.5px solid rgba(22, 212, 114, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ai-neon, #16d472);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  overflow: hidden;
}

/* Robot SVG scaled for orb */
.ai-pn-orb .ai-avatar-svg {
  width: 38px;
  height: 38px;
  filter: none;
}

.ai-pn-h {
  flex: 1;
  min-width: 0;
}

.ai-pn-title {
  font-size: 14px;
  font-weight: 800;
  color: #1a1a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-pn-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

/* Status dot */
.ai-pn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd5e1;
  flex-shrink: 0;
  transition: background 0.2s;
}

.ai-chat-panel.state-connected .ai-pn-dot,
.ai-chat-panel.state-active    .ai-pn-dot {
  background: var(--ai-neon, #16d472);
  animation: aiStatusPulse 1.6s ease-in-out infinite;
}
.ai-chat-panel.state-active .ai-pn-dot { animation-duration: 0.8s; }
.ai-chat-panel.state-error  .ai-pn-dot { background: #ef4444; animation: none; }

@keyframes aiStatusPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(22, 212, 114, 0.22); }
  50%       { box-shadow: 0 0 0 5px rgba(22, 212, 114, 0.08); }
}

.ai-pn-status {
  font-size: 11.5px;
  color: #64748b;
  transition: color 0.2s;
}
.ai-chat-panel.state-connected .ai-pn-status,
.ai-chat-panel.state-active    .ai-pn-status { color: #16a35a; }
.ai-chat-panel.state-error     .ai-pn-status { color: #ef4444; }

.ai-pn-x {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f4f6f8;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #64748b;
  font-size: 19px;
  font-weight: 400;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.ai-pn-x:hover {
  background: #fee2e2;
  color: #ef4444;
}

/* ── Body (messages) ──────────────────────────────────────── */

.ai-pn-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: #f7f9fb;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: #d0d5db transparent;
}
.ai-pn-body::-webkit-scrollbar { width: 4px; }
.ai-pn-body::-webkit-scrollbar-thumb { background: #d0d5db; border-radius: 2px; }

.ai-pn-chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ai-pn-empty {
  font-size: 13px;
  color: #94a3b8;
  text-align: center;
  padding: 24px 8px;
  line-height: 1.7;
}

/* Message bubbles — new BotChat design */
.ai-pn-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: aiBubbleIn 0.25s ease forwards;
}

.ai-pn-bubble.bot {
  background: #ffffff;
  color: #1a2330;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.ai-pn-bubble.user {
  background: var(--icon-blue, #2bb6e6);
  color: #ffffff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  margin-left: auto;
}

@keyframes aiBubbleIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Streaming cursor */
.ai-pn-bubble-text--stream::after {
  content: '\25ae';
  display: inline-block;
  margin-left: 2px;
  color: var(--icon-blue, #2bb6e6);
  font-size: 0.8em;
  animation: cursorBlink 0.7s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}



/* ── Composer ─────────────────────────────────────────────── */

.ai-pn-composer {
  display: flex;
  flex-direction: column;
  padding: 10px 12px 14px;
  border-top: 1px solid #eef0f2;
  background: #fafbfc;
  flex-shrink: 0;
  gap: 8px;
}

/* Top row: input + mic + send */
.ai-pn-composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-pn-input {
  flex: 1;
  height: 36px;
  padding: 0 14px;
  border: 1.5px solid #e4e8ec;
  border-radius: 18px;
  font-size: 13px;
  font-family: inherit;
  background: #ffffff;
  color: #111111 !important;
  outline: none;
  transition: border-color 0.15s;
}
.ai-pn-input:focus { border-color: var(--icon-blue, #2bb6e6); }
.ai-pn-input::placeholder { color: #adb5bd; }

.ai-pn-mic {
  width: 36px !important;
  height: 36px !important;
  border-radius: 50% !important;
  border: 1.5px solid var(--ai-neon, #16d472) !important;
  background: #ffffff !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer;
  color: var(--ai-neon, #16d472) !important;
  flex-shrink: 0;
  transition: background 0.15s, box-shadow 0.15s;
}
.ai-pn-mic:hover { background: var(--ai-neon-soft, rgba(22,212,114,0.18)); }

/* Muted / disconnected mic */
.ai-pn-mic.ai-pn-mic--muted {
  border-color: #e4e8ec;
  color: #94a3b8;
}

/* Active mic: pulse ring */
.ai-pn-mic.ai-pn-mic--active {
  border-color: var(--ai-neon, #16d472);
  background: var(--ai-neon-soft);
  animation: aiMicPulse 1.4s ease-in-out infinite;
}

@keyframes aiMicPulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--ai-neon-soft), 0 0 14px var(--ai-neon); }
  50%       { box-shadow: 0 0 0 7px rgba(22,212,114,.06), 0 0 22px var(--ai-neon); }
}

.ai-pn-send {
  width: 36px !important;
  height: 36px !important;
  border-radius: 50% !important;
  border: none !important;
  background: var(--icon-blue, #2bb6e6) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  color: #ffffff !important;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}
.ai-pn-send:hover {
  background: var(--icon-blue-dark, #1a9bcb) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(43,182,230,0.4);
}

/* Faded state when input is empty */
.ai-pn-send.ai-pn-send--idle {
  background: rgba(43, 182, 230, 0.32) !important;
  cursor: default;
}
.ai-pn-send.ai-pn-send--idle:hover {
  background: rgba(43, 182, 230, 0.32) !important;
  transform: none;
  box-shadow: none;
}

.ai-pn-send svg,
.ai-pn-mic svg {
  display: block;
  flex-shrink: 0;
  max-width: none !important;
  max-height: none !important;
}

/* FA paper-plane: shift left to compensate asymmetric viewBox */
.ai-pn-send svg {
  transform: translateX(-1px);
}

/* ── Waveform (24 bars) ───────────────────────────────────── */

.ai-pn-waveform {
  display: none;
  align-items: center;
  justify-content: center;
  height: 28px;
  gap: 2px;
}

.ai-chat-panel.state-active .ai-pn-waveform { display: flex; }

.ai-pn-waveform span {
  display: inline-block;
  width: 3px;
  border-radius: 2px;
  background: var(--ai-neon, #16d472);
  box-shadow: 0 0 5px var(--ai-neon), 0 0 10px var(--ai-neon-strong);
  transform-origin: center;
  animation: aiWaveBar 1s ease-in-out infinite;
}

@keyframes aiWaveBar {
  0%, 100% { transform: scaleY(0.25); }
  50%       { transform: scaleY(1); }
}

/* Staggered 24-bar profile — symmetric bell curve */
.ai-pn-waveform span:nth-child(1)  { height: 8px;  animation-delay: 0.00s; }
.ai-pn-waveform span:nth-child(2)  { height: 10px; animation-delay: 0.04s; }
.ai-pn-waveform span:nth-child(3)  { height: 13px; animation-delay: 0.08s; }
.ai-pn-waveform span:nth-child(4)  { height: 16px; animation-delay: 0.12s; }
.ai-pn-waveform span:nth-child(5)  { height: 19px; animation-delay: 0.16s; }
.ai-pn-waveform span:nth-child(6)  { height: 21px; animation-delay: 0.20s; }
.ai-pn-waveform span:nth-child(7)  { height: 24px; animation-delay: 0.24s; }
.ai-pn-waveform span:nth-child(8)  { height: 26px; animation-delay: 0.28s; }
.ai-pn-waveform span:nth-child(9)  { height: 28px; animation-delay: 0.32s; }
.ai-pn-waveform span:nth-child(10) { height: 28px; animation-delay: 0.36s; }
.ai-pn-waveform span:nth-child(11) { height: 28px; animation-delay: 0.32s; }
.ai-pn-waveform span:nth-child(12) { height: 26px; animation-delay: 0.28s; }
.ai-pn-waveform span:nth-child(13) { height: 24px; animation-delay: 0.24s; }
.ai-pn-waveform span:nth-child(14) { height: 24px; animation-delay: 0.20s; }
.ai-pn-waveform span:nth-child(15) { height: 26px; animation-delay: 0.24s; }
.ai-pn-waveform span:nth-child(16) { height: 28px; animation-delay: 0.28s; }
.ai-pn-waveform span:nth-child(17) { height: 28px; animation-delay: 0.32s; }
.ai-pn-waveform span:nth-child(18) { height: 28px; animation-delay: 0.36s; }
.ai-pn-waveform span:nth-child(19) { height: 26px; animation-delay: 0.28s; }
.ai-pn-waveform span:nth-child(20) { height: 24px; animation-delay: 0.24s; }
.ai-pn-waveform span:nth-child(21) { height: 21px; animation-delay: 0.20s; }
.ai-pn-waveform span:nth-child(22) { height: 16px; animation-delay: 0.12s; }
.ai-pn-waveform span:nth-child(23) { height: 11px; animation-delay: 0.08s; }
.ai-pn-waveform span:nth-child(24) { height: 8px;  animation-delay: 0.04s; }

/* ── Mobile: full-width bottom sheet ─────────────────────── */
@media (max-width: 768px) {
  .ai-chat-panel {
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-height: 70dvh !important;
    border-radius: 20px 20px 0 0 !important;
    transform: translateY(100%) !important;
    transform-origin: bottom center !important;
  }
  .ai-chat-panel--open {
    transform: translateY(0) !important;
  }
  .ai-chat-bubble--panel-open {
    bottom: calc(70dvh + 12px) !important;
  }
}

/* ── Keep old ai-button state CSS intact ─────────────────── */
.ai-chat-btn-stop {
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #f87171;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.ai-chat-btn-stop:hover {
  color: #fff;
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.6);
}

.ai-dot {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.ai-btn--recording .ai-dot {
  opacity: 1;
  animation: dot-pulse-green 1.2s ease-in-out infinite;
}

@keyframes dot-pulse-green {
  0%, 100% { box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
  50%       { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.05); }
}

/* ── Replay button inside bot bubbles ─────────────────────── */
.ai-pn-replay {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-top: 6px;
  margin-left: 2px;
  border-radius: 50%;
  border: 1px solid rgba(43, 182, 230, 0.35);
  background: rgba(43, 182, 230, 0.08);
  color: var(--icon-blue, #2bb6e6);
  cursor: pointer;
  vertical-align: middle;
  transition: background 0.15s, border-color 0.15s;
}
.ai-pn-replay:hover {
  background: rgba(43, 182, 230, 0.22);
  border-color: var(--icon-blue, #2bb6e6);
}
.ai-pn-bubble.bot { display: flex; flex-direction: column; align-items: flex-start; }
