/* ===== 变量 / 重置 / 字体 ===== */
:root {
  /* 背景色阶 */
  --bg-0: #0a0d12;
  --bg-1: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1c222b;
  --bg-4: #232a35;

  /* 边框 */
  --border-1: #2a313c;
  --border-2: #353d4a;

  /* 文本 */
  --text-1: #e8edf3;
  --text-2: #b0bac6;
  --text-3: #6e7884;
  --text-4: #4a5260;

  /* 强调色（六间房橙红） */
  --accent: #ff6b1a;
  --accent-dim: #b84a0f;
  --accent-cyan: #22d3ee;
  --accent-amber: #f59e0b;
  --accent-green: #34d399;
  --accent-violet: #a78bfa;

  /* 状态色 */
  --state-idle: #6e7884;
  --state-connecting: #f59e0b;
  --state-live: #34d399;
  --state-error: #fe2c55;

  /* 字体 */
  --font-sans: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;

  /* 圆角 */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* 阴影 */
  --shadow-1: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 4px 12px rgba(0,0,0,0.35);
  --shadow-3: 0 8px 24px rgba(0,0,0,0.45);
  --shadow-glow: 0 0 0 1px rgba(255,107,26,0.3), 0 0 16px rgba(255,107,26,0.2);

  /* 过渡 */
  --t-fast: 120ms ease;
  --t-base: 200ms ease;
  --t-slow: 360ms cubic-bezier(.16,.84,.44,1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-0);
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

body {
  background:
    radial-gradient(circle at 12% 0%, rgba(255,107,26,0.08), transparent 40%),
    radial-gradient(circle at 88% 8%, rgba(34,211,238,0.05), transparent 45%),
    var(--bg-0);
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
button { cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.accent-cyan { color: var(--accent-cyan); }
.accent-amber { color: var(--accent-amber); }
.accent-green { color: var(--accent-green); }
.accent-red { color: var(--state-error); }

/* 滚动条 */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-1);
  border-radius: 6px;
  border: 2px solid var(--bg-1);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

::selection { background: rgba(255,107,26,0.3); color: var(--text-1); }

/* ===== 顶部品牌条 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
  box-shadow: var(--shadow-1);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 2px 8px rgba(255,107,26,0.4);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-size: 15px; font-weight: 700; color: var(--text-1); }
.brand-sub { font-size: 11px; color: var(--text-3); font-family: var(--font-mono); letter-spacing: 0.5px; }

.status-bar {
  display: flex;
  align-items: center;
  gap: 20px;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: 20px;
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--state-idle);
  transition: var(--t-base);
}
.status-dot[data-state="connecting"] {
  background: var(--state-connecting);
  animation: pulse 1.2s infinite;
}
.status-dot[data-state="live"] {
  background: var(--state-live);
  box-shadow: 0 0 8px var(--state-live);
}
.status-dot[data-state="error"] {
  background: var(--state-error);
  box-shadow: 0 0 8px var(--state-error);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.status-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.2;
}
.status-item-label {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.status-item-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
}

/* ===== 主体布局 ===== */
.app-body {
  display: grid;
  grid-template-columns: 1fr;
  height: calc(100vh - 56px);
  overflow: hidden;
}
/* 有房间标签栏时减去标签栏高度 */
.app-body.with-tabs {
  height: calc(100vh - 56px - 44px);
}

/* ===== 多房间标签栏 ===== */
.room-tabs-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border-1);
  height: 44px;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}
.room-tabs-bar::-webkit-scrollbar { height: 4px; }
.room-tabs-bar::-webkit-scrollbar-thumb { background: var(--border-1); border-radius: 2px; }
.room-tabs-list {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.room-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border-1);
  border-radius: 6px;
  background: var(--bg-2);
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  max-width: 200px;
}
.room-tab:hover {
  border-color: var(--accent);
  color: var(--text-1);
}
.room-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.room-tab-name {
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}
.room-tab-anchor {
  font-size: 11px;
  opacity: 0.8;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  font-size: 14px;
  line-height: 1;
  opacity: 0.6;
  transition: all 0.15s;
}
.room-tab-close:hover {
  opacity: 1;
  background: rgba(255,255,255,0.2);
}
.room-tab.active .room-tab-close:hover {
  background: rgba(0,0,0,0.2);
}
.room-tab-add {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px dashed var(--border-1);
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.room-tab-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.room-tab-add:focus-within {
  border-color: var(--accent);
  border-style: solid;
  background: var(--bg-2);
}
.new-room-input {
  width: 92px;
  padding: 2px 4px;
  border: none;
  background: transparent;
  color: var(--text-1);
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  outline: none;
}
.new-room-input::placeholder {
  color: var(--text-3);
  opacity: 0.7;
}

/* 房间标签上的状态切换按钮（●绿=已连接 / ●黄=连接中 / ○红=已断开） */
.room-tab-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.room-tab-state.connected {
  color: var(--accent-green);
  text-shadow: 0 0 6px var(--accent-green);
}
.room-tab-state.connecting {
  color: var(--state-connecting);
  text-shadow: 0 0 6px var(--state-connecting);
  animation: tab-pulse 1s ease-in-out infinite;
}
.room-tab-state.disconnected {
  color: var(--state-error);
  opacity: 0.7;
}
.room-tab-state:hover {
  transform: scale(1.3);
}
.room-tab-state.connected:hover {
  color: var(--state-error);
  text-shadow: 0 0 6px var(--state-error);
}
.room-tab-state.connecting:hover {
  animation: none;
  opacity: 1;
}
.room-tab-state.disconnected:hover {
  color: var(--accent-green);
  text-shadow: 0 0 6px var(--accent-green);
  opacity: 1;
}
@keyframes tab-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
/* 连接中状态（●黄闪烁）的标签 */
.room-tab.tab-connecting {
  opacity: 0.75;
}
.room-tab.tab-connecting:hover {
  opacity: 0.9;
}
/* 软断开状态（○红）的标签整体变灰 */
.room-tab.tab-disconnected {
  opacity: 0.55;
  border-style: dashed;
}
.room-tab.tab-disconnected:hover {
  opacity: 0.85;
}

/* 左右两栏布局：左弹幕 / 右控制台 */
.app-body.app-grid {
  grid-template-columns: 1fr 460px;
  gap: 0;
}

/* 左侧弹幕区：填满高度 */
.danmu-side {
  display: flex;
  flex-direction: column;
  padding: 20px 16px 20px 20px;
  gap: 12px;
  overflow: hidden;
  min-width: 0;
}

/* 右侧控制台：固定宽度，独立滚动 */
.control-side {
  display: flex;
  flex-direction: column;
  padding: 20px 20px 20px 16px;
  gap: 16px;
  overflow-y: auto;
  border-left: 1px solid var(--border-1);
  background: var(--bg-1);
  min-width: 0;
}

.main-panel {
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 16px;
  overflow: hidden;
}

/* ===== 连接卡片 ===== */
.connect-card {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: var(--shadow-1);
}

.connect-card .field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.connect-card label {
  font-size: 12px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.connect-card input {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: 10px 12px;
  color: var(--text-1);
  font-size: 14px;
  transition: var(--t-fast);
}
.connect-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,107,26,0.15);
}

.btn {
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 13px;
  transition: var(--t-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}
/* 连接卡片中的按钮进一步紧凑 */
.connect-card .btn {
  padding: 8px 12px;
  font-size: 13px;
}
.connect-card .btn svg {
  flex-shrink: 0;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dim) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255,107,26,0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(255,107,26,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-ghost {
  background: var(--bg-2);
  color: var(--text-2);
  border: 1px solid var(--border-1);
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text-1); }

/* ===== 房间信息条 ===== */
.room-info {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow-1);
}
.room-info .anchor-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-3);
  overflow: hidden;
  flex-shrink: 0;
}
.room-info .anchor-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.room-info .anchor-avatar .fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent);
  background: linear-gradient(135deg, var(--bg-3), var(--bg-2));
}
.room-info .room-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.room-info .room-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-1);
}
.room-info .room-sub {
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  gap: 12px;
}
.room-info .hot-display {
  text-align: right;
}
.room-info .hot-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
}
.room-info .hot-label {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
}

/* ===== 弹幕列表 ===== */
.danmu-panel {
  flex: 1;
  min-height: 220px;
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-1);
}

.danmu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-1);
  background: var(--bg-2);
}
.danmu-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  display: flex;
  align-items: center;
  gap: 8px;
}
.danmu-header .count {
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  font-weight: 700;
}
.danmu-header .filters {
  display: flex;
  gap: 6px;
}
.filter-btn {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  color: var(--text-3);
  border: 1px solid var(--border-1);
  transition: var(--t-fast);
}
.filter-btn:hover { color: var(--text-2); }
.filter-btn.active {
  background: rgba(255,107,26,0.15);
  color: var(--accent);
  border-color: var(--accent);
}

.danmu-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* 页面内发弹幕输入框（贴在弹幕列表下方） */
.inline-send {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-1);
  border-top: 1px solid var(--border-1);
  flex-shrink: 0;
}

.inline-send-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  color: var(--text-0);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
}

.inline-send-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 107, 26, 0.15);
}

.inline-send-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.inline-send-btn {
  flex-shrink: 0;
  padding: 8px 16px;
}

.inline-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.danmu-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  transition: var(--t-fast);
  animation: slideIn 0.3s ease;
}
.danmu-item:hover { background: var(--bg-2); }
.danmu-item + .danmu-item { border-top: 1px solid rgba(42,49,60,0.4); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.danmu-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-3);
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
}
.danmu-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.danmu-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.danmu-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.danmu-name {
  color: var(--text-2);
  font-weight: 500;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.danmu-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
}
.tag-chat { background: rgba(34,211,238,0.15); color: var(--accent-cyan); }
.tag-member { background: rgba(52,211,153,0.15); color: var(--accent-green); }
.tag-social { background: rgba(167,139,250,0.15); color: var(--accent-violet); }
.tag-gift { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.tag-reasoning { background: rgba(236,72,153,0.15); color: #f472b6; }
.tag-asr { background: rgba(99,102,241,0.15); color: #818cf8; }

/* 财富等级标签：按等级分段着色 */
.danmu-wealth {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.wealth-1  { background: rgba(107,114,128,0.18); color: #9ca3af; }      /* 1-3 新手(灰) */
.wealth-4  { background: rgba(59,130,246,0.18);  color: #60a5fa; }      /* 4-9 普通(蓝) */
.wealth-10 { background: rgba(139,92,246,0.20);  color: #a78bfa; }      /* 10-19 进阶(紫) */
.wealth-20 { background: rgba(249,115,22,0.20);  color: #fb923c; }      /* 20-29 高级(橙) */
.wealth-30 { background: rgba(239,68,68,0.22);   color: #f87171; }      /* 30+ 大佬(红) */

.danmu-time {
  margin-left: auto;
  color: var(--text-4);
  font-family: var(--font-mono);
  font-size: 11px;
}
.danmu-text {
  color: var(--text-1);
  font-size: 14px;
  word-break: break-word;
  line-height: 1.4;
}
.danmu-text.member { color: var(--text-3); font-style: italic; }
.danmu-text.social { color: var(--accent-violet); }
.danmu-text.gift {
  color: var(--accent-amber);
  font-weight: 600;
}
.danmu-text.asr {
  color: #818cf8;
  font-style: italic;
  border-left: 2px solid rgba(99,102,241,0.4);
  padding-left: 8px;
}

/* 礼物徽章：显示礼物名 · 数量 · 币数 */
.gift-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 700;
  background: linear-gradient(135deg, rgba(245,158,11,0.25), rgba(239,68,68,0.20));
  color: #fbbf24;
  border: 1px solid rgba(245,158,11,0.35);
  white-space: nowrap;
  letter-spacing: 0.3px;
}

/* AI 推理过程卡片 */
.danmu-item.reasoning-item {
  background: linear-gradient(135deg, rgba(236,72,153,0.06), rgba(139,92,246,0.05));
  border-left: 3px solid #ec4899;
  padding: 10px 12px;
}
.danmu-item.reasoning-item:hover {
  background: linear-gradient(135deg, rgba(236,72,153,0.10), rgba(139,92,246,0.08));
}
.reasoning-trigger,
.reasoning-reply {
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.5;
}
.reasoning-label {
  color: #f472b6;
  font-weight: 600;
  font-size: 11px;
}
.reasoning-source {
  color: var(--text-2);
}
.reasoning-reply-text {
  color: #fbbf24;
  font-weight: 600;
}
.reasoning-body {
  font-size: 12px;
  color: var(--text-3);
  background: rgba(0,0,0,0.25);
  border-radius: 4px;
  padding: 6px 8px;
  margin-top: 6px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
  border: 1px dashed rgba(236,72,153,0.25);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-3);
  gap: 12px;
  padding: 40px;
  text-align: center;
}
.empty-state svg { opacity: 0.4; }
.empty-state .title { font-size: 16px; font-weight: 600; color: var(--text-2); }
.empty-state .desc { font-size: 13px; max-width: 400px; }

/* ===== 错误提示 ===== */
.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--state-error);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-3);
  z-index: 1000;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .status-bar { gap: 12px; }
  .status-item-label { display: none; }
  .connect-card { flex-direction: column; align-items: stretch; }
  .room-info { flex-wrap: wrap; }
  /* 窄屏：左右两栏改为上下两栏（弹幕在上，控制台在下） */
  .app-body.app-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    height: auto;
    min-height: calc(100vh - 56px);
  }
  .danmu-side { height: 60vh; padding: 12px; }
  .control-side {
    border-left: none;
    border-top: 1px solid var(--border-1);
    overflow-y: visible;
    max-height: none;
  }
}

/* ===== AI 自动回复面板 ===== */
.ai-panel {
  background: var(--bg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-1);
  flex-shrink: 0;
}
.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(167,139,250,0.10), rgba(34,211,238,0.06));
  border-bottom: 1px solid var(--border-1);
}
.ai-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-header h3 svg { color: var(--accent-violet); }
.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* 折叠按钮 */
.ai-collapse-btn {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ai-collapse-btn:hover {
  background: var(--bg-2);
  color: var(--text-1);
}
.ai-collapse-icon {
  transition: transform 0.2s ease;
}
/* 折叠态：箭头朝左（chevron 旋转 -90deg） */
.ai-panel.collapsed .ai-collapse-icon {
  transform: rotate(-90deg);
}

/* body 折叠（改用 display 切换：内容高度超过 max-height 会被裁切，
   此前 max-height:2000px 导致面板底部"上下文容量/入库清理"被裁掉不显示） */
.ai-body {
  max-height: calc(100vh - 220px);  /* 分组全展开后内容很长：限制面板高度，内部滚动 */
  overflow-y: auto;
}
.ai-body > * {
  flex-shrink: 0;  /* 限高 flex 容器：禁止压缩子项，超出改为整体滚动 */
}
.ai-panel.collapsed .ai-body {
  display: none;
}

/* 开关 */
.ai-switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 22px;
}
.ai-switch input { opacity: 0; width: 0; height: 0; }
.ai-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 22px;
  transition: var(--t-base);
}
.ai-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-3);
  border-radius: 50%;
  transition: var(--t-base);
}
.ai-switch input:checked + .ai-slider {
  background: rgba(167,139,250,0.30);
  border-color: var(--accent-violet);
}
.ai-switch input:checked + .ai-slider::before {
  transform: translate(20px, -50%);
  background: var(--accent-violet);
}

.ai-body {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 提供商专属配置行：按当前所选提供商按需显示（JS 控制 hidden） */
.ai-sub {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-sub[hidden] { display: none; }
.ai-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;  /* 按钮过多时换行，避免被压缩到无法显示 */
  gap: 8px 12px;
  font-size: 13px;
}
.ai-label {
  color: var(--text-3);
  font-size: 12px;
  min-width: 90px;
  flex-shrink: 0;  /* 标签不被压缩 */
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.ai-value {
  color: var(--text-1);
  font-weight: 500;
  flex: 1;
  min-width: 40px;  /* 防止 flex:1 把它压到 0 */
}
.ai-hint {
  color: var(--text-3);
  font-size: 12px;
  font-style: italic;
}
.ai-input {
  flex: 1;
  min-width: 80px;  /* 保证输入框有最小宽度 */
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  color: var(--text-1);
  font-size: 13px;
}
.ai-input:focus {
  outline: none;
  border-color: var(--accent-violet);
  box-shadow: 0 0 0 2px rgba(167,139,250,0.15);
}

/* 风格选择器 */
.ai-select {
  flex: 1;
  min-width: 100px;  /* 保证 select 有最小宽度 */
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--r-sm);
  padding: 5px 10px;
  color: var(--text-1);
  font-size: 13px;
  cursor: pointer;
}
.ai-select:focus {
  outline: none;
  border-color: var(--accent-violet);
  box-shadow: 0 0 0 2px rgba(167,139,250,0.15);
}
.ai-select option {
  background: var(--bg-2);
  color: var(--text-1);
}
.ai-style-desc {
  color: var(--text-3);
  font-size: 11px;
  padding: 0 4px 0 102px;  /* 与 label 对齐 */
  line-height: 1.5;
  font-style: italic;
}

/* 小号开关（用于推理过程开关） */
.ai-switch-small {
  width: 32px !important;
  height: 16px !important;
  flex-shrink: 0;
}
.ai-switch-small .ai-slider::before {
  width: 12px !important;
  height: 12px !important;
}
.ai-switch-small input:checked + .ai-slider::before {
  /* 必须保留 Y 轴 -50% 居中，否则会错位 */
  transform: translate(16px, -50%) !important;
}

.btn-small {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: var(--r-sm);
  background: var(--bg-3);
  color: var(--text-2);
  border: 1px solid var(--border-1);
  font-weight: 500;
  flex-shrink: 0;  /* 按钮不被压缩，避免文字被截断 */
  white-space: nowrap;  /* 按钮文字不换行 */
  transition: var(--t-fast);
}
.btn-small:hover {
  background: var(--bg-4);
  color: var(--text-1);
}
.btn-small.primary {
  background: linear-gradient(135deg, var(--accent-violet), #7c3aed);
  color: #fff;
  border: none;
}
