/* Reusable chart and data visualization styles */

/* Shared titles */
.table-title,
.chart-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* Shared container */
.chart-wrap,
.table-wrap {
  margin: 0 0 2rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap .source {
  font-size: 0.7rem;
  color: var(--text-faint);
  padding: 0.5rem 1rem 0.25rem;
  margin: 0;
  border-top: 1px solid var(--border);
}

/* ---- Data table ---- */
.data-table {
  width: 100%;
  min-width: 400px;
  font-size: 0.9rem;
  border-spacing: 0;
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
}

.data-table thead {
  background: var(--border);
}

.data-table thead tr {
  border-bottom: 1px solid var(--text-faint);
}

.data-table th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: opacity 0.15s;
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.data-table td {
  color: var(--text-muted);
}

.data-table caption {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: left;
  caption-side: top;
  padding: 0.75rem 1rem 0;
}

.data-table tbody:hover tr:not(:hover) {
  opacity: 0.6;
}

.data-table tbody tr:hover td {
  color: var(--text);
}

/* ---- Horizontal bar chart ---- */
.bar-chart {
  padding: 1rem;
}

.bar-chart-row {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
  transition: opacity 0.15s;
}

.bar-chart-row:last-child {
  margin-bottom: 0;
}

.bar-chart-label {
  flex: 0 0 120px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  padding-right: 1rem;
}

.bar-chart-track {
  flex: 1;
  height: 1.25rem;
  background: var(--border);
  border-radius: 0.25rem;
  overflow: hidden;
}

.bar-chart-bar {
  height: 100%;
  background: var(--text-faint);
  border-radius: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.5rem;
  font-size: 0.7rem;
  color: var(--bg);
  font-weight: 500;
}

.bar-chart:hover .bar-chart-row:not(:hover) {
  opacity: 0.6;
}

.bar-chart-row:hover .bar-chart-bar {
  background: var(--text-muted);
}

/* ---- Shared grid layout (scatter + line) ---- */
.scatter-chart,
.line-chart {
  padding: 1rem;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr auto;
  gap: 0;
}

/* ---- Scatter plot ---- */
.scatter-area {
  position: relative;
  height: 200px;
  border-left: 1px solid var(--border-muted);
  border-bottom: 1px solid var(--border-muted);
  grid-column: 2;
  grid-row: 1;
}

.scatter-dot {
  position: absolute;
  left: var(--x);
  bottom: var(--y);
  width: 6px;
  height: 6px;
  background: var(--text-faint);
  border-radius: 50%;
  transform: translate(-50%, 50%);
  transition: transform 0.15s, background 0.15s;
}

.scatter-dot:hover {
  transform: translate(-50%, 50%) scale(1.6);
  background: var(--text-muted);
}

.scatter-dot::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 0.25rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.scatter-dot:hover::after {
  opacity: 1;
}

/* ---- Line chart ---- */
.line-chart svg {
  display: block;
  width: 100%;
  height: 150px;
  border-left: 1px solid var(--border-muted);
  border-bottom: 1px solid var(--border-muted);
  grid-column: 2;
  grid-row: 1;
}

.line-chart polyline {
  fill: none;
  stroke: var(--text-faint);
  stroke-width: 1.5;
}

.line-chart circle {
  fill: var(--text-faint);
  transition: r 0.15s, fill 0.15s;
}

.line-chart circle:hover {
  r: 5;
  fill: var(--text-muted);
}

/* ---- Line chart: self-labeled (SVG contains its own axes) ---- */
.line-chart-labeled svg {
  border-left: none;
  border-bottom: none;
  grid-column: 1 / -1;
  height: auto;
}

.line-chart-labeled .line-chart-legend {
  grid-column: 1 / -1;
}

/* ---- Line chart: multi-series ---- */
.line-chart .grid-line {
  stroke: var(--border-muted);
  stroke-width: 0.5;
}

.line-chart .axis-label {
  font-size: 7px;
  fill: var(--text-faint);
  font-family: inherit;
}

.line-chart .axis-label-y {
  text-anchor: end;
}

.line-chart .axis-label-x {
  text-anchor: middle;
}

.line-chart .series-a polyline {
  stroke: var(--text-muted);
  stroke-width: 1.8;
}

.line-chart .series-a circle {
  fill: var(--text-muted);
}

.line-chart .series-b polyline {
  stroke: var(--text-faint);
  stroke-width: 1.8;
  stroke-dasharray: 4 3;
}

.line-chart .series-b circle {
  fill: var(--text-faint);
}

.line-chart-legend {
  grid-column: 2;
  display: flex;
  justify-content: center;
  gap: 1.25rem;
  padding-top: 0.5rem;
}

.line-chart-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.line-chart-legend-line {
  display: inline-block;
  width: 18px;
  height: 0;
  border-top: 2px solid var(--text-muted);
}

.line-chart-legend-line.dashed {
  border-top-style: dashed;
  border-top-color: var(--text-faint);
}

/* ---- Vertical bar chart ---- */
.vbar-chart {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
}

.vbar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  max-width: 60px;
  transition: opacity 0.15s;
}

.vbar-value {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.vbar-track {
  width: 100%;
  height: 160px;
  display: flex;
  align-items: flex-end;
  border-bottom: 1px solid var(--border-muted);
}

.vbar-fill {
  width: 100%;
  background: var(--text-faint);
  border-radius: 0.25rem 0.25rem 0 0;
}

.vbar-label {
  font-size: 0.75rem;
  color: var(--text-faint);
}

.vbar-chart:hover .vbar-col:not(:hover) {
  opacity: 0.6;
}

.vbar-col:hover .vbar-fill {
  background: var(--text-muted);
}

.vbar-col:hover .vbar-value {
  color: var(--text);
}

/* ---- Pie chart ---- */
.pie-chart {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem;
}

.pie-chart-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pie-chart-legend {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.pie-chart-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: opacity 0.15s;
}

.pie-chart-legend:hover .pie-chart-item:not(:hover) {
  opacity: 0.6;
}

.pie-chart-item:hover .pie-chart-label {
  color: var(--text);
}

.pie-chart-item:hover .pie-chart-pct {
  color: var(--text-muted);
}

.pie-chart-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pie-chart-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  flex: 1;
}

.pie-chart-pct {
  font-size: 0.7rem;
  color: var(--text-faint);
}

/* ---- Axis labels (scatter + line) ---- */
.chart-axis-y {
  grid-column: 1;
  grid-row: 1;
  writing-mode: vertical-lr;
  transform: rotate(180deg);
  font-size: 0.7rem;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 0.4rem;
}

.chart-axis-x {
  grid-column: 2;
  grid-row: 2;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-faint);
  padding-top: 0.4rem;
}

/* Mobile adjustments */
@media (max-width: 480px) {
  .chart-title,
  .table-title {
    font-size: 0.85rem;
  }

  .table-wrap,
  .chart-wrap {
    border-radius: 0.5rem;
  }

  /* ---- Bar chart: stack labels above bars ---- */
  .bar-chart {
    padding: 1rem;
  }

  .bar-chart-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
  }

  .bar-chart-label {
    flex: none;
    text-align: left;
    padding-right: 0;
    font-size: 0.85rem;
  }

  .bar-chart-track {
    height: 1.75rem;
  }

  .bar-chart-bar {
    font-size: 0.75rem;
  }

  /* ---- Data table: no forced min-width ---- */
  .data-table {
    min-width: 0;
  }

  .data-table th,
  .data-table td {
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
  }

  .data-table th {
    font-size: 0.65rem;
  }

  /* ---- Scatter plot: taller, larger dots ---- */
  .scatter-area {
    height: 220px;
  }

  .scatter-dot {
    width: 10px;
    height: 10px;
  }

  /* ---- Line chart: taller ---- */
  .line-chart svg {
    height: 180px;
  }

  .line-chart circle {
    r: 4;
  }

  /* ---- Vertical bar chart: taller, roomier ---- */
  .vbar-chart {
    gap: 0.5rem;
    padding: 1rem;
  }

  .vbar-col {
    max-width: none;
  }

  .vbar-track {
    height: 180px;
  }

  .vbar-value {
    font-size: 0.8rem;
  }

  .vbar-label {
    font-size: 0.8rem;
  }

  /* ---- Pie chart: larger ring, stacked ---- */
  .pie-chart {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }

  .pie-chart-ring {
    width: 140px;
    height: 140px;
  }

  .pie-chart-label {
    font-size: 0.85rem;
  }

  .pie-chart-pct {
    font-size: 0.8rem;
  }

  /* ---- Axis labels ---- */
  .chart-axis-y {
    font-size: 0.75rem;
  }

  .chart-axis-x {
    font-size: 0.75rem;
  }
}
