/* ============================================================
   TOAST SYSTEM — Bridge platform
   Glassmorphic, bottom-center, status-aware
   ============================================================ */

/* 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;
  min-width: 280px;
  max-width: 420px;
  border-radius: 18px;
  font-size: 13px;
  line-height: 1.45;
  color: #0f172a;
  background: var(--color-white);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 1px 2px rgba(15, 23, 42, 0.06),
    0 8px 24px -8px rgba(15, 23, 42, 0.18),
    0 24px 56px -16px rgba(15, 23, 42, 0.22);
  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;
}

/* 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: #64748b;
}

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

.toast-close:hover {
  color: #0f172a;
  background: rgba(15, 23, 42, 0.06);
}

/* Status colors (icon container + progress bar) */
.toast[data-status="success"] .toast-icon {
  background: var(--color-success-light);
  color: var(--color-success-dark);
  box-shadow: 0 1px 2px rgba(16, 185, 129, 0.18);
}

.toast[data-status="info"] .toast-icon {
  background: var(--color-info-light);
  color: var(--color-info-dark);
  box-shadow: 0 1px 2px rgba(96, 165, 250, 0.2);
}

.toast[data-status="warning"] .toast-icon {
  background: var(--color-warning-light);
  color: var(--color-warning-dark);
  box-shadow: 0 1px 2px rgba(251, 191, 36, 0.25);
}

.toast[data-status="error"] .toast-icon {
  background: var(--color-error-light);
  color: var(--color-error-dark);
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.2);
}

/* Auto-dismiss progress bar */
.toast-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  transform-origin: right center;
  animation: toast-progress var(--toast-duration, 4000ms) linear forwards;
  opacity: 0.6;
  pointer-events: none;
}

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

.toast[data-status="success"] .toast-progress {
  background: var(--color-success-dark);
}
.toast[data-status="info"] .toast-progress {
  background: var(--color-info-dark);
}
.toast[data-status="warning"] .toast-progress {
  background: var(--color-warning-dark);
}
.toast[data-status="error"] .toast-progress {
  background: var(--color-error-dark);
}

/* 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;
  white-space: nowrap;
}

.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;
  }
  .toast-progress {
    display: none;
  }
}
