.chat-container {
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  height: 560px;
  position: relative;
  overflow: hidden;
}

.chat-container::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: var(--gradient-border);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.chat-container:focus-within::before {
  opacity: 1;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.95rem;
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
  animation: chat-pulse 2s infinite;
}

@keyframes chat-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-remaining {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.chat-model-select {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 4px 28px 4px 10px;
  font-size: 0.8rem;
  font-family: var(--font-sans);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='%23a1a1aa'%3E%3Cpath d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color 0.2s ease;
  max-width: 180px;
}

.chat-model-select:hover {
  border-color: var(--border-color-hover);
}

.chat-model-select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.chat-model-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

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

.chat-message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: chat-message-in 0.3s var(--ease-out);
}

@keyframes chat-message-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.chat-message.assistant {
  align-self: flex-start;
}

.chat-message.error {
  align-self: flex-start;
}

.chat-message.error .chat-bubble {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

.chat-message.user .chat-avatar {
  background: var(--gradient-primary);
  color: #fff;
}

.chat-message.assistant .chat-avatar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--accent-cyan);
}

.chat-message.error .chat-avatar {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.chat-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.chat-message.assistant .chat-bubble {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-bubble.loading {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 20px;
}

.chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chat-dot-bounce 1.4s infinite;
}

.chat-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-input-area {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px;
  transition: border-color 0.2s ease;
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent-blue);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.5;
  padding: 8px 12px;
  resize: none;
  max-height: 120px;
}

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

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--gradient-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-send-btn:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.chat-footer-hint {
  margin-top: 6px;
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-limit-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
}

.chat-limit-overlay .chat-limit-icon {
  font-size: 2.5rem;
  opacity: 0.5;
}

.chat-limit-overlay p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 300px;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 2px;
}

@media (max-width: 640px) {
  .chat-container {
    height: 480px;
    border-radius: var(--radius-md);
  }

  .chat-message {
    max-width: 92%;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .chat-messages {
    padding: 16px;
  }

  .chat-input-area {
    padding: 8px 12px 12px;
  }
}
