/* static/css/precision_badge.css — the Precision badge on a closed Grid tile.
 *
 * precision_badge.js adds one .pk-pb to the top-right of each Precision card. It is display:none
 * everywhere except a closed Grid tile (the other densities keep their own pills, an opened tile
 * is the plain card), so deleting the script or this file restores the page exactly as it was.
 *
 * Pending: a soft teal halo breathes behind the pill and the star twinkles, one 2.4s clock.
 * Done: a check. The first time a tile goes pending -> done it plays a 600ms settle (star out,
 * check drawn in, one ring) and is still afterwards; a tile that is already done is drawn in its
 * final frame with no animation. Under reduced motion nothing loops or moves: the halo is a fixed
 * glow and the star/check glyph carries the state.
 *
 * Opacity and transform only, on a ~70x24px element. Sizes and spacing follow DESIGN.md (12px/600,
 * 4/8px steps). The fill is a deeper teal than iStock's #009CBD so white text clears 4.5:1.
 */

/* Everything below is for a closed Grid tile only. */
.pk-pb { display: none; }

:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb {
  --pk-pb-fill: #00819c;
  --pk-pb-glow: #22c1e0;
  --pk-pb-ease: cubic-bezier(.16, 1, .3, 1);
  position: absolute; z-index: 2; top: 8px; right: 8px;
  display: inline-flex;
  pointer-events: none;   /* a click on the corner still opens the tile */
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb-pill {
  position: relative;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 16px; white-space: nowrap;
  color: #fff; background: var(--pk-pb-fill);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28), 0 1px 3px rgba(0, 0, 0, .35);
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb-ico {
  display: grid; width: 12px; height: 12px; flex: none;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb-ico > svg {
  grid-area: 1 / 1; width: 12px; height: 12px; overflow: visible;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb-spark { fill: currentColor; }
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb-check {
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
}

/* The halo sits behind the pill (it comes first in the markup) and spills past its edge. */
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb-halo {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--pk-pb-glow); filter: blur(8px);
  opacity: 0; transform: translateY(2px);
}

/* Pending: halo breathes, star twinkles. */
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb[data-state="pending"] .pk-pb-halo {
  animation: pkPbBreathe 2.4s ease-in-out infinite;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb[data-state="pending"] .pk-pb-spark {
  animation: pkPbTwinkle 2.4s ease-in-out infinite;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb[data-state="pending"] .pk-pb-check { opacity: 0; }

/* Done: the final frame, with no motion. */
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb[data-state="done"] .pk-pb-spark { opacity: 0; transform: scale(0); }
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb[data-state="done"] .pk-pb-check { stroke-dashoffset: 0; }

/* The settle: once, on the pending -> done change (.pk-pb-settle is removed after 900ms). */
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb.pk-pb-settle .pk-pb-pill {
  animation: pkPbNudge .32s var(--pk-pb-ease) both;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb.pk-pb-settle .pk-pb-spark {
  animation: pkPbSparkOut .14s ease-in both;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb.pk-pb-settle .pk-pb-check {
  animation: pkPbDraw .26s var(--pk-pb-ease) .12s both;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb.pk-pb-settle .pk-pb-halo {
  animation: pkPbHaloOut .5s ease-out both;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb.pk-pb-settle::after {
  content: ""; position: absolute; inset: 0; border-radius: 999px;
  border: 2px solid var(--pk-pb-glow);
  animation: pkPbRing .6s var(--pk-pb-ease) both;
}

@keyframes pkPbBreathe {
  0%, 100% { opacity: .18; transform: translateY(2px) scale(1); }
  50%      { opacity: .55; transform: translateY(2px) scale(1.14); }
}
@keyframes pkPbTwinkle { 0%, 100% { opacity: .7; } 50% { opacity: 1; } }
@keyframes pkPbNudge { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes pkPbSparkOut { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0); } }
@keyframes pkPbDraw {
  from { opacity: 0; stroke-dashoffset: 1; }
  20%  { opacity: 1; }
  to   { opacity: 1; stroke-dashoffset: 0; }
}
@keyframes pkPbHaloOut { from { opacity: .55; } to { opacity: 0; } }
@keyframes pkPbRing { from { opacity: .6; transform: scale(1); } to { opacity: 0; transform: scale(1.5); } }
@keyframes pkPbFade { from { opacity: 0; } to { opacity: 1; } }

/* Reduced motion: nothing loops or moves. A pending tile keeps a fixed glow, a finished one
   fades its check in. The star vs check glyph and the aria-label carry the state without motion. */
@media (prefers-reduced-motion: reduce) {
  :is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb[data-state="pending"] .pk-pb-halo { animation: none; opacity: .4; }
  :is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb[data-state="pending"] .pk-pb-spark { animation: none; }
  :is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb.pk-pb-settle :is(.pk-pb-pill, .pk-pb-spark, .pk-pb-halo) { animation: none; }
  :is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb.pk-pb-settle::after { content: none; }
  :is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .pk-pb.pk-pb-settle .pk-pb-check { animation: pkPbFade .15s linear both; }
}

/* With the badge up, the tile's other top-right and top-left items make room for it. Reject
   Radar pills (agency strip) drop below it and stack; the dark "Optimizing…" pill top-left is
   hidden while pending, since the glowing badge says the same thing. */
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .rcard:has(> .pk-pb) .agency-check {
  top: calc(8px + 24px + 4px);
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .rcard:has(> .pk-pb) .agency-check .agency-row {
  flex-direction: column; align-items: flex-end;
}
:is(#img-list, #vid-list)[data-density="grid"] > :not([data-rd-open]) .rcard:has(> .pk-pb[data-state="pending"]) .rbadges > .badge-dim:not(.kw-badge, .bx-badge) {
  display: none;
}
