/* ============================================================
   LiveKit Voice Assistant v2 — Clean White + Teal Theme
   ============================================================ */

:root {
  --lk-primary: #10384f;
  --lk-primary-light: #1a5070;
  --lk-accent: #01BEFF;
  --lk-green: #56D500;
  --lk-bg: #ffffff;
  --lk-bg-muted: #f6f8fa;
  --lk-bg-card: #f0f0f2;
  --lk-fg: #1a1a1a;
  --lk-fg-muted: #6b7280;
  --lk-border: #e5e7eb;
  --lk-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  --lk-radius: 20px;
  --lk-width: 400px;
  --lk-height: 620px;
  --lk-danger: #ef4444;
}

/* =========================================================
   Trigger Button — Bottom-right floating pill
   ========================================================= */
#lk-trigger {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 20px 0 16px;
  border: none;
  border-radius: 26px;
  background: var(--lk-primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  white-space: nowrap;
}

#lk-trigger:hover {
  transform: scale(1.04);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.32);
  background: var(--lk-primary-light);
}

/* Wave bars in trigger button */
#lk-trigger .lk-trigger-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 22px;
}

#lk-trigger .lk-trigger-bars span {
  display: block;
  width: 3px;
  border-radius: 2px;
  background: var(--lk-accent);
  animation: lk-trigger-pulse 1.2s ease-in-out infinite;
}

#lk-trigger .lk-trigger-bars span:nth-child(1) { height: 8px; animation-delay: 0s; }
#lk-trigger .lk-trigger-bars span:nth-child(2) { height: 14px; animation-delay: 0.15s; }
#lk-trigger .lk-trigger-bars span:nth-child(3) { height: 20px; animation-delay: 0.3s; }
#lk-trigger .lk-trigger-bars span:nth-child(4) { height: 14px; animation-delay: 0.15s; }
#lk-trigger .lk-trigger-bars span:nth-child(5) { height: 8px; animation-delay: 0s; }

@keyframes lk-trigger-pulse {
  0%, 100% { transform: scaleY(0.4); opacity: 0.5; }
  50% { transform: scaleY(1); opacity: 1; }
}

#lk-trigger.lk-active .lk-trigger-bars span {
  background: var(--lk-green);
}

/* =========================================================
   Panel — Main floating widget
   ========================================================= */
#lk-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  z-index: 10001;
  width: var(--lk-width);
  height: var(--lk-height);
  max-height: calc(100vh - 110px);
  background: var(--lk-bg);
  border-radius: var(--lk-radius);
  border: 1px solid var(--lk-border);
  box-shadow: var(--lk-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform-origin: bottom right;
}

#lk-panel.lk-hidden {
  opacity: 0;
  transform: scale(0.92) translateY(12px);
  pointer-events: none;
}

#lk-panel.lk-visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

/* =========================================================
   Header — Title, status, minimize
   ========================================================= */
#lk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 16px;
  background: var(--lk-primary);
  color: #fff;
  flex-shrink: 0;
  min-height: 48px;
}

#lk-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#lk-header-logo {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

#lk-header-title {
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
}

#lk-header-status {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.7;
  margin-left: 2px;
  color: rgba(255, 255, 255, 0.8);
}

#lk-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* Minimize button */
#lk-minimize-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

#lk-minimize-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

/* =========================================================
   Main Content Area
   ========================================================= */
#lk-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--lk-bg-muted);
}

/* =========================================================
   Welcome Screen
   ========================================================= */
#lk-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 24px;
  text-align: center;
  height: 100%;
  background: transparent;
}

#lk-welcome-icon {
  width: 48px;
  height: 48px;
  fill: var(--lk-accent);
}

#lk-welcome h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--lk-fg);
  margin: 0;
}

#lk-welcome p {
  font-size: 13px;
  color: var(--lk-fg-muted);
  line-height: 1.5;
  margin: 0;
  max-width: 280px;
}

#lk-connect-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border: none;
  border-radius: 12px;
  background: var(--lk-primary);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, transform 0.15s;
  margin-top: 8px;
}

#lk-connect-btn:hover {
  background: var(--lk-primary-light);
  transform: translateY(-1px);
}

#lk-connect-btn:disabled {
  cursor: default;
  transform: none;
}
#lk-connect-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* =========================================================
   Connection Status Pill
   ========================================================= */
#lk-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(16, 56, 79, 0.07);
  font-size: 14px;
  color: #374151;
  font-weight: 500;
  transition: background 0.3s, color 0.3s;
}
#lk-status-pill.lk-status-pill-success {
  background: rgba(5, 150, 105, 0.1);
  color: #059669;
}
.lk-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lk-primary, #10384f);
  position: relative;
  flex-shrink: 0;
}
.lk-status-dot::before,
.lk-status-dot::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--lk-primary, #10384f);
  animation: lk-status-pulse 1.2s ease-out infinite;
}
.lk-status-dot::after {
  animation-delay: 0.6s;
}
.lk-status-dot-success {
  background: #059669;
}
.lk-status-dot-success::before,
.lk-status-dot-success::after {
  animation: none;
  border-color: transparent;
}
@keyframes lk-status-pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* =========================================================
   Transcript / Chat Messages
   ========================================================= */
#lk-transcript {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#lk-transcript::-webkit-scrollbar { width: 4px; }
#lk-transcript::-webkit-scrollbar-track { background: transparent; }
#lk-transcript::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

/* Message Bubbles */
.lk-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: lk-msg-in 0.25s ease;
}

@keyframes lk-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.lk-msg.lk-user { align-self: flex-end; }
.lk-msg.lk-agent { align-self: flex-start; }

.lk-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.lk-msg.lk-user .lk-msg-bubble {
  background: var(--lk-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.lk-msg.lk-agent .lk-msg-bubble {
  background: #fff;
  color: var(--lk-fg);
  border: 1px solid var(--lk-border);
  border-bottom-left-radius: 4px;
}

.lk-msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  padding: 0 4px;
  font-size: 10px;
  color: var(--lk-fg-muted);
}

.lk-msg.lk-user .lk-msg-meta { justify-content: flex-end; }

/* Mic icon for STT messages */
.lk-msg-meta .lk-stt-icon {
  width: 10px;
  height: 10px;
  fill: var(--lk-fg-muted);
}

/* Live STT bubble — pulsing border while user is speaking */
.lk-msg.lk-user.lk-stt-live .lk-msg-bubble {
  background: var(--lk-primary);
  opacity: 0.85;
  border: 2px solid var(--lk-accent);
  animation: lk-stt-pulse 1.5s ease-in-out infinite;
}

@keyframes lk-stt-pulse {
  0%, 100% { border-color: var(--lk-accent); }
  50% { border-color: transparent; }
}

/* Inline code */
.lk-msg.lk-agent .lk-msg-bubble code {
  background: #eef2f7;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12.5px;
  font-family: "Consolas", "Monaco", monospace;
}

/* Code blocks */
.lk-msg.lk-agent .lk-msg-bubble pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.4;
}

.lk-msg.lk-agent .lk-msg-bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.lk-msg.lk-agent .lk-msg-bubble a {
  color: var(--lk-accent);
  text-decoration: underline;
}

/* Typing indicator */
.lk-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--lk-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  max-width: 72px;
}

#lk-typing-ind .lk-avatar {
  margin-bottom: 0;
}

.lk-typing span {
  width: 5px;
  height: 5px;
  background: #10b4c9;
  border-radius: 50%;
  animation: lk-typing-wave 1s infinite ease-in-out;
}

.lk-typing span:nth-child(2) { animation-delay: 0.1s; }
.lk-typing span:nth-child(3) { animation-delay: 0.2s; }

@keyframes lk-typing-wave {
  0%, 100% { transform: translateY(0); }
  25% { transform: translateY(-5px); }
  50% { transform: translateY(0); }
}

/* System messages */
.lk-sys {
  text-align: center;
  font-size: 11.5px;
  color: var(--lk-fg-muted);
  padding: 4px 8px;
  align-self: center;
}

.lk-sys.lk-err { color: var(--lk-danger); }

/* Date divider */
.lk-date-divider {
  text-align: center;
  font-size: 11px;
  color: var(--lk-fg-muted);
  padding: 8px 0 4px;
  letter-spacing: 0.3px;
}

/* =========================================================
   Bottom Control Bar — 3-Button Voice + Text Mode
   ========================================================= */
#lk-controls {
  display: none; /* hidden until session */
  flex-shrink: 0;
  padding: 12px 16px 20px;
  background: var(--lk-bg);
  border-top: 1px solid var(--lk-border);
}

#lk-controls.lk-show { display: block; }

#lk-input-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

/* Side control buttons (keyboard, end) */
.lk-ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--lk-border);
  border-radius: 50%;
  background: transparent;
  color: var(--lk-fg-muted);
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s, transform 0.15s;
}

.lk-ctrl-btn:hover {
  background: rgba(16, 56, 79, 0.06);
  border-color: var(--lk-primary);
  color: var(--lk-fg);
  transform: scale(1.06);
}

.lk-ctrl-btn:active {
  transform: scale(0.94);
  background: rgba(16, 56, 79, 0.1);
}

.lk-ctrl-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* End button hover — danger red */
#lk-end-btn:hover {
  background: rgba(239, 68, 68, 0.06);
  border-color: var(--lk-danger);
  color: var(--lk-danger);
}

/* Mic button — sole control, borderless with soft glow */
#lk-mic-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: 1.5px solid var(--lk-border);
  border-radius: 50%;
  background: transparent;
  color: var(--lk-fg-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.25s, color 0.25s, border-color 0.25s, box-shadow 0.4s, transform 0.15s;
  position: relative;
}

#lk-mic-btn:hover {
  background: rgba(16, 56, 79, 0.06);
  border-color: var(--lk-primary);
  transform: scale(1.04);
}

#lk-mic-btn:active {
  transform: scale(0.96);
  background: rgba(16, 56, 79, 0.1);
}

#lk-mic-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

#lk-mic-btn.lk-on {
  color: var(--lk-accent);
  border-color: var(--lk-accent);
  background: rgba(1, 190, 255, 0.08);
}

#lk-mic-btn.lk-off {
  color: var(--lk-danger);
  border-color: var(--lk-danger);
  background: rgba(239, 68, 68, 0.06);
  animation: none;
  box-shadow: none;
}

/* Mic bars animation inside mic button */
#lk-mic-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 24px;
}

#lk-mic-bars span {
  display: block;
  width: 3.5px;
  border-radius: 2px;
  background: currentColor;
  animation: lk-mic-pulse 1s ease-in-out infinite;
}

#lk-mic-bars span:nth-child(1) { height: 10px; animation-delay: 0s; }
#lk-mic-bars span:nth-child(2) { height: 20px; animation-delay: 0.12s; }
#lk-mic-bars span:nth-child(3) { height: 10px; animation-delay: 0.24s; }

@keyframes lk-mic-pulse {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}

/* =========================================================
   Text Input Bar (keyboard mode)
   ========================================================= */
#lk-text-bar {
  display: none;
  align-items: center;
  gap: 8px;
}

#lk-chat-input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--lk-border);
  border-radius: 20px;
  background: var(--lk-bg-muted);
  color: var(--lk-fg);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#lk-chat-input:focus {
  border-color: var(--lk-primary);
}

#lk-chat-input::placeholder {
  color: var(--lk-fg-muted);
}

#lk-chat-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--lk-primary);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

#lk-chat-send:hover {
  background: var(--lk-primary-light);
  transform: scale(1.06);
}

#lk-chat-send svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* =========================================================
   Sine Wave Canvas
   ========================================================= */
#lk-sine-wave {
  display: none;
  flex-shrink: 0;
  width: 100%;
  height: 40px;
}

#lk-sine-wave.lk-show {
  display: block;
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 480px) {
  #lk-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    bottom: 76px;
    right: 8px;
    border-radius: 16px;
  }

  #lk-trigger {
    bottom: 16px;
    right: 16px;
  }
}

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
  #lk-panel {
    transition: none !important;
  }
}
