/* =========================
   Toasts – Tokens
   ========================= */
:root {
  --toast-radius: 14px;
  --toast-shadow: 0 12px 28px rgba(0,0,0,.22);
  --toast-border: rgba(255,255,255,.18);
  --toast-glass: blur(10px);

  /* gradients */
  --info-1: #0a66c2;   --info-2: #4fc3f7;
  --ok-1:   #28a745;   --ok-2:   #60d394;
  --err-1:  #dc3545;   --err-2:  #ff6b6b;
  --warn-1: #ffc107;   --warn-2: #ffb347;

  /* ink */
  --toast-ink: #ffffff;
  --toast-muted: rgba(255,255,255,.82);

  /* progress */
  --bar-bg: rgba(255,255,255,.28);
  --bar-fg: #ffffff;

  /* container gap/margins */
  --toast-gap: 12px;
  --toast-pad-block: 16px;
  --toast-pad-inline: 18px;
}

/* Dark mode */
:root[data-theme="dark"], .theme-dark {
  --toast-shadow: 0 14px 32px rgba(0,0,0,.45);
  --toast-border: rgba(255,255,255,.14);
  --toast-muted: rgba(255,255,255,.86);

  --info-1: #0b4e96;   --info-2: #3aa6e6;
  --ok-1:   #1f8e3a;   --ok-2:  #48c67e;
  --err-1:  #b52b39;   --err-2: #f25562;
  --warn-1: #e1a807;   --warn-2: #ffae3a;
}

/* =========================
   Full-screen Screen-Lock Overlay
   ========================= */

body.toast-screen-locked {
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
}

#toast-screen-blocker {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6); /* slate-900 w/ opacity */
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);

  /* ⬆️ Highest z we can reasonably use */
  z-index: 2147483647;

  display: flex;
  align-items: center;   /* vertical center */
  justify-content: center; /* horizontal center */

  pointer-events: none;
  opacity: 0;
  transition: opacity .22s ease;
}

#toast-screen-blocker.is-active {
  opacity: 1;
  pointer-events: auto; /* block all clicks under it */
}

.toast-blocker-inner {
  min-width: 260px;
  max-width: 360px;
  padding: 18px 20px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(148, 163, 184, .6);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.55);

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;

  color: #e5e7eb;
  text-align: center;
  font-size: 14px;
}

/* Spinner */
.toast-blocker-spinner {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 3px solid rgba(148, 163, 184, 0.45);
  border-top-color: #60a5fa;
  animation: toast-spin 0.8s linear infinite;
}

.toast-blocker-text {
  font-weight: 600;
}

@keyframes toast-spin {
  to { transform: rotate(360deg); }
}

/* Progress inside blocker */
.toast-blocker-progress {
  width: 100%;
  margin-top: 6px;
  height: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.35); /* slate-400-ish */
  overflow: hidden;
}

.toast-blocker-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    #60a5fa 0%,
    #22c55e 50%,
    #a855f7 100%
  );
  transform-origin: left center;
  transition: width .25s ease;
}

.toast-blocker-subtext {
  margin-top: 4px;
  font-size: 12px;
  color: rgba(209, 213, 219, 0.9); /* light gray */
}

/* =========================
   Complete state (subtle, not full-screen green)
   ========================= */

#toast-screen-blocker.is-complete {
  /* Slightly warmer/dimmer but still full overlay */
  background: rgba(15, 23, 42, 0.7);
}

#toast-screen-blocker.is-complete .toast-blocker-inner {
  background: rgba(6, 78, 59, 0.92); /* teal/emerald panel */
  border-color: rgba(52, 211, 153, 0.9);
  box-shadow: 0 18px 45px rgba(16, 185, 129, 0.45);
  transform: translateY(0);
  transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
}

#toast-screen-blocker.is-complete .toast-blocker-spinner {
  display: none; /* hide spinner on completion */
}

#toast-screen-blocker.is-complete .toast-blocker-progress {
  opacity: 0.9;
}

#toast-screen-blocker.is-complete .toast-blocker-text {
  font-size: 1.05rem;
  font-weight: 600;
}

/* Optional “error” full-screen variant if you ever use it */
#toast-screen-blocker.is-error .toast-blocker-inner {
  background: rgba(127, 29, 29, 0.95);
  border-color: rgba(248, 113, 113, 0.9);
  box-shadow: 0 18px 45px rgba(248, 113, 113, 0.4);
}

/* Mobile: still centered */
@media (max-width: 640px) {
  #toast-screen-blocker {
    justify-content: center;
    align-items: center;
  }

  .toast-blocker-inner {
    max-width: 92vw;
  }
}

/* =========================
   Container (Right Edge, fixed & scrollable)
   ========================= */

#toast-container {
  position: fixed !important;
  top: 16px !important;
  right: 24px !important;

  /* Just under blocker so blocker always wins */
  z-index: 2147483646 !important;

  display: flex;
  flex-direction: column;
  gap: var(--toast-gap);
  pointer-events: none;
  width: min(420px, 92vw);

  /* Make the right column stay in view and scroll if too many toasts */
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding-bottom: 4px;

  /* Optional: nice scrollbars */
  scrollbar-width: thin;
}

/* Tablet optimization */
@media (max-width: 1024px) {
  #toast-container {
    right: 18px !important;
    top: 16px !important;
    max-height: calc(100vh - 32px);
  }
}

/* MOBILE optimization — center horizontally but still fixed to viewport */
@media (max-width: 480px) {
  #toast-container {
    top: 12px !important;
    right: 12px !important;
    left: 12px !important;
    width: auto !important;
    max-height: calc(100vh - 24px);
  }
}

/* =========================
   Toast base
   ========================= */
.toast {
  --grad-a: var(--info-1);
  --grad-b: var(--info-2);

  background: linear-gradient(90deg, var(--grad-a), var(--grad-b));
  color: var(--toast-ink);
  border: 1px solid var(--toast-border);
  border-radius: var(--toast-radius);
  box-shadow: var(--toast-shadow);
  padding: var(--toast-pad-block) var(--toast-pad-inline);
  min-width: 280px;
  max-width: 100%;
  font-size: 15px;
  line-height: 1.35;

  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 10px 12px;

  pointer-events: auto;
  opacity: 0;
  transform: translate3d(40px,0,0) scale(.98);
  filter: saturate(1.02);
  backdrop-filter: var(--toast-glass);
  -webkit-backdrop-filter: var(--toast-glass);
}

/* Content */
.toast__icon   { font-size: 18px; line-height: 1; margin-top: 2px; opacity: .95; }
.toast__title  { font-weight: 700; margin: 0; }
.toast__body   { opacity: .95; color: var(--toast-muted); }
.toast__title + .toast__body { margin-top: 2px; }

/* Close button */
.toast__close {
  margin-left: 6px;
  border: 0;
  background: transparent;
  color: var(--toast-ink);
  opacity: .82;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px;
}
.toast__close:hover { opacity: 1; }

.toast__actions {
  grid-column: 2 / span 2;
  display: inline-flex;
  gap: 8px;
}
.toast__action-btn {
  appearance: none;
  font-size: 13px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.35);
  color: var(--toast-ink);
  background: rgba(255,255,255,.08);
  cursor: pointer;
}
.toast__action-btn:hover { background: rgba(255,255,255,.14); }

/* Animations */
.toast.show {
  animation: toast-in .35s cubic-bezier(.2,.8,.2,1) forwards;
}
.toast.hide {
  animation: toast-out .26s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate3d(40px,0,0) scale(.98); }
  to   { opacity: 1; transform: translate3d(0,0,0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translate3d(20px,0,0) scale(.98); }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .toast, .toast.show, .toast.hide { 
    animation: none !important; 
    transform: none !important; 
    opacity: 1; 
  }
}

/* Variants */
.toast.success { --grad-a: var(--ok-1);   --grad-b: var(--ok-2); }
.toast.error   { --grad-a: var(--err-1);  --grad-b: var(--err-2); }
.toast.warning { --grad-a: var(--warn-1); --grad-b: var(--warn-2); }
.toast.loading { --grad-a: var(--info-1); --grad-b: var(--info-2); }

.toast--solid { backdrop-filter: none; -webkit-backdrop-filter: none; }

/* Message row */
.toast-message {
  grid-column: 2 / span 1;
  display: flex;
  align-items: center;
  gap: 10px;
  word-break: break-word;
  font-weight: 600;
}
.toast .toast-message { color: var(--toast-ink); }

/* Progress bar (legacy, if you ever use inside toast) */
.toast-progress {
  grid-column: 1 / -1;
  width: 100%;
  height: 4px;
  background: var(--bar-bg);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--bar-fg);
  width: var(--progress, 0%);
  transform-origin: left center;
  transition: width .25s ease;
}

/* Loading shimmer */
.toast.loading .progress-bar {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,.0) 0%,
    rgba(255,255,255,.9) 50%,
    rgba(255,255,255,.0) 100%
  );
  background-size: 200% 100%;
  animation: barber 1.25s linear infinite;
}
@keyframes barber {
  to { background-position: -200% 0; }
}

/* Depth / stacking polish */
#toast-container .toast:nth-child(2)  { transform: translate3d(32px,0,0) scale(.995); }
#toast-container .toast:nth-child(3)  { transform: translate3d(24px,0,0) scale(.992); }
#toast-container .toast:nth-child(4)  { transform: translate3d(16px,0,0) scale(.989); }
#toast-container .toast:nth-child(n+5) { opacity: .92; }

#toast-container .toast.show { transform: none; }

/* Compact / Inline */
.toast--compact {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  grid-template-columns: auto 1fr auto;
}
.toast--inline {
  position: static;
  width: auto;
  box-shadow: none;
  border: 1px solid var(--toast-border);
}