/* shared/contracts.css -- the visual vocabulary for the system contracts
   (liveness, freshness, activity, receipts). Generalizes the Liveness system
   sheet. Reuses the keyframes already in ds/components.css (spin, pulse-dot,
   bouncy, shimmer); adds `indet` (indeterminate bar) and `wash` (the arrival
   accent wash). Loop animations run 0.9-1.4s, a separate scale from the
   140-220ms transition tokens. Reduced motion swaps loops for opacity pulses. */

@keyframes indet {
  0%   { left: -40%; }
  100% { left: 100%; }
}
@keyframes wash {
  0%   { background-color: var(--accent-soft); }
  100% { background-color: transparent; }
}

/* ── liveness: working control (inline dots + spinner) ── */
.lv-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.lv-dots > i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: bouncy 1.2s ease-in-out infinite;
}
.lv-dots > i:nth-child(2) { animation-delay: 0.16s; }
.lv-dots > i:nth-child(3) { animation-delay: 0.32s; }

.lv-spin {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  flex-shrink: 0;
}

/* ── liveness: progress bars ── */
.lv-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--bg-elev-2);
  overflow: hidden;
  position: relative;
}
.lv-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width var(--transition-fast);
}
.lv-bar.indet .lv-bar-fill {
  position: absolute;
  width: 40%;
  left: -40%;
  opacity: 0.85;
  animation: indet 1.2s ease-in-out infinite;
}

/* ── liveness: working region (one overlay per screen max) ── */
.lv-region {
  position: relative;
}
.lv-region-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 16px;
  text-align: center;
  background: color-mix(in oklab, var(--bg) 45%, transparent);
  backdrop-filter: blur(2px) saturate(0.7);
  z-index: var(--z-sticky);
  border-radius: inherit;
}
.lv-region-status {
  font-size: 13px;
  color: var(--text-2);
  animation: pulse-dot 1.3s ease-in-out infinite;
}
.lv-region-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-4);
}
.lv-region-error {
  color: var(--danger);
  font-size: 13px;
  max-width: 40ch;
  line-height: 1.5;
}

/* ── freshness: arrival grammar ── */
.fresh-wash {
  animation: wash 2.6s ease-out forwards;
}
.fresh-pill {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
  border-radius: var(--r-pill);
  padding: 1px 6px;
  transition: opacity var(--transition-base);
}
.fresh-pill.fade { opacity: 0; }
/* "N new -- show" collector chip for above-the-fold arrivals. */
.fresh-collector {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  animation: pulse-dot 1.3s ease-in-out infinite;
}

/* ── receipts: toast stack (top of the z-ladder) ── */
.tcg-toast-wrap {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw / var(--ui-scale, 1) - 24px));
  pointer-events: none;
}
.tcg-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--bg-elev-1);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-lg, 0 8px 28px rgba(0,0,0,0.32));
  font-size: 13px;
  color: var(--text);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition-base), transform var(--transition-base);
}
.tcg-toast.in { opacity: 1; transform: translateY(0); }
.tcg-toast.danger { border-color: oklch(0.72 0.18 25 / 0.4); }
.tcg-toast-msg { flex: 1; min-width: 0; }
.tcg-toast-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-4);
  flex-shrink: 0;
}
.tcg-toast-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin: -4px -4px -4px 0;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-4);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: color var(--transition-base), background var(--transition-base);
}
.tcg-toast-close:hover { color: var(--text); background: var(--bg-elev-2); }
@media (pointer: coarse) {
  /* shell.css bumps button min-height to 44px here; match the width so the
     dismiss target is square rather than a tall sliver. */
  .tcg-toast-close { min-width: 44px; }
}

@media (min-width: 768px) /* --bp-md */ {
  .tcg-toast-wrap {
    left: auto;
    right: calc(16px + env(safe-area-inset-right));
    transform: none;
  }
}

/* ── activity tray rows ── */
.act-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px 10px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--text-4);
}
.act-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-4);
  font-size: 13px;
}
.act-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 11px 13px;
  border-top: 1px solid var(--border-soft);
}
.act-row.queued { opacity: 0.82; }
.act-row-head {
  display: flex;
  align-items: center;
  gap: 9px;
}
.act-state {
  flex-shrink: 0;
  width: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.act-state.done {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  font-size: 8.5px;
}
.act-state.failed { color: var(--danger); }
.act-state.cancelled { color: var(--text-4); }
.act-state.queued {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1px dashed var(--border-strong);
  animation: pulse-dot 1.3s ease-in-out infinite;
}
.act-state.paused { color: var(--text-3); font-size: 12px; }
.act-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.act-controls { display: flex; gap: 4px; flex-shrink: 0; }
.act-sub {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-4);
}
.act-sub.err { color: var(--danger); white-space: normal; line-height: 1.5; }
.act-time {
  font-family: var(--font-mono);
  font-size: 8.5px;
  color: var(--text-4);
  opacity: 0.8;
  letter-spacing: 0.02em;
}

/* Topbar + sidebar Activity dot: pulses while anything runs. */
.activity-dot {
  position: relative;
  display: inline-flex;
}
.activity-dot[data-running="1"]::after {
  content: "";
  position: absolute;
  top: -1px;
  right: -1px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse-dot 1.3s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .lv-dots > i,
  .lv-spin,
  .lv-bar.indet .lv-bar-fill,
  .lv-region-status,
  .fresh-collector,
  .act-state.queued,
  .activity-dot[data-running="1"]::after {
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
  }
  /* keep the spinner readable as a static ring; show progress by numbers */
  .lv-spin { border-top-color: var(--accent); }
  .fresh-wash { animation: none; }
}
