/* ==========================================================
   AI PANEL STYLES — css/ai-panel.css
   Styles for:
     - Transcript overlay badge
     - AI button states (connected, recording, error)
     - Chat panel (slide-in from right)
   ========================================================== */

/* ── 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);
}

/* ──────────────────────────────────────────────────────────
   CHAT PANEL
   ────────────────────────────────────────────────────────── */

.ai-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100dvh;
  background: #0d1117;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 9500;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: 'Be Vietnam Pro', sans-serif;
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.5);
}

.ai-chat-panel--open {
  transform: translateX(0);
}

/* ── Floating bubble (mobile only, hidden on desktop) ─────── */
.ai-chat-bubble {
  display: none;
}

/* ── Mobile: panel slides from bottom, bubble floats ─────── */
@media (max-width: 768px) {

  /* Panel overrides: slide up from bottom 50% height */
  .ai-chat-panel {
    top: auto !important;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100% !important;
    height: 50dvh;
    max-height: 50dvh;
    border-left: none;
    border-top: 1px solid rgba(94, 234, 212, 0.15);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6);
  }

  .ai-chat-panel--open {
    transform: translateY(0) !important;
  }

  /* Floating bubble */
  .ai-chat-bubble {
    display: flex;
    position: fixed;
    bottom: 88px;
    right: 16px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(13, 17, 23, 0.92);
    border: 2px solid rgba(94, 234, 212, 0.35);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 9600;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.55);
    color: #5eead4;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.2s,
                box-shadow 0.2s;
  }

  /* Move bubble above panel when panel is open */
  .ai-chat-bubble--panel-open {
    bottom: calc(50dvh + 16px);
  }

  /* Recording: pulsing green border */
  .ai-chat-bubble--recording {
    border-color: #22c55e;
  }

  @keyframes bubble-pulse {
    0%, 100% { box-shadow: 0 4px 24px rgba(0,0,0,0.55), 0 0 0 0   rgba(34, 197, 94, 0.5); }
    50%       { box-shadow: 0 4px 24px rgba(0,0,0,0.55), 0 0 0 10px rgba(34, 197, 94, 0);   }
  }

  .ai-chat-bubble--recording {
    border-color: #22c55e;
    animation: bubble-pulse 1.4s ease-in-out infinite;
  }

  /* Status dot in the top-right of bubble */
  .ai-chat-bubble-dot {
    position: absolute;
    top: 9px;
    right: 9px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #64748b;
    border: 1.5px solid rgba(13, 17, 23, 0.85);
    transition: background 0.2s;
  }

  .ai-chat-bubble--connected .ai-chat-bubble-dot { background: #94a3b8; }
  .ai-chat-bubble--active    .ai-chat-bubble-dot { background: #22c55e; animation: dot-pulse 1.2s ease-in-out infinite; }
  .ai-chat-bubble--error     .ai-chat-bubble-dot { background: #ef4444; }
}

/* ── Header ───────────────────────────────────────────────── */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.03);
  flex-shrink: 0;
}

.ai-chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #e2e8f0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.ai-chat-title svg {
  color: #5eead4;
  flex-shrink: 0;
}

.ai-chat-btn-close {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.ai-chat-btn-close:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.08);
}

/* ── Messages ─────────────────────────────────────────────── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.ai-chat-messages::-webkit-scrollbar { width: 4px; }
.ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 2px;
}

.ai-chat-empty {
  color: #475569;
  font-size: 0.8rem;
  text-align: center;
  margin: auto;
  padding: 32px 16px;
  line-height: 1.7;
}
.ai-chat-empty strong { color: #5eead4; }

/* Message bubble */
.ai-chat-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
}

.ai-chat-row-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ai-chat-role {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ai-chat-msg--user .ai-chat-role { color: #7dd3fc; }
.ai-chat-msg--model .ai-chat-role { color: #5eead4; }

.ai-chat-time {
  font-size: 0.68rem;
  color: #475569;
}

.ai-chat-text {
  font-size: 0.85rem;
  line-height: 1.6;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  word-break: break-word;
}

/* Streaming cursor — biến mất khi finalize */
.ai-chat-text--streaming::after {
  content: '▋';
  display: inline-block;
  margin-left: 2px;
  color: #5eead4;
  font-size: 0.75em;
  vertical-align: middle;
  animation: cursor-blink 0.7s ease-in-out infinite;
}

@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

.ai-chat-msg--user .ai-chat-text {
  background: rgba(125, 211, 252, 0.07);
  border-color: rgba(125, 211, 252, 0.15);
}

/* Audio player */
.ai-chat-audio {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  outline: none;
  accent-color: #5eead4;
}
.ai-chat-audio::-webkit-media-controls-panel {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}

/* ── Footer / Status bar ──────────────────────────────────── */
.ai-chat-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 0.75rem;
  color: #475569;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.02);
}
/* push status text to fill remaining space */
#ai-chat-status-text {
  flex: 1;
}

.ai-chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #475569;
  flex-shrink: 0;
}
.ai-chat-dot--connected { background: #94a3b8; }             /* grey — WS connected, mic off */
.ai-chat-dot--active {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
  animation: dot-pulse 1.5s ease-in-out infinite;
}
.ai-chat-dot--idle   { background: #64748b; }
.ai-chat-dot--error  { background: #ef4444; }

@keyframes dot-pulse {
  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); }
}

/* ── Button recording indicator (dot below AI button) ───────────── */
.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 1.2s ease-in-out infinite;
}

/* ── Header mic toggle button ──────────────────────────────── */
.ai-chat-btn-mic {
  background: rgba(94, 234, 212, 0.12);
  border: 1px solid rgba(94, 234, 212, 0.3);
  color: #5eead4;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.ai-chat-btn-mic:hover {
  background: rgba(94, 234, 212, 0.22);
  border-color: rgba(94, 234, 212, 0.55);
}
/* Muted state — mic is paused */
.ai-chat-btn-mic--muted {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.35);
  color: #f87171;
}
.ai-chat-btn-mic--muted:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.6);
}

/* ── Header actions (mic + close) ──────────────────────────── */
.ai-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-chat-btn-stop {
  background: none;
  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;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 4px;
  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);
}

/* ── Text input row ────────────────────────────────────── */
.ai-chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

#ai-chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 8px 12px;
  color: #e2e8f0;
  font-size: 14px;
  font-family: 'Be Vietnam Pro', sans-serif;
  outline: none;
  transition: border-color 0.15s;
}
#ai-chat-input::placeholder {
  color: #475569;
}
#ai-chat-input:focus {
  border-color: rgba(94, 234, 212, 0.4);
}

#ai-chat-send {
  background: #0F6E56;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
#ai-chat-send:hover {
  background: #0e7d62;
}
