:root {
  --bg: #fafafa; --panel: #fff; --ink: #1b1d21; --muted: #6b7079; --line: #e3e5e8;
  --accent: #2f5bd3; --accent-ink: #fff; --user: #eef2fc; --warn: #a15c00; --err: #b3261e;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15171a; --panel: #1d2024; --ink: #e6e7e9; --muted: #969ba3; --line: #2d3137;
          --accent: #6d8ff0; --accent-ink: #0d1220; --user: #232a3a; --warn: #e3a54a; --err: #f08a82; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); display: flex; flex-direction: column; font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
.muted { color: var(--muted); }
button, select, input, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); padding: 6px 12px; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.icon { padding: 6px 10px; }
button.rec { background: var(--err); color: #fff; border-color: var(--err); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { font-size: 17px; margin: 0; white-space: nowrap; }
.brand .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; }
.gpu { font-size: 12px; color: var(--muted); white-space: nowrap; }
.gpu.bad { color: var(--err); }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 290px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--line); padding: 8px; background: var(--panel); }
.sidebar h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 8px 6px; }
.mitem { display: block; width: 100%; text-align: left; border: 1px solid transparent; background: none; padding: 8px; margin-bottom: 2px; }
.mitem:hover { background: var(--bg); }
.mitem.active { border-color: var(--accent); background: var(--user); }
.mitem .n { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.mitem .s { font-weight: 400; font-size: 12px; color: var(--muted); white-space: nowrap; }
.mitem .b { font-size: 12.5px; color: var(--muted); }
.mitem .loaded { color: var(--accent); font-size: 12px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 0 16px; }
.model-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0 8px; border-bottom: 1px solid var(--line); }
.model-head h2 { margin: 0; font-size: 18px; }
.model-head p { margin: 2px 0 0; font-size: 13.5px; }
.head-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.link { font-size: 13px; }

.progress { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 13px; }
.bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
#progressFill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.mode-row { display: flex; gap: 16px; padding: 8px 0; font-size: 13.5px; flex-wrap: wrap; }
.mode-row select { margin-left: 6px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }

.log { flex: 1; overflow-y: auto; padding: 12px 0; display: flex; flex-direction: column; gap: 12px; }
.empty { max-width: 640px; margin: 24px auto; font-size: 14.5px; }
.msg { max-width: 820px; width: 100%; margin: 0 auto; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg .body { white-space: normal; overflow-wrap: anywhere; }
.msg.user .body { background: var(--user); padding: 8px 12px; border-radius: var(--radius); }
.msg .body p { margin: 0 0 .6em; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body pre { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; overflow-x: auto; font-size: 13px; }
.msg .body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.msg img.thumb { max-width: 220px; max-height: 180px; border-radius: 6px; display: block; margin-bottom: 6px; }
.msg audio { display: block; margin-top: 6px; max-width: 100%; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.msg.error .body { color: var(--err); }
details.think { border-left: 3px solid var(--line); padding: 2px 10px; margin-bottom: 8px; color: var(--muted); font-size: 13.5px; }
details.think summary { cursor: pointer; }

.composer { border-top: 1px solid var(--line); padding: 10px 0 12px; max-width: 820px; width: 100%; margin: 0 auto; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; background: var(--panel); max-height: 180px; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; }
.attachments:not(:empty) { margin-bottom: 8px; }
.chip { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; font-size: 12.5px; background: var(--panel); }
.chip img { height: 36px; border-radius: 4px; }
.chip button { padding: 0 6px; border: none; }
.settings { margin-top: 8px; font-size: 13px; color: var(--muted); }
.settings summary { cursor: pointer; }
.settings label { display: inline-flex; align-items: center; gap: 6px; margin: 6px 14px 0 0; }
.settings input { border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; background: var(--panel); width: 90px; }
.settings input[type=text] { width: 260px; }

.foot { font-size: 12px; padding: 6px 16px; border-top: 1px solid var(--line); text-align: center; }

@media (max-width: 760px) {
  .menu-btn { display: inline-block; padding: 2px 8px; }
  .brand .sub { display: none; }
  .sidebar { position: fixed; z-index: 10; top: 49px; bottom: 0; left: 0; width: 86vw; max-width: 320px; transform: translateX(-100%); transition: transform .2s; box-shadow: 2px 0 12px rgba(0,0,0,.15); }
  .sidebar.open { transform: none; }
  .main { padding: 0 10px; }
  .model-head { flex-wrap: wrap; }
  .settings input[type=text] { width: 100%; }
  .foot { display: none; }
}
