:root {
  --bg: #0b1020;
  --panel: rgba(255, 255, 255, 0.06);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.7);
  --border: rgba(255, 255, 255, 0.12);
  --accent: #3e52ee;
  --accent-hover: #2d3ed8;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }

body {
  background: radial-gradient(circle at 20% 10%, #1a2a6c 0%, transparent 60%),
              radial-gradient(circle at 90% 20%, #b21f1f 0%, transparent 60%),
              var(--bg);
}

/* 状态切换核心：所有带 hidden 属性的元素必须彻底消失 */
[hidden] { display: none !important; }

.page { display: flex; flex-direction: column; height: 100vh; }

.header {
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
}

.header-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.header-btn:hover { background: rgba(255,255,255,0.1); }

.content {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
}

.shell { width: 100%; max-width: 800px; display: flex; flex-direction: column; height: 100%; }

/* 登录界面 */
.login-container { margin-top: 10vh; width: 100%; max-width: 400px; align-self: center; }
.login-box {
  background: var(--panel);
  backdrop-filter: blur(30px);
  padding: 40px;
  border-radius: 24px;
  border: 1px solid var(--border);
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-box h2 { margin: 0 0 20px; font-size: 22px; }
.login-box input {
  width: 100%; padding: 14px; margin-bottom: 20px;
  background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: 12px; color: white; outline: none; font-size: 16px;
}
.login-box button {
  width: 100%; padding: 14px; background: var(--accent);
  border: none; border-radius: 12px; color: white; cursor: pointer; font-weight: 600;
}

/* 聊天界面 */
.chat-container {
  background: var(--panel);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

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

/* 欢迎消息 */
.welcome-message {
  padding: 24px; background: rgba(255,255,255,0.03); border-radius: 16px;
  border: 1px solid var(--border); margin-bottom: 10px;
}
.welcome-avatar { font-size: 32px; margin-bottom: 12px; }
.welcome-content h3 { margin: 0 0 8px; font-size: 18px; }
.welcome-content p { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.6; }

/* 消息气泡 */
.message { 
  display: flex; 
  gap: 12px; 
  width: 100%; 
  max-width: 90%; 
  margin-bottom: 8px; 
}
.message.assistant { align-self: flex-start; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  flex-shrink: 0;
}
.message.user .message-avatar { background: var(--accent); color: white; }

.message-content {
  flex: 1;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  position: relative;
  min-width: 0;
}

/* Markdown 样式优化 */
.message-content p { margin: 0 0 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
}
.message-content pre {
  background: #1e1e1e !important;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
  border: 1px solid var(--border);
}
.message-content pre code {
  background: none;
  padding: 0;
}
.message-content h1, .message-content h2, .message-content h3 {
  margin: 16px 0 8px;
  font-size: 1.2em;
}
.message-content ul, .message-content ol {
  padding-left: 20px;
  margin: 8px 0;
}
.message-content li { margin-bottom: 4px; }
.message-content blockquote {
  border-left: 4px solid var(--accent);
  margin: 8px 0;
  padding-left: 12px;
  color: var(--muted);
}
.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
}
.message-content th, .message-content td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: left;
}
.message-content th { background: rgba(255,255,255,0.05); }
.message.user .message-content { background: var(--accent); color: white; border-bottom-right-radius: 4px; }
.message.assistant .message-content { background: rgba(255,255,255,0.08); border-bottom-left-radius: 4px; }

.message-timestamp { font-size: 11px; color: var(--muted); margin-top: 6px; opacity: 0.6; }

/* 输入区域 */
.input-area { padding: 20px; border-top: 1px solid var(--border); background: rgba(0,0,0,0.2); }
.input-wrapper { display: flex; gap: 12px; align-items: flex-end; }
.user-input {
  flex: 1; background: rgba(255,255,255,0.05); border: 1px solid var(--border);
  border-radius: 12px; color: white; padding: 12px; resize: none;
  min-height: 44px; max-height: 150px; outline: none; font-size: 14px;
}
.send-btn {
  height: 44px; min-width: 80px; background: var(--accent); border: none;
  border-radius: 12px; color: white; cursor: pointer; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.input-hint { font-size: 11px; color: var(--muted); text-align: center; margin-top: 8px; }

/* 报错和状态 */
.status {
  padding: 10px 16px; border-radius: 10px; font-size: 13px; margin-bottom: 10px;
  background: var(--panel); border: 1px solid var(--border); display: inline-flex;
}
.status[data-level="error"] { border-color: rgba(255,100,100,0.4); color: #ff6b6b; }
.error-text { color: #ff6b6b; font-size: 13px; margin-top: 10px; }

/* 加载动画 */
.spinner {
  width: 20px; height: 18px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white; border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 移动端适配 */
@media (max-width: 640px) {
  .shell { padding: 0; }
  .chat-container { border-radius: 0; border-left: none; border-right: none; }
  .message { max-width: 92%; }
}
