/* Live usage stats (stats.js): the home page badge with its inline panel, and the /stats page.
 * Same zinc tokens as styles.css; light only. The badge stays hidden until the API answers with live numbers. */

/* ---------- badge (home) ---------- */
.stats-badge { position: relative; justify-self: start; max-width: 100%; }
.stats-pill {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%; height: 28px; padding: 0 10px 0 9px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--background);
  font: 500 12px/1 var(--font); color: var(--muted-foreground); cursor: pointer; white-space: nowrap;
  font-variant-numeric: tabular-nums; transition: color .15s, border-color .15s, background-color .15s;
}
.stats-pill > span[data-stats-line] { overflow: hidden; text-overflow: ellipsis; }
.stats-pill:hover, .stats-pill[aria-expanded="true"] { color: var(--foreground); border-color: var(--ring); background: var(--muted); }
.stats-dot { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--foreground); box-shadow: 0 0 0 3px var(--muted); }
.stats-chev {
  width: 6px; height: 6px; flex: none; margin: -3px 1px 0 2px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg); transition: transform .15s;
}
.stats-pill[aria-expanded="true"] .stats-chev { transform: translateY(3px) rotate(225deg); }
@media (prefers-reduced-motion: no-preference) {
  .stats-dot { animation: stats-pulse 2.4s ease-in-out infinite; }
}
@keyframes stats-pulse { 50% { box-shadow: 0 0 0 1px var(--muted); } }

.stats-pop {
  position: absolute; z-index: 30; top: calc(100% + 8px); left: 0;
  width: min(600px, calc(100vw - 32px)); max-height: min(68vh, 600px); overflow: auto; overscroll-behavior: contain;
  padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--background); box-shadow: var(--shadow);
}
.stats-close {
  position: absolute; top: 10px; right: 10px; display: grid; place-items: center; width: 24px; height: 24px; padding: 0;
  border: 1px solid transparent; border-radius: 6px; background: var(--background); color: var(--muted-foreground);
  font: 400 16px/1 var(--font); cursor: pointer;
}
.stats-close:hover { color: var(--foreground); border-color: var(--border); background: var(--muted); }
.stats-pop .stats-updated { padding-right: 32px; }
.stats-pop-up { top: auto; bottom: calc(100% + 8px); }
.stats-more { display: inline-block; margin-top: 12px; font-size: 12px; color: var(--muted-foreground); text-decoration: none; }
.stats-more:hover { color: var(--foreground); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- panel (both) ---------- */
.stats-panel { font-variant-numeric: tabular-nums; }
.stats-updated {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; margin: 0 0 10px;
  font-size: 12px; color: var(--muted-foreground);
}
.stats-updated span { color: var(--foreground); font-weight: 500; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; margin: 0; }
.stats-cell { min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--background); }
.stats-cell:hover { border-color: var(--ring); }
.stats-cell dt { font-size: 11px; line-height: 1.4; color: var(--muted-foreground); }
.stats-cell dd { margin: 2px 0 0; font-size: 15px; font-weight: 700; line-height: 1.3; letter-spacing: -.02em; color: var(--foreground); overflow-wrap: anywhere; }
.stats-big { background: var(--muted); }
.stats-big dd { font-size: 18px; }
.stats-h { margin: 16px 0 6px; font-size: 12px; font-weight: 700; letter-spacing: -.01em; color: var(--foreground); }
.stats-note { margin: 6px 0 0; font-size: 11px; color: var(--muted-foreground); }

/* tables: kept as tables on phones too (doc.css stacks other tables below 600px) */
.stats-panel table.stats-table { display: table; width: 100%; margin: 0; border-collapse: collapse; font-size: 12px; }
.stats-panel .stats-table thead { display: table-header-group; }
.stats-panel .stats-table tbody { display: table-row-group; }
.stats-panel .stats-table tr { display: table-row; padding: 0; }
.stats-panel .stats-table th, .stats-panel .stats-table td {
  display: table-cell; padding: 5px 8px 5px 0; border-bottom: 1px solid var(--border); text-align: left;
  font-weight: 400; color: var(--foreground); overflow-wrap: anywhere;
}
.stats-panel .stats-table th { font-size: 11px; font-weight: 500; color: var(--muted-foreground); }
.stats-panel .stats-table tbody tr:hover td { background: var(--muted); }
.stats-panel .stats-table .num { text-align: right; white-space: nowrap; }
.stats-panel .stats-table .rank { width: 3ch; padding-right: 10px; color: var(--muted-foreground); }
.stats-panel .stats-table th:last-child, .stats-panel .stats-table td:last-child { padding-right: 0; }

/* ---------- /stats page ---------- */
.stats-page { margin-top: 8px; }
.stats-page[data-state="loading"] .stats-off { visibility: hidden; }
.stats-page[data-state="live"] .stats-off { display: none; }
.stats-page .stats-off { margin: 0; padding: 12px 14px; border: 1px solid var(--ring); border-radius: 6px; background: var(--muted, transparent); color: var(--muted-foreground); }
.stats-page .stats-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.stats-page .stats-updated span { display: none; } /* the lede says it */
.stats-page .stats-cell dd { font-size: 18px; }
.stats-page .stats-big dd { font-size: 22px; }
.stats-page .stats-h { margin-top: 24px; font-size: 13px; }

/* ---------- phones: the panel opens as a sheet under the nav ---------- */
@media (max-width: 600px) {
  .stats-pop { position: fixed; top: 64px; left: 16px; right: 16px; width: auto; max-height: calc(100svh - 132px); padding: 14px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-cell dd, .stats-page .stats-cell dd { font-size: 14px; }
  .stats-big dd, .stats-page .stats-big dd { font-size: 16px; }
}
