/*
 * stats.css — Portal joinet.org
 * Criado em: 2026-11-13
 * Autor:     João Camargo Neto (com Claude Code)
 *
 * Estatísticas panel (ADR-023). Charts are plain HTML/CSS: thin bars
 * in one color (the site accent, 4.65:1 on the card surface), 4px
 * rounded data-ends, hairline solid gridlines, text in text colors,
 * never in the bar color. Heatmap: one blue ramp, darker = fewer.
 */

.dash {
  --heat-1: #184f95;
  --heat-2: #1c5cab;
  --heat-3: #256abf;
  --heat-4: #3987e5;
  --heat-5: #6da7ec;
  --up: #0ca30c;
  --down: #e66767;
  position: relative;
  margin-top: 28px;
}

/* ── Period filter: one row above everything it scopes ── */

.dash-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 28px;
}

.dash-filter-label {
  margin-right: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dash-filter a {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.dash-filter a:hover {
  color: var(--text);
}

.dash-filter a.is-active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text);
}

.dash-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 10px;
  margin: 36px 0 14px;
  font-size: 1.1rem;
}

.dash-heading span {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.dash-private {
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-muted);
}

.dash-empty {
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* ── Stat tiles ── */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 12px;
}

.tile {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.tile-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tile-value {
  margin: 2px 0;
  font-size: 1.9rem;
  font-weight: 600;
  line-height: 1.2;
}

.tile-delta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tile-delta.is-up span {
  color: var(--up);
}

.tile-delta.is-down span {
  color: var(--down);
}

.tile-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* ── Chart cards ── */

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.dash-card {
  margin: 0;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}

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

.dash-card figcaption {
  margin-bottom: 14px;
}

.dash-card h3 {
  font-size: 0.95rem;
}

.dash-card figcaption p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Columns over time ── */

.cols-plot {
  position: relative;
  height: 160px;
  margin-left: 2.25rem; /* room for the y labels */
}

.cols-grid {
  position: absolute;
  right: 0;
  left: 0;
  border-top: 1px solid var(--border);
}

.cols-grid span {
  position: absolute;
  right: calc(100% + 8px);
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.cols-bars {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  gap: 2px; /* the surface gap between touching columns */
}

.col {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  outline: none;
}

.col-fill {
  width: 100%;
  max-width: 24px;
  background: var(--accent);
  border-radius: 4px 4px 0 0; /* rounded data-end, square at baseline */
}

.col:hover .col-fill,
.col:focus-visible .col-fill {
  background: #7a9dff;
}

.cols-x {
  display: flex;
  justify-content: space-between;
  margin: 6px 0 0 2.25rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ── Ranked horizontal bars ── */

.bars {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(6rem, 40%) 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  outline: none;
  border-radius: var(--radius-sm);
}

.bar-row:focus-visible {
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.bar-label {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-label a {
  color: inherit;
}

.bar-label a:hover {
  color: var(--accent);
}

.bar-track {
  height: 12px;
}

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

.bar-row:hover .bar-fill,
.bar-row:focus-visible .bar-fill {
  background: #7a9dff;
}

.bar-value {
  min-width: 2.5rem;
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Heatmap ── */

.heat {
  display: grid;
  grid-template-columns: 2.25rem repeat(24, minmax(0, 1fr));
  gap: 2px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.heat-hour {
  text-align: left;
}

.heat-day {
  align-self: center;
}

.heat-cell {
  display: block;
  aspect-ratio: 1;
  min-height: 10px;
  max-height: 26px;
  border-radius: 3px;
  background: var(--surface2);
}

.heat-cell.lvl-1 { background: var(--heat-1); }
.heat-cell.lvl-2 { background: var(--heat-2); }
.heat-cell.lvl-3 { background: var(--heat-3); }
.heat-cell.lvl-4 { background: var(--heat-4); }
.heat-cell.lvl-5 { background: var(--heat-5); }

.heat .heat-cell:hover {
  outline: 1px solid var(--text);
}

.heat-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 10px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.heat-legend .heat-cell {
  width: 12px;
  min-height: 12px;
}

.heat-legend span:first-child {
  margin-right: 4px;
}

.heat-legend span:last-child {
  margin-left: 4px;
}

/* ── Table view of each chart ── */

.dash-table {
  margin-top: 12px;
  font-size: 0.75rem;
}

.dash-table summary {
  color: var(--text-muted);
  cursor: pointer;
}

.dash-table table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
}

.dash-table td,
.dash-table th {
  padding: 3px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* ── Tooltip: value first, label after ── */

.dash-tip {
  position: fixed;
  z-index: 60;
  max-width: 18rem;
  padding: 6px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
  font-size: 0.78rem;
  pointer-events: none;
}

.dash-tip strong {
  display: block;
  color: var(--text);
}

.dash-tip span {
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .dash-grid {
    grid-template-columns: 1fr;
  }

  .heat-hour {
    font-size: 0.55rem;
  }
}
