:root {
  --chart-bar: #3b82f6;
  --chart-bar-soft: rgba(59, 130, 246, 0.45);
  --chart-grid: #2c2c2e;
  --chart-area: rgba(59, 130, 246, 0.12);
}

:root.light {
  --chart-bar: #2563eb;
  --chart-bar-soft: rgba(37, 99, 235, 0.4);
  --chart-grid: #ececf0;
  --chart-area: rgba(37, 99, 235, 0.08);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px;
}

.summary strong {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.summary small {
  color: var(--muted);
  font-size: 12px;
}

.summary-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--panel-2);
}

.change i {
  font-size: 10px;
}

.change.up {
  color: var(--ok);
  background: var(--ok-bg);
}

.change.down {
  color: var(--danger);
  background: var(--danger-bg);
}

/* Breakdown: one card of compact stats under the headline metrics */

.breakdown-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 12px;
  overflow: hidden;
}

.breakdown-card[hidden] {
  display: none;
}

.breakdown-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px;
  box-shadow: -1px 0 0 var(--border-soft);
}

.breakdown-item strong {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.breakdown-item small {
  color: var(--muted);
  font-size: 12px;
}

/* Placeholder lines sized to the real label/value/note so the card doesn't jump when data lands */
.breakdown-item .skeleton-line {
  margin: 2px 0;
}

.breakdown-item .skeleton-line.value {
  width: 40px;
  height: 22px;
  margin: 0;
}

.breakdown-item .skeleton-line.short {
  width: 90px;
}

/* Charts */

.charts-section {
  margin-bottom: 12px;
}

.charts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 12px;
}

.chart-grid-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chart-card {
  padding: 18px 20px 12px;
}

.chart-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.chart-card-head strong {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.chart-card-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.mini-chart {
  position: relative;
  height: 180px;
  margin-top: 12px;
}

.mini-chart svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.mini-chart .empty-state {
  min-height: 0;
  height: 100%;
}

/* Loading: spinner over existing charts, shimmer on first-load placeholders */

.charts-section.is-loading .mini-chart > svg {
  opacity: 0.35;
  transition: opacity 160ms ease;
}

.charts-section.is-loading .mini-chart::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2px solid var(--border);
  border-top-color: var(--chart-bar);
  border-radius: 50%;
  animation: chart-spin 700ms linear infinite;
}

.charts-section.is-loading .chart-card-head strong {
  opacity: 0.4;
}

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

.skeleton-line {
  display: block;
  width: 120px;
  height: 10px;
  margin-top: 8px;
  border-radius: 6px;
  background: var(--panel-2);
  animation: skeleton-pulse 1.2s ease-in-out infinite;
}

.skeleton-line.short {
  width: 70px;
  margin-top: 0;
}

.skeleton-line.value {
  width: 64px;
  height: 20px;
  margin-top: 0;
}

.chart-card.skeleton .mini-chart {
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel-2) 45%, transparent);
}

@keyframes skeleton-pulse {
  50% { opacity: 0.45; }
}

.chart-gridlines line {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.chart-axis text {
  fill: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-bar {
  fill: var(--chart-bar);
}

.chart-bar.incomplete {
  fill: var(--chart-bar-soft);
}

.chart-line {
  fill: none;
  stroke: var(--chart-bar);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line.incomplete {
  stroke-dasharray: 4 4;
}

.chart-area {
  fill: var(--chart-area);
}

.chart-cursor {
  stroke: var(--text);
  stroke-width: 1;
  opacity: 0.6;
}

.chart-marker {
  fill: var(--panel);
  stroke: var(--chart-bar);
  stroke-width: 2.5;
}

.chart-focus[hidden] {
  display: none;
}

.chart-hit {
  fill: transparent;
  outline: 0;
  cursor: crosshair;
}

.chart-tooltip[hidden] {
  display: none;
}

.chart-tooltip {
  position: absolute;
  top: 0;
  z-index: 4;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--tooltip-bg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

.chart-tooltip b {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* Countries: ranked horizontal bars */

.chart-card.wide {
  grid-column: 1 / -1;
}

.country-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 32px;
  margin: 16px 0 8px;
  padding: 0;
  list-style: none;
}

.country-row {
  display: grid;
  grid-template-columns: minmax(90px, 160px) minmax(0, 1fr) 76px;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.country-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.country-track {
  height: 8px;
  border-radius: 4px;
  background: var(--chart-grid);
}

.country-bar {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: 4px;
  background: var(--chart-bar);
}

.country-row.other .country-name {
  color: var(--muted);
}

.country-row.other .country-bar {
  background: var(--chart-bar-soft);
}

.country-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.country-value small {
  margin-left: 6px;
  color: var(--muted);
  font-size: 11px;
}

.setup-panel {
  margin-bottom: 12px;
  padding: 22px 24px;
}

.setup-panel h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
}

.setup-panel p {
  margin: 0;
  color: var(--muted);
}

.setup-panel ol {
  margin: 14px 0 0;
  padding-left: 20px;
  line-height: 1.7;
}

.setup-panel a {
  color: var(--link);
}

.setup-panel code {
  font-family: var(--mono);
  font-size: 12px;
}

@media (max-width: 760px) {
  .chart-grid-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .chart-card {
    padding: 16px 16px 10px;
  }

  .summary,
  .breakdown-item {
    padding: 18px 16px;
  }

  .country-list {
    grid-template-columns: minmax(0, 1fr);
  }
}
