:root {
  --bg: #f5f6fb;
  --panel: #ffffff;
  --ink: #1f2430;
  --muted: #8a90a2;
  --line: #e7e9f2;
  --brand: #5b5bd6;
  --brand-dark: #4545b8;
  --brand-soft: #eef0ff;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --free: #16a34a;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(30, 35, 80, 0.06);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar { height: 60px; display: flex; align-items: center; padding: 0 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; gap: 32px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.brand:hover { text-decoration: none; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #7c7cf0, #4545b8); color: #fff; display: grid; place-items: center; font-size: 18px; }
.brand-name small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; letter-spacing: 1px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 14px; border-radius: 8px; color: #555b6e; font-size: 14px; }
.nav a:hover { background: var(--brand-soft); color: var(--brand-dark); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.user-area { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.balance-badge { background: var(--brand-soft); color: var(--brand-dark); padding: 5px 12px; border-radius: 20px; font-size: 13px; }
.balance-badge b { font-weight: 700; }
.username { color: var(--muted); }
.btn-link { color: var(--muted); font-size: 13px; }

main.with-topbar { padding: 24px; max-width: 1280px; margin: 0 auto; }
main { min-height: calc(100vh - 60px); }

/* Auth pages */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #6366f1, #8b5cf6); padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 36px 32px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.auth-card .brand-mini { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }

/* Forms */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: #555b6e; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; background: #fff; color: var(--ink); outline: none; transition: border .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; font-family: inherit; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border: none; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; transition: background .15s, transform .05s; }
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: #f0f1f7; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }

/* Cards / grid */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 16px; font-size: 17px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 24px; font-weight: 700; }
.stat .value.small { font-size: 18px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 600; background: #fafbff; }
.table tr:hover td { background: #fafbff; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.tag.free { background: #e7f8ee; color: var(--free); }
.tag.paid { background: #fff3e0; color: var(--warn); }
.tag.ok { background: #e7f8ee; color: var(--ok); }
.tag.pending { background: #fff3e0; color: var(--warn); }
.tag.disabled { background: #f0f1f5; color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }

/* Chat layout */
.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; height: calc(100vh - 108px); }
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; height: auto; } }
.sidebar { display: flex; flex-direction: column; gap: 14px; overflow-y: auto; padding-right: 4px; }
.model-list { display: flex; flex-direction: column; gap: 6px; }
.model-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: #fff; transition: all .15s; }
.model-item:hover { border-color: var(--brand); }
.model-item.active { border-color: var(--brand); background: var(--brand-soft); }
.model-item .m-name { font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; }
.model-item .m-meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.chat-main { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chat-header { padding: 12px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.chat-header .cur { font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; background: #fafbff; }
.msg { max-width: 80%; }
.msg .role { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg .bubble { padding: 12px 16px; border-radius: 14px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; }
.msg.assistant .bubble { background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.reasoning { background: #f6f7fb; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; font-size: 12px; color: var(--muted); margin-bottom: 8px; white-space: pre-wrap; max-height: 160px; overflow-y: auto; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 5px; }
.composer { padding: 14px 18px; border-top: 1px solid var(--line); background: #fff; }
.composer textarea { min-height: 60px; max-height: 200px; }
.composer-row { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.composer-row .spacer { flex: 1; }
.cursor::after { content: '▋'; animation: blink 1s infinite; color: var(--brand); }
@keyframes blink { 50% { opacity: 0; } }

/* toast */
.toast { position: fixed; top: 80px; right: 24px; background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 9px; font-size: 13px; opacity: 0; transform: translateY(-8px); transition: all .25s; z-index: 999; pointer-events: none; max-width: 320px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px; font-size: 13px; }
.key-reveal { background: #0f172a; color: #a5f3fc; padding: 10px 12px; border-radius: 8px; font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; }

/* ================= 创作台（新版） ================= */
.studio { max-width: 940px; margin: 0 auto; width: 100%; height: calc(100vh - 108px); display: flex; flex-direction: column; }
.studio-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 10px; }
.studio-title { font-weight: 700; font-size: 15px; }
.studio-messages { flex: 1; overflow-y: auto; padding: 6px 6px 18px; display: flex; flex-direction: column; gap: 18px; }
.studio-messages .empty { margin: auto; }

.composer-shell { padding: 6px 0 8px; }
.composer-box { background: #fff; border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 8px 30px rgba(30, 35, 80, .08); padding: 12px 14px 10px; }
.composer-box textarea { border: none; box-shadow: none; background: transparent; padding: 4px 6px; min-height: 52px; max-height: 220px; resize: none; font-size: 14px; line-height: 1.6; }
.composer-box textarea:focus { border: none; box-shadow: none; }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.composer-bar .spacer { flex: 1; }
.composer-hint { height: 16px; padding: 4px 10px; font-size: 12px; color: var(--muted); }

.icon-btn { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: #4b5266; display: grid; place-items: center; cursor: pointer; font-size: 16px; line-height: 1; flex: none; transition: background .15s; }
.icon-btn:hover { background: #f2f3f9; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line); background: #fff; color: #3d4356; font-size: 13px; cursor: pointer; max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s; }
.chip:hover { background: #f2f3f9; }
.chip .caret { color: var(--muted); font-size: 10px; }
#cur-model { overflow: hidden; text-overflow: ellipsis; }
.send-btn { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--brand); color: #fff; font-size: 18px; line-height: 1; cursor: pointer; display: grid; place-items: center; flex: none; transition: background .15s; }
.send-btn:hover { background: var(--brand-dark); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }

.picker { position: relative; }
.menu { position: absolute; bottom: 42px; left: 0; width: 340px; max-height: 380px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(20, 24, 60, .16); padding: 8px; display: none; z-index: 60; }
.menu.open { display: block; }
.menu.narrow { width: 210px; }
.menu.right { left: auto; right: 0; }
.menu-search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 13px; margin-bottom: 6px; }
.menu-list { max-height: 300px; overflow-y: auto; }
.menu-item { padding: 8px 10px; border-radius: 9px; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu-item:hover { background: var(--brand-soft); }
.menu-item.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.menu-item .mi-meta { color: var(--muted); font-size: 11px; font-weight: 400; }
.menu-item.model-opt { flex-direction: column; align-items: flex-start; gap: 2px; }
.menu-item.model-opt .mi-name { font-size: 13px; }
.params { width: 250px; }
.params label { display: block; font-size: 12px; color: #555b6e; margin: 8px 4px; }
.params input { width: 100%; margin-top: 4px; }
@media (max-width: 640px) {
  .menu { width: min(340px, 88vw); }
  .chip { max-width: 150px; }
  .studio { height: calc(100vh - 88px); }
}

/* 支付通道 / 快捷金额选中态 */
.ch.active, .quick.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 91, 255, .25);
}
.ch.active:hover, .quick.active:hover {
  background: var(--brand-dark);
  color: #fff;
}
