:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --side: #efeee9;
  --text: #1d1d1b;
  --muted: #6b6a64;
  --border: #e2e0d8;
  --accent: #0f6e6e;
  --accent-soft: #e3f0ef;
  --user-bubble: #e9e7e0;
  --code-bg: #f1f0ea;
  --think: #8a887f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --panel: #232321;
    --side: #151514;
    --text: #ecebe6;
    --muted: #9c9a92;
    --border: #34332f;
    --accent: #4fb3ad;
    --accent-soft: #1f3534;
    --user-bubble: #2e2d2a;
    --code-bg: #2a2926;
    --think: #8f8d85;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* Sidebar */
#sidebar {
  width: 260px; flex-shrink: 0;
  background: var(--side);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 14px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand-name { font-weight: 650; letter-spacing: .2px; }
.new-chat {
  border: 1px solid var(--border); background: var(--panel);
  border-radius: 10px; padding: 9px 12px; text-align: left;
}
.new-chat:hover { border-color: var(--accent); }
.side-label { font-size: 12px; color: var(--muted); margin: 18px 8px 6px; text-transform: uppercase; letter-spacing: .6px; }
#chatList { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; align-items: center; gap: 6px;
  width: 100%; border: 0; background: none; text-align: left;
  padding: 7px 10px; border-radius: 8px; font-size: 14px;
}
.chat-item span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item .del { flex: none; opacity: 0; color: var(--muted); padding: 0 4px; }
.chat-item:hover { background: var(--border); }
.chat-item:hover .del { opacity: 1; }
.chat-item.active { background: var(--accent-soft); }
.side-foot { border-top: 1px solid var(--border); padding: 10px 8px 0; font-size: 12px; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--accent); padding: 4px 0; font-size: 12px; }

/* Main */
main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.icon-btn { border: 0; background: none; font-size: 18px; display: none; }
.model-pill { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; }

#thread { flex: 1; overflow-y: auto; padding: 8px 16px 24px; }
.msg { max-width: 780px; margin: 0 auto 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); border-radius: 18px;
  padding: 10px 16px; max-width: 80%; white-space: pre-wrap;
}

/* Reasoning panel */
.reasoning {
  border-left: 2px solid var(--border);
  padding: 2px 0 2px 14px; margin-bottom: 12px;
}
.reasoning summary {
  list-style: none; cursor: pointer; color: var(--muted); font-size: 14px;
  display: flex; align-items: center; gap: 8px;
}
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning summary::after { content: "›"; transition: transform .15s; }
.reasoning[open] summary::after { transform: rotate(90deg); }
.reasoning.live summary .label { background: linear-gradient(90deg, var(--muted) 30%, var(--text) 50%, var(--muted) 70%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.steps { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13.5px; color: var(--muted); }
.steps li { padding: 2px 0 2px 20px; position: relative; }
.steps li::before { content: "✓"; position: absolute; left: 0; color: var(--accent); }
.steps li.current::before { content: "•"; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .2; } }
.thinking {
  margin-top: 8px; font-size: 13.5px; color: var(--think);
  white-space: pre-wrap; max-height: 320px; overflow-y: auto;
}
.thinking:empty { display: none; }

/* Answer */
.answer { overflow-wrap: anywhere; }
.answer p { margin: 0 0 10px; }
.answer ol, .answer ul { margin: 0 0 10px; padding-left: 24px; }
.answer li { margin: 3px 0; }
.answer h2, .answer h3, .answer h4 { margin: 14px 0 6px; font-size: 16px; }
.answer code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font: 13px Consolas, "Cascadia Mono", monospace; }
.answer pre { background: var(--code-bg); border-radius: 10px; padding: 12px 14px; overflow-x: auto; position: relative; }
.answer pre code { background: none; padding: 0; }
.copy-code { position: absolute; top: 6px; right: 8px; font-size: 12px; border: 1px solid var(--border); background: var(--panel); border-radius: 6px; padding: 1px 8px; }
sup.cite { color: var(--accent); font-weight: 600; font-size: 11px; margin-left: 1px; }
.cursor::after { content: "▍"; animation: pulse 1s infinite; color: var(--accent); }
.error { color: #c0392b; background: rgba(192,57,43,.08); border-radius: 8px; padding: 8px 12px; }

/* Screenshots */
.answer img.shot {
  display: block; max-width: min(100%, 560px); max-height: 300px; margin: 8px 0 12px;
  border: 1px solid var(--border); border-radius: 8px; cursor: zoom-in;
  background: var(--panel);
}
.gallery-label { font-size: 12.5px; color: var(--muted); margin: 6px 0 6px; }
.gallery-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.gallery-row img.shot {
  height: 110px; width: auto; flex: none; border: 1px solid var(--border);
  border-radius: 8px; cursor: zoom-in; background: var(--panel);
}
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.8);
  display: grid; place-items: center; padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; }

/* Sources */
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.src {
  font-size: 12.5px; border: 1px solid var(--border); background: var(--panel);
  border-radius: 999px; padding: 3px 10px; color: var(--muted); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.src b { color: var(--accent); margin-right: 4px; }
.meta-row { display: flex; gap: 12px; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.meta-row button { border: 0; background: none; color: var(--muted); padding: 0; }
.meta-row button:hover { color: var(--text); }

/* Empty state */
.empty { max-width: 680px; margin: 12vh auto 0; text-align: center; }
.empty h1 { font-size: 28px; font-weight: 600; margin: 0 0 6px; }
.empty p { color: var(--muted); margin: 0 0 24px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.suggestions button {
  text-align: left; border: 1px solid var(--border); background: var(--panel);
  border-radius: 12px; padding: 12px 14px; font-size: 14px;
}
.suggestions button:hover { border-color: var(--accent); }

/* Composer */
#composer {
  max-width: 780px; width: calc(100% - 32px); margin: 0 auto;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 22px; padding: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,.05);
}
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.clip {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: none;
  color: var(--muted); display: grid; place-items: center; flex: none;
}
.clip:hover { background: var(--accent-soft); color: var(--accent); }
.attach-chip {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 8px;
  margin: 2px 4px 0; padding: 6px 8px 6px 10px; max-width: 100%;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 13px;
}
.attach-chip[hidden] { display: none; }
.attach-chip .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .info { color: var(--muted); white-space: nowrap; }
.attach-chip .x { border: 0; background: none; color: var(--muted); padding: 0 2px; }
.attach-chip.err { color: #c0392b; border-color: rgba(192,57,43,.4); }
.bubble-file {
  display: inline-block; margin-bottom: 4px; font-size: 12.5px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px; padding: 2px 8px; background: var(--panel);
}
main.dragging #composer { border-color: var(--accent); border-style: dashed; }
.drop-hint { text-align: center; font-size: 12.5px; color: var(--accent); padding-top: 6px; }
.drop-hint[hidden] { display: none; }

/* Knowledge base upload (sidebar) */
.kb-upload {
  width: 100%; margin-bottom: 8px; padding: 8px 10px; border-radius: 10px; text-align: left;
  border: 1px dashed var(--accent); background: var(--accent-soft); color: var(--accent); font-size: 13px;
}
.kb-upload:disabled { opacity: .6; cursor: default; }
.kb-status { font-size: 12px; margin-bottom: 8px; }
.kb-status:empty { display: none; }
.kb-status .ok { color: var(--accent); }
.kb-status .bad { color: #c0392b; }
.kb-status div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#composer:focus-within { border-color: var(--accent); }
#input {
  flex: 1; border: 0; outline: 0; resize: none; background: none; color: var(--text);
  font: inherit; max-height: 200px; padding: 6px 0; align-self: center;
}
#send {
  width: 36px; height: 36px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 15px;
}
#send:disabled { opacity: .4; cursor: default; }
#send.stop { background: var(--text); color: var(--bg); }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); padding: 8px 16px 12px; }

/* Mobile */
@media (max-width: 760px) {
  #sidebar { position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  body.side-open #sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .icon-btn { display: block; }
  .suggestions { grid-template-columns: 1fr; }
  .empty { margin-top: 6vh; }
  .msg.user .bubble { max-width: 90%; }
}
.brand-name small { display: block; font-size: 11.5px; font-weight: 500; color: var(--muted); letter-spacing: .2px; }
