/*
 * Banners: a message filled with its role's color, green for a notice and
 * red with data-variant="alert" for an error. Floating at the top of the
 * page in .toasts, banners are the app's flash messages, dismissing
 * themselves (flash Stimulus controller) or with their dismiss button.
 *
 *   <div class="toasts stack" data-space="2">
 *     <div class="banner" role="status" data-controller="flash">
 *       <p>Saved</p>
 *       <button type="button" class="banner__dismiss" aria-label="Dismiss">×</button>
 *     </div>
 *   </div>
 *
 *   <p class="banner" data-variant="alert" role="alert">Couldn't scan</p>
 */
@layer components {
  .banner {
    --banner-bg: var(--color-success);
    --banner-fg: var(--color-on-success);

    position: relative;
    padding: var(--space-4);
    background: var(--banner-bg);
    color: var(--banner-fg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-overlay);

    &[data-variant="alert"] {
      --banner-bg: var(--color-danger);
      --banner-fg: var(--color-on-danger);
    }

    /* Keep the message clear of the dismiss button in the corner */
    &:has(> .banner__dismiss) { padding-inline-end: 3rem; }
  }

  /* A 44px target in the corner, so the × sits near the edge */
  .banner__dismiss {
    position: absolute;
    inset-block-start: var(--space-1);
    inset-inline-end: 0;
    inline-size: 2.75rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: inherit;
    font-size: var(--text-lg);
    line-height: 1;
    opacity: 0.7;
    cursor: pointer;
    transition: opacity var(--duration-fast), background-color var(--duration-fast);

    &:hover { opacity: 1; background: oklch(100% 0 0 / 0.1); }
  }

  /* The region floating banners stack in, over the top of the page */
  .toasts {
    position: fixed;
    inset-block-start: var(--space-4);
    inset-inline: var(--space-4);
    z-index: 2000;

    & > .banner { transition: translate var(--duration-base) ease-out, opacity var(--duration-base) ease-out; }

    & > .banner[data-dismissing] { translate: 0 -100%; opacity: 0; }
  }
}
