/* Flash messages.

   These used to be a DaisyUI `.alert` row rendered inline at the top of
   `.content`, which pushed the whole page down by its own height the moment a
   view left a message behind - the reader's eye was already on the content, so
   the news arrived by shoving it. They are toasts now: they sit over the page
   under the navbar, say their piece, and time out on their own. */

.flash-stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  left: 50%;
  /* Below the sticky navbar (h-14). Pages without one - the exam shell - pass
     their own offset in. */
  max-height: calc(100vh - var(--flash-top, 4rem) - 1rem);
  max-width: min(30rem, calc(100vw - 1.5rem));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.25rem;
  pointer-events: none;
  position: fixed;
  top: var(--flash-top, 4rem);
  transform: translateX(-50%);
  width: 100%;
  /* Over the drawers (60) and their handles (70), under the confirm dialog,
     which is a top-layer <dialog> and so above all of this regardless. */
  z-index: 80;
}

.flash {
  align-items: flex-start;
  background-color: #fffdf7;
  border: 1px solid var(--flash-edge, #e3dac2);
  border-radius: 0.75rem;
  box-shadow: 0 10px 30px rgba(58, 52, 20, 0.18);
  color: #3a3428;
  display: flex;
  gap: 0.7rem;
  overflow: hidden;
  padding: 0.85rem 0.9rem;
  pointer-events: auto;
  position: relative;
}

/* Entrance. The stack is fixed at the top, so a toast comes down out of the
   bar rather than in from a corner nothing else on the page uses. */
.flash {
  animation: flash-in 0.22s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes flash-in {
  from {
    opacity: 0;
    transform: translateY(-0.7rem) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Leaving collapses the row as well as fading it, so the toasts below it walk
   up rather than jumping. */
.flash.is-leaving {
  margin-top: calc(-1 * var(--flash-height, 0px) - 0.6rem);
  opacity: 0;
  transform: translateY(-0.4rem);
  transition: opacity 0.14s ease, transform 0.14s ease, margin-top 0.18s ease 0.04s;
}

.flash__icon {
  align-items: center;
  background-color: var(--flash-tint, #f2ead6);
  border-radius: 999px;
  color: var(--flash-ink, #4e0d0d);
  display: flex;
  flex: 0 0 auto;
  font-size: 0.95rem;
  height: 1.85rem;
  justify-content: center;
  width: 1.85rem;
}

.flash__text {
  flex: 1 1 auto;
  font-size: 0.98rem;
  line-height: 1.5;
  /* A cleared-records message names a title that can run long and hold no
     spaces to break at. */
  overflow-wrap: anywhere;
  padding-top: 0.2rem;
}

.flash__close {
  background: none;
  border: none;
  border-radius: 0.5rem;
  color: #8a7a6a;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0.4rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.flash__close:hover {
  background-color: rgba(78, 13, 13, 0.07);
  color: #4e0d0d;
}

.flash__close:focus-visible {
  outline: 2px solid var(--flash-ink, #4e0d0d);
  outline-offset: 1px;
}

/* How long is left, drawn rather than counted down in script: hovering the
   toast pauses the animation, and the same pause holds the dismissal, so the
   bar and the timer can never disagree. */
.flash__timer {
  animation: flash-timer var(--flash-life, 5s) linear forwards;
  background-color: var(--flash-ink, #4e0d0d);
  bottom: 0;
  height: 3px;
  left: 0;
  opacity: 0.45;
  position: absolute;
  transform-origin: left center;
  width: 100%;
}

@keyframes flash-timer {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

.flash:hover .flash__timer,
.flash:focus-within .flash__timer {
  animation-play-state: paused;
}

.flash--success {
  --flash-edge: #cfe1d3;
  --flash-ink: #35603f;
  --flash-tint: #e8f2ea;
}

.flash--error {
  --flash-edge: #e6c9c9;
  --flash-ink: #9b2c2c;
  --flash-tint: #fbeceb;
}

.flash--warning {
  --flash-edge: #e8d7a8;
  --flash-ink: #8a5a12;
  --flash-tint: #fbf1da;
}

.flash--info {
  --flash-edge: #dccfb0;
  --flash-ink: #4e0d0d;
  --flash-tint: #f4ecd9;
}

@media (max-width: 640px) {
  .flash-stack {
    max-width: none;
    padding: 0.25rem 0.5rem;
  }

  .flash {
    padding: 0.75rem 0.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flash {
    animation-duration: 0.01ms;
  }

  .flash.is-leaving {
    transition-duration: 0.01ms;
  }

  /* The bar still has to run - it is the timer, not decoration - but it moves
     as one step per second rather than continuously. */
  .flash__timer {
    animation-timing-function: steps(8, end);
  }
}
