/* Stats Dashboard Styles */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --red: #e63946;
  --orange: #e76f51;
  --cream: #fdf0d5;
  --dark: #2b2b2b;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  background: #f5f5f5;
  color: var(--dark);
  min-height: 100vh;
}

/* ── Concluded banner ──────────────────────── */

.concluded-banner {
  display: none;
  background: linear-gradient(135deg, #fff8f0 0%, #ffe8cc 100%);
  color: var(--dark);
  text-align: center;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  border-bottom: 1px solid #f0d9b5;
}

.concluded-banner a {
  color: var(--orange);
  text-decoration: none;
  margin-left: 4px;
}

.concluded-banner a:hover {
  text-decoration: underline;
}

/* ── Header ──────────────────────────────── */

header {
  background: linear-gradient(135deg, var(--dark) 0%, #3a2a1e 100%);
  color: var(--cream);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--red);
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
}

header h1 a {
  color: inherit;
  text-decoration: none;
}

header h1 a:hover {
  text-decoration: underline;
}

.header-sub {
  font-size: 0.85rem;
  color: var(--orange);
  font-weight: 400;
}

.back-link {
  color: var(--orange);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}

.back-link:hover {
  text-decoration: underline;
}

/* ── Live activity ───────────────────────── */

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  animation: live-pulse 2s ease-in-out infinite;
  margin-right: 6px;
  vertical-align: middle;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.live-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* ── Info tooltip ────────────────────────── */

.info-tip {
  position: relative;
  cursor: pointer;
  color: #aaa;
  font-size: 0.85rem;
  vertical-align: middle;
}

.info-tip:hover,
.info-tip:focus {
  color: var(--orange);
}

.info-tip-text {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--dark);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
}

.info-tip:hover .info-tip-text,
.info-tip:focus .info-tip-text {
  display: block;
}

/* ── Main ────────────────────────────────── */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* ── Summary cards ───────────────────────── */

.summary-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.card {
  flex: 1;
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.2;
}

.card-label {
  font-size: 0.82rem;
  color: #888;
  margin-top: 4px;
}

/* ── Leaderboard ─────────────────────────── */

.leaderboard-section {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.leaderboard-section + .leaderboard-section {
  margin-top: 20px;
}

.leaderboard-section h2 {
  font-size: 1.1rem;
  margin-bottom: 4px;
  position: sticky;
  top: 45px;
  background: #fff;
  padding: 12px 0 8px;
  margin: -12px 0 4px;
  z-index: 3;
  box-shadow: 0 1px 0 #fff;
}

.leaderboard-hint {
  font-size: 0.8rem;
  color: #999;
  margin-bottom: 16px;
  position: sticky;
  top: 77px;
  background: #fff;
  z-index: 2;
  padding-bottom: 4px;
}

.scoring-toggle {
  color: var(--orange);
  cursor: pointer;
  font-weight: 500;
}

.scoring-toggle:hover {
  text-decoration: underline;
}

.toggle-arrow {
  font-size: 0.6rem;
  vertical-align: middle;
  display: inline-block;
  transition: transform 0.2s;
}

.toggle-arrow.open {
  transform: rotate(180deg);
}

.scoring-detail {
  display: none;
  background: #f9f9f9;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.82rem;
  color: #555;
  line-height: 1.6;
}

.scoring-detail.open {
  display: block;
}

.scoring-detail p + p {
  margin-top: 4px;
}

.table-wrap {
  overflow-x: visible;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid #eee;
  font-size: 0.78rem;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  user-select: none;
  position: sticky;
  top: 93px;
  background: #fff;
  z-index: 1;
  box-shadow: 0 -4px 0 #fff, 0 2px 0 #eee;
}

thead th[data-sort] {
  cursor: pointer;
  white-space: nowrap;
}

thead th[data-sort]:hover {
  color: var(--dark);
}

thead th.sort-active {
  color: var(--red);
}

.sort-arrow {
  font-size: 0.6rem;
  vertical-align: middle;
}

tbody tr {
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.1s;
}

tbody tr:hover {
  background: var(--cream);
}

tbody td {
  padding: 8px 10px;
}

.col-rank {
  width: 40px;
}

.col-num {
  text-align: right;
  width: 80px;
}

tbody td.col-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rank-cell {
  font-weight: 700;
  color: #888;
}

.name-cell {
  font-weight: 500;
}
.name-cell a {
  color: inherit;
  text-decoration: none;
}

.area-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.score-cell {
  font-weight: 700;
  color: var(--red);
}

.fires {
  font-size: 0.72rem;
  margin-left: 4px;
  letter-spacing: -1px;
}

/* ── Filter stats grid ───────────────────── */

.filter-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* ── Platform & Device ───────────────────── */

.platform-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.platform-col h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin-bottom: 12px;
}

.device-cards {
  display: flex;
  gap: 10px;
}

.device-card {
  flex: 1;
  text-align: center;
  background: #f9f9f9;
  border-radius: 8px;
  padding: 12px 6px;
}

.device-card .device-emoji {
  font-size: 1.5rem;
  display: block;
  margin-bottom: 4px;
}

.device-card .device-pct {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.2;
}

.device-card .device-label {
  font-size: 0.72rem;
  color: #888;
  margin-top: 2px;
}

.device-card .device-count {
  font-size: 0.68rem;
  color: #aaa;
  margin-top: 2px;
}

.bar-row {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.bar-label {
  width: 70px;
  font-size: 0.78rem;
  color: var(--dark);
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  flex: 1;
  height: 18px;
  background: #f0f0f0;
  border-radius: 4px;
  overflow: hidden;
  margin: 0 8px;
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--orange), var(--red));
  transition: width 0.4s ease;
}

.bar-value {
  width: 40px;
  font-size: 0.75rem;
  color: #888;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ── Clickable cards ─────────────────────── */

.card-clickable {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.card-clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.card-clickable:active {
  transform: translateY(0);
}

/* ── Chart modal ─────────────────────────── */

.chart-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.chart-modal-overlay.open {
  display: flex;
}

.chart-modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: chart-modal-in 0.2s ease;
}

@keyframes chart-modal-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.chart-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.chart-modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.chart-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #888;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.chart-modal-close:hover {
  color: var(--dark);
}

.chart-modal-body {
  padding: 16px 20px 20px;
}

.chart-modal-body canvas {
  width: 100% !important;
  max-height: 400px;
}

/* ── Heatmap ─────────────────────────────── */

.heatmap-wrap {
  overflow-x: auto;
  padding: 4px 0;
  position: relative;
}

.heatmap-row {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 2px;
}

.heatmap-header {
  margin-bottom: 4px;
}

.heatmap-day-label {
  width: 70px;
  flex-shrink: 0;
  font-size: 0.72rem;
  color: #888;
  text-align: right;
  padding-right: 8px;
  white-space: nowrap;
}

.heatmap-hour-label {
  flex: 1;
  min-width: 20px;
  font-size: 0.62rem;
  color: #aaa;
  text-align: center;
}

.heatmap-cell {
  flex: 1;
  min-width: 20px;
  aspect-ratio: 1;
  border-radius: 3px;
  cursor: crosshair;
  transition: outline 0.1s, transform 0.1s;
}

.heatmap-cell:hover {
  outline: 2px solid var(--dark);
  outline-offset: -1px;
  transform: scale(1.15);
  z-index: 2;
}

.heatmap-peak {
  outline: 2px solid var(--dark);
  outline-offset: -1px;
  box-shadow: 0 0 0 3px rgba(231, 111, 81, 0.4);
}

.heatmap-row-total {
  width: 42px;
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: #888;
  text-align: right;
  padding-left: 6px;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.heatmap-tooltip {
  position: absolute;
  background: var(--dark);
  color: #fff;
  font-size: 0.78rem;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
  z-index: 10;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 10px;
  font-size: 0.68rem;
  color: #999;
}

.heatmap-legend-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

/* ── Footer ──────────────────────────────── */

.footer-note {
  text-align: center;
  font-size: 0.78rem;
  color: #aaa;
  margin-top: 20px;
}

/* ── Mobile ──────────────────────────────── */

@media (max-width: 600px) {
  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .card {
    padding: 14px;
  }

  .card-value {
    font-size: 1.5rem;
  }

  .header-left {
    flex-direction: column;
    gap: 0;
  }

  header h1 {
    font-size: 1rem;
  }

  .leaderboard-section {
    padding: 14px;
  }

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

  .platform-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  table {
    font-size: 0.8rem;
  }

  thead th,
  tbody td {
    padding: 6px 6px;
  }

  .col-num {
    width: 55px;
  }
}
