/* === 全局变量 === */
:root {
  --primary: #185fa5;
  --primary-dark: #0c447c;
  --primary-light: #378add;
  --primary-bg: #e6f1fb;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  /* 数值语义：红优绿劣（国内习惯） */
  --up: #ef4444;
  --down: #10b981;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-light: #94a3b8;
  --bg-main: #f7f8fa;
  --bg-card: #ffffff;
  --bg-sunken: #f1f3f6;
  --border: #e3e6ec;
  --border-light: #eef0f4;
  /* 层级：1 次级卡 / 2 主卡（图表） / 3 浮层 */
  --elev-1: 0 1px 2px rgba(15, 23, 42, 0.04);
  --elev-2: 0 4px 16px rgba(15, 23, 42, 0.08);
  --elev-3: 0 10px 24px rgba(15, 23, 42, 0.1);
  --shadow-sm: var(--elev-1);
  --shadow: var(--elev-2);
  --shadow-lg: var(--elev-3);
  /* 间距 */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  /* 字号 */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                color 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === 重置 === */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
  /* 页脚贴底：内容不足时信息条不会浮在中间 */
  display: flex;
  flex-direction: column;
}

/* === 可访问性基线 === */
:where(a, button, textarea, input, [tabindex]):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* === 顶部导航 === */
.header {
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 0;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
}
.logo { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.logo-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.5px;
}
.logo-text { min-width: 0; }
.logo h1 {
  font-size: var(--fs-lg);
  font-weight: 600;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtitle {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-source-badge {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  background: var(--bg-sunken);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
}
.dot {
  width: 8px; height: 8px;
  background: var(--success);
  border-radius: 50%;
}
.dot.pulse {
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

/* === 主内容 === */
.main {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-8);
}

/* === 查询输入区 === */
.query-section { margin-bottom: 24px; }
.query-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--elev-1);
  border: 1px solid var(--border);
}
.query-input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.input-wrapper { flex: 1; min-width: 0; }
.input-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-light);
  margin-bottom: 6px;
}
.input-label svg { color: var(--text-light); }
#queryInput {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
  font-family: inherit;
  resize: none;
  transition: var(--transition);
  line-height: 1.6;
}
#queryInput:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.query-actions {
  display: flex;
  gap: 8px;
  flex-direction: column;
}
.btn-voice, .btn-query {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: var(--fs-md);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  padding: 10px 16px;
  min-height: 44px;
}
.btn-voice {
  background: var(--bg-card);
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-voice:hover {
  background: var(--primary-bg);
  border-color: var(--primary-light);
  color: var(--primary);
}
.btn-voice.recording {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  animation: recording-pulse 1.5s infinite;
}
@keyframes recording-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}
.btn-query {
  background: var(--primary);
  color: white;
  padding: 10px 24px;
}
.btn-query:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}
.btn-query:active { transform: translateY(0); }

/* 快捷查询 */
.quick-queries {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}
.quick-label {
  font-size: var(--fs-sm);
  color: var(--text-light);
  font-weight: 500;
  flex: 0 0 auto;
}
.quick-btn {
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  font-family: inherit;
}
.quick-btn:hover {
  background: var(--primary-bg);
  border-color: var(--primary-light);
  color: var(--primary);
}

/* 语音环境提示条（http 局域网访问导致语音被禁用时显示） */
.voice-env-warning {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  font-size: 13px;
  color: #92400e;
  line-height: 1.7;
}
.voice-env-warning code {
  background: #fef3c7;
  padding: 1px 7px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 12.5px;
  user-select: all; /* 手机长按可全选复制 */
}

/* 语音状态 */
.voice-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 16px;
  background: #fef2f2;
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}
/* 状态条实时识别文本：长文本截断为单行省略 */
.voice-status #voiceStatusText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 识别完成高亮：文字已上屏，提示可查询 */
#queryInput.voice-done {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}
.voice-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 24px;
}
.voice-wave span {
  display: block;
  width: 3px;
  background: var(--danger);
  border-radius: 2px;
  animation: wave 1.2s ease-in-out infinite;
}
.voice-wave span:nth-child(1) { height: 8px; animation-delay: 0s; }
.voice-wave span:nth-child(2) { height: 16px; animation-delay: 0.15s; }
.voice-wave span:nth-child(3) { height: 24px; animation-delay: 0.3s; }
.voice-wave span:nth-child(4) { height: 16px; animation-delay: 0.45s; }
.voice-wave span:nth-child(5) { height: 8px; animation-delay: 0.6s; }
@keyframes wave {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}

/* === 加载状态 === */
.loading-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.loader {
  width: 48px; height: 48px;
  border: 4px solid var(--border-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === 空状态 === */
.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-5) var(--sp-6);
}
.empty-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto var(--sp-4);
  border-radius: var(--radius);
  background: var(--primary-bg);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.empty-state p {
  color: var(--text-secondary);
  font-size: var(--fs-base);
  max-width: 520px;
  margin: 0 auto;
}
/* 数据概览：一条紧凑指标带，不再堆卡片 */
.data-overview {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0;
  margin: var(--sp-5) auto 0;
  padding: var(--sp-3) 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--elev-1);
  overflow: hidden;
}
.overview-stat {
  padding: 0 var(--sp-5);
  text-align: center;
  border-right: 1px solid var(--border-light);
  min-width: 92px;
}
.overview-stat:last-child { border-right: none; }
.overview-stat .value {
  font-size: var(--fs-xl);
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.overview-stat .label {
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

/* 空状态引导示例 */
.empty-hints {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}
.empty-hints .hint-label {
  font-size: var(--fs-sm);
  color: var(--text-light);
}

/* === 查询摘要条（原意图卡片，降级为条以突出图表） === */
.intent-card {
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
  border: 1px solid transparent;
}
.intent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: 6px;
}
.intent-header h3 {
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}
.query-text {
  font-size: var(--fs-sm);
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: var(--radius-sm);
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.intent-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.5;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.tag-metric { background: #e6f1fb; color: #185fa5; border-color: #c9ddf2; }
.tag-bank { background: #eaf3de; color: #3b6d11; border-color: #d3e6bd; }
.tag-type { background: #faeeda; color: #854f0b; border-color: #f2ddb8; }
.tag-date { background: #eeedfe; color: #534ab7; border-color: #d9d5f5; }
.tag-info { background: var(--bg-sunken); color: var(--text-secondary); }

/* === 可视化容器 === */
.viz-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.viz-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--elev-2);
  border: 1px solid var(--border);
  border-left: 2px solid var(--primary);
}
.viz-card-title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.viz-card-title .chart-type-badge {
  font-size: var(--fs-xs);
  font-weight: 400;
  background: var(--bg-sunken);
  color: var(--text-secondary);
  padding: 1px 8px;
  border-radius: var(--radius-sm);
}
.chart-container {
  position: relative;
  height: clamp(300px, 44vh, 460px);
}
.chart-container.small { height: clamp(260px, 32vh, 340px); }
.chart-container > canvas { display: block; }

/* 热力图（自绘 Canvas，无 Chart.js matrix 依赖） */
.chart-container.heatmap-box { overflow: hidden; }
.heat-tip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 5;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(30, 41, 59, 0.95);
  color: #fff;
  font-size: var(--fs-xs);
  line-height: 1.55;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
  box-shadow: var(--elev-2);
}
.heat-tip.show { opacity: 1; }

/* 双图表布局 */
.viz-container.two-cols {
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
}
@media (max-width: 900px) {
  .viz-container.two-cols { grid-template-columns: 1fr; }
}

/* === 数据表格 === */
.table-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--elev-1);
  border: 1px solid var(--border);
}
.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.table-header h3 {
  font-size: 15px;
  color: var(--text-primary);
}
.btn-export {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--primary-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--primary);
  cursor: pointer;
  transition: var(--transition);
}
.btn-export:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.table-wrapper {
  overflow-x: auto;
  max-height: 520px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-base);
}
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-sunken);
}
th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 500;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
tbody tr:nth-child(even) { background: #fafbfc; }
tbody tr:hover { background: var(--primary-bg); }
tbody tr:nth-child(even) td:first-child { background: #fafbfc; }
tbody tr:hover td:first-child { background: var(--primary-bg); }

/* 首列冻结：横向滚动时银行名称始终可见 */
th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-card);
  box-shadow: 1px 0 0 var(--border);
  min-width: 96px;
}
thead th:first-child { z-index: 3; background: var(--bg-sunken); }

.table-meta {
  font-size: var(--fs-xs);
  color: var(--text-light);
  font-weight: 400;
  margin-left: var(--sp-2);
}
.text-right { text-align: right; font-variant-numeric: tabular-nums; }
/* 数值语义：红优绿劣 */
.text-positive { color: var(--up); font-weight: 600; }
.text-negative { color: var(--down); font-weight: 600; }

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: var(--transition);
  z-index: 1000;
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* === 解析模式徽章（顶栏） === */
.parse-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-right: 8px;
  border: 1px solid transparent;
  transition: var(--transition);
}
.parse-mode-badge .mode-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.parse-mode-badge .mode-short { display: none; }
.data-source-badge .ds-short { display: none; }
.parse-mode-badge.mode-ai {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.parse-mode-badge.mode-rule {
  background: #f3f4f6;
  color: #6b7280;
  border-color: #e5e7eb;
}
.parse-mode-badge.mode-fallback {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fed7aa;
}
.parse-mode-badge.mode-unknown {
  background: #f9fafb;
  color: #9ca3af;
  border-color: #e5e7eb;
}

/* === 意图标签：解析模式 & 摘要 === */
.tag-mode-ai {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}
.tag-mode-rule {
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
}
.tag-mode-fallback {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}
.tag-summary {
  background: #fefce8;
  color: #a16207;
  border: 1px solid #fde68a;
  max-width: 100%;
}

/* === 响应式 === */
/* 中等屏幕：徽章简化文字 */
@media (max-width: 900px) {
  .parse-mode-badge .mode-full { display: none; }
  .parse-mode-badge .mode-short { display: inline; }
  .data-source-badge .ds-full { display: none; }
  .data-source-badge .ds-short { display: inline; }
  .parse-mode-badge { font-size: 11px; padding: 4px 10px; }
  .data-source-badge { font-size: 11px; padding: 4px 10px; }
}

/* 移动端布局 */
@media (max-width: 768px) {
  /* Header 改为两行布局：logo 一行，徽章一行 */
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 16px;
    gap: 8px;
  }
  .logo { justify-content: flex-start; }
  .logo-icon { width: 26px; height: 26px; font-size: 13px; }
  .logo h1 { font-size: var(--fs-md); }
  .subtitle { font-size: var(--fs-xs); line-height: 1.4; }
  .header-info {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
  .parse-mode-badge { margin-right: 0; flex: 1; min-width: 0; justify-content: center; }
  .data-source-badge { flex: 1; min-width: 0; justify-content: center; }
  
  /* 主内容 */
  .main { padding: 12px; }
  
  /* 查询输入区 */
  .query-box { padding: 14px; }
  .query-input-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .input-wrapper { width: 100%; }
  .input-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  .input-label svg { color: var(--primary); }
  #queryInput { font-size: 15px; padding: 12px 14px; }
  
  /* 按钮横向铺满，移动端更好点击 */
  .query-actions {
    flex-direction: row;
    width: 100%;
    gap: 10px;
  }
  .btn-voice, .btn-query { flex: 1; padding: 12px; min-height: 48px; }
  .btn-query { padding: 12px; }
  
  /* 快捷查询 */
  .quick-queries { gap: 6px; }
  .quick-label { width: 100%; margin-bottom: 4px; }
  .quick-btn { font-size: 11px; padding: 6px 10px; }
  
  /* 查询摘要条 */
  .intent-card { padding: var(--sp-2) var(--sp-3); }
  .intent-header { flex-direction: column; align-items: flex-start; gap: var(--sp-1); }
  .intent-header h3 { font-size: var(--fs-sm); }
  .query-text { font-size: var(--fs-sm); padding: 2px 8px; max-width: 100%; word-break: break-all; white-space: normal; }

  /* 可视化 */
  .viz-container { gap: var(--sp-3); }
  .viz-card { padding: var(--sp-3); }
  .viz-card-title { font-size: var(--fs-base); }
  .chart-container { height: clamp(240px, 46vh, 320px); }
  .chart-container.small { height: clamp(220px, 38vh, 280px); }

  /* 表格：首列冻结在窄屏同样生效，收窄列宽 */
  .table-section { padding: var(--sp-3); }
  .table-header { flex-wrap: wrap; gap: var(--sp-2); }
  .table-header h3 { font-size: var(--fs-base); }
  table { font-size: var(--fs-sm); }
  th, td { padding: 6px 10px; }
  th:first-child, td:first-child { min-width: 72px; }
  .table-wrapper { max-height: 60vh; }

  /* 空状态：指标带改为网格，保证窄屏不挤 */
  .empty-state { padding: var(--sp-6) var(--sp-4); }
  .empty-icon { width: 44px; height: 44px; }
  .empty-state h2 { font-size: var(--fs-md); }
  .empty-state p { font-size: var(--fs-base); }
  .data-overview {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    padding: var(--sp-3) 0;
  }
  .overview-stat {
    min-width: 0;
    padding: 0 var(--sp-2);
    border-right: 1px solid var(--border-light);
    border-bottom: none;
  }
  .overview-stat:nth-child(3n) { border-right: none; }
  .overview-stat:nth-child(n+4) { margin-top: var(--sp-2); }
  .overview-stat .value { font-size: var(--fs-lg); }
  .empty-hints { gap: 6px; }
  .empty-hints .hint-label { width: 100%; text-align: center; }
}

/* 超窄屏（< 380px，常见小屏手机） */
@media (max-width: 380px) {
  .header-inner { padding: 10px 12px; }
  .logo h1 { font-size: var(--fs-base); }
  .subtitle { font-size: 10px; }
  .main { padding: var(--sp-3); }
  .query-box { padding: var(--sp-3); }
  #queryInput { font-size: var(--fs-md); padding: 10px 12px; }
  .btn-voice .voice-text { display: inline; }
  .data-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview-stat:nth-child(3n) { border-right: 1px solid var(--border-light); }
  .overview-stat:nth-child(2n) { border-right: none; }
  .overview-stat:nth-child(n+3) { margin-top: var(--sp-2); }
  th:first-child, td:first-child { min-width: 64px; }
  .chart-container { height: 240px; }
}

/* ============================================================
   数据新鲜度 / 解析状态
   ============================================================ */

/* === 顶栏数据新鲜度徽章 === */
.header-info {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.data-source-badge {
  border: 1px solid transparent;
  white-space: nowrap;
  transition: var(--transition);
}
.data-source-badge .dot { flex: 0 0 auto; }

.data-source-badge.ds-loading {
  background: var(--bg-sunken);
  border-color: var(--border);
  color: var(--text-secondary);
}
.data-source-badge.ds-loading .dot { background: var(--primary-light); }

.data-source-badge.ds-live {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #047857;
}
.data-source-badge.ds-live .dot { background: #10b981; }

.data-source-badge.ds-parsing {
  background: #e6f1fb;
  border-color: #b5d4f4;
  color: #185fa5;
}
.data-source-badge.ds-parsing .dot { background: #378add; }

.data-source-badge.ds-stale {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}
.data-source-badge.ds-stale .dot { background: #f59e0b; animation: none; }

.data-source-badge.ds-offline {
  background: var(--bg-sunken);
  border-color: var(--border);
  color: var(--text-secondary);
}
.data-source-badge.ds-offline .dot { background: var(--text-light); animation: none; }

/* === 顶栏「重新解析」按钮 === */
.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}
.btn-refresh:hover:not(:disabled) {
  background: var(--primary-bg);
  border-color: var(--primary-light);
  color: var(--primary);
}
.btn-refresh:active:not(:disabled) { transform: translateY(0); }
.btn-refresh:disabled { opacity: 0.65; cursor: not-allowed; }
.btn-refresh .refresh-icon { flex: 0 0 auto; }
.btn-refresh.is-busy .refresh-icon { animation: spin 0.9s linear infinite; }

/* === 底部数据来源信息条 === */
.datasource-bar {
  margin-top: 36px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.ds-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 32px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 28px;
}
.ds-cell {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.ds-label {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-light);
}
.ds-value {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 360px;
}
.ds-cell-right { margin-left: auto; }
.ds-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.ds-badge-live { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.ds-badge-off  { background: #f3f4f6; color: #6b7280; border-color: #e5e7eb; }

/* === 空状态数据来源说明 === */
.empty-state .overview-note {
  max-width: 100%;
  margin: 14px auto 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-light);
  word-break: break-all;
}

/* 中等屏幕：信息条文字收窄 */
@media (max-width: 1100px) {
  .ds-value { max-width: 220px; }
}

/* 移动端：信息条换行显示 */
@media (max-width: 768px) {
  .datasource-bar { margin-top: 24px; }
  .ds-bar-inner { padding: 12px 16px; gap: 8px 16px; }
  .ds-cell { width: 100%; align-items: flex-start; }
  .ds-value { max-width: none; white-space: normal; word-break: break-all; }
  .ds-cell-right { margin-left: 0; }
  .btn-refresh { font-size: 11px; padding: 4px 10px; gap: 5px; }
  .data-source-badge { font-size: 11px; }
}

/* ============================================================
   方案 B：金融终端（Terminal）
   深海军蓝顶栏 / 压缩行高间距 / 数字等宽 / 信息密度最高
   回退方法：删除本区块即还原方案 A
   ============================================================ */
:root {
  /* 顶栏：深海军蓝（用户指定 #0d3b66） */
  --header-bg: #0d3b66;
  --header-bg-2: #0a2f52;
  --header-fg: #e8eef5;
  --header-fg-dim: #9db4cc;
  /* 底色偏冷，贴金融终端观感 */
  --bg-main: #eef1f5;
  --bg-sunken: #e9edf2;
  --border: #d8dee7;
  --border-light: #e6eaf0;
  /* 圆角收紧：终端感 */
  --radius: 6px;
  --radius-sm: 4px;
  --radius-lg: 8px;
}

/* --- 顶栏 --- */
.header {
  background: linear-gradient(180deg, var(--header-bg) 0%, var(--header-bg-2) 100%);
  border-bottom: 1px solid #08243f;
}
.header-inner { padding: 8px 20px; }
.logo h1 { color: var(--header-fg); }
.logo-icon { background: rgba(255, 255, 255, 0.12); color: #fff; }
.subtitle { color: var(--header-fg-dim); }
/* 徽章与按钮改为半透明描边，避免浅底块在深底上跳色 */
.data-source-badge {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--header-fg-dim);
}
.data-source-badge.ds-loading,
.data-source-badge.ds-offline {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--header-fg-dim);
}
.data-source-badge.ds-offline .dot { background: var(--header-fg-dim); }
.btn-refresh {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
  color: var(--header-fg);
}
.btn-refresh:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.38);
  color: #fff;
}

/* --- 信息密度：压缩容器与行高 --- */
.main { padding: 16px 24px; }
.query-box { padding: 12px 16px; }
.viz-card { padding: 14px; }
th { padding: 5px 10px; }
td { padding: 4px 10px; }

/* ⚠️ 本区块位于文件末尾，会盖掉上方所有断点。
   顶栏移动端内边距必须显式补回，否则 390px 下左右留白从 12px 变 20px */
@media (max-width: 768px) {
  .header-inner { padding: 8px 12px; }
  .main { padding: 12px 12px; }
}
