:root {
  --bg: #faf9f5; --side: #f0eee6; --panel: #ffffff; --text: #1f1e1d; --muted: #6b6a65;
  --line: #e3e1d9; --accent: #c96442; --accent-text: #fff; --user: #f0eee6; --code: #f3f2ee;
  --err: #b3261e; --hover: rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #262624; --side: #1f1e1d; --panel: #30302e; --text: #ece9e1; --muted: #a3a09a;
    --line: #3a3936; --accent: #d97757; --user: #3a3936; --code: #1f1e1d; --err: #f2b8b5; --hover: rgba(255,255,255,.06);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif; }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.login-card input { font: inherit; font-size: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); }
.login-card button { padding: 12px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.err { color: var(--err); min-height: 1.4em; margin: 0; font-size: 14px; }
.logo { font-size: 34px; color: var(--accent); line-height: 1; }
.logo.big { font-size: 44px; }

/* layout */
.app { display: flex; height: 100dvh; }
.side { width: 280px; flex: none; background: var(--side); display: flex; flex-direction: column; border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top); padding-left: env(safe-area-inset-left); }
.side-top { padding: 12px; }
.new-btn { width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-weight: 500; }
.list { flex: 1; overflow-y: auto; padding: 4px 8px; -webkit-overflow-scrolling: touch; }
.item { display: flex; align-items: center; gap: 4px; border-radius: 8px; }
.item a { flex: 1; min-width: 0; padding: 9px 10px; color: var(--text); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.item.active, .item:hover { background: var(--hover); }
.item.active a { font-weight: 600; }
.item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
.item .more { padding: 6px 8px; color: var(--muted); font-size: 18px; line-height: 1; }
.group { font-size: 12px; color: var(--muted); padding: 12px 10px 4px; }
.side-bot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; border-top: 1px solid var(--line); }
.link { color: var(--muted); font-size: 14px; }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 4px; padding: calc(6px + env(safe-area-inset-top)) 8px 6px; border-bottom: 1px solid var(--line); background: var(--bg); }
.title { flex: 1; min-width: 0; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; color: var(--text); flex: none; }
.icon-btn:active { background: var(--hover); }
.model { font: inherit; font-size: 14px; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; }
#menuBtn { visibility: hidden; }

.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px 16px 8px; }
.msgs > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.empty { text-align: center; margin-top: 18vh; color: var(--muted); padding: 0 16px; }
.empty p { margin: 10px 0 0; font-size: 18px; color: var(--text); }
.empty .hint { font-size: 14px; color: var(--muted); }

.msg { margin-bottom: 18px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble { background: var(--user); padding: 10px 14px; border-radius: 18px; max-width: 85%; white-space: pre-wrap; word-break: break-word; }
.msg.assistant .body { word-break: break-word; }
.body > :first-child { margin-top: 0; } .body > :last-child { margin-bottom: 0; }
.body p, .body ul, .body ol { margin: .6em 0; }
.body ul, .body ol { padding-left: 1.4em; }
.body h1, .body h2, .body h3 { font-size: 1.08em; margin: 1em 0 .4em; }
.body a { color: var(--accent); }
.body code { background: var(--code); padding: .1em .35em; border-radius: 5px; font: 14px/1.5 ui-monospace, Menlo, monospace; }
.body pre { background: var(--code); padding: 12px; border-radius: 10px; overflow-x: auto; position: relative; }
.body pre code { background: none; padding: 0; font-size: 13px; }
.body table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 8px; }
.body blockquote { margin: .6em 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.body img { max-width: 100%; border-radius: 8px; }
.copy { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--panel); color: var(--muted); border: 1px solid var(--line); }

.tools { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.tools summary { cursor: pointer; list-style: none; }
.tools summary::-webkit-details-marker { display: none; }
.tools ol { margin: 4px 0 0; padding-left: 1.4em; }
.status { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.msg .error { color: var(--err); font-size: 14px; margin-top: 6px; }

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.msg.user .files { justify-content: flex-end; margin-top: 0; margin-bottom: 6px; }
.file { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); text-decoration: none; font-size: 14px; }
.file .ext { flex: none; font-size: 11px; font-weight: 700; color: var(--accent-text); background: var(--accent); border-radius: 5px; padding: 2px 5px; text-transform: uppercase; }
.file .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .sz { flex: none; color: var(--muted); font-size: 12px; }
.thumb { display: block; max-width: 240px; max-height: 240px; border-radius: 10px; border: 1px solid var(--line); }

.composer { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:not(:empty) { margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; font-size: 13px; padding: 5px 6px 5px 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { color: var(--muted); padding: 0 4px; font-size: 16px; line-height: 1; }
.chip.up { opacity: .6; }
.box { display: flex; align-items: flex-end; gap: 4px; padding: 6px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); }
.box textarea { flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.45; padding: 9px 4px; max-height: 40vh; }
.send { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .35; }
.send svg { width: 20px; height: 20px; }
.send.stop svg { display: none; }
.send.stop::before { content: ""; width: 12px; height: 12px; background: currentColor; border-radius: 2px; }

@media (max-width: 820px) {
  .side { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: 82vw; max-width: 320px; transform: translateX(-100%); transition: transform .22s ease; }
  .app.open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .app.open .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.3); }
  #menuBtn { visibility: visible; }
  .msgs { padding: 12px 16px 8px; }
}
