/* Floating toast notifications */
.toast-stack {
  position: fixed;
  top: max(20px, env(safe-area-inset-top, 0px));
  right: max(20px, env(safe-area-inset-right, 0px));
  z-index: 10050;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: hidden;
  pointer-events: none;
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 14px 44px 14px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--toast-bg);
  color: var(--toast-fg);
  box-shadow:
    0 12px 40px rgba(15, 23, 42, 0.12),
    0 4px 12px rgba(15, 23, 42, 0.08);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(24px);
  transition:
    opacity 0.28s ease,
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

html.dark .toast {
  box-shadow:
    0 16px 48px rgba(0, 0, 0, 0.45),
    0 4px 12px rgba(0, 0, 0, 0.25);
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(0);
}

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

.toast__icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1;
}

.toast__message {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.5;
  word-break: break-word;
}

.toast__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  opacity: 0.55;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.toast__close:hover {
  opacity: 1;
  background: rgba(15, 23, 42, 0.06);
}

html.dark .toast__close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.toast--success {
  border-color: rgba(16, 185, 129, 0.35);
  background: linear-gradient(135deg, rgba(209, 250, 229, 0.98), rgba(255, 255, 255, 0.98));
  color: #065f46;
}

html.dark .toast--success {
  background: linear-gradient(135deg, rgba(6, 78, 59, 0.92), rgba(17, 24, 39, 0.95));
  color: #bbf7d0;
  border-color: rgba(16, 185, 129, 0.4);
}

.toast--success .toast__icon {
  background: rgba(16, 185, 129, 0.2);
  color: #059669;
}

.toast--error {
  border-color: rgba(220, 38, 38, 0.35);
  background: linear-gradient(135deg, rgba(254, 226, 226, 0.98), rgba(255, 255, 255, 0.98));
  color: #991b1b;
}

html.dark .toast--error {
  background: linear-gradient(135deg, rgba(127, 29, 29, 0.88), rgba(17, 24, 39, 0.95));
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.4);
}

.toast--error .toast__icon {
  background: rgba(220, 38, 38, 0.15);
  color: #dc2626;
}

.toast--warning {
  border-color: rgba(217, 119, 6, 0.4);
  background: linear-gradient(135deg, rgba(254, 243, 199, 0.98), rgba(255, 255, 255, 0.98));
  color: #92400e;
}

html.dark .toast--warning {
  background: linear-gradient(135deg, rgba(120, 53, 15, 0.88), rgba(17, 24, 39, 0.95));
  color: #fde68a;
  border-color: rgba(245, 158, 11, 0.4);
}

.toast--warning .toast__icon {
  background: rgba(217, 119, 6, 0.18);
  color: #d97706;
}

.toast--info {
  border-color: rgba(37, 99, 235, 0.35);
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.98), rgba(255, 255, 255, 0.98));
  color: #1e40af;
}

html.dark .toast--info {
  background: linear-gradient(135deg, rgba(30, 58, 138, 0.88), rgba(17, 24, 39, 0.95));
  color: #bfdbfe;
  border-color: rgba(59, 130, 246, 0.4);
}

.toast--info .toast__icon {
  background: rgba(37, 99, 235, 0.15);
  color: #2563eb;
}

@media (max-width: 640px) {
  .toast-stack {
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    width: auto;
    align-items: stretch;
  }

  .toast {
    transform: translateY(-12px);
  }

  .toast.is-visible {
    transform: translateY(0);
  }

  .toast.is-leaving {
    transform: translateY(-8px);
  }
}
