/* sd-toast — in-house toast notifications (replaces PNotify, 2026-07-14).
   Design language follows .sd-callout (modernize.css): flat card, 4px semantic
   accent rail, feather icon in a tinted tile. Light mode = hardcoded palette
   (same discipline as modernize.css), dark mode = theme.css token overrides.
   Loaded globally from fragments/header/css.html; JS API + PNotify compat
   shim in sd-toast.js. */

/* ---- stacks (one fixed container per corner, created on demand) ---- */
.sd-toast-stack {
  position: fixed;
  z-index: 10800; /* above Bootstrap modals (1050) and SweetAlert2 (~1060) */
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 344px;
  max-width: calc(100vw - 32px);
  pointer-events: none; /* clicks pass through the empty column */
}
.sd-toast-stack[data-position="top-right"]    { top: 16px;    right: 16px; }
.sd-toast-stack[data-position="top-left"]     { top: 16px;    left: 16px;  }
.sd-toast-stack[data-position="bottom-right"] { bottom: 16px; right: 16px; flex-direction: column-reverse; }
.sd-toast-stack[data-position="bottom-left"]  { bottom: 16px; left: 16px;  flex-direction: column-reverse; }

@media (max-width: 576px) {
  .sd-toast-stack { width: calc(100vw - 24px); }
  .sd-toast-stack[data-position="top-right"], .sd-toast-stack[data-position="top-left"]       { top: 12px;    right: 12px; left: 12px; }
  .sd-toast-stack[data-position="bottom-right"], .sd-toast-stack[data-position="bottom-left"] { bottom: 12px; right: 12px; left: 12px; }
}

/* ---- toast card ---- */
.sd-toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 32px 12px 12px;
  overflow: hidden; /* clips the accent rail + timer to the radius */
  pointer-events: auto;
  background: #ffffff;
  color: #37474f;
  border: 1px solid #dde3e8;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(23, 43, 77, 0.14), 0 1px 3px rgba(23, 43, 77, 0.08);
  line-height: 1.45;
  animation: sd-toast-in 0.26s cubic-bezier(0.21, 1.02, 0.55, 1) both;
}
.sd-toast-stack[data-position$="left"] .sd-toast {
  animation-name: sd-toast-in-left;
}

/* semantic accent rail (::before so no layout cost) */
.sd-toast::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 4px;
  background: var(--sd-toast-accent, #1f56e6);
}

/* ---- pieces ---- */
.sd-toast__icon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-left: 2px; /* clear the rail */
  border-radius: 6px;
  font-size: 15px;
  color: var(--sd-toast-accent, #1f56e6);
  background: var(--sd-toast-accent-wash, rgba(31, 86, 230, 0.10));
}
.sd-toast__body  { min-width: 0; flex: 1 1 auto; padding-top: 1px; }
.sd-toast__title { font-weight: 700; font-size: 0.8125rem; margin-bottom: 1px; overflow-wrap: break-word; }
.sd-toast__msg   { font-size: 0.78rem; overflow-wrap: break-word; }
.sd-toast__msg a { font-weight: 600; text-decoration: underline; color: inherit; }

.sd-toast__close {
  position: absolute;
  top: 4px; right: 4px;
  width: 24px; height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #90a0ab;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
}
.sd-toast__close:hover { color: #37474f; background: rgba(23, 43, 77, 0.06); }

/* auto-dismiss countdown hairline; JS sets animation-duration = delay.
   Hover pauses it (JS pauses the dismiss timer in step). */
.sd-toast__timer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2px;
}
.sd-toast__timer > i {
  display: block;
  height: 100%;
  background: var(--sd-toast-accent, #1f56e6);
  opacity: 0.45;
  transform-origin: left;
  animation: sd-toast-timer linear both;
}
.sd-toast:hover .sd-toast__timer > i { animation-play-state: paused; }

/* ---- type accents (light) — palette matches .sd-callout / brand sweep ---- */
.sd-toast--default { --sd-toast-accent: #1f56e6; --sd-toast-accent-wash: rgba(31, 86, 230, 0.10); }  /* brand-600 */
.sd-toast--info    { --sd-toast-accent: #2196c4; --sd-toast-accent-wash: rgba(33, 150, 196, 0.12); }
.sd-toast--success { --sd-toast-accent: #16a34a; --sd-toast-accent-wash: rgba(22, 163, 74, 0.12); }
.sd-toast--warning { --sd-toast-accent: #d6970f; --sd-toast-accent-wash: rgba(214, 151, 15, 0.14); }
.sd-toast--error   { --sd-toast-accent: #dc2626; --sd-toast-accent-wash: rgba(220, 38, 38, 0.11); }

/* ---- dark mode: token overlay (same pattern as the rest of the theme) ---- */
[data-theme="dark"] .sd-toast {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-subtle);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}
[data-theme="dark"] .sd-toast__close       { color: var(--text-muted); }
[data-theme="dark"] .sd-toast__close:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .sd-toast--default { --sd-toast-accent: var(--accent-primary); --sd-toast-accent-wash: rgba(88, 166, 255, 0.14); }
[data-theme="dark"] .sd-toast--info    { --sd-toast-accent: var(--accent-info);    --sd-toast-accent-wash: rgba(121, 192, 255, 0.14); }
[data-theme="dark"] .sd-toast--success { --sd-toast-accent: var(--accent-success); --sd-toast-accent-wash: rgba(63, 185, 80, 0.15); }
[data-theme="dark"] .sd-toast--warning { --sd-toast-accent: var(--accent-warning); --sd-toast-accent-wash: rgba(210, 153, 34, 0.16); }
[data-theme="dark"] .sd-toast--error   { --sd-toast-accent: var(--accent-danger);  --sd-toast-accent-wash: rgba(248, 81, 73, 0.14); }

/* ---- PNotify-compat: addclass "bg-primary" (sticky brand note used by the
   trading-account save flow) renders as a filled brand card ---- */
.sd-toast.bg-primary {
  background: #1f56e6;
  border-color: #1a45b8;
  color: #ffffff;
}
.sd-toast.bg-primary::before { display: none; }
.sd-toast.bg-primary .sd-toast__close       { color: rgba(255, 255, 255, 0.75); }
.sd-toast.bg-primary .sd-toast__close:hover { color: #ffffff; background: rgba(255, 255, 255, 0.12); }
[data-theme="dark"] .sd-toast.bg-primary {
  background: #1a45b8;
  border-color: #1f56e6;
  color: #ffffff;
}

/* ---- exit: fade + slide, and collapse so the stack reflows smoothly.
   JS pins height before adding the class. ---- */
.sd-toast--out {
  height: 0 !important;
  margin: -5px 0 !important; /* swallow half the stack gap on each side */
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-width: 0 !important;
  opacity: 0;
  transform: translateX(30%);
  transition: opacity 0.18s ease, transform 0.18s ease,
              height 0.24s ease 0.08s, margin 0.24s ease 0.08s, padding 0.24s ease 0.08s;
}

@keyframes sd-toast-in {
  from { opacity: 0; transform: translateX(calc(100% + 24px)); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes sd-toast-in-left {
  from { opacity: 0; transform: translateX(calc(-100% - 24px)); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes sd-toast-timer {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .sd-toast { animation: sd-toast-fade 0.15s ease both; }
  .sd-toast--out { transition-duration: 0.05s; transform: none; }
  @keyframes sd-toast-fade { from { opacity: 0; } to { opacity: 1; } }
}
