:root {
  --bg: #0e1014;
  --panel: #151920;
  --panel-2: #1b202a;
  --line: #262c37;
  --line-soft: #1f242d;
  --text: #e7eaf0;
  --muted: #8a93a6;
  --accent: #6c7bff;
  --accent-dim: #4d5ad6;
  --danger: #e2564f;
  --ok: #3fb27f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

/* hidden 属性要压过组件自己的 display —— 否则 .composer-tools{display:flex}
   会把 [hidden] 顶掉，管理员专用的按钮就漏给别人看了 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

/* ---------- 通用控件 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: #232a36; border-color: #333c4a; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #3a2528; }
.btn.danger:hover { background: #2a1a1c; }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

input, textarea, select {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.6; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

/* 常用服务商快捷填入 */
.presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.presets-label { font-size: 12px; color: var(--muted); }
.chip {
  padding: 5px 11px;
  font-size: 12.5px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip:active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- 登录页 ---------- */

.auth-wrap {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.auth-logo { font-size: 26px; margin-bottom: 4px; }
.auth-title { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.auth-sub { font-size: 13px; color: var(--muted); margin: 0 0 22px; }
.auth-tabs {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}
.auth-tabs button {
  flex: 1;
  padding: 7px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 7px;
  font-size: 14px;
  cursor: pointer;
}
.auth-tabs button.on { background: var(--panel-2); color: var(--text); }
.auth-msg { font-size: 13px; margin-top: 14px; min-height: 18px; }
.auth-msg.err { color: var(--danger); }
.auth-msg.ok { color: var(--ok); }

/* ---------- 主界面 ---------- */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* 移动端浏览器地址栏收起/展开时不留白 */
  overflow: hidden;
}

/* iPhone 刘海与底部条避让 */
@supports (padding: env(safe-area-inset-bottom)) {
  .composer { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .sb-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .sidebar { padding-top: env(safe-area-inset-top); }
  .admin-wrap { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
}

.sidebar {
  width: 270px;
  flex: 0 0 270px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.sb-head {
  padding: 16px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sb-brand { font-size: 16px; font-weight: 600; }
.sb-section {
  padding: 12px 12px 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .04em;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sb-scroll { flex: 1; overflow-y: auto; padding-bottom: 12px; }

.char-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  margin: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.char-item:hover { background: var(--panel-2); }
.char-avatar {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  border-radius: 10px;
  background: var(--panel-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.char-meta { min-width: 0; }
.char-name { font-size: 14px; font-weight: 500; }
.char-tag { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sess-item {
  padding: 9px 12px;
  margin: 2px 8px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sess-item:hover { background: var(--panel-2); }
.sess-item.active { background: var(--panel-2); border: 1px solid #2f3a4d; }
.sess-title { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess-time { flex: 0 0 auto; font-size: 11px; color: var(--muted); }
.sess-del {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 15px; opacity: 0; padding: 2px 4px;
}
.sess-item:hover .sess-del { opacity: 1; }
.sess-del:hover { color: var(--danger); }

.sb-foot {
  border-top: 1px solid var(--line-soft);
  padding: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.sb-user { flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 聊天区 ---------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-head {
  height: 56px;
  flex: 0 0 56px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px 0 8px;
  background: rgba(21, 25, 32, .8);
  backdrop-filter: blur(8px);
  position: relative;
  z-index: 40;
}
.chat-head .char-avatar { width: 32px; height: 32px; flex-basis: 32px; font-size: 16px; border-radius: 10px; }
.head-meta { min-width: 0; flex: 1 1 auto; }
.chat-title { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 2px; }

/* 顶栏上的方形图标按钮：返回 / 新对话 / 更多 */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  flex: 0 0 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.on { background: var(--panel-2); color: var(--text); }
.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.back { margin-right: 2px; }
.icon-btn.back svg { width: 20px; height: 20px; stroke-width: 2.1; }

/* ---------- 右上角「更多」菜单 ---------- */
.head-menu-wrap { position: relative; flex: 0 0 auto; }
.head-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 70;
  width: 232px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .55);
  animation: mmIn .14s ease-out;
}
.hm-title {
  padding: 6px 10px 7px;
  font-size: 11.5px;
  letter-spacing: .04em;
  color: var(--muted);
  text-transform: uppercase;
}
.hm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.hm-item:hover { background: var(--panel-2); }
.hm-item svg {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .8;
}
.hm-item.danger { color: #e9736c; }
.hm-item.danger:hover { background: rgba(226, 86, 79, .12); }
.hm-sep { height: 1px; margin: 5px 6px; background: var(--line-soft); }

/* ---------- 模型切换（现在挂在输入框上方那一条里） ---------- */
.model-switch {
  flex: 0 0 auto;
  position: relative;
  min-width: 0;
}

.model-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 210px;
  padding: 5px 9px 5px 11px;
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.model-btn:hover:not(:disabled) { border-color: var(--accent); }
.model-btn:disabled { opacity: .45; cursor: not-allowed; }

.mb-name {
  min-width: 0;
  max-width: 132px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 价格做成小药丸，扫一眼就能比 */
.mb-price {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  flex: 0 0 auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(108, 123, 255, .16);
  color: #aeb6ff;
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.mb-price b { font-size: 9px; font-weight: 400; opacity: .85; }
.mb-price em { font-style: normal; }

/* 用纯三角画箭头，比旋转边框可靠——不会因为渲染差异变成朝上 */
.mb-caret {
  flex: 0 0 auto;
  width: 0;
  height: 0;
  margin-left: 1px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  transition: transform .18s;
}
.model-switch.open .mb-caret { transform: rotate(180deg); }

/* 展开的价目表 */
.model-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 60;
  width: 308px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .55);
  animation: mmIn .14s ease-out;
}
/* 在输入框上方展开，就得朝上开，否则会钻出屏幕底部 */
.model-menu.up { top: auto; bottom: calc(100% + 10px); }

@keyframes mmIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.mm-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px 8px;
  font-size: 12px;
  color: var(--muted);
}
.mm-head > span:first-child { color: var(--text); font-weight: 600; font-size: 12.5px; }
.mm-hint { font-size: 11px; opacity: .8; }

.mm-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 322px;
  overflow-y: auto;
}

.mm-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 9px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.mm-item:hover { background: var(--panel-2); }
.mm-item.on { background: rgba(108, 123, 255, .12); border-color: rgba(108, 123, 255, .35); }
.mm-item.poor .mm-name { opacity: .5; }

.mm-radio {
  flex: 0 0 auto;
  position: relative;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
}
.mm-item.on .mm-radio { border-color: var(--accent); }
.mm-item.on .mm-radio::after {
  content: '';
  position: absolute;
  inset: 2.5px;
  border-radius: 50%;
  background: var(--accent);
}

.mm-main { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; }
.mm-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}
.mm-tag {
  flex: 0 0 auto;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 10.5px;
  line-height: 1.5;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line-soft);
}
.mm-tag.econ   { color: #6fd3a4; border-color: rgba(63, 178, 127, .3);  background: rgba(63, 178, 127, .1); }
.mm-tag.best   { color: #aeb6ff; border-color: rgba(108, 123, 255, .35); background: rgba(108, 123, 255, .14); }
.mm-tag.strong { color: #f0b35e; border-color: rgba(240, 179, 94, .3);  background: rgba(240, 179, 94, .1); }
.mm-tag.max    { color: #e88a5e; border-color: rgba(232, 138, 94, .3);  background: rgba(232, 138, 94, .1); }
.mm-tag.image  { color: #c58cf0; border-color: rgba(197, 140, 240, .3); background: rgba(197, 140, 240, .1); }

.mm-price {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 2px;
  min-width: 46px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 13px;
  color: #aeb6ff;
}
.mm-price b { font-size: 9px; font-weight: 400; opacity: .8; }
.mm-price em { font-style: normal; }

.mm-foot {
  margin-top: 6px;
  padding: 7px 9px 3px;
  border-top: 1px solid var(--line-soft);
  font-size: 11.5px;
  color: var(--muted);
}

@media (max-width: 480px) {
  .chat-head { padding: 0 8px 0 4px; gap: 8px; }
  .icon-btn { width: 32px; height: 32px; flex-basis: 32px; }
  .model-btn { max-width: 152px; font-size: 12px; padding: 4px 8px 4px 10px; }
  .mb-name { max-width: 62px; }
  .model-menu { width: min(308px, calc(100vw - 28px)); right: 0; }
  .head-menu { width: min(232px, calc(100vw - 20px)); }
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 10px;
}
/* 一行一组：左边头像，右边内容。AI 的气泡占满整行，用户的气泡靠右收窄 */
.msg-row {
  max-width: 820px;
  margin: 0 auto 22px;
  display: flex;
  gap: 11px;
  align-items: flex-start;
}
.msg-row.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px; flex: 0 0 32px;
  margin-top: 2px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  overflow: hidden;
}
.msg-avatar.ai { background: linear-gradient(160deg, #2a3155, #1b202a); }
.msg-avatar.me {
  background: rgba(108, 123, 255, .16);
  border-color: rgba(108, 123, 255, .3);
  color: #aeb6ff;
  font-size: 13px;
  font-weight: 600;
}
.msg-body { min-width: 0; max-width: 100%; flex: 1 1 auto; }
.msg-row.user .msg-body { flex: 0 1 auto; max-width: 78%; }

/* AI 消息头顶那行：AI 标签 + 角色名 + 悬停出现的复制 */
.msg-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 2px 6px;
  min-height: 20px;
}
.msg-tag {
  flex: 0 0 auto;
  padding: 0 6px;
  border-radius: 5px;
  background: rgba(108, 123, 255, .16);
  border: 1px solid rgba(108, 123, 255, .3);
  color: #aeb6ff;
  font-size: 10px;
  font-weight: 600;
  line-height: 16px;
}
.msg-name {
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 气泡下面那排小按钮：复制、重新生成。平时压暗，鼠标进到这一条才亮起来 */
.msg-acts {
  display: flex;
  gap: 4px;
  margin: 7px 0 0 0;
  opacity: .62;
  transition: opacity .15s;
}
.msg-row:hover .msg-acts,
.msg-acts:focus-within { opacity: 1; }
.msg-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.msg-act:hover { background: var(--panel-2); color: var(--text); }
.msg-act svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.bubble {
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.user .bubble {
  background: #2a3155;
  border-color: #343d68;
  padding: 10px 15px;
}
.bubble em { color: #9aa6c4; font-style: italic; }
.bubble .cursor {
  display: inline-block; width: 7px; height: 15px;
  background: var(--accent); vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.empty-state {
  height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); gap: 8px; text-align: center;
}
.empty-state .big { font-size: 34px; }

.composer {
  border-top: 1px solid var(--line-soft);
  padding: 10px 20px 14px;
  background: var(--panel);
}
/* 输入框上方那条：左 chips、右模型价目 + 余额 */
.composer-bar {
  max-width: 820px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
}
.composer-side { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.wallet-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: #aeb6ff;
  font-variant-numeric: tabular-nums;
}
.wallet-chip b { font-size: 10px; }
.wallet-chip em { font-style: normal; font-weight: 600; }

.composer-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  min-height: 46px;
  max-height: 200px;
  padding: 12px 15px;
  border-radius: 14px;
  background: var(--panel-2);
  resize: none;
}
.composer .btn { height: 46px; }

/* 圆形发送键 */
.send-btn {
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-dim); border-color: var(--accent-dim); }
.send-btn:active:not(:disabled) { transform: scale(.94); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.send-btn svg {
  width: 21px; height: 21px;
  fill: none; stroke: currentColor;
  stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round;
}
.composer-tip {
  max-width: 820px; margin: 8px auto 0;
  font-size: 12px; color: var(--muted);
  display: flex; justify-content: space-between;
}

/* ---------- 提示词 / 世界书面板（对话页输入框上方，仅管理员） ---------- */

.composer-tools {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.tool-chip {
  padding: 5px 13px;
  font-size: 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.tool-chip:hover { border-color: var(--accent); color: var(--accent); }
.tool-chip.on { border-color: var(--accent); color: var(--accent); background: rgba(108, 123, 255, .12); }

.composer-panel {
  max-width: 820px; margin: 0 auto 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
}
.cp-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px;
}
.cp-head > span { font-size: 14px; font-weight: 600; color: var(--text); }
.cp-body { max-height: 46vh; overflow-y: auto; padding-right: 2px; }
.cp-hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.6; }
.cp-hint code, .cp-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  background: var(--bg);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: 1px 5px;
}
.cp-actions { display: flex; gap: 10px; margin-top: 14px; }
.cp-regex-actions { margin-top: 8px; }
.cp-import {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding-bottom: 10px; margin-bottom: 2px;
  border-bottom: 1px solid var(--line-soft);
}
.cp-import-hint { font-size: 12px; color: var(--muted); }
/* 面板里的输入框别被 .composer textarea 的「输入条」样式带偏 */
.composer-panel textarea {
  flex: none;
  min-height: 0;
  max-height: none;
  resize: vertical;
  background: var(--bg);
}

/* ---------- 管理后台 ---------- */

.admin-wrap { max-width: 980px; margin: 0 auto; padding: 28px 20px 60px; }
.admin-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.admin-head h1 { font-size: 20px; margin: 0; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 22px; }
.tabs button {
  padding: 9px 14px; border: 0; background: transparent;
  color: var(--muted); font-size: 14px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 4px; }
.card .sub { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.actions { display: flex; gap: 10px; margin-top: 18px; }

.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line-soft);
}
.list-item:last-child { border-bottom: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 14px; }
.list-sub { font-size: 12px; color: var(--muted); }
.tag {
  font-size: 11px; padding: 2px 7px; border-radius: 6px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.tag.ok { color: var(--ok); border-color: #1e3a2e; background: #14251d; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(20px);
  background: #232a36; border: 1px solid var(--line);
  color: var(--text); padding: 10px 18px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 99;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: #4a2b2e; color: #ffb4ae; }

/* ---------- 移动端 ---------- */

.menu-btn { display: none; }
.sb-close { display: none; }
.sb-head-actions { display: flex; gap: 6px; align-items: center; }
.sb-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 45;
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    width: 82%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; }
  .sb-close { display: inline-flex; }
  .sb-mask.show { display: block; }
  .messages { padding: 16px 14px 8px; }
  .msg-row.user .msg-body { max-width: 88%; }
  .msg-acts { opacity: 1; }   /* 手机上没 hover，复制按钮常驻 */
  .composer { padding: 8px 14px 12px; }
  .row { flex-direction: column; }
}

/* ---------- 导入酒馆角色卡（后台） ---------- */

.import-box { margin: 4px 0 16px; }
.import-box .btn {
  width: 100%;
  padding: 11px;
  border: 1px dashed var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13.5px;
  border-radius: var(--radius);
}
.import-box .btn:active { background: var(--panel); }
.import-hint {
  margin: 10px 2px 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--ok);
}
.import-hint.warn { color: #d9a441; }

/* ---------- 后台：按次定价表 ---------- */
.price-table {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.pt-head,
.pt-row {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) 96px 74px 84px 66px;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}
.pt-head {
  font-size: 11.5px;
  color: var(--muted);
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.pt-row { border-bottom: 1px solid var(--line-soft); }
.pt-row:last-child { border-bottom: 0; }
.pt-row:hover { background: rgba(255, 255, 255, .015); }

.pt-model {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.pt-cost { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pt-costd { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.pt-price {
  width: 100%;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
}
.pt-price:focus { outline: none; border-color: var(--accent); }

.pt-margin {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--muted);
}
.pt-margin.ok { color: var(--ok); }
.pt-margin.warn { color: #d9a441; }
.pt-margin.bad { color: var(--danger); }

.pt-empty { padding: 16px 12px; font-size: 12.5px; color: var(--muted); }

@media (max-width: 560px) {
  .pt-head { display: none; }
  .pt-row {
    grid-template-columns: minmax(0, 1fr) 76px 58px;
    grid-template-areas:
      "model model model"
      "cost d price"
      "mg mg mg";
    row-gap: 6px;
    padding: 10px 12px;
  }
  .pt-model { grid-area: model; }
  .pt-cost { grid-area: cost; }
  .pt-costd { grid-area: d; }
  .pt-price { grid-area: price; }
  .pt-margin { grid-area: mg; text-align: left; }
}

/* ---------- 后台：数据看板 ---------- */
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; }
.card-sub { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* KPI 卡片：3 列 × 2 行，比 auto-fit 挤成 5+1 整齐 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-val {
  margin-top: 6px;
  font-size: 23px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpi-sub {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--muted);
  opacity: .85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 柱状图：SVG 自己画，宽度撑满、高度按比例 */
.chart { width: 100%; }
.chart-svg { display: block; width: 100%; height: auto; }
.chart-svg rect { transition: opacity .12s; }
.chart-svg rect:hover { opacity: .72; }

/* 横向条形 */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label {
  flex: 0 0 132px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.bar-track {
  flex: 1 1 auto;
  height: 7px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4d5ad6, #6c7bff);
}
.bar-val {
  flex: 0 0 auto;
  min-width: 30px;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* 数据表 */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.data-table th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, .02); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .muted { color: var(--muted); }
.data-table .plus { color: var(--ok); }
.data-table .minus { color: var(--danger); }
.data-table .ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 11px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line-soft);
}
.tag.admin { color: #aeb6ff; border-color: rgba(108, 123, 255, .35); background: rgba(108, 123, 255, .14); }

.empty-line {
  padding: 22px 10px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}

/* 存储占用 */
.storage-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.storage-item {
  flex: 1 1 150px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: var(--radius-sm);
}
.storage-item span { font-size: 11.5px; color: var(--muted); }
.storage-item b { font-size: 14px; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-val { font-size: 20px; }
  .bar-label { flex-basis: 92px; }
  .data-table .ellipsis { max-width: 120px; }
}

/* 两张表列数不同，用固定列宽免得「用户名」那列吃掉半个屏幕 */
.data-table.t-users { table-layout: fixed; }
.data-table.t-users th:nth-child(1) { width: 26%; }
.data-table.t-users th:nth-child(2) { width: 13%; }
.data-table.t-users th:nth-child(3) { width: 12%; }
.data-table.t-users th:nth-child(4) { width: 10%; }
.data-table.t-users th:nth-child(5) { width: 10%; }
.data-table.t-users th:nth-child(6) { width: 15%; }
.data-table.t-users th:nth-child(7) { width: 14%; }

.data-table.t-ledger { table-layout: fixed; }
.data-table.t-ledger th:nth-child(1) { width: 15%; }
.data-table.t-ledger th:nth-child(2) { width: 20%; }
.data-table.t-ledger th:nth-child(3) { width: 18%; }
.data-table.t-ledger th:nth-child(4) { width: 31%; }
.data-table.t-ledger th:nth-child(5) { width: 16%; }
