:root {
  --bg: #ffffff;
  --bg-panel: #f7f8fa;
  --bg-elev: #eef0f4;
  --border: #e5e7eb;
  --text: #1f2328;
  --text-dim: #6b7280;
  --accent: #3b82f6;
  --user: #dbeafe;
  --assistant: #f3f4f6;
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

[v-cloak] { display: none; }

.center-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 登录页 */
.login-wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
  margin-bottom: 14px;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}
.login-card button:disabled { opacity: 0.6; cursor: default; }
.err-text { color: #dc2626; font-size: 13px; margin-top: 12px; }

/* 主界面 */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 260px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.new-chat {
  margin: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent); }

.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
}
.conv-item:hover { background: var(--bg-elev); }
.conv-item.active { background: var(--bg-elev); }
.conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  font-size: 14px;
}
.conv-del {
  display: none;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}
.conv-item:hover .conv-del { display: block; }
.conv-del:hover { color: #dc2626; }
.conv-empty { color: var(--text-dim); text-align: center; padding: 20px; font-size: 13px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.topbar-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}
.menu-btn { display: none; }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}
.welcome {
  text-align: center;
  color: var(--text-dim);
  margin-top: 15vh;
}
.welcome h2 { color: var(--text); margin-bottom: 10px; }

.msg { display: flex; margin-bottom: 16px; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.65;
  word-break: break-word;
}
.msg.user .bubble { background: var(--user); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--assistant); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.bubble pre {
  background: #f6f8fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
.bubble code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}
.bubble p code { background: #f1f2f4; padding: 2px 6px; border-radius: 4px; }
.bubble h1, .bubble h2, .bubble h3 { margin: 12px 0 6px; }
.bubble p { margin: 6px 0; }
.bubble ul, .bubble ol { margin: 6px 0; padding-left: 22px; }
.bubble table { border-collapse: collapse; margin: 10px 0; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.bubble a { color: var(--accent); }
.bubble blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-dim); margin: 8px 0; }

.cursor { animation: blink 1s step-start infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.err-banner {
  background: rgba(220, 38, 38, 0.08);
  color: #dc2626;
  padding: 10px 14px;
  border-radius: 8px;
  margin: 12px 0;
  font-size: 13px;
}

.composer { padding: 12px 16px 16px; border-top: 1px solid var(--border); background: var(--bg-panel); }
.composer-box {
  max-width: 860px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.file-btn {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 16px;
  padding: 4px;
}
.file-btn:hover { color: var(--text); }
.file-btn input { display: none; }
.model-select {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  outline: none;
  max-width: 340px;
}

.input-row { display: flex; align-items: flex-end; gap: 10px; }
.input-row textarea {
  flex: 1;
  resize: none;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  max-height: 200px;
  font-family: inherit;
}
.send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 8px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.5; cursor: default; }

.mask { display: none; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar.open { transform: translateX(0); }
  .mask { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 15; }
  .menu-btn { display: block; }
  .bubble { max-width: 92%; }
}

/* 图片识别 */
.img-preview {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.img-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.img-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 18px;
}
.msg-img {
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
  margin: 6px 0;
  display: block;
}

/* 联网搜索开关 */
.search-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  user-select: none;
  white-space: nowrap;
}
.search-toggle.on {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}
.search-toggle input {
  display: none;
}
