/* ===== Chat Modal - Sidebar Style ===== */
:root {
  --chat-bg: #0d0d1a;
  --chat-surface: rgba(255,255,255,0.03);
  --chat-border: rgba(255,255,255,0.07);
  --chat-user-bg: rgba(0,240,255,0.08);
  --chat-assistant-bg: rgba(168,85,247,0.06);
  --chat-input-bg: #0a0a18;
}

/* Overlay */
.chat-overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 9998;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}
.chat-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Sidebar Panel */
.chat-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 65%;
  max-width: 800px;
  min-width: 380px;
  background: var(--chat-bg);
  border-left: 1px solid rgba(0,240,255,0.15);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: -8px 0 40px rgba(0,0,0,0.5);
}
.chat-overlay.active .chat-panel {
  transform: translateX(0);
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--chat-border);
  background: rgba(11,11,26,0.98);
  flex-shrink: 0;
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.chat-model-select {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(0,240,255,0.2);
  color: #00f0ff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-model-select:focus {
  border-color: #00f0ff;
  box-shadow: 0 0 0 2px rgba(0,240,255,0.15);
}
.chat-model-select option {
  background: #0d0d1a;
  color: #e0e0e0;
}
.chat-rate-info {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.4);
  white-space: nowrap;
}
.chat-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: rgba(255,255,255,0.6);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.chat-close-btn:hover {
  background: rgba(0,240,255,0.1);
  color: #00f0ff;
  border-color: rgba(0,240,255,0.3);
  box-shadow: 0 0 12px rgba(0,240,255,0.15);
}

/* Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(0,240,255,0.2); }

/* Welcome Screen */
.chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
}
.chat-welcome-icon { font-size: 3rem; margin-bottom: 16px; }
.chat-welcome h3 { font-size: 1.2rem; color: #e0e0e0; margin-bottom: 8px; }
.chat-welcome p { font-size: 0.85rem; color: rgba(255,255,255,0.4); margin-bottom: 24px; }

/* Preset Prompts */
.chat-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.chat-preset-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid rgba(0,240,255,0.2);
  background: rgba(0,240,255,0.04);
  color: #00f0ff;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.chat-preset-btn:hover {
  background: rgba(0,240,255,0.1);
  border-color: rgba(0,240,255,0.4);
  box-shadow: 0 0 12px rgba(0,240,255,0.1);
}

/* Message Bubbles */
.chat-msg {
  display: flex;
  gap: 10px;
  max-width: 100%;
  animation: chatMsgIn 0.3s ease;
}
@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.user { flex-direction: row-reverse; }
.chat-msg-avatar {
  width: 32px; height: 32px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
  font-weight: 600;
}
.chat-msg.user .chat-msg-avatar { background: rgba(0,240,255,0.15); color: #00f0ff; }
.chat-msg.assistant .chat-msg-avatar { background: rgba(168,85,247,0.15); color: #a855f7; }
.chat-msg-content {
  flex: 1; min-width: 0;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.7;
  word-break: break-word;
}
.chat-msg.user .chat-msg-content {
  background: var(--chat-user-bg);
  border: 1px solid rgba(0,240,255,0.15);
  color: #e0e0e0;
  border-top-right-radius: 4px;
}
.chat-msg.assistant .chat-msg-content {
  background: var(--chat-assistant-bg);
  border: 1px solid rgba(168,85,247,0.1);
  color: #e0e0e0;
  border-top-left-radius: 4px;
}

/* Markdown in chat */
.chat-msg-content p { margin: 0 0 0.6em; }
.chat-msg-content p:last-child { margin-bottom: 0; }
.chat-msg-content ul, .chat-msg-content ol { margin: 0.4em 0; padding-left: 1.5em; }
.chat-msg-content li { margin: 0.2em 0; }
.chat-msg-content strong { color: #00f0ff; }
.chat-msg-content em { color: rgba(255,255,255,0.7); }
.chat-msg-content a { color: #00f0ff; text-decoration: underline; }
.chat-msg-content blockquote {
  border-left: 3px solid #a855f7;
  padding: 0.4em 1em;
  margin: 0.6em 0;
  color: rgba(255,255,255,0.6);
  background: rgba(168,85,247,0.04);
  border-radius: 0 8px 8px 0;
}
.chat-msg-content code {
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 0.82em;
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: #00f0ff;
}
.chat-msg-content pre {
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
  margin: 0.6em 0;
  position: relative;
}
.chat-msg-content pre code {
  background: none; padding: 0; font-size: 0.82em; color: #e0e0e0;
}
.chat-msg-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6em 0;
  font-size: 0.85em;
}
.chat-msg-content th, .chat-msg-content td {
  border: 1px solid rgba(255,255,255,0.1);
  padding: 6px 10px;
  text-align: left;
}
.chat-msg-content th {
  background: rgba(0,240,255,0.06);
  color: #00f0ff;
  font-weight: 600;
}

/* Thinking indicator */
.chat-thinking {
  display: flex; align-items: center; gap: 4px; padding: 4px 0;
}
.chat-thinking-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #a855f7;
  animation: thinkBounce 1.2s infinite;
}
.chat-thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-thinking-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes thinkBounce {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.1); }
}

/* Input Area */
.chat-input-area {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--chat-border);
  background: rgba(11,11,26,0.98);
  flex-shrink: 0;
}
.chat-input-wrap {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--chat-input-bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 8px 8px 8px 16px;
  transition: border-color 0.2s;
}
.chat-input-wrap:focus-within {
  border-color: rgba(0,240,255,0.4);
  box-shadow: 0 0 0 2px rgba(0,240,255,0.08);
}
.chat-textarea {
  flex: 1; background: none; border: none;
  color: #e0e0e0; font-size: 0.9rem; font-family: inherit;
  line-height: 1.5; resize: none; outline: none;
  max-height: 120px; min-height: 24px; padding: 4px 0;
}
.chat-textarea::placeholder { color: rgba(255,255,255,0.25); }

/* Send / Stop Button */
.chat-send-btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
  transition: all 0.2s;
}
.chat-send-btn.send {
  background: linear-gradient(135deg, #00f0ff, #00c4d6);
  color: #0a0e17;
  box-shadow: 0 2px 10px rgba(0,240,255,0.25);
}
.chat-send-btn.send:hover {
  box-shadow: 0 4px 20px rgba(0,240,255,0.4);
  transform: scale(1.05);
}
.chat-send-btn.send:active { transform: scale(0.92); }
.chat-send-btn.send:disabled {
  opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none;
}
.chat-send-btn.stop {
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  color: #ef4444;
}
.chat-send-btn.stop:hover {
  background: rgba(239,68,68,0.25);
  box-shadow: 0 0 12px rgba(239,68,68,0.2);
}
.chat-send-btn.stop:active { transform: scale(0.92); }

/* Error message */
.chat-error {
  text-align: center; padding: 12px;
  color: #ef4444; font-size: 0.85rem;
  background: rgba(239,68,68,0.06);
  border-radius: 8px;
  border: 1px solid rgba(239,68,68,0.15);
}

/* Login prompt */
.chat-login-prompt {
  text-align: center; padding: 16px;
  font-size: 0.85rem; color: rgba(255,255,255,0.5);
}
.chat-login-prompt a {
  color: #00f0ff; cursor: pointer; text-decoration: underline;
}

/* Mobile: Full Screen */
@media (max-width: 768px) {
  .chat-panel {
    width: 100%; max-width: 100%; min-width: 100%;
    border-left: none;
  }
}
