/* ============================================================
   TOAST SYSTEM — Bridge platform
   Bottom-center, status-aware, inverse-surface

   A toast floats over the page, so it is the opposite tone of the page in
   both themes: a warm mid-dark surface on the light canvas, an off-white
   card in dark mode. Everything inside it is paired to that surface rather
   than to the page theme, which is what the --toast-* tokens in input.css
   encode. Do not reach for --color-* tokens in here: they follow the page,
   and mixing the two is what left a #0d3825 disc sitting on a white card.
   ============================================================ */

/* Region: bottom-center, stacked.
   Uses Popover API (popover="manual") so the region renders in the browser
   top layer, escaping any open <dialog>::backdrop which otherwise wins
   regardless of z-index. */
.toast-region,
.toast-region:popover-open {
  position: fixed;
  inset: auto;
  top: auto;
  left: 50%;
  right: auto;
  bottom: 28px;
  transform: translateX(-50%);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  z-index: var(--z-toast, 9999);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: min(420px, calc(100vw - 32px));
}

/* Base toast (Rich variant default) */
.toast {
  pointer-events: auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 12px 16px;
  /* Width is owned by .toast-region (max-width: min(420px, 100vw - 32px)).
     The toast fills that width; min-width keeps short messages from
     collapsing, but never exceeds the region on narrow viewports. */
  width: 100%;
  min-width: min(280px, 100%);
  border-radius: 18px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--toast-fg);
  background: var(--toast-surface);
  /* No border and no backdrop-filter: the surface is opaque and carries a
     tone the page does not, so a border has nothing to add and a blur has
     nothing to blur. The shadow only lifts the card; it is not what makes
     it visible. */
  border: 0;
  box-shadow: var(--toast-shadow);
  animation: toast-in 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
  will-change: transform, opacity;
  overflow: hidden;
}

.toast.is-leaving {
  animation: toast-out 200ms cubic-bezier(0.4, 0, 1, 1) both;
}

/* Rail behind the auto-dismiss bar. Without it the bar shows how much time
   is left but not how much of the total that is, so it reads as a stray
   line rather than as progress. */
.toast::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--toast-track);
  pointer-events: none;
}

/* Icon container */
.toast-icon {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}

/* Override the global svg sizing rule (components.css sets svg to 1.5rem). */
.toast .toast-icon svg {
  width: 14px;
  height: 14px;
}

.toast .toast-close svg {
  width: 13px;
  height: 13px;
}

.toast-body {
  flex: 1 1 auto;
  min-width: 0;
}

.toast-title {
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
}

.toast-msg {
  margin-top: 1px;
  font-size: 12.5px;
  color: var(--toast-fg-muted);
}

/* Close button */
.toast-close {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--toast-close);
  border-radius: 8px;
  cursor: pointer;
  margin: 0 -4px 0 4px;
  transition:
    color 140ms ease,
    background 140ms ease;
}

.toast-close:hover {
  color: var(--toast-fg);
  background: var(--toast-close-hover-bg);
}

/* Status colors (icon disc + progress bar).
   The disc is a solid accent with the glyph punched out of it, so the glyph
   takes its contrast from the disc rather than from the surface. A tinted
   translucent disc lands within a few points of the surface and dissolves. */
.toast[data-status="success"] {
  --toast-accent: var(--toast-accent-success);
}

.toast[data-status="info"] {
  --toast-accent: var(--toast-accent-info);
}

.toast[data-status="warning"] {
  --toast-accent: var(--toast-accent-warning);
}

.toast[data-status="error"] {
  --toast-accent: var(--toast-accent-error);
}

.toast .toast-icon {
  background: var(--toast-accent, var(--toast-accent-info));
  color: var(--toast-accent-on);
}

/* Auto-dismiss progress bar */
.toast-progress {
  position: absolute;
  left: 0;
  right: 0;
  /* Flush with the bottom edge, not one pixel past it: the corner radius
     clips anything that overhangs, which made the bar read shorter than
     the toast is wide. */
  bottom: 0;
  height: 3px;
  transform-origin: right center;
  animation: toast-progress var(--toast-duration, 4000ms) linear forwards;
  background: var(--toast-accent, var(--toast-accent-info));
  pointer-events: none;
}

.toast:hover .toast-progress,
.toast:focus-within .toast-progress {
  animation-play-state: paused;
}

/* Compact variant (single-line confirmation) */
.toast.toast-compact {
  min-width: 0;
  padding: 10px 8px 10px 12px;
  gap: 10px;
  border-radius: 999px;
}

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

.toast.toast-compact .toast-icon svg,
.toast.toast-compact .toast-close svg {
  width: 11px;
  height: 11px;
}

.toast.toast-compact .toast-title {
  font-size: 13px;
  font-weight: 550;
  letter-spacing: -0.005em;
}

.toast.toast-compact .toast-close {
  width: 20px;
  height: 20px;
  margin: 0 2px 0 -2px;
}

/* Animations */
@keyframes toast-in {
  0% {
    opacity: 0;
    transform: translateY(24px) scale(0.92);
  }
  60% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .toast,
  .toast.is-leaving {
    animation-duration: 1ms !important;
  }
  /* The rail exists to give the bar a track; with the bar gone it would be
     a stray line, so both go. */
  .toast-progress,
  .toast::before {
    display: none;
  }
}
