/*
 * The circuit breakers, made visible.
 *
 * Three states get a look of their own, and the difference between them is the whole
 * point: KILLED means the desk stopped itself and nothing will go out until somebody
 * says so; PAUSED means entries are refused but exits are not; BLOCKED means one order
 * was refused and everything else is untouched. Three severities that look alike would
 * be worse than not showing them at all — a trader would learn to read orange as "some
 * breaker thing" and stop distinguishing the one that ended their day.
 *
 * All three borrow the hot orange rather than the desk green. Green is the colour of
 * things working.
 */

/* The limits as the breaker sees them, after validation. */
.breaker-limits {
  display: grid;
  gap: 1px;
  padding: var(--sp-1) 0;
}

.breaker-limits__row {
  display: flex;
  gap: var(--sp-2);
  justify-content: space-between;
  font-size: var(--fs-0);
  color: var(--ink-muted);
}

/* The record. Dense and scrollable — it is read after the fact, not during. */
.breaker-log {
  display: grid;
  gap: 1px;
  max-block-size: 12rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-1);
  background: var(--bg-inset);
}

.breaker-log__row {
  display: flex;
  gap: var(--sp-2);
  align-items: baseline;
  padding: 2px var(--sp-2);
  font-size: var(--fs-0);
}

.breaker-log__what {
  color: var(--orange);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The lights. Three dots, each one a button onto the limit behind it. */
.breaker-leds {
  display: inline-flex;
  gap: var(--sp-2);
  align-items: center;
}

.breaker-led {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-muted);
  cursor: pointer;
}

.breaker-led:hover {
  color: var(--ink-strong);
}

.breaker-led__dot--ok {
  background: var(--green);
  box-shadow: var(--glow-green);
}

.breaker-led__dot--warn {
  background: var(--orange);
  box-shadow: var(--glow-orange);
}

.breaker-led__dot--tripped {
  background: var(--orange-hot);
  animation: led-blink 900ms steps(1, end) infinite;
}

@keyframes led-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0.25;
  }
}

/* The always-there kill button. Sized past the 44px guideline in both axes: this is the
   one control that gets hit under stress, one-handed, without aiming. */
.kill {
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
  align-items: center;
  justify-content: center;
  min-inline-size: 4.5rem;
  min-block-size: 44px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--orange-hot);
  border-radius: var(--radius-1);
  background: color-mix(in srgb, var(--orange-hot) 14%, transparent);
  color: var(--orange-hot);
  font-family: var(--font-mono);
  font-size: var(--fs-1);
  font-weight: 700;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.kill:hover {
  background: color-mix(in srgb, var(--orange-hot) 26%, transparent);
}

/* No transition on :active. A control whose whole promise is "faster than thinking"
   must not spend 120ms easing into its pressed state. */
.kill:active {
  background: var(--orange-hot);
  color: var(--ink-inverse);
}

.kill:focus-visible {
  outline: 2px solid var(--orange-hot);
  outline-offset: 2px;
}

/* Tripped: the button becomes the notice, and the notice is the re-arm. One element,
   because a separate banner and a separate button is two things to find. */
.kill--tripped {
  border-color: var(--orange-hot);
  background: var(--orange-hot);
  color: var(--ink-inverse);
  animation: kill-alarm 1.1s ease-in-out infinite;
}

/*
 * The hold. A bar rather than a literal ring — at header height a radial sweep is four
 * pixels of arc nobody can read, and the honest version of "how far through am I" here is a
 * line that fills. Green as it fills, so the completion reads as the desk coming back
 * rather than as more alarm.
 */
.kill__ring {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  block-size: 3px;
  inline-size: var(--held, 0%);
  background: var(--green);
  /* Short, because the ring must never lag the finger: a bar still travelling after the
     press landed would read as a hold that had not finished. */
  transition: inline-size 60ms linear;
}

.kill--tripped {
  position: relative;
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .kill__ring {
    transition: none;
  }
}

.kill__why {
  max-inline-size: 11rem;
  font-size: var(--fs-0);
  font-weight: 400;
  letter-spacing: 0.02em;
  opacity: 0.85;
}

@keyframes kill-alarm {
  0%,
  100% {
    box-shadow: 0 0 6px color-mix(in srgb, var(--orange-hot) 40%, transparent);
  }
  50% {
    box-shadow: 0 0 18px color-mix(in srgb, var(--orange-hot) 85%, transparent);
  }
}

/*
 * What the flatten has not finished closing. Red and loud until the list empties, because a
 * wipe that half-worked and looked finished is more dangerous than one that visibly failed:
 * the trader walks away believing they are flat.
 */
.pending {
  display: inline-flex;
  gap: var(--sp-1);
  align-items: center;
}

/* No list, no chrome. The container is always mounted so the each-binding has somewhere to
   render; empty it must take up nothing at all. */
.pending:empty {
  display: none;
}

.pending__inst {
  padding: 1px var(--sp-1);
  border: 1px solid var(--orange-hot);
  border-radius: var(--radius-1);
  color: var(--orange-hot);
  font-size: var(--fs-0);
  letter-spacing: 0.04em;
}

/* The pause stamp. Across the vitals, not inside them. */
.paused {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--orange);
  border-radius: var(--radius-1);
  background: color-mix(in srgb, var(--orange) 12%, transparent);
}

.paused__stamp {
  color: var(--orange);
  font-size: var(--fs-1);
  font-weight: 700;
  letter-spacing: 0.16em;
}

.paused__why {
  flex: 1;
  color: var(--ink-muted);
  font-size: var(--fs-0);
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/*
 * A blocked order. Twin animations under alternating class names: an animation on an
 * element that only changed its text never replays, so a second block against the same
 * cap would land silently — which is precisely the case where a trader needs telling
 * that the desk meant it the first time.
 */
.ticket__block {
  margin: 0;
  padding: var(--sp-1) var(--sp-2);
  border-left: 3px solid var(--orange);
  color: var(--orange);
  font-size: var(--fs-0);
  letter-spacing: 0.04em;
}

.ticket__block--0 {
  animation: block-flash-a 420ms ease-out;
}

.ticket__block--1 {
  animation: block-flash-b 420ms ease-out;
}

@keyframes block-flash-a {
  from {
    background: var(--orange);
    color: var(--ink-inverse);
  }
  to {
    background: transparent;
    color: var(--orange);
  }
}

@keyframes block-flash-b {
  from {
    background: var(--orange);
    color: var(--ink-inverse);
  }
  to {
    background: transparent;
    color: var(--orange);
  }
}

/* Reduced motion loses the pulse, never the colour: the state must still be readable
   for somebody who cannot have things flashing at them. */
@media (prefers-reduced-motion: reduce) {
  .kill--tripped,
  .ticket__block--0,
  .ticket__block--1,
  .breaker-led__dot--tripped {
    animation: none;
    /* Solid red, never nothing: the state has to stay readable for somebody who cannot
       have things flashing at them. */
    opacity: 1;
  }
}
