/* X-Pert /chat 樣式（規格 docs/xpert-next.md §6.2、§16）。無 build。
 * 色票：§16 品牌色彩系統；字級／間距 token 命名參考 XPower-BPM app.scss（--fs-*、--sp-*）；
 * 泡泡參考 AiAssistantDrawer.vue；殼層與 iOS 鍵盤調校借 botUI style.css（:60-130、:2841-2870）。
 * 深淺色（v1.1）：<html data-theme="light|dark"> 驅動，由 theme.js 依 localStorage xpert.theme 設定（auto 時跟系統）。
 */

/* ── token ─────────────────────────────────────────────── */
:root {
  /* §16.2 */
  --brand-red: #cf1f29;
  --brand-red-dark: #a8181f;
  --data-slate: #475569;
  --data-slate-2: #64748b;
  --surface-dark: #090e17;
  --surface-dark-2: #0f172a;
  --surface-light: #ffffff;
  --surface-light-2: #f8fafc;

  /* 字級（XPower --fs-*） */
  --fs-xxs: 0.625rem;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-base: 0.9375rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --font: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  --font-mono: "Noto Sans Mono", Consolas, "SFMono-Regular", Menlo, monospace;

  /* 間距（botUI --sp-*） */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;

  --sidebar-width: 272px;
  --chat-max-width: 880px;
  --app-viewport-height: 100dvh;
  --ios-keyboard-offset: 0px;

  /* 語意色（淺色） */
  --bg-app: var(--surface-light-2);
  --bg-panel: var(--surface-light);
  --bg-sidebar: #f1f5f9;
  --bg-soft: #f1f5f9;
  --bg-hover: rgba(15, 23, 42, 0.05);
  --text: var(--surface-dark-2);
  --text-2: var(--data-slate);
  --text-mute: var(--data-slate-2);
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --bubble-user-bg: var(--data-slate);
  --bubble-user-text: #ffffff;
  --code-bg: #f1f5f9;
  --link: var(--brand-red);
  --accent-soft: rgba(207, 31, 41, 0.08);
  --ok: #15803d;
  --warn-bg: #fff7ed;
  --warn-border: #fdba74;
  --err-bg: #fef2f2;
  --err-border: #fca5a5;
  --err-text: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, 0.08);
  color-scheme: light;
}

/* 深色：data-theme 由 theme.js 設定（auto 時跟系統） */
:root[data-theme="dark"] {
  --bg-app: var(--surface-dark);
  --bg-panel: var(--surface-dark-2);
  --bg-sidebar: var(--surface-dark-2);
  --bg-soft: #1e293b;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --text: #f1f5f9;
  --text-2: #cbd5e1;
  --text-mute: #94a3b8;
  --border: #1e293b;
  --border-strong: #334155;
  --bubble-user-bg: var(--data-slate);
  --code-bg: #1e293b;
  --link: #f0646b;
  --accent-soft: rgba(207, 31, 41, 0.16);
  --ok: #4ade80;
  --warn-bg: #2a1d0e;
  --warn-border: #9a5b1a;
  --err-bg: #2a1215;
  --err-border: #7f1d1d;
  --err-text: #fca5a5;
  --shadow-sm: none;
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

/* ── base ──────────────────────────────────────────────── */
* { box-sizing: border-box; }
html { height: 100%; height: -webkit-fill-available; }
body {
  height: 100%;
  height: -webkit-fill-available;
  margin: 0;
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.6;
  overflow: hidden;
  position: fixed;
  width: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }
.material-icons { font-size: 20px; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-1);
  min-height: 36px; padding: 0 var(--sp-4);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-panel); color: var(--text);
  font-size: var(--fs-sm); line-height: 1.2;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn--primary { background: var(--brand-red); border-color: var(--brand-red); color: #fff; }
.btn--primary:hover { background: var(--brand-red-dark); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-2);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.boot { display: flex; height: 100%; align-items: center; justify-content: center; color: var(--text-mute); }

/* ── 登入畫面 ─────────────────────────────────────────── */
.login {
  display: flex; align-items: center; justify-content: center;
  height: var(--app-viewport-height, 100dvh);
  padding: var(--sp-4);
  overflow-y: auto;
}
.login__card {
  width: 100%; max-width: 380px;
  padding: var(--sp-8) var(--sp-6);
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  text-align: center;
}
.login__logo { height: 36px; width: auto; }
.login__customer { margin-top: var(--sp-3); color: var(--text-2); font-size: var(--fs-sm); min-height: 1.4em; }
.login__lead { margin: var(--sp-5) 0 var(--sp-6); color: var(--text-mute); font-size: var(--fs-sm); }
.login__btn { width: 100%; min-height: 44px; font-size: var(--fs-md); }
.login__form { display: flex; flex-direction: column; gap: var(--sp-3); text-align: left; }
.login__form label { display: flex; flex-direction: column; gap: var(--sp-1); font-size: var(--fs-sm); color: var(--text-2); }
.login__form input {
  min-height: 44px; padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-app); font-size: 16px; /* iOS 不自動放大 */
}
.login__form input:focus { outline: 2px solid var(--brand-red); outline-offset: -1px; }
.login__err { margin-top: var(--sp-4); color: var(--err-text); font-size: var(--fs-sm); min-height: 1.4em; }

/* ── 殼層 ─────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  height: 100dvh;
  height: var(--app-viewport-height, 100dvh);
  max-height: var(--app-viewport-height, 100dvh);
  overflow: hidden;
}

.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
}
.sidebar__head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-4) var(--sp-3); }
.sidebar__logo { height: 28px; width: auto; display: block; }
.sidebar__close { display: none; }
.sidebar__new { margin: 0 var(--sp-3) var(--sp-3); }
.conv-list { flex: 1; overflow-y: auto; padding: 0 var(--sp-2); overscroll-behavior: contain; }
.conv-empty { padding: var(--sp-3); color: var(--text-mute); font-size: var(--fs-sm); }
.conv-item {
  display: flex; align-items: center; gap: var(--sp-1);
  border-radius: var(--radius-md);
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.is-active { background: var(--accent-soft); }
.conv-item__open {
  flex: 1; min-width: 0; padding: var(--sp-2) var(--sp-3);
  border: 0; background: transparent; text-align: left;
  font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item.is-active .conv-item__open { font-weight: 600; }
.sidebar__foot {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.sidebar__user { flex: 1; min-width: 0; font-size: var(--fs-sm); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scrim { display: none; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-app); }
.chat-container { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat__top {
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: 52px; padding: var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border); background: var(--bg-panel);
}
.chat__title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__toplogo { display: none; height: 24px; width: auto; }
#menuBtn { display: none; }

.messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: var(--sp-5) var(--sp-4);
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}
.messages__inner { max-width: var(--chat-max-width); margin: 0 auto; }

/* 歡迎區（不是訊息，不送模型） */
.welcome { padding: 20vh 0 var(--sp-4); }  /* 空白狀態往下放到視線中上，像一般 AI 聊天的起始畫面；窄螢幕與 embed 另有覆寫 */
.welcome__hi { margin: 0 0 var(--sp-1); font-size: var(--fs-xl); font-weight: 700; }
.welcome__sub { margin: 0 0 var(--sp-5); color: var(--text-mute); font-size: var(--fs-sm); }
.skill-cards { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  padding: var(--sp-1) var(--sp-3);
  border: 1px solid var(--border); border-radius: 999px; background: var(--bg-panel);
  font-size: var(--fs-sm); color: var(--text); text-align: left; box-shadow: var(--shadow-sm);
}
.chip:hover { background: var(--accent-soft); color: var(--brand-red); border-color: var(--brand-red); }
.chip--more { background: transparent; border-style: dashed; color: var(--text-mute); box-shadow: none; }

/* ── 訊息 ─────────────────────────────────────────────── */
.msg-row { display: flex; flex-direction: column; margin-bottom: var(--sp-5); }
.msg-row.is-user { align-items: flex-end; }
.msg-row.is-assistant { align-items: stretch; }
.bubble { max-width: 88%; border-radius: var(--radius-lg); padding: var(--sp-2) var(--sp-3); word-break: break-word; overflow-wrap: anywhere; }
.is-user .bubble { background: var(--bubble-user-bg); color: var(--bubble-user-text); white-space: pre-wrap; }
.is-assistant .bubble {
  max-width: 100%; background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); padding: var(--sp-3) var(--sp-4);
}
.msg-actions { display: flex; gap: var(--sp-1); margin-top: var(--sp-1); min-height: 28px; }
.msg-actions .icon-btn { width: 28px; height: 28px; color: var(--text-mute); }
.msg-actions .icon-btn .material-icons { font-size: 16px; }
.is-user .msg-actions { opacity: 0; transition: opacity 0.15s; }
.is-user:hover .msg-actions, .is-user:focus-within .msg-actions { opacity: 1; }
.msg-actions__tip { font-size: var(--fs-xs); color: var(--text-mute); align-self: center; }

/* Markdown 內容 */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 var(--sp-2); }
.md ul, .md ol { margin: 0 0 var(--sp-2); padding-left: 1.4em; }
.md li + li { margin-top: 2px; }
.md h1, .md h2, .md h3, .md h4 { margin: var(--sp-4) 0 var(--sp-2); line-height: 1.35; }
.md h1 { font-size: var(--fs-lg); } .md h2 { font-size: 1.125rem; } .md h3, .md h4 { font-size: var(--fs-md); }
.md a { font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.md code { font-family: var(--font-mono); font-size: 0.85em; background: var(--code-bg); border-radius: 4px; padding: 0 4px; }
.md pre { margin: 0 0 var(--sp-2); padding: var(--sp-3); background: var(--code-bg); border-radius: var(--radius-md); overflow-x: auto; }
.md pre code { padding: 0; background: none; font-size: var(--fs-xs); }
.md blockquote { margin: 0 0 var(--sp-2); padding-left: var(--sp-3); border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-3) 0; }
.md img { max-width: 100%; height: auto; }
.md table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 0 0 var(--sp-2); font-size: var(--fs-sm); }
.md th, .md td { border: 1px solid var(--border-strong); padding: var(--sp-1) var(--sp-2); text-align: left; vertical-align: top; }
.md th { background: var(--bg-soft); font-weight: 600; white-space: nowrap; }
.md tr:nth-child(even) td { background: rgba(100, 116, 139, 0.05); }

/* 思考中三點（botUI ui.js:12-20） */
.thinking { display: inline-flex; gap: 5px; padding: var(--sp-2) 0; }
.thinking-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-mute); animation: think 1.2s infinite ease-in-out; }
.thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.thinking-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes think { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* 進度列（status tool 的 label） */
.progress { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-2); color: var(--text-mute); font-size: var(--fs-sm); }
.progress__dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-red); animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.75); } }

/* 「查了什麼」（tool 卡片；概念借 origin/main tool-calls.js） */
.tools { margin: 0 0 var(--sp-2); font-size: var(--fs-sm); }
.tools > summary { cursor: pointer; color: var(--text-mute); list-style: none; display: inline-flex; align-items: center; gap: 2px; }
.tools > summary::-webkit-details-marker { display: none; }
.tools > summary .material-icons { font-size: 18px; transition: transform 0.15s; }
.tools[open] > summary .material-icons { transform: rotate(90deg); }
.tools__list { margin-top: var(--sp-2); display: flex; flex-direction: column; gap: var(--sp-1); }
.toolcall { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-app); }
.toolcall > summary { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-1) var(--sp-3); cursor: pointer; list-style: none; }
.toolcall > summary::-webkit-details-marker { display: none; }
.toolcall__dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--brand-red); animation: pulse 1.2s infinite ease-in-out; }
.toolcall__icon { flex: none; font-size: 16px !important; color: var(--ok); }
.toolcall.is-fail .toolcall__icon { color: var(--err-text); }
.toolcall__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolcall__meta { flex: none; color: var(--text-mute); font-size: var(--fs-xs); font-family: var(--font-mono); }
.toolcall__body { margin: 0; padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--border); max-height: 240px; overflow: auto; font-family: var(--font-mono); font-size: var(--fs-xs); white-space: pre-wrap; word-break: break-all; color: var(--text-2); }

/* 確認卡片（§4.8） */
.confirm-card { margin-top: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--warn-border); background: var(--warn-bg); border-radius: var(--radius-md); }
.confirm-card__title { margin: 0 0 var(--sp-2); font-weight: 700; display: flex; align-items: center; gap: var(--sp-1); }
.confirm-card__title .material-icons { color: var(--brand-red); }
.confirm-card dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
.confirm-card dt { color: var(--text-mute); }
.confirm-card dd { margin: 0; min-width: 0; word-break: break-word; }
.confirm-card__body { max-height: 220px; overflow: auto; padding: var(--sp-2); background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-sm); white-space: pre-wrap; }
.confirm-card__body.is-html { white-space: normal; }
.confirm-card__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); }
.confirm-card__state { font-size: var(--fs-sm); color: var(--text-mute); }

.msg-error { margin-top: var(--sp-2); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--err-border); background: var(--err-bg); color: var(--err-text); border-radius: var(--radius-md); font-size: var(--fs-sm); }
.msg-note { margin-top: var(--sp-2); color: var(--text-mute); font-size: var(--fs-xs); }

/* ── 輸入列 ───────────────────────────────────────────── */
.composer-wrap { padding: var(--sp-2) var(--sp-4) calc(var(--sp-2) + env(safe-area-inset-bottom)); background: var(--bg-app); }
.composer {
  display: flex; align-items: flex-end; gap: var(--sp-2);
  max-width: var(--chat-max-width); margin: 0 auto;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4);
  background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.composer:focus-within { border-color: var(--data-slate-2); }
.composer textarea {
  flex: 1; min-width: 0; min-height: 40px; max-height: 200px; resize: none;
  padding: 9px 0; border: 0; outline: 0; background: transparent; line-height: 1.4;
  font-size: var(--fs-base);
}
.composer textarea:disabled { cursor: not-allowed; }
.composer .icon-btn { width: 40px; height: 40px; flex: none; }
#sendBtn { background: var(--brand-red); color: #fff; border-radius: var(--radius-full); }
#sendBtn:disabled { background: var(--border-strong); color: var(--text-mute); cursor: default; }
#stopBtn { background: var(--surface-dark-2); color: #fff; border-radius: var(--radius-full); }
.composer-note { max-width: var(--chat-max-width); margin: var(--sp-1) auto 0; text-align: center; font-size: var(--fs-xxs); color: var(--text-mute); }
.disabled-note { max-width: var(--chat-max-width); margin: 0 auto var(--sp-2); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--warn-border); background: var(--warn-bg); border-radius: var(--radius-md); font-size: var(--fs-sm); }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 50; max-width: calc(100% - 32px); padding: var(--sp-2) var(--sp-4);
  background: var(--surface-dark-2); color: #fff; border-radius: var(--radius-md); font-size: var(--fs-sm); box-shadow: var(--shadow-md);
}

/* ── 表格工具列（tables.js；搬自 DominoClaw useTableTools.js，CSS 原本不在該檔） ── */
.tbl-tools { margin: 0 0 var(--sp-3); max-width: 100%; }
.tbl-tools__bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1); margin-bottom: var(--sp-2); }
.tbl-tools__btn {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 28px; padding: 0 var(--sp-2);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg-panel); color: var(--text-2); font-size: var(--fs-xs);
}
.tbl-tools__btn:hover { background: var(--bg-hover); color: var(--text); }
.tbl-tools__btn .material-icons { font-size: 15px; }
.tbl-tools__btn--primary { border-color: var(--brand-red); color: var(--brand-red); }
.tbl-tools__btn.is-on { background: var(--data-slate); border-color: var(--data-slate); color: #fff; }
.tbl-tools__types { display: inline-flex; gap: 2px; }
.tbl-tools__chart { position: relative; height: 280px; margin-bottom: var(--sp-2); }
.tbl-tools__chart canvas { max-width: 100%; }

/* ── 手機（botUI 斷點 820；寬 ≥360 可操作） ───────────── */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; top: 0; bottom: 0; left: 0;
    width: min(84vw, var(--sidebar-width));
    transform: translateX(-102%); transition: transform 0.22s ease-out;
    box-shadow: var(--shadow-md);
  }
  body.drawer-open .sidebar { transform: translateX(0); }
  body.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(9, 14, 23, 0.45); }
  .sidebar__close { display: inline-flex; }
  #menuBtn { display: inline-flex; }
  .chat__toplogo { display: block; }
  .chat__title { font-size: var(--fs-sm); color: var(--text-2); font-weight: 400; text-align: right; }
}
@media (max-width: 640px) {
  .messages { padding: var(--sp-4) var(--sp-3); }
  .composer-wrap { padding-left: var(--sp-2); padding-right: var(--sp-2); }
  .bubble { max-width: 92%; }
  .is-assistant .bubble { padding: var(--sp-2) var(--sp-3); }
  .welcome { padding-top: var(--sp-2); }
  .tbl-tools__chart { height: 240px; }
}
/* 觸控裝置：輸入框 16px 避免 iOS 自動放大（botUI style.css:2766-2800）；按鈕放大、使用者訊息動作常駐 */
@media (hover: none), (pointer: coarse), (max-width: 768px) {
  .composer textarea { font-size: 16px; }
  .is-user .msg-actions { opacity: 1; }
  .msg-actions .icon-btn { width: 36px; height: 36px; }
}

/* ── iOS 鍵盤（botUI style.css:2841-2870；JS 在 app.js syncAppViewportHeight） ── */
body.ios-keyboard-open .chat { overflow: hidden; }
body.ios-keyboard-open .chat-container {
  transform: translateY(calc(-1 * var(--ios-keyboard-offset)));
  transition: transform 0.15s ease-out;
}
body.ios-keyboard-open .messages { max-height: calc(100% - var(--ios-keyboard-offset)); }
body:not(.ios-keyboard-open) .chat-container { transform: translateY(0); transition: transform 0.2s ease-out; }

/* ══ v1.1（§6.1 中欄）與 embed=1（§13） ═════════════════════ */

/* 深淺 logo：兩張 img 都在 DOM，依 data-theme 只顯示一張（<picture media> 不會跟手動切換） */
:root[data-theme="dark"] .logo-l, :root:not([data-theme="dark"]) .logo-d { display: none !important; }

/* 頂欄右側：模型下拉、主題切換 */
.chat__tools { display: flex; align-items: center; gap: var(--sp-1); flex: none; }
.profile-sel {
  max-width: 180px; min-height: 32px; padding: 0 var(--sp-2);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--bg-panel); color: var(--text); font-size: var(--fs-xs);
}

/* 對話搜尋、⋯ 選單、改名 */
.conv-search {
  display: flex; align-items: center; gap: var(--sp-1);
  margin: 0 var(--sp-3) var(--sp-2); padding: 0 var(--sp-2);
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-panel);
}
.conv-search .material-icons { font-size: 18px; color: var(--text-mute); }
.conv-search input { flex: 1; min-width: 0; min-height: 32px; border: 0; outline: 0; background: transparent; font-size: var(--fs-sm); }
.conv-item { position: relative; }
.conv-item__more { opacity: 0; width: 32px; height: 32px; }
.conv-item:hover .conv-item__more, .conv-item.is-active .conv-item__more, .conv-item__more[aria-expanded="true"] { opacity: 1; }
.conv-item__more .material-icons { font-size: 18px; }
.conv-item__rename {
  flex: 1; min-width: 0; margin: 2px; padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--brand-red); border-radius: var(--radius-sm); background: var(--bg-panel); font-size: var(--fs-sm);
}
.conv-menu {
  position: absolute; right: 4px; top: 34px; z-index: 20; min-width: 120px; padding: var(--sp-1);
  background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
}
.conv-menu button {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; padding: var(--sp-1) var(--sp-2);
  border: 0; border-radius: var(--radius-sm); background: transparent; text-align: left; font-size: var(--fs-sm);
}
.conv-menu button:hover { background: var(--bg-hover); }
.conv-menu .material-icons { font-size: 18px; color: var(--text-mute); }
.conv-menu .is-danger { color: var(--err-text); }
.conv-hit { padding: 0 var(--sp-3) var(--sp-1); margin-top: -4px; font-size: var(--fs-xxs); color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 待送附件列、縮圖、檔案標籤 */
.tray {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  max-width: var(--chat-max-width); margin: 0 auto var(--sp-2);
}
.tray__item { position: relative; display: inline-flex; }
.tray__x {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0;
  border: 0; border-radius: 50%; background: var(--surface-dark-2); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.tray__x .material-icons { font-size: 14px; }
.tray__item.is-busy { opacity: 0.6; }
.thumbs { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.thumb {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px; padding: 0; overflow: hidden;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-soft);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.is-loading { animation: pulse 1.2s infinite ease-in-out; }
.thumb.is-missing { width: auto; padding: 0 var(--sp-2); font-size: var(--fs-xxs); color: var(--text-mute); }
.file-chip {
  display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
  min-height: 32px; padding: 0 var(--sp-3) 0 var(--sp-2);
  border: 1px solid var(--border-strong); border-radius: var(--radius-full); background: var(--bg-panel); color: var(--text);
  font-size: var(--fs-sm);
}
.file-chip .material-icons { font-size: 16px; color: var(--text-mute); }
.file-chip__name { min-width: 0; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip__meta { flex: none; color: var(--text-mute); font-size: var(--fs-xs); }
.msg-attach { display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-1); margin-bottom: var(--sp-1); max-width: 88%; }
.msg-attach .thumbs { justify-content: flex-end; }

/* 輸入列兩側小鈕、錄音中 */
.composer { padding-left: var(--sp-2); }
.composer textarea { padding-left: var(--sp-2); }
.composer .composer__side { width: 36px; height: 40px; }
#micBtn.is-rec { color: #fff; background: var(--brand-red); border-radius: var(--radius-full); animation: pulse 1.2s infinite ease-in-out; }

/* 「正在看」（embed context） */
.ctx-chip {
  display: flex; align-items: center; gap: var(--sp-1);
  max-width: var(--chat-max-width); margin: 0 auto var(--sp-2); padding: 0 0 0 var(--sp-2);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-md); color: var(--text-2); font-size: var(--fs-xs);
}
.ctx-chip .material-icons { font-size: 16px; }
.ctx-chip__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-chip .icon-btn { width: 28px; height: 28px; }

/* 回答動作列：播放／👍👎 按下狀態 */
.msg-actions .icon-btn.is-on { color: var(--brand-red); }
.msg-actions .icon-btn:disabled { opacity: 0.5; cursor: default; }

/* 拖放覆蓋層（botUI events.js:226-245 的概念） */
.chat { position: relative; }
.drop-overlay {
  position: absolute; inset: 8px; z-index: 25; display: flex; align-items: center; justify-content: center;
  border: 2px dashed var(--brand-red); border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--bg-app) 88%, transparent); color: var(--brand-red); font-weight: 600; pointer-events: none;
}
.drop-overlay > span { display: inline-flex; align-items: center; gap: var(--sp-2); }

/* 圖片預覽 */
.lightbox { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(9, 14, 23, 0.85); }
.lightbox__img { max-width: calc(100% - 96px); max-height: calc(100% - 96px); border-radius: var(--radius-md); background: #fff; }
.lightbox .icon-btn { position: absolute; color: #fff; background: rgba(255, 255, 255, 0.12); }
.lightbox .icon-btn:hover { background: rgba(255, 255, 255, 0.24); color: #fff; }
.lightbox__close { top: 16px; right: 16px; }
.lightbox__nav { top: 50%; transform: translateY(-50%); }
.lightbox__nav.is-prev { left: 12px; }
.lightbox__nav.is-next { right: 12px; }

@media (max-width: 640px) {
  .profile-sel { max-width: 120px; }
  .chat__title { display: none; }
  .file-chip__name { max-width: 160px; }
}
@media (hover: none), (pointer: coarse), (max-width: 768px) {
  .conv-item__more { opacity: 1; }
}

/* embed=1：隱藏側欄、對話清單、歡迎大標；只留單一對話（§13） */
body.is-embed .sidebar, body.is-embed .scrim, body.is-embed #menuBtn, body.is-embed .welcome__hi { display: none !important; }
body.is-embed .app { grid-template-columns: 1fr; }
body.is-embed .chat__toplogo { display: block; height: 22px; }
body.is-embed .chat__title { font-size: var(--fs-sm); color: var(--text-2); font-weight: 400; }
body.is-embed .messages { padding: var(--sp-3); }
body.is-embed .welcome { padding-top: var(--sp-2); }
/* 側邊欄小畫面：只留一句「問這個畫面的事」，不放 skill 卡片 */
body.is-embed .skill-cards { display: none !important; }
body.is-embed .welcome { padding-top: 32vh; text-align: center; }
body.is-embed .welcome__sub { font-size: var(--fs-base); }
body.is-embed .composer-wrap { padding-left: var(--sp-2); padding-right: var(--sp-2); }

/* 側欄底部：管理員才看得到的嵌入示範連結 */
.sidebar__admin { display: flex; align-items: center; gap: 6px; margin: 0 var(--sp-3) var(--sp-2); padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-mute); font-size: var(--fs-sm); text-decoration: none; }
.sidebar__admin:hover { background: var(--bg-soft); color: var(--brand-red); }
.sidebar__admin[hidden] { display: none; }
.sidebar__admin .material-icons { font-size: 18px; }

/* 登入頁：OAuth 模式下的「用其他帳號登入」 */
.login__other { margin-top: var(--sp-2); border: 0; background: none; color: var(--text-mute); font-size: var(--fs-sm); text-decoration: underline; cursor: pointer; }
.login__other:hover { color: var(--brand-red); }
.login__other[hidden] { display: none; }
/* OAuth 鈕下面展開帳密表單時，用分隔線分開兩種登入 */
.login__btn:not([hidden]) + .login__form { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
/* OAuth 模式：帳密表單的按鈕改次要樣式（外框），跟上面主要的 OAuth 鈕分得出來 */
.login__btn:not([hidden]) + .login__form .btn--primary { background: transparent; color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.login__btn:not([hidden]) + .login__form .btn--primary:hover { border-color: var(--brand-red); color: var(--brand-red); background: transparent; }
/* 對話清單：置頂圖示、側邊欄標籤 */
.conv-item__pin { font-size: 14px; margin-right: 4px; vertical-align: -2px; color: var(--brand-red); }
.conv-item__tag { margin-left: 6px; padding: 0 6px; border-radius: 999px; background: var(--bg-soft); color: var(--text-mute); font-size: 11px; }

/* 標題列「⋮」選單、標題改名 */
.chat__tools { position: relative; }
.conv-menu--top { top: 40px; right: 0; min-width: 170px; }
.chat__rename { flex: 1; min-width: 0; font: inherit; font-weight: 600; padding: 2px 6px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg-panel); color: var(--text); }

/* 下載 PDF＝瀏覽器列印存成 PDF：只留對話內容 */
@media print {
  .sidebar, .scrim, .chat__tools, #menuBtn, .composer-wrap, .msg-actions, .ctx-chip, .sidebar__admin, .toast { display: none !important; }
  body, .app, .chat, .chat-container, .messages { height: auto !important; overflow: visible !important; background: #fff !important; color: #000 !important; }
  .app { display: block !important; }
  .msg, .msg * { color: #000 !important; }
  .msg { break-inside: avoid-page; }
}

/* Claude 風格：輸入框上面打字、下面一列工具（左＋／麥克風，右模型／送出） */
.composer--stack { flex-direction: column; align-items: stretch; gap: 0; padding: var(--sp-2) var(--sp-2) var(--sp-1) var(--sp-3); }
.composer--stack textarea { width: 100%; padding: 6px 4px; }
.composer__bar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.composer__group { display: flex; align-items: center; gap: 2px; }
.composer--stack .icon-btn { width: 36px; height: 36px; }
.composer--stack .profile-sel { border: 0; background: transparent; color: var(--text-mute); font-size: var(--fs-xs); max-width: 200px; cursor: pointer; }
.composer--stack .profile-sel:hover { color: var(--text); }
/* 標題列：標題可點（⌄ 選單）、右邊「分享」 */
.chat__titlebtn { display: flex; align-items: center; gap: 2px; min-width: 0; padding: 4px 8px; border: 0; border-radius: var(--radius-sm); background: transparent; color: inherit; cursor: pointer; }
.chat__titlebtn:hover { background: var(--bg-hover); }
.chat__titlebtn .chat__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat__caret { font-size: 18px; color: var(--text-mute); }
.chat__share { padding: 4px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-panel); font-size: var(--fs-sm); }
.chat__share[hidden] { display: none; }
.conv-menu--top { left: 0; right: auto; }
.chat__top { position: relative; }
/* 側欄：已釘選／最近 分區標題 */
.conv-section { padding: var(--sp-3) var(--sp-3) var(--sp-1); font-size: var(--fs-xxs); color: var(--text-mute); letter-spacing: .04em; }
/* 側邊欄小畫面：標題列只留標題、模型移到輸入框下，跟一般頁一致 */
body.is-embed .chat__titlebtn { pointer-events: none; }
body.is-embed .composer--stack .profile-sel { max-width: 140px; }

/* 分享對話框 */
.share-ov { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; background: rgba(0,0,0,.45); }
.share-dlg { position: relative; width: 100%; max-width: 520px; max-height: 80vh; overflow: auto; padding: var(--sp-4); background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.share-dlg__close { position: absolute; top: 8px; right: 8px; }
.share-dlg__title { margin: 0 0 var(--sp-2); font-size: var(--fs-lg); }
.share-dlg__note { margin: 0 0 var(--sp-3); color: var(--text-mute); font-size: var(--fs-sm); }
.share-inp, .share-link { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-app); color: var(--text); font: inherit; }
.share-people { display: flex; flex-direction: column; margin: 4px 0 var(--sp-3); }
.share-person { text-align: left; padding: 6px 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); font-size: var(--fs-sm); cursor: pointer; }
.share-person:hover { background: var(--bg-hover); }
.share-person--group { color: var(--text-mute); }
.share-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--sp-2); }
.share-chip { display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 10px; border-radius: 999px; background: var(--bg-soft); font-size: var(--fs-sm); }
.share-chip .icon-btn { width: 22px; height: 22px; }
.share-chip .material-icons { font-size: 14px; }
.share-msg { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); font-size: var(--fs-sm); }
.share-msg .share-link { flex: 1 1 100%; }
.share-tip { color: var(--text-mute); }
.share-row { display: flex; align-items: center; gap: var(--sp-2); padding: 6px 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.share-row__who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn--danger { color: var(--err-text); }
/* 看別人分享的快照 */
.share-banner { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); max-width: var(--chat-max-width); margin: var(--sp-2) auto 0; padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-soft); font-size: var(--fs-sm); }

/* 左下角帳號選單（仿 Claude） */
.sidebar__foot { position: relative; }
.acct-btn { display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-width: 0; padding: 6px 8px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.acct-btn:hover { background: var(--bg-hover); }
.acct-avatar { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand-red); color: #fff; font-size: var(--fs-sm); font-weight: 600; }
.acct-text { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px; }
.acct-role { flex: none; font-size: var(--fs-xxs); color: var(--text-mute); }
.acct-caret { font-size: 18px; color: var(--text-mute); }
.acct-menu { top: auto; bottom: calc(100% + 4px); left: 8px; right: 8px; min-width: 0; }
.acct-menu__head { padding: 6px 8px; font-size: var(--fs-xxs); color: var(--text-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-menu__sep { height: 1px; margin: 4px 0; background: var(--border); }
.acct-menu__check { margin-left: auto; color: var(--brand-red) !important; }
/* 外觀切換移到帳號選單；只有側邊欄小畫面（沒有左側欄）才在標題列留按鈕 */
body:not(.is-embed) #themeBtn { display: none; }

/* 標題在左、分享／⋯ 靠右 */
.chat__tools { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }
.conv-menu--right { top: 40px; right: 0; left: auto; min-width: 170px; }

.share-person { display: flex; align-items: center; gap: 6px; }
.share-person .material-icons { font-size: 18px; color: var(--text-mute); }
.share-empty { padding: 6px 10px; font-size: var(--fs-sm); color: var(--text-mute); }
.share-confirm { width: 100%; padding: var(--sp-3); border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--bg-soft); }
.share-confirm p { margin: 0 0 var(--sp-2); }
.share-confirm .btn { margin-right: var(--sp-2); }
