:root {
  --bg: #faf9f7;
  --panel: #f1efea;
  --surface: #ffffff;
  --text: #1f1e1c;
  --muted: #6b6862;
  --border: #e2dfd8;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --user-bubble: #ece9e2;
  --code-bg: #f4f2ee;
  --error: #b42318;
  --warn-bg: #fff6e0;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b1a;
    --panel: #232221;
    --surface: #2a2927;
    --text: #ecebe8;
    --muted: #a19e97;
    --border: #3a3936;
    --accent: #5b8ff0;
    --user-bubble: #34332f;
    --code-bg: #232220;
    --error: #ff8a80;
    --warn-bg: #3a3220;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* login */
.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; width: min(380px, 100%); display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); }
.login-card input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; }
.login-card button { padding: 10px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text); }
.error { color: var(--error); min-height: 1em; }

/* 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: 14px 10px; gap: 10px; }
.brand { font-weight: 650; font-size: 17px; padding: 4px 8px; }
.new-chat { border: 1px solid var(--border); background: var(--surface); padding: 9px 12px; border-radius: 10px; text-align: left; }
.new-chat:hover { border-color: var(--accent); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv { display: flex; align-items: center; gap: 4px; border-radius: 8px; padding: 2px 4px 2px 10px; }
.conv:hover, .conv.active { background: var(--user-bubble); }
.conv a { flex: 1; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 6px 0; font-size: 14px; }
.conv .del { visibility: hidden; border: 0; background: none; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.conv:hover .del { visibility: visible; }
.conv .del:hover { color: var(--error); }
.sidebar-foot { font-size: 12px; color: var(--muted); padding: 0 8px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.chat-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.lang-toggle { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 3px 12px; font-size: 13px; flex-shrink: 0; }
.lang-toggle:hover { color: var(--text); border-color: var(--accent); }
.login-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.login-card .lang-toggle { padding: 3px 12px; background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.icon-btn { border: 0; background: none; font-size: 18px; padding: 6px 8px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--user-bubble); }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.msg { max-width: 820px; margin: 0 auto 20px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); border-radius: 16px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .bubble { overflow-wrap: anywhere; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 13px; line-height: 1.5; }
.codeblock { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 12px 0; background: var(--code-bg); }
.codeblock-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--code-bg) 80%, var(--border)); }
.codeblock pre { margin: 0; border: 0; border-radius: 0; }
.codeblock pre code.hljs { background: transparent; padding: 0; }
.copy-btn { border: 0; background: none; color: var(--muted); font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.copy-btn:hover { background: var(--surface); color: var(--text); }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; }
.bubble :not(pre) > code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.bubble .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: flex-end; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 3px 9px; font-size: 13px; color: var(--muted); }

.thinking { margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.thinking summary { cursor: pointer; user-select: none; }
.thinking .thinking-body { white-space: pre-wrap; border-left: 2px solid var(--border); padding-left: 10px; margin-top: 6px; max-height: 260px; overflow-y: auto; }
.status { font-size: 13px; color: var(--muted); margin: 6px 0; }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 8px; animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3 } to { opacity: 1 } }
.notice { font-size: 13px; color: var(--muted); font-style: italic; }
.blocked { background: var(--warn-bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.err { color: var(--error); }

.exports { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.export { display: inline-flex; align-items: center; gap: 10px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 12px; text-decoration: none; color: var(--text); }
.export:hover { border-color: var(--accent); }
.export .ico { font-size: 20px; }
.export small { color: var(--muted); display: block; }
.usage { font-size: 11.5px; color: var(--muted); margin-top: 8px; opacity: .8; }

.empty { max-width: 720px; margin: 8vh auto 0; text-align: center; }
.empty h2 { font-weight: 600; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 20px; }
.suggestions button { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 12px; color: var(--text); }
.suggestions button:hover { border-color: var(--accent); }

.composer { padding: 8px 16px 14px; max-width: 852px; width: 100%; margin: 0 auto; }
.composer.drag .composer-row { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 8px; }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; background: none; color: var(--text); font: inherit; max-height: 240px; padding: 6px 4px; }
.send { border: 0; background: var(--accent); color: var(--accent-text); width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; }
.send:disabled { opacity: .4; cursor: default; }
.stop { background: var(--text); color: var(--bg); }
.attach { cursor: pointer; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.att { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px 4px 10px; font-size: 13px; max-width: 100%; }
.att.loading { opacity: .6; }
.att.failed { border-color: var(--error); color: var(--error); }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.att button { border: 0; background: none; color: var(--muted); padding: 0 4px; }
.hint { font-size: 11.5px; color: var(--muted); text-align: center; margin-top: 6px; }

@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .hint { display: none; }
}
