/* Toasts: the flash messages and Turbo Stream toasts in app/views/shared/_toasts.html.erb.

   Plain CSS with explicit values under #toasts, so a church website's custom CSS (which can style p, button,
   span and svg globally) can't restyle them. The font is inherited, so a public toast uses the site's typeface,
   and the church's --primary-color only colours the countdown bar. */

#toasts.toast-region {
  position: fixed;
  z-index: 110;
  top: max(0.75rem, env(safe-area-inset-top));
  left: 0;
  right: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0 0.75rem;
  pointer-events: none;
}

/* Admin: below the 48px top bar on phones, so the menu button stays usable while an error is up.
   On desktop, centred on the content beside the sidebar, expanded (15rem) or collapsed (4rem). */
#toasts.toast-region--admin { top: 3.5rem; }
@media (min-width: 1024px) {
  #toasts.toast-region--admin { top: 1rem; left: 15rem; transition: left 300ms ease; }
  [data-sidebar-collapsed-value="true"] > #toasts.toast-region--admin { left: 4rem; }
}

/* Pages without JavaScript (oauth): the toasts sit in the page flow above the content and can't be closed. */
#toasts.toast-region--static {
  position: static;
  align-items: stretch;
  margin-bottom: 1.25rem;
  padding: 0;
  pointer-events: auto;
}

#toasts > noscript { display: contents; }

/* At most three show at once. The rest wait, and their countdown doesn't start until they show. */
#toasts > .toast:nth-child(n + 4 of .toast) { display: none; }

#toasts .toast {
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  width: 100%;
  max-width: 26rem;
  margin: 0;
  padding: 0.75rem 0.5rem 0.75rem 0.875rem;
  border: 0;
  border-radius: 0.75rem;
  background: #fff;
  color: #0f172a;
  box-shadow: 0 0 0 1px rgb(15 23 42 / 0.08), 0 12px 32px -12px rgb(15 23 42 / 0.35);
  font-family: inherit;
  font-size: 0.875rem;
  font-style: normal;
  font-weight: 500;
  line-height: 1.375rem;
  letter-spacing: normal;
  text-align: left;
  text-transform: none;
  text-shadow: none;
  animation: toast-in 220ms cubic-bezier(0.2, 0.9, 0.3, 1.1);
  transition: opacity 160ms ease-in, transform 160ms ease-in;
}
#toasts .toast[data-leaving] { opacity: 0; transform: translateY(-6px) scale(0.98); }

#toasts .toast--alert {
  background: #fef2f2;
  color: #7f1d1d;
  box-shadow: 0 0 0 1px #fecaca, 0 12px 32px -12px rgb(127 29 29 / 0.35);
}

#toasts .toast .toast__icon {
  display: block;
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0.0625rem 0 0;
  fill: none;
  stroke: currentColor;
  color: #16a34a;
}
#toasts .toast--alert .toast__icon { color: #dc2626; }

#toasts .toast .toast__message {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: none;
  overflow-wrap: anywhere;
}

#toasts .toast .toast__close {
  flex: none;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  min-width: 0;
  min-height: 0;
  margin: -0.3125rem 0;
  padding: 0;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: inherit;
  font: inherit;
  opacity: 0.55;
  cursor: pointer;
  box-shadow: none;
  transform: none;
  -webkit-appearance: none;
  appearance: none;
}
#toasts .toast .toast__close:hover { opacity: 1; background: rgb(15 23 42 / 0.06); }
#toasts .toast .toast__close:focus-visible { opacity: 1; outline: 2px solid currentColor; outline-offset: 1px; }
#toasts .toast .toast__close-icon {
  display: block;
  width: 1rem;
  height: 1rem;
  margin: 0;
  fill: none;
  stroke: currentColor;
}

/* The countdown bar. Its animation's end closes the notice, so pausing it pauses the countdown. */
#toasts .toast .toast__timer {
  position: absolute;
  left: 0;
  bottom: 0;
  display: block;
  width: 100%;
  height: 3px;
  margin: 0;
  padding: 0;
  background: var(--primary-color, #16a34a);
  opacity: 0.45;
  transform-origin: left;
  animation: toast-timer var(--toast-duration, 5000ms) linear forwards;
}
#toasts .toast[data-paused] .toast__timer { animation-play-state: paused; }

@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(0.98); } }
@keyframes toast-timer { to { transform: scaleX(0); } }
@keyframes toast-fade { from { opacity: 0; } }

/* Reduced motion: fade only. The countdown bar still runs, because it shows the time left. */
@media (prefers-reduced-motion: reduce) {
  #toasts .toast { animation-name: toast-fade; }
  #toasts .toast[data-leaving] { transform: none; }
}
