.chart-container {
  --chart-bg: #f4f4f5;
  --chart-text: #27272a;
  --chart-muted: #71717a;
  --chart-btn-bg: #e4e4e7;
  --chart-btn-border: #d4d4d8;
  --chart-btn-active-bg: #18181b;
  --chart-btn-active-text: #fafafa;
  --chart-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  background: var(--chart-bg);
  border-radius: 12px;
  padding: 20px;
  margin-top: 20px;
  box-shadow: var(--chart-shadow);
  color: var(--chart-text);
  width: 100%;
  max-width: 100%;
  position: relative;
}

.chart-container[data-chart-theme="dark"],
html[data-theme="dark"] .chart-container {
  --chart-bg: #3f3f46;
  --chart-text: #fafafa;
  --chart-muted: #a1a1aa;
  --chart-btn-bg: #27272a;
  --chart-btn-border: #52525b;
  --chart-btn-active-bg: #fafafa;
  --chart-btn-active-text: #18181b;
  --chart-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.chart-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.chart-toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.chart-mode {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chart-wrapper {
  width: 100%;
  height: 400px;
  position: relative;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.chart-wrapper canvas[hidden] {
  display: none !important;
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--chart-muted);
  font-size: 14px;
  letter-spacing: 0.02em;
}

.chart-loading::after {
  content: '';
  width: 22px;
  height: 22px;
  margin-left: 10px;
  border: 2px solid rgba(128, 128, 128, 0.25);
  border-top-color: var(--chart-text);
  border-radius: 50%;
  animation: chart-spin 0.75s linear infinite;
}

.chart-loading[hidden] {
  display: none !important;
}

@keyframes chart-spin {
  to { transform: rotate(360deg); }
}

.chart-unavailable {
  margin: 0;
  padding: 2rem 1rem;
  text-align: center;
  color: var(--chart-muted);
}

.chart-insight {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.12);
  color: var(--chart-text);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

.chart-insight[hidden] {
  display: none !important;
}

.chart-tabs,
.chart-scope {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tab-btn,
.chart-scope-btn,
.chart-mode-btn,
.chart-export-btn {
  background: var(--chart-btn-bg);
  border: 1px solid var(--chart-btn-border);
  color: var(--chart-text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s ease-in-out, color 0.2s ease-in-out;
}

.tab-btn:hover,
.chart-scope-btn:hover,
.chart-mode-btn:hover:not(:disabled),
.chart-export-btn:hover {
  filter: brightness(0.97);
}

.tab-btn.active,
.chart-scope-btn.active,
.chart-mode-btn.active {
  background: var(--chart-btn-active-bg);
  color: var(--chart-btn-active-text);
  border-color: var(--chart-btn-active-bg);
  font-weight: bold;
}

.chart-mode-btn--disabled,
.chart-mode-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chart-export-btn {
  font-weight: 600;
  letter-spacing: 0.03em;
}

@media (max-width: 767px) {
  .chart-wrapper {
    height: 300px;
  }

  .chart-toolbar {
    gap: 8px;
  }

  .tab-btn,
  .chart-scope-btn,
  .chart-mode-btn,
  .chart-export-btn {
    font-size: 11px;
    padding: 5px 9px;
  }

  .chart-insight {
    font-size: 12px;
  }
}
