.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(396px, calc(100vw - 40px));
  pointer-events: none;
}

.toast {
  --toast-accent: var(--color-primary);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  padding: 16px 16px 19px 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  background: var(--color-card);
  box-shadow: var(--shadow-dashboard);
  overflow: hidden;
  pointer-events: auto;
  animation: toast-in 0.42s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast--success { --toast-accent: var(--color-success); }
.toast--error { --toast-accent: var(--color-danger); }
.toast--warning { --toast-accent: var(--color-warning); }
.toast--info { --toast-accent: var(--color-primary); }

.toast__icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--toast-accent);
  background: color-mix(in srgb, var(--toast-accent) 13%, #FFFFFF);
}

.toast__body {
  min-width: 0;
  padding-top: 1px;
}

.toast__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-heading);
}

.toast__text {
  margin: 4px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-body-dark);
  overflow-wrap: anywhere;
}

.toast__close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: -4px -6px 0 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.toast__close:hover {
  background: var(--color-section);
  color: var(--color-heading);
}

.toast__close:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.toast__progress {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 3px;
  background: var(--toast-accent);
  opacity: 0.6;
  transform-origin: left center;
  animation: toast-timer var(--toast-duration, 5500ms) linear forwards;
}

.toast:hover .toast__progress {
  animation-play-state: paused;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateX(24px) scale(0.98);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(28px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

.toast-stack--below-header {
  top: calc(var(--header-height) + 12px);
}

@media (max-width: 640px) {
  .toast-stack {
    top: 12px;
    right: 12px;
    left: 12px;
    width: auto;
  }

  .toast-stack--below-header {
    top: calc(var(--header-height) + 8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
    transition: none;
  }

  .toast__progress {
    animation: none;
  }
}
