/*
  Flash messages ("Saved", "Please try again", ...), used by the shop and the
  admin alike.

  They sit in a stack under the header instead of pushing the page down, so
  nothing jumps around while you read. Good news fades by itself; anything you
  may need to act on stays until you close it.
*/

.flash-stack {
    position: fixed;
    top: var(--flash-top, 5rem);
    right: 1rem;
    z-index: 60;
    width: min(24rem, calc(100vw - 2rem));
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    max-height: calc(100vh - var(--flash-top, 5rem) - 1rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    pointer-events: none;   /* the page underneath stays usable */
}

/* On a phone the message spans the screen, just under the header */
@media (max-width: 639px) {
    .flash-stack {
        top: var(--flash-top-phone, 4.5rem);
        left: 1rem;
        right: 1rem;
        width: auto;
    }
}

.flash-message {
    pointer-events: auto;
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 2.5rem 0.875rem 0.9rem;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-left: 4px solid var(--flash-accent, #111827);
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(17, 24, 39, 0.12);
    overflow: hidden;
    animation: flash-in 0.25s ease-out;
}

.flash-message[data-category="success"] {
    --flash-accent: #16a34a;
}

.flash-message[data-category="danger"],
.flash-message[data-category="error"] {
    --flash-accent: #dc2626;
}

.flash-message[data-category="warning"] {
    --flash-accent: #d97706;
}

.flash-icon {
    flex-shrink: 0;
    margin-top: 0.15rem;
    font-size: 1rem;
    color: var(--flash-accent, #111827);
}

.flash-text {
    font-size: 0.875rem;
    line-height: 1.45;
    color: #111827;
    overflow-wrap: anywhere;
}

.flash-text strong {
    font-weight: 700;
}

.flash-close {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: #9ca3af;
    font-size: 0.8rem;
    cursor: pointer;
}

.flash-close:hover,
.flash-close:focus-visible {
    color: #111827;
    background: #f3f4f6;
}

/* How long a message has left; hovering or tabbing into it holds the clock */
.flash-timer {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    background: var(--flash-accent, #111827);
    opacity: 0.5;
    transform-origin: left center;
    animation: flash-timer linear forwards;
}

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

.flash-message.is-going {
    animation: flash-out 0.2s ease-in forwards;
}

@keyframes flash-in {
    from {
        opacity: 0;
        transform: translateY(-0.5rem);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes flash-out {
    to {
        opacity: 0;
        transform: translateX(1.25rem);
    }
}

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

    to {
        transform: scaleX(0);
    }
}

/* Some people set their device to keep movement to a minimum */
@media (prefers-reduced-motion: reduce) {

    .flash-message,
    .flash-message.is-going {
        animation: none;
    }

    .flash-timer {
        animation-duration: 0.01ms;
    }
}

/* Printing a page should not carry a "Saved" bubble onto the paper */
@media print {
    .flash-stack {
        display: none;
    }
}
