/* ==========================================================================
   Toast — brief notifications. Created by moey.js:

   Moey.toast('Saved')                         Moey.toast.success('Order created')
   Moey.toast({ title: 'Invite sent', message: 'jane@moey.test', action: { label: 'Undo', onClick } })
   <button data-moey-toast="Saved" data-moey-toast-type="success">   (no JS of your own)

   They stack in a corner (bottom-end by default), collapse into a neat pile and
   expand on hover. Static markup works too: <div class="toast">…</div>.
   ========================================================================== */

.toast {
  --mo-toast-bg: var(--mo-bg-raised);
  --mo-toast-width: 22rem;
  --mo-toast-accent: var(--mo-fg-3);
  --mo-toast-line: calc(.875rem * 1.45);       /* one line of text */
  position: relative;
  display: flex;
  gap: .75rem;
  align-items: center;                         /* one line: icon, text, buttons and ✕ centered */
  box-sizing: border-box;
  width: var(--mo-toast-width);
  max-width: 100%;
  padding: .875rem .875rem .875rem 1rem;
  overflow: hidden;
  font-size: .875rem;
  line-height: 1.45;
  color: var(--mo-fg-body);
  background: var(--mo-toast-bg);
  border-radius: var(--mo-radius-overlay);
  box-shadow: var(--mo-shadow-overlay);
}
.toast[data-type] { --mo-toast-accent: var(--mo-theme-base); }
.toast:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: 1px; }

/* Icon: built in per type, or your own <i class="mi …"> inside */
.toast-icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--mo-theme-fg);
}
.toast:not([data-type]) .toast-icon { color: var(--mo-fg-2); }
.toast-icon:empty { background-color: currentcolor; mask: var(--mo-toast-icon) center / contain no-repeat; }
.toast[data-type="success"] { --mo-toast-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='m8.5 12 2.5 2.5 4.5-5'/%3E%3C/svg%3E"); }
.toast[data-type="error"] { --mo-toast-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='m15 9-6 6m0-6 6 6'/%3E%3C/svg%3E"); }
.toast[data-type="warning"] { --mo-toast-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 2.4 17.6A2 2 0 0 0 4.1 20.6h15.8a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0Z'/%3E%3Cpath d='M12 9v4m0 3.5h.01'/%3E%3C/svg%3E"); }
.toast[data-type="info"] { --mo-toast-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9.5'/%3E%3Cpath d='M12 16v-4.5m0-3.5h.01'/%3E%3C/svg%3E"); }

/* Loading */
.toast-spinner {
  display: block;
  width: 1.125rem;
  height: 1.125rem;
  margin: .0625rem;
  border: 2px solid color-mix(in oklab, currentcolor 25%, transparent);
  border-top-color: currentcolor;
  border-radius: 50%;
  animation: mo-toast-spin .7s linear infinite;
}
@keyframes mo-toast-spin { to { rotate: 1turn; } }

.toast-content { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-title { font-weight: var(--mo-font-weight-semibold); }
.toast-title + .toast-message { margin-top: .125rem; color: var(--mo-fg-2); }
.toast-actions { display: flex; flex-shrink: 0; gap: .375rem; align-self: center; }
.toast > .btn-close { flex-shrink: 0; margin-block: -.25rem; margin-inline-end: -.25rem; color: var(--mo-fg-3); }

/* More than one line (a title + message, or text that wraps — moey.js measures it):
   the icon and ✕ line up with the first line, buttons stay centered */
.toast:is(.is-multiline, :has(.toast-title + .toast-message)) { align-items: flex-start; }
.toast:is(.is-multiline, :has(.toast-title + .toast-message)) > .toast-icon { margin-top: calc((var(--mo-toast-line) - 1.25rem) / 2); }
.toast:is(.is-multiline, :has(.toast-title + .toast-message)) > .btn-close { margin-block: calc((var(--mo-toast-line) - var(--mo-close-size)) / 2) 0; }
.toast > .btn-close:hover { color: var(--mo-fg-body); }

/* Countdown bar (progress: true) */
.toast-progress {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 3px;
  background: var(--mo-toast-accent);
  opacity: .55;
  transform-origin: left;
  animation: mo-toast-progress var(--mo-toast-duration, 5s) linear forwards;
}
.toast-progress:dir(rtl) { transform-origin: right; }
.toast.is-paused .toast-progress { animation-play-state: paused; }
@keyframes mo-toast-progress { to { scale: 0 1; } }

/* Variants */
/* Strengths, like buttons (the color comes from the type, or theme / .theme-*):
   .toast-subtle (tint) · .toast-soft · .toast-solid · .toast-vivid · .toast-deep */
.toast-subtle { --_toast-fill: var(--mo-theme-subtle); --_toast-on: var(--mo-theme-subtle-text); }
.toast-soft   { --_toast-fill: var(--mo-theme-soft);   --_toast-on: var(--mo-theme-soft-text); }
.toast-solid  { --_toast-fill: var(--mo-theme-solid);  --_toast-on: var(--mo-theme-solid-text); }
.toast-vivid  { --_toast-fill: var(--mo-theme-vivid);  --_toast-on: var(--mo-theme-vivid-text); }
.toast-deep   { --_toast-fill: var(--mo-theme-deep);   --_toast-on: var(--mo-theme-deep-text); }
:is(.toast-subtle, .toast-soft, .toast-solid, .toast-vivid, .toast-deep) {
  --mo-toast-bg: var(--_toast-fill);
  --mo-toast-accent: var(--_toast-on);
  color: var(--_toast-on);
  box-shadow: var(--mo-shadow-overlay);
}
:is(.toast-subtle, .toast-soft) .toast-icon { color: var(--mo-theme-fg); }
:is(.toast-solid, .toast-vivid, .toast-deep) :is(.toast-icon, .toast-message),
:is(.toast-solid, .toast-vivid, .toast-deep) > .btn-close { color: inherit; }
:is(.toast-subtle, .toast-soft, .toast-solid, .toast-vivid, .toast-deep) .toast-title + .toast-message { color: inherit; opacity: .85; }

/* Static toasts dismissed with their ✕ fade out (like alerts) */
.toast.hiding { opacity: 0; transition: opacity var(--mo-duration) var(--mo-ease); }

/* Stack -------------------------------------------------------------------------
   One per position, in the top layer. moey.js sets --y / --s per toast and the
   stack's height; hovering expands it. */
.toast-stack {
  --mo-toast-gap: .625rem;
  --mo-toast-edge: 1rem;
  position: fixed;
  inset: auto;
  box-sizing: border-box;
  width: var(--mo-toast-width, 22rem);
  max-width: calc(100vw - 2 * var(--mo-toast-edge));
  height: 0;
  padding: 0;
  margin: 0;
  overflow: visible;
  color: inherit;
  background: none;
  border: 0;
  transition: height .35s var(--mo-ease);
}
.toast-stack[data-position^="bottom"] { bottom: max(var(--mo-toast-edge) + var(--mo-tabbar-space, 0px), env(safe-area-inset-bottom)); }   /* above a tab bar */
.toast-stack[data-position^="top"] { top: max(var(--mo-toast-edge), env(safe-area-inset-top)); }
.toast-stack[data-position$="end"] { inset-inline-end: var(--mo-toast-edge); }
.toast-stack[data-position$="start"] { inset-inline-start: var(--mo-toast-edge); }
.toast-stack[data-position$="right"] { right: var(--mo-toast-edge); }
.toast-stack[data-position$="left"] { left: var(--mo-toast-edge); }
.toast-stack[data-position$="center"] { inset-inline: 0; margin-inline: auto; }
@media (width < 576px) {
  .toast-stack { --mo-toast-edge: .5rem; inset-inline: 0; width: auto; margin-inline: var(--mo-toast-edge); max-width: none; }
}

.toast-stack > .toast {
  position: absolute;
  inset-inline: 0;
  z-index: calc(100 - var(--i, 0));
  width: auto;
  translate: var(--x, 0) var(--y, 0);
  scale: var(--s, 1);
  touch-action: pan-y;
  transition:
    translate .35s var(--mo-ease),
    scale .35s var(--mo-ease),
    opacity .35s var(--mo-ease),
    height .35s var(--mo-ease);
}
.toast-stack[data-position^="bottom"] > .toast { bottom: 0; transform-origin: center bottom; }
.toast-stack[data-position^="top"] > .toast { top: 0; transform-origin: center top; }
.toast-stack[data-position^="bottom"] { --mo-toast-enter: 100%; }
.toast-stack[data-position^="top"] { --mo-toast-enter: -100%; }
@starting-style {
  .toast-stack > .toast { opacity: 0; translate: 0 var(--mo-toast-enter); }
}

/* Collapsed pile: toasts behind the front one take its height and hide their content */
.toast-stack:not(.is-expanded) > .toast:not(.is-front, .is-leaving) { height: var(--mo-toast-front-h); }
.toast-stack:not(.is-expanded) > .toast:not(.is-front) > * { opacity: 0; transition: opacity .2s; }
.toast-stack > .toast > * { transition: opacity .2s; }
.toast-stack > .toast.is-hidden { opacity: 0; pointer-events: none; }
.toast-stack > .toast.is-leaving { opacity: 0; scale: calc(var(--s, 1) * .96); pointer-events: none; }
.toast-stack > .toast.is-swiping { user-select: none; transition: none; }

@media (prefers-reduced-motion: reduce) {
  .toast-stack, .toast-stack > .toast { transition: opacity .2s; }
  .toast-spinner { animation-duration: 1.5s; }
}
