/* ==========================================================================
   Toasts
   ========================================================================== */
/* ---------- Toasts ----------
   A card on the app's own surface with a coloured icon chip and an accent edge, rather
   than a solid block of colour: it reads as part of the panel, stays legible in both
   themes, and leaves room for the message to actually be read. Auto-dismiss is shown by
   the progress bar and pauses while the toast is hovered or focused. */
#toast-container {
  position: fixed;
  top: 0.9rem;
  right: 0.9rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: min(24rem, calc(100vw - 1.8rem));
  pointer-events: none;
}
.toast {
  --toast-accent: var(--color-accent);
  --toast-accent-bg: var(--color-success-bg);
  --toast-accent-fg: var(--color-success-text);
  --toast-remaining: 4200ms;
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.7rem 0.75rem 0.75rem;
  overflow: hidden;
  pointer-events: auto;
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--toast-accent);
  border-radius: 14px;
  background: var(--color-surface);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16), 0 2px 6px rgba(0, 0, 0, 0.06);
  opacity: 0;
  transform: translateX(1.5rem) scale(0.97);
  transition: opacity 220ms var(--ease), transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}
.toast-show { opacity: 1; transform: translateX(0) scale(1); }
.toast-hide { opacity: 0; transform: translateX(1.5rem) scale(0.97); }

.toast-icon {
  display: grid;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  flex: none;
  border-radius: 10px;
  background: var(--toast-accent-bg);
  color: var(--toast-accent-fg);
}
.toast-icon svg {
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.toast-body { min-width: 0; padding-top: 0.1rem; }
.toast-title {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.25;
}
.toast-message {
  display: block;
  margin-top: 0.1rem;
  color: var(--color-text-muted);
  font-size: 0.79rem;
  line-height: 1.45;
  /* Server errors can be long — cap it rather than letting one toast fill the screen. */
  max-height: 5.2rem;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.toast-close {
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  flex: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--color-text-faint);
  cursor: pointer;
  transition: background var(--transition-fast) var(--ease), color var(--transition-fast) var(--ease);
}
.toast-close:hover { background: var(--color-surface-muted); color: var(--color-text); }
.toast-close svg { width: 0.8rem; height: 0.8rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

.toast-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  transform-origin: left center;
  background: var(--toast-accent);
  opacity: 0.55;
  animation: toast-countdown var(--toast-remaining) linear forwards;
}
.toast.is-paused .toast-progress { animation-play-state: paused; }
@keyframes toast-countdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

.toast-success {
  --toast-accent: var(--color-success-text);
  --toast-accent-bg: var(--color-success-bg);
  --toast-accent-fg: var(--color-success-text);
}
.toast-error {
  --toast-accent: var(--color-danger-text);
  --toast-accent-bg: var(--color-danger-bg);
  --toast-accent-fg: var(--color-danger-text);
}
.toast-warning {
  --toast-accent: var(--color-warning-text);
  --toast-accent-bg: var(--color-warning-bg);
  --toast-accent-fg: var(--color-warning-text);
}
.toast-info {
  --toast-accent: var(--color-primary);
  --toast-accent-bg: color-mix(in srgb, var(--color-primary) 13%, transparent);
  --toast-accent-fg: var(--color-primary);
}

@media (max-width: 650px) {
  #toast-container { top: auto; bottom: 0.9rem; left: 0.9rem; right: 0.9rem; width: auto; }
  .toast { transform: translateY(1.2rem) scale(0.97); }
  .toast-show { transform: translateY(0) scale(1); }
  .toast-hide { transform: translateY(1.2rem) scale(0.97); }
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity 120ms linear; transform: none; }
  .toast-show, .toast-hide { transform: none; }
  .toast-progress { animation: none; opacity: 0.3; }
}

