/* LLMaaS chat UI. No framework, no external fonts, no third-party requests. */

:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef0f3; --border: #e1e4e9;
  --text: #16191d; --muted: #5b6470; --accent: #d52b1e; --accent-ink: #fff;
  --user-bg: #fff4f3; --user-border: #f3d3cf;
  --tool-bg: var(--surface-2); --tool-border: var(--border); --tool-ink: var(--muted);
  --code-bg: #0d1117; --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --border: #2a313b;
  --text: #eef1f4; --muted: #98a2ae; --user-bg: #2a1c1b; --user-border: #4a2a27;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
}}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --border: #2a313b;
  --text: #eef1f4; --muted: #98a2ae; --user-bg: #2a1c1b; --user-border: #4a2a27;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15.5px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 1.15em; height: 1.15em; flex: none; }
[hidden] { display: none !important; }
.only-dark { display: none; } :root[data-theme="dark"] .only-dark { display: inline; } :root[data-theme="dark"] .only-light { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .only-dark { display: inline; } :root:not([data-theme="light"]) .only-light { display: none; } }

/* Layout */
.app { display: grid; grid-template-columns: 268px 1fr; height: 100dvh; }
.sidebar { display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); padding: .9rem; gap: .75rem; min-height: 0; }
.main { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; min-width: 0; }
.mobile-only, .icon-btn.mobile-only { display: none; }
.backdrop { display: none; }

/* Sidebar */
.sidebar-top { display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 750; text-decoration: none; color: inherit; font-size: 1.05rem; }
.brand-mark { width: 26px; height: 26px; }
.btn-new { display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-new:hover { filter: brightness(.95); }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -.3rem; padding: 0 .3rem; }
.conv { display: flex; align-items: center; gap: .4rem; padding: .5rem .6rem; border-radius: 9px; color: var(--muted); cursor: pointer; }
.conv:hover { background: var(--surface-2); color: var(--text); }
.conv.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.conv .title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .93rem; }
.conv .del { opacity: 0; padding: .15rem; border-radius: 6px; }
.conv:hover .del { opacity: .7; } .conv .del:hover { opacity: 1; color: var(--accent); }
.conv-empty { color: var(--muted); font-size: .9rem; padding: .5rem .6rem; }
.sidebar-bottom { border-top: 1px solid var(--border); padding-top: .6rem; display: flex; flex-direction: column; gap: .1rem; }
.side-link { display: flex; align-items: center; gap: .5rem; padding: .45rem .6rem; border-radius: 9px; color: var(--muted); text-decoration: none; font-size: .93rem; }
.side-link:hover { background: var(--surface-2); color: var(--text); }
.side-link .who { margin-left: auto; max-width: 45%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: .78rem; opacity: .7; }
.side-form { display: contents; }
.side-form .side-link { width: 100%; text-align: left; }

/* Top bar */
.topbar { position: relative; display: flex; align-items: center; gap: .8rem; padding: .7rem 1.1rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.title-wrap { position: relative; }
.top-title { display: inline-flex; align-items: center; gap: .4rem; max-width: 40vw; padding: .2rem .45rem; margin-left: -.45rem; border-radius: 8px; color: var(--muted); font-size: .92rem; }
.top-title:hover { color: var(--text); }
.top-title .t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.top-title .caret { flex: none; font-size: .75em; opacity: .7; }
.title-pop { position: absolute; top: calc(100% + .35rem); left: 0; z-index: 5; display: flex; flex-direction: column; align-items: stretch; min-width: 150px; gap: .15rem; padding: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.title-pop .opt.danger, .title-pop .opt.danger:hover { color: var(--accent); }
.context-meter { margin-left: auto; display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.context-meter .bar { width: 110px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.context-meter .fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.context-meter .fill.warn { background: #e0a100; } .context-meter .fill.full { background: #b00020; }
.icon-btn { display: inline-grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 9px; color: var(--muted); }
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.settings-pop { position: absolute; right: 1rem; top: calc(100% + .4rem); z-index: 5; width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem; display: flex; flex-direction: column; gap: .7rem; }
.settings-pop label { display: flex; justify-content: space-between; align-items: center; gap: .6rem; font-size: .92rem; }
.settings-pop input, .settings-pop select { width: 150px; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .3rem .5rem; }
.settings-pop select { width: 165px; }
.settings-pop .field { position: relative; display: inline-flex; align-items: center; }
.settings-pop .field input { padding-right: 1.8rem; }
.settings-pop .field .clear { position: absolute; right: .3rem; }
.settings-pop .clear { display: grid; place-items: center; width: 1.35rem; height: 1.35rem; border-radius: 50%; color: var(--muted); font-size: .95rem; line-height: 1; }
.settings-pop .clear:hover { background: var(--surface-2); color: var(--text); }
.settings-pop .instr { flex-direction: column; align-items: stretch; gap: .35rem; }
.settings-pop textarea { width: 100%; min-height: 3.2rem; font: inherit; font-size: .9rem; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .4rem .5rem; resize: vertical; }
.settings-pop .hint { margin: 0; color: var(--muted); font-size: .8rem; }
.settings-pop .danger { display: flex; align-items: center; gap: .4rem; color: var(--accent); font-size: .9rem; padding: .3rem 0; }

/* Messages */
.messages { overflow-y: auto; padding: 1.4rem 1rem 1rem; scroll-behavior: smooth; }
.messages > * { width: min(860px, 100%); margin-inline: auto; }
.empty { text-align: center; padding: 10vh 1rem 2rem; color: var(--muted); }
.empty-mark { width: 44px; height: 44px; }
.empty h1 { font-size: 1.6rem; color: var(--text); margin: 1rem 0 .4rem; }
.empty p { max-width: 46ch; margin: 0 auto 1.4rem; }
.suggestions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }
.suggestions button { padding: .5rem .9rem; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: .9rem; }
.suggestions button:hover { border-color: var(--accent); }
.msg { display: flex; gap: .8rem; margin-bottom: 1.3rem; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { max-width: 80%; background: var(--user-bg); border: 1px solid var(--user-border); border-radius: 16px 16px 4px 16px; padding: .7rem 1rem; white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .avatar { width: 28px; height: 28px; margin-top: .2rem; }
.msg.assistant .body { flex: 1; min-width: 0; }
.content { line-height: 1.6; word-wrap: break-word; }
.content > :first-child { margin-top: 0; } .content > :last-child { margin-bottom: 0; }
.content p { margin: .5em 0; }
.content pre { position: relative; background: var(--code-bg); color: #e6edf3; border-radius: 10px; padding: .9rem 1rem; overflow-x: auto; font-size: .86rem; line-height: 1.5; }
.content code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.content :not(pre) > code { background: var(--surface-2); padding: .1em .35em; border-radius: 5px; font-size: .9em; }
.content pre code.hljs { background: transparent; padding: 0; }
.copy-btn { position: absolute; top: .45rem; right: .5rem; font-size: .75rem; color: #9fb0c0; background: rgba(255,255,255,.08); border-radius: 6px; padding: .2rem .5rem; opacity: 0; transition: opacity .15s; }
.content pre:hover .copy-btn { opacity: 1; }
.content table { border-collapse: collapse; margin: .6em 0; font-size: .92em; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--border); padding: .35em .6em; }
.content blockquote { margin: .6em 0; padding: .2em .9em; border-left: 3px solid var(--border); color: var(--muted); }
.content img { max-width: 100%; }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg .meta { display: flex; gap: .8rem; align-items: center; margin-top: .4rem; font-size: .78rem; color: var(--muted); opacity: 0; transition: opacity .15s; }
.msg:hover .meta, .msg.streaming .meta { opacity: 1; }
.link { padding: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--text); }
.error { color: #b00020; background: color-mix(in srgb, #b00020 8%, transparent); border-radius: 8px; padding: .5rem .8rem; margin: .5rem 0 0; }

/* Activity: a plain muted link for the latest action; steps and reasoning expand underneath */
.activity { margin: 0 0 .55rem; }
.act-head { display: inline-flex; align-items: center; gap: .45rem; max-width: 100%; padding: 0; cursor: pointer; font-size: .85rem; color: var(--muted); }
.act-head:hover { color: var(--text); }
.act-head .live { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.act-head .caret { flex: none; font-size: .85em; opacity: .75; }
.act-body { padding: .25rem 0 .35rem 1rem; }
.think-head { display: inline-flex; align-items: center; gap: .45rem; padding: .15rem 0; cursor: pointer; font-size: .85rem; color: var(--muted); }
.think-head:hover { color: var(--text); }
.thinking-body { padding: .15rem 0 .3rem; font-size: .84rem; line-height: 1.42; opacity: .88; max-height: 34vh; overflow-y: auto; overscroll-behavior: contain; }
.tline { margin: 0; overflow-wrap: anywhere; }
.tline.gap { margin-top: .45em; }
.tline.bullet { padding-left: 1.1em; text-indent: -1.1em; }
.tline.bullet::before { content: "\2022"; display: inline-block; width: 1.1em; text-indent: 0; opacity: .7; }
.tline.num { padding-left: 1.7em; text-indent: -1.7em; }
.tline.num .marker { display: inline-block; width: 1.7em; text-indent: 0; opacity: .8; }
.thinking-body strong { font-weight: 650; }
.thinking-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; background: rgba(127,127,127,.15); padding: .05em .3em; border-radius: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.tool-step { margin: 0 0 .15rem; font-size: .88rem; }
.tool-step .step-head { display: flex; align-items: center; gap: .5rem; width: 100%; text-align: left; padding: .28rem 0; color: var(--tool-ink); }
.tool-step .step-head .label { font-weight: 600; }
.tool-step .step-head .q { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tool-step .step-head .count { flex: none; font-size: .8rem; opacity: .8; }
.tool-step .step-head .caret { flex: none; font-size: .85em; opacity: .75; }
.tool-step .step-head.bare { cursor: default; }
.tool-step.error .step-head { color: #8a1c1c; }
.tool-step .step-head .spin { width: .9em; height: .9em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.tool-step .step-body { display: flex; flex-direction: column; margin: 0 0 .35rem 1.6rem; padding-left: .7rem; border-left: 2px solid var(--border); }
.srow { display: flex; align-items: center; gap: .5rem; padding: .32rem 0; margin-top: .35rem; font-size: .82rem; color: var(--text); text-decoration: none; border-top: 1px solid var(--border); }
.srow:hover .t { color: var(--accent); }
.srow .fav { width: 16px; height: 16px; flex: none; border-radius: 3px; object-fit: contain; }
.srow .fav.letter { display: inline-flex; align-items: center; justify-content: center; font-size: .62rem; font-weight: 700; color: #fff; }
.srow .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.srow .d { color: var(--muted); font-size: .9em; flex: none; }

/* Citations: one bold (domain) link per cited source, at the end of the answer */
.cite { font-weight: 700; color: var(--accent); text-decoration: none; }
.cite:hover { text-decoration: underline; }

/* Composer */
.composer { padding: .6rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px)); background: var(--bg); }
.composer > * { width: min(860px, 100%); margin-inline: auto; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .25rem .6rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .82rem; }
.chip.uploading { opacity: .6; } .chip.failed { border-color: #e6b3b3; color: #8a1c1c; }
.chip button { padding: 0; line-height: 0; color: var(--muted); } .chip button:hover { color: var(--accent); }
.chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }
.msg.user .thumbs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .5rem; }
.msg.user .thumbs img { max-width: 160px; max-height: 160px; border-radius: 10px; border: 1px solid var(--user-border); }
.composer-box { display: flex; align-items: flex-end; gap: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: .45rem .45rem .45rem .45rem; }
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
textarea { flex: 1; border: 0; outline: none; resize: none; font: inherit; color: inherit; background: transparent; max-height: 40vh; line-height: 1.5; padding: .55rem 0; }
.plus-menu, .send { flex: none; margin-bottom: .15rem; }
.plus-menu { position: relative; }
.plus-pop { position: absolute; bottom: calc(100% + .55rem); left: 0; z-index: 6; display: flex; flex-direction: column; align-items: stretch; min-width: 200px; gap: .15rem; padding: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.opt { display: flex; align-items: center; gap: .55rem; padding: .5rem .6rem; border-radius: 10px; color: var(--muted); font-size: .88rem; text-align: left; }
.opt svg { width: 1.25rem; height: 1.25rem; }
.opt:hover { background: var(--surface-2); color: var(--text); }
.opt[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--text); }
.opt[aria-pressed="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); }
.send { display: grid; place-items: center; width: 2.4rem; height: 2.4rem; border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
.send:disabled { opacity: .45; cursor: default; }
.send .when-busy { display: none; } .send.busy .when-busy { display: block; } .send.busy .when-idle { display: none; }

/* Mobile */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .mobile-only, .icon-btn.mobile-only { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 85vw); z-index: 20; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .app.sidebar-open .sidebar { transform: none; }
  .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .app.sidebar-open .backdrop { opacity: 1; pointer-events: auto; }
  .topbar { padding: .55rem .7rem; gap: .5rem; }
  .context-meter .bar { width: 70px; } .context-meter span { display: none; }
  .msg.user .bubble { max-width: 92%; }
  .suggestions button { width: 100%; }
}
