/* Live updates of blocks (shared/query/_live, explorer/live.js). Colors come
   from the theme tokens: --bq-* of the redesign, else the --q-* of query.css. */

.q-api-buttons:has(.q-live) { flex-wrap: wrap; align-items: center; }
/* First in the row of the block's buttons, the IDE buttons pushed right. */
.q-live { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; order: -1; margin-right: auto; }
.q-live[hidden] { display: none; }

.q-live button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--bq-border-strong, var(--q-border));
  border-radius: 999px;
  background: var(--bq-surface, var(--q-surface));
  color: var(--bq-text, var(--q-text));
  font-size: 0.8125rem;
  line-height: 1.4;
  cursor: pointer;
}
.q-live button:hover { border-color: var(--bq-teal-text, var(--q-ok)); }
.q-live button:focus-visible { outline: 2px solid var(--bq-focus-ring, var(--q-accent)); outline-offset: 2px; }

/* The dot of Live: grey when off, green and pulsing while live, amber when
   the stream is unavailable (the table keeps its cached data). */
.q-live-toggle::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--bq-text-muted, var(--q-muted));
}
.q-live[data-status="live"] .q-live-toggle::before { background: var(--bq-success, var(--q-ok)); animation: q-live-pulse 2s ease-in-out infinite; }
.q-live[data-status="subscribed"] .q-live-toggle::before { background: var(--bq-success, var(--q-ok)); }
.q-live[data-status="connecting"] .q-live-toggle::before,
.q-live[data-status="disconnected"] .q-live-toggle::before { background: var(--bq-success, var(--q-ok)); opacity: 0.5; }
.q-live[data-status="rate_limited"] .q-live-toggle::before,
.q-live[data-status="busy"] .q-live-toggle::before,
.q-live[data-status="error"] .q-live-toggle::before { background: var(--bq-yellow, #c27c0e); }
.q-live-toggle[aria-pressed="true"] { border-color: var(--bq-success, var(--q-ok)); }

.q-live-mempool[aria-pressed="true"] {
  border-color: var(--bq-accent, var(--q-accent));
  background: var(--bq-accent, var(--q-accent));
  color: var(--bq-accent-contrast, var(--q-on-accent));
}

.q-live-status { color: var(--bq-text-muted, var(--q-muted)); font-size: 0.8125rem; }

/* "↑ 37 new rows": new rows wait above a reader scrolled down the table
   (explorer/live.js). The bar sticks under a sticky page header
   (--bq-header-h) and has no height, so showing it moves no
   row; its pill floats over the table. */
.q-live-more {
  position: sticky;
  top: calc(var(--bq-header-h, 0px) + 0.5rem);
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  height: 0;
  overflow: visible;
}
.q-live-more button {
  padding: 0.3rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--bq-accent, var(--q-accent));
  color: var(--bq-accent-contrast, var(--q-on-accent));
  font-size: 0.8125rem;
  line-height: 1.2;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.q-live-more button:hover { background: var(--bq-accent-hover, var(--q-accent-hover)); }
.q-live-more button:focus-visible { outline: 2px solid var(--bq-focus-ring, var(--q-accent)); outline-offset: 2px; }

/* Pending transactions (Mempool): a bar in the accent color on the left. */
tr.q-live-pending > td:first-child { box-shadow: inset 3px 0 0 var(--bq-accent, var(--q-accent)); }

/* Rows that arrived with the last update fade in from the highlight. */
tr.q-live-new > td { animation: q-live-new 4s ease-out; }

@keyframes q-live-pulse { 50% { opacity: 0.35; } }
@keyframes q-live-new { from { background-color: var(--bq-teal-soft, rgba(25, 135, 84, 0.18)); } }

@media (prefers-reduced-motion: reduce) {
  .q-live[data-status="live"] .q-live-toggle::before { animation: none; }
  tr.q-live-new > td { animation: none; background-color: var(--bq-teal-soft, rgba(25, 135, 84, 0.12)); }
}
