/* IMOS 操作助手 — design system. Light + dark via [data-theme] on <html>. */

:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-2: #eaeef4;
  --surface-3: #dfe5ee;
  --line: #dde3ec;
  --line-strong: #c9d2e0;
  --ink: #1c2433;
  --muted: #61708b;
  --faint: #8b98af;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, .10);
  --on-accent: #ffffff;
  --user-bubble: #2563eb;
  --on-user-bubble: #f4f8ff;
  --kb: #15803d;      --kb-soft: rgba(21, 128, 61, .12);
  --web: #0369a1;     --web-soft: rgba(3, 105, 161, .11);
  --warn: #b45309;    --warn-soft: rgba(180, 83, 9, .12);
  --danger: #dc2626;  --danger-soft: rgba(220, 38, 38, .10);
  --code-bg: #f0f3f8;
  --pre-bg: #101623;
  --pre-ink: #dbe4f0;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px -12px rgba(16, 24, 40, .18);
  --shadow-lg: 0 8px 40px -8px rgba(16, 24, 40, .28);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 300px;
  --thread-w: 860px;
  --dur: .18s;
  --ease: cubic-bezier(.3, .8, .3, 1);
}

[data-theme="dark"] {
  --bg: #0d1219;
  --surface: #161d28;
  --surface-2: #1e2735;
  --surface-3: #273245;
  --line: rgba(148, 163, 190, .16);
  --line-strong: rgba(148, 163, 190, .30);
  --ink: #e7edf6;
  --muted: #94a3bc;
  --faint: #64748b;
  --accent: #3b82f6;
  --accent-strong: #60a5fa;
  --accent-soft: rgba(59, 130, 246, .16);
  --user-bubble: #2158c9;
  --on-user-bubble: #eaf1ff;
  --kb: #4ade80;      --kb-soft: rgba(74, 222, 128, .13);
  --web: #38bdf8;     --web-soft: rgba(56, 189, 248, .12);
  --warn: #fbbf24;    --warn-soft: rgba(251, 191, 36, .13);
  --danger: #f87171;  --danger-soft: rgba(248, 113, 113, .13);
  --code-bg: rgba(148, 163, 190, .13);
  --pre-bg: #0b1018;
  --pre-ink: #d5dfee;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 28px -14px rgba(0, 0, 0, .6);
  --shadow-lg: 0 12px 48px -8px rgba(0, 0, 0, .65);
}

/* ---------------- base ---------------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: .5; cursor: not-allowed; }
a { color: var(--accent); }
::selection { background: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.hidden { display: none !important; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------------- shared controls ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink); font-size: 14px; font-weight: 500;
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease), opacity var(--dur);
  user-select: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  color: var(--muted); flex: 0 0 auto;
  transition: background var(--dur), color var(--dur);
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.iconbtn svg { width: 20px; height: 20px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: 16px; outline: none;
  transition: border-color var(--dur), box-shadow var(--dur);
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ---------------- login ---------------- */
#loginView {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; background:
    radial-gradient(1000px 500px at 15% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  z-index: 50;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; padding: 34px 30px 28px;
  box-shadow: var(--shadow-lg);
  animation: rise .35s var(--ease);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand h1 { font-size: 20px; margin: 0; font-weight: 700; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; }
.login-error {
  min-height: 20px; font-size: 13px; color: var(--danger); margin: 2px 0 10px;
}
.login-card.shake { animation: shake .4s; }
@keyframes shake {
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.logo {
  width: 40px; height: 40px; border-radius: 11px; flex: 0 0 auto;
  background: linear-gradient(135deg, #2563eb, #0ea5a3);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 19px;
  box-shadow: 0 4px 14px -4px rgba(37, 99, 235, .6);
}
.logo.sm { width: 30px; height: 30px; font-size: 14px; border-radius: 9px; }

/* ---------------- app shell ---------------- */
#appView {
  height: 100vh; height: 100dvh;
  display: flex; overflow: hidden;
}

/* ---------------- sidebar ---------------- */
#sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
  transition: margin-left .24s var(--ease), transform .24s var(--ease);
}
.side-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 10px;
}
.side-head .name { font-weight: 700; font-size: 15px; flex: 1; letter-spacing: .2px; }
.side-actions { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 8px; }
#newChatBtn { width: 100%; justify-content: flex-start; padding: 10px 14px; }
.search-wrap { position: relative; }
.search-wrap svg {
  position: absolute; left: 11px; top: 50%; translate: 0 -50%;
  width: 15px; height: 15px; color: var(--faint); pointer-events: none;
}
#searchInput {
  width: 100%; padding: 8px 12px 8px 33px; font-size: 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); outline: none;
  transition: border-color var(--dur), background var(--dur);
}
#searchInput:focus { border-color: var(--accent); background: var(--surface); }

#chatList { flex: 1; overflow-y: auto; padding: 2px 8px 12px; min-height: 0; }
.group-label {
  font-size: 11.5px; color: var(--faint); font-weight: 600;
  padding: 14px 8px 5px; letter-spacing: .4px;
}
.chat-item { position: relative; margin-bottom: 2px; }
.chat-open {
  display: block; width: 100%; text-align: left;
  padding: 8px 62px 8px 10px; border-radius: var(--radius-sm);
  transition: background var(--dur);
}
.chat-open:hover { background: var(--surface-2); }
.chat-item.active .chat-open { background: var(--accent-soft); }
.chat-title {
  display: block; font-size: 13.5px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.chat-item.active .chat-title { color: var(--accent); font-weight: 600; }
.chat-time { display: block; font-size: 11px; color: var(--faint); margin-top: 2px; }
.chat-tools {
  position: absolute; right: 6px; top: 50%; translate: 0 -50%;
  display: flex; gap: 2px; opacity: 0;
  transition: opacity var(--dur);
}
.chat-item:hover .chat-tools, .chat-item.active .chat-tools,
.chat-item:focus-within .chat-tools { opacity: 1; }
@media (pointer: coarse) { .chat-tools { opacity: 1; } }
.chat-tools .iconbtn { width: 28px; height: 28px; border-radius: 7px; }
.chat-tools .iconbtn svg { width: 15px; height: 15px; }
.chat-rename-input {
  width: 100%; padding: 8px 10px; font-size: 13.5px;
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); outline: none;
}
.chat-confirm {
  display: flex; gap: 6px; align-items: center; padding: 6px 10px;
  font-size: 12.5px; color: var(--danger);
}
.chat-confirm .btn { padding: 4px 10px; font-size: 12.5px; }
.empty-list { color: var(--faint); font-size: 13px; padding: 18px 10px; text-align: center; }

.side-foot { border-top: 1px solid var(--line); padding: 10px; position: relative; }
.user-card {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: var(--radius-sm); text-align: left;
  transition: background var(--dur);
}
.user-card:hover { background: var(--surface-2); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  background: var(--accent-soft); color: var(--accent);
}
.user-card .info { flex: 1; min-width: 0; }
.user-card .uname {
  font-size: 14px; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.user-card .urole { font-size: 11.5px; color: var(--faint); }
.role-badge {
  display: inline-block; font-size: 10.5px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-radius: 20px; padding: 1px 8px;
  vertical-align: 1px; margin-left: 5px;
}

/* user menu popover */
.menu {
  position: absolute; left: 10px; right: 10px; bottom: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 6px; z-index: 30;
  animation: pop .16s var(--ease);
  transform-origin: bottom center;
}
@keyframes pop { from { opacity: 0; transform: translateY(5px) scale(.98); } }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border-radius: var(--radius-sm); font-size: 13.5px;
  text-align: left; transition: background var(--dur);
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu button svg { width: 17px; height: 17px; color: var(--muted); flex: 0 0 auto; }
.menu button.danger svg { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 8px; }

/* ---------------- main pane ---------------- */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; position: relative; }
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  z-index: 5;
}
#topbar .title {
  flex: 1; min-width: 0; font-size: 15px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-chip {
  font-size: 11.5px; color: var(--muted); background: var(--surface-2);
  padding: 4px 11px; border-radius: 20px; white-space: nowrap;
  border: 1px solid var(--line);
}
#sidebarBtn.desktop-only { display: inline-flex; }

/* ---------------- thread ---------------- */
#thread { flex: 1; overflow-y: auto; min-height: 0; scroll-padding-bottom: 40px; }
.thread-inner {
  max-width: var(--thread-w); margin: 0 auto; padding: 22px 22px 30px;
}
.day-sep {
  display: flex; align-items: center; gap: 12px;
  color: var(--faint); font-size: 11.5px; margin: 18px 0 14px;
}
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.msg { margin-bottom: 22px; animation: msg-in .22s var(--ease); }
@keyframes msg-in { from { opacity: 0; transform: translateY(5px); } }

/* user message: right-aligned bubble */
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  max-width: min(78%, 620px);
  background: var(--user-bubble); color: var(--on-user-bubble);
  border-radius: 18px 18px 5px 18px;
  padding: 10px 15px; font-size: 14.5px;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
  box-shadow: var(--shadow);
}
.msg.user .msg-atts { display: flex; flex-wrap: wrap; gap: 5px; justify-content: flex-end; margin-bottom: 6px; }
.msg-att {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 3px 9px; max-width: 280px;
}
.msg-att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* assistant message: full-width document style */
.msg.bot { display: flex; gap: 12px; }
.msg.bot > .logo.sm { margin-top: 2px; }
.msg.bot .body { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-head .who { font-size: 13px; font-weight: 700; }
.msg-time { font-size: 11px; color: var(--faint); }
.msg.user .msg-time { margin-top: 5px; margin-right: 4px; opacity: 0; transition: opacity var(--dur); }
.msg.user:hover .msg-time { opacity: 1; }

/* activity (tool calls / retrieval) */
.activity { margin: 6px 0 2px; font-size: 12.5px; color: var(--muted); }
.activity .act {
  display: flex; align-items: center; gap: 8px; padding: 3px 0;
  animation: msg-in .2s var(--ease);
}
.act .spin {
  width: 12px; height: 12px; flex: 0 0 auto; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: rot .8s linear infinite;
}
.act.done .spin { border: 0; width: 12px; height: 12px; animation: none; position: relative; }
.act.done .spin::after { content: "✓"; position: absolute; inset: 0; font-size: 11px; color: var(--kb); line-height: 1; }
.act .act-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
@keyframes rot { to { transform: rotate(360deg); } }
.activity-summary {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); background: var(--surface-2);
  padding: 3px 10px; border-radius: 20px; margin: 4px 0;
  transition: background var(--dur);
}
.activity-summary:hover { background: var(--surface-3); }

/* markdown content */
.content { font-size: 15px; overflow-wrap: break-word; word-break: break-word; }
.content > :first-child { margin-top: 4px; }
.content p { margin: .55em 0; }
.content h2, .content h3, .content h4, .content h5 {
  margin: 1em 0 .35em; line-height: 1.35; font-weight: 700;
}
.content h2 { font-size: 1.22em; }
.content h3 { font-size: 1.1em; }
.content h4, .content h5 { font-size: 1em; }
.content ul, .content ol { margin: .45em 0; padding-left: 1.55em; }
.content li { margin: .22em 0; }
.content li > ul, .content li > ol { margin: .15em 0; }
.content blockquote {
  margin: .6em 0; padding: 2px 14px; color: var(--muted);
  border-left: 3px solid var(--line-strong);
}
.content hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.content code {
  background: var(--code-bg); border-radius: 5px; padding: 1.5px 6px;
  font-size: .88em;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Cascadia Code", monospace;
}
.codeblock {
  margin: .7em 0; border-radius: 11px; overflow: hidden;
  border: 1px solid var(--line); background: var(--pre-bg);
}
.codehead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; font-size: 11.5px; color: #93a4bd;
  background: rgba(148, 163, 190, .08);
}
.codecopy {
  font-size: 11.5px; color: #93a4bd; padding: 3px 9px; border-radius: 6px;
  transition: background var(--dur), color var(--dur);
}
.codecopy:hover { background: rgba(148, 163, 190, .15); color: #e7edf6; }
.codeblock pre {
  margin: 0; padding: 12px 14px; overflow-x: auto;
  color: var(--pre-ink); font-size: 13px; line-height: 1.55;
}
.codeblock pre code { background: none; padding: 0; font-size: inherit; color: inherit; }
.tablewrap { overflow-x: auto; margin: .7em 0; border: 1px solid var(--line); border-radius: 10px; }
.content table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.content th, .content td { border-bottom: 1px solid var(--line); padding: 7px 12px; text-align: left; vertical-align: top; }
.content th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.content tr:last-child td { border-bottom: 0; }

/* streaming caret */
.msg.streaming .content::after {
  content: ""; display: inline-block; width: 8px; height: 15px;
  background: var(--accent); border-radius: 2px;
  margin-left: 3px; vertical-align: -2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* typing dots (before first token) */
.dots { display: inline-flex; gap: 5px; padding: 8px 0; }
.dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--faint);
  animation: bounce .9s ease-in-out infinite;
}
.dots span:nth-child(2) { animation-delay: .12s; }
.dots span:nth-child(3) { animation-delay: .24s; }
@keyframes bounce { 30% { transform: translateY(-4px); opacity: 1; } 0%, 60%, 100% { opacity: .4; } }

/* sources */
.sources { margin-top: 10px; }
.sources summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font-size: 12px; color: var(--muted); user-select: none;
  padding: 3px 10px; border-radius: 20px; background: var(--surface-2);
  list-style: none; transition: background var(--dur);
}
.sources summary::-webkit-details-marker { display: none; }
.sources summary:hover { background: var(--surface-3); }
.sources[open] summary { margin-bottom: 7px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 4px 11px; border-radius: 20px;
  text-decoration: none; max-width: 100%;
  transition: filter var(--dur);
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip:hover { filter: brightness(1.08); }
.chip.kb { background: var(--kb-soft); color: var(--kb); }
.chip.web { background: var(--web-soft); color: var(--web); }

/* message actions */
.msg-actions { display: flex; gap: 4px; margin-top: 7px; opacity: 0; transition: opacity var(--dur); }
.msg.bot:hover .msg-actions, .msg.bot:focus-within .msg-actions { opacity: 1; }
@media (pointer: coarse) { .msg-actions { opacity: .85; } }
.msg-actions .iconbtn { width: 30px; height: 30px; }
.msg-actions .iconbtn svg { width: 16px; height: 16px; }
.stopped-badge {
  display: inline-block; font-size: 11.5px; color: var(--warn);
  background: var(--warn-soft); padding: 2px 9px; border-radius: 20px; margin-top: 8px;
}

/* error card */
.error-card {
  background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger); border-radius: var(--radius);
  padding: 12px 14px; font-size: 14px; margin-top: 4px;
}
.error-card .btn { margin-top: 9px; }

/* empty state */
.welcome { text-align: center; padding: 9vh 10px 20px; animation: msg-in .3s var(--ease); }
.welcome .logo { width: 54px; height: 54px; font-size: 25px; border-radius: 15px; margin: 0 auto 16px; }
.welcome h2 { font-size: 21px; margin: 0 0 8px; }
.welcome p { color: var(--muted); font-size: 14px; margin: 0 0 26px; }
.suggest-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px; max-width: 620px; margin: 0 auto;
}
.suggest {
  text-align: left; padding: 13px 15px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface);
  font-size: 13.5px; color: var(--ink); line-height: 1.45;
  transition: border-color var(--dur), background var(--dur), transform var(--dur) var(--ease);
}
.suggest:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.suggest .s-tag { display: block; font-size: 11.5px; color: var(--faint); margin-bottom: 3px; }

/* jump to bottom pill */
#scrollPill {
  position: absolute; left: 50%; translate: -50% 0; bottom: 108px;
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 12.5px;
  padding: 7px 14px; border-radius: 30px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transform: translateY(6px);
  transition: opacity var(--dur), transform var(--dur) var(--ease);
  z-index: 6;
}
#scrollPill.show { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* ---------------- composer ---------------- */
#composer {
  flex: 0 0 auto; padding: 6px 16px calc(14px + env(safe-area-inset-bottom));
  max-width: calc(var(--thread-w) + 8px); margin: 0 auto; width: 100%;
}
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px 8px; }
.attach-row:empty { display: none; }
.att {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; padding: 6px 11px; border-radius: 9px;
  background: var(--surface); border: 1px solid var(--line); max-width: 100%;
}
.att .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.att .att-meta { color: var(--faint); font-size: 11.5px; white-space: nowrap; }
.att.bad { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.att.pending .att-meta { color: var(--warn); }
.att .x { color: var(--faint); width: 20px; height: 20px; border-radius: 5px; display: grid; place-items: center; }
.att .x:hover { color: var(--danger); background: var(--danger-soft); }
.att .mini-spin {
  width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid var(--line-strong); border-top-color: var(--warn);
  animation: rot .8s linear infinite;
}

.inputwrap {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 18px; padding: 8px;
  box-shadow: var(--shadow);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.inputwrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
#input {
  flex: 1; min-width: 0; border: 0; background: none; resize: none; outline: none;
  font-size: 16px; line-height: 1.5; padding: 7px 6px; max-height: 190px;
  color: var(--ink);
}
#input::placeholder { color: var(--faint); }
#sendBtn {
  width: 40px; height: 40px; border-radius: 13px; flex: 0 0 auto;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  transition: background var(--dur), transform var(--dur) var(--ease);
}
#sendBtn:hover:not(:disabled) { background: var(--accent-strong); }
#sendBtn:active:not(:disabled) { transform: scale(.93); }
#sendBtn svg { width: 19px; height: 19px; }
#sendBtn.stop { background: var(--danger); }
.hint {
  text-align: center; font-size: 11.5px; color: var(--faint);
  padding: 8px 10px 0; user-select: none;
}
#composer.drag-over .inputwrap {
  border-color: var(--accent); border-style: dashed;
  background: var(--accent-soft);
}

/* ---------------- modals ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 14, 22, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 60;
  animation: fade .18s;
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 460px; max-height: min(84vh, 84dvh); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 22px; box-shadow: var(--shadow-lg);
  animation: rise .22s var(--ease);
}
.modal.wide { max-width: 620px; }
.modal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal .tip { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }

/* user management table */
.utable { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.utable th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.utable td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.utable tr:last-child td { border-bottom: 0; }
.utable .uactions { display: flex; gap: 4px; justify-content: flex-end; }
.utable .uactions .btn { padding: 4px 10px; font-size: 12.5px; }
.add-user-box { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 14px; }
.add-user-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* ---------------- toast ---------------- */
#toasts {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; translate: -50% 0;
  display: flex; flex-direction: column; gap: 8px; z-index: 80; pointer-events: none;
  width: max-content; max-width: min(90vw, 420px);
}
.toast {
  background: var(--ink); color: var(--bg);
  font-size: 13.5px; padding: 10px 18px; border-radius: 12px;
  box-shadow: var(--shadow-lg); text-align: center;
  animation: rise .22s var(--ease);
}
.toast.err { background: var(--danger); color: #fff; }

/* ---------------- backdrop (mobile drawer) ---------------- */
#backdrop {
  position: fixed; inset: 0; background: rgba(10, 14, 22, .45); z-index: 19;
  opacity: 0; pointer-events: none; transition: opacity .24s;
}

/* ---------------- responsive ---------------- */
@media (min-width: 901px) {
  #appView.side-collapsed #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
  #closeSideBtn { display: none; }
}

@media (max-width: 900px) {
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20;
    transform: translateX(-104%);
    box-shadow: none;
    width: min(84vw, 330px); flex-basis: auto;
    padding-top: env(safe-area-inset-top);
  }
  #appView.drawer-open #sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  #appView.drawer-open #backdrop { opacity: 1; pointer-events: auto; }
  .thread-inner { padding: 16px 14px 24px; }
  #composer { padding-left: 10px; padding-right: 10px; }
  .msg.user .bubble { max-width: 88%; }
  .suggest-grid { grid-template-columns: 1fr; }
  .model-chip { display: none; }
  .add-user-grid { grid-template-columns: 1fr; }
  #topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  .hint .desktop-hint { display: none; }
}
