/* ============================================================
   中医小助手 Agent · 界面样式
   finesse Set 7「Brick & Olive」暖药铺风
   ============================================================ */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ================= 侧栏 ================= */
.sidebar {
  position: relative;          /* 用户菜单的定位基准（移动端被 media query 覆盖为 fixed） */
  width: 264px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel-2);
  border-right: 1px solid var(--border);
  transition: transform var(--norm) var(--ease);
}

.sidebar-header { padding: var(--sp-5) var(--sp-4) var(--sp-3); }

.brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.brand-logo {
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  background: var(--accent-soft);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}
.brand-name { font-family: var(--font-serif); font-size: 17px; font-weight: 700; color: var(--ink-1); }
.brand-sub { font-size: 11px; color: var(--ink-3); letter-spacing: 0.04em; }

.new-chat-btn {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--ink-1);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--fast) var(--ease);
}
.new-chat-btn:hover { border-color: var(--accent); color: var(--accent); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-2) var(--sp-3);
}

.conv-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-2);
  transition: background var(--fast) var(--ease);
}
.conv-item:hover { background: rgba(156, 74, 56, 0.06); }
.conv-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 11px; font-weight: 400; color: var(--ink-3); }
.conv-item.active .conv-time { color: var(--accent); opacity: 0.72; }

.conv-acts { display: none; gap: 2px; flex-shrink: 0; }
.conv-item:hover .conv-acts, .conv-item.active .conv-acts { display: flex; }
.conv-act {
  border: none; background: none;
  color: var(--ink-3); cursor: pointer;
  font-size: 11px; line-height: 1;
  padding: 4px 5px; border-radius: 6px;
  transition: all var(--fast) var(--ease);
}
.conv-act:hover { color: var(--accent); background: rgba(156, 74, 56, 0.12); }
.conv-act[data-a="delete"]:hover { color: var(--down); background: rgba(194, 46, 34, 0.12); }

.conv-empty {
  padding: 20px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.9;
}

/* —— 对话搜索 —— */
.conv-search { position: relative; margin-top: var(--sp-2); }
.conv-search input {
  width: 100%;
  padding: 8px 28px 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--ink-1);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
  transition: border-color var(--fast) var(--ease);
}
.conv-search input:focus { border-color: var(--accent); }
.conv-search input::-webkit-search-cancel-button { display: none; }
.conv-search-clear {
  position: absolute; right: 4px; top: 50%;
  transform: translateY(-50%);
  border: none; background: none;
  color: var(--ink-3); cursor: pointer;
  font-size: 11px; padding: 4px 6px; border-radius: 6px;
}
.conv-search-clear:hover { color: var(--down); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
}
.sidebar-footnote { font-size: 11px; color: var(--ink-3); }

.theme-toggle, .icon-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--r-sm);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 15px;
  color: var(--ink-2);
  transition: all var(--fast) var(--ease);
}
.theme-toggle:hover, .icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ================= 主区 ================= */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.main-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-height: 58px;
}
#menuBtn { display: none; }
.header-title {
  flex: 1;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.header-actions { display: flex; align-items: center; gap: var(--sp-3); }

/* 深度思考开关 */
.deep-switch {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
}
.deep-switch input { display: none; }
.deep-switch-track {
  width: 34px; height: 19px;
  background: rgba(127, 114, 99, 0.25);
  border-radius: 999px;
  position: relative;
  transition: background var(--fast) var(--ease);
}
.deep-switch-dot {
  position: absolute;
  top: 2px; left: 2px;
  width: 15px; height: 15px;
  background: var(--bg);
  border-radius: 50%;
  transition: transform var(--fast) var(--ease);
  box-shadow: var(--shadow);
}
.deep-switch input:checked + .deep-switch-track { background: var(--accent-2); }
.deep-switch input:checked + .deep-switch-track .deep-switch-dot { transform: translateX(15px); }
.deep-switch-label { font-size: 12px; color: var(--ink-3); }
.deep-switch input:checked ~ .deep-switch-label { color: var(--accent-2); font-weight: 600; }

/* ================= 消息区 ================= */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-6) var(--sp-5);
  scroll-behavior: smooth;
}

.msg { display: flex; margin-bottom: var(--sp-5); }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--r) var(--r) 4px var(--r);
  padding: 12px 16px;
  max-width: 76%;
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.65;
}
.msg.agent .bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px var(--r) var(--r) var(--r);
  padding: var(--sp-4) var(--sp-5);
  max-width: 92%;
  width: 100%;
  box-shadow: var(--shadow);
}

/* Agent 状态行 */
.agent-status {
  font-size: 12.5px;
  color: var(--accent-2);
  margin-bottom: var(--sp-2);
}

/* ---- 工具执行轨迹 ---- */
.tool-trace {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.tool-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-3);
  min-height: 22px;
}
.tool-step.done { color: var(--ink-2); }
.tool-icon { font-size: 14px; }
.tool-label { font-weight: 600; color: var(--ink-2); flex-shrink: 0; }
.tool-summary {
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-check { color: var(--up); font-weight: 700; flex-shrink: 0; }
.tool-spinner {
  width: 13px; height: 13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 深度思考折叠 ---- */
.reasoning {
  margin-bottom: var(--sp-4);
  border-left: 3px solid var(--accent-2);
  background: rgba(92, 90, 58, 0.06);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: var(--sp-2) var(--sp-4);
}
.reasoning summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent-2);
  user-select: none;
  list-style: none;
}
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning summary::before { content: '▸ '; }
.reasoning[open] summary::before { content: '▾ '; }
.reasoning-body {
  margin-top: var(--sp-2);
  font-size: 12.5px;
  color: var(--ink-3);
  white-space: pre-wrap;
  line-height: 1.7;
  max-height: 320px;
  overflow-y: auto;
}

/* ---- Markdown 正文 ---- */
.md-content { font-size: 14.5px; line-height: 1.75; color: var(--ink-2); }
.md-content h1, .md-content h2, .md-content h3, .md-content h4 {
  font-family: var(--font-serif);
  color: var(--ink-1);
  margin: 1.1em 0 0.5em;
  line-height: 1.4;
}
.md-content h1 { font-size: 1.25em; }
.md-content h2 { font-size: 1.15em; }
.md-content h3 { font-size: 1.05em; }
.md-content p { margin: 0.5em 0; }
.md-content ul, .md-content ol { padding-left: 1.4em; margin: 0.5em 0; }
.md-content li { margin: 0.25em 0; }
.md-content strong { color: var(--ink-1); }
.md-content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--panel-2);
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--accent);
}
.md-content pre {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-4);
  overflow-x: auto;
}
.md-content pre code { background: none; padding: 0; color: var(--ink-2); }
.md-content blockquote {
  margin: 0.6em 0;
  padding: var(--sp-2) var(--sp-4);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--ink-2);
}
.md-content table { border-collapse: collapse; margin: 0.8em 0; width: 100%; font-size: 0.92em; }
.md-content th, .md-content td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.md-content th { background: var(--panel-2); font-family: var(--font-serif); color: var(--ink-1); }
.md-content hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

/* ================= 欢迎页 ================= */
.welcome {
  max-width: 640px;
  margin: 8vh auto 0;
  text-align: center;
  animation: rise var(--slow) var(--ease);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
.welcome-mark {
  width: 68px; height: 68px;
  margin: 0 auto var(--sp-4);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.welcome-title { font-size: 24px; margin: 0 0 var(--sp-2); }
.welcome-sub { color: var(--ink-3); font-size: 14px; margin: 0 0 var(--sp-6); }

.cap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin-bottom: var(--sp-6);
}
.cap-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--ink-2);
  box-shadow: var(--shadow);
}
.cap-icon { font-size: 17px; }

.tpl-section { text-align: left; }
.tpl-title {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.05em;
  margin-bottom: var(--sp-2);
}
.tpl-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.tpl-chip {
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  transition: all var(--fast) var(--ease);
}
.tpl-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.tpl-chip strong { font-weight: 600; }

/* ================= 输入区 ================= */
.input-area {
  padding: var(--sp-3) var(--sp-5) var(--sp-4);
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.input-box {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-3);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-box textarea {
  flex: 1;
  border: none;
  background: none;
  resize: none;
  outline: none;
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink-1);
  max-height: 180px;
  padding: 8px 0;
}
.input-box textarea::placeholder { color: var(--ink-3); }
.send-btn {
  width: 40px; height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 16px;
  cursor: pointer;
  transition: all var(--fast) var(--ease);
}
.send-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px var(--glow); }
.send-btn.busy { background: var(--down); }
.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--ink-3);
  margin-top: var(--sp-2);
}

/* ================= 患者档案抽屉 ================= */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(30, 23, 18, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--norm) var(--ease);
  z-index: 40;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }

.patient-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(680px, 94vw);
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--norm) var(--ease);
  box-shadow: var(--shadow-lg);
}
.patient-drawer.open { transform: none; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.drawer-header h3 { margin: 0; font-size: 16px; }
.drawer-tip {
  font-size: 12px;
  color: var(--ink-3);
  margin: 0;
  padding: var(--sp-3) var(--sp-5) 0;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.drawer-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}
.drawer-body input, .drawer-body select, .drawer-body textarea {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--panel-2);
  padding: 9px 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ink-1);
  outline: none;
  transition: border-color var(--fast) var(--ease);
}
.drawer-body input:focus, .drawer-body select:focus, .drawer-body textarea:focus {
  border-color: var(--accent);
}
.drawer-footer {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
}
.btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--fast) var(--ease);
}
.btn.ghost { background: none; color: var(--ink-2); }
.btn.ghost:hover { border-color: var(--down); color: var(--down); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px var(--glow); }

/* ---- 患者档案：分区与网格 ---- */
.pf-section { margin-bottom: var(--sp-2); }
.pf-section + .pf-section {
  padding-top: var(--sp-4);
  border-top: 1px dashed var(--border);
}
.pf-section-title {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-2);
  margin-bottom: var(--sp-3);
  letter-spacing: 0.02em;
}
.pf-grid { display: grid; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.pf-grid-2 { grid-template-columns: 1fr 1fr; }
.pf-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.pf-grid-4 { grid-template-columns: repeat(4, 1fr); }
.pf-grid label { min-width: 0; }
.pf-grid select { width: 100%; }

/* ================= Toast ================= */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translate(-50%, 12px);
  background: var(--ink-1);
  color: var(--page);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transition: all var(--norm) var(--ease);
  z-index: 60;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 带操作按钮的 toast（撤销删除） */
.toast.action {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px 10px 18px;
  border-radius: 14px;
  pointer-events: auto;
  max-width: min(90vw, 460px);
}
.toast.action > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toast-btn {
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  border-radius: 999px;
  padding: 4px 13px;
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--fast) var(--ease);
}
.toast-btn:hover { background: rgba(255, 255, 255, 0.26); }

/* ================= 响应式 ================= */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 45;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  #menuBtn { display: flex; }
  .messages { padding: var(--sp-4) var(--sp-3); }
  .input-area { padding: var(--sp-2) var(--sp-3) var(--sp-3); }
  .msg.agent .bubble { max-width: 100%; padding: var(--sp-3) var(--sp-4); }
  .cap-grid { grid-template-columns: 1fr; }
  .welcome { margin-top: 4vh; }
  .deep-switch-label { display: none; }
  .pf-grid-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 460px) {
  .pf-grid-2, .pf-grid-3, .pf-grid-4 { grid-template-columns: 1fr; }
}

/* ============================================================
   登录层
   ============================================================ */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background:
    radial-gradient(120% 90% at 15% 0%, rgba(156, 74, 56, 0.10), transparent 55%),
    radial-gradient(100% 80% at 90% 100%, rgba(92, 90, 58, 0.12), transparent 55%),
    var(--page);
}
.auth-gate[hidden] { display: none; }

.auth-card {
  width: 100%;
  max-width: 380px;
  padding: var(--sp-6) var(--sp-6) var(--sp-5);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: authIn var(--slow) var(--ease);
}
@keyframes authIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.auth-brand { text-align: center; margin-bottom: var(--sp-5); }
.auth-logo {
  font-size: 40px;
  line-height: 1;
  margin-bottom: var(--sp-3);
  filter: drop-shadow(0 6px 14px var(--glow));
}
.auth-title {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.06em;
}
.auth-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
}

.auth-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: var(--sp-4) 0;
  font-size: 13px;
  color: var(--ink-3);
}
.auth-loading[hidden] { display: none; }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-form { display: flex; flex-direction: column; gap: var(--sp-3); }
.auth-form[hidden] { display: none; }

.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-label { font-size: 12px; color: var(--ink-3); letter-spacing: 0.04em; }
.auth-field input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--panel-2);
  color: var(--ink-1);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.auth-field input:focus { border-color: var(--accent); background: var(--bg); }

.auth-error {
  padding: 9px 12px;
  border-radius: var(--r-sm);
  background: rgba(194, 46, 34, 0.08);
  border: 1px solid rgba(194, 46, 34, 0.22);
  color: var(--down);
  font-size: 12.5px;
  line-height: 1.6;
}
.auth-error[hidden] { display: none; }

.auth-submit { width: 100%; padding: 12px; font-size: 15px; letter-spacing: 0.3em; }

.auth-foot {
  margin: var(--sp-2) 0 0;
  font-size: 11.5px;
  line-height: 1.8;
  color: var(--ink-3);
  text-align: center;
}

/* ============================================================
   用户菜单
   ============================================================ */
.user-chip {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--ink-2);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: all var(--fast) var(--ease);
}
.user-chip:hover { border-color: var(--accent); color: var(--accent); }
.user-avatar {
  width: 24px; height: 24px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.user-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.user-caret { font-size: 10px; opacity: 0.7; }

.user-menu {
  position: absolute;
  left: var(--sp-3);
  right: var(--sp-3);
  bottom: 62px;
  z-index: 50;
  padding: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  animation: authIn var(--fast) var(--ease);
}
.user-menu[hidden] { display: none; }
.user-menu-head {
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.user-menu-name { font-size: 13px; color: var(--ink-1); font-weight: 600; }
.user-menu-role { font-size: 11px; color: var(--ink-3); }
.user-menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
.user-menu button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background var(--fast) var(--ease);
}
.user-menu button:hover { background: var(--accent-soft); color: var(--accent); }
.user-menu button.danger:hover { background: rgba(194, 46, 34, 0.1); color: var(--down); }

/* ============================================================
   通用弹窗
   ============================================================ */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(30, 23, 18, 0.42);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity var(--norm) var(--ease);
}
.modal-mask[hidden] { display: none; }
.modal-mask.show { opacity: 1; }

.modal {
  width: 100%;
  max-width: 460px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(10px) scale(0.98);
  transition: transform var(--norm) var(--ease);
}
.modal-mask.show .modal { transform: none; }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5) var(--sp-4);
  border-top: 1px solid var(--border);
}
.modal-foot:empty { display: none; }

.form-stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.form-row { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.form-row input, .form-row select {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--panel-2);
  color: var(--ink-1);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.form-row input:focus, .form-row select:focus { border-color: var(--accent); background: var(--bg); }

/* —— 用户管理 —— */
.um-list { max-height: 240px; overflow-y: auto; margin-bottom: var(--sp-4); }
.um-empty { padding: var(--sp-4); text-align: center; font-size: 13px; color: var(--ink-3); }
.um-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.um-row:last-child { border-bottom: none; }
.um-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.um-name { font-size: 13.5px; color: var(--ink-1); font-weight: 600; }
.um-sub { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.um-actions { display: flex; gap: 4px; flex-shrink: 0; }
.mini-btn {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--fast) var(--ease);
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.mini-btn.danger:hover { border-color: var(--down); color: var(--down); }

.um-create {
  padding-top: var(--sp-4);
  border-top: 1px solid var(--border);
}
.um-create-title {
  font-size: 12.5px;
  color: var(--ink-3);
  margin-bottom: var(--sp-3);
  letter-spacing: 0.04em;
}

/* ============================================================
   消息操作条
   ============================================================ */
.msg { position: relative; }
.msg-acts {
  display: flex;
  gap: 2px;
  align-items: center;
  opacity: 0;
  transition: opacity var(--fast) var(--ease);
}
.msg.user .msg-acts { order: -1; margin-right: 6px; }
.msg.agent .msg-acts { margin-left: 4px; margin-top: -6px; }
.msg:hover .msg-acts { opacity: 1; }
.msg-act {
  border: 1px solid transparent;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 5px 6px;
  border-radius: 8px;
  transition: all var(--fast) var(--ease);
}
.msg-act:hover {
  color: var(--accent);
  border-color: var(--border);
  background: var(--bg);
}

@media (hover: none) {
  .msg-acts { opacity: 1; }
  .conv-acts { display: flex; }
}

/* ============================================================
   杂项
   ============================================================ */
.drawer-saved {
  margin-right: auto;
  font-size: 11px;
  color: var(--ink-3);
}
.draft-hint { color: var(--ink-3); font-size: 11px; }
.toast.error { background: var(--down); color: #fff; }

.send-btn.busy {
  background: var(--down);
  animation: pulseStop 1.6s ease-in-out infinite;
}
@keyframes pulseStop {
  0%, 100% { box-shadow: 0 0 0 0 rgba(194, 46, 34, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(194, 46, 34, 0); }
}

#appRoot { transition: filter var(--norm) var(--ease); }

