/* owner: server — live bridge (ui/live.js). Taiwan convention: red = up / live, green = down. */

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: var(--fs-xs, 12px);
}

/* The topbar's own .live-dot is redundant once the richer badge is mounted. */
.tb-right:has(.live[data-mode]) > .live-dot { display: none; }

/* ---------- static mode hint ---------- */
.live__static {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--r-pill, 999px);
  border: 1px dashed var(--border-strong);
  color: var(--faint, var(--muted));
  font-size: var(--fs-2xs, 11px);
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: help;
}
.live__static::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--flat, var(--muted));
  opacity: 0.6;
}

/* ---------- live badge ---------- */
.live__badge {
  --c: var(--muted);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px 0 8px;
  border-radius: var(--r-pill, 999px);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  background: color-mix(in srgb, var(--c) 10%, transparent);
  color: var(--c);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs, 11px);
  font-weight: 600;
  letter-spacing: 0.08em;
  white-space: nowrap;
  cursor: default;
  transition: background 0.3s var(--ease-out, ease), border-color 0.3s var(--ease-out, ease), color 0.3s;
}
.live__badge--open { --c: var(--up); }
.live__badge--closed { --c: var(--accent); letter-spacing: 0.04em; font-family: var(--font-sans); }
.live__badge--offline { --c: var(--warn, var(--muted)); letter-spacing: 0.02em; font-family: var(--font-sans); }

.live__dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c);
  flex: none;
}
.live__badge--open .live__dot::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid var(--c);
  animation: live-pulse 1.8s var(--ease-out, ease-out) infinite;
}
.live__badge--offline .live__dot { animation: live-blink 1.2s steps(2, jump-none) infinite; }

.live__time {
  color: var(--text-2, var(--text));
  font-weight: 500;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

/* A tick just arrived: a quick glow sweep, subtle enough to live with all day. */
.live__badge.is-flash {
  animation: live-flash 0.9s var(--ease-out, ease-out);
}
.live__badge.is-flash::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(100deg, transparent 20%, color-mix(in srgb, var(--c) 40%, transparent) 50%, transparent 80%);
  background-size: 250% 100%;
  animation: live-sweep 0.9s var(--ease-out, ease-out) forwards;
  pointer-events: none;
}

/* ---------- sync button with progress ring ---------- */
.live__sync {
  --p: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px 0 4px;
  border-radius: var(--r-pill, 999px);
  border: 1px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text-2, var(--text));
  font: inherit;
  font-size: var(--fs-2xs, 11px);
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.live__sync:hover { border-color: var(--accent); color: var(--text); background: var(--panel-hover); }
.live__sync:focus-visible { outline: none; box-shadow: var(--ring); }
.live__sync b { font-family: var(--font-mono); font-weight: 600; color: var(--accent-strong, var(--accent)); font-variant-numeric: tabular-nums; }

.live__ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex: none;
}
.live__ring svg { width: 12px; height: 12px; }
.live__sync.is-running { cursor: progress; border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.live__sync.is-running .live__ring {
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), color-mix(in srgb, var(--accent) 16%, transparent) 0);
  -webkit-mask: radial-gradient(circle, transparent 6px, #000 6.5px);
          mask: radial-gradient(circle, transparent 6px, #000 6.5px);
  transition: background 0.4s;
}
.live__sync.is-running .live__ring svg { display: none; }
.live__sync.is-running .live__ring::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 80%, var(--accent-glow, var(--accent)) 100%);
  animation: live-spin 1.1s linear infinite;
}

@media (max-width: 900px) {
  .live__sync-text, .live__time { display: none; }
  .live__sync { padding: 0 3px; }
}

@keyframes live-pulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(1.9); opacity: 0; }
}
@keyframes live-blink { 50% { opacity: 0.25; } }
@keyframes live-flash {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 55%, transparent); }
  100% { box-shadow: 0 0 0 7px transparent; }
}
@keyframes live-sweep {
  from { background-position: 120% 0; }
  to { background-position: -30% 0; }
}
@keyframes live-spin { to { transform: rotate(1turn); } }

@media (prefers-reduced-motion: reduce) {
  .live__badge--open .live__dot::after,
  .live__badge--offline .live__dot,
  .live__badge.is-flash,
  .live__badge.is-flash::before,
  .live__sync.is-running .live__ring::after { animation: none; }
}
