#toasts {
  position: fixed;
  top: calc(var(--topbar-h, 46px) + 14px + env(safe-area-inset-top, 0px));
  right: 14px;
  bottom: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(86vw, 356px);
  max-height: min(46vh, 420px);
  overflow: visible;
  pointer-events: none;
  z-index: 2147483000;
}

#toasts .toast {
  --toast-accent: #3b82f6;
  --toast-bg: color-mix(in srgb, #ffffff 96%, var(--toast-accent) 4%);
  --toast-border: color-mix(in srgb, var(--toast-accent) 24%, rgba(15, 23, 42, 0.12));
  --toast-title-color: #0f172a;
  --toast-msg-color: #334155;
  --toast-close-bg: color-mix(in srgb, #ffffff 84%, var(--toast-accent) 16%);
  --toast-close-border: color-mix(in srgb, var(--toast-accent) 28%, rgba(15, 23, 42, 0.12));
  --toast-close-color: color-mix(in srgb, var(--toast-accent) 72%, #0f172a 28%);
  --toast-shadow:
    0 18px 36px rgba(15, 23, 42, 0.12),
    0 6px 16px rgba(15, 23, 42, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
  min-width: 0;
  max-width: 100%;
  position: relative;
  border-radius: 18px;
  border: none;
  background: var(--toast-bg);
  color: var(--toast-title-color);
  box-shadow: var(--toast-shadow);
  outline: none;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: auto;
  overflow: hidden;
  isolation: isolate;
}

#toasts .toast::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--toast-accent);
  opacity: 0.92;
}

#toasts .toast__row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  column-gap: 10px;
  padding: 10px 10px 6px 10px;
}

#toasts .toast__icon {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  background: color-mix(in srgb, var(--toast-accent) 82%, #0f172a 18%);
  box-shadow: 0 3px 8px color-mix(in srgb, var(--toast-accent) 32%, rgba(15, 23, 42, 0.22));
}

#toasts .toast__body {
  min-width: 0;
}

#toasts .toast__close {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1px solid var(--toast-close-border);
  background: var(--toast-close-bg);
  color: var(--toast-close-color);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

#toasts .toast__close:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--toast-accent) 28%, rgba(255, 255, 255, 0.86));
  outline-offset: 2px;
}

#toasts .toast__close:hover {
  background: color-mix(in srgb, var(--toast-close-bg) 72%, var(--toast-accent) 28%);
}

#toasts .toast__close:active {
  transform: scale(0.96);
}

#toasts .toast__progress {
  height: 3px;
  margin: 0 10px 8px 10px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--toast-accent) 16%, rgba(148, 163, 184, 0.2));
}

#toasts .toast__progressbar {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: color-mix(in srgb, var(--toast-accent) 76%, rgba(2, 21, 80, 0.22));
  transform-origin: left center;
  animation: toastProgress var(--toast-duration, 4200ms) linear forwards;
}

#toasts .toast:hover .toast__progressbar {
  animation-play-state: paused;
}

#toasts .toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

#toasts .toast.hide {
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
}

#toasts .toast .title {
  font-weight: 700;
  font-size: 13px;
  line-height: 1.35;
  margin-bottom: 1px;
  color: var(--toast-title-color);
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#toasts .toast .msg {
  color: var(--toast-msg-color);
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#toasts .toast.ok {
  --toast-accent: #10b981;
  border-color: rgba(16, 185, 129, 0.34);
}

#toasts .toast.warn {
  --toast-accent: #f59e0b;
  border-color: rgba(245, 158, 11, 0.34);
}

#toasts .toast.err {
  --toast-accent: #ef4444;
  border-color: rgba(239, 68, 68, 0.36);
}

#toasts .toast.info {
  --toast-accent: #3b82f6;
  border-color: rgba(59, 130, 246, 0.34);
}

html[data-theme="dark"] #toasts .toast,
:root.theme-dark #toasts .toast,
body.theme-dark #toasts .toast {
  --toast-bg: color-mix(in srgb, #0f172a 92%, var(--toast-accent) 8%);
  --toast-border: color-mix(in srgb, var(--toast-accent) 40%, rgba(148, 163, 184, 0.34));
  --toast-title-color: #f8fafc;
  --toast-msg-color: #e2e8f0;
  --toast-close-bg: color-mix(in srgb, #111827 82%, var(--toast-accent) 18%);
  --toast-close-border: color-mix(in srgb, var(--toast-accent) 48%, rgba(148, 163, 184, 0.3));
  --toast-close-color: #f8fafc;
  --toast-shadow:
    0 20px 40px rgba(2, 6, 23, 0.4),
    0 8px 20px rgba(2, 6, 23, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) #toasts .toast,
  :root:not(.theme-light) #toasts .toast {
    --toast-bg: color-mix(in srgb, #0f172a 92%, var(--toast-accent) 8%);
    --toast-border: color-mix(in srgb, var(--toast-accent) 40%, rgba(148, 163, 184, 0.34));
    --toast-title-color: #f8fafc;
    --toast-msg-color: #e2e8f0;
    --toast-close-bg: color-mix(in srgb, #111827 82%, var(--toast-accent) 18%);
    --toast-close-border: color-mix(in srgb, var(--toast-accent) 48%, rgba(148, 163, 184, 0.3));
    --toast-close-color: #f8fafc;
    --toast-shadow:
      0 20px 40px rgba(2, 6, 23, 0.4),
      0 8px 20px rgba(2, 6, 23, 0.22),
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
  }
}

@keyframes toastProgress {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}

@media (max-width: 768px) {
  #toasts {
    left: 10px;
    right: 10px;
    width: auto;
    top: calc(var(--topbar-h, 46px) + 10px + env(safe-area-inset-top, 0px));
    max-height: min(42vh, 360px);
  }
}
