:root {
  --bg: #0f1115;
  --panel: #161922;
  --panel2: #1d212c;
  --border: #2a2f3c;
  --text: #e6e8ee;
  --muted: #8b92a5;
  --accent: #d97757;
  --accent2: #4d6bfe;
  --danger: #ef5b5b;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
button { font: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 600;
}
.primary:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--muted); padding: 0; text-decoration: underline; }
.icon { background: none; border: 0; color: var(--text); font-size: 20px; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); }
.error { color: var(--danger); min-height: 1.2em; font-size: 13.5px; }

/* auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.auth-card form { display: flex; flex-direction: column; gap: 10px; }
.tabs { display: flex; gap: 4px; background: var(--panel2); border-radius: 10px; padding: 4px; }
.tab { flex: 1; background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 8px; }
.tab.active { background: var(--border); color: var(--text); }

/* layout */
.app { display: flex; height: 100%; }
.sidebar {
  width: 270px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 12px;
}
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); cursor: pointer; font-size: 14px;
}
.chat-item:hover { background: var(--panel2); }
.chat-item.active { background: var(--border); }
.chat-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del { visibility: hidden; background: none; border: 0; color: var(--muted); }
.chat-item:hover .del { visibility: visible; }
.account { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.balance-row { display: flex; justify-content: space-between; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; }
#model-select { max-width: 260px; }

.messages { flex: 1; overflow-y: auto; padding: 24px 20px; }
.empty { max-width: 640px; margin: 12vh auto 0; text-align: center; }
.empty h1 { font-size: 28px; margin: 0 0 8px; }

.msg { max-width: 820px; margin: 0 auto 22px; }
.msg.user .bubble {
  background: var(--panel2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-left: auto; width: fit-content; max-width: 85%; white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.assistant .meta { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 10px; }
.msg.assistant .meta .model.claude { color: var(--accent); }
.msg.assistant .meta .model.deepseek { color: var(--accent2); }
.msg .body { word-wrap: break-word; }
.msg .body p { margin: 0 0 10px; }
.msg .body h1, .msg .body h2, .msg .body h3 { margin: 14px 0 8px; font-size: 1.1em; }
.msg .body ul, .msg .body ol { margin: 0 0 10px; padding-left: 22px; }
.msg .body code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.msg .body a { color: var(--accent2); }
.codeblock { position: relative; margin: 0 0 12px; }
.codeblock pre {
  background: #0a0c10; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  overflow-x: auto; margin: 0; font-size: 13.5px;
}
.codeblock pre code { background: none; padding: 0; }
.codeblock .lang { position: absolute; top: 6px; left: 12px; font-size: 11px; color: var(--muted); }
.codeblock .copy {
  position: absolute; top: 6px; right: 6px; background: var(--panel2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 6px; font-size: 12px; padding: 2px 8px;
}
.codeblock pre.has-lang { padding-top: 26px; }
details.reasoning {
  border-left: 2px solid var(--border); padding: 2px 0 2px 12px; margin-bottom: 10px; color: var(--muted);
  font-size: 13.5px;
}
details.reasoning summary { cursor: pointer; user-select: none; }
details.reasoning .r { white-space: pre-wrap; margin-top: 6px; }
.notice { color: #e0b35a; font-size: 13.5px; margin-top: 6px; }
.msg .err { color: var(--danger); font-size: 13.5px; margin-top: 6px; }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }

.composer {
  display: flex; gap: 8px; align-items: flex-end; max-width: 860px; width: 100%;
  margin: 0 auto; padding: 12px 20px 18px;
}
.composer textarea { flex: 1; resize: none; max-height: 220px; padding: 12px 14px; border-radius: 14px; }
.send { width: 46px; height: 46px; border-radius: 12px; font-size: 18px; }
.stop {
  height: 46px; padding: 0 16px; border-radius: 12px; background: var(--panel2);
  border: 1px solid var(--border); color: var(--text);
}

.web-toggle {
  height: 46px; padding: 0 12px; border-radius: 12px; background: var(--panel2);
  border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.web-toggle.on { border-color: var(--accent2); color: #fff; background: #2a3570; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sources a {
  display: inline-flex; align-items: center; gap: 6px; max-width: 280px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--panel2);
  color: var(--text); text-decoration: none; font-size: 12.5px;
}
.sources a:hover { border-color: var(--accent2); }
.sources a .d { color: var(--muted); flex-shrink: 0; }
.sources a .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.searching { color: var(--muted); font-size: 13px; margin-bottom: 6px; }

@media (max-width: 760px) {
  .web-toggle { padding: 0 9px; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px #000; }
  .menu-btn { display: block; }
  #model-price { display: none; }
  .messages { padding: 16px 12px; }
  .composer { padding: 10px 12px 14px; }
}
