/* ============================================================
 *  OpenWebUI alternative chat UI — theme tokens & layout
 * ============================================================ */

:root,
:root[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elev: #161920;
  --bg-soft: #1c2029;
  --bg-hover: #232835;
  --bg-input: #1a1e26;
  --border: #2a303c;
  --border-soft: #222733;
  --text: #e6e8ee;
  --text-dim: #a9b0bf;
  --text-faint: #6f7787;
  --accent: #6aa6ff;
  --accent-strong: #3d86f5;
  --accent-soft: rgba(106, 166, 255, 0.14);
  --ok: #3ccf91;
  --warn: #f5b84b;
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.12);
  --user-bubble: #232a36;
  --code-bg: #0b0d11;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f7f7f8;
  --bg-soft: #f1f2f4;
  --bg-hover: #e9ebef;
  --bg-input: #ffffff;
  --border: #dfe2e8;
  --border-soft: #eceef2;
  --text: #1b1f27;
  --text-dim: #4d5566;
  --text-faint: #8a92a3;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --ok: #0f9f62;
  --warn: #b7791f;
  --danger: #d93636;
  --danger-soft: rgba(217, 54, 54, 0.08);
  --user-bubble: #f0f2f6;
  --code-bg: #f6f8fa;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
a { color: var(--accent); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.fill { fill: currentColor; stroke: none; }
.i.ok { color: var(--ok); }
.i.bad { color: var(--danger); }

/* ------------------------------------------------------------ layout */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 272px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-elev); border-right: 1px solid var(--border-soft);
  transition: margin-left .2s ease;
}
.app.sidebar-collapsed .sidebar { margin-left: -272px; }
.sidebar-scrim { display: none; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

/* ------------------------------------------------------------ sidebar */
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 6px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff; font-size: 14px; }
.brand-title { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: var(--text-faint); }
.new-chat {
  margin: 6px 12px; display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-soft); font-weight: 550;
}
.new-chat:hover { background: var(--bg-hover); }
.search-wrap { position: relative; margin: 6px 12px 4px; }
.search-wrap .search-i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); width: 16px; height: 16px; }
.search-wrap input {
  width: 100%; padding: 7px 10px 7px 32px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft); background: var(--bg); outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }
.chat-nav { flex: 1; overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; }
.nav-section { margin-top: 8px; }
.nav-title { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; }
.group-title { padding: 10px 8px 2px; font-size: 11.5px; color: var(--text-faint); font-weight: 600; }
.chat-list, .folder-list { list-style: none; margin: 0; padding: 0; }
.chat-list.nested { padding-left: 10px; border-left: 1px solid var(--border-soft); margin-left: 12px; }
.chat-item { display: flex; align-items: center; border-radius: 8px; position: relative; }
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--accent-soft); }
.chat-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 7px 8px; color: var(--text); text-decoration: none; font-size: 13.5px; }
.chat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-more { opacity: 0; }
.chat-item:hover .chat-more, .chat-item.active .chat-more, .folder-head:hover .chat-more { opacity: 1; }
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; animation: pulse 1.2s infinite; }
.chat-empty { padding: 8px; font-size: 13px; color: var(--text-faint); }
.list-sentinel { height: 1px; }
.folder-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.folder-head:hover { background: var(--bg-hover); }
.folder-head.drop { outline: 2px dashed var(--accent); }
.folder-caret { width: 12px; color: var(--text-faint); font-size: 11px; }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-bottom { border-top: 1px solid var(--border-soft); padding: 8px; }
.tool-row { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tool-link { font-size: 12px; padding: 4px 8px; border-radius: 7px; border: 1px solid var(--border-soft); background: transparent; color: var(--text-dim); }
.tool-link:hover { background: var(--bg-hover); color: var(--text); }
.user-chip { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--radius-sm); border: none; background: transparent; text-align: left; }
.user-chip:hover { background: var(--bg-hover); }
.user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-mode { font-size: 11.5px; color: var(--text-faint); }

/* ------------------------------------------------------------ buttons */
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: none; background: transparent; color: var(--text-dim); }
.icon-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; border-radius: 7px; }
.icon-btn.sm .i { width: 16px; height: 16px; }
.icon-btn.on { color: var(--accent); }
.link-btn { border: none; background: none; color: var(--accent); font-size: 12.5px; padding: 2px 6px; border-radius: 6px; }
.link-btn:hover { background: var(--accent-soft); }
.link-btn.small { font-size: 12px; margin: 2px 0 6px 22px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-soft); font-weight: 550; font-size: 13.5px; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--text-dim); font-size: 12.5px; }
.chip-btn:hover { background: var(--bg-hover); color: var(--text); }
.chip-btn.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 50%, transparent); color: var(--accent); }
.chip-btn .i { width: 15px; height: 15px; }

/* ------------------------------------------------------------ topbar */
.topbar { display: flex; align-items: center; gap: 8px; height: 54px; padding: 0 12px; border-bottom: 1px solid var(--border-soft); flex: none; }
.app:not(.sidebar-collapsed) #sidebar-open { display: none; }
.model-bar { display: flex; align-items: center; gap: 4px; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.model-slot { display: flex; align-items: center; }
.model-btn { display: flex; align-items: center; gap: 6px; max-width: 280px; padding: 6px 10px; border-radius: 10px; border: none; background: transparent; font-weight: 650; font-size: 15px; }
.model-btn:hover { background: var(--bg-hover); }
.model-btn-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret { color: var(--text-faint); font-size: 11px; }
.add-model { font-size: 16px; }
.topbar-spacer { flex: 1; }
.chat-head { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 50%; }
.chat-title { flex: 0 1 auto; min-width: 80px; font-size: 13.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text; }
.chat-tags { flex: 0 1 auto; display: flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; min-width: 0; }
.tag { display: inline-flex; align-items: center; gap: 2px; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--bg-soft); color: var(--text-dim); border: 1px solid var(--border-soft); white-space: nowrap; }
.tag.add { border-style: dashed; background: transparent; cursor: pointer; }
.tag-x { border: none; background: none; color: var(--text-faint); padding: 0 0 0 2px; }
.topbar-actions { display: flex; gap: 2px; }

.model-pop { position: fixed; z-index: 60; width: min(420px, calc(100vw - 16px)); max-height: 60vh; display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: var(--radius); background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow); }
.model-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.model-option { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 9px; border: none; background: transparent; text-align: left; }
.model-option:hover, .model-option.selected { background: var(--bg-hover); }
.mo-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.mo-name { font-weight: 600; font-size: 13.5px; }
.mo-desc { font-size: 12px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mo-check { color: var(--accent); font-weight: 700; }
.badge { font-size: 10.5px; font-weight: 500; padding: 0 6px; border-radius: 6px; background: var(--bg-soft); color: var(--text-dim); margin-left: 4px; }

/* ------------------------------------------------------------ messages */
.content-row { flex: 1; min-height: 0; display: flex; }
.messages { flex: 1; min-width: 0; overflow-y: auto; scroll-behavior: auto; padding: 18px 16px 28px; }
.messages-inner { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; gap: 12px; min-width: 0; }
.msg-main { flex: 1; min-width: 0; }
.msg.user { justify-content: flex-end; }
.msg.user .msg-main { display: flex; flex-direction: column; align-items: flex-end; max-width: 85%; flex: none; }
.bubble { background: var(--user-bubble); padding: 10px 14px; border-radius: 18px 18px 6px 18px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble.md { white-space: normal; }
.bubble.md p:last-child { margin-bottom: 0; }
.msg-avatar { flex: none; padding-top: 2px; }
.avatar, .avatar-img { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--bg-soft); color: var(--text-dim); font-weight: 650; font-size: 13px; object-fit: cover; border: 1px solid var(--border-soft); }
.avatar.sm, .avatar-img.sm { width: 24px; height: 24px; font-size: 11px; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.model-name { font-weight: 650; font-size: 14px; }
.time { font-size: 11.5px; color: var(--text-faint); }
.msg-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 1px; margin-top: 4px; min-height: 28px; opacity: 0.85; }
.user-foot { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 2px; }
.user-foot .msg-actions { margin-top: 0; }
.msg.user .msg-actions { opacity: 0; transition: opacity .15s; }
.msg.user:hover .msg-actions, .msg.user:focus-within .msg-actions { opacity: 1; }
.branch { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; color: var(--text-faint); margin-right: 4px; }
.msg-error { margin: 8px 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); white-space: pre-wrap; word-wrap: break-word; }
.typing { display: inline-flex; gap: 4px; padding: 10px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }

.msg-multi { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.multi-col { border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 12px; cursor: pointer; min-width: 0; }
.multi-col.selected { border-color: color-mix(in srgb, var(--accent) 60%, transparent); box-shadow: 0 0 0 1px var(--accent-soft); }

/* status, details, embeds */
.msg-status:empty { display: none; }
.status { display: flex; align-items: center; gap: 8px; color: var(--text-faint); font-size: 14px; margin: 2px 0 6px; }
.status-links { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.status-links a { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg-soft); text-decoration: none; color: var(--text-dim); }
.status-older { font-size: 12.5px; color: var(--text-faint); margin-bottom: 6px; }
.status-older summary { cursor: pointer; }
.shimmer { background: linear-gradient(90deg, var(--text-faint) 0%, var(--text) 50%, var(--text-faint) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
.detail { margin: 4px 0; border-radius: var(--radius-sm); }
.detail > summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; color: var(--text-faint); font-size: 14px; user-select: none; }
.detail > summary::-webkit-details-marker { display: none; }
.detail > summary:hover { color: var(--text-dim); }
.detail.disabled > summary { cursor: default; }
.detail > summary .chev { width: 8px; height: 8px; border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor; transform: rotate(45deg); margin-left: 2px; transition: transform .15s; }
.detail[open] > summary .chev { transform: rotate(225deg); }
.d-name { color: var(--text-faint); opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-sum { white-space: nowrap; }
.detail-body { margin: 4px 0 8px 9px; padding-left: 14px; border-left: 2px solid var(--border-soft); font-size: 14px; color: var(--text-dim); }
.detail-body .detail { margin: 2px 0; }
.detail-label { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin: 8px 0 2px; }
.tool-image { max-width: 100%; border-radius: var(--radius-sm); margin-top: 6px; }
.embed-label, .embed-title { font-size: 12.5px; color: var(--text-faint); margin: 8px 0 2px; }
.embed-wrap { margin: 6px 0 10px; }
iframe.embed { width: 100%; min-height: 60px; height: 160px; border: 1px solid var(--border-soft); border-radius: var(--radius); background: #fff; display: block; resize: vertical; overflow: auto; }

/* sources & follow-ups */
.sources { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.source-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; padding: 3px 10px 3px 4px; border-radius: 999px; border: 1px solid var(--border-soft); background: var(--bg-soft); font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-chip b { display: inline-grid; place-items: center; min-width: 18px; height: 18px; border-radius: 50%; background: var(--bg-hover); font-size: 11px; }
.cite { display: inline-flex; align-items: center; max-width: 200px; height: 18px; padding: 0 8px; margin: 0 2px; border-radius: 999px; border: none; background: var(--bg-soft); color: var(--text-dim); font-size: 10.5px; font-weight: 500; vertical-align: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cite:hover { color: var(--text); background: var(--bg-hover); }
.cite-more { opacity: .6; margin-left: 2px; }
.followups { margin-top: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.fu-title { font-size: 12.5px; color: var(--text-faint); font-weight: 600; margin-bottom: 2px; }
.fu { border: none; background: transparent; text-align: left; padding: 5px 8px; border-radius: 8px; color: var(--text-dim); font-size: 14px; }
.fu::before { content: "↳ "; color: var(--text-faint); }
.fu:hover { background: var(--bg-hover); color: var(--text); }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; justify-content: inherit; }
.img-thumb img { max-width: 260px; max-height: 220px; border-radius: 12px; display: block; border: 1px solid var(--border-soft); }
.file-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 12px; border: 1px solid var(--border-soft); background: var(--bg-soft); color: var(--text); text-decoration: none; font-size: 13px; max-width: 280px; }
.fc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-meta { color: var(--text-faint); font-size: 11.5px; white-space: nowrap; }

/* markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .75em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.1em 0 .5em; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 .75em; }
.md li { margin: .2em 0; }
.md blockquote { margin: .6em 0; padding: .2em 1em; border-left: 3px solid var(--border); color: var(--text-dim); }
.md code { font: 0.88em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg-soft); padding: .12em .38em; border-radius: 6px; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md img { max-width: 100%; border-radius: 10px; }
.code-block { margin: .7em 0; border: 1px solid var(--border-soft); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 4px 12px; font-size: 12px; color: var(--text-faint); background: var(--bg-soft); }
.code-copy { border: none; background: transparent; color: var(--text-faint); font-size: 12px; padding: 2px 8px; border-radius: 6px; }
.code-copy:hover { background: var(--bg-hover); color: var(--text); }
.code-block pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code-block code, .code-block pre code.hljs { background: transparent !important; padding: 0; font-size: 13px; display: block; overflow-x: visible; }
.table-wrap { overflow-x: auto; margin: .7em 0; border: 1px solid var(--border-soft); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td { padding: 7px 10px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: top; }
.md th { background: var(--bg-soft); font-weight: 650; }
.md tr:last-child td { border-bottom: none; }
.math-block { overflow-x: auto; padding: .3em 0; }
.md details { margin: .5em 0; }

/* edit box */
.edit-box { width: 100%; min-width: min(560px, 80vw); }
.edit-input { width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-input); resize: vertical; outline: none; }
.edit-input:focus { border-color: var(--accent); }
.edit-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 6px; }

/* empty state */
.empty { text-align: center; padding: 10vh 12px 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-avatar .avatar, .empty-avatar .avatar-img { width: 54px; height: 54px; font-size: 22px; }
.empty-title { font-size: 26px; font-weight: 700; }
.empty-desc { color: var(--text-dim); max-width: 560px; }
.empty-sub { color: var(--text-faint); }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; width: 100%; max-width: 760px; margin-top: 18px; }
.suggestion { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border-soft); background: var(--bg-elev); text-align: left; }
.suggestion:hover { background: var(--bg-hover); }
.suggestion span { font-size: 13px; color: var(--text-faint); }

.scroll-bottom { position: absolute; left: 50%; transform: translateX(-50%); bottom: 150px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg-elev); box-shadow: var(--shadow); display: grid; place-items: center; z-index: 5; }

/* ------------------------------------------------------------ composer */
.composer-wrap { flex: none; padding: 0 16px 10px; }
.composer, .queue { max-width: 860px; margin: 0 auto; }
.composer { position: relative; border: 1px solid var(--border); border-radius: 24px; background: var(--bg-input); padding: 8px 8px 6px 14px; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
#composer-input { width: 100%; resize: none; border: none; outline: none; background: transparent; padding: 6px 4px; max-height: 40vh; line-height: 1.5; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.composer-left, .composer-right { display: flex; align-items: center; gap: 4px; min-width: 0; }
.composer-left { flex-wrap: wrap; }
.feature-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.send-btn { width: 36px; height: 36px; border-radius: 50%; border: none; display: grid; place-items: center; background: var(--text); color: var(--bg); }
.send-btn:disabled { opacity: .3; }
.send-btn.stop { background: var(--text); }
#mic-btn.recording { color: var(--danger); animation: pulse 1.2s infinite; }
.composer-foot { text-align: center; font-size: 11.5px; color: var(--text-faint); padding-top: 6px; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 6px; }
.attach { display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 6px; border-radius: 12px; border: 1px solid var(--border-soft); background: var(--bg-soft); max-width: 260px; }
.attach.error { border-color: var(--danger); }
.attach img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.attach-icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--bg-hover); }
.attach-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.attach-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.attach-meta { font-size: 11.5px; color: var(--text-faint); }
.attach-x { border: none; background: none; color: var(--text-faint); padding: 2px 6px; border-radius: 6px; }
.attach-x:hover { color: var(--danger); background: var(--danger-soft); }
.queue { margin-bottom: 6px; padding: 8px 12px; border: 1px dashed var(--border); border-radius: 14px; font-size: 13px; }
.queue-title { color: var(--text-faint); font-size: 12px; margin-bottom: 4px; }
.queue-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.queue-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-anchor { position: relative; }
.popover, .suggest-pop { position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 30; width: min(380px, 86vw); max-height: 50vh; overflow-y: auto; padding: 8px; border-radius: var(--radius); background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow); }
.suggest-pop { left: 8px; }
.pop-title { font-size: 12px; color: var(--text-faint); font-weight: 600; padding: 2px 6px 6px; }
.pop-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px; border-radius: 9px; cursor: pointer; }
.pop-row:hover { background: var(--bg-hover); }
.pop-row input { margin-top: 4px; }
.pop-text { display: flex; flex-direction: column; min-width: 0; }
.pop-name { font-weight: 600; font-size: 13.5px; }
.pop-desc { font-size: 12px; color: var(--text-faint); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.suggest-item { width: 100%; display: flex; flex-direction: column; align-items: flex-start; padding: 7px 8px; border: none; background: transparent; border-radius: 8px; text-align: left; }
.suggest-item.active, .suggest-item:hover { background: var(--bg-hover); }
.s-label { font-weight: 600; font-size: 13.5px; }
.s-desc { font-size: 12px; color: var(--text-faint); }
.drop-overlay { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 80%, transparent); border: 2px dashed var(--accent); font-size: 18px; font-weight: 600; }

/* ------------------------------------------------------------ controls panel */
.controls-panel { width: 320px; flex: none; border-left: 1px solid var(--border-soft); background: var(--bg-elev); display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--border-soft); }
.panel-body { padding: 12px; overflow-y: auto; }
.param-row { display: grid; grid-template-columns: 1fr 120px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }

/* ------------------------------------------------------------ modal, menu, toast */
.modal-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .45); backdrop-filter: blur(2px); }
.modal { position: fixed; z-index: 71; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); display: flex; flex-direction: column; border-radius: 18px; background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow); }
.modal.wide { width: min(860px, calc(100vw - 24px)); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 4px 16px 14px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--border-soft); }
.dialog-text { white-space: pre-wrap; color: var(--text-dim); }
.input { width: 100%; padding: 8px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-input); outline: none; }
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; }
.form-row { margin: 8px 0; }
.form-row.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-row.inline .input { flex: 1; min-width: 140px; }
.field-label { display: block; font-size: 12.5px; color: var(--text-faint); margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 14px; }
.list-rows { display: flex; flex-direction: column; gap: 6px; }
.list-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border-soft); background: var(--bg); flex-wrap: wrap; }
.btn-row { width: 100%; text-align: left; cursor: pointer; }
.btn-row:hover { background: var(--bg-hover); }
.grow { flex: 1; min-width: 160px; }
.muted { color: var(--text-faint); }
.small { font-size: 12.5px; }
.pad { padding: 10px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border-soft); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border-soft); font-size: 14px; }
.kv span { color: var(--text-faint); }
.seg { display: flex; gap: 4px; padding: 3px; border-radius: 11px; background: var(--bg-soft); margin: 10px 0; }
.seg-btn { flex: 1; padding: 6px; border: none; border-radius: 8px; background: transparent; color: var(--text-dim); font-weight: 550; }
.seg-btn.on { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .15); }
.login .btn.block { margin-top: 10px; }
.source-doc { margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border-soft); }
.research-out { margin-top: 12px; }

.menu { position: fixed; z-index: 80; min-width: 210px; padding: 6px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow); }
.menu-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 10px; border: none; background: transparent; border-radius: 8px; text-align: left; font-size: 13.5px; }
.menu-item:hover { background: var(--bg-hover); }
.menu-item.danger { color: var(--danger); }
.menu-icon { width: 18px; text-align: center; }
.menu-sep { height: 1px; background: var(--border-soft); margin: 4px 0; }

.toast-container { position: fixed; z-index: 90; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13.5px; transition: opacity .25s, transform .25s; word-wrap: break-word; }
.toast.success { border-left: 3px solid var(--ok); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warn { border-left: 3px solid var(--warn); }
.toast.info { border-left: 3px solid var(--accent); }
.toast.leaving { opacity: 0; transform: translateY(6px); }

.spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); display: inline-block; animation: spin .8s linear infinite; flex: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ------------------------------------------------------------ responsive */
@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; margin-left: -290px; width: 280px; box-shadow: var(--shadow); }
  .app.sidebar-open .sidebar { margin-left: 0; }
  .app.sidebar-open .sidebar-scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, .4); }
  .app #sidebar-open { display: inline-grid !important; }
  .chat-head { display: none !important; }
  .controls-panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 55; width: min(340px, 92vw); box-shadow: var(--shadow); }
  .messages { padding: 14px 12px 24px; }
  .msg.user .msg-main { max-width: 92%; }
  .msg-avatar { display: none; }
  .composer-wrap { padding: 0 8px 8px; }
  .chip-label { display: none; }
  .scroll-bottom { bottom: 130px; }
  .msg.user .msg-actions { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* model-HTML elements OpenWebUI renders natively */
.md-media { width: 100%; margin: 8px 0; border-radius: 10px; }
audio.md-media { height: 40px; }
.md-iframe { width: 100%; min-height: 120px; border: 1px solid var(--border-soft); border-radius: var(--radius); margin: 8px 0; background: #fff; }
.md-iframe.yt { aspect-ratio: 16 / 9; height: auto; }
.md-status { color: var(--text-faint); font-size: 14px; margin: 2px 0; }
.md-details { margin: 6px 0; }

/* ------------------------------------------------------------ sign-in */
.login-view { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 45%), var(--bg); overflow-y: auto; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 6px; padding: 28px 26px; border-radius: 20px; background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow); }
.login-logo { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; margin: 0 auto 4px; background: linear-gradient(135deg, var(--accent), #8b5cf6); color: #fff; font-size: 20px; }
.login-title { margin: 0; text-align: center; font-size: 22px; }
.login-sub { margin: 0 0 12px; text-align: center; color: var(--text-faint); font-size: 14px; }
.login-card .field-label { margin-top: 6px; }
.login-card .btn.block { margin-top: 10px; padding: 10px 14px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 70px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: none; background: transparent; color: var(--text-faint); font-size: 12px; padding: 4px 8px; border-radius: 6px; }
.pw-toggle:hover { color: var(--text); background: var(--bg-hover); }

/* rating follow-up (score, reason, comment) */
.fb-panel { margin: 10px 0 4px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); max-width: 560px; }
.fb-head { display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.fb-scale { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.fb-score { aspect-ratio: 1; border: 1px solid var(--border); border-radius: 8px; background: transparent; font-size: 13px; color: var(--text-dim); }
.fb-score:hover { background: var(--bg-hover); }
.fb-score.on { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.fb-scale-labels { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-faint); margin: 4px 0 10px; }
.fb-label { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.fb-reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.fb-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
