/* ==========================================================================
   Chart surfaces, tooltips and table-view fallbacks
   ========================================================================== */

.chart-card {
  min-height: 0;
}

.chart-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

/* One compact line of summary figures between the head and the plot.
   Deliberately a line of type, not a row of tiles: the chart stays the
   dominant element and the card gains ~18px, not a block of chrome. */
.chart-card__stats {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--sp-2) var(--sp-3);
  margin: calc(var(--sp-3) * -1) 0 var(--sp-4);
  font-size: var(--fs-xs);
}

.chart-card__stat {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-1);
}

.chart-card__stat-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
}

.chart-card__stat-value {
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}

.chart-card__sep {
  color: var(--text-muted);
  opacity: 0.5;
}

.chart-card__controls {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* Chart.js needs a bounded parent to resize into, but a *fixed* height was
   the wrong bound. These cards sit in .grid--split, whose default
   align-items: stretch makes every card in a row as tall as the tallest. The
   chart card was routinely stretched ~150px beyond its content by the taller
   column beside it, and a fixed-height plot left all of that as dead space
   below the chart.
   
   flex: 1 hands the surplus to the plot instead: the chart grows to fill
   whatever height the row gives the card, and min-height keeps it usable
   when the card is not stretched at all. */
.chart {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 280px;
}

.chart--tall {
  min-height: 340px;
}

.chart--short {
  min-height: 180px;
}

.chart canvas {
  position: absolute;
  inset: 0;
}

@media (max-width: 640px) {
  .chart,
  .chart--tall {
    min-height: 240px;
  }
}

/* --------------------------------------------------------------------------
   Custom tooltip — rendered as HTML so it can carry multiple rows,
   tabular figures and a real border. Positioned by the chart component.
   -------------------------------------------------------------------------- */

.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 148px;
  padding: var(--sp-3);
  border-radius: var(--radius-md);
  background: var(--surface-overlay);
  border: 1px solid var(--glass-border-strong);
  backdrop-filter: var(--glass-filter);
  -webkit-backdrop-filter: var(--glass-filter);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-xs);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity var(--dur-fast) var(--ease-out);
}

.chart-tip[data-visible="true"] {
  opacity: 1;
}

.chart-tip__title {
  margin-bottom: var(--sp-2);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--glass-border);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  white-space: nowrap;
}

.chart-tip__row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 2px 0;
  white-space: nowrap;
}

.chart-tip__swatch {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-tip__label {
  color: var(--text-secondary);
  flex: 1;
}

/* Values wear text ink, never the series color. */
.chart-tip__value {
  margin-left: var(--sp-4);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Table view — the accessible equivalent of every chart
   -------------------------------------------------------------------------- */

.chart-table {
  max-height: 300px;
  overflow: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
}

.chart-table table {
  min-width: 100%;
  font-size: var(--fs-xs);
}

.chart-table th,
.chart-table td {
  padding: var(--sp-2) var(--sp-3);
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--divider);
}

.chart-table th:first-child,
.chart-table td:first-child {
  text-align: left;
}

.chart-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-muted);
}

.chart-table td {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Luck gauge — a semicircular arc, drawn in SVG
   -------------------------------------------------------------------------- */

.gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
}

.gauge svg {
  width: 100%;
  max-width: 240px;
  height: auto;
}

.gauge__track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 12;
  stroke-linecap: round;
}

.gauge__value {
  fill: none;
  stroke: var(--brand);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke-dashoffset var(--dur-slow) var(--ease-out);
}

.gauge__value--good {
  stroke: var(--status-good);
}

.gauge__value--warning {
  stroke: var(--status-warning);
}

.gauge__value--critical {
  stroke: var(--status-critical);
}

.gauge__readout {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-display);
  font-variant-numeric: tabular-nums;
}

.gauge__caption {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-align: center;
  max-width: 34ch;
}
