/* The toast region: bottom right, never over the sidebar and its account menu, and no wider than a short sentence;
   on a phone it stops above the bottom tab bar (toast_region_controller.js measures it). The region is a manual
   popover, so the browser's popover box is undone. */
.wi-toast-region,
.wi-toast-region[popover] {
  position: fixed;
  z-index: var(--z-index-toast);
  inset: auto var(--space-4) calc(var(--wi-bottom-tab-bar-height, env(safe-area-inset-bottom, 0px)) + var(--space-4)) auto;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: var(--space-2);
  box-sizing: border-box;
  width: max-content;
  max-width: min(calc(100% - var(--space-8)), 26rem);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  overflow: visible;
  pointer-events: none;
}

.wi-toast-region:focus-visible {
  border-radius: var(--radius-lg);
  box-shadow: var(--focus-ring);
  outline: none;
}

/* One line on the dark background: the tone's icon, the page's icon and name, then the message, with a thin line along
   the bottom, the countdown, the toast's life (none for a danger, which stays until it is closed). */
.wi-toast {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  box-sizing: border-box;
  max-width: 100%;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-lg);
  background-color: var(--background-inverse);
  color: var(--text-primary-inverse);
  font-family: var(--font-family-sans);
  font-size: var(--font-size-sm);
  line-height: var(--font-line-height-sm);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  pointer-events: auto;
  animation: wi-toast-in 0.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.wi-toast--success { --wi-toast-tone: var(--green-400); }
.wi-toast--danger { --wi-toast-tone: var(--red-300); }
.wi-toast--warning { --wi-toast-tone: var(--amber-300); }

.wi-toast:focus-visible {
  box-shadow: var(--shadow-lg), var(--focus-ring-inverse);
  outline: none;
}

.wi-toast[data-closing] {
  animation: wi-toast-out 0.16s ease-in both;
}

.wi-toast__icon {
  width: var(--size-icon-md);
  height: var(--size-icon-md);
  color: var(--wi-toast-tone);
  flex-shrink: 0;
}

.wi-toast__content {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.wi-toast .wi-toast__close {
  --wi-btn-height-sm: var(--size-icon-xl);
  --wi-btn-radius: var(--radius-full);
  color: var(--text-primary-inverse);
  flex-shrink: 0;
  margin-inline-end: calc(var(--space-2) * -1);
  text-decoration: none;
}

.wi-toast .wi-toast__close > svg {
  width: var(--size-icon-sm);
  height: var(--size-icon-sm);
}

.wi-toast .wi-toast__close[data-hovered] {
  background-color: var(--background-raised-inverse);
}

.wi-toast .wi-toast__close[data-pressed] {
  background-color: var(--background-raised-inverse-hover);
  color: var(--text-primary-inverse);
}

.wi-toast .wi-toast__close[data-focus-visible] {
  box-shadow: var(--focus-ring-inverse);
}

/* The time left, and the toast's clock: toast_controller.js closes the toast when this animation ends, and gives
   its duration (--wi-toast-duration); held, it waits, and so does the toast. */
.wi-toast__countdown {
  position: absolute;
  inset: auto 0 0 0;
  height: calc(var(--border-1) * 3);
  background-color: var(--wi-toast-tone);
  opacity: 0.7;
  transform-origin: left center;
}

/* Only once toast_controller.js has connected: the animation's end closes the toast, so it must not start before. */
.wi-toast[data-toast-countdown] .wi-toast__countdown {
  animation: wi-toast-countdown var(--wi-toast-duration) linear both;
}

.wi-toast:hover .wi-toast__countdown,
.wi-toast:focus-within .wi-toast__countdown {
  animation-play-state: paused;
}

@keyframes wi-toast-in {
  from { opacity: 0; transform: translateY(var(--space-2)); }
  to { opacity: 1; transform: none; }
}

@keyframes wi-toast-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateX(var(--space-4)); }
}

@keyframes wi-toast-countdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* For a person who asks for less motion: the countdown stays still and faint, and still ends the toast's time. */
@keyframes wi-toast-countdown-still {
  from { opacity: 0.3; }
  to { opacity: 0.3; }
}

@media (prefers-reduced-motion: reduce) {
  .wi-toast,
  .wi-toast[data-closing] {
    animation: none;
  }

  .wi-toast[data-toast-countdown] .wi-toast__countdown {
    animation-name: wi-toast-countdown-still;
  }
}
