.toasts {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-3));
  right: var(--space-5);
  z-index: var(--z-toast);          
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(380px, calc(100vw - var(--space-5) * 2));
  pointer-events: none;             
}

.toast {
  pointer-events: auto;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  overflow: hidden;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  border-left: 3px solid var(--toast-accent, var(--toast-info));
}

.toast--success { --toast-accent: var(--toast-success); }
.toast--error   { --toast-accent: var(--toast-error); }
.toast--info    { --toast-accent: var(--toast-info); }

.toast__icon {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--toast-accent, var(--toast-info));
}

.toast__message {
  margin: 0;
  color: var(--text-primary);
  overflow-wrap: anywhere;          
}

.toast__close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-silk),
              background var(--dur-fast) var(--ease-silk);
}
.toast__close:hover { color: var(--text-primary); background: var(--bg-elevated); }
.toast__close:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }
.toast__close .icon { width: 14px; height: 14px; }

.toast__timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  transform-origin: left center;
  background: var(--toast-accent, var(--toast-info));
  opacity: 0.55;
  animation: toast-timer var(--toast-remaining, 5000ms) linear forwards;
}
.toast--paused .toast__timer { animation-play-state: paused; }

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

.toast--in  { animation: toast-in  var(--dur-normal) var(--ease-spring) both; }
.toast--out { animation: toast-out var(--dur-fast)   var(--ease-silk)  both; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px) scale(0.98); }
  to   { opacity: 1; transform: translateX(0)    scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0)    scale(1); }
  to   { opacity: 0; transform: translateX(16px) scale(0.98); }
}

@media (max-width: 640px) {
  .toasts {
    top: calc(var(--topbar-h) + var(--space-2));
    right: var(--space-3);
    left: var(--space-3);
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast--in,
  .toast--out,
  .toast__timer {
    animation: none;
  }
  .toast__timer { display: none; }
}

@supports not (backdrop-filter: blur(1px)) {
  .toast { background: var(--surface-solid); }
}
