/* ============================================
   AI Voice Demo — Dark Premium Theme
   ============================================ */

/* ---------- Design Tokens ---------- */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: rgba(22, 27, 34, 0.75);
  --bg-card-hover: rgba(30, 40, 60, 0.85);
  --bg-input: rgba(13, 17, 23, 0.8);
  --border-subtle: rgba(48, 54, 61, 0.6);
  --border-glow: rgba(79, 70, 229, 0.4);

  --accent-blue: #4f46e5;
  --accent-purple: #7c3aed;
  --accent-cyan: #06b6d4;
  --accent-green: #22c55e;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  --gradient-accent: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 50%;

  --blur-glass: blur(16px);
  --shadow-card: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.2);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Meiryo", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  background: var(--bg-primary);
}

/* Fluid Background Orbs for Deep Glassmorphism */
.bg-orbs {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-orbs::before, .bg-orbs::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.25;
  animation: float 25s infinite alternate ease-in-out;
}

.bg-orbs::before {
  width: 50vw; height: 50vw;
  background: var(--accent-purple);
  top: -20vh; left: -10vw;
}

.bg-orbs::after {
  width: 45vw; height: 45vw;
  background: var(--accent-cyan);
  bottom: -20vh; right: -5vw;
  animation-delay: -5s;
}

@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(15vw, 15vh) scale(1.1); }
  100% { transform: translate(-5vw, 10vh) scale(0.9); }
}

/* ---------- Layout ---------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  background: rgba(13, 17, 23, 0.5);
  z-index: 10;
  flex-shrink: 0;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-logo svg {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 0 8px rgba(6, 182, 212, 0.5));
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-normal);
}

.status-dot.connected { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); animation: pulse-dot 2s infinite; }
.status-dot.error { background: var(--accent-red); }

.lang-switcher {
  display: flex;
  align-items: center;
  margin-right: 12px;
}

.custom-lang-dropdown {
  position: relative;
  display: inline-block;
}

.lang-trigger {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.lang-trigger:hover {
  color: #fff;
}

.lang-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: rgba(15, 18, 28, 0.95);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  min-width: 100px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all var(--transition-fast);
}

.custom-lang-dropdown:hover .lang-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-option {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.lang-option:hover {
  background: rgba(255, 255, 255, 0.1);
}

.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  flex: 4;
  min-width: 320px;
  background: rgba(10, 12, 18, 0.25);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  z-index: 5;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 4px; }

.card {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.01) 100%);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  transition: border-color var(--transition-normal);
}

.card:hover { border-color: var(--border-glow); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  cursor: pointer;
  user-select: none;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.card-toggle {
  width: 20px; height: 20px;
  color: var(--text-muted);
  transition: transform var(--transition-normal);
}

.card-toggle.collapsed { transform: rotate(-90deg); }

.card-body { display: block; }
.card-body.collapsed { display: none; }

/* ---------- Form Controls ---------- */
.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

.btn-text-small {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 0;
  transition: color var(--transition-fast);
}
.btn-text-small:hover {
  color: var(--accent-red);
}

.form-label {
  display: flex;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.info-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  color: var(--text-secondary);
  font-size: 10px;
  margin-left: 6px;
  cursor: help;
  transition: all var(--transition-fast);
}

.info-icon:hover {
  background: var(--accent-cyan);
  color: #000;
}

.info-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  top: 100%;
  left: 0;
  transform: translateY(6px);
  background: var(--bg-card);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  width: max-content;
  max-width: 240px;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  transition: all 0.15s ease;
  z-index: 999;
}

.info-icon:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(2px);
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  transition: all var(--transition-fast);
  outline: none;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* Tag Textarea & Pills (Hotwords) */
.tag-textarea {
  display: flex;
  flex-direction: column;
  cursor: text;
  padding: 8px 12px;
  min-height: 110px;
}

.tag-textarea input::placeholder {
  color: var(--text-muted);
}

.tag-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
  align-content: flex-start;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(79, 70, 229, 0.15);
  border: 1px solid rgba(79, 70, 229, 0.3);
  border-radius: var(--radius-xl);
  font-size: 12px;
  color: var(--accent-cyan);
  animation: fadeIn 0.2s ease;
}

.tag-close {
  width: 14px; height: 14px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}

.tag-close:hover { opacity: 1; color: var(--accent-red); }

/* Knowledge File List */
.knowledge-files {
  max-height: 180px;
  overflow-y: auto;
  margin-top: 10px;
}

.knowledge-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.knowledge-file:hover { background: rgba(255,255,255,0.03); }

.knowledge-file input[type="checkbox"] {
  accent-color: var(--accent-blue);
  width: 16px; height: 16px;
}

.knowledge-file-info {
  flex: 1;
  min-width: 0;
}

.knowledge-file-name {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.knowledge-file-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.btn-extract, .btn-upload {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  height: 35px;
}

.btn-extract {
  background: var(--gradient-accent);
  color: #fff;
}

.btn-upload {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn-extract:hover, .btn-upload:hover { opacity: 0.85; transform: translateY(-1px); }
.btn-extract:disabled, .btn-upload:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.url-row {
  display: flex;
  gap: 6px;
}

.url-row .form-input { flex: 1; }

/* ---------- Settings Lock Overlay ---------- */
.sidebar-overlay {
  display: none;
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(13, 17, 23, 0.5); /* adjusted transparency to 0.5 */
  backdrop-filter: none;
  z-index: 5;
  border-radius: 0;
  /* Centered visually */
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  gap: 6px;
  pointer-events: all;
}

.sidebar-overlay.active { display: flex; }

.sidebar-overlay .lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.65); /* Slightly darker than overlay, no border */
  border-radius: 6px;
  padding: 8px 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.sidebar-overlay .lock-icon {
  font-size: 13px;
  opacity: 0.9;
}

.sidebar-overlay .lock-text {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
}

/* ---------- Chat Panel ---------- */
.chat-panel {
  flex: 6;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ---------- Dashboard ---------- */
.server-dashboard {
  flex: 1;
  margin: 16px 8px 16px 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  position: relative;
  /* Use drop-shadow filter to create aura around irregular shapes! */
  filter: drop-shadow(0 0 10px rgba(6, 182, 212, 0.4)) drop-shadow(0 0 25px rgba(139, 92, 246, 0.2)); 
  background: transparent;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

/* The neon border background (Cyberpunk Cut) */
.server-dashboard::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  /* Vibrant Cyan on the top-left, Purple on the bottom-right */
  background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 50%, #d946ef 100%);
  /* Octagonal cuts on ALL 4 corners */
  clip-path: polygon(24px 0, calc(100% - 24px) 0, 100% 24px, 100% calc(100% - 24px), calc(100% - 24px) 100%, 24px 100%, 0 calc(100% - 24px), 0 24px);
  z-index: -2;
}

/* The dark inner panel */
.server-dashboard::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px; right: 2px; bottom: 2px;
  background: linear-gradient(145deg, rgba(8, 12, 20, 0.95) 0%, rgba(13, 20, 32, 0.98) 100%);
  clip-path: polygon(22px 0, calc(100% - 22px) 0, 100% 22px, 100% calc(100% - 22px), calc(100% - 22px) 100%, 22px 100%, 0 calc(100% - 22px), 0 22px);
  z-index: -1;
  backdrop-filter: blur(16px);
}

/* Ensure contents stay on top of the clipped backgrounds */
.dashboard-header,
.dashboard-global,
.dashboard-engines,
.dashboard-divider {
  position: relative;
  z-index: 10;
}

.dashboard-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
  padding: 4px 0 16px 0; /* Reduced top padding to move text up closer to the tab */
}

/* The upper glowing center console tab (\____/) */
.dashboard-header::before {
  content: "";
  position: absolute;
  top: -24px; /* Pull completely up to clip against the top border of the outer dashboard */
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 5px;
  background: #06b6d4;
  box-shadow: 0 0 15px rgba(6, 182, 212, 1);
  clip-path: polygon(0 0, 100% 0, calc(100% - 15px) 100%, 15px 100%);
  z-index: 2;
}

/* The long thin line extending from the bottom of the tab */
.dashboard-header::after {
  content: "";
  position: absolute;
  top: -19px; /* Align precisely with the bottom of the tab */
  left: -10px;
  right: -10px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(6, 182, 212, 0.7) 30%, #06b6d4 50%, rgba(6, 182, 212, 0.7) 70%, transparent);
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.8);
  z-index: 1;
}

.dashboard-header h3 {
  font-size: 17px;
  font-family: 'Orbitron', 'Chakra Petch', 'Segoe UI', system-ui, sans-serif;
  font-weight: 800;
  color: #cffafe;
  text-shadow: 
    0 0 10px rgba(6, 182, 212, 0.9),
    0 0 20px rgba(6, 182, 212, 0.6),
    0 0 35px rgba(6, 182, 212, 0.4);
  margin: 0;
  letter-spacing: 2px;
  text-transform: uppercase;
  z-index: 3;
}

/* Sub-bottom long glowing thin line */
.dashboard-header h3::after {
  content: "";
  position: absolute;
  bottom: 0px;
  left: -10px;
  right: -10px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(6, 182, 212, 0.9) 20%, rgba(6, 182, 212, 1) 50%, rgba(6, 182, 212, 0.9) 80%, transparent);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.8), 0 0 3px #fff;
}

.pulse-indicator {
  width: 8px;
  height: 8px;
  background: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 10px #34d399, 0 0 20px rgba(52, 211, 153, 0.6);
  animation: pulse-dot 2s infinite;
}

.dashboard-global, .dashboard-engines {
  display: flex;
  flex-direction: column;
  gap: 12px; /* Reduced from 16 */
}

.dashboard-divider {
  margin: 16px 0 12px 0; /* Reduced from 24/16 */
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.4);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 4px; /* Reduced from 8 */
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 4px; /* Reduced from 8 */
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.progress-bar-bg {
  width: 100%;
  height: 10px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.8);
}

.progress-bar-bg.small { height: 8px; }

.progress-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(90deg, #3b82f6, #2dd4bf);
  box-shadow: 0 0 12px rgba(45, 212, 191, 0.6);
}

/* Specific glows matching the image */
.progress-fill.gpu { background: linear-gradient(90deg, #06b6d4, #10b981); box-shadow: 0 0 12px rgba(16, 185, 129, 0.6); }
.progress-fill.ram { background: linear-gradient(90deg, #3b82f6, #6366f1); box-shadow: 0 0 12px rgba(99, 102, 241, 0.6); }
.progress-fill.cpu { background: linear-gradient(90deg, #8b5cf6, #d946ef); box-shadow: 0 0 12px rgba(217, 70, 239, 0.6); }

.progress-fill.model-llm { background: linear-gradient(90deg, #3b82f6, #06b6d4); box-shadow: 0 0 10px rgba(6, 182, 212, 0.5); }
.progress-fill.model-slm { background: linear-gradient(90deg, #0ea5e9, #38bdf8); box-shadow: 0 0 10px rgba(14, 165, 233, 0.5); }
.progress-fill.model-asr { background: linear-gradient(90deg, #10b981, #34d399); box-shadow: 0 0 10px rgba(16, 185, 129, 0.5); }
.progress-fill.model-tts { background: linear-gradient(90deg, #d946ef, #f472b6); box-shadow: 0 0 10px rgba(217, 70, 239, 0.5); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.session-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 12px;
  opacity: 0.6;
}

.session-divider::before,
.session-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border-subtle);
  margin: 0 16px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 4px; }

/* Message Bubbles */
.message {
  display: flex;
  gap: 10px;
  max-width: 80%;
  animation: slideIn 0.3s ease;
}

.message.ai { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.message-avatar {
  width: 36px; height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.message.ai .message-avatar {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
  box-shadow: 0 0 15px rgba(6, 182, 212, 0.6), 0 0 30px rgba(124, 58, 237, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.message.user .message-avatar {
  background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.02));
  border: 1px solid var(--border-subtle);
  backdrop-filter: blur(10px);
}

.message-content { flex: 1; min-width: 0; }

.message-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 14px;
  word-break: break-word;
  position: relative;
}

.message.ai .message-bubble {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.15) 0%, rgba(6, 182, 212, 0.05) 100%);
  border: 1px solid rgba(79, 70, 229, 0.3);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.2),
    inset 0 0 12px rgba(79, 70, 229, 0.15),
    0 0 20px rgba(79, 70, 229, 0.2);
  color: #fff;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.02) 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  color: #f8fafc;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

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

.metric-badge {
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: rgba(6, 182, 212, 0.1);
  color: var(--accent-cyan);
  font-size: 10px;
}

/* Thinking Animation */
.thinking-dots {
  display: inline-flex;
  gap: 4px;
  padding: 12px 16px;
}

.thinking-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-blue);
  animation: dotBounce 1.2s infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

/* Speaking Indicator */
.speaking-icon {
  display: inline-flex;
  gap: 2px;
  align-items: flex-end;
  height: 14px;
  margin-left: 6px;
}

.speaking-icon span {
  width: 3px;
  background: var(--accent-cyan);
  border-radius: 2px;
  animation: speakBar 0.8s infinite ease-in-out;
}

.speaking-icon span:nth-child(1) { height: 6px; animation-delay: 0s; }
.speaking-icon span:nth-child(2) { height: 10px; animation-delay: 0.15s; }
.speaking-icon span:nth-child(3) { height: 14px; animation-delay: 0.3s; }
.speaking-icon span:nth-child(4) { height: 10px; animation-delay: 0.45s; }
.speaking-icon span:nth-child(5) { height: 6px; animation-delay: 0.6s; }

/* ---------- Bottom Area ---------- */
.chat-bottom {
  padding: 0 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Waveform Visualizer */
.waveform-container {
  width: 100%;
  height: 48px;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-md);
}

#waveform-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ASR Transcription Bar */
.asr-bar {
  width: 100%;
  min-height: 36px;
  padding: 8px 16px;
  background: var(--bg-card);
  backdrop-filter: var(--blur-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.asr-bar.visible { opacity: 1; }

.asr-bar-label {
  color: var(--accent-cyan);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.asr-bar-text {
  flex: 1;
  color: var(--text-primary);
}

.asr-cursor {
  display: inline-block;
  width: 2px;
  height: 16px;
  background: var(--accent-cyan);
  animation: blink 1s step-end infinite;
  vertical-align: middle;
  margin-left: 2px;
}

/* Microphone Button */
.mic-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all var(--transition-normal);
  background: var(--gradient-accent);
  box-shadow: 0 0 24px rgba(79, 70, 229, 0.3);
  color: #fff;
  font-size: 28px;
  overflow: visible; /* MUST be visible so ::before rings show outside the button */
}

.mic-btn:hover { transform: scale(1.06); }
.mic-btn:active { transform: scale(0.96); }

/* Idle state - autonomous breathing pulse ring */
.mic-btn.idle::before {
  content: '';
  position: absolute;
  width: 100%; height: 100%;
  border-radius: 50%;
  background: transparent;
  border: 2px solid rgba(6, 182, 212, 0.7);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.5), inset 0 0 12px rgba(6, 182, 212, 0.1);
  animation: breathe 2.5s infinite ease-in-out;
  /* No z-index:-1 — let it float visibly around the button */
}

/* Recording state */
.mic-btn.recording {
  background: var(--accent-red);
  box-shadow: 0 0 30px rgba(239, 68, 68, 0.7), 0 0 60px rgba(239, 68, 68, 0.35);
  animation: none;
}

.mic-btn.recording::before,
.mic-btn.recording::after {
  content: '';
  position: absolute;
  width: 100%; height: 100%;
  border-radius: 50%;
  background: transparent;
  border: 2px solid rgba(239, 68, 68, 0.7);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.6);
}

.mic-btn.recording::before { animation: ripple 1.4s infinite ease-out; }
.mic-btn.recording::after  { animation: ripple 1.4s infinite ease-out 0.7s; }

/* Connecting state */
.mic-btn.connecting {
  background: var(--text-muted);
  box-shadow: none;
  cursor: wait;
}

.mic-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* Metrics Bar */
.metrics-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.metrics-bar.visible { opacity: 1; }

.metrics-bar .metric {
  display: flex;
  align-items: center;
  gap: 4px;
}

.metrics-bar .metric-value {
  color: var(--accent-cyan);
  font-weight: 500;
}

.metrics-bar .metric-arrow {
  color: var(--text-muted);
  margin: 0 2px;
}

.metrics-bar .metric-total {
  color: var(--accent-orange);
  font-weight: 600;
  padding-left: 8px;
  border-left: 1px solid var(--border-subtle);
}

/* ---------- Permission Dialog ---------- */
.permission-dialog {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.permission-dialog.active { display: flex; }

.permission-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 32px;
  max-width: 400px;
  text-align: center;
  animation: fadeIn 0.3s ease;
}

.permission-card h3 {
  font-size: 18px;
  margin-bottom: 12px;
}

.permission-card p {
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ---------- General Modals ---------- */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  width: 420px;
  max-width: calc(100vw - 40px);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

.modal-card-large {
  width: 720px;
  max-width: calc(100vw - 40px);
  max-height: 85vh;
}

.modal-header {
  padding: 20px 24px 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.modal-body {
  padding: 16px 24px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
}

.modal-desc {
  font-size: 13px;
  line-height: 1.6;
  margin: 0;
  color: var(--text-secondary);
}

.modal-footer {
  padding: 12px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-btn-cancel {
  padding: 8px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.modal-btn-cancel:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.modal-btn-confirm {
  padding: 8px 18px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--gradient-accent);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}
.modal-btn-confirm:hover { opacity: 0.85; }
.modal-btn-confirm:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Knowledge Action Buttons ---------- */
.knowledge-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.btn-icon {
  position: relative;
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.btn-icon:hover {
  background: rgba(79, 70, 229, 0.15);
  border-color: rgba(79, 70, 229, 0.4);
  color: var(--accent-cyan);
}
.btn-icon svg { width: 15px; height: 15px; }

.btn-icon-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: rgba(15, 18, 28, 0.95);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 11px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: all var(--transition-fast);
  z-index: 10;
  /* Allow wrapping within a bounded max-width so tooltip never escapes the sidebar */
  white-space: normal;
  width: max-content;
  max-width: 160px;
  line-height: 1.5;
  text-align: right;
  word-break: break-all;
}
.btn-icon:hover .btn-icon-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.btn-icon-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--accent-red);
}

/* ---------- Animations ---------- */
.spin-svg {
  animation: spin 1s linear infinite;
  transform-origin: center;
}

@keyframes spin {
  100% { transform: rotate(360deg); }
}
@keyframes breathe {
  0% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.45); opacity: 0; }
}

@keyframes ripple {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.7); opacity: 0; }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-8px); }
}

@keyframes blink {
  50% { opacity: 0; }
}

@keyframes speakBar {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -320px;
    top: 0; bottom: 0;
    z-index: 20;
    background: var(--bg-primary);
    transition: left var(--transition-normal);
  }
  .sidebar.open { left: 0; }
  .message { max-width: 92%; }
}
