/* ═══════════════════════════════════════════════════════════════
   EVIDENT — Data Visualization
   
   Charts, graphs, and metrics for dashboard and analytics.
   CSS-only where possible, minimal JS required.
   ═══════════════════════════════════════════════════════════════ */

/* ── Chart Container ────────────────────────────────────────── */
.chart-container {
  position: relative;
  padding: 1.5rem;
  background: var(--surface-card, #fff);
  border: 1px solid var(--border-subtle, #e5e7eb);
  border-radius: var(--radius-lg, 12px);
}

.chart-container__header {
  margin-bottom: 1.5rem;
}

.chart-container__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary, #111827);
  margin: 0 0 0.25rem;
}

.chart-container__subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
  margin: 0;
}

/* ── Bar Chart ───────────────────────────────────────────────── */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  height: 200px;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-default, #e5e7eb);
}

.bar-chart__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.bar-chart__bar {
  width: 100%;
  max-width: 40px;
  background: linear-gradient(to top, var(--color-primary, #3b82f6), var(--color-primary-light, #60a5fa));
  border-radius: 4px 4px 0 0;
  transition: height 0.5s var(--ease-spring, cubic-bezier(0.22, 1, 0.36, 1));
  position: relative;
}

.bar-chart__bar:hover {
  filter: brightness(1.1);
}

.bar-chart__bar::after {
  content: attr(data-value);
  position: absolute;
  top: -1.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary, #111827);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.bar-chart__bar:hover::after {
  opacity: 1;
}

.bar-chart__label {
  font-size: 0.75rem;
  color: var(--text-muted, #9ca3af);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* Stacked bar chart */
.bar-chart__bar--stacked {
  display: flex;
  flex-direction: column-reverse;
}

.bar-chart__segment {
  width: 100%;
  transition: height 0.5s ease;
}

/* Horizontal bar chart */
.bar-chart--horizontal {
  flex-direction: column;
  height: auto;
  padding-bottom: 0;
  border-bottom: none;
  gap: 0.75rem;
}

.bar-chart--horizontal .bar-chart__item {
  flex-direction: row;
  align-items: center;
  gap: 1rem;
}

.bar-chart--horizontal .bar-chart__bar {
  height: 24px;
  max-width: none;
  border-radius: 0 4px 4px 0;
}

.bar-chart--horizontal .bar-chart__label {
  width: 100px;
  flex-shrink: 0;
  text-align: right;
}

/* ── Donut/Pie Chart ─────────────────────────────────────────── */
.donut-chart {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: conic-gradient(
    var(--color-primary, #3b82f6) calc(var(--value-1, 0) * 1%),
    var(--color-accent, #f59e0b) calc(var(--value-1, 0) * 1%) calc((var(--value-1, 0) + var(--value-2, 0)) * 1%),
    var(--color-emerald, #10b981) calc((var(--value-1, 0) + var(--value-2, 0)) * 1%)
      calc((var(--value-1, 0) + var(--value-2, 0) + var(--value-3, 0)) * 1%),
    var(--border-default, #e5e7eb) 0
  );
  position: relative;
  flex-shrink: 0;
}

.donut-chart__hole {
  position: absolute;
  inset: 25%;
  background: var(--surface-card, #fff);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.donut-chart__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
  line-height: 1;
}

.donut-chart__label {
  font-size: 0.625rem;
  color: var(--text-muted, #9ca3af);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Sparkline ───────────────────────────────────────────────── */
.sparkline {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.sparkline__bar {
  flex: 1;
  background: var(--color-primary, #3b82f6);
  border-radius: 1px;
  min-height: 2px;
  transition: height 0.3s ease;
}

.sparkline--positive .sparkline__bar {
  background: linear-gradient(to top, #22c55e, #4ade80);
}

.sparkline--negative .sparkline__bar {
  background: linear-gradient(to top, #ef4444, #f87171);
}

/* ── Metric Cards ───────────────────────────────────────────── */
.metric-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.25rem;
  background: var(--surface-card, #fff);
  border: 1px solid var(--border-subtle, #e5e7eb);
  border-radius: var(--radius-lg, 12px);
  transition: box-shadow 0.2s ease;
}

.metric-card:hover {
  box-shadow: var(--shadow-md, 0 4px 24px rgb(0 0 0 / 7%));
}

.metric-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.metric-card__label {
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
}

.metric-card__icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-elevated, #f3f4f6);
  border-radius: 8px;
  color: var(--text-muted, #9ca3af);
}

.metric-card__value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
  line-height: 1.2;
}

.metric-card__change {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
}

.metric-card__change--positive {
  background: #d1fae5;
  color: #065f46;
}

.metric-card__change--negative {
  background: #fee2e2;
  color: #991b1b;
}

.metric-card__sparkline {
  margin-top: 0.5rem;
}

/* ── Progress Rings ─────────────────────────────────────────── */
.progress-ring {
  width: 120px;
  height: 120px;
  position: relative;
}

.progress-ring__svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.progress-ring__track {
  fill: none;
  stroke: var(--border-subtle, #e5e7eb);
  stroke-width: 8;
}

.progress-ring__fill {
  fill: none;
  stroke: var(--color-primary, #3b82f6);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s var(--ease-spring, cubic-bezier(0.22, 1, 0.36, 1));
}

.progress-ring__content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.progress-ring__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary, #111827);
}

.progress-ring__label {
  font-size: 0.75rem;
  color: var(--text-muted, #9ca3af);
}

/* ── Timeline Visualization ──────────────────────────────────── */
.timeline {
  position: relative;
  padding-left: 2rem;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 0.5rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border-default, #e5e7eb);
}

.timeline__item {
  position: relative;
  padding-bottom: 1.5rem;
}

.timeline__item:last-child {
  padding-bottom: 0;
}

.timeline__dot {
  position: absolute;
  left: -1.75rem;
  top: 0.25rem;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-primary, #3b82f6);
  border: 2px solid var(--surface-card, #fff);
  box-shadow: 0 0 0 2px var(--color-primary, #3b82f6);
}

.timeline__dot--complete {
  background: #22c55e;
  box-shadow: 0 0 0 2px #22c55e;
}

.timeline__dot--error {
  background: #ef4444;
  box-shadow: 0 0 0 2px #ef4444;
}

.timeline__dot--pending {
  background: var(--surface-card, #fff);
  border-color: var(--border-strong, #d1d5db);
  box-shadow: 0 0 0 2px var(--border-strong, #d1d5db);
}

.timeline__content {
  background: var(--surface-elevated, #f9fafb);
  border: 1px solid var(--border-subtle, #e5e7eb);
  border-radius: var(--radius-md, 8px);
  padding: 1rem;
}

.timeline__time {
  font-size: 0.75rem;
  color: var(--text-muted, #9ca3af);
  margin-bottom: 0.25rem;
}

.timeline__title {
  font-weight: 600;
  color: var(--text-primary, #111827);
  margin: 0 0 0.25rem;
}

.timeline__description {
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
  margin: 0;
}

/* ── Heatmap Grid ───────────────────────────────────────────── */
.heatmap {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.heatmap__cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--border-subtle, #e5e7eb);
  transition: transform 0.15s ease;
}

.heatmap__cell:hover {
  transform: scale(1.2);
  z-index: 1;
}

.heatmap__cell--level-1 {
  background: #dbeafe;
}

.heatmap__cell--level-2 {
  background: #93c5fd;
}

.heatmap__cell--level-3 {
  background: #3b82f6;
}

.heatmap__cell--level-4 {
  background: #1d4ed8;
}

/* ── Legend ──────────────────────────────────────────────────── */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle, #e5e7eb);
}

.chart-legend__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary, #6b7280);
}

.chart-legend__color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

/* ── Dashboard Grid ──────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.dashboard-grid--2col {
  grid-template-columns: repeat(2, 1fr);
}

.dashboard-grid--3col {
  grid-template-columns: repeat(3, 1fr);
}

.dashboard-grid--4col {
  grid-template-columns: repeat(4, 1fr);
}

@media (width <= 1024px) {
  .dashboard-grid--4col,
  .dashboard-grid--3col {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (width <= 640px) {
  .dashboard-grid--4col,
  .dashboard-grid--3col,
  .dashboard-grid--2col {
    grid-template-columns: 1fr;
  }
}
