* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f14;
  --surface: #1a1a24;
  --surface-hover: #22222e;
  --border: #2a2a3a;
  --text: #e8e8ed;
  --text-muted: #8888a0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --error: #f87171;
  --me-bubble: #6366f1;
  --other-bubble: #252532;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* 登录/注册页 */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f0f14 0%, #1a1520 50%, #0f1419 100%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 0.25rem;
}

.auth-card .subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-card .tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.auth-card .tab {
  flex: 1;
  padding: 0.6rem;
  font-size: 0.95rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-card .tab:hover {
  color: var(--text);
}

.auth-card .tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.auth-card .form {
  display: none;
  flex-direction: column;
  gap: 1rem;
}

.auth-card .form.active {
  display: flex;
}

.auth-card input {
  padding: 0.875rem 1rem;
  font-size: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.auth-card input:focus {
  border-color: var(--accent);
}

.auth-card button[type="submit"] {
  padding: 0.875rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-card button[type="submit"]:hover {
  background: var(--accent-hover);
}

.auth-card .error {
  color: var(--error);
  font-size: 0.875rem;
  margin-top: 0.75rem;
  min-height: 1.25rem;
}

/* 聊天页 */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.chat-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.chat-header .header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.chat-header .connection-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-header .connection-status.connected {
  color: #4ade80;
}

.chat-header .connection-status.error {
  color: var(--error);
}

.chat-header .username {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.btn-logout {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-retry {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-retry:hover:not(:disabled) {
  opacity: 0.9;
}

.btn-retry:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.msg {
  display: flex;
  gap: 0.75rem;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.me {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg .avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
}

.msg.me .avatar {
  background: var(--me-bubble);
}

.msg.other .avatar {
  background: var(--other-bubble);
  border: 1px solid var(--border);
}

.msg.ai .avatar {
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  border: none;
}

.msg .name {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.msg.me .name {
  text-align: right;
}

.msg .content {
  padding: 0.875rem 1rem;
  border-radius: 12px;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.me .content {
  background: var(--me-bubble);
}

.msg.other .content {
  background: var(--other-bubble);
  border: 1px solid var(--border);
}

.msg.ai .content {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(99, 102, 241, 0.2) 100%);
  border: 1px solid rgba(139, 92, 246, 0.4);
}

.msg .time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.msg.system {
  align-self: center;
  max-width: none;
}

.msg.system .system-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.25rem 0.75rem;
  background: var(--surface);
  border-radius: 999px;
}

.input-area {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.input-area textarea {
  flex: 1;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.input-area textarea:focus {
  border-color: var(--accent);
}

.input-area button {
  padding: 0.875rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
  align-self: flex-end;
}

.input-area button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.input-area button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
