* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container {
  max-width: 900px;
  margin: 0 auto;
}

header {
  text-align: center;
  color: white;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.subtitle {
  font-size: 1.1rem;
  opacity: 0.9;
}

.api-key-setup {
  background: white;
  padding: 2rem;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.api-key-setup h2 {
  color: #1f2937;
  margin-bottom: 1rem;
}

.api-key-setup p {
  color: #6b7280;
  margin-bottom: 1.5rem;
}

.api-key-form {
  display: flex;
  gap: 0.5rem;
  max-width: 500px;
  margin: 0 auto 1rem;
}

#api-key-input {
  flex: 1;
  padding: 0.75rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 1rem;
}

#api-key-input:focus {
  outline: none;
  border-color: #667eea;
}

.note {
  font-size: 0.85rem;
  color: #9ca3af;
  margin-top: 1rem;
}

.note a {
  color: #667eea;
  text-decoration: none;
}

.note a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.key-status {
  background: white;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.key-indicator {
  color: #10b981;
  font-weight: 600;
  font-size: 0.9rem;
}

.btn-small {
  padding: 0.4rem 0.8rem;
  background: #6b7280;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-small:hover {
  background: #4b5563;
}

.model-select-card {
  background: white;
  padding: 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  display: flex;
  gap: 1rem;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.model-select-card label {
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
}

#model-select {
  flex: 1;
  padding: 0.75rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
}

#model-select:focus {
  outline: none;
  border-color: #667eea;
}

.chat-container {
  background: white;
  border-radius: 12px;
  padding: 2rem;
  min-height: 500px;
  max-height: 600px;
  overflow-y: auto;
  margin-bottom: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.welcome-message {
  text-align: center;
  color: #6b7280;
  padding: 4rem 2rem;
}

.welcome-message h2 {
  color: #1f2937;
  margin-bottom: 1rem;
}

.message {
  margin-bottom: 1.5rem;
  display: flex;
  gap: 1rem;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.message-content {
  flex: 1;
}

.message-role {
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.message-text {
  background: #f9fafb;
  padding: 1rem;
  border-radius: 8px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user .message-avatar {
  background: #667eea;
}

.message.user .message-role {
  color: #667eea;
}

.message.user .message-text {
  background: #e0e7ff;
}

.message.assistant .message-avatar {
  background: #10b981;
}

.message.assistant .message-role {
  color: #10b981;
}

.message.assistant .message-text {
  background: #f9fafb;
}

.message.loading .message-text {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  color: #6b7280;
}

.loading-dots {
  display: flex;
  gap: 0.25rem;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #667eea;
  animation: bounce 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

.input-area {
  background: white;
  padding: 1rem;
  border-radius: 12px;
  display: flex;
  gap: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#user-input {
  flex: 1;
  padding: 0.75rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

#user-input:focus {
  outline: none;
  border-color: #667eea;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, opacity 0.2s;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: #667eea;
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: #5568d3;
}

.btn-send {
  background: #667eea;
  color: white;
}

.btn-send:hover:not(:disabled) {
  background: #5568d3;
}

.btn-clear {
  background: #ef4444;
  color: white;
}

.btn-clear:hover {
  background: #dc2626;
}

.status {
  text-align: center;
  color: white;
  padding: 0.5rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  header h1 {
    font-size: 2rem;
  }

  .api-key-form {
    flex-direction: column;
  }

  .model-select-card {
    flex-direction: column;
    align-items: stretch;
  }

  .input-area {
    flex-wrap: wrap;
  }

  #user-input {
    width: 100%;
  }

  .btn {
    flex: 1;
  }

  .chat-container {
    max-height: 400px;
  }

  .key-status {
    flex-direction: column;
    gap: 0.5rem;
  }
}
