/* ============================================================
   TOAST NOTIFICATIONS — drop-in component (giixi)
   Source design: design-pkg/live-roi/project/Toasts.html
   Used everywhere: Django messages, JS notifications, errors.

   NOTE: Every rule is scoped under `.toast-stack` so that
   Bootstrap 5's own `.toast` class (which sets display:none
   and a fixed width on bare `.toast`) cannot override us.
   ============================================================ */
:root {
  /* Toast kind colors — fall through to defaults if site doesn't define */
  --toast-success: #5eb985;
  --toast-error:   #e0664f;
  --toast-warning: #e8a33d;
  --toast-info:    var(--info, #3B82F6);
}

/* ---------- Toast stack (fixed positioner) ---------- */
.toast-stack {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 380px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

/* ---------- Single toast ---------- */
.toast-stack .toast {
  --toast-color: var(--toast-info);
  pointer-events: auto;
  position: relative;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: var(--panel-2, #202023);
  border: 1px solid var(--line-2, #35353a);
  border-radius: 12px;
  box-shadow:
    0 16px 40px -8px rgba(0, 0, 0, 0.55),
    0 2px 6px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  animation: toast-in .32s cubic-bezier(.2, .9, .3, 1.2);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text, #ececee);
  width: auto;
  max-width: 100%;
  min-height: 0;
  opacity: 1;
}
.toast-stack .toast--success { --toast-color: var(--toast-success); }
.toast-stack .toast--error   { --toast-color: var(--toast-error);   }
.toast-stack .toast--warning { --toast-color: var(--toast-warning); }
.toast-stack .toast--info    { --toast-color: var(--toast-info);    }

.toast-stack .toast__icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--toast-color) 18%, transparent);
  color: var(--toast-color);
  flex-shrink: 0;
}
.toast-stack .toast__icon svg { width: 15px; height: 15px; }

.toast-stack .toast__body { min-width: 0; }
.toast-stack .toast__row  { display: flex; align-items: flex-start; gap: 8px; }
.toast-stack .toast__title {
  flex: 1;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text, #ececee);
  line-height: 1.35;
  letter-spacing: -0.005em;
}

.toast-stack .toast__close {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 0;
  background: transparent;
  color: var(--text-3, #6c6c72);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: -2px -4px 0 0;
  transition: color .12s, background .12s;
}
.toast-stack .toast__close:hover { color: var(--text, #ececee); background: var(--panel-3, #26262a); }
.toast-stack .toast__close svg   { width: 12px; height: 12px; }

.toast-stack .toast__msg {
  margin-top: 4px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-2, #a0a0a6);
}

.toast-stack .toast__actions { display: flex; gap: 6px; margin-top: 10px; }
.toast-stack .toast__btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  background: color-mix(in oklab, var(--toast-color) 16%, transparent);
  color: var(--toast-color);
  border: 1px solid color-mix(in oklab, var(--toast-color) 35%, transparent);
  transition: background .12s, border-color .12s;
}
.toast-stack .toast__btn:hover {
  background: color-mix(in oklab, var(--toast-color) 26%, transparent);
  border-color: color-mix(in oklab, var(--toast-color) 55%, transparent);
}
.toast-stack .toast__btn svg { width: 12px; height: 12px; }
.toast-stack .toast__btn--ghost {
  background: transparent;
  color: var(--text-2, #a0a0a6);
  border-color: transparent;
}
.toast-stack .toast__btn--ghost:hover {
  background: var(--panel-3, #26262a);
  color: var(--text, #ececee);
  border-color: transparent;
}

.toast-stack .toast__progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  background: color-mix(in oklab, var(--toast-color) 70%, transparent);
  transform-origin: left center;
  animation: toast-progress var(--toast-dur, 5400ms) linear forwards;
}

.toast-stack .toast--out { animation: toast-out .26s ease-in forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(28px) scale(.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(40px) scale(.98);
    margin-bottom: -100%;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;
  }
}
@keyframes toast-progress {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

@media (max-width: 520px) {
  .toast-stack { right: 8px; left: 8px; width: auto; }
}

/* ============================================================
   LIGHT THEME OVERRIDE
   ponytail: light override only — dark block above stays the
   default and byte-identical. The dark rules bake DARK literal
   fallbacks into var() (e.g. var(--panel-2, #202023)), so under
   light we can't just redefine tokens; we restate the few rules
   that carry hardcoded dark literals with light values. The 4
   --toast-* kind hues stay as DECORATIVE accents (progress bar /
   chip tint / btn fill+border). But two usages put a kind hue on
   white where it fails WCAG contrast: the action-button LABEL TEXT
   (.toast__btn) needs >=4.5:1 and the kind-indicator GLYPH
   (.toast__icon svg) needs >=3:1. On white the raw hues are far
   too light (warning ~1.9:1, success ~2.1:1), so for light theme we
   darken those chromatic foregrounds toward #18181b via color-mix.
   Shadows re-anchored lighter.
   ============================================================ */
[data-bs-theme="light"] .toast-stack .toast {
  background: #ffffff;
  border: 1px solid #e4e4e7;
  box-shadow:
    0 8px 24px -12px rgba(0, 0, 0, 0.18),
    0 1px 2px rgba(0, 0, 0, 0.06);
  color: #18181b;
}

[data-bs-theme="light"] .toast-stack .toast__title {
  color: #18181b;
}

[data-bs-theme="light"] .toast-stack .toast__msg {
  color: #52525b;
}

[data-bs-theme="light"] .toast-stack .toast__close {
  color: #71717a;
}
[data-bs-theme="light"] .toast-stack .toast__close:hover {
  color: #18181b;
  background: #f1f1f3;
}

[data-bs-theme="light"] .toast-stack .toast__btn--ghost {
  color: #52525b;
}
[data-bs-theme="light"] .toast-stack .toast__btn--ghost:hover {
  background: #f1f1f3;
  color: #18181b;
}

/* Kind-indicator glyph: raw hue on the near-white chip drops below
   the 3:1 non-text threshold (warning ~1.9:1). Darken the glyph
   toward near-black so the indicator stays legible on white. */
[data-bs-theme="light"] .toast-stack .toast__icon {
  color: color-mix(in oklab, var(--toast-color) 38%, #18181b);
}

/* Action-button label: the dark rule paints the kind hue as TEXT
   over a faint tint, which on white is ~1.9–2.9:1 and fails the
   4.5:1 text minimum. Darken label + border toward near-black so
   the button reads on its light fill. Ghost variant handled above. */
[data-bs-theme="light"] .toast-stack .toast__btn {
  color: color-mix(in oklab, var(--toast-color) 30%, #18181b);
  border-color: color-mix(in oklab, var(--toast-color) 45%, transparent);
}
[data-bs-theme="light"] .toast-stack .toast__btn:hover {
  border-color: color-mix(in oklab, var(--toast-color) 60%, transparent);
}
[data-bs-theme="light"] .toast-stack .toast__btn--ghost {
  border-color: transparent;
}
[data-bs-theme="light"] .toast-stack .toast__btn--ghost:hover {
  border-color: transparent;
}
