

:root {
  --blue: #2563EB;
  --blue-dark: #1D4ED8;
  --blue-light: #EFF4FF;
  --blue-tint: #DBEAFE;
  --text: #0F172A;
  --text-2: #334155;
  --text-3: #64748B;
  --text-4: #94A3B8;
  --bg: #F3F5FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --border: #E7EAF1;
  --border-2: #D4D9E3;
  --ok: #16A34A;
  --warn: #EA580C;
  --err: #DC2626;
  --purple: #7C3AED;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.05);
  --shadow-md: 0 6px 20px rgba(15,23,42,.08);
  --shadow-lg: 0 24px 60px rgba(15,23,42,.26);
  --radius-lg: 0px;
  --radius: 0px;
  --radius-sm: 0px;
  --radius-xs: 0px;
  --topbar-h: 58px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, #EAF0FF 0%, rgba(234,240,255,0) 60%),
    radial-gradient(900px 500px at -10% 110%, #EAFBF2 0%, rgba(234,251,242,0) 55%),
    var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "tnum" 1, "cv01" 1;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: inherit;
  outline: none;
}
a { color: var(--blue); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--text-3); }


.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 34px; padding: 0 13px;
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  font-weight: 600;
  transition: background .14s ease, border-color .14s ease, color .14s ease, box-shadow .14s ease, transform .06s ease;
  white-space: nowrap;
  user-select: none;
  line-height: 1;
  gap: 6px;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--surface-2); border-color: var(--border-2); }
.btn:active { transform: translateY(1px); background: #F1F5F9; }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

.btn.sm { height: 30px; padding: 0 11px; font-size: 13px; }
.btn.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); box-shadow: 0 2px 8px rgba(37,99,235,.28); }
.btn.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.btn-danger { background: var(--err); color: #fff; border-color: var(--err); box-shadow: 0 2px 8px rgba(220,38,38,.25); }
.btn.btn-danger:hover { background: #B91C1C; border-color: #B91C1C; }

.icon-btn { width: 36px; height: 36px; padding: 0; flex-shrink: 0; border-radius: 0; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn svg { width: 17px; height: 17px; stroke: var(--text-3); flex-shrink: 0; transition: stroke .14s ease; }
.icon-btn:hover { background: var(--blue-light); border-color: var(--blue-tint); }
.icon-btn:hover svg { stroke: var(--blue); }
.btn-primary svg { stroke: #fff; }
.btn-primary:hover svg { stroke: #fff; }

.btn-select {
  min-width: 140px;
  max-width: 420px;
  height: 34px;
  padding: 0 30px 0 11px;
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--surface);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position:
    calc(100% - 15px) calc(50% - 1px),
    calc(100% - 11px) calc(50% - 1px);
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  border: none;
  border-radius: 0;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
  outline: none;
  transition: background-color .14s ease;
}
.btn-select:hover { background-color: var(--surface-2); }
.btn-select:focus { outline: none; box-shadow: none; }


.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr) minmax(0, 1fr);
  align-items: center;
  height: var(--topbar-h);
  padding: 0 16px;
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 250;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
}
.top-left, .top-right {
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
  flex-wrap: nowrap;
  overflow: hidden;
}
.top-right { justify-content: flex-end; }
.top-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.topbar-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
}
.topbar-session {
  font-weight: 700; font-size: 15px; color: var(--text);
  letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
}


.session-title-wrap {
  display: flex; align-items: center; justify-content: center;
  min-width: 0; width: 100%;
}
.session-title {
  font-weight: 700; font-size: 15px; color: var(--text);
  letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
}


.context-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 5px;
  align-items: center;
  width: 100%;
  max-width: 440px;
  min-width: 280px;
}
.context-text {
  grid-column: 1;
  grid-row: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.bar-track {
  grid-column: 1;
  grid-row: 2;
  height: 7px;
  width: 100%;
  background: #E8ECF3;
  overflow: hidden;
  border-radius: 999px;
}
.bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--blue), #4F8BFF);
  border-radius: 999px;
  transition: width .25s ease;
}
.bar-fill.warn { background: linear-gradient(90deg, #F59E0B, var(--warn)); }
.bar-fill.danger { background: linear-gradient(90deg, #EF4444, var(--err)); }
#btnRefreshCtx {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
}


.main {
  display: grid;
  /* 数字人(左) | 聊天(右) — 会话抽屉独立于 grid 外 */
  grid-template-columns: minmax(400px, 520px) 1fr;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - var(--topbar-h));
  min-height: 0;
  max-height: calc(100vh - var(--topbar-h));
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
}
/* ── 悬浮会话抽屉（fixed，从左侧滑出）── */
.col-mid {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: 300px;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
  background: var(--bg);
  padding: 14px;
  box-sizing: border-box;
  overflow: hidden; /* 由内部 .session-list 独占滚动，避免嵌套滚动导致底部被切 */
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: none;
}
.col-mid.mobile-open {
  transform: translateX(0);
  box-shadow: 4px 0 24px rgba(15,23,42,.15);
}
.mobile-sidebar-mask {
  position: fixed; inset: 0; z-index: 199;
  background: rgba(15,23,42,.35);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.mobile-sidebar-mask.show {
  opacity: 1; pointer-events: auto;
}

.col {
  display: flex; flex-direction: column; gap: 14px;
  min-height: 0; min-width: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
}


.col-left {}

.avatar-card {
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  border-radius: var(--radius);
}
.avatar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.avatar-actions .btn.sm {
  height: 30px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  background: var(--blue);
  color: #fff;
  border-radius: 8px;
  border: none;
  cursor: pointer;
}
.avatar-actions .btn.sm:hover { background: var(--blue-dark); }
.avatar-actions-hint {
  font-size: 12px;
  color: var(--text-4);
}
.avatar-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 420px;
  flex: 1 1 auto;
  border-radius: calc(var(--radius) - 2px);
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 25%, #3B4A63 0%, #1B2740 55%, #0A1124 100%);
  
  isolation: isolate;
  transform: translateZ(0);
}
#avatarCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  z-index: 1;
  background: transparent !important;
}
.avatar-2d-layer, .avatar-frames-layer {
  position: absolute; inset: 0;
  left: 0; right: 0; top: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  background: transparent;
  z-index: 3;            
  pointer-events: none; 
  visibility: visible;
}
.avatar-frames-layer img,
.avatar-2d-layer img {
  width: auto;
  height: 88%;
  max-width: 92%;
  max-height: 92%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center bottom;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  image-rendering: auto;
  filter: drop-shadow(0 22px 36px rgba(2,6,23,0.55));
}
.avatar-overlay {
  position: absolute;
  left: 14px; bottom: 14px;
  right: 14px;
  z-index: 50;    
  pointer-events: none;
  line-height: 1.2 !important;
}
.avatar-status-chip {
  display: inline-flex !important; align-items: center; gap: 6px;
  background: rgba(15,23,42,.6); color: #F1F5F9 !important;
  padding: 6px 13px; font-size: 12px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-weight: 700;
  letter-spacing: .2px;
  line-height: 1.2 !important;
  min-height: 26px;
  box-sizing: border-box;
  opacity: 1 !important;
  visibility: visible !important;
  position: relative;
  z-index: 51;
  box-shadow: 0 4px 14px rgba(2,6,23,.3);
}
.avatar-loading {
  position: absolute; inset: 0;
  z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; color: #CBD5E1; background: rgba(15,23,42,.5);
  font-size: 13px; font-weight: 600;
  border-radius: calc(var(--radius) - 2px);
}
.avatar-loading.hidden { display: none; }
.spinner {
  width: 30px; height: 30px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


.status-grid-card {
  flex: 0 0 auto;
  padding: 14px 16px 16px;
  border-radius: var(--radius);
}
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.status-cell {
  display: grid;
  grid-template-columns: 30px 1fr;
  grid-template-rows: auto auto;
  column-gap: 11px;
  row-gap: 2px;
  align-items: center;
  padding: 11px 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, background .15s ease;
}
.status-cell.ok { border-color: #BBF7D0; background: #F0FDF4; }
.status-cell.warn { border-color: #FED7AA; background: #FFF7ED; }
.status-cell.warn .card-icon { border-color: #FDBA74; background: #FFEDD5; }
.status-cell.warn .card-icon svg { stroke: var(--warn); }
.status-cell.bad { border-color: #FECACA; background: #FEF2F2; }
.status-cell.bad .card-icon { border-color: #FCA5A5; background: #FEE2E2; }
.status-cell.bad .card-icon svg { stroke: var(--err); }
.status-cell.unknown { border-color: var(--border); background: var(--surface-2); }
.status-cell .card-icon {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
}
.status-cell .card-icon svg {
  width: 17px; height: 17px;
  max-width: 17px; max-height: 17px;
  display: block;
  stroke: var(--text-2);
  fill: none;
}
.status-cell.ok .card-icon { border-color: #86EFAC; background: #ECFDF5; }
.status-cell.ok .card-icon svg { stroke: var(--ok); }
.status-cell .card-val {
  grid-column: 2;
  grid-row: 1;
  font-size: 14px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.status-cell .card-desc {
  grid-column: 2;
  grid-row: 2;
  font-size: 11.5px; color: var(--text-4); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}


.col-mid {}
.session-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 15px;
  border-radius: var(--radius);
}
.session-head .muted { font-size: 12px; font-weight: 700; color: var(--text-3); letter-spacing: .4px; }

.session-list-card {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  padding: 8px 8px 12px;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
}
.session-head {
  flex-shrink: 0; /* 防止头部被压缩，确保会话列表获得剩余全部高度 */
}
.session-list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

/* 侧边栏「当前员工」选择器：强制占满卡片宽度（覆盖 .btn-select 的 inline-flex / max-width） */
.session-list-card > #selAgents,
.session-list-card > select.btn-select {
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  display: block !important;
  box-sizing: border-box !important;
}
.session-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
  padding: 12px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease, transform .06s ease;
}
.session-item:hover { background: var(--surface-2); border-color: var(--border-2); box-shadow: var(--shadow-sm); }
.session-item:active { transform: translateY(1px); }
.session-item.active { background: var(--blue-light); border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.session-item .si-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-4); box-shadow: 0 0 0 3px rgba(148,163,184,.18); }
.session-item.active .si-dot { background: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.18); }
.session-item .si-main {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-width: 0;
  overflow: hidden;
}
.session-item .si-title {
  font-size: 13.5px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-item .si-sub {
  font-size: 11px; color: var(--text-4); margin-top: 3px;
  display: flex; justify-content: space-between; gap: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-item .si-actions {
  grid-column: 3;
  grid-row: 1 / span 2;
  display: none; gap: 2px;
}
.session-item:hover .si-actions { display: flex; }


.session-item .session-ic {
  grid-column: 1; grid-row: 1 / span 2;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
}
.session-item .session-body {
  grid-column: 2; grid-row: 1 / span 2;
  min-width: 0; overflow: hidden;
}
.session-item .session-title-line {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  min-width: 0;
}
.session-item .session-title {
  font-size: 13.5px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.session-item .session-time {
  font-size: 11px; color: var(--text-4);
  flex-shrink: 0; white-space: nowrap;
}
.session-item .session-sub {
  font-size: 11px; color: var(--text-4); margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 会话标题可编辑（双击重命名） */
.session-item .session-title.editable {
  cursor: text;
  border-radius: 0;
  transition: background .12s ease;
}
.session-item .session-title.editable:hover { background: rgba(37,99,235,.08); }
.session-rename-input {
  width: 100%;
  font-size: 13.5px; font-weight: 700;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--blue);
  border-radius: 0;
  padding: 1px 4px;
  outline: none;
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
/* 会话删除按钮 */
.session-del-btn {
  grid-column: 3; grid-row: 1 / span 2;
  display: flex; align-items: center; justify-content: center;
  opacity: .55; color: var(--text-3);
  background: none; border: none; border-radius: 0;
  padding: 4px; cursor: pointer;
  transition: opacity .15s ease, color .15s ease, background .15s ease;
  align-self: center; justify-self: center;
}
.session-item:hover .session-del-btn { opacity: .9; }
.session-del-btn:hover { opacity: 1 !important; color: #EF4444; background: rgba(239,68,68,.08); }

.empty-list {
  padding: 44px 18px;
  text-align: center;
  color: var(--text-4);
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  align-items: center;
  gap: 8px;
}
.empty-title { font-weight: 700; color: var(--text-3); font-size: 14px; }
.empty-sub { font-size: 12.5px; color: var(--text-4); }


.col-right {}
.chat-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  position: relative;
  overflow: hidden;
  height: 100%;
  border-radius: var(--radius);
}

.messages-container {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 24px 16px;
  display: flex; flex-direction: column; gap: 16px;
  background:
    radial-gradient(800px 400px at 100% 0%, #F5F8FF 0%, rgba(245,248,255,0) 60%),
    #fff;
  min-height: 0;
  scroll-behavior: auto;
  
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.messages-container::-webkit-scrollbar,
.dh-messages::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.msg { display: flex; gap: 11px; max-width: 100%; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.msg .avatar-bubble {
  width: 34px; height: 34px; flex-shrink: 0;
  background: var(--blue-light); color: var(--blue-dark);
  border: 1px solid #BFDBFE;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
  box-shadow: var(--shadow-sm);
}
.msg.user .avatar-bubble { background: #EFF6FF; color: var(--blue); border-color: #DBEAFE; }
.msg .bubble {
  background: var(--surface-2);
  padding: 11px 15px;
  max-width: 82%;
  line-height: 1.68;
  color: var(--text);
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
}
.msg.user .bubble { background: var(--blue); color: #fff; border-color: var(--blue); border-radius: 16px 4px 16px 16px; box-shadow: 0 4px 14px rgba(37,99,235,.22); }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3, .msg .bubble h4 { margin: 8px 0 6px; }
.msg .bubble p { margin: 0 0 8px; }
.msg .bubble pre {
  background: rgba(15,23,42,.06); padding: 9px 11px; overflow: auto;
  font-size: 12.5px; border: 1px solid var(--border); margin: 6px 0;
  line-height: 1.5; border-radius: 8px;
}
.msg .bubble code {
  background: rgba(15,23,42,.06);
  padding: 1px 5px;
  font-family: Consolas, Menlo, "SF Mono", monospace;
  font-size: 12.5px; border-radius: 5px;
}
.msg.user .bubble code, .msg.user .bubble pre {
  background: rgba(255,255,255,.15);
  color: #EFF6FF;
  border-color: rgba(255,255,255,.2);
}
.msg-meta {
  font-size: 10.5px; color: var(--text-4);
  margin-top: 5px;
  display: flex; align-items: center; gap: 8px;
}
.msg.user .msg-meta { justify-content: flex-end; }


.msg-wrap { display: flex; gap: 11px; max-width: 100%; align-items: flex-start; }
.msg-wrap.msg-user { flex-direction: row-reverse; }
.msg-wrap.msg-assistant { flex-direction: row; }

.msg-avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px;
  box-shadow: var(--shadow-sm);
}
.user-av { background: linear-gradient(135deg,#3B82F6,#1D4ED8); color:#fff; border:1px solid #DBEAFE; }
.bot-av  { background: linear-gradient(135deg,#10B981,#059669); color:#fff; border:1px solid #A7F3D0; }
.sys-av  { background: var(--text-3); color:#fff; width:26px; height:26px; }

.msg-body {
  max-width: 78%;
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.msg-user .msg-body { align-items: flex-end; }
.msg-assistant .msg-body { align-items: flex-start; }
.msg-system .sys-body { max-width: 88%; }

.msg-name {
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
  padding: 0 6px;
}
.msg-user .msg-name { display: none; }

.msg-text {
  background: var(--surface-2);
  padding: 11px 15px;
  border-radius: 4px 16px 16px 16px;
  line-height: 1.68;
  color: var(--text);
  font-size: 14px;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-sm);
}
.msg-user .msg-text {
  background: linear-gradient(135deg,#2563EB,#1D4ED8);
  color: #fff;
  border-color: #1E40AF;
  border-radius: 16px 4px 16px 16px;
  box-shadow: 0 4px 14px rgba(37,99,235,.22);
}
.msg-system .msg-text {
  background: rgba(148,163,184,.12);
  border-color: rgba(148,163,184,.22);
  color: var(--text-2);
  font-size: 12.5px;
  padding: 7px 13px;
  border-radius: 10px;
}
.msg-text.streaming::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: var(--blue);
  animation: blink 1s steps(2) infinite;
}
.msg-user .msg-text.streaming::after { color: #DBEAFE; }
@keyframes blink { 0%,50% { opacity: 1; } 50.01%,100% { opacity: 0; } }

/* ===== 音乐卡片 ===== */
.music-card {
  --mc-prog: 0%;
  position: relative;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.music-card .mc-cover {
  width: 52px; height: 52px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--blue-light), var(--blue-tint));
  display: flex; align-items: center; justify-content: center;
}
.music-card .mc-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.music-card .mc-cover-ph {
  font-size: 24px; line-height: 1;
  color: var(--blue);
  font-weight: 700;
}
.music-card .mc-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex; flex-direction: column; gap: 3px;
}
.music-card .mc-title {
  font-size: 14px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.music-card .mc-artist {
  font-size: 12px; color: var(--text-3); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.music-card .mc-play {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(37,99,235,.28);
  transition: transform .12s ease, box-shadow .12s ease;
}
.music-card .mc-play:hover { transform: scale(1.06); box-shadow: 0 6px 16px rgba(37,99,235,.34); }
.music-card .mc-play:active { transform: scale(.96); }
.music-card .mc-play svg { width: 18px; height: 18px; stroke: #fff; }
.music-card .mc-dur {
  flex-shrink: 0;
  font-size: 12px; font-weight: 600; color: var(--text-3);
  font-variant-numeric: tabular-nums;
  min-width: 38px; text-align: right;
}
.music-card.playing .mc-play { box-shadow: 0 4px 14px rgba(37,99,235,.42); }
/* 底部播放进度条 */
.music-card::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0;
  height: 3px;
  width: var(--mc-prog, 0%);
  background: linear-gradient(90deg, var(--blue), var(--blue-dark));
  transition: width .15s linear;
}

/* VIP 版权保护歌曲卡片 */
.music-card.mc-vip { opacity: .88; }
.music-card .mc-vip-badge {
  flex-shrink: 0;
  font-size: 10px; font-weight: 700; line-height: 1;
  padding: 2px 6px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  border-radius: 4px;
  letter-spacing: .5px;
}
.music-card .mc-ext-link {
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff !important;
  text-decoration: none;
  font-size: 11px; font-weight: 700;
  box-shadow: 0 4px 12px rgba(37,99,235,.28);
  transition: transform .12s ease, box-shadow .12s ease;
}
.music-card .mc-ext-link:hover { transform: scale(1.06); box-shadow: 0 6px 16px rgba(37,99,235,.34); }
.music-card .mc-ext-link:active { transform: scale(.96); }


.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 15px;
  border-radius: 4px 16px 16px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;      
  flex-wrap: nowrap;
}
.typing-text {
  font-size: 13px;
  font-weight: 500;
  background: linear-gradient(90deg, var(--text-3) 0%, var(--blue) 45%, var(--blue) 55%, var(--text-3) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation: typing-shimmer 1.8s linear infinite;
}
@keyframes typing-shimmer {
  0% { background-position: 130% 0; }
  100% { background-position: -130% 0; }
}
.typing-dots { display: inline-flex; gap: 4px; padding-bottom: 1px; }
.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--blue);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.msg-text.md h1,.msg-text.md h2,.msg-text.md h3,.msg-text.md h4 { margin:8px 0 6px; line-height:1.35; }
.msg-text.md p { margin: 0 0 8px; }
.msg-text.md pre {
  background: rgba(15,23,42,.06); padding: 9px 11px; overflow: auto;
  font-size: 12.5px; border: 1px solid var(--border); margin: 6px 0;
  line-height: 1.5; border-radius: 8px; 
}
.msg-text.md code, .msg-text.md .md-inline {
  background: rgba(15,23,42,.06);
  padding: 1px 5px;
  font-family: Consolas, Menlo, "SF Mono", monospace;
  font-size: 12.5px; border-radius: 5px;
}
.msg-text.md .md-code {
  background: #0F172A; color: #E2E8F0;
  border-radius: 10px; padding: 11px 13px; margin: 6px 0;
  overflow-x: auto; line-height: 1.55;
}
.msg-text.md .md-code code { background: transparent; padding: 0; color: #E2E8F0; border-radius: 0; }
.msg-user .msg-text.md code,
.msg-user .msg-text.md pre,
.msg-user .msg-text.md .md-inline {
  background: rgba(255,255,255,.15);
  color: #EFF6FF;
  border-color: rgba(255,255,255,.2);
}
.msg-user .msg-text.md .md-code { background: rgba(15,23,42,.25); }
.msg-user .msg-text.md .md-code code { background: transparent; color: #F1F5F9; }

.msg-tool .msg-text {
  background: #F0F9FF;
  border-color: #BAE6FD;
}


.tool-images {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px;
}
.tool-shot {
  max-width: 300px; max-height: 220px;
  border-radius: 10px;
  border: 1px solid var(--border-2);
  background: #0B0F19;
  object-fit: contain;
  cursor: zoom-in;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .12s ease;
}
.tool-shot:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
}


.tool-activity {
  margin: 2px 0 4px; max-width: 100%;
  flex-direction: column;
}
/* 工具卡片紧贴上方助手消息（无头像重复感） */
.tool-activity .msg-avatar { display: none; }
.ta-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 7px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer; user-select: none;
  font-size: 12.5px; color: var(--text-2);
  transition: border-color .12s ease, background .12s ease;
}
.ta-head:hover { border-color: var(--border-2); }
.ta-title {
  display: flex; align-items: center; gap: 6px;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ta-head-ic { display: inline-flex; flex-shrink: 0; color: var(--text-3); }
.ta-caret { opacity: .55; font-size: 11px; flex-shrink: 0; display: inline-flex; }
.ta-body {
  margin-top: 6px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2);
  font-size: 12px; line-height: 1.55; color: var(--text-2);
}

.ta-line {
  display: flex; flex-direction: column; gap: 2px;
  margin: 5px 0; word-break: break-all;
}
.ta-tool { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ta-tool b { color: var(--text-1); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ta-ic { display: inline-flex; flex-shrink: 0; color: var(--text-3); }
.ta-args, .ta-res { margin-left: 20px; font-size: 11.5px; line-height: 1.5; }
.ta-args { opacity: .65; }
.ta-res { opacity: .85; }


.typing-indicator {
  display: inline-flex; align-items: center; gap: 6px; height: 24px;
}
.typing-dots {
  display: inline-flex; align-items: center; gap: 4px; height: 14px;
  padding: 0 2px;
}
.typing-dots span {
  width: 6px; height: 6px; background: var(--text-3);
  border-radius: 50%; display: inline-block;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100% { transform: scale(.6); opacity: .5;} 40% { transform: scale(1); opacity: 1; } }


.asr-hint {
  position: absolute;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%);
  background: rgba(15,23,42,.84);
  color: #F8FAFC;
  padding: 9px 18px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  z-index: 30;
  max-width: 80%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 8px 24px rgba(2,6,23,.35);
}


.input-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-top: 1px solid var(--border);
  background: rgba(250,252,255,.9);
  width: 100%;
  box-sizing: border-box;
}
.input-toolbar .btn-select {
  min-width: 100px;
  max-width: 220px;
  height: 30px;
  font-size: 12px;
  padding: 0 24px 0 8px;
}
.ctx-mini {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}
.ctx-mini .bar-track { height: 4px; }


.input-bar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  align-items: end;
  gap: 8px 10px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  width: 100%;
  box-sizing: border-box;
  border-radius: 0 0 0 0;
}


.mic-wave-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  grid-column: 2;
  grid-row: 2;
  margin: 0;
  padding: 5px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 30px;
  box-sizing: border-box;
}
.mic-wave-bar .mic-wave-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--blue);
  animation: pulseDot 1.4s infinite;
}
.mic-wave-bar.recording .mic-wave-dot { background: var(--err); animation: pulseDotErr 1.4s infinite; }
.mic-wave-bar.recording .mic-wave-label { color: var(--err); }
.mic-wave-bar.listening .mic-wave-label { color: var(--blue); }
.mic-wave-label { font-size: 12px; font-weight: 600; white-space: nowrap; }
.mic-wave-canvas { width: 100%; height: 24px; flex: 1; display: block; }
@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(37,99,235,.5); }
  70% { box-shadow: 0 0 0 6px rgba(37,99,235,0); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); }
}
@keyframes pulseDotErr {
  0% { box-shadow: 0 0 0 0 rgba(220,38,38,.5); }
  70% { box-shadow: 0 0 0 6px rgba(220,38,38,0); }
  100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); }
}

#btnAsr {
  grid-column: 1;
  grid-row: 2;
  width: 36px;
  height: 36px;
  padding: 0;
  gap: 0;
  justify-self: start;
  align-self: center;
  min-width: auto;
  border-radius: 0;
}
#btnAsr.recording {
  background: var(--err);
  border-color: var(--err);
  color: #fff;
  box-shadow: 0 4px 14px rgba(220,38,38,.3);
}
#btnAsr.listening {
  color: var(--blue);
  border-color: var(--blue);
  animation: asrListenPulse 1.6s ease-in-out infinite;
}
#btnAsr.listening svg { stroke: var(--blue); }
@keyframes asrListenPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(37,99,235,.26); }
  50% { box-shadow: 0 0 0 6px rgba(37,99,235,.07); }
}
#btnAsr.recording svg { stroke: #fff; }
#btnAsr .asr-btn-text { font-size: 13px; font-weight: 700; }

#inputText {
  grid-column: 2;
  grid-row: 2;
  width: 100%;
  min-height: 36px;
  max-height: 120px;
  resize: none;
  overflow-y: auto;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  line-height: 1.45;
  transition: border-color .12s ease, background .12s ease, box-shadow .12s ease;
  box-sizing: border-box;
}
#inputText:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}

.btn-send {
  grid-column: 3;
  grid-row: 2;
  width: 36px;
  height: 36px;
  align-self: center;
  border-radius: 0;
  background: var(--blue); color: #fff; border-color: var(--blue);
  box-shadow: 0 2px 8px rgba(37,99,235,.28);
}
.btn-send:hover { background: var(--blue-dark); border-color: var(--blue-dark); }

.btn-send.stop-mode { background: var(--err); border-color: var(--err); box-shadow: 0 2px 8px rgba(220,38,38,.28); }
.btn-send.stop-mode:hover { background: #B91C1C; border-color: #B91C1C; }


.user-avatar {
  position: absolute;
  right: 18px;
  bottom: 72px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #DBEAFE;
  color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 3px 10px rgba(15,23,42,.12);
  font-weight: 700;
  font-size: 12px;
  z-index: 15;
  pointer-events: none;
}


.modal { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; }
.modal.show, .modal.open { display: flex; }
.modal-mask { position: absolute; inset: 0; background: rgba(15,23,42,.5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal-dialog {
  position: relative;
  width: 580px;
  max-width: calc(100vw - 40px);
  max-height: 88vh;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 800; color: var(--text); font-size: 16px; letter-spacing: .2px; }
.modal-body {
  padding: 18px 20px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.modal-confirm-text {
  font-size: 14px; line-height: 1.7; color: var(--text);
  white-space: pre-line; word-break: break-word;
}
.form-grid {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 12px 16px;
  align-items: center;
}
.form-grid label { color: var(--text-2); font-size: 13px; font-weight: 600; }
.agents-list-box {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 240px; overflow: auto;
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.agent-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.agent-row:hover { border-color: var(--border-2); background: var(--surface-2); }
.agent-row.active { background: var(--blue-light); border-color: var(--blue); }
.agent-row .ar-name { font-weight: 700; font-size: 13.5px; color: var(--text); }
.agent-row .ar-meta { font-size: 11px; color: var(--text-4); margin-top: 3px; }

.input {
  height: 38px; padding: 0 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: border-color .12s ease, box-shadow .12s ease;
  width: 100%;
  box-sizing: border-box;
}
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
textarea.input {
  height: auto;
  padding: 9px 12px;
  line-height: 1.5;
  resize: vertical;
  min-height: 88px;
}


.toast {
  position: fixed;
  top: 76px;
  right: 20px;
  z-index: 500;
  padding: 11px 16px;
  background: rgba(15,23,42,.94);
  color: #F8FAFC;
  border: 1px solid #1E293B;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  min-width: 230px;
  max-width: 440px;
  display: none;
  align-items: center;
  gap: 9px;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s ease;
}
.toast.show { display: flex; }
.toast.ok { background: #064E3B; color: #D1FAE5; border-color: #065F46; }
.toast.warn { background: #7C2D12; color: #FED7AA; border-color: #9A3412; }
.toast.err { background: #7F1D1D; color: #FECACA; border-color: #991B1B; }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }


.dh-mode {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  background: #0A1124;
  overflow: hidden;
}


.dh-mode .dh-inner {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  height: 100%;
  position: relative;
  background:
    radial-gradient(120% 80% at 50% 0%, #1C2A47 0%, #0E1730 55%, #070C1C 100%);
  box-shadow: 0 0 80px rgba(0,0,0,0.45);
  border-left: 1px solid rgba(255,255,255,.05);
  border-right: 1px solid rgba(255,255,255,.05);
}


.dh-settings-btn {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 200;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,23,42,0.55);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 50%;
  cursor: pointer;
  color: #E2E8F0;
  transition: background .15s ease, color .15s ease, transform .1s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.dh-settings-btn:hover {
  background: rgba(37,99,235,0.8);
  color: #fff;
  transform: rotate(35deg);
}
.dh-settings-btn svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
}


.dh-avatar-area {
  height: 100%;
  position: relative;
  overflow: hidden;
  background: transparent;
}
.dh-avatar-area canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  background: transparent !important;
}
.dh-avatar-area .avatar-2d-layer,
.dh-avatar-area .avatar-frames-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  pointer-events: none;
}
.dh-avatar-area .avatar-frames-layer img,
.dh-avatar-area .avatar-2d-layer img {
  width: auto;
  height: 88%;
  max-width: 92%;
  max-height: 92%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 22px 36px rgba(2,6,23,0.55));
}


.dh-status-chip {
  position: absolute;
  right: 18px;
  bottom: 84px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(15,23,42,0.6);
  color: #F1F5F9;
  padding: 6px 13px;
  font-size: 12px;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.2;
  box-shadow: 0 4px 14px rgba(2,6,23,.3);
}


.dh-messages {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 72px;
  max-height: 46vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 22px 8px;
  z-index: 20;
  pointer-events: none;
  
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 36px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 36px);
}
.dh-messages .msg-wrap { pointer-events: auto; }


.dh-messages .msg-wrap {
  display: flex;
  gap: 9px;
  max-width: 100%;
  align-items: flex-start;
  animation: dhMsgIn 0.22s ease;
  margin-bottom: 8px;
}
@keyframes dhMsgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.dh-messages .msg-wrap.msg-user { flex-direction: row-reverse; }
.dh-messages .msg-wrap.msg-assistant { flex-direction: row; }

.dh-messages .msg-avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(2,6,23,0.4);
}
.dh-messages .msg-body {
  max-width: 78%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.dh-messages .msg-user .msg-body { align-items: flex-end; }
.dh-messages .msg-assistant .msg-body { align-items: flex-start; }

.dh-messages .msg-text {
  padding: 9px 15px;
  line-height: 1.58;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
  word-break: break-word;
  overflow-wrap: anywhere;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #0F172A;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.22);
}
.dh-messages .msg-user .msg-text {
  background: rgba(37,99,235,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  border-color: rgba(37,99,235,0.45);
  border-radius: 16px 4px 16px 16px;
}
.dh-messages .msg-assistant .msg-text {
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #0F172A;
  border-color: rgba(255,255,255,0.4);
}
.dh-messages .msg-system .msg-text {
  background: rgba(148,163,184,0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-color: rgba(148,163,184,0.25);
  color: #E2E8F0;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 10px;
}
.dh-messages .msg-text.streaming::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  color: #2563EB;
  animation: blink 1s steps(2) infinite;
}
.dh-messages .msg-user .msg-text.streaming::after { color: #DBEAFE; }

.dh-messages .msg-text.md h1,.dh-messages .msg-text.md h2,
.dh-messages .msg-text.md h3,.dh-messages .msg-text.md h4 {
  margin: 6px 0 4px;
  line-height: 1.3;
}
.dh-messages .msg-text.md p { margin: 0 0 6px; }
.dh-messages .msg-text.md pre {
  background: rgba(15,23,42,0.08);
  padding: 7px 9px;
  overflow: auto;
  font-size: 12px;
  border: 1px solid rgba(0,0,0,0.1);
  margin: 4px 0;
  line-height: 1.4;
  border-radius: 8px;
}
.dh-messages .msg-text.md code {
  background: rgba(15,23,42,0.08);
  padding: 1px 4px;
  font-family: Consolas, Menlo, "SF Mono", monospace;
  font-size: 12px;
  border-radius: 5px;
}
.dh-messages .msg-name {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  padding: 0 5px;
}
.dh-messages .msg-user .msg-name { display: none; }


.dh-messages .typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
}
.dh-messages .typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 12px;
}
.dh-messages .typing-dots span {
  width: 5px;
  height: 5px;
  background: rgba(255,255,255,0.7);
  display: inline-block;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}


.dh-input-bar {
  position: absolute;
  bottom: 22px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 30;
  padding: 0;
  border: none;
  background: transparent;
  pointer-events: none;
}
.dh-input-bar > * {
  pointer-events: auto;
}

.dh-asr-btn {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(37,99,235,0.9);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  transition: background .15s ease, transform .15s ease, box-shadow .15s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(37,99,235,.4);
}
.dh-asr-btn:hover {
  background: rgba(37,99,235,1);
  transform: scale(1.06);
}
.dh-asr-btn:active {
  transform: scale(0.96);
}
.dh-asr-btn.recording {
  background: rgba(220,38,38,0.92);
  border-color: rgba(255,255,255,0.45);
  animation: dhPulse 1.3s ease-in-out infinite;
}
.dh-asr-btn.recording svg { display: none; }
.dh-asr-btn .asr-btn-text { display: none; font-size: 12px; font-weight: 700; }
.dh-asr-btn.recording .asr-btn-text { display: inline; }
@keyframes dhPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.45); }
  50% { box-shadow: 0 0 0 16px rgba(220,38,38,0); }
}


.dh-avatar-area .avatar-loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #CBD5E1;
  background: rgba(10,17,36,.5);
  font-size: 13px;
  font-weight: 600;
}
.dh-avatar-area .avatar-loading.hidden { display: none; }
.dh-avatar-area .spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #2563EB;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}


@media (max-width: 640px) {
  .dh-messages { padding: 10px 14px 6px; }
  .dh-messages .msg-body { max-width: 88%; }
  .dh-settings-btn { top: 12px; right: 12px; width: 38px; height: 38px; }
  .dh-asr-btn { width: 54px; height: 54px; }
  .dh-asr-btn svg { width: 22px; height: 22px; }
}


::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; border: 2px solid transparent; background-clip: padding-box; }


@media (max-width: 1280px) {
  .main { grid-template-columns: minmax(360px, 480px) 1fr; }
}
@media (max-width: 1100px) {
  .main { grid-template-columns: minmax(340px, 420px) 1fr; }
}
@media (max-width: 960px) {
  :root { --topbar-h: auto; }
  .col-mid {
    top: 52px;
    bottom: 0;
    height: calc(100vh - 52px);
    max-height: calc(100vh - 52px);
    overflow-y: auto;
    max-width: 82vw;
  }
  .topbar {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto;
    padding: 10px 12px;
    gap: 8px;
  }
  .top-center {
    grid-column: 1;
    justify-content: center;
  }
  .topbar-logo { display: none; }
  .context-wrap { max-width: 100%; min-width: 0; }

  /* ── 主布局：flex 纵向，聊天区填满剩余高度 ── */
  .main {
    height: auto;
    min-height: calc(100vh - var(--topbar-h, 80px));
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    max-height: none;
    padding: 10px;
    gap: 10px;
  }
  .col { height: auto; max-height: none; overflow: visible; flex-shrink: 0; }
  .col-left { display: none !important; }
  .avatar-stage { min-height: 200px; flex-shrink: 0; }
  /* 聊天区填满剩余空间 */
  .chat-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .messages-container {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 12px 10px;
  }
  .msg .bubble { max-width: 92%; }
}


.skeleton {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;   /* 旧内核不支持 inset，改用四边定位 */
  z-index: 500;
  background: #F6F7F9;
  display: flex; flex-direction: column; padding: 16px;
  box-sizing: border-box;
  transition: opacity .35s ease;
  /* 纯 CSS 自动消失兜底：即使 JS 的 setTimeout 被 WebView 后台节流/暂停，
     渲染时间线仍会在 5s 后淡出骨架屏，彻底杜绝「一直加载不消失」 */
  animation: sk-autohide .6s ease 5s forwards;
}
.skeleton.hide { opacity: 0; pointer-events: none; }
/* 渲染时间线驱动的兜底淡出（不受 JS 定时器节流影响） */
@keyframes sk-autohide {
  from { opacity: 1; visibility: visible; }
  to   { opacity: 0; visibility: hidden; }
}
.sk-topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 58px; flex: 0 0 auto;
}
.sk-topbar .sk-block { margin-left: 12px; }          /* 替代 flex gap（旧内核无 gap） */
.sk-topbar .sk-block:first-child { margin-left: 0; }
.sk-main {
  display: block;                                     /* 替代 grid minmax+gap（旧内核不支持） */
  margin-top: 14px; flex: 1; min-height: 0;
}
.sk-main:after { content: ""; display: block; clear: both; }   /* 清除浮动列 */
.sk-col {
  display: block; float: left; width: 33.3333%;
  box-sizing: border-box; padding-right: 14px; min-height: 0;
}
.sk-col:last-child { padding-right: 0; }
.sk-col .sk-block { margin-bottom: 14px; }           /* 替代 flex gap */
.sk-block {
  background: linear-gradient(90deg, #ECEEF3 25%, #F6F7FA 50%, #ECEEF3 75%);
  background-size: 200% 100%;
  border-radius: 12px;
  animation: sk-shimmer 1.4s infinite linear;
}
.sk-lines { position: relative; }
.sk-lines::after {
  content: "";
  position: absolute; top: 14px; right: 16px; bottom: 14px; left: 16px;   /* 替代 inset */
  background: linear-gradient(90deg, #ECEEF3 25%, #F6F7FA 50%, #ECEEF3 75%);
  background-size: 200% 100%;
  border-radius: 10px;
  animation: sk-shimmer 1.4s infinite linear;
}
@keyframes sk-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


.sk-logo-stage {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;             /* 替代 inset:0 */
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  z-index: 2;
}
.sk-logo-wrap {
  position: relative;
  width: 66vw; max-width: 560px;                     /* 替代 min(560px,66vw)（旧内核不支持 min()） */
  overflow: hidden;
}
.sk-logo { width: 100%; height: auto; display: block; }
.sk-shine {
  position: absolute; top: 0; left: 0;
  width: 14%; height: 100%;        
  background: linear-gradient(105deg,
    rgba(255,255,255,0) 0%,
    rgba(255,255,255,.30) 32%,
    rgba(255,255,255,.95) 50%,
    rgba(255,255,255,.30) 68%,
    rgba(255,255,255,0) 100%);
  transform: translateX(-220%);
  animation: sk-sweep 2s ease-in-out infinite;
  pointer-events: none;
  mix-blend-mode: screen;
}


@keyframes sk-sweep {
  0%   { transform: translateX(-220%); }
  55%  { transform: translateX(850%); }
  100% { transform: translateX(850%); }
}


.ctx-menu {
  position: fixed; z-index: 999;
  min-width: 168px; max-width: 260px;
  background: #FFFFFF;
  border: 1px solid #E5E7EB;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(2,6,23,.18);
  padding: 5px;
  display: none;
}
.ctx-menu.show { display: block; }
.ctx-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px; font-size: 13px; color: #334155;
  border-radius: 7px; cursor: pointer; user-select: none;
  white-space: nowrap;
}
.ctx-item:hover { background: #F1F5F9; }
.ctx-ic { display: inline-flex; color: #64748B; flex-shrink: 0; }
.ctx-item .ic { vertical-align: -2px; }


/* ═══════════════════ 手机适配 (≤960px) ═══════════════════ */
@media (max-width: 960px) {

  /* ── 骨架屏：logo 绝对定位全屏居中，骨架块单列流式排列在下方 ── */
  .skeleton {
    display: block;                 /* flex 列在部分旧内核不稳，改用 block 流式 */
  }
  .sk-topbar {
    display: flex; flex-wrap: wrap; height: auto; padding: 8px 0;
    justify-content: center; width: 100%;
  }
  .sk-topbar .sk-block { width: 30%; height: 32px !important; margin: 0 1.5%; }  /* 替代 flex:1 1 calc(50% - 6px) */
  .sk-main {
    display: block !important;      /* 替代 grid 1fr + gap（旧内核不支持） */
    width: 100%;                  /* 兼容旧内核：用百分比宽度而非依赖 grid */
    max-width: 420px; margin: 0 auto;
  }
  .sk-col { float: none; width: 100%; padding-right: 0; margin-bottom: 10px; }  /* 单列 */
  .sk-col .sk-block { margin-bottom: 10px; }   /* 替代 gap:10px */
  .sk-col .sk-block[style*="height:240px"] { height: 180px !important; }
  .sk-col .sk-block[style*="height:96px"] { height: 70px !important; }
  .sk-col .sk-block[style*="flex:1"] { min-height: 120px; }
  /* logo 覆盖层：保持 absolute 全屏居中（关键！不要改成 relative） */
  .sk-logo-stage {
    position: absolute !important;
    top: 0; right: 0; bottom: 0; left: 0 !important;   /* 替代 inset:0 !important */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 2;
    pointer-events: none;
  }
  .sk-logo-wrap { width: 60vw; max-width: 240px; }  /* 替代 min(240px,60vw) */

  /* ── 主布局：body 变 flex 列，main 自动填满顶栏后的全部空间 ── */
  html, body { overflow: hidden; }
  body {
    display: flex;
    flex-direction: column;
  }
  :root { --topbar-h: auto; }
  .col-mid {
    top: 46px;
    bottom: 0;
    height: calc(100vh - 46px);
    max-height: calc(100vh - 46px);
    overflow-y: auto;
  }
  .topbar {
    flex-shrink: 0;
    flex-wrap: wrap;
    height: auto;
    padding: 8px 10px;
 gap: 6px;
  }
  .main {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    width: 100%;
    padding: 10px;
    gap: 10px;
    box-sizing: border-box;
  }
  .col-left { display: none !important; }
  /* col-mid 已是 position:fixed，不影响主布局流 */
  .col {
    height: auto;
    max-height: none;
    overflow: visible;
    flex-shrink: 0;
  }
  .col-right {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  /* 手机端聊天区充分利用宽度 */
  .messages-container { padding: 12px 10px 8px; }
  .msg .bubble { max-width: 94%; }
  .chat-wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    height: 100%;
  }
  .messages-container {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* 输入栏固定在底部，不随内容滚动；去底部圆角 */
  .input-bar {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    border-radius: 0 !important;
  }
  /* chat-wrap 手机端去底部圆角 */
  .chat-wrap { border-radius: var(--radius) var(--radius) 0 0 !important; }
  /* textarea 单行不换行 */
  #inputText {
    white-space: nowrap;
    overflow-x: hidden;
  }

  .btn-toggle-sessions {
    display: flex;
    align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
  }
  .btn-toggle-sessions:hover { background: var(--surface-2); }

  /* 顶栏紧凑化：一行搞定 */
  .topbar {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    height: auto !important;
    min-height: auto;
    padding: 6px 8px;
    gap: 4px;
  }
  .top-left { order: 1; gap: 3px; }
  .top-center { order: 2; flex: 1; min-width: 0; justify-content: center; }
  .top-right { order: 3; }
  .topbar-logo { display: none; }
  .topbar-session { text-align: center; }

  /* 上下文栏在手机上隐藏（省空间） */
  .context-wrap { display: none !important; }

  /* 模型/音色下拉：手机端隐藏文字只留图标，或缩小到极简 */
  .btn-select {
    max-width: 80px !important;
    font-size: 11px !important;
    padding: 0 18px 0 6px !important;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }

  /* 输入工具栏：手机端换行 + 隐藏上下文 */
  .input-toolbar {
    flex-wrap: wrap;
    gap: 5px;
    padding: 5px 8px;
  }
  .input-toolbar .ctx-mini { display: none; }
  .input-toolbar .btn-select {
    max-width: calc(50% - 3px) !important;
    min-width: 0 !important;
    flex: 1 1 auto;
  }

  /* 输入框自适应 */
  #chatInput, #inputText { min-width: 0; flex: 1; }

  /* 用户头像缩小 */
  .user-avatar { right: 10px; bottom: 64px; width: 34px; height: 34px; font-size: 11px; }
}

/* 超小屏幕 (≤480px) 进一步优化 */
@media (max-width: 480px) {
  .sk-topbar .sk-block { flex: 1 1 100%; height: 28px !important; margin-bottom: 6px; }
  .btn-select { max-width: 100px !important; font-size: 11px; }
  .session-title { font-size: 14px; }
  .context-text { font-size: 11px; }
}

/* ── 会话操作菜单按钮（⋯，始终可见，替代仅 hover 的删除按钮，解决移动端右键/长按缺失）── */
.session-menu-btn {
  grid-column: 3; grid-row: 1 / span 2;
  display: flex; align-items: center; justify-content: center;
  opacity: .6; color: var(--text-3);
  background: none; border: none; border-radius: 8px;
  padding: 4px; cursor: pointer;
  align-self: center; justify-self: center;
  transition: opacity .15s ease, color .15s ease, background .15s ease;
}
.session-menu-btn:hover { opacity: 1; color: var(--text-1); background: rgba(15,23,42,.06); }
.session-item.active .session-menu-btn { color: var(--blue); }

.session-popup {
  position: fixed; z-index: 1200;
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.18);
  padding: 4px; min-width: 144px; display: none;
}
.session-popup.show { display: block; }
.sp-item {
  padding: 9px 12px; border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--text-1); white-space: nowrap;
}
.sp-item:hover { background: var(--surface-2); }
.sp-item.danger { color: #EF4444; }
.sp-item.danger:hover { background: rgba(239,68,68,.08); }

/* ── 消息操作弹层（引用 / 复制 / 删除）── */
.message-popup {
  position: fixed; z-index: 1200;
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(15,23,42,.18);
  padding: 4px; min-width: 120px; display: none;
}
.message-popup.show { display: block; }
.mp-item {
  padding: 9px 12px; border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--text-1); white-space: nowrap;
}
.mp-item:hover { background: var(--surface-2); }
.mp-item.danger { color: #EF4444; }
.mp-item.danger:hover { background: rgba(239,68,68,.08); }

/* ── 触摸设备：隐藏侧边栏 / 消息区的「幻滚动条」（WebView 下 overflow:auto 会常驻显示滚动条轨道）── */
@media (hover: none) and (pointer: coarse) {
  .session-list, .messages-container, .dh-messages {
    scrollbar-width: none; -ms-overflow-style: none;
  }
  .session-list::-webkit-scrollbar,
  .messages-container::-webkit-scrollbar,
  .dh-messages::-webkit-scrollbar { display: none; }
}
