:root {
  --blue: #4d6bfe;
  --blue-dark: #3d5bee;
  --blue-soft: #eff3ff;
  --bg: #ffffff;
  --sidebar: #f8faff;
  --border: #e8ecf3;
  --text: #1b1f27;
  --muted: #8b93a1;
  --muted-2: #a8b0bd;
  --danger: #e5484d;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(31, 41, 55, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
[hidden] { display: none !important; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 9px; color: var(--muted);
  font-size: 16px; line-height: 1;
}
.icon-btn:hover { background: #eef1f7; color: var(--text); }
.mobile-only { display: none !important; }

/* ============================ 登录 ============================ */

.auth {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #f7f9ff 0%, #ffffff 45%);
}
.auth-panel {
  width: 100%; max-width: 380px;
  padding: 36px 32px 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(77, 107, 254, 0.08);
}
.auth-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 21px; font-weight: 600; letter-spacing: 0.2px;
  margin-bottom: 26px;
}
.auth-tabs {
  display: flex; gap: 4px;
  background: #f3f5f9; border-radius: 10px; padding: 4px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1; padding: 8px; border-radius: 8px;
  color: var(--muted); font-size: 14px;
}
.auth-tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.reg-email { display: flex; flex-direction: column; gap: 10px; }
.input {
  width: 100%; height: 44px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: #fbfcfe; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--blue); background: #fff; box-shadow: 0 0 0 3px rgba(77,107,254,0.12); }
.code-row { display: flex; gap: 8px; }
.code-row .input { flex: 1; }

.btn-primary {
  height: 44px; border-radius: 12px;
  background: var(--blue); color: #fff; font-weight: 600;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-ghost {
  height: 44px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }

.auth-hint { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.auth-terms { color: var(--muted-2); font-size: 12px; margin: 22px 0 0; text-align: center; }

/* ============================ 布局 ============================ */

.layout { display: flex; height: 100dvh; }

.sidebar {
  width: 264px; flex: none;
  display: flex; flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 12px 10px 10px;
  z-index: 20;
}
.sidebar-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 14px;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; }

.new-chat {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; border-radius: 12px;
  border: 1px solid #dfe6f5; background: #fff;
  color: var(--text); font-size: 14px;
  transition: all 0.15s;
}
.new-chat:hover { border-color: var(--blue); color: var(--blue); background: #f7f9ff; }

.history { flex: 1; overflow-y: auto; margin-top: 14px; padding-right: 2px; }
.history::-webkit-scrollbar { width: 6px; }
.history::-webkit-scrollbar-thumb { background: #dde3ee; border-radius: 3px; }

.group-label {
  font-size: 12px; color: var(--muted-2);
  padding: 12px 8px 6px;
}
.history-item {
  width: 100%; text-align: left;
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px; height: 38px; border-radius: 10px;
  color: #3d4350; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.history-item:hover { background: #eef2fb; }
.history-item.active { background: #e7eeff; color: var(--blue); font-weight: 500; }
.history-del {
  flex: none; width: 22px; height: 22px; border-radius: 6px;
  color: var(--muted-2); opacity: 0; font-size: 15px; line-height: 1;
}
.history-item:hover .history-del { opacity: 1; }
.history-del:hover { background: #dfe6f5; color: var(--danger); }

.user-card {
  display: flex; align-items: center; gap: 10px;
  margin-top: 8px; padding: 8px;
  border-radius: 12px; cursor: pointer;
}
.user-card:hover { background: #eef2fb; }
.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: 50%; background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; text-transform: uppercase;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-balance { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

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

.topbar {
  height: 56px; flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid #f1f4f9;
}
.model-pill {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 14px; color: #3d4350;
}
.model-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: #34c759; }

.chat-scroll { flex: 1; overflow-y: auto; padding: 8px 20px 0; }
.chat-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-thumb { background: #e3e8f1; border-radius: 4px; }

.welcome {
  max-width: 720px; margin: 18vh auto 0; text-align: center;
}
.welcome h1 {
  font-size: 26px; font-weight: 600; margin: 0 0 10px;
  letter-spacing: 0.3px;
}
.welcome p { color: var(--muted); font-size: 15px; margin: 0; }

.messages { max-width: 760px; margin: 0 auto; padding: 18px 0 8px; display: flex; flex-direction: column; gap: 26px; }

.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  max-width: 78%;
  background: var(--blue-soft); color: #1f2734;
  padding: 10px 16px; border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap; word-break: break-word;
}

.msg-ai { display: flex; gap: 12px; align-items: flex-start; }
.msg-ai .ai-avatar {
  width: 28px; height: 28px; flex: none; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: #eef2ff;
}
.msg-ai .ai-main { flex: 1; min-width: 0; }
.msg-ai .ai-body { word-break: break-word; }
.msg-ai .ai-body.streaming { white-space: pre-wrap; }
.msg-ai .ai-body.error { color: var(--danger); }

.ai-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity 0.15s; }
.msg-ai:hover .ai-actions { opacity: 1; }
.ai-actions button {
  height: 28px; padding: 0 8px; border-radius: 8px;
  color: var(--muted); font-size: 12px;
  display: inline-flex; align-items: center; gap: 4px;
}
.ai-actions button:hover { background: #f2f5fa; color: var(--text); }

/* Markdown */
.ai-body p { margin: 0 0 12px; }
.ai-body p:last-child { margin-bottom: 0; }
.ai-body h1, .ai-body h2, .ai-body h3, .ai-body h4 { margin: 18px 0 10px; line-height: 1.4; }
.ai-body h1 { font-size: 21px; } .ai-body h2 { font-size: 19px; } .ai-body h3 { font-size: 17px; }
.ai-body ul, .ai-body ol { margin: 0 0 12px; padding-left: 22px; }
.ai-body li { margin: 4px 0; }
.ai-body blockquote {
  margin: 0 0 12px; padding: 8px 14px;
  border-left: 3px solid #d7e0f5; background: #f8faff; color: #4b5563;
  border-radius: 0 8px 8px 0;
}
.ai-body code {
  background: #f2f4f9; padding: 2px 6px; border-radius: 6px;
  font: 13px/1.6 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
.ai-body pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  background: #f7f9fc; border: 1px solid #e9eef7;
  border-radius: 12px;
  font: 13px/1.6 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
.ai-body pre code { background: none; padding: 0; }
.code-block { margin: 0 0 14px; border: 1px solid #e9eef7; border-radius: 12px; overflow: hidden; }
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; background: #f2f5fa; border-bottom: 1px solid #e9eef7;
  font-size: 12px; color: var(--muted);
}
.code-head button { font-size: 12px; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.code-head button:hover { background: #e6ebf5; color: var(--text); }
.code-block pre { border: none; border-radius: 0; }
.ai-body table { border-collapse: collapse; margin: 0 0 12px; font-size: 14px; }
.ai-body th, .ai-body td { border: 1px solid #e5eaf2; padding: 6px 12px; }
.ai-body th { background: #f7f9fc; }

/* ============================ 输入区 ============================ */

.composer-wrap { flex: none; padding: 8px 20px 14px; }
.composer {
  max-width: 760px; margin: 0 auto;
  border: 1px solid #dde3ee; border-radius: 22px;
  background: #fff; padding: 10px 12px 8px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within { border-color: #b9c8ff; box-shadow: 0 2px 16px rgba(77, 107, 254, 0.12); }
.composer textarea {
  width: 100%; border: none; outline: none; resize: none;
  max-height: 180px; padding: 6px 4px; background: transparent;
  line-height: 1.6;
}
.composer textarea::placeholder { color: var(--muted-2); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; padding-top: 4px; }

.toggle-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px; border-radius: 15px;
  border: 1px solid var(--border); color: var(--muted); font-size: 13px;
  transition: all 0.15s;
}
.toggle-btn .toggle-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #d3d9e4;
}
.toggle-btn[aria-pressed="true"] {
  border-color: #c3cfff; background: var(--blue-soft); color: var(--blue);
}
.toggle-btn[aria-pressed="true"] .toggle-dot { background: var(--blue); }

.send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--blue); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}
.send-btn:disabled { background: #ccd6f0; cursor: default; }
.send-btn:not(:disabled):hover { background: var(--blue-dark); }

.composer-tip { text-align: center; color: var(--muted-2); font-size: 12px; margin: 8px 0 0; }

/* ============================ 弹窗 / Toast ============================ */

.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(17, 24, 39, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-card {
  width: 100%; max-width: 460px; max-height: 82vh;
  background: #fff; border-radius: 18px; padding: 20px;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(17, 24, 39, 0.2);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { margin-top: 16px; overflow-y: auto; }

.amounts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.amount-btn {
  height: 44px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; font-variant-numeric: tabular-nums;
}
.amount-btn:hover { border-color: var(--blue); color: var(--blue); }
.amount-btn.active-amount { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.pay-qr {
  display: block; width: 176px; height: 176px; object-fit: contain;
  margin: 14px auto 0; padding: 8px; background: #fff;
  border: 1px solid var(--border); border-radius: 12px;
}
.pay-link { display: block; text-align: center; margin-top: 10px; line-height: 42px; height: 42px; }
.order-list { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.order-item { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.import-actions { display: flex; gap: 8px; margin-top: 12px; }
.import-actions .btn-ghost { flex: 1; height: 38px; padding: 0 8px; font-size: 13px; }
.modal-note { color: var(--muted); font-size: 12px; margin: 12px 0; }

.invite-link { display: flex; gap: 8px; margin: 12px 0; }
.invite-link input { flex: 1; height: 40px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: #fbfcfe; }
.modal-body textarea {
  width: 100%; min-height: 140px; padding: 12px; resize: vertical;
  border: 1px solid var(--border); border-radius: 12px; background: #fbfcfe; outline: none;
}

.menu-list { display: flex; flex-direction: column; gap: 2px; }
.menu-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 11px 10px; border-radius: 10px; text-align: left;
}
.menu-item:hover { background: #f4f7fc; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: #1f2734; color: #fff; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; z-index: 80;
  max-width: 90vw;
}

.overlay {
  position: fixed; inset: 0; z-index: 15;
  background: rgba(17, 24, 39, 0.35);
}

/* ============================ 响应式 ============================ */

@media (max-width: 860px) {
  .mobile-only { display: inline-flex !important; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: 80vw; max-width: 300px;
    box-shadow: 0 0 40px rgba(17,24,39,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .chat-scroll { padding: 8px 14px 0; }
  .composer-wrap { padding: 6px 12px 10px; }
  .welcome { margin-top: 14vh; }
  .welcome h1 { font-size: 21px; }
}
