/* BI 对话。只使用驾驶舱已有 CSS 变量，类名统一 bi- 前缀。 */

body[data-view="bi"] .filters { display: none; }

.bi-app { min-width: 0; }
.bi-app [hidden] { display: none !important; }

.bi-badge {
  display: inline-flex; align-items: center; min-height: 22px; padding: 2px 8px;
  border-radius: 11px; color: var(--muted); background: var(--surface-2);
  font-size: 10px; font-weight: 650; white-space: nowrap;
}

.bi-layout {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start;
}
@media (min-width: 1100px) {
  .bi-layout { grid-template-columns: minmax(0, 1fr) 300px; }
}

.bi-chat.panel {
  display: flex; flex-direction: column; min-width: 0;
  height: calc(100vh - var(--topbar-h) - 150px); min-height: 520px;
  background: var(--canvas); overflow: hidden;
}
.bi-messages {
  flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column;
  gap: 12px; padding: 14px;
}
.bi-messages:has(.bi-welcome) { justify-content: center; }

.bi-welcome { width: min(560px, 100%); margin: 0 auto; }
.bi-welcome-mark {
  width: 36px; height: 36px; display: grid; place-items: center; margin-bottom: 10px;
  border-radius: 8px; color: var(--brand); background: var(--brand-soft);
}
.bi-welcome-mark svg { width: 18px; height: 18px; }
.bi-welcome strong { display: block; font-size: 16px; line-height: 1.35; }
.bi-welcome p { margin: 6px 0 12px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.bi-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bi-card-q {
  min-height: 72px; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 8px;
  background: var(--surface); color: var(--ink); text-align: left; cursor: pointer; font: inherit;
}
.bi-card-q:hover { border-color: var(--blue); background: var(--blue-soft); }
.bi-card-q span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }
.bi-card-q strong { display: block; font-size: 12.5px; font-weight: 650; line-height: 1.45; }

.bi-msg-user { align-self: flex-end; max-width: min(560px, 88%); }
.bi-bubble {
  padding: 8px 12px; border-radius: 12px 12px 4px 12px; background: var(--blue-soft);
  color: var(--ink); white-space: pre-wrap; word-break: break-word; line-height: 1.6;
}
.bi-msg-assistant { align-self: stretch; min-width: 0; }
.bi-card {
  min-width: 0; padding: 12px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 10px;
}
.bi-blocks { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.bi-card .panel { box-shadow: none; }
.bi-card .chart-wrap { min-height: 0; padding: 8px 10px 4px; }
.bi-head-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.bi-md { font-size: 13px; line-height: 1.65; word-break: break-word; }
.bi-md p { margin: 0 0 8px; }
.bi-md p:last-child { margin-bottom: 0; }
.bi-md-list { margin: 0 0 8px; padding-left: 18px; }
.bi-md-list li { margin: 2px 0; }
.bi-md-code {
  padding: 0 4px; border-radius: 4px; background: var(--surface-2);
  font-family: var(--mono); font-size: 12px;
}
.bi-caret::after {
  content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 2px;
  background: var(--brand); vertical-align: text-bottom;
  animation: bi-blink 1s steps(1) infinite;
}
@keyframes bi-blink { 50% { opacity: 0; } }
.bi-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.bi-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--quiet);
  animation: bi-dot 1s infinite ease-in-out;
}
.bi-dots i:nth-child(2) { animation-delay: .15s; }
.bi-dots i:nth-child(3) { animation-delay: .3s; }
.bi-loading { display: flex; align-items: center; gap: 8px; min-height: 18px; }
.bi-status { color: var(--muted); font-size: 12px; transition: opacity .32s ease; }
.bi-status.is-out { opacity: 0; }
@keyframes bi-dot {
  0%, 80%, 100% { opacity: .3; }
  40% { opacity: 1; }
}

.bi-table-scroll { overflow: auto; }
.bi-table-scroll.is-scroll { max-height: 360px; }
.bi-table-scroll table { border-collapse: separate; border-spacing: 0; }
.bi-table-scroll thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  box-shadow: inset 0 -1px 0 var(--rule);
}
.bi-table-scroll td { height: auto; padding: 8px 12px; }
.bi-row-flag td { background: var(--amber-soft); }
.bi-footnote {
  margin: 0; padding: 8px 14px 12px; color: var(--muted); font-size: 10.5px; line-height: 1.55;
}

.bi-chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.bi-pie {
  display: grid; grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  gap: 8px 16px; align-items: center;
}
.bi-pie svg { width: 100%; height: auto; display: block; }
.bi-pie-total { fill: var(--ink); font-size: 18px; font-weight: 720; font-family: var(--font); }
.bi-pie-sub { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.bi-pie-legend { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.bi-pie-row {
  display: grid; grid-template-columns: 8px minmax(0, 1fr) auto auto;
  gap: 8px; align-items: center; font-size: 12px;
}
.bi-pie-swatch { width: 8px; height: 8px; border-radius: 2px; }
.bi-pie-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bi-pie-share { color: var(--muted); }

.bi-sql { border-top: 1px solid var(--rule); padding-top: 8px; }
.bi-sql summary { cursor: pointer; color: var(--blue); font-size: 12px; font-weight: 650; }
.bi-sql summary:hover { text-decoration: underline; }
.bi-sql-views { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.bi-sql pre {
  margin: 0 0 8px; padding: 10px 12px; overflow: auto; max-height: 240px;
  border-radius: 6px; background: var(--surface-2); color: var(--ink);
  font-family: var(--mono); font-size: 11px; line-height: 1.55; white-space: pre;
}
.bi-sql-time { margin: 0 0 8px; color: var(--muted); font-size: 10.5px; }

.bi-error { padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); }
.bi-error strong { display: block; font-size: 12.5px; line-height: 1.5; }
.bi-error-code { display: block; margin-top: 4px; color: var(--muted); font-family: var(--mono); font-size: 10px; }
.bi-error .btn { margin-top: 8px; }

.bi-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 8px; color: var(--muted); font-size: 10.5px;
}
.bi-scope {
  display: inline-flex; align-items: center; min-height: 20px; padding: 0 8px;
  border-radius: 10px; font-size: 10px; font-weight: 650; cursor: help;
}
.bi-scope-snapshot { color: var(--blue); background: var(--blue-soft); }
.bi-scope-latest { color: var(--green); background: var(--green-soft); }
.bi-req {
  max-width: 100%; padding: 0; border: 0; background: none; cursor: pointer;
  color: var(--quiet); font-family: var(--mono); font-size: 10px;
}
.bi-req:hover { color: var(--blue); }
.bi-note-inline { color: var(--muted); }

.bi-composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  background: var(--surface); border-top: 1px solid var(--rule);
}
.bi-composer textarea {
  flex: 1; min-width: 0; min-height: 38px; max-height: calc(1.5em * 4 + 16px);
  padding: 8px 10px; resize: none; overflow: auto; border: 1px solid var(--rule-strong);
  border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; line-height: 1.5;
}
.bi-composer textarea:hover { border-color: var(--quiet); }
.bi-composer textarea:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.bi-composer-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.bi-composer .btn:disabled { opacity: .55; cursor: not-allowed; }

.bi-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.bi-examples { max-height: 460px; overflow: auto; }
.bi-cat { padding: 8px 12px 2px; color: var(--muted); font-size: 10px; font-weight: 700; }
.bi-q {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  width: 100%; padding: 8px 12px; border: 0; border-top: 1px solid var(--rule);
  background: transparent; color: var(--ink); text-align: left; cursor: pointer; font: inherit; line-height: 1.45;
}
.bi-q:hover { background: var(--blue-soft); }
.bi-q-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.bi-caveat {
  margin: 0; padding: 0; list-style: none; color: var(--muted); font-size: 10.5px; line-height: 1.55;
}
.bi-caveat li { display: flex; align-items: flex-start; gap: 6px; margin: 3px 0; }
.bi-caveat svg, .bi-caveat i { width: 12px; height: 12px; flex: 0 0 auto; margin-top: 2px; }
.bi-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
button.cat-tag {
  border: 0; cursor: pointer; font: inherit; line-height: 1.4;
}
button.cat-tag:hover { color: var(--blue); background: var(--blue-soft); }
.bi-caliber ul { margin: 0; padding-left: 18px; }
.bi-caliber li { margin: 6px 0; line-height: 1.6; }

@media (max-width: 640px) {
  .bi-cards, .bi-pie { grid-template-columns: 1fr; }
  .bi-composer { flex-wrap: wrap; }
  .bi-composer-actions { width: 100%; justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) {
  .bi-caret::after, .bi-dots i { animation: none; }
  .bi-status { transition: none; }
}
