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

:root {
  --bg: #0f1117;
  --bg-2: #171a23;
  --bg-3: #1e2230;
  --border: #2a2f42;
  --text: #e8eaf0;
  --text-2: #9aa1b5;
  --accent: #6c8cff;
  --accent-2: #8b5cf6;
  --danger: #f87171;
  --ok: #34d399;
}

/* ===== 浅色主题 ===== */
:root[data-theme="light"] {
  --bg: #f4f5fa;
  --bg-2: #ffffff;
  --bg-3: #eceef5;
  --border: #dde1ec;
  --text: #1b1f2e;
  --text-2: #5d6478;
  --accent: #4f6ef7;
  --accent-2: #7c5cf0;
  --danger: #e5484d;
  --ok: #12a577;
}

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app { display: flex; height: 100vh; }

/* ===== 侧边栏 ===== */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 700;
}
.brand .logo { font-size: 24px; }
.brand-logo { height: 30px; width: auto; border-radius: 8px; object-fit: contain; }

.btn {
  border: none; border-radius: 10px;
  padding: 10px 14px; font-size: 14px;
  cursor: pointer; transition: all .15s;
  font-family: inherit;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.15); }
.btn.ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn.ghost:hover { color: var(--text); border-color: var(--text-2); }

.new-chat { width: 100%; }

.section { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.skills-section { flex: 1; overflow-y: auto; }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--text-2); font-weight: 600;
  letter-spacing: .5px;
}

.mini-btn {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; width: 24px; height: 24px; cursor: pointer; font-size: 14px;
  line-height: 1;
}
.mini-btn:hover { color: var(--accent); border-color: var(--accent); }

.hint { font-size: 11px; color: var(--text-2); opacity: .7; }

.conv-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; max-height: 34vh; }

.conv-item {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; border-radius: 9px;
  cursor: pointer; font-size: 13.5px;
  color: var(--text-2); border: 1px solid transparent;
  transition: all .12s;
}
.conv-item:hover { background: var(--bg-3); color: var(--text); }
.conv-item.active { background: var(--bg-3); color: var(--text); border-color: var(--accent); }
.conv-item .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .conv-del {
  visibility: hidden; background: none; border: none; color: var(--danger);
  cursor: pointer; font-size: 14px; padding: 2px 4px; border-radius: 4px;
}
.conv-item:hover .conv-del { visibility: visible; }
.conv-item .conv-del:hover { background: rgba(248,113,113,.15); }

.empty-tip { font-size: 12px; color: var(--text-2); opacity: .6; padding: 6px 2px; }

.skill-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }

.skill-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 9px; background: var(--bg-3);
  border: 1px solid var(--border);
}
.skill-item .skill-info { flex: 1; min-width: 0; }
.skill-item .skill-name { font-size: 13px; font-weight: 600; }
.skill-item .skill-desc {
  font-size: 11px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.skill-item input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
.skill-item .skill-del {
  background: none; border: none; color: var(--text-2); cursor: pointer; font-size: 13px;
  padding: 2px 5px; border-radius: 4px; visibility: hidden;
}
.skill-item:hover .skill-del { visibility: visible; }
.skill-item .skill-del:hover { color: var(--danger); background: rgba(248,113,113,.12); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; }
.sidebar-footer .btn { width: 100%; }

/* ===== 主区域 ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.chat-title { font-size: 15px; font-weight: 600; }
.model-picker {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 9px; padding: 4px 10px;
}
.model-picker label { font-size: 15px; }
.model-picker select {
  background: transparent; border: none; outline: none;
  color: var(--text); font-family: inherit; font-size: 13.5px;
  cursor: pointer; max-width: 180px;
}
.model-picker select option { background: var(--bg-3); color: var(--text); }
.user-area {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
}
.user-name {
  color: var(--text); background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 5px 12px; white-space: nowrap;
}
.user-area .btn.small {
  font-size: 12.5px; padding: 5px 10px; border-radius: 8px;
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border); cursor: pointer; font-family: inherit;
}
.user-area .btn.small:hover { color: var(--danger); border-color: var(--danger); }
.active-skills { display: flex; gap: 6px; flex-wrap: wrap; }
.skill-tag {
  font-size: 11px; background: rgba(108,140,255,.15); color: var(--accent);
  border: 1px solid rgba(108,140,255,.35);
  padding: 2px 8px; border-radius: 20px;
}

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

.welcome { text-align: center; margin: auto; color: var(--text-2); }
.welcome-icon { font-size: 56px; margin-bottom: 12px; }
.welcome h2 { color: var(--text); margin-bottom: 8px; font-size: 22px; }
.welcome p { font-size: 14px; }

.msg { display: flex; gap: 12px; max-width: 85%; animation: fadeIn .2s ease; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

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

.avatar {
  width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
  background: var(--bg-3); border: 1px solid var(--border);
}
.msg.user .avatar { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }

.bubble {
  padding: 12px 16px; border-radius: 14px; font-size: 14.5px; line-height: 1.75;
  background: var(--bg-3); border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-word; min-width: 60px;
}
.msg.user .bubble { background: linear-gradient(135deg, rgba(108,140,255,.25), rgba(139,92,246,.25)); border-color: rgba(108,140,255,.4); }

.bubble h2, .bubble h3, .bubble h4 { margin: 10px 0 6px; line-height: 1.4; }
.bubble h2 { font-size: 18px; } .bubble h3 { font-size: 16px; } .bubble h4 { font-size: 14.5px; }
.bubble ul { padding-left: 20px; margin: 6px 0; }
.bubble li { margin: 2px 0; }
.bubble code {
  background: rgba(0,0,0,.35); padding: 2px 6px; border-radius: 5px;
  font-family: Consolas, "Courier New", monospace; font-size: 13px;
}
.bubble pre {
  background: rgba(0,0,0,.45); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; margin: 8px 0; overflow-x: auto;
}
.bubble pre code { background: none; padding: 0; font-size: 13px; }
.bubble a { color: var(--accent); }
.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }

.typing-dots { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-2);
  animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ===== 输入区 ===== */
.composer-wrap { padding: 12px 24px 14px; background: var(--bg-2); border-top: 1px solid var(--border); }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 14px;
  padding: 10px 12px; transition: border-color .15s;
}
.composer:focus-within { border-color: var(--accent); }

.composer textarea {
  flex: 1; background: transparent; border: none; outline: none; resize: none;
  color: var(--text); font-family: inherit; font-size: 14.5px; line-height: 1.6;
  max-height: 180px;
}
.composer textarea::placeholder { color: var(--text-2); opacity: .6; }

.send { border-radius: 10px; padding: 9px 20px; }

.composer-tip { text-align: center; font-size: 11px; color: var(--text-2); opacity: .55; margin-top: 7px; }

/* ===== 弹窗 ===== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(3px);
}
.modal-mask.hidden { display: none; }

.modal {
  width: 440px; max-width: 92vw; max-height: 85vh; overflow-y: auto;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px;
}
.modal h3 { margin-bottom: 14px; font-size: 17px; }
.modal label { display: block; font-size: 12.5px; color: var(--text-2); margin: 12px 0 6px; font-weight: 600; }
.modal input, .modal textarea {
  width: 100%; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 9px; color: var(--text); font-family: inherit; font-size: 14px;
  padding: 9px 12px; outline: none;
}
.modal input:focus, .modal textarea:focus { border-color: var(--accent); }
.modal textarea { resize: vertical; }
.modal .tip { font-size: 12px; color: var(--text-2); margin-bottom: 6px; }

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

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--danger); color: var(--text);
  padding: 11px 20px; border-radius: 10px; font-size: 13.5px; z-index: 200;
  box-shadow: 0 8px 30px rgba(0,0,0,.4); max-width: 80vw;
}
.toast.hidden { display: none; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3a4160; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== 角色标签 ===== */
.admin-tag {
  background: rgba(108,140,255,.15); color: #9db4ff; border: 1px solid rgba(108,140,255,.4);
  padding: 1px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; margin-left: 4px;
}
#settingsBtn.hidden { display: none !important; }

/* ===== 主题切换按钮 ===== */
.btn.icon-only { padding: 8px 10px; font-size: 16px; line-height: 1; }

/* ===== VIP 徽章 ===== */
.vip-tag {
  background: linear-gradient(135deg, #f6c453, #e8a020);
  color: #5a3a00; border: none;
  padding: 1px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; margin-left: 4px;
}

/* ===== 配额提示 ===== */
.quota-hint { font-size: 11.5px; color: var(--text-2); margin-left: 6px; }
.quota-hint .warn { color: var(--danger); font-weight: 600; }

/* ===== 会员等级徽章 ===== */
.level-tag {
  padding: 1px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; margin-left: 5px;
  color: #fff; display: inline-block; vertical-align: middle;
}
.level-tag.gold { background: linear-gradient(135deg, #f6c453, #d97706); color: #3d2600; }
.level-tag.platinum { background: linear-gradient(135deg, #e2e8f0, #94a3b8); color: #1e293b; }
.level-tag.premium { background: linear-gradient(135deg, #a78bfa, #7c3aed); }


/* ===== 自定义等级徽章（聊天页） ===== */
.level-tag.custom { background: rgba(167,139,250,.16); color: #a78bfa; border: 1px solid rgba(167,139,250,.35); }


/* ===== 商城 ===== */
.shop-modal { max-width: 560px; max-height: 80vh; overflow-y: auto; }
.shop-goods h4 { margin: 14px 0 8px; font-size: 13.5px; color: var(--text-2); }
.goods-row { display: flex; gap: 10px; flex-wrap: wrap; }
.goods-card { flex: 1; min-width: 120px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: center; }
.goods-name { font-weight: 600; margin-bottom: 4px; }
.goods-price { color: var(--warn); font-size: 13px; margin-bottom: 8px; }
.goods-buy { display: flex; gap: 6px; justify-content: center; align-items: center; }
.goods-buy input { width: 64px; padding: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.shop-records { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 10px; }
.shop-records h4 { font-size: 13.5px; color: var(--text-2); margin-bottom: 8px; }
.rec-row { font-size: 12.5px; color: var(--text-2); padding: 3px 0; border-bottom: 1px dashed var(--border); }
.money-tag { color: var(--warn); font-weight: 600; font-size: 13px; white-space: nowrap; }


/* ===== 商城固定档位按钮（7天/1个月/1年） ===== */
.goods-buy { flex-wrap: wrap; }
.goods-buy .btn.small { display: flex; flex-direction: column; align-items: center; padding: 6px 10px; line-height: 1.25; }
.goods-buy .dur-price { font-size: 11px; opacity: .75; margin-top: 2px; }


/* ===== 激活码兑换 ===== */
.redeem-box { margin-top: 16px; padding: 14px; border: 1px dashed var(--border); border-radius: 12px; background: var(--bg-2); }
.redeem-box h4 { font-size: 14.5px; margin-bottom: 6px; }
.redeem-box .tip { font-size: 12.5px; color: var(--text-2); margin-bottom: 10px; }
.redeem-row { display: flex; gap: 10px; }
.redeem-row input { flex: 1; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 14px; font-family: Consolas, monospace; letter-spacing: .5px; outline: none; }
.redeem-row input:focus { border-color: var(--accent); }
