/* Site statistics page. Loads after base.css.
   Heading + range tabs → six summary tiles → chart cards. Charts are canvases drawn by stats.js. */

.stats-page-main { padding-top: 24px; padding-bottom: 24px; }

/* ---------- Heading ---------- */
.archive-stats-heading { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 20px 24px; margin-bottom: 24px; }
.stats-page-back { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.stats-page-back:hover { color: var(--accent); }
.stats-page-back .ico { width: 14px; height: 14px; }
.stats-page-title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
/* The Rodin subset lacks many hanzi, so Chinese headings stay in the UI font. */
.stats-page-title { font-size: clamp(26px, 3vw, 34px); font-weight: 800; line-height: 1.15; letter-spacing: -0.03em; }
.stats-live-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); font-size: 11px; font-weight: 700; }
.stats-live-pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: live 2.4s ease-in-out infinite; }
@keyframes live { 50% { opacity: 0.4; } }
.stats-page-lead { margin-top: 6px; color: var(--muted); font-size: 13px; }
.stats-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; max-width: 100%; }
.stats-range-tabs { display: flex; gap: 2px; max-width: 100%; padding: 3px; overflow-x: auto; border-radius: 11px; background: var(--surface-2); scrollbar-width: none; }
.stats-range-tabs::-webkit-scrollbar { display: none; }
.stats-range-tab { flex: none; min-height: 34px; padding: 0 12px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; transition: background 160ms ease, color 160ms ease; }
.stats-range-tab:hover { color: var(--text); }
.stats-range-tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.stats-refresh-btn.is-loading .ico { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Summary tiles ---------- */
.stats-summary-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 36px; }
.stats-summary-card {
  position: relative; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 112px;
  padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  animation: rise 360ms var(--ease) backwards;
  transition: border-color 160ms ease, transform 200ms var(--ease);
}
.stats-summary-card:nth-child(2) { animation-delay: 30ms; } .stats-summary-card:nth-child(3) { animation-delay: 60ms; }
.stats-summary-card:nth-child(4) { animation-delay: 90ms; } .stats-summary-card:nth-child(5) { animation-delay: 120ms; }
.stats-summary-card:nth-child(6) { animation-delay: 150ms; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.stats-summary-card:hover { border-color: color-mix(in srgb, var(--tone) 50%, var(--line)); }
.stat-count-toggle-card { cursor: pointer; }
.stats-summary-card[data-tone="blue"] { --tone: #3d6fe0; }
.stats-summary-card[data-tone="pink"] { --tone: var(--d7); }
.stats-summary-card[data-tone="green"] { --tone: var(--d5); }
.stats-summary-card[data-tone="amber"] { --tone: var(--d3); }
.stats-summary-card[data-tone="cyan"] { --tone: var(--d2); }
.stats-summary-card[data-tone="neutral"] { --tone: var(--faint); }
.stats-summary-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stats-summary-label { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 600; }
.stats-summary-label::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--tone); }
.stats-summary-head > span:last-child { padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--faint); font-size: 10px; }
.stats-summary-value { font-family: var(--display); font-size: 26px; font-weight: 800; line-height: 1.15; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stats-summary-sub { color: var(--faint); font-size: 11px; }
.stats-summary-pressure { font-family: var(--ui); }
.stats-summary-pressure.is-low { color: var(--ok); }
.stats-summary-pressure.is-medium { color: var(--warn); }
.stats-summary-pressure.is-high { color: var(--hot); }
.stats-summary-pressure.is-critical { color: var(--bad); }

/* ---------- R2 prewarm progress ---------- */
.stats-prewarm {
  --tone: var(--d5);
  display: flex; flex-direction: column; gap: 10px; margin: -20px 0 36px; padding: 16px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.stats-prewarm-row { display: flex; align-items: center; gap: 16px; min-width: 0; }
.stats-prewarm-value { flex: none; font-family: var(--display); font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats-prewarm-bar { flex: 1; min-width: 0; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.stats-prewarm-bar > span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--tone); transition: width 400ms var(--ease); }

/* ---------- Charts ---------- */
.stats-section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.stats-section-head h2 { font-size: 18px; font-weight: 750; }
.stats-section-head p, .stats-section-head > span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.stats-chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.stats-chart-card { min-width: 0; padding: 16px 16px 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.stats-chart-card--wide { grid-column: 1 / -1; }
.stats-chart-card.is-chart-entering { animation: rise 420ms var(--ease) backwards; }
.stats-chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.stats-chart-head h2 { font-size: 14px; font-weight: 700; }
.stats-chart-hint { color: var(--faint); font-size: 11px; }
.stats-chart-body { position: relative; min-width: 0; }
.stats-chart-canvas { display: block; width: 100%; cursor: crosshair; }
.stats-chart-tooltip {
  position: fixed; z-index: 100; min-width: 140px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow-pop);
  color: var(--text); font-size: 12px; line-height: 1.6; pointer-events: none;
}
.stats-chart-tooltip-time { margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.stats-chart-tooltip-row strong { margin-left: 4px; font-variant-numeric: tabular-nums; }
.stats-page-footnote { margin-top: 18px; color: var(--faint); font-size: 12px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stats-summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .stats-chart-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .stats-page-main { padding-top: 16px; }
  .stats-toolbar { width: 100%; }
  .stats-range-tabs { flex: 1 1 100%; }
  .stats-refresh-btn { flex: 1; }
  .stats-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 28px; }
  .stats-summary-card { min-height: 96px; padding: 14px; }
  .stats-summary-value { font-size: 21px; }
  .stats-prewarm { margin: -16px 0 28px; padding: 14px; }
  .stats-prewarm-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .stats-prewarm-bar { flex: none; }
  .stats-section-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .stats-chart-card { padding: 14px 12px 10px; }
}
