/* ============================================================
 * 钱包标准通用 UI 组件（AI数据中台等新原型页面复用）
 * 与钱包页面保持同一套设计令牌：主色 #165DFF，描边 #E5E6EB，
 * 卡片 10px 圆角，标签 4px 圆角，表头 #F5F7FA。
 * 页面需同时引入 shared/theme.css（基础排版 / 导航 / 说明面板 / 连线）。
 * ============================================================ */

/* ==================== 卡片 ==================== */
.card {
  background: #fff;
  border: 1px solid #E5E6EB;
  border-radius: 10px;
  padding: 24px;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; color: #1D2129; }
.card-sub { margin-top: 3px; font-size: 12px; color: #86909C; line-height: 1.6; }

/* ==================== 统计卡片 ==================== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid #E5E6EB;
  border-radius: 10px;
  padding: 20px 24px;
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, .05); }
.stat-label {
  margin-bottom: 8px;
  color: #86909C;
  font-size: 12px;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.stat-value {
  margin-bottom: 4px;
  color: #1D2129;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.stat-change { font-family: 'SF Mono', 'Menlo', monospace; font-size: 12px; }
.up { color: #CF1322; }
.down { color: #0E7B3A; }
.muted { color: #86909C; }

/* ==================== 按钮 ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid #E5E6EB;
  border-radius: 8px;
  background: #fff;
  color: #4E5969;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  transition: all .15s;
}
.btn:hover { border-color: #BCD0FF; color: #165DFF; }
.btn:active { transform: scale(.97); }
.btn-primary { background: #165DFF; border-color: #165DFF; color: #fff; }
.btn-primary:hover { background: #0E42D2; border-color: #0E42D2; color: #fff; }
.btn-danger { color: #CF1322; }
.btn-danger:hover { border-color: #F7BAB6; color: #CF1322; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 12px; border-radius: 4px; }
.btn-link {
  padding: 0;
  border: 0;
  background: none;
  color: #165DFF;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: #CF1322; }

/* ==================== 标签 ==================== */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
}
.tag-blue { background: rgba(22, 93, 255, .1); color: #165DFF; }
.tag-green { background: rgba(0, 180, 42, .1); color: #00B42A; }
.tag-orange { background: rgba(212, 107, 8, .1); color: #D46B08; }
.tag-red { background: rgba(207, 19, 34, .1); color: #CF1322; }
.tag-gray { background: #F5F7FA; color: #86909C; }
.tag-purple { background: rgba(114, 46, 209, .1); color: #722ED1; }

/* ==================== 表格 ==================== */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  padding: 10px 12px;
  background: #F5F7FA;
  border-bottom: 1px solid #E5E6EB;
  color: #1D2129;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.data-table td {
  padding: 12px;
  border-bottom: 1px solid #F2F3F5;
  color: #4E5969;
  vertical-align: middle;
}
.data-table tbody tr { transition: background-color .15s; }
.data-table tbody tr:hover { background: rgba(22, 93, 255, .04); }
.data-table tbody tr.selected { background: rgba(22, 93, 255, .06); }
.data-table .cell-strong { color: #1D2129; font-weight: 500; }
.data-table .cell-mono { font-family: 'SF Mono', 'Menlo', monospace; font-size: 12px; white-space: nowrap; }
.data-table .cell-sub { margin-top: 2px; color: #86909C; font-size: 11px; }
.data-table td:last-child { white-space: nowrap; }
.data-table td:last-child .btn-link + .btn-link { margin-left: 10px; }

/* ==================== 筛选 / 表单 ==================== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
}
.filter-item { display: flex; flex-direction: column; gap: 5px; }
.filter-item label { color: #86909C; font-size: 12px; }
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  border: 1px solid #E5E6EB;
  border-radius: 6px;
  background: #fff;
  color: #1D2129;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  transition: all .15s;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: #165DFF;
  box-shadow: 0 0 0 3px rgba(22, 93, 255, .1);
}
.form-textarea { resize: vertical; line-height: 1.7; }
.form-input[readonly] { background: #FAFBFC; color: #86909C; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { color: #1D2129; font-size: 13px; font-weight: 500; }
.field .hint { color: #86909C; font-size: 11px; line-height: 1.6; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; }
.form-grid .wide { grid-column: 1 / -1; }

/* ==================== 开关 ==================== */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: #C9CDD4;
  cursor: pointer;
  transition: .2s;
}
.switch span::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: .2s;
}
.switch input:checked + span { background: #165DFF; }
.switch input:checked + span::before { transform: translateX(16px); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid #F2F3F5; }
.switch-row:last-child { border-bottom: 0; }
.switch-row .switch-copy strong { display: block; color: #1D2129; font-size: 13px; font-weight: 500; }
.switch-row .switch-copy span { display: block; margin-top: 2px; color: #86909C; font-size: 11px; }

/* ==================== 标签页 / 选项块 ==================== */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid #E5E6EB; margin-bottom: 16px; }
.tab {
  margin-bottom: -1px;
  padding: 8px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: #4E5969;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tab:hover { color: #165DFF; }
.tab.active { color: #165DFF; border-bottom-color: #165DFF; font-weight: 600; }
.tab .count { margin-left: 4px; color: #86909C; font-size: 11px; }
.tab.active .count { color: #165DFF; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.chip {
  display: block;
  padding: 10px 12px;
  border: 1px solid #E5E6EB;
  border-radius: 8px;
  background: #fff;
  color: #1D2129;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: #BCD0FF; color: #165DFF; }
.chip small { display: block; margin-bottom: 2px; color: #86909C; font-size: 11px; }

/* ==================== 问答 ==================== */
.chat-row { display: flex; gap: 10px; margin-bottom: 16px; }
.chat-row:last-child { margin-bottom: 0; }
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #E8F3FF;
  color: #165DFF;
  font-size: 13px;
  font-weight: 600;
}
.avatar.ai { background: #165DFF; color: #fff; }
.bubble {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #F7F8FA;
  color: #1D2129;
  font-size: 13px;
  line-height: 1.75;
}
.bubble.user { background: #E8F3FF; }
.mini-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mini {
  padding: 12px;
  border: 1px solid #F2F3F5;
  border-radius: 8px;
  background: #F7F8FA;
}
.mini-label { color: #86909C; font-size: 11px; }
.mini-value {
  margin-top: 4px;
  color: #1D2129;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 18px;
  font-weight: 700;
}

/* ==================== 简易柱状图 ==================== */
.bar-chart { display: flex; align-items: flex-end; gap: 18px; height: 176px; padding: 4px 4px 0; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.bar-track { display: flex; align-items: flex-end; justify-content: center; gap: 4px; width: 100%; height: 150px; }
.bar { width: 18px; border-radius: 3px 3px 0 0; background: #4F6EF7; }
.bar.alt { background: #D46B08; }
.bar-x { color: #86909C; font-size: 11px; }

/* ==================== 提示块 ==================== */
.info-box {
  padding: 12px 14px;
  border: 1px solid #D6E4FF;
  border-radius: 8px;
  background: #F0F5FF;
  color: #4E5969;
  font-size: 12px;
  line-height: 1.75;
}
.warn-box {
  padding: 12px 14px;
  border: 1px solid #FFE7BA;
  border-radius: 8px;
  background: #FFF7E6;
  color: #AD6800;
  font-size: 12px;
  line-height: 1.75;
}
.mono { font-family: 'SF Mono', 'Menlo', monospace; }
.code-chip {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(22, 93, 255, .08);
  color: #165DFF;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 11px;
}

/* ==================== 指标卡片 ==================== */
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.metric-card {
  padding: 18px 20px;
  border: 1px solid #E5E6EB;
  border-radius: 10px;
  background: #fff;
}
.metric-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.metric-name { color: #1D2129; font-size: 15px; font-weight: 600; }
.metric-desc {
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #F7F8FA;
  color: #4E5969;
  font-size: 12px;
  line-height: 1.7;
}
.metric-row { display: flex; gap: 10px; font-size: 12px; line-height: 1.9; }
.metric-row .k { flex: 0 0 76px; color: #86909C; }
.metric-row .v { min-width: 0; color: #1D2129; word-break: break-all; }
.metric-foot { display: flex; align-items: center; gap: 14px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #F2F3F5; }
.metric-foot .btn-link { font-size: 12px; }

/* ==================== 历史提问 ==================== */
.history-item {
  margin-bottom: 4px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
}
.history-item:hover { border-color: #E8F3FF; background: #F7FAFF; }
.history-q {
  overflow: hidden;
  color: #1D2129;
  font-size: 13px;
  line-height: 1.5;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.history-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 5px; color: #86909C; font-size: 11px; }
.history-meta .hit { color: #4E5969; font-family: 'SF Mono', 'Menlo', monospace; }

/* ==================== 分页 ==================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  border-top: 1px solid #E5E6EB;
  color: #86909C;
  font-size: 12px;
}
.page-buttons { display: flex; gap: 4px; }
.page-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid #E5E6EB;
  border-radius: 4px;
  background: #fff;
  color: #4E5969;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.page-btn:hover:not(.disabled):not(.active) { background: #F7FAFF; color: #165DFF; }
.page-btn.active { background: #165DFF; border-color: #165DFF; color: #fff; }
.page-btn.disabled { color: #C9CDD4; cursor: not-allowed; }

/* ==================== Toast / Modal ==================== */
.toast {
  position: fixed;
  right: 26px;
  bottom: 25px;
  z-index: 200;
  padding: 10px 14px;
  border-radius: 8px;
  background: #1D2129;
  color: #fff;
  font-size: 12px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: all .25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.toast.show { opacity: 1; transform: translateY(0); }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, .35);
}
.modal-overlay.active { display: flex; }
.modal {
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 46px rgba(0, 0, 0, .16);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid #E5E6EB; }
.modal-head h3 { margin: 0; color: #1D2129; font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px; border-top: 1px solid #F2F3F5; background: #FAFBFC; }
.modal-close { border: 0; background: none; color: #86909C; font-size: 18px; line-height: 1; cursor: pointer; }
.modal-close:hover { color: #1D2129; }

/* ==================== 空状态 ==================== */
.empty { padding: 48px 20px; text-align: center; color: #86909C; font-size: 12px; }
.empty strong { display: block; margin-bottom: 6px; color: #1D2129; font-size: 15px; }

/* ==================== 响应式 ==================== */
@media (max-width: 1280px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .mini-metrics { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
}
@media (max-width: 768px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 16px; }
  .card { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr !important; }
}
