:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --line: #d9e1ea;
  --text: #475467;
  --muted: #667085;
  --blue: #1d4ed8;
  --teal: #0f766e;
  --amber: #b45309;
  --red: #b91c1c;
  --green: #15803d;
  --shadow: 0 10px 28px rgba(20, 33, 61, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
  color: var(--blue);
}

select,
input {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  min-width: 120px;
}

input:focus,
select:focus,
textarea:focus,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.topbar-main {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  gap: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.record-count {
  position: relative;
  display: inline-flex;
  align-items: flex-start;
  gap: 3px;
  color: var(--text);
}

.record-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-top: -6px;
  border: 1px solid var(--blue);
  border-radius: 50%;
  color: var(--blue);
  background: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
}

.record-tooltip {
  position: absolute;
  left: 100%;
  top: -8px;
  z-index: 20;
  display: none;
  width: 360px;
  max-width: min(360px, 80vw);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  line-height: 1.6;
}

.record-count:hover .record-tooltip,
.record-help:focus + .record-tooltip {
  display: block;
}

.toolbar {
  display: flex;
  flex: 0 0 auto;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.forecast-only-control {
  display: none;
}

.forecast-only-control[hidden] {
  display: none !important;
}

body.forecast-tab-active .forecast-only-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.analysis-range-control[hidden] {
  display: none !important;
}

.anomaly-range-control[hidden] {
  display: none !important;
}

.toolbar label.forecast-only-control {
  flex-direction: row;
  align-items: center;
}

.field-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
}

.field-help {
  position: absolute;
  left: -8px;
  top: -8px;
  margin-left: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--blue);
  background: #fff;
  color: var(--blue);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  cursor: help;
}

.field-tooltip {
  position: absolute;
  left: auto;
  right: calc(100% + 10px);
  top: -4px;
  bottom: auto;
  z-index: 120;
  min-width: 128px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: none;
  transition: opacity 0.12s ease, visibility 0.12s ease;
}

.field-help:hover + .field-tooltip,
.field-help:focus + .field-tooltip {
  opacity: 1;
  visibility: visible;
}

#horizonInput {
  width: 82px;
  min-width: 82px;
}

.layout-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  transition: grid-template-columns 0.18s ease;
}

.layout-shell.sidebar-collapsed {
  grid-template-columns: 68px minmax(0, 1fr);
}

.sidebar {
  grid-row: 1 / span 2;
  position: relative;
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 12px 10px;
  min-width: 0;
}

.brand-block {
  display: flex;
  position: relative;
  align-items: center;
  gap: 10px;
  height: 58px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
  overflow: visible;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue);
  background: #fff;
  font-weight: 800;
}

.brand-mark svg,
.tab-icon svg,
.sidebar-toggle svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
  stroke-width: 2.1;
}

.brand-title {
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}

.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: -16px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--blue);
  background: #fff;
  transform: translateY(-50%);
}

.sidebar-toggle svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.2;
}

.layout-shell.sidebar-collapsed .brand-title,
.layout-shell.sidebar-collapsed .tab-label {
  display: none;
}

.layout-shell.sidebar-collapsed .brand-block {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.layout-shell.sidebar-collapsed .sidebar-toggle {
  right: -30px;
  transform: translateY(-50%) rotate(180deg);
}

main {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.tabbar {
  display: grid;
  gap: 8px;
}

.tab-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  height: 42px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  text-align: left;
}

.tab-btn:hover {
  background: #f7f9fc;
}

.tab-btn.active {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: var(--blue);
}

.tab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--blue);
  background: #fff;
}

.tab-icon svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout-shell.sidebar-collapsed .tab-btn {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.tab-panel {
  display: block;
}

.tab-panel[hidden] {
  display: none;
}

#tab-query {
  height: 100%;
}

.overview-range-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.overview-range-bar[hidden] {
  display: none !important;
}

.topbar-overview-range {
  width: auto;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  justify-content: flex-start;
  align-items: center;
}

.range-picker {
  position: relative;
  display: inline-flex;
}

.range-picker-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  min-width: 0;
  max-width: 320px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.range-picker-toggle:hover,
.range-picker-toggle.open {
  border-color: var(--blue);
  background: #f8fbff;
}

.range-picker-label {
  color: var(--muted);
  white-space: nowrap;
}

.range-picker-value {
  min-width: 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.range-picker-caret {
  margin-left: -2px;
  color: var(--muted);
  font-size: 18px !important;
  line-height: 1;
  transform: translateY(-6px);
}

.range-picker-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 90;
  width: 320px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.16);
}

.range-picker-menu[hidden] {
  display: none;
}

.range-picker-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.range-picker-fields label {
  display: grid;
  gap: 5px;
  color: var(--muted);
}

.range-picker-fields select {
  width: 100%;
}

.range-hint {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 15px;
  box-shadow: var(--shadow);
}

.kpi .label {
  color: var(--muted);
  font-size: 13px;
}

.kpi .value {
  font-size: 25px;
  font-weight: 700;
  margin-top: 8px;
  white-space: nowrap;
}

.kpi .sub {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
  position: relative;
}

.forecast-chart-wrap {
  position: relative;
}

.panel.loading .forecast-chart-wrap::after {
  content: "正在更新预测...";
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 8px 16px;
  background: #eff6ff;
  color: var(--blue);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 700;
  transform: translate(-50%, -50%);
  white-space: nowrap;
}

.span-4 {
  grid-column: span 4;
}

.span-5 {
  grid-column: span 5;
}

.span-7 {
  grid-column: span 7;
}

.span-8 {
  grid-column: span 8;
}

.span-12 {
  grid-column: span 12;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head.panel-head-right {
  justify-content: flex-end;
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
}

.relation-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.segmented {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.segmented button {
  height: 28px;
  min-width: 36px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  color: var(--blue);
  background: #eff6ff;
}

.chart {
  width: 100%;
  height: 320px;
}

.chart.fullscreen-enabled,
.chat-result-chart.fullscreen-enabled {
  position: relative;
}

.visual-fullscreen-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 5px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  opacity: 0.68;
}

.visual-fullscreen-btn:hover {
  color: var(--blue);
  background: #f2f4f7;
  opacity: 1;
}

.visual-fullscreen-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart.large {
  height: 360px;
}

.chart.analysis-small {
  height: 280px;
}

.analysis-share-grid .chart.analysis-small,
.analysis-contribution-grid .chart.analysis-small,
.analysis-trend-grid .chart.analysis-small,
.analysis-rate-grid .chart.analysis-small {
  height: 305px;
}

.analysis-share-grid .visual-fullscreen-btn,
.analysis-contribution-grid .visual-fullscreen-btn,
.analysis-trend-grid .visual-fullscreen-btn,
.analysis-rate-grid .visual-fullscreen-btn {
  top: 0;
  right: 0;
}

.chart.analysis-large {
  height: 340px;
}

.analysis-share-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.analysis-contribution-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.analysis-trend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.analysis-rate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.forecast-tabs {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
}

.forecast-tab-buttons {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.forecast-btn {
  height: 32px;
  min-width: 86px;
  font-size: 13px;
  color: var(--muted);
}

.forecast-btn.active {
  border-color: var(--blue);
  color: var(--blue);
  background: #eff6ff;
  font-weight: 700;
}

.forecast-metric-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}

.forecast-mini {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfcff;
}

.forecast-mini .label {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.forecast-mini .label::after {
  content: "：";
}

.forecast-mini .value {
  min-width: 0;
  margin-top: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  font-weight: 700;
}

.model-info {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.model-pill.ok {
  color: var(--green);
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.model-pill.warn {
  color: var(--amber);
  border-color: #fde68a;
  background: #fffbeb;
}

.model-pill.selected {
  color: var(--blue);
  border-color: #bfdbfe;
  background: #eff6ff;
  font-weight: 700;
}

.model-dialog-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.model-dialog-trigger:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.model-dialog {
  width: min(980px, calc(100vw - 48px));
  max-width: none;
  max-height: calc(100vh - 48px);
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.model-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.model-dialog.fullscreen {
  width: calc(100vw - 24px);
  height: calc(100vh - 24px);
  max-height: none;
}

.model-dialog-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: calc(100vh - 48px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.model-dialog.fullscreen .model-dialog-shell {
  height: 100%;
  max-height: none;
}

.model-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.model-dialog-head h3 {
  margin: 0;
  font-size: 17px;
}

.model-dialog-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.model-dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.model-dialog-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  background: transparent;
  padding: 0;
}

.model-dialog-action:hover {
  background: #f2f4f7;
  color: var(--blue);
}

.model-dialog-action svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.model-dialog-action .fullscreen-exit-icon,
.model-dialog-action[aria-pressed="true"] .fullscreen-enter-icon {
  display: none;
}

.model-dialog-action[aria-pressed="true"] .fullscreen-exit-icon {
  display: block;
}

.model-dialog-table {
  min-height: 0;
  margin-top: 0;
  border: 0;
  border-radius: 0;
  max-height: calc(100vh - 150px);
}

.model-dialog.fullscreen .model-dialog-table {
  height: 100%;
  max-height: none;
}

.chart-fullscreen-open {
  overflow: hidden;
}

.chart-fullscreen-overlay {
  position: fixed;
  z-index: 1000;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  inset: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
}

.chart-fullscreen-overlay[hidden] {
  display: none !important;
}

.chart-fullscreen-overlay:fullscreen {
  background: #fff;
}

.chart-fullscreen-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  overflow: hidden;
}

.chart-fullscreen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 54px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.chart-fullscreen-head h3 {
  margin: 0;
  font-size: 17px;
}

.chart-fullscreen-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.chart-fullscreen-content {
  min-height: 0;
  overflow: auto;
  padding: 24px;
}

.chart-fullscreen-content .matrix {
  width: min(760px, 100%);
  margin: 0 auto;
  grid-template-columns: 96px repeat(3, minmax(120px, 1fr));
}

.chart-fullscreen-content .matrix div {
  min-height: 72px;
  font-size: 15px;
}

.chart-fullscreen-content .table-wrap.fullscreen-clone {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

.chart-fullscreen-content .table-wrap.fullscreen-clone .table-scroll {
  flex: 1;
  min-height: 0;
}

.query-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px 84px;
  gap: 10px;
}

.query-box input {
  width: 100%;
}

.examples {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.examples button {
  height: 32px;
  font-size: 13px;
}

.answer {
  min-height: 42px;
  border-left: 4px solid var(--teal);
  background: #f1f8f7;
  padding: 10px 12px;
  line-height: 1.55;
  border-radius: 6px;
  margin-bottom: 10px;
}

.chat-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 0;
  height: 100%;
  min-height: 0;
  background: #fff;
  overflow: hidden;
}

.chat-history-panel,
.chat-main {
  background: #fff;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.chat-history-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.chat-history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.chat-history-title {
  font-size: 16px;
  font-weight: 700;
}

.chat-history-sub,
.history-label {
  color: var(--muted);
  font-size: 12px;
}

.new-chat-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--blue);
  font-size: 20px;
  font-weight: 700;
}

.history-search {
  width: 100%;
  margin-bottom: 12px;
}

.history-label {
  margin-bottom: 8px;
}

.conversation-list {
  display: grid;
  gap: 8px;
  align-content: start;
  grid-auto-rows: max-content;
  max-height: none;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.conversation-item {
  width: 100%;
  min-height: 58px;
  height: auto;
  display: grid;
  grid-template-rows: auto auto;
  align-items: start;
  gap: 4px;
  justify-items: start;
  border-color: transparent;
  background: transparent;
  text-align: left;
  padding: 9px 10px;
}

.conversation-item:hover,
.conversation-item.active {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: var(--blue);
}

.conversation-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.conversation-time {
  color: var(--muted);
  font-size: 12px;
}

.chat-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  padding: 18px 28px 28px;
  overflow: hidden;
}

.chat-main-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.chat-main-head h2,
.chat-hero h3 {
  margin: 0;
}

.chat-main-head p,
.chat-main-head span,
.chat-hero p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.chat-hero {
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  overflow: auto;
  padding: 42px 6vw 22px;
  text-align: center;
}

.chat-hero h3 {
  font-size: 30px;
  line-height: 1.25;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
  margin-top: 28px;
}

.prompt-grid button {
  min-height: 52px;
  height: auto;
  border-radius: 8px;
  text-align: left;
  padding: 0 22px;
}

.chat-messages {
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px 4px 16px;
}

.chat-messages:empty {
  display: none;
}

.chat-message {
  display: flex;
  margin-bottom: 14px;
}

.chat-message.user {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: min(860px, 82%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
  line-height: 1.55;
}

.chat-message.user .chat-bubble {
  color: var(--text);
  background: #f3f4f6;
  border-color: #f3f4f6;
}

.chat-bubble .insight-line {
  margin-top: 6px;
  color: var(--muted);
}

.chat-result-chart {
  width: 100%;
  height: 280px;
  margin-top: 10px;
}

.chat-composer {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 12px 12px 18px;
  background: #fff;
}

.chat-composer:focus-within {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.chat-composer textarea {
  width: 100%;
  min-height: 52px;
  max-height: 130px;
  resize: none;
  border: 0;
  outline: none;
  box-shadow: none;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
}

.chat-composer textarea:focus,
.chat-composer textarea:focus-visible {
  border: 0;
  outline: none;
  box-shadow: none;
}

.composer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-action {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  color: #98a2b3;
  background: transparent;
  font-size: 20px;
  line-height: 1;
}

.icon-action svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-action:hover {
  background: #f2f4f7;
  color: var(--blue);
}

.icon-action.primary {
  background: #f2f4f7;
  color: #cbd5e1;
  font-size: 22px;
}

.icon-action.primary:hover {
  background: #eff6ff;
  color: var(--blue);
}

.icon-action.listening {
  background: #dbeafe;
  color: #1d4ed8;
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.26), 0 0 12px rgba(37, 99, 235, 0.2);
  animation: voiceButtonPulse 0.9s ease-in-out infinite;
}

@keyframes voiceButtonPulse {
  0%,
  100% {
    background: #dbeafe;
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.22), 0 0 8px rgba(37, 99, 235, 0.14);
  }
  50% {
    background: #bfdbfe;
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.42), 0 0 14px rgba(37, 99, 235, 0.32);
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon-action.listening {
    animation: none;
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.42), 0 0 10px rgba(37, 99, 235, 0.16);
  }
}

.table-wrap {
  width: 100%;
  overflow: auto;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.interactive-table {
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcff;
}

.table-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.table-fullscreen-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 5px;
  padding: 0;
  color: #64748b;
  background: transparent;
  cursor: pointer;
}

.table-fullscreen-btn:hover {
  color: var(--blue);
  background: #eff6ff;
}

.table-fullscreen-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.table-scroll {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 620px;
}

.forecast-detail-table {
  min-width: 1256px;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

th {
  background: #f7f9fc;
  color: #344054;
  font-weight: 700;
  position: sticky;
  top: 0;
}

.forecast-detail-table th,
.forecast-detail-table td {
  box-sizing: border-box;
  text-align: center;
}

.table-sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: auto;
  height: auto;
  min-height: 0;
  border: 0;
  border-radius: 4px;
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  font-weight: 700;
}

.forecast-detail-table .table-sort-btn,
.forecast-detail-table .table-header-filter {
  width: 100%;
  justify-content: center;
}

.table-sort-btn:hover {
  color: var(--blue);
  background: transparent;
}

.sort-icon {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.table-sort-btn[data-direction="asc"] .sort-icon,
.table-sort-btn[data-direction="desc"] .sort-icon {
  color: var(--blue);
}

.table-header-filter {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 1px;
}

.header-filter-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 4px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.header-filter-arrow {
  display: block;
  color: currentColor;
  font-size: 14px;
  line-height: 1;
  pointer-events: none;
  transform: translateY(-3px);
}

.header-filter-trigger:hover,
.header-filter-trigger:focus,
.table-header-filter.open .header-filter-trigger {
  background: #eff6ff;
  color: var(--blue);
  outline: none;
}

.header-filter-menu {
  position: absolute;
  left: 0;
  top: calc(100% + 5px);
  z-index: 80;
  min-width: 72px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.16);
}

.header-filter-menu[hidden] {
  display: none;
}

.header-filter-menu button {
  display: block;
  width: 100%;
  height: 28px;
  min-height: 0;
  border: 0;
  border-radius: 4px;
  padding: 0 10px;
  color: var(--text);
  background: transparent;
  font-size: 12px;
  text-align: left;
  white-space: nowrap;
}

.header-filter-menu button:hover,
.header-filter-menu button.active {
  color: var(--blue);
  background: #eff6ff;
}

.table-help {
  position: relative;
  top: -7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 11px;
  height: 11px;
  margin-left: 2px;
  border: 1px solid var(--blue);
  border-radius: 50%;
  color: var(--blue);
  background: #fff;
  font-size: 8px;
  font-weight: 800;
  line-height: 1;
  cursor: help;
}

.table-tooltip {
  position: absolute;
  left: 8px;
  top: 24px;
  z-index: 30;
  display: none;
  width: 360px;
  max-width: min(360px, 70vw);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.55;
  white-space: normal;
}

.table-tooltip-list {
  display: grid;
  gap: 8px;
}

.table-tooltip-item {
  display: grid;
  gap: 2px;
}

.table-tooltip-name {
  color: var(--blue);
}

.table-tooltip-desc {
  color: var(--text);
}

th.has-help:hover .table-tooltip,
.table-help:focus + .table-tooltip {
  display: block;
}

tr:last-child td {
  border-bottom: 0;
}

.insight-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 12px;
}

.insight-group {
  min-width: 0;
}

.insight-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.insight-group-head h3 {
  margin: 0;
  font-size: 14px;
}

.insight-group-head span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.insight-group-body {
  display: grid;
  gap: 8px;
}

.insight {
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 7px;
  padding: 10px 12px;
  line-height: 1.5;
  background: #fbfcff;
}

.matrix {
  position: relative;
  display: grid;
  grid-template-columns: 80px repeat(3, minmax(72px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.matrix div {
  min-height: 52px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  text-align: center;
  font-size: 13px;
}

.matrix .head {
  background: #f7f9fc;
  font-weight: 700;
}

.matrix .strong {
  color: #fff;
  background: var(--teal);
}

.matrix .medium {
  color: #fff;
  background: var(--blue);
}

.matrix .weak {
  background: #eef2f7;
}

.compact-table {
  margin-top: 10px;
}

.compact-table table {
  min-width: 720px;
}

.compact-table th,
.compact-table td {
  padding: 7px 9px;
  font-size: 12px;
}

.positive {
  color: var(--red);
}

.negative {
  color: var(--green);
}

.muted {
  color: var(--muted);
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-main {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-overview-range {
    margin-left: 0;
  }

  .layout-shell {
    grid-template-columns: 68px minmax(0, 1fr);
  }

  .layout-shell .brand-title,
  .layout-shell .tab-label {
    display: none;
  }

  .layout-shell .brand-block,
  .layout-shell .tab-btn {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }

  .layout-shell .sidebar-toggle {
    right: -30px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .overview-range-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .range-hint {
    white-space: normal;
  }

  .chat-layout {
    grid-template-columns: 1fr;
  }

  .conversation-list {
    max-height: 220px;
  }

  .span-4,
  .span-5,
  .span-7,
  .span-8,
  .span-12 {
    grid-column: span 12;
  }

  .analysis-share-grid,
  .analysis-contribution-grid,
  .analysis-trend-grid,
  .analysis-rate-grid,
  .insight-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  main {
    padding: 0;
  }

  .topbar {
    padding: 16px;
  }

  .layout-shell {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .sidebar {
    padding: 10px 6px;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .query-box {
    grid-template-columns: 1fr;
  }

  .chart,
  .chart.large {
    height: 300px;
  }

  .forecast-metric-summary {
    grid-template-columns: 1fr;
  }

  .prompt-grid,
  .chat-composer {
    grid-template-columns: 1fr;
  }

  .chat-main {
    padding: 16px;
  }

  .chat-history-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-hero {
    padding: 28px 10px 18px;
  }

  .chat-hero h3 {
    font-size: 24px;
  }

  .chat-bubble {
    max-width: 92%;
  }

  .composer-actions {
    justify-content: flex-end;
  }
}

body,
body *,
button,
input,
select,
textarea,
th,
td,
h1,
h2,
h3,
h4,
h5,
h6,
b,
strong {
  font-size: 13px !important;
  font-weight: 400 !important;
}

.brand-title,
.tab-label,
.topbar h1,
.panel-head h2,
.chat-main-head h2,
.chat-hero h3,
.kpi .value,
.forecast-mini .value,
th,
td,
.table-sort-btn,
.matrix .head,
.conversation-name,
.insight-group-head h3 {
  color: var(--text) !important;
}

.record-help {
  width: 12px !important;
  height: 12px !important;
  margin-top: -4px;
  font-size: 8px !important;
  line-height: 1 !important;
}

.field-help {
  width: 10px !important;
  height: 10px !important;
  left: -8px;
  top: -8px;
  font-size: 7px !important;
  line-height: 1 !important;
}

.table-help {
  width: 9px !important;
  height: 9px !important;
  font-size: 7px !important;
  line-height: 1 !important;
}

.table-help {
  top: -7px;
  margin-left: 1px;
}
