:root {
  --toast-bg: rgba(18, 18, 20, 0.62);
  --toast-border: rgba(255, 255, 255, 0.08);
  --toast-text: var(--text-primary, #ffffff);
  --toast-muted: var(--text-secondary, #888888);
  --toast-success: var(--success, #00cc88);
  --toast-error: var(--error, #ff4d4d);
  --toast-info: var(--accent, #008eff);
  --toast-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04), 0 12px 36px -14px rgba(0, 0, 0, 0.7), 0 4px 12px -4px rgba(0, 0, 0, 0.45);
}

.toast-stack {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 9999;
  max-width: min(320px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}

.toast {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: auto;
  max-width: 100%;
  min-width: 260px;
  box-sizing: border-box;
  padding: 15px 18px;
  background: var(--toast-bg);
  color: var(--toast-text);
  border: 1px solid var(--toast-border);
  border-radius: 14px;
  box-shadow: var(--toast-shadow);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
  font-size: 0.95rem;
  line-height: 1.45;
  pointer-events: auto;
  cursor: pointer;
  overflow: hidden;
  opacity: 0;
  transform: translate3d(110%, 0, 0) scale(0.96);
  animation: toast-in 420ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease;
}

.toast:hover {
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 16px 44px -14px rgba(0, 0, 0, 0.75),
    0 6px 16px -4px rgba(0, 0, 0, 0.5);
}

.toast-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  color: var(--toast-info);
  background: rgba(0, 142, 255, 0.12);
}

.toast-icon svg {
  width: 20px;
  height: 20px;
}

.toast.toast-success .toast-icon {
  color: var(--toast-success);
  background: rgba(0, 204, 136, 0.14);
}
.toast.toast-error .toast-icon {
  color: var(--toast-error);
  background: rgba(255, 77, 77, 0.14);
}
.toast.toast-info .toast-icon {
  color: var(--toast-info);
  background: rgba(0, 142, 255, 0.14);
}

.toast-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.toast-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--toast-text);
  letter-spacing: -0.005em;
}

.toast-message {
  color: var(--toast-text);
  font-size: 0.92rem;
  word-break: break-word;
  letter-spacing: -0.003em;
}

.toast-title + .toast-message {
  color: var(--toast-muted);
  font-size: 0.87rem;
}

.toast-close {
  display: none;
}

.toast-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: currentColor;
  color: var(--toast-info);
  transform-origin: left center;
  animation: toast-progress var(--toast-duration, 4500ms) linear forwards;
  opacity: 0.5;
}

.toast.toast-success .toast-progress {
  color: var(--toast-success);
}
.toast.toast-error .toast-progress {
  color: var(--toast-error);
}

.toast.toast-paused .toast-progress {
  animation-play-state: paused;
}

.toast.toast-leaving {
  animation: toast-out 280ms cubic-bezier(0.55, 0, 0.7, 0.2) forwards;
  pointer-events: none;
}

.toast.toast-leaving .toast-progress {
  animation: none;
  opacity: 0;
}

@keyframes toast-in {
  0% {
    opacity: 0;
    transform: translate3d(110%, 0, 0) scale(0.96);
  }
  60% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes toast-out {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate3d(120%, 0, 0) scale(0.96);
  }
}

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

@media (max-width: 540px) {
  .toast-stack {
    top: auto;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    margin-left: 0;
  }
  .toast {
    max-width: none;
  }
  @keyframes toast-in {
    0% {
      opacity: 0;
      transform: translate3d(110%, 0, 0) scale(0.96);
    }
    60% {
      opacity: 1;
    }
    100% {
      opacity: 1;
      transform: translate3d(0, 0, 0) scale(1);
    }
  }
  @keyframes toast-out {
    0% {
      opacity: 1;
      transform: translate3d(0, 0, 0) scale(1);
    }
    100% {
      opacity: 0;
      transform: translate3d(120%, 0, 0) scale(0.96);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
    opacity: 1;
    transform: none;
  }
  .toast-leaving {
    opacity: 0;
    transition: opacity 160ms ease;
    animation: none;
  }
  .toast-progress {
    animation: none;
    opacity: 0;
  }
}

.auth-alert {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 0.9rem;
  line-height: 1.45;
  border-radius: 10px;
  border: 1px solid var(--toast-border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--toast-text);
  opacity: 0;
  transform: translateY(-6px);
  animation: auth-alert-in 220ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.auth-alert > svg {
  flex-shrink: 0;
}

.auth-alert.error {
  color: var(--toast-error);
  background: rgba(255, 77, 77, 0.08);
  border-color: rgba(255, 77, 77, 0.28);
}

.auth-alert.success {
  color: var(--toast-success);
  background: rgba(0, 204, 136, 0.08);
  border-color: rgba(0, 204, 136, 0.28);
}

.auth-alert > span {
  color: inherit;
}

.auth-alert.leaving {
  animation: auth-alert-out 180ms ease forwards;
}

@keyframes auth-alert-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes auth-alert-out {
  to {
    opacity: 0;
    transform: translateY(-4px);
  }
}
