/* ================= 基础 ================= */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --sidebar: #171717;
  --sidebar-hover: #2a2a2a;
  --sidebar-text: #ececec;
  --sidebar-muted: #9a9a9a;
  --main-bg: #ffffff;
  --text: #0d0d0d;
  --text-muted: #6e6e80;
  --border: #e5e5e5;
  --user-bubble: #f4f4f4;
  --accent: #0d0d0d;
  --green: #10a37f;
  --danger: #d92d20;
  --radius: 14px;
  --font: "Söhne", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
html, body { height: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--main-bg); -webkit-font-smoothing: antialiased; }

/* ================= 登录页 ================= */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: #f7f7f8;
}
.login-card {
  width: 360px; max-width: 92vw; background: #fff;
  border: 1px solid var(--border); border-radius: 20px;
  padding: 40px 32px; text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,.06);
}
.login-logo { color: var(--green); display: flex; justify-content: center; margin-bottom: 14px; }
.login-card h1 { font-size: 22px; font-weight: 600; }
.login-sub { color: var(--text-muted); font-size: 14px; margin: 6px 0 24px; }
.login-input {
  width: 100%; padding: 13px 14px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 12px; font-size: 15px;
  outline: none; transition: border-color .15s;
}
.login-input:focus { border-color: var(--green); }
.login-btn {
  width: 100%; padding: 13px; background: var(--green); color: #fff;
  border: none; border-radius: 12px; font-size: 15px; font-weight: 500;
  cursor: pointer; transition: opacity .15s;
}
.login-btn:hover { opacity: .9; }
.login-error {
  background: #fef3f2; color: var(--danger); border: 1px solid #fecdca;
  border-radius: 10px; padding: 10px; font-size: 13px; margin-bottom: 16px;
}
.login-foot { color: var(--sidebar-muted); font-size: 12px; margin-top: 18px; }

/* ================= 布局 ================= */
.app { display: flex; height: 100vh; overflow: hidden; }

/* 侧边栏 */
.sidebar {
  width: 260px; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-top { padding: 12px; }
.new-chat {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 12px; background: transparent; color: var(--sidebar-text);
  border: 1px solid #3a3a3a; border-radius: 11px; cursor: pointer;
  font-size: 14px; font-family: var(--font); transition: background .12s;
}
.new-chat:hover { background: var(--sidebar-hover); }
.conv-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.conv-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 10px; border-radius: 9px; cursor: pointer; font-size: 14px;
  color: var(--sidebar-text); white-space: nowrap; overflow: hidden;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-hover); }
.conv-title { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.conv-del {
  opacity: 0; color: var(--sidebar-muted); background: none; border: none;
  cursor: pointer; font-size: 15px; padding: 2px 4px; flex-shrink: 0;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: #fff; }

.sidebar-bottom { padding: 10px 12px; border-top: 1px solid #2a2a2a; }
.side-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  color: var(--sidebar-text); text-decoration: none; border-radius: 9px;
  font-size: 14px;
}
.side-link:hover { background: var(--sidebar-hover); }
.side-user { color: var(--sidebar-muted); font-size: 12px; padding: 6px 10px; }

/* 主区 */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 52px; display: flex; align-items: center; gap: 10px;
  padding: 0 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.topbar .model-badge {
  font-size: 13px; color: var(--text-muted); font-weight: 500;
  padding: 4px 10px; background: #f4f4f4; border-radius: 8px;
}
.usage-mini { margin-left: auto; font-size: 12px; color: var(--text-muted); }

.messages { flex: 1; overflow-y: auto; }
.messages-inner { max-width: 760px; margin: 0 auto; padding: 24px 20px 40px; }

.empty-hero {
  height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; color: var(--text);
}
.empty-hero h2 { font-size: 26px; font-weight: 600; margin-bottom: 24px; }
.suggest-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  max-width: 620px; width: 100%;
}
.suggest {
  text-align: left; padding: 14px 16px; border: 1px solid var(--border);
  border-radius: 12px; background: #fff; cursor: pointer; font-size: 14px;
  color: var(--text); transition: background .12s;
}
.suggest:hover { background: #f7f7f8; }
.suggest .s-title { font-weight: 500; }
.suggest .s-sub { color: var(--text-muted); font-size: 13px; margin-top: 3px; }

/* 消息 */
.msg { display: flex; gap: 14px; padding: 18px 0; }
.msg .avatar {
  width: 30px; height: 30px; border-radius: 6px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: #fff;
}
.msg.user .avatar { background: #b4b4b4; }
.msg.assistant .avatar { background: var(--green); }
.msg .body { flex: 1; min-width: 0; padding-top: 3px; }
.msg .body .name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.msg .content {
  font-size: 15.5px; line-height: 1.7; color: var(--text);
  word-wrap: break-word; white-space: pre-wrap;
}
.msg .content img {
  max-width: 100%; border-radius: 12px; margin-top: 8px;
  border: 1px solid var(--border);
}
.msg .content pre {
  background: #0d0d0d; color: #e6e6e6; padding: 14px; border-radius: 10px;
  overflow-x: auto; margin: 10px 0; font-size: 13.5px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.msg .content code {
  background: #f0f0f0; padding: 2px 5px; border-radius: 4px;
  font-size: 13.5px; font-family: "SF Mono", Menlo, Consolas, monospace;
}
.msg .content pre code { background: none; padding: 0; }
.msg .content .md-h { font-weight: 600; margin: 14px 0 6px; line-height: 1.3; }
.msg .content h1.md-h { font-size: 20px; }
.msg .content h2.md-h { font-size: 18px; }
.msg .content h3.md-h { font-size: 16px; }
.msg .content h4.md-h, .msg .content h5.md-h, .msg .content h6.md-h { font-size: 15px; }
.msg .content .md-ul, .msg .content .md-ol { margin: 6px 0 6px 2px; padding-left: 22px; }
.msg .content .md-ul li, .msg .content .md-ol li { margin: 3px 0; }
.msg .content strong { font-weight: 600; }
.msg .content em { font-style: italic; }
.cursor-blink { display: inline-block; width: 8px; height: 16px; background: var(--text);
  vertical-align: text-bottom; animation: blink 1s steps(2) infinite; }
@keyframes blink { 0%,50%{opacity:1} 51%,100%{opacity:0} }

/* 思考中动画 */
.thinking { display: inline-flex; gap: 5px; align-items: center; padding: 5px 0; }
.thinking span {
  width: 7px; height: 7px; border-radius: 50%; background: #c4c4c4;
  animation: think-bounce 1.3s infinite ease-in-out both;
}
.thinking span:nth-child(1) { animation-delay: -0.24s; }
.thinking span:nth-child(2) { animation-delay: -0.12s; }
@keyframes think-bounce {
  0%, 70%, 100% { transform: translateY(0); opacity: .35; }
  35% { transform: translateY(-6px); opacity: 1; }
}

.img-loading { color: var(--text-muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.spinner {
  width: 15px; height: 15px; border: 2px solid #ddd; border-top-color: var(--green);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 输入区 */
.composer { padding: 12px 20px 20px; flex-shrink: 0; }
.composer-inner { max-width: 760px; margin: 0 auto; }
.mode-row { display: flex; gap: 8px; margin-bottom: 8px; }
.mode-btn {
  font-size: 13px; padding: 6px 14px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--border); background: #fff; color: var(--text-muted);
  font-family: var(--font); display: flex; align-items: center; gap: 6px;
}
.mode-btn.active { background: #0d0d0d; color: #fff; border-color: #0d0d0d; }
.input-box {
  display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border);
  border-radius: 24px; padding: 8px 8px 8px 18px; background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
}
.input-box textarea {
  flex: 1; border: none; outline: none; resize: none; font-size: 15.5px;
  font-family: var(--font); line-height: 1.5; max-height: 200px; padding: 6px 0;
  background: transparent;
}
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer;
  background: #0d0d0d; color: #fff; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; transition: opacity .15s;
}
.send-btn:disabled { background: #d4d4d4; cursor: not-allowed; }
.attach-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
  background: transparent; color: #6e6e80; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
.attach-btn:hover { background: #f0f0f0; color: #0d0d0d; }
#attachChip { max-width: 760px; margin: 0 auto 8px; }
#attachChip .chip {
  display: inline-flex; align-items: center; gap: 8px; background: #f4f4f4;
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 12px;
  font-size: 13px; color: var(--text);
}
#attachChip .chip.err { background: #fef3f2; color: var(--danger); border-color: #fecdca; }
#attachChip .chip button {
  background: none; border: none; cursor: pointer; color: #6e6e80; font-size: 13px;
}
.msg-actions { display: flex; gap: 6px; margin-top: 10px; }
.msg-actions button {
  font-size: 12px; padding: 4px 10px; border: 1px solid var(--border);
  background: #fff; border-radius: 7px; cursor: pointer; color: var(--text-muted);
  font-family: var(--font);
}
.msg-actions button:hover { background: #f7f7f8; color: var(--text); }
.dl-wrap { position: relative; display: inline-block; }
.dl-menu {
  display: none; position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 20;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.12); padding: 5px; min-width: 150px;
}
.dl-menu.open { display: block; }
.dl-menu button {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 8px 12px; border-radius: 7px; font-size: 13px; cursor: pointer; color: var(--text);
}
.dl-menu button:hover { background: #f4f4f4; }
.composer-hint { text-align: center; font-size: 11px; color: var(--sidebar-muted); margin-top: 8px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0d0d0d; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; z-index: 999; opacity: 0; transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* ================= 后台 ================= */
.admin-wrap { max-width: 1180px; margin: 0 auto; padding: 24px 24px 60px; }
.admin-top {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px;
}
.admin-top h1 { font-size: 22px; font-weight: 600; }
.admin-top a { color: var(--green); text-decoration: none; font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.card {
  background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 18px;
}
.card .label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.card .value { font-size: 24px; font-weight: 600; }
.card .value.green { color: var(--green); }
.card .value.danger { color: var(--danger); }
.card .sub { font-size: 12px; color: var(--sidebar-muted); margin-top: 4px; }

.pricing-note {
  background: #f7f7f8; border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; font-size: 13px; color: var(--text-muted); margin-bottom: 24px;
  line-height: 1.7;
}
.pricing-note b { color: var(--text); }

.section-title { font-size: 16px; font-weight: 600; margin: 24px 0 12px; display:flex; align-items:center; justify-content: space-between; }
.btn {
  padding: 8px 16px; border-radius: 9px; border: none; cursor: pointer;
  font-size: 14px; font-family: var(--font); background: var(--green); color: #fff;
}
.btn.ghost { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.danger { background: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 500;
  border-bottom: 1px solid var(--border); font-size: 13px; white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid #f0f0f0; }
tbody tr:hover { background: #fafafa; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 20px; }
.tag.on { background: #ecfdf3; color: #027a48; }
.tag.off { background: #fef3f2; color: var(--danger); }
.tag.admin { background: #eff4ff; color: #175cd3; }
.row-actions { display: flex; gap: 6px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); display: none;
  align-items: center; justify-content: center; z-index: 100;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px; padding: 26px; width: 420px; max-width: 92vw;
}
.modal h3 { font-size: 18px; margin-bottom: 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 9px; font-size: 14px; outline: none; font-family: var(--font);
}
.field input:focus { border-color: var(--green); }
.field.inline { display: flex; align-items: center; gap: 8px; }
.field.inline input { width: auto; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.mono { font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .sidebar { position: absolute; z-index: 50; height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .cards { grid-template-columns: 1fr 1fr; }
  .suggest-grid { grid-template-columns: 1fr; }
}
