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

/* 默认（浅色 · 白色） */
:root {
  --bg: #ffffff;
  --panel: #f6f7f9;
  --panel-2: #eceef2;
  --border: #dcdfe6;
  --text: #1b1e26;
  --text-dim: #667085;
  --accent: #5b6bff;
  --accent-2: #8a5cff;
  --user-bubble: #e8ecff;
  --danger: #d64545;
  --card-active-bg: linear-gradient(135deg, #eef0ff, #f4eeff);
  --code-bg: #f3f4f6;
}

/* 跟随系统：深色时套用黑主题 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]),
  :root[data-theme="system"] {
    --bg: #000000;
    --panel: #111114;
    --panel-2: #1a1a1f;
    --border: #26262c;
    --text: #e8e8ee;
    --text-dim: #9a9aa8;
    --accent: #6c7cff;
    --accent-2: #9a6cff;
    --user-bubble: #232337;
    --danger: #ff6b6b;
    --card-active-bg: linear-gradient(135deg, #1d2340, #241d3a);
    --code-bg: #0d0f16;
  }
}

/* 黑色主题 */
:root[data-theme="dark"] {
  --bg: #000000;
  --panel: #111114;
  --panel-2: #1a1a1f;
  --border: #26262c;
  --text: #e8e8ee;
  --text-dim: #9a9aa8;
  --accent: #6c7cff;
  --accent-2: #9a6cff;
  --user-bubble: #232337;
  --danger: #ff6b6b;
  --card-active-bg: linear-gradient(135deg, #1d2340, #241d3a);
  --code-bg: #0d0f16;
}

/* 灰色主题 */
:root[data-theme="gray"] {
  --bg: #383a3f;
  --panel: #43454b;
  --panel-2: #4e5158;
  --border: #5b5e66;
  --text: #ececef;
  --text-dim: #adb0b8;
  --accent: #7c8cff;
  --accent-2: #a97cff;
  --user-bubble: #4d5166;
  --danger: #ff6b6b;
  --card-active-bg: linear-gradient(135deg, #4a4e6a, #514a6a);
  --code-bg: #2a2c30;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  font-size: 20px;
}

.title {
  font-weight: 700;
  font-size: 16px;
}

.model-select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.model-select:focus {
  border-color: var(--accent);
}

.new-chat-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}

.new-chat-btn:hover { opacity: .9; }
.new-chat-btn:active { transform: scale(.95); }
.new-chat-btn:disabled { opacity: .4; cursor: not-allowed; }

.export-menu {
  position: fixed;
  z-index: 100;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  padding: 4px;
  min-width: 140px;
}

.export-menu-item {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text);
}

.export-menu-item:hover {
  background: var(--card-active-bg);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .45);
}

.modal {
  width: min(480px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}

.modal-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
}

.modal-hint {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 18px;
}

.settings-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.set-field {
  display: block;
}

.set-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.set-input {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 11px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.set-input:focus {
  border-color: var(--accent);
}

.set-desc {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.modal-btn {
  padding: 8px 18px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.modal-btn:hover { opacity: .9; }

.modal-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

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

.auth-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}

.auth-btn:hover { opacity: .85; }

.user-badge {
  font-size: 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  white-space: nowrap;
}

.skill-select {
  max-width: 180px;
}

.auth-switch {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-dim);
}

.auth-switch a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.empty-sub {
  font-size: 12px;
  margin-top: 6px;
  opacity: .7;
}

.msg {
  max-width: 88%;
  animation: fadeIn .2s ease;
}

.msg.user {
  align-self: flex-end;
}

.msg.bot {
  align-self: flex-start;
  max-width: 100%;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 14px;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.msg.bot .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg.bot .bubble.markdown {
  white-space: normal;
}

/* markdown */
.msg.bot .bubble h1, .msg.bot .bubble h2, .msg.bot .bubble h3 {
  margin: 10px 0 6px;
  font-size: 1.1em;
}

.msg.bot .bubble h1 { font-size: 1.25em; }
.msg.bot .bubble h2 { font-size: 1.15em; }

.msg.bot .bubble p {
  margin: 6px 0;
}

.msg.bot .bubble ul, .msg.bot .bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}

.msg.bot .bubble li {
  margin: 3px 0;
}

.msg.bot .bubble code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12.5px;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
}

.msg.bot .bubble pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.msg.bot .bubble pre code {
  background: none;
  border: none;
  padding: 0;
  white-space: pre;
}

.msg.bot .bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 8px 0;
  color: var(--text-dim);
}

.msg.bot .bubble strong {
  font-weight: 700;
}

.msg.bot .bubble a {
  color: var(--accent);
}

.msg.meta {
  align-self: center;
  font-size: 12px;
  color: var(--text-dim);
}

.msg.error .bubble {
  border-color: var(--danger);
  color: var(--danger);
}

.input-area {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

textarea {
  flex: 1;
  resize: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
}

textarea:focus {
  border-color: var(--accent);
}

textarea:disabled {
  opacity: .5;
}

.send-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}

.send-btn:hover { opacity: .9; }
.send-btn:active { transform: scale(.95); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }

.tip {
  font-size: 11px;
  color: var(--text-dim);
  padding: 0 16px 8px;
  min-height: 16px;
  background: var(--panel);
}

/* 移动端 */
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .theme-select, .export-btn { display: none; }
  .skill-select { max-width: 120px; }
  .msg { max-width: 95%; }
}
