:root {
  --bg: #faf9f5; --panel: #f0eee6; --card: #ffffff; --text: #1f1e1d; --muted: #6b6a66;
  --border: #e3e0d6; --accent: #c96442; --accent-2: #ae5630; --user: #efece3; --code: #f6f5f0;
  --danger: #b42318; --ok: #227a4a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624; --panel: #1f1e1d; --card: #30302e; --text: #ece9e1; --muted: #a09d96;
    --border: #3d3c39; --user: #393937; --code: #1b1b1a; --danger: #f97066; --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; }

.btn { border: 1px solid var(--border); background: var(--card); border-radius: 8px; padding: 7px 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.full { width: 100%; }
.btn.danger { color: var(--danger); }
.link { background: none; border: 0; color: var(--muted); padding: 0 4px; font-size: 13px; }
.link:hover { color: var(--text); }
.icon-btn { background: none; border: 0; font-size: 18px; padding: 4px 8px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--panel); color: var(--text); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

.logo-dot { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); margin: 0 auto 8px; }
.logo-dot.big { width: 44px; height: 44px; }

/* login */
.login { height: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: 320px; display: flex; flex-direction: column; gap: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.login-card h1 { margin: 0 0 6px; text-align: center; font-size: 20px; font-weight: 600; }

/* 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: 12px; gap: 10px; }
.search { width: 100%; font-size: 14px; padding: 6px 10px; }
.conv-list { flex: 1; overflow-y: auto; margin: 0 -4px; }
.conv-item { display: flex; align-items: center; gap: 6px; padding: 7px 10px; margin: 1px 4px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.conv-item:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.conv-item.active { background: color-mix(in srgb, var(--text) 10%, transparent); }
.conv-item .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .del { visibility: hidden; background: none; border: 0; color: var(--muted); font-size: 13px; padding: 0 2px; }
.conv-item:hover .del { visibility: visible; }
.conv-group { font-size: 12px; color: var(--muted); padding: 10px 14px 2px; }
.side-foot { border-top: 1px solid var(--border); padding-top: 10px; font-size: 13px; }
.quota { color: var(--muted); margin-bottom: 6px; }
.quota .bar { height: 4px; background: var(--border); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.quota .bar i { display: block; height: 100%; background: var(--accent); }
.side-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; }
.who { font-weight: 600; margin-right: auto; }
.brand { color: var(--muted); font-size: 11px; margin-top: 8px; opacity: .7; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.conv-title { flex: 1; border: 0; background: transparent; font-weight: 600; font-size: 15px; padding: 6px 4px; min-width: 0; }
.conv-cost { color: var(--muted); font-size: 12px; white-space: nowrap; }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.empty { text-align: center; color: var(--muted); margin-top: 18vh; font-size: 20px; }
.msg { max-width: 780px; margin: 0 auto 22px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user); border-radius: 14px; padding: 10px 14px; max-width: 85%; white-space: pre-wrap; word-break: break-word; }
.msg.user .files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.msg.user .files img { max-height: 160px; max-width: 220px; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.msg-actions { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg:last-child .msg-actions { opacity: 1; }
.msg-actions button { background: none; border: 0; color: var(--muted); font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.msg-actions button:hover { background: var(--panel); color: var(--text); }

.assistant .md { word-break: break-word; }
.md p { margin: .5em 0; }
.md pre { background: var(--code); border: 1px solid var(--border); border-radius: 10px; padding: 0; overflow: hidden; position: relative; }
.md pre code { display: block; padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.5; background: transparent !important; }
.md code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.md :not(pre) > code { background: var(--code); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; margin: .6em 0; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; }
.md blockquote { border-left: 3px solid var(--border); margin: .5em 0; padding-left: 12px; color: var(--muted); }
.md a { color: var(--accent); }
.md img { max-width: 100%; }
.copy-code { position: absolute; top: 6px; right: 6px; font-size: 12px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 1px 8px; color: var(--muted); opacity: 0; }
.md pre:hover .copy-code { opacity: 1; }

details.think, details.search-res { border: 1px solid var(--border); border-radius: 10px; margin: 6px 0 10px; background: color-mix(in srgb, var(--panel) 60%, transparent); }
details.think summary, details.search-res summary { cursor: pointer; padding: 6px 12px; font-size: 13px; color: var(--muted); list-style: none; }
details.think summary::before, details.search-res summary::before { content: "▸ "; }
details[open].think summary::before, details[open].search-res summary::before { content: "▾ "; }
details.think .body { padding: 0 14px 10px; font-size: 13.5px; color: var(--muted); white-space: pre-wrap; max-height: 420px; overflow-y: auto; }
details.search-res ul { margin: 0; padding: 0 14px 10px 30px; font-size: 13px; }
.tool-line { font-size: 13px; color: var(--muted); margin: 6px 0; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.sources a { font-size: 12px; color: var(--muted); text-decoration: none; border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sources a:hover { color: var(--text); }
.meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.cursor::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.error-box { border: 1px solid var(--danger); color: var(--danger); border-radius: 10px; padding: 8px 12px; font-size: 14px; }

/* composer */
.composer-wrap { padding: 8px 16px 16px; position: relative; }
.composer { max-width: 780px; margin: 0 auto; background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 10px 12px 8px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
.composer textarea { width: 100%; border: 0; resize: none; padding: 4px 2px; max-height: 260px; background: transparent; outline: none; }
.composer-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.spacer { flex: 1; }
.sel { padding: 4px 8px; font-size: 13px; border-radius: 8px; }
.sel.small { padding: 4px 4px; }
.toggle { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; cursor: pointer; user-select: none; }
.toggle:has(input:checked) { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.toggle input { margin: 0; accent-color: var(--accent); }
.send { width: 34px; height: 34px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; font-size: 17px; font-weight: 700; }
.send:disabled { opacity: .4; cursor: default; }
.send.stop { background: var(--text); color: var(--bg); font-size: 13px; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments:not(:empty) { margin-bottom: 8px; }
.att { position: relative; }
.att img { height: 56px; width: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.att .x { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); font-size: 11px; line-height: 18px; padding: 0; }
.drop-hint { position: absolute; inset: 0 16px 16px; border: 2px dashed var(--accent); border-radius: 16px; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 85%, transparent); z-index: 5; color: var(--accent); }

/* dialogs */
.dlg { border: 1px solid var(--border); border-radius: 14px; background: var(--card); color: var(--text); padding: 20px; width: min(520px, 92vw); }
.dlg.wide { width: min(980px, 96vw); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg h3 { margin: 0 0 12px; }
.dlg textarea, .dlg > input { width: 100%; margin-bottom: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.table-wrap { overflow-x: auto; }
#userTable { width: 100%; border-collapse: collapse; font-size: 13px; }
#userTable th, #userTable td { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; white-space: nowrap; }
#userTable input { padding: 3px 6px; width: 80px; font-size: 13px; }
.admin-summary { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.scrim { display: none; }
.mobile-only { display: none; }
@media (max-width: 800px) {
  .mobile-only { display: inline-block; }
  .sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 15; }
  .messages { padding: 16px 10px 8px; }
  .composer-wrap { padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); }
  .msg.user .bubble { max-width: 92%; }
}
