/* ====== 基础重置与全局样式 ====== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f0f2f5;
  color: #333;
  line-height: 1.6;
  padding: 20px;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  padding: 30px 30px 20px;
}

/* ====== 页面标题 ====== */
header {
  text-align: center;
  margin-bottom: 24px;
}

header h1 {
  font-size: 28px;
  color: #1a1a1a;
  margin-bottom: 8px;
}

header p {
  font-size: 14px;
  color: #888;
}

header strong {
  color: #6c5ce7;
}

/* ====== API Key 输入区 ====== */
.api-key-section {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.api-key-section label {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

#api-key-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

#api-key-input:focus {
  border-color: #6c5ce7;
}

#save-key-btn {
  padding: 8px 16px;
  background: #6c5ce7;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

#save-key-btn:hover {
  background: #5a4bd1;
}

.key-status {
  font-size: 13px;
  font-weight: 500;
}

.key-status.saved {
  color: #00b894;
}

.key-status.missing {
  color: #d63031;
}

/* ====== 用户输入区 ====== */
.input-section {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

#user-input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

#user-input:focus {
  border-color: #6c5ce7;
}

#send-btn {
  padding: 0 24px;
  background: #0984e3;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.2s;
  white-space: nowrap;
}

#send-btn:hover:not(:disabled) {
  background: #0770c2;
}

#send-btn:disabled {
  background: #b2bec3;
  cursor: not-allowed;
}

/* ====== 聊天显示区 ====== */
.chat-section {
  margin-bottom: 16px;
}

.chat-header {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 10px;
  color: #555;
}

.chat-box {
  min-height: 200px;
  max-height: 450px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 16px;
  background: #fafafa;
}

.empty-hint {
  color: #bbb;
  text-align: center;
  padding-top: 40px;
  font-size: 14px;
}

/* 消息气泡 */
.message {
  margin-bottom: 14px;
  max-width: 90%;
  animation: fadeIn 0.3s ease;
}

.message.user {
  margin-left: auto;
  text-align: right;
}

.message.user .bubble {
  background: #6c5ce7;
  color: #fff;
  display: inline-block;
  text-align: left;
}

.message.assistant .bubble {
  background: #fff;
  border: 1px solid #e0e0e0;
}

.message .label {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #888;
}

.message.user .label {
  color: #a29bfe;
}

.bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}

/* 加载中 & 错误提示 */
.bubble.loading {
  color: #888;
  font-style: italic;
}

.bubble.error {
  background: #ffeaa7;
  color: #d63031;
  border: 1px solid #fab1a0;
}

/* ====== 清空按钮 ====== */
#clear-btn {
  display: block;
  margin: 0 auto;
  padding: 10px 24px;
  background: #fff;
  color: #d63031;
  border: 1px solid #d63031;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

#clear-btn:hover {
  background: #d63031;
  color: #fff;
}

/* ====== 动画 ====== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ====== 响应式 ====== */
@media (max-width: 600px) {
  .container {
    padding: 20px 16px 14px;
  }

  .input-section {
    flex-direction: column;
  }

  #send-btn {
    padding: 12px;
  }

  .api-key-section {
    flex-direction: column;
    align-items: stretch;
  }
}