/* 百变 AI — 浅色主题 */
:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e7e9f2;
  --border-strong: #d9dceb;
  --text: #1b1f33;
  --text-2: #5a6180;
  --text-3: #949bb4;
  --primary: #5b5bd6;
  --primary-dark: #4a49c0;
  --primary-soft: #eeeefe;
  --accent: #5b5bd6;
  --accent-soft: #eeeefe;
  --shadow-sm: 0 2px 10px rgba(30, 36, 80, .05);
  --shadow: 0 10px 32px rgba(30, 36, 80, .08);
  --shadow-lg: 0 18px 50px rgba(30, 36, 80, .14);
  --r: 18px;
  --sidebar-w: 296px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.6;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100dvh; overflow: hidden; }

/* ---------- 侧栏 ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 22px 22px 16px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center; color: #fff; font-size: 21px;
  background: linear-gradient(135deg, #6d6dea, #4b49c4);
  box-shadow: 0 6px 16px rgba(91, 91, 214, .28);
}
.brand-title { font-size: 16px; font-weight: 700; letter-spacing: .3px; }
.brand-sub { font-size: 11.5px; color: var(--text-3); margin-top: -2px; }

.new-chat {
  margin: 4px 16px 16px; padding: 11px 14px; border-radius: 12px;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 13.5px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  box-shadow: 0 6px 16px rgba(91, 91, 214, .22);
  transition: transform .16s, box-shadow .16s, background .16s;
}
.new-chat:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 9px 20px rgba(91, 91, 214, .3); }
.new-chat .plus { font-size: 18px; line-height: 1; font-weight: 400; }

.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 12px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.side-scroll::-webkit-scrollbar { width: 6px; }
.side-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }

.section-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--text-3); padding: 8px 6px 10px;
}
.section-count { font-weight: 600; letter-spacing: 0; text-transform: none; }
.text-btn { color: var(--text-3); font-size: 11px; letter-spacing: 0; text-transform: none; font-weight: 500; }
.text-btn:hover { color: #d9534f; }

.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.style-card {
  position: relative; text-align: left; padding: 9px 10px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  display: flex; align-items: center; gap: 8px; min-width: 0;
  transition: border-color .16s, background .16s, transform .16s, box-shadow .16s;
}
.style-card:hover { transform: translateY(-1px); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.style-card.active { border-color: var(--sc); background: var(--sc-soft); box-shadow: 0 3px 12px var(--sc-shadow); }
.style-card.active::after {
  content: ''; position: absolute; top: 7px; right: 8px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--sc);
}
.style-emoji { font-size: 19px; line-height: 1; flex: none; }
.style-name { font-size: 12.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.style-card.active .style-name { color: var(--sc); }

.history-label { margin-top: 20px; }
.history { display: flex; flex-direction: column; gap: 3px; }
.history-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 10px; color: var(--text-2); font-size: 12.5px;
  transition: background .15s, color .15s;
}
.history-item:hover { background: var(--surface-2); color: var(--text); }
.history-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.history-item .h-emoji { font-size: 14px; flex: none; }
.history-item .h-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-del { opacity: 0; font-size: 13px; color: var(--text-3); padding: 0 2px; flex: none; }
.history-item:hover .h-del { opacity: 1; }
.history-item .h-del:hover { color: #d9534f; }
.history-empty { font-size: 12px; color: var(--text-3); padding: 8px 10px; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 16px 14px; }
.status-row { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-3); margin-bottom: 10px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #c9ccdb; flex: none; }
.status-dot.ok { background: #2fbf78; box-shadow: 0 0 0 3px rgba(47, 191, 120, .14); }
.status-dot.warn { background: #e8a33d; box-shadow: 0 0 0 3px rgba(232, 163, 61, .14); }
.status-dot.err { background: #e06a67; box-shadow: 0 0 0 3px rgba(224, 106, 103, .14); }
.settings-btn { width: 100%; text-align: left; padding: 8px 10px; border-radius: 10px; color: var(--text-2); font-size: 12.5px; }
.settings-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- 主区 ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.main::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 320px; pointer-events: none;
  background: radial-gradient(620px 220px at 72% -40px, rgba(107, 107, 235, .09), transparent 70%);
}
.topbar {
  position: relative; z-index: 2; flex: none; height: 72px; padding: 0 26px;
  display: flex; align-items: center; gap: 12px;
  background: rgba(255, 255, 255, .82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; }
.topbar-emoji {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  font-size: 19px; background: var(--accent-soft); flex: none;
  transition: background .2s;
}
.topbar-name { font-size: 14.5px; font-weight: 700; }
.topbar-desc { font-size: 11.5px; color: var(--text-3); margin-top: -2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.mode-badge {
  font-size: 11px; font-weight: 600; padding: 5px 11px; border-radius: 20px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap;
}
.mode-badge.live { background: #eaf8f1; color: #1e9c62; border-color: #c8ecd9; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  color: var(--text-2); font-size: 16px; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.menu-btn { display: none; }

.chat-scroll { position: relative; z-index: 1; flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.chat-scroll::-webkit-scrollbar { width: 8px; }
.chat-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid var(--bg); }

/* 欢迎页 */
.welcome { max-width: 760px; margin: 0 auto; padding: 62px 28px 30px; text-align: center; }
.welcome-badge {
  display: inline-block; font-size: 11.5px; font-weight: 650; letter-spacing: .4px;
  color: var(--primary); background: var(--primary-soft); border: 1px solid #dedef8;
  padding: 6px 14px; border-radius: 20px; margin-bottom: 20px;
}
.welcome h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.3; margin: 0 0 12px; letter-spacing: -.5px; font-weight: 750; }
.welcome h1 em { font-style: normal; color: var(--primary); }
.welcome-lead { color: var(--text-2); font-size: 14px; margin: 0 auto 30px; max-width: 480px; }
.try-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; text-align: left; }
.try-card {
  border: 1px solid var(--border); background: var(--surface); border-radius: 14px;
  padding: 14px 16px; box-shadow: var(--shadow-sm); transition: transform .16s, box-shadow .16s, border-color .16s;
  display: flex; align-items: flex-start; gap: 10px;
}
.try-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }
.try-card .t-emoji { font-size: 17px; }
.try-card .t-text { font-size: 13px; color: var(--text-2); line-height: 1.5; }
.try-card:hover .t-text { color: var(--text); }
.welcome-tip { margin-top: 24px; font-size: 12px; color: var(--text-3); }

/* 消息 */
.messages { max-width: 800px; margin: 0 auto; padding: 26px 28px 36px; display: flex; flex-direction: column; gap: 20px; }
.msg { display: flex; gap: 11px; animation: fadeUp .32s ease both; }
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 11px; flex: none; display: grid; place-items: center;
  font-size: 17px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.msg.user .msg-avatar { background: linear-gradient(135deg, #6d6dea, #4b49c4); border: none; color: #fff; font-size: 13px; font-weight: 700; }
.msg-body { max-width: min(78%, 620px); min-width: 0; }
.msg-meta { font-size: 11px; color: var(--text-3); margin-bottom: 5px; display: flex; gap: 8px; align-items: center; }
.msg.user .msg-meta { justify-content: flex-end; }
.msg-meta .m-style { color: var(--accent); font-weight: 600; }
.bubble {
  padding: 13px 16px; border-radius: 4px 16px 16px 16px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.75; color: var(--text);
  border-left: 3px solid var(--accent);
}
.msg.user .bubble {
  background: linear-gradient(135deg, #6262df, #4e4dc7); color: #fff; border: none;
  border-radius: 16px 4px 16px 16px; box-shadow: 0 8px 20px rgba(91, 91, 214, .22);
}
.msg.user .bubble a { color: #fff; }
.bubble.error { border-left-color: #e06a67; color: #b04745; background: #fff7f7; }
.msg-actions { display: flex; gap: 6px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button { font-size: 11px; color: var(--text-3); padding: 2px 7px; border-radius: 6px; }
.msg-actions button:hover { background: var(--surface-2); color: var(--text); }

.typing { display: flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .45; animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* 输入区 */
.composer-wrap { position: relative; z-index: 2; flex: none; padding: 12px 28px 14px; background: linear-gradient(to top, var(--bg) 72%, transparent); }
.composer {
  max-width: 800px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 16px; box-shadow: var(--shadow); padding: 12px 12px 9px;
  transition: border-color .18s, box-shadow .18s;
}
.composer:focus-within { border-color: var(--primary); box-shadow: 0 10px 30px rgba(91, 91, 214, .16); }
.composer textarea {
  width: 100%; border: none; outline: none; resize: none; background: transparent;
  font-size: 14px; line-height: 1.65; max-height: 160px; padding: 2px 4px;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.composer-hint { font-size: 11.5px; color: var(--text-3); padding-left: 4px; }
.composer-hint b { color: var(--accent); font-weight: 650; }
.send-btn {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary); color: #fff; transition: transform .15s, background .15s, opacity .15s;
}
.send-btn:hover:not(:disabled) { background: var(--primary-dark); transform: translateY(-1px); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.footnote { text-align: center; font-size: 10.5px; color: var(--text-3); margin-top: 8px; }

/* ---------- 设置抽屉 ---------- */
.drawer-mask { position: fixed; inset: 0; background: rgba(24, 28, 50, .32); opacity: 0; pointer-events: none; transition: opacity .22s; z-index: 40; }
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 92vw); z-index: 41;
  background: var(--surface); box-shadow: var(--shadow-lg); transform: translateX(102%);
  transition: transform .26s cubic-bezier(.22,.8,.3,1); display: flex; flex-direction: column;
}
.drawer.show { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.drawer-body { flex: 1; overflow-y: auto; padding: 8px 22px 28px; }
.cfg-section { padding: 20px 0; border-bottom: 1px solid var(--border); }
.cfg-section h3 { margin: 0 0 12px; font-size: 13px; font-weight: 700; }
.radio-list { display: flex; flex-direction: column; gap: 8px; }
.radio-row {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 11px; cursor: pointer; background: var(--surface-2);
}
.radio-row:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio-row input { margin-top: 3px; accent-color: var(--primary); }
.radio-row b { display: block; font-size: 12.5px; font-weight: 650; }
.radio-row small { display: block; font-size: 11px; color: var(--text-3); margin-top: 2px; }
.field { display: block; margin-bottom: 12px; font-size: 11.5px; font-weight: 600; color: var(--text-2); }
.field input {
  display: block; width: 100%; margin-top: 6px; padding: 9px 11px; border: 1px solid var(--border-strong);
  border-radius: 9px; background: var(--surface-2); font-size: 12.5px; font-weight: 400;
}
.field input:focus { border-color: var(--primary); outline: none; background: #fff; }
.help { font-size: 11px; color: var(--text-3); line-height: 1.65; margin: 10px 0 0; }
.help code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 4px; border-radius: 4px; font-size: 10.5px; }
.drawer-actions { display: flex; gap: 9px; margin-top: 22px; }
.btn-primary { flex: 1; padding: 11px; border-radius: 10px; background: var(--primary); color: #fff; font-weight: 650; font-size: 13px; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { padding: 11px 16px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 13px; border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); }
.drawer-meta { margin-top: 16px; font-size: 10.5px; color: var(--text-3); line-height: 1.7; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 14px); z-index: 60;
  background: #242842; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 12.5px;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(300px, 86vw);
    transform: translateX(-102%); transition: transform .25s cubic-bezier(.22,.8,.3,1); box-shadow: var(--shadow-lg);
  }
  .sidebar.show { transform: none; }
  .menu-btn { display: grid; }
  .topbar { padding: 0 16px; height: 62px; }
  .chat-scroll { padding-bottom: 0; }
  .welcome { padding: 40px 18px 24px; }
  .messages { padding: 20px 16px 30px; }
  .composer-wrap { padding: 10px 14px 12px; }
}
@media (max-width: 560px) {
  .try-grid { grid-template-columns: 1fr; }
  .welcome h1 { font-size: 27px; }
  .msg-body { max-width: 86%; }
  .mode-badge { display: none; }
}
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(24,28,50,.3); z-index: 19; opacity: 0; pointer-events: none; transition: opacity .2s; }
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
