/* ============================================
   Chat Widget — Floating bubble + panel
   ============================================ */

/* Bubble */
.chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #7c5cfc;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(124,92,252,0.3);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 9999;
}

.chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 32px rgba(124,92,252,0.4);
}

.chat-bubble svg {
  width: 24px;
  height: 24px;
  fill: #fff;
  transition: transform 0.2s;
}

.chat-bubble.open svg {
  transform: rotate(90deg);
}

/* Panel */
.chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 48px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: #0c0c14;
  border: 1px solid #1a1a2e;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
}

.chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid #1a1a2e;
  background: #0c0c14;
}

.chat-header-title {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #e8e8f0;
  flex: 1;
}

.chat-header-credits {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: #34d399;
  background: rgba(52,211,153,0.1);
  padding: 2px 8px;
  border-radius: 999px;
}

.chat-header-credits.low {
  color: #fb923c;
  background: rgba(251,146,60,0.1);
}

.chat-header-credits.empty {
  color: #f87171;
  background: rgba(248,113,113,0.1);
}

/* Tabs */
.chat-tabs {
  display: flex;
  border-bottom: 1px solid #1a1a2e;
  background: #0a0a12;
}

.chat-tab {
  flex: 1;
  padding: 8px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: #6a6a8a;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.chat-tab:hover {
  color: #c8c8d8;
}

.chat-tab.active {
  color: #7c5cfc;
  border-bottom-color: #7c5cfc;
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #252540; border-radius: 4px; }

.chat-msg {
  max-width: 85%;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  line-height: 1.5;
}

.chat-msg.user {
  align-self: flex-end;
  background: #7c5cfc;
  color: #fff;
  padding: 8px 14px;
  border-radius: 14px 14px 4px 14px;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: #1a1a2e;
  color: #c8c8d8;
  padding: 8px 14px;
  border-radius: 14px 14px 14px 4px;
}

.chat-msg.system {
  align-self: center;
  font-size: 11px;
  color: #4a4a6a;
  background: none;
  padding: 4px 0;
}

.chat-msg code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  background: rgba(255,255,255,0.06);
  padding: 1px 4px;
  border-radius: 3px;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  align-self: flex-start;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4a4a6a;
  animation: chat-bounce 1.2s ease-in-out infinite;
}

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

@keyframes chat-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Input */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #1a1a2e;
  background: #0c0c14;
}

.chat-input {
  flex: 1;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: #e8e8f0;
  background: #12121e;
  border: 1px solid #1a1a2e;
  border-radius: 10px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  max-height: 80px;
  transition: border-color 0.15s;
}

.chat-input::placeholder {
  color: #4a4a6a;
}

.chat-input:focus {
  border-color: #7c5cfc;
}

.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #7c5cfc;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.chat-send:hover {
  background: #6a4ae0;
}

.chat-send:disabled {
  background: #252540;
  cursor: not-allowed;
}

.chat-send svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}

/* Model selector */
.chat-model-select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #6a6a8a;
  background: #12121e;
  border: 1px solid #1a1a2e;
  border-radius: 6px;
  padding: 2px 6px;
  outline: none;
  cursor: pointer;
}

/* Memory tab */
.chat-memory {
  padding: 16px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: #6a6a8a;
}

.chat-memory-item {
  padding: 8px 0;
  border-bottom: 1px solid #12121e;
}

.chat-memory-item strong {
  color: #c8c8d8;
  display: block;
  margin-bottom: 2px;
}

.chat-memory-empty {
  text-align: center;
  padding: 40px 20px;
  color: #4a4a6a;
}

/* Responsive */
@media (max-width: 480px) {
  .chat-panel {
    right: 8px;
    bottom: 80px;
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    border-radius: 12px;
  }
  .chat-bubble {
    bottom: 16px;
    right: 16px;
  }
}
