/* MAHORA · 墨绿品牌 + 冷灰绿中性面（弃用暖黄象牙） */
:root {
  --mahora-red: #a62c21;
  --mahora-red-shadow: rgba(166, 44, 33, 0.18);

  --bg: #f2f5f4;
  --bg-grad: linear-gradient(175deg, #f4f6f5 0%, #eef2f0 52%, #e8edea 100%);
  --bg-atmosphere: radial-gradient(ellipse 68% 50% at 62% 0%, rgba(36, 56, 50, 0.05), transparent 70%);

  --ink: #1e2622;
  --ink-soft: rgba(30, 38, 34, 0.88);
  --ink-muted: rgba(36, 50, 44, 0.52);

  --surface: #ffffff;
  --surface-muted: #f2f5f3;
  --surface-hover: rgba(36, 56, 50, 0.05);
  --surface-elevated: #ffffff;
  --surface-frost: rgba(255, 255, 255, 0.72);
  --surface-select: rgba(36, 56, 50, 0.07);

  --accent: #243832;
  --accent-hover: #2f4a42;
  --accent-grad: linear-gradient(135deg, #384840 0%, #243832 100%);
  --accent-shadow: rgba(32, 40, 36, 0.22);
  --accent-dim: rgba(36, 56, 50, 0.07);
  --accent-muted: rgba(36, 56, 50, 0.14);
  --accent-fg-soft: #3d5650;
  --on-accent: #eef4f1;

  --border: rgba(36, 56, 50, 0.12);
  --border-strong: rgba(36, 56, 50, 0.18);
  --border-soft: rgba(36, 56, 50, 0.1);
  --border-faint: rgba(36, 56, 50, 0.07);
  --border-frost: rgba(36, 56, 50, 0.08);

  --err: #be123c;
  --err-bg: #fef2f2;
  --ok: #2f6b5a;
  --ok-bg: rgba(47, 107, 90, 0.1);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pane: 18px;
  --radius-pill: 999px;

  --sidebar-w: 252px;
  --artifact-w: 360px;
  --chat-max: 680px;
  --app-pad: 10px;

  --shadow-soft: 0 1px 2px rgba(36, 42, 38, 0.05), 0 1px 1px rgba(36, 42, 38, 0.04);
  --shadow-md: 0 4px 10px rgba(36, 42, 38, 0.07), 0 1px 3px rgba(36, 42, 38, 0.05);
  --shadow-lg: 0 10px 24px rgba(36, 42, 38, 0.08), 0 4px 10px rgba(36, 42, 38, 0.04);
  --shadow-card: 0 10px 28px rgba(36, 42, 38, 0.07), 0 2px 6px rgba(36, 42, 38, 0.04);
  --inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  --inset-ring: inset 0 0 0 1px var(--border-faint);

  --font-ui: "Noto Sans SC", "Inter", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Menlo", ui-monospace, monospace;

  /* 字号：全局略收一档 */
  --fs-meta: 0.72rem;
  --fs-ui: 0.85rem;
  --fs-body: 0.9375rem;
  --fs-chat: 0.9375rem;
  --fs-title: 1.15rem;

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  --lh-tight: 1.25;
  --lh-snug: 1.4;
  --lh-body: 1.55;
  --lh-chat: 1.62;

  --t-fast: 120ms;
  --t-ease: cubic-bezier(0.4, 0, 0.2, 1);

  /* legacy aliases */
  --text: var(--ink);
  --text-secondary: var(--ink-soft);
  --text-muted: var(--ink-muted);
  --pane: rgba(255, 255, 255, 0.72);
  --pane-solid: var(--surface);
  --pane-hover: var(--surface-hover);
  --well: var(--surface-muted);
  --surface-raised: var(--surface);
  --bg-elevated: var(--pane);
  --border-hair: var(--border-soft);
  --fs-2xs: var(--fs-meta);
  --fs-xs: var(--fs-meta);
  --fs-sm: var(--fs-ui);
  --fs-base: var(--fs-body);
  --fs-md: var(--fs-chat);
  --fs-lg: 1rem;
  --fs-xl: var(--fs-title);
  --lh-normal: var(--lh-body);
  --lh-relaxed: var(--lh-chat);
  --radius: var(--radius-md);
  --radius-ui: var(--radius-md);
  --shadow-pane: var(--shadow-soft);
  --tab-selected: var(--accent);
  --chip-bg: var(--surface-muted);
  --chip-border: var(--border);
  --user-bubble: var(--surface-muted);
  --err-border: #fecdd3;
  --ok-border: rgba(47, 107, 90, 0.22);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  color: var(--text);
  background: var(--bg-grad);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

body {
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--bg-atmosphere);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }

.app {
  display: flex;
  gap: var(--app-pad);
  height: 100dvh;
  padding: var(--app-pad);
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.pane {
  background: var(--surface-elevated);
  border: 1px solid var(--border-frost);
  border-radius: var(--radius-pane);
  box-shadow: var(--shadow-soft), var(--inset-highlight);
}

/* —— Sidebar —— */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 0.9rem 0.7rem;
  z-index: 40;
}

.brand {
  display: flex;
  gap: 0.65rem;
  align-items: center;
  padding: 0.25rem 0.4rem 0.85rem;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 8px var(--mahora-red-shadow);
}

.brand strong {
  display: block;
  font-size: var(--fs-ui);
  font-weight: var(--fw-semibold);
  color: var(--ink);
}

.brand span {
  font-size: var(--fs-meta);
  color: var(--ink-muted);
}

.new-chat-btn {
  width: 100%;
  margin-bottom: 0.65rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-ui);
  background: var(--accent-dim);
  color: var(--accent);
  cursor: pointer;
  font-size: var(--fs-ui);
  font-weight: var(--fw-medium);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.new-chat-btn:hover {
  background: rgba(36, 56, 50, 0.1);
  border-color: var(--accent-muted);
}

.section-label {
  display: none;
}

.conv-list-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 0.35rem;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}

.conv-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.conv-item {
  width: 100%;
  text-align: left;
  padding: 0.38rem 0.45rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-muted);
  font-size: var(--fs-ui);
  line-height: var(--lh-snug);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.12s ease, background 0.12s ease;
}

.conv-item:hover {
  background: var(--surface-hover);
  color: var(--ink-soft);
}

.conv-item.active {
  background: var(--accent-dim);
  color: var(--ink);
  font-weight: var(--fw-medium);
  box-shadow: inset 2px 0 0 var(--accent);
  padding-left: calc(0.45rem - 2px);
}

.conv-group-label {
  font-size: var(--fs-meta);
  color: var(--accent-fg-soft);
  margin: 0.65rem 0.45rem 0.2rem;
  padding-top: 0;
  font-weight: var(--fw-medium);
  letter-spacing: 0.04em;
  opacity: 0.75;
}

.conv-group-label:first-child {
  margin-top: 0;
  padding-top: 0;
}

.conv-empty {
  padding: 0.65rem 0.5rem;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  line-height: var(--lh-relaxed);
  text-align: left;
}

.conv-files-wrap {
  flex: 0 0 auto;
  max-height: 200px;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  margin: 0.35rem 0 0.5rem;
  padding: 0.45rem 0.35rem 0.35rem;
  border-top: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.35);
  border-radius: 10px;
}

.conv-files-label {
  display: block;
  font-size: var(--fs-meta);
  color: var(--accent-fg-soft);
  margin: 0 0.2rem 0.35rem;
  font-weight: var(--fw-medium);
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.conv-files-empty {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  padding: 0.25rem 0.35rem 0.4rem;
  margin: 0;
}

.conv-files {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.conv-file-item {
  width: 100%;
}

.conv-file-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.4rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
  font-size: var(--fs-xs);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.conv-file-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-soft);
}

.conv-file-thumb {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border-soft);
}

.conv-file-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--accent-dim);
  color: var(--accent-fg);
  font-size: 0.72rem;
  font-weight: var(--fw-medium);
}

.conv-file-meta {
  min-width: 0;
  flex: 1;
}

.conv-file-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.conv-file-sub {
  display: block;
  color: var(--text-muted);
  font-size: 0.68rem;
  margin-top: 0.1rem;
}

.msg-files {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.msg-file {
  display: block;
  text-decoration: none;
  color: inherit;
}

.msg-file-image img {
  display: block;
  max-width: min(100%, 320px);
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  cursor: zoom-in;
}

.msg-file-cap {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.msg-file-doc {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
  background: var(--accent-dim);
  font-size: var(--fs-xs);
  border: 1px solid var(--border-soft);
}

.composer-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0 0.15rem 0.35rem;
}

.composer-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-dim);
  font-size: var(--fs-xs);
  color: var(--ink-soft);
}

.composer-attach-chip button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
}

.attach-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--text-muted);
}

.attach-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.tools-drawer {
  margin-top: auto;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.tools-drawer > summary {
  list-style: none;
}

.tools-drawer > summary::-webkit-details-marker {
  display: none;
}

.tools-drawer[open] > summary .sidebar-row-chevron {
  transform: rotate(90deg);
}

.tools-nav {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.15rem 0 0.25rem 1.65rem;
}

.tool-link {
  text-align: left;
  padding: 0.38rem 0.45rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: var(--fs-ui);
  transition: background 0.12s ease, color 0.12s ease;
}

.tool-link:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

.sidebar-foot {
  padding-top: 0.35rem;
  border-top: 1px solid var(--border-faint);
  margin-top: 0.25rem;
}

.sidebar-row-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.45rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: var(--fs-ui);
  font-family: inherit;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-row-btn:hover,
.sidebar-row-btn.is-open {
  background: var(--surface-hover);
  color: var(--ink);
}

.sidebar-row-icon {
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--accent-fg-soft);
  opacity: 0.85;
}

.sidebar-row-btn:hover .sidebar-row-icon,
.sidebar-row-btn.is-open .sidebar-row-icon {
  color: var(--accent);
  opacity: 1;
}

.sidebar-row-label {
  flex: 1;
  min-width: 0;
}

.sidebar-row-chevron {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--ink-muted);
  opacity: 0.55;
  transition: transform 0.15s ease, opacity 0.12s ease;
}

.sidebar-row-btn.is-open .sidebar-row-chevron {
  transform: rotate(90deg);
  opacity: 0.85;
}

.settings-panel {
  padding: 0.45rem 0 0.15rem;
}

.settings-panel.hidden {
  display: none;
}

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem;
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  border: 1px solid var(--border-faint);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field-label {
  font-size: var(--fs-meta);
  font-weight: var(--fw-medium);
  color: var(--accent-fg-soft);
  letter-spacing: 0.02em;
}

.settings-card input,
.settings-card select {
  width: 100%;
  padding: 0.48rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border-faint);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-ui);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.field-select {
  appearance: none;
  padding-right: 1.75rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%233d5650' d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
}

.settings-card input:focus,
.settings-card select:focus {
  outline: none;
  border-color: var(--accent-muted);
  box-shadow: 0 0 0 3px rgba(36, 56, 50, 0.08);
}

.settings-save {
  width: 100%;
  margin-top: 0.15rem;
  padding: 0.52rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: var(--accent-grad);
  color: var(--on-accent);
  font-size: var(--fs-ui);
  font-weight: var(--fw-medium);
  cursor: pointer;
  box-shadow: 0 2px 6px var(--accent-shadow);
  transition: box-shadow 0.12s ease;
}

.settings-save:hover {
  box-shadow: 0 4px 10px var(--accent-shadow);
}

.settings input,
.settings select,
.tool-panel input,
.tool-panel textarea {
  width: 100%;
  padding: 0.52rem 0.62rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  font-size: var(--fs-sm);
}

.settings input:focus,
.settings select:focus,
.tool-panel input:focus,
.tool-panel textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 56, 50, 0.12);
}

.tool-panel button,
.search-row button {
  padding: 0.52rem 0.95rem;
  border: none;
  border-radius: 10px;
  background: var(--accent-grad);
  color: #eef4f1;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  box-shadow: 0 2px 8px var(--accent-shadow);
  transition: box-shadow 0.12s ease, transform 0.12s ease;
}

.tool-panel button:hover,
.search-row button:hover {
  box-shadow: 0 4px 12px var(--accent-shadow);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(30, 38, 32, 0.38);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 30;
}

.sidebar-backdrop:not(.hidden) { display: block; }

/* —— Main —— */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  overflow: hidden;
  background: var(--surface);
}

.main:has(#view-chat.active) .topbar {
  position: absolute;
  inset: 0.85rem 1rem auto auto;
  width: auto;
  height: auto;
  padding: 0;
  z-index: 3;
  pointer-events: none;
}

.main:has(#view-chat.active) .topbar-title,
.main:has(#view-chat.active) .menu-btn,
.main:has(#view-chat.active) .back-chat {
  display: none;
}

.main:has(#view-chat.active) .conn-badge {
  pointer-events: auto;
}

.topbar-title { flex: 1; min-width: 0; }

.topbar {
  height: 52px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0 1.1rem;
  background: transparent;
}

.menu-btn,
.back-chat,
.icon-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--radius-ui);
  background: var(--well);
  color: var(--ink);
  cursor: pointer;
  box-shadow: none;
}

.menu-btn,
.back-chat { display: none; }

.topbar-title h1 {
  margin: 0;
  font-size: var(--fs-body);
  font-weight: var(--fw-semibold);
  color: var(--ink);
}

.topbar-title p:not(.hidden) {
  margin: 0.1rem 0 0;
  font-size: var(--fs-meta);
  color: var(--ink-muted);
}

.conn-badge {
  font-size: var(--fs-meta);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  color: var(--ink-muted);
  background: var(--well);
  flex-shrink: 0;
}

.conn-badge.ok {
  color: var(--ok);
  background: var(--ok-bg);
}

.conn-badge.err {
  color: var(--err);
  background: var(--err-bg);
}

.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  min-width: 0;
}

.workspace-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.view.active { display: flex; }

.view-chat {
  min-height: 0;
}

.view-tools {
  overflow: auto;
  padding: 1rem;
}

.tool-panel {
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  box-shadow: var(--shadow-soft);
}

.tool-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.tool-head h2 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
}

.search-row {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0 0.75rem;
  align-items: center;
}

.search-row input { flex: 1; }

.panel-desc {
  color: var(--text-secondary);
  font-size: var(--fs-base);
  line-height: var(--lh-relaxed);
}

.result-list,
.card-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.result-list li,
.card-list li {
  background: var(--surface-raised);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 0.75rem;
  margin-bottom: 0.45rem;
  font-size: var(--fs-sm);
}

.card-list .actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.4rem;
}

.card-list .reject {
  background: var(--err);
  color: #fff;
  box-shadow: none;
}

.table-wrap { overflow-x: auto; }

#auditTable {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-xs);
}

#auditTable th,
#auditTable td {
  border-bottom: 1px solid var(--border-soft);
  padding: 0.48rem;
  text-align: left;
}

#auditTable thead th {
  color: var(--accent-fg-soft);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-2xs);
  background: var(--accent-dim);
}

/* —— Chat —— */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem 1rem;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.messages:has(.welcome:not(.hidden)) {
  justify-content: center;
}

.welcome {
  width: 100%;
  max-width: var(--chat-max);
  text-align: center;
  padding: 0 0 1rem;
}

.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.welcome-logo {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  object-fit: cover;
  margin-bottom: 1.1rem;
  box-shadow: 0 4px 14px var(--mahora-red-shadow);
}

.welcome-card h2 {
  margin: 0 0 0.4rem;
  font-size: var(--fs-title);
  font-weight: var(--fw-bold);
  color: var(--ink);
  line-height: var(--lh-tight);
  letter-spacing: -0.01em;
}

.welcome-lead {
  margin: 0 0 1.25rem;
  color: var(--ink-muted);
  font-size: var(--fs-ui);
  line-height: var(--lh-snug);
}

.chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  width: 100%;
  text-align: left;
}

.chip {
  padding: 0.62rem 0.85rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-faint);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: var(--fs-ui);
  line-height: var(--lh-snug);
  cursor: pointer;
  transition: background var(--t-fast) var(--t-ease), border-color var(--t-fast) var(--t-ease), color var(--t-fast) var(--t-ease);
}

.chip:hover {
  background: var(--accent-dim);
  border-color: var(--accent-muted);
  color: var(--ink);
}

.msg {
  display: flex;
  width: 100%;
  max-width: var(--chat-max);
  margin-bottom: 1.75rem;
  animation: fadeUp 0.2s ease;
}

.msg.assistant {
  align-self: flex-start;
}

.msg.user {
  align-self: flex-end;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  margin-top: 3px;
}

.msg.user .msg-avatar {
  background: var(--accent-dim);
  color: var(--accent);
  margin-left: 0.55rem;
  border: 1px solid rgba(36, 56, 50, 0.12);
}

.msg.assistant .msg-avatar {
  padding: 0;
  overflow: hidden;
  background: transparent;
  margin-right: 0.55rem;
  box-shadow: 0 2px 6px var(--mahora-red-shadow);
}

.msg.assistant .msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.msg-body {
  min-width: 0;
  max-width: min(100%, 720px);
}

.msg-bubble {
  padding: 0;
  line-height: var(--lh-chat);
  font-size: var(--fs-chat);
}

.msg.user .msg-bubble {
  padding: 0.45rem 0.75rem;
  background: var(--accent-dim);
  border: none;
  border-radius: 10px;
  line-height: var(--lh-snug);
  white-space: pre-wrap;
}

.msg.assistant .msg-bubble {
  background: transparent;
  padding: 0;
}

.msg.assistant.streaming .msg-bubble {
  /* streaming: no extra border in doc mode */
}

.md-body :is(h1, h2, h3) {
  margin: 1.6rem 0 0.55rem;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  color: var(--ink);
  letter-spacing: -0.015em;
}

.md-body :is(h1, h2, h3):first-child {
  margin-top: 0;
}

.md-body h2 { font-size: 1.05rem; }
.md-body h3 { font-size: var(--fs-base); font-weight: var(--fw-medium); }

.md-body p {
  margin: 0.55rem 0;
  color: var(--ink-soft);
}

.md-body ul,
.md-body ol {
  margin: 0.45rem 0 0.75rem;
  padding-left: 1.4rem;
}

.md-body li {
  margin: 0.3rem 0;
}

.md-body li::marker {
  color: var(--ink-muted);
}

.md-body p:first-child { margin-top: 0; }
.md-body p:last-child { margin-bottom: 0; }

.md-body strong {
  font-weight: var(--fw-semibold);
  color: var(--ink);
}

.md-body hr {
  border: none;
  border-top: 1px solid var(--border-faint);
  margin: 1.25rem 0;
}

.md-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-ui);
  margin: 0.85rem 0 1rem;
  line-height: var(--lh-snug);
}

.md-body th,
.md-body td {
  border: none;
  border-bottom: 1px solid var(--border-faint);
  padding: 0.55rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

.md-body th {
  background: var(--accent-dim);
  color: var(--accent-fg-soft);
  font-weight: var(--fw-medium);
  font-size: var(--fs-meta);
  letter-spacing: 0.02em;
}

.md-body tr:last-child td {
  border-bottom: none;
}

.md-body code {
  font-family: var(--font-mono);
  background: var(--accent-dim);
  color: var(--accent-fg-soft);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.md-body pre {
  font-family: var(--font-mono);
  background: var(--surface-muted);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--border-faint);
  font-size: 0.88em;
}

.md-body pre code {
  font-family: inherit;
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

.err-text { color: var(--err); }

.msg.assistant.streaming .md-body:empty::before {
  content: "在想…";
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* —— B · 引用来源（Perplexity 风格）—— */
.msg-sources {
  margin-top: 0.55rem;
  padding-top: 0;
}

.msg-sources .cite-label {
  display: none;
}

.cite-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.cite-ref {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
  padding: 0.3rem 0.55rem;
  border-radius: 8px;
  background: var(--accent-dim);
  color: var(--ink-soft);
  border: none;
}

.cite-ref:hover,
.cite-ref[aria-expanded="true"] {
  background: rgba(36, 56, 50, 0.1);
  color: var(--ink);
}

.cite-num {
  min-width: 1.15rem;
  height: 1.15rem;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: var(--fs-meta);
}

.cite-title {
  font-size: var(--fs-meta);
}

.cite-card {
  flex-basis: 100%;
  margin: 0.15rem 0 0;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  background: var(--surface-muted);
  border: none;
}

.cite-excerpt {
  margin: 0 0 0.35rem;
  font-size: var(--fs-xs);
  line-height: var(--lh-relaxed);
  color: var(--text-secondary);
}

.cite-meta {
  font-size: var(--fs-2xs);
  color: var(--text-muted);
}

/* legacy cite chips — hidden if msg-sources present */
.msg-cites {
  display: none;
}

.msg-actions {
  display: flex;
  gap: 0.15rem;
  align-items: center;
  margin-top: 0.5rem;
  flex-wrap: wrap;
  opacity: 0;
  transition: opacity 0.15s;
}

.msg:hover .msg-actions,
.msg-actions:focus-within {
  opacity: 1;
}

.msg-action-sep {
  width: 1px;
  height: 14px;
  margin: 0 0.2rem;
  background: var(--border-faint);
  flex-shrink: 0;
}

.msg-action-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  box-shadow: none;
  flex-shrink: 0;
}

.msg-action-btn svg {
  display: block;
}

.msg-action-btn:hover {
  background: var(--accent-dim);
  color: var(--accent);
}

.msg-action-btn.feedback-on {
  background: var(--accent-dim);
  color: var(--accent);
}

/* legacy selectors — keep for any old markup */
.msg-actions button {
  padding: 0;
  font-size: inherit;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  box-shadow: none;
}

.msg-actions button[data-action="up"],
.msg-actions button[data-action="down"] {
  padding: 0;
  min-width: 0;
}

.msg-actions button.feedback-on {
  background: var(--accent-dim);
  color: var(--accent);
}

.msg-actions button:hover {
  color: var(--accent);
  background: var(--accent-dim);
}

.composer {
  flex-shrink: 0;
  max-width: var(--chat-max);
  width: 100%;
  margin: 0 auto;
  padding: 0 2rem 1.25rem;
  background: var(--surface);
}

.status-inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.15rem 0.5rem;
  font-size: var(--fs-meta);
  color: var(--ink-muted);
}

.composer-inner {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  min-height: 48px;
  background: var(--surface-muted);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-lg);
  padding: 0.45rem 0.55rem 0.45rem 0.85rem;
  box-shadow: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.composer-inner:focus-within {
  border-color: var(--accent-muted);
  box-shadow: 0 0 0 3px rgba(36, 56, 50, 0.08);
}

.composer-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.35rem;
  padding: 0.4rem 0.15rem 0;
  margin-top: 0.35rem;
}

.model-sep {
  color: var(--ink-muted);
  font-size: var(--fs-meta);
  opacity: 0.5;
}

.model-picker select {
  min-width: 0;
  max-width: 9rem;
  padding: 0.15rem 1.2rem 0.15rem 0;
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-size: var(--fs-meta);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%233d5650' d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0 center;
}

.model-picker select:hover,
.model-picker select:focus {
  color: var(--ink-soft);
  outline: none;
}

.dot-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.model-picker {
  display: inline-flex;
  align-items: center;
}

.composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  resize: none;
  max-height: 140px;
  min-height: 24px;
  padding: 0;
  margin: 0;
  align-self: center;
}

.composer textarea::placeholder {
  color: var(--text-muted);
}

.composer textarea:focus {
  outline: none;
  box-shadow: none;
}

.composer-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-shrink: 0;
  align-self: center;
}

.send-btn,
.stop-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
}

.send-btn {
  background: var(--accent-grad);
  color: var(--on-accent);
  font-weight: var(--fw-semibold);
  box-shadow: 0 2px 6px var(--accent-shadow);
  border-radius: 11px;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.stop-btn {
  width: auto;
  padding: 0 0.65rem;
  font-size: var(--fs-xs);
  background: var(--surface-raised);
  color: var(--err);
  border: 1px solid var(--err-border);
  box-shadow: none;
}

.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.52rem 0.95rem;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  font-size: var(--fs-sm);
  z-index: 50;
  box-shadow: var(--shadow-md);
}

.toast.err {
  color: var(--err);
  background: var(--err-bg);
  border-color: var(--err-border);
}

.toggle-polish.inline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* 多行输入时：发送钮贴底，避免长文时按钮悬空居中 */
.composer-inner.is-multiline {
  align-items: flex-end;
  padding-bottom: 0.4rem;
}

.composer-inner.is-multiline .composer-actions {
  align-self: flex-end;
  padding-bottom: 2px;
}

/* —— C · Artifact 工作台侧栏 —— */
.artifact-panel {
  width: var(--artifact-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border-soft);
  background: var(--surface-raised);
  min-height: 0;
}

.artifact-panel.hidden {
  display: none;
}

.artifact-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 0.85rem 0.65rem;
  border-bottom: 1px solid var(--border-soft);
}

.artifact-kicker {
  margin: 0 0 0.15rem;
  font-size: var(--fs-2xs);
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.artifact-head h2 {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
}

.artifact-close {
  flex-shrink: 0;
}

.artifact-body {
  flex: 1;
  overflow: auto;
  padding: 0.85rem;
  font-size: var(--fs-sm);
  line-height: var(--lh-relaxed);
}

.artifact-body pre,
.artifact-body textarea {
  width: 100%;
  min-height: 200px;
  padding: 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  font-size: var(--fs-sm);
  line-height: var(--lh-relaxed);
  resize: vertical;
  white-space: pre-wrap;
}

.artifact-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-xs);
}

.artifact-table th,
.artifact-table td {
  border-bottom: 1px solid var(--border-soft);
  padding: 0.45rem 0.35rem;
  text-align: left;
}

.artifact-table th {
  color: var(--text-muted);
  font-weight: var(--fw-semibold);
}

.artifact-foot {
  padding: 0.65rem 0.85rem calc(0.65rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.artifact-foot button {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  cursor: pointer;
}

.artifact-foot button.primary {
  background: var(--accent-grad);
  color: #eef4f1;
  border: none;
  box-shadow: 0 2px 6px var(--accent-shadow);
}

@media (max-width: 768px) {
  :root {
    --app-pad: 0;
    --radius-pane: 0;
  }

  .app {
    gap: 0;
    padding: 0;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    border-radius: 0;
    box-shadow: var(--shadow-pane);
    z-index: 40;
  }

  .main {
    border-radius: 0;
  }

  .main:has(#view-chat.active) .menu-btn {
    display: grid;
    place-items: center;
    pointer-events: auto;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 4;
  }

  .main:has(#view-chat.active) .topbar {
    inset: 0.75rem 0.75rem auto auto;
  }

  .sidebar.open { transform: translateX(0); }

  .back-chat:not(.hidden) {
    display: grid;
    place-items: center;
  }

  .chips {
    grid-template-columns: 1fr;
  }

  .messages {
    padding: 1rem 1rem 0.5rem;
  }

  .composer {
    padding: 0 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  }

  .msg {
    max-width: 100%;
  }

  .workspace.artifact-open .artifact-panel {
    position: fixed;
    inset: 0 0 0 0;
    width: 100%;
    z-index: 45;
    border-left: none;
    border-radius: 0;
  }
}
