/* ==========================================================================
   冠军三代 · 算力共享 —— 样式
   ========================================================================== */

:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --text: #1f2430;
  --text-2: #5b6270;
  --text-3: #8b93a3;
  --border: #e5e8ef;
  --border-2: #eef0f5;
  --accent: #5b5bd6;
  --accent-2: #7c6cf0;
  --accent-soft: #eeeefc;
  --user-bubble: #eef0ff;
  --sidebar: #141826;
  --sidebar-2: #1b2032;
  --sidebar-text: #e8eaf2;
  --sidebar-text-2: #9aa2b8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(20, 24, 38, .10);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
          "Noto Sans CJK SC", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --panel: #161a23;
    --panel-2: #1b202b;
    --text: #e6e8ee;
    --text-2: #a6adbd;
    --text-3: #737b8d;
    --border: #262c39;
    --border-2: #1f2531;
    --accent: #8b8bf5;
    --accent-2: #a78bfa;
    --accent-soft: #23233d;
    --user-bubble: #23264a;
    --sidebar: #0b0d13;
    --sidebar-2: #12151f;
    --sidebar-text: #e6e8ee;
    --sidebar-text-2: #8a92a6;
    --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(120, 128, 150, .28); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(120, 128, 150, .45); }
::-webkit-scrollbar-track { background: transparent; }

/* ============================ 登录页 ============================ */
.login-view {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(900px 600px at 15% 10%, rgba(124, 108, 240, .30), transparent 60%),
    radial-gradient(800px 600px at 85% 90%, rgba(56, 189, 248, .20), transparent 60%),
    linear-gradient(140deg, #141826 0%, #1d2338 55%, #10131d 100%);
}
.login-bg::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,.055) 1px, transparent 1px);
  background-size: 22px 22px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}
.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 380px;
  padding: 36px 32px 26px;
  border-radius: 24px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
  text-align: center;
}
@media (prefers-color-scheme: dark) {
  .login-card { background: rgba(22, 26, 35, .97); }
}
.login-logo {
  width: 58px; height: 58px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 18px;
  background: linear-gradient(135deg, #6366f1, #a855f7 55%, #ec4899);
  color: #fff; font-size: 27px; font-weight: 700;
  box-shadow: 0 10px 24px rgba(99, 102, 241, .40);
}
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: .5px; }
.login-sub { margin: 8px 0 26px; font-size: 12.5px; line-height: 1.7; color: var(--text-3); }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; margin-bottom: 6px; font-size: 12.5px; color: var(--text-2); }
.field input {
  width: 100%; height: 44px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel-2); color: var(--text);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .14); }
.btn-primary {
  width: 100%; height: 46px; margin-top: 6px;
  border-radius: 12px; color: #fff; font-size: 15px; font-weight: 600;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  box-shadow: 0 8px 20px rgba(99, 102, 241, .35);
  transition: transform .1s, box-shadow .15s, opacity .15s;
}
.btn-primary:hover { box-shadow: 0 10px 26px rgba(99, 102, 241, .45); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.login-error { min-height: 20px; margin-top: 10px; font-size: 12.5px; color: var(--danger); }
.login-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border-2);
  font-size: 12px; color: var(--text-3);
}

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

.sidebar {
  width: 286px; flex: 0 0 286px;
  display: flex; flex-direction: column;
  background: var(--sidebar); color: var(--sidebar-text);
  border-right: 1px solid rgba(255, 255, 255, .04);
  z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 18px 16px 14px;
}
.brand-logo {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; font-size: 19px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #6366f1, #a855f7 60%, #ec4899);
  box-shadow: 0 6px 16px rgba(99, 102, 241, .40);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15.5px; letter-spacing: .4px; }
.brand-text span { font-size: 11.5px; color: var(--sidebar-text-2); }
.sidebar-close { display: none; margin-left: auto; color: var(--sidebar-text-2); }

.new-chat {
  margin: 4px 14px 12px;
  height: 42px; border-radius: 12px;
  color: #fff; font-size: 14px; font-weight: 600;
  background: linear-gradient(135deg, rgba(99, 102, 241, .95), rgba(139, 92, 246, .95));
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  transition: filter .15s;
}
.new-chat:hover { filter: brightness(1.08); }

.side-section-title {
  padding: 6px 18px 8px;
  font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--sidebar-text-2);
}
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 10px; }
.conv-group-title { padding: 10px 10px 4px; font-size: 11px; color: var(--sidebar-text-2); }
.conv-item {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin: 1px 0;
  border-radius: 10px; cursor: pointer;
  color: var(--sidebar-text); font-size: 13.5px;
  transition: background .12s;
}
.conv-item:hover { background: rgba(255, 255, 255, .07); }
.conv-item.active { background: rgba(99, 102, 241, .26); }
.conv-item .conv-title {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-item .conv-del {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 6px;
  display: none; align-items: center; justify-content: center;
  color: var(--sidebar-text-2); font-size: 13px;
}
.conv-item:hover .conv-del { display: flex; }
.conv-item .conv-del:hover { background: rgba(239, 68, 68, .25); color: #fca5a5; }
.conv-empty { padding: 16px 12px; font-size: 12.5px; color: var(--sidebar-text-2); line-height: 1.7; }

.side-bottom { padding: 10px 12px 12px; border-top: 1px solid rgba(255, 255, 255, .06); }
.queue-card {
  padding: 11px 12px; border-radius: 13px;
  background: var(--sidebar-2);
  border: 1px solid rgba(255, 255, 255, .05);
}
.queue-head { display: flex; align-items: center; justify-content: space-between; }
.queue-title { font-size: 12px; font-weight: 600; letter-spacing: .5px; color: var(--sidebar-text); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.dot.busy { background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.dot.off { background: var(--danger); box-shadow: 0 0 0 3px rgba(239, 68, 68, .18); }
.queue-body { margin-top: 7px; font-size: 12px; line-height: 1.65; color: var(--sidebar-text-2); }
.queue-body b { color: var(--sidebar-text); font-weight: 600; }
.queue-body .q-line { display: flex; gap: 6px; align-items: center; }
.queue-body .q-pos {
  flex: 0 0 auto; width: 18px; height: 18px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10.5px; color: #c7d2fe; background: rgba(99, 102, 241, .28);
}
.queue-stats { margin-top: 8px; font-size: 11px; color: var(--sidebar-text-2); opacity: .85; }
.user-row { display: flex; align-items: center; gap: 8px; padding: 12px 4px 0; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 13px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  flex: 0 0 auto;
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.user-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.help-link {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--sidebar-text-2);
  border: 1px solid rgba(255, 255, 255, .16);
}
.help-link:hover { color: #fff; text-decoration: none; border-color: rgba(255,255,255,.4); }
.icon-btn {
  width: 30px; height: 30px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2); font-size: 15px;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: rgba(120, 128, 150, .12); color: var(--text); }
.user-row .icon-btn { color: var(--sidebar-text-2); }
.user-row .icon-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.mask { position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .45); }

/* ============================ 主区域 ============================ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px; min-height: 60px;
  border-bottom: 1px solid var(--border-2);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
}
.menu-btn { display: none; }
.model-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.model-name { font-size: 15px; font-weight: 650; white-space: nowrap; }
.model-badge {
  padding: 2px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .3px;
  color: var(--accent); background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  white-space: nowrap;
}
.model-status { font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.model-status.ok { color: #16a34a; }
.model-status.bad { color: var(--danger); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.effort-select {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px 5px 11px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel-2);
  font-size: 12px; color: var(--text-2);
}
.effort-select select {
  border: none; background: transparent; outline: none;
  font-size: 12.5px; color: var(--text); cursor: pointer;
}
.pill {
  padding: 4px 11px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  color: #92400e; background: #fef3c7;
  border: 1px solid #fde68a;
}
@media (prefers-color-scheme: dark) {
  .pill { color: #fcd34d; background: rgba(245, 158, 11, .16); border-color: rgba(245, 158, 11, .3); }
}

.messages {
  flex: 1; overflow-y: auto;
  padding: 26px max(22px, calc((100% - 860px) / 2)) 18px;
  scroll-behavior: smooth;
}

/* 欢迎屏 */
.welcome {
  max-width: 680px; margin: 8vh auto 0; text-align: center;
  animation: fadeUp .4s ease;
}
.welcome-logo {
  width: 72px; height: 72px; margin: 0 auto 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 22px; font-size: 34px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #6366f1, #a855f7 55%, #ec4899);
  box-shadow: 0 16px 40px rgba(99, 102, 241, .35);
}
.welcome h2 { margin: 0 0 10px; font-size: 24px; letter-spacing: .3px; }
.welcome p { margin: 0 auto 28px; max-width: 480px; font-size: 13.5px; line-height: 1.8; color: var(--text-2); }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suggestion {
  padding: 13px 15px; text-align: left; font-size: 13px; line-height: 1.5;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--panel-2); color: var(--text-2);
  transition: border-color .15s, transform .1s, background .15s;
}
.suggestion:hover { border-color: var(--accent); color: var(--text); transform: translateY(-1px); }
.suggestion b { display: block; margin-bottom: 3px; font-size: 13px; color: var(--text); font-weight: 600; }

/* 消息 */
.msg { display: flex; gap: 12px; margin-bottom: 24px; animation: fadeUp .22s ease; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: 76%;
  padding: 11px 16px; border-radius: 16px 16px 4px 16px;
  background: var(--user-bubble); color: var(--text);
  font-size: 14.5px; line-height: 1.75; white-space: pre-wrap; word-break: break-word;
}
.msg.assistant .avatar { margin-top: 2px; }
.msg.assistant .body { flex: 1; min-width: 0; max-width: 100%; }
.msg.assistant .md { font-size: 14.5px; line-height: 1.8; word-break: break-word; }
.msg .meta { margin-top: 8px; font-size: 11.5px; color: var(--text-3); display: flex; gap: 10px; flex-wrap: wrap; }
.msg .meta .err { color: var(--danger); }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 22px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-3);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
.stream-cursor {
  display: inline-block; width: 7px; height: 15px; margin-left: 2px;
  vertical-align: -2px; border-radius: 2px; background: var(--accent);
  animation: blink 1s infinite;
}

/* 思考过程 */
.reasoning { margin-bottom: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2); }
.reasoning summary {
  padding: 8px 12px; cursor: pointer; user-select: none;
  font-size: 12.5px; color: var(--text-2); list-style: none;
}
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning summary::before { content: "▸ "; }
.reasoning[open] summary::before { content: "▾ "; }
.reasoning .reasoning-text {
  max-height: 260px; overflow-y: auto;
  padding: 0 12px 10px; font-size: 12.5px; line-height: 1.75;
  color: var(--text-3); white-space: pre-wrap; word-break: break-word;
}

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; line-height: 1.4; font-weight: 650; }
.md h1 { font-size: 20px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; } .md h4 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md blockquote {
  margin: 0 0 10px; padding: 8px 14px;
  border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0;
  background: var(--panel-2); color: var(--text-2);
}
.md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.md a { color: var(--accent); }
.md code {
  padding: 1.5px 5px; border-radius: 5px;
  font-family: var(--mono); font-size: 12.8px;
  background: color-mix(in srgb, var(--accent) 9%, var(--panel-2));
  border: 1px solid var(--border-2);
}
.md .code-block {
  margin: 12px 0; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border); background: #0f1420;
}
.md .code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; background: #171e2e; color: #8b93a8;
  font-size: 11px; font-family: var(--mono); letter-spacing: .5px;
}
.md .copy-code {
  padding: 2px 9px; border-radius: 6px;
  font-size: 11px; color: #aab3c8; background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
}
.md .copy-code:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.md .code-block pre { margin: 0; padding: 13px 15px; overflow-x: auto; }
.md .code-block pre code {
  padding: 0; background: none; border: none; color: #dbe3f4;
  font-size: 12.8px; line-height: 1.65;
}
.md table { width: 100%; margin: 10px 0; border-collapse: collapse; font-size: 13px; }
.md th, .md td { padding: 7px 10px; border: 1px solid var(--border); text-align: left; }
.md th { background: var(--panel-2); font-weight: 600; }

/* 排队横幅 */
.queue-banner {
  margin: 0 max(22px, calc((100% - 860px) / 2)) 8px;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-radius: 12px;
  font-size: 12.5px; color: #92400e;
  background: #fffbeb; border: 1px solid #fde68a;
}
@media (prefers-color-scheme: dark) {
  .queue-banner { color: #fcd34d; background: rgba(245, 158, 11, .10); border-color: rgba(245, 158, 11, .25); }
}
.pulse {
  width: 9px; height: 9px; border-radius: 50%; background: var(--warn);
  animation: pulse 1.3s infinite;
  flex: 0 0 auto;
}

/* 输入区 */
.composer-wrap {
  padding: 10px max(22px, calc((100% - 860px) / 2)) 14px;
  border-top: 1px solid var(--border-2);
  background: var(--panel);
}
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--panel-2);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .12); }
.composer textarea {
  flex: 1; min-height: 26px; max-height: 200px;
  padding: 5px 0; border: none; outline: none; resize: none;
  background: transparent; font-size: 14.5px; line-height: 1.65;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.btn-send {
  height: 38px; padding: 0 17px; border-radius: 12px;
  color: #fff; font-size: 13.5px; font-weight: 600;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  box-shadow: 0 5px 14px rgba(99, 102, 241, .3);
  transition: opacity .15s, transform .1s;
}
.btn-send:hover { filter: brightness(1.06); }
.btn-send:active { transform: translateY(1px); }
.btn-send:disabled { opacity: .45; cursor: default; box-shadow: none; }
.btn-send .arrow { margin-left: 2px; }
.btn-stop {
  height: 38px; padding: 0 14px; border-radius: 12px;
  font-size: 13px; font-weight: 600;
  color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}
.btn-stop:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); }
.composer-hint {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 4px 0; font-size: 11px; color: var(--text-3);
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 30px; z-index: 90;
  transform: translateX(-50%);
  max-width: 80vw; padding: 10px 18px;
  border-radius: 12px; font-size: 13px; color: #fff;
  background: rgba(31, 36, 48, .94);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  animation: fadeUp .2s ease;
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, .45); }
  70% { box-shadow: 0 0 0 9px rgba(245, 158, 11, 0); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

/* ============================ 移动端 ============================ */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 60px rgba(0, 0, 0, .35);
    width: min(84vw, 300px);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 14px; }
  .model-status { display: none; }
  .messages { padding: 18px 14px 10px; }
  .queue-banner { margin: 0 14px 8px; }
  .composer-wrap { padding: 8px 12px 10px; }
  .composer-hint span:last-child { display: none; }
  .suggestions { grid-template-columns: 1fr; }
  .msg.user .bubble { max-width: 88%; }
}
