:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --side: #fbfbfd;
  --text: #17171c;
  --text-2: #5c5c6b;
  --muted: #9a9aa8;
  --line: #ececf1;
  --line-2: #e2e2ea;
  --brand: #4f46e5;
  --brand-soft: #eef0ff;
  --brand-2: #7c6cff;
  --green: #0f9d58;
  --amber: #b26a00;
  --danger: #d93025;
  --bubble-ai: #f4f5f8;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(16, 18, 32, .04), 0 8px 24px rgba(16, 18, 32, .06);
  --shadow-lg: 0 24px 70px rgba(16, 18, 32, .16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
h1, h2, h3, p { margin: 0; }
button { font-family: inherit; }

/* ================= 布局 ================= */
.app { display: flex; height: 100%; height: 100dvh; }

.sidebar {
  width: 268px; flex: 0 0 268px; background: var(--side); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 18px 16px 12px; }
.brand-mini {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 10px; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 15px;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .28);
}
.brand-name { font-size: 15px; font-weight: 650; letter-spacing: -.2px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.new-chat {
  margin: 4px 14px 12px; padding: 10px 12px; border-radius: 12px; cursor: pointer;
  background: #fff; border: 1px solid var(--line-2); color: var(--text); font-size: 14px; font-weight: 550;
  display: flex; align-items: center; justify-content: center; gap: 6px; transition: .16s;
}
.new-chat:hover { border-color: #cfcfe0; box-shadow: var(--shadow); }
.new-chat .plus { color: var(--brand); font-size: 15px; }

.conv-list { flex: 1; overflow-y: auto; padding: 0 10px 10px; }
.conv-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 11px; border-radius: 10px;
  font-size: 13.5px; color: var(--text-2); cursor: pointer; margin-bottom: 1px; transition: .14s;
}
.conv-item:hover { background: #f1f2f6; }
.conv-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 550; }
.conv-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .del { opacity: 0; font-size: 13px; color: var(--muted); padding: 0 2px; }
.conv-item:hover .del { opacity: 1; }
.conv-empty { padding: 20px 12px; font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.8; }

.side-foot {
  border-top: 1px solid var(--line); padding: 12px 14px; display: flex; align-items: center; gap: 8px;
}
.who { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.avatar-sm {
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 9px; background: #eceef5; color: var(--text-2);
  display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 600;
}
.who-txt { min-width: 0; line-height: 1.25; }
.who-txt b { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-txt span { font-size: 11.5px; color: var(--muted); }
.link-btn { background: none; border: 0; color: var(--brand); font-size: 13px; cursor: pointer; padding: 4px; }

/* ================= 主区 ================= */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.topbar {
  height: 54px; flex: 0 0 54px; display: flex; align-items: center; gap: 10px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .86); backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 14.5px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent; color: var(--text-2);
  font-size: 17px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: .14s;
}
.icon-btn:hover { background: #f1f2f6; color: var(--text); }

.bal-pill {
  display: flex; align-items: center; gap: 2px; padding: 6px 11px; border-radius: 20px; cursor: pointer;
  background: #f4f5f9; border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--text);
  transition: .16s;
}
.bal-pill:hover { background: var(--brand-soft); border-color: #d9d8ff; color: var(--brand); }
.bal-pill .cur { font-size: 11.5px; font-weight: 500; opacity: .6; }
.bal-pill.low { background: #fdeceb; border-color: #f7cfcb; color: var(--danger); }

/* ================= 消息区 ================= */
.messages { flex: 1; overflow-y: auto; padding: 22px 20px 10px; }
.hero { max-width: 560px; margin: 6vh auto 0; text-align: center; padding: 0 10px; }
.hero-icon {
  width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 16px; background: var(--brand);
  color: #fff; font-size: 24px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 30px rgba(79, 70, 229, .28);
}
.hero h2 { font-size: 22px; font-weight: 650; letter-spacing: -.4px; margin-bottom: 8px; }
.hero p { font-size: 13.5px; color: var(--text-2); line-height: 1.7; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.chip {
  padding: 8px 14px; border-radius: 20px; background: #fff; border: 1px solid var(--line-2);
  font-size: 13px; color: var(--text-2); cursor: pointer; transition: .16s;
}
.chip:hover { border-color: #cfcfe0; color: var(--text); box-shadow: var(--shadow); }
.hero-note { margin-top: 18px; font-size: 12px; color: var(--muted); }

.msg { display: flex; gap: 11px; margin-bottom: 20px; max-width: 860px; margin-left: auto; margin-right: auto; }
.msg .av {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 9px; display: flex; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 600; margin-top: 1px;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .av { background: var(--brand); color: #fff; }
.msg.assistant .av { background: #f0f1f6; color: var(--brand); font-size: 14px; }
.wrap { max-width: min(680px, 80%); display: flex; flex-direction: column; }
.msg.user .wrap { align-items: flex-end; }
.bubble {
  padding: 11px 15px; border-radius: var(--radius); font-size: 14.6px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
}
.msg.assistant .bubble { background: var(--bubble-ai); color: var(--text); border-bottom-left-radius: 6px; }
.msg.user .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 6px; }
.bubble code {
  background: #e7e8ef; padding: 2px 5px; border-radius: 5px; font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.bubble pre {
  background: #17171c; color: #eceef4; border-radius: 12px; padding: 13px 14px; overflow-x: auto;
  margin: 9px 0; font-size: 12.8px; line-height: 1.6;
}
.bubble pre code { background: none; padding: 0; color: inherit; }
.bubble strong { font-weight: 650; }
.meta { font-size: 11px; color: var(--muted); margin-top: 6px; padding: 0 4px; }
.typing::after { content: '▍'; color: var(--brand); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }

.attach-row { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 7px; }
.attach-chip {
  display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2);
  background: #fff; border: 1px solid var(--line-2); border-radius: 10px; padding: 7px 10px;
  text-decoration: none; max-width: 240px;
}
.attach-chip:hover { border-color: #cfcfe0; }
.attach-chip .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .sz { color: var(--muted); font-size: 11px; }
.attach-chip img { width: 32px; height: 32px; border-radius: 7px; object-fit: cover; }

.msg-actions { display: flex; gap: 6px; margin-top: 7px; opacity: 0; transition: .16s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions .act {
  font-size: 11.5px; color: var(--text-2); background: #fff; border: 1px solid var(--line-2);
  border-radius: 8px; padding: 4px 9px; cursor: pointer; transition: .14s;
}
.msg-actions .act:hover { color: var(--brand); border-color: #d9d8ff; background: var(--brand-soft); }

/* ================= 输入区 ================= */
.composer { padding: 8px 20px 14px; background: linear-gradient(to top, #fff 60%, rgba(255,255,255,0)); }
.box {
  max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px;
  background: #fff; border: 1px solid var(--line-2); border-radius: 20px; padding: 7px 8px 7px 6px;
  box-shadow: var(--shadow); transition: .16s;
}
.box:focus-within { border-color: #c7c4ff; box-shadow: 0 0 0 3px rgba(79, 70, 229, .09), var(--shadow); }
.tool {
  width: 36px; height: 36px; flex: 0 0 36px; border: 0; background: transparent; color: var(--text-2);
  font-size: 16px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.tool:hover { background: #f1f2f6; }
#input {
  flex: 1; border: 0; outline: none; resize: none; background: transparent; color: var(--text);
  font-size: 15px; line-height: 1.6; padding: 8px 4px; max-height: 170px;
}
#input::placeholder { color: var(--muted); }
.send {
  width: 36px; height: 36px; flex: 0 0 36px; border: 0; border-radius: 11px; cursor: pointer;
  background: var(--brand); color: #fff; font-size: 17px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; transition: .16s;
}
.send:hover:not(:disabled) { background: #4038cf; }
.send:disabled { background: #e5e6ee; color: #b6b7c6; cursor: not-allowed; }
.hint { text-align: center; font-size: 11px; color: var(--muted); margin-top: 8px; }

.pending-bar { display: flex; flex-wrap: wrap; gap: 7px; max-width: 860px; margin: 0 auto 8px; }
.pending-bar:empty { display: none; }
.pill {
  display: flex; align-items: center; gap: 6px; font-size: 12px; background: var(--brand-soft);
  border: 1px solid #dcdaff; border-radius: 9px; padding: 5px 9px; color: var(--brand);
}
.pill b { cursor: pointer; font-weight: 400; opacity: .7; }

/* ================= 弹窗 ================= */
.modal {
  position: fixed; inset: 0; background: rgba(20, 22, 34, .32); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; padding: 18px; z-index: 80;
}
.modal.on { display: flex; }
.modal-card {
  width: 100%; max-width: 372px; background: #fff; border-radius: 22px; padding: 26px 24px 22px;
  box-shadow: var(--shadow-lg); position: relative; animation: pop .22s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal-x {
  position: absolute; top: 12px; right: 12px; width: 28px; height: 28px; border: 0; background: transparent;
  color: var(--muted); font-size: 15px; cursor: pointer; border-radius: 8px;
}
.modal-x:hover { background: #f2f3f7; color: var(--text); }
.modal-logo {
  width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 14px; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 21px;
  box-shadow: 0 8px 22px rgba(79, 70, 229, .28);
}
.modal-logo.money { background: #0f9d58; box-shadow: 0 8px 22px rgba(15, 157, 88, .26); font-size: 22px; font-weight: 700; }
.modal-card h3 { text-align: center; font-size: 17px; font-weight: 650; letter-spacing: -.2px; }
.modal-sub { text-align: center; font-size: 12.5px; color: var(--text-2); margin: 6px 0 18px; }
.modal-sub b { color: var(--text); font-size: 15px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; font-weight: 500; }
input, textarea, select {
  width: 100%; border: 1px solid var(--line-2); background: #fff; color: var(--text);
  border-radius: 11px; padding: 11px 12px; font-size: 14.5px; outline: none; transition: .16s; font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .1);
}
.btn {
  width: 100%; border: 0; border-radius: 11px; padding: 12px; font-size: 14.5px; font-weight: 600;
  cursor: pointer; transition: .16s;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: #4038cf; }
.btn.primary:disabled { background: #d8d9e6; cursor: not-allowed; }
.swap { text-align: center; font-size: 13px; color: var(--text-2); margin-top: 14px; }
.swap a { color: var(--brand); cursor: pointer; font-weight: 550; }
.form-msg { font-size: 12.5px; text-align: center; min-height: 16px; margin-top: 10px; }
.form-msg.ok { color: var(--green); }
.form-msg.bad { color: var(--danger); }
.pay-note { font-size: 12px; color: var(--text-2); text-align: center; margin-top: 14px; line-height: 1.7; }

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(14px);
  background: #17171c; color: #fff; padding: 10px 16px; border-radius: 11px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: .22s; z-index: 200; max-width: 86vw; text-align: center;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

.mask { position: fixed; inset: 0; background: rgba(20, 22, 34, .3); z-index: 60; display: none; }
.mask.on { display: block; }

.only-mobile { display: none; }

@media (max-width: 780px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 70; width: 82%; max-width: 296px;
    transform: translateX(-100%); transition: transform .24s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.on { transform: translateX(0); }
  .only-mobile { display: flex; }
  .messages { padding: 16px 12px 6px; }
  .composer { padding: 6px 10px 12px; }
  .wrap { max-width: 86%; }
  .msg .av { width: 26px; height: 26px; flex: 0 0 26px; font-size: 11px; }
  .hero { margin-top: 4vh; }
  .hero h2 { font-size: 19px; }
  .msg-actions { opacity: 1; }
  .bal-pill { padding: 5px 9px; font-size: 12.5px; }
}

/* ================= 模型选择 ================= */
.model-bar { max-width: 860px; margin: 0 auto 7px; position: relative; }
.model-btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 18px;
  background: #fff; border: 1px solid var(--line-2); color: var(--text-2); font-size: 12.5px;
  cursor: pointer; transition: .16s; font-weight: 550;
}
.model-btn:hover { border-color: #cfcfe0; color: var(--text); }
.model-btn .mdot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.model-btn .caret { font-size: 9px; opacity: .5; }
.model-menu {
  position: absolute; left: 0; bottom: 46px; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 230px; max-width: 300px;
  display: none; z-index: 50; max-height: 320px; overflow-y: auto;
}
.model-menu.on { display: block; animation: pop .16s ease; }
.model-opt {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 9px;
  cursor: pointer; font-size: 13px; color: var(--text-2);
}
.model-opt:hover { background: var(--bg-soft); }
.model-opt.sel { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.model-opt .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-opt .vd { font-size: 10.5px; color: var(--muted); }
.model-opt .chk { color: var(--brand); font-size: 12px; }

/* ================= 思考状态 ================= */
.think-line {
  display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: #8a8a99;
  line-height: 1.65; padding-left: 10px; border-left: 2px solid #e4e4ee; margin-bottom: 9px;
  max-height: 150px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.think-line.done { opacity: .55; font-size: 12px; margin-bottom: 7px; }
.think-line .spin {
  width: 11px; height: 11px; flex: 0 0 11px; margin-top: 5px; border-radius: 50%;
  border: 2px solid #dcdce8; border-top-color: var(--brand);
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.think-line.done .spin { animation: none; border-color: #b9e5cd; border-top-color: #0f9d58; }
.bubble .answer { white-space: pre-wrap; }
.bubble .answer:empty { display: none; }

/* 购买按钮 */
.btn.buy {
  display: block; text-align: center; text-decoration: none; margin-top: 10px;
  background: #f4f5f9; border: 1px solid var(--line-2); color: var(--text-2); font-weight: 550;
  padding: 11px; border-radius: 11px; font-size: 14px; transition: .16s;
}
.btn.buy:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }

/* ================= Markdown 排版 ================= */
.msg.assistant .bubble .answer { white-space: normal; }
.msg.assistant .bubble .answer:empty { display: none; }
.bubble .md-p { margin: 0 0 8px; white-space: pre-wrap; }
.bubble .md-p:last-child { margin-bottom: 0; }
.bubble .md-h { font-size: 15px; font-weight: 650; margin: 13px 0 7px; letter-spacing: -.2px; }
.bubble .md-h:first-child { margin-top: 0; }
.bubble .md-ul, .bubble .md-ol { margin: 6px 0 9px; padding-left: 21px; }
.bubble .md-ul li, .bubble .md-ol li { margin-bottom: 4px; }
.bubble .md-hr { border: 0; border-top: 1px solid var(--line-2); margin: 11px 0; }
.bubble .md-table {
  border-collapse: collapse; width: 100%; margin: 9px 0; font-size: 13px;
  display: block; overflow-x: auto; white-space: nowrap;
}
.bubble .md-table th, .bubble .md-table td {
  border: 1px solid var(--line-2); padding: 7px 10px; text-align: left; vertical-align: top;
}
.bubble .md-table th { background: #f6f7fb; font-weight: 600; }
.bubble a { color: var(--brand); text-decoration: underline; word-break: break-all; }

/* 用户气泡里的表格/链接配色 */
.msg.user .bubble .md-table th { background: rgba(255,255,255,.16); }
.msg.user .bubble .md-table th, .msg.user .bubble .md-table td { border-color: rgba(255,255,255,.32); }
.msg.user .bubble a { color: #fff; }
.msg.user .bubble .md-hr { border-top-color: rgba(255,255,255,.3); }
.msg.user .bubble code { background: rgba(255,255,255,.18); color: #fff; }

.btn.buy.disabled { opacity: .5; cursor: not-allowed; }
.btn.buy.disabled:hover { border-color: var(--line-2); color: var(--text-2); background: #f4f5f9; }

/* 生成图片 */
.gen-img { margin-bottom: 9px; }
.gen-img img {
  max-width: min(320px, 100%); border-radius: 13px; display: block;
  border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(16,18,32,.08);
}

/* ================= 上传进度 ================= */
.upload-box {
  display: none; max-width: 860px; margin: 0 auto 8px; padding: 10px 13px; border-radius: 12px;
  background: #fff; border: 1px solid var(--line-2); box-shadow: var(--shadow);
}
.upload-box.on { display: block; }
.upload-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.upload-head .uname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 70%; }
.upload-head .upct { font-weight: 650; color: var(--brand); font-variant-numeric: tabular-nums; }
.upload-bar { height: 6px; border-radius: 6px; background: #eef0f5; overflow: hidden; }
.upload-fill {
  height: 100%; width: 0%; border-radius: 6px;
  background: linear-gradient(90deg, var(--brand), #6d8bff);
  transition: width .18s ease;
}
.upload-sub { font-size: 11px; color: var(--muted); margin-top: 5px; }
