/*
 * toast.css — vanilla-JS port of Sonner stack/animation styles.
 *
 * Color, radius, typography, shadow tokens are deliberately not set here;
 * style via [data-sonner-toast] in the consumer's stylesheet. Variables
 * the toast layer needs (set by toast.js inline on each instance):
 *   --width, --gap, --front-toast-height, --initial-height,
 *   --index, --toasts-before, --z-index, --offset, --y, --lift,
 *   --lift-amount, --swipe-amount-x, --swipe-amount-y,
 *   --offset-top/right/bottom/left, --mobile-offset-top/right/bottom/left
 *
 * Selectors mirror Sonner so any override snippet from the Sonner ecosystem
 * applies cleanly.
 */

[data-sonner-toaster] {
  position: fixed;
  width: var(--width);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica Neue, Arial, sans-serif;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  list-style: none;
  outline: none;
  z-index: 999999999;
  transition: transform 400ms ease;
  --toast-icon-margin-start: -3px;
  --toast-icon-margin-end: 4px;
  --toast-button-margin-start: auto;
  --toast-button-margin-end: 0;
  --border-radius: 8px;
}

/* bottom-center is the only supported position in this port. */
[data-sonner-toaster][data-x-position="center"] {
  left: 50%;
  transform: translateX(-50%);
}
[data-sonner-toaster][data-y-position="bottom"] {
  bottom: var(--offset-bottom);
}
[data-sonner-toaster][data-y-position="top"] {
  top: var(--offset-top);
}

@media (hover: none) and (pointer: coarse) {
  [data-sonner-toaster][data-lifted="true"] { transform: none; }
}

/* per-toast base */
[data-sonner-toast] {
  --y: translateY(100%);
  --lift-amount: calc(var(--lift) * var(--gap));
  z-index: var(--z-index);
  position: absolute;
  opacity: 0;
  transform: var(--y);
  touch-action: none;
  transition: transform 400ms, opacity 400ms, height 400ms, box-shadow 200ms;
  box-sizing: border-box;
  outline: none;
  overflow-wrap: anywhere;
}

[data-sonner-toast][data-styled="true"] {
  padding: 16px;
  background: var(--st-toast-bg, #fff);
  border: 1px solid var(--st-toast-border, rgba(0, 0, 0, 0.08));
  color: var(--st-toast-text, #111);
  border-radius: var(--border-radius);
  box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
  width: var(--width);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

[data-sonner-toast]:focus-visible {
  box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1), 0 0 0 2px rgba(0, 0, 0, 0.2);
}

[data-sonner-toast][data-y-position="top"] {
  top: 0;
  --y: translateY(-100%);
  --lift: 1;
  --lift-amount: calc(1 * var(--gap));
}

[data-sonner-toast][data-y-position="bottom"] {
  bottom: 0;
  --y: translateY(100%);
  --lift: -1;
  --lift-amount: calc(var(--lift) * var(--gap));
}

[data-sonner-toast][data-styled="true"] [data-title] {
  font-weight: 500;
  line-height: 1.5;
  color: inherit;
}

[data-sonner-toast][data-styled="true"] [data-content] {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

/* action button */
[data-sonner-toast][data-styled="true"] [data-button] {
  border-radius: 4px;
  padding-left: 8px;
  padding-right: 8px;
  height: 24px;
  font-size: 12px;
  color: var(--st-toast-action-text, var(--st-toast-bg, #fff));
  background: var(--st-toast-action-bg, var(--st-toast-text, #111));
  margin-left: var(--toast-button-margin-start);
  margin-right: var(--toast-button-margin-end);
  border: none;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: opacity 400ms, box-shadow 200ms;
}
[data-sonner-toast][data-styled="true"] [data-button]:focus-visible {
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4);
}

/* Swiping bg pad so dragging past the toast edge doesn't expose page chrome. */
[data-sonner-toast][data-swiping="true"]::before {
  content: "";
  position: absolute;
  left: -100%;
  right: -100%;
  height: 100%;
  z-index: -1;
}
[data-sonner-toast][data-y-position="bottom"][data-swiping="true"]::before {
  top: 50%;
  transform: scaleY(3) translateY(-50%);
}
[data-sonner-toast][data-y-position="top"][data-swiping="true"]::before {
  bottom: 50%;
  transform: scaleY(3) translateY(50%);
}

[data-sonner-toast][data-swiping="false"][data-removed="true"]::before {
  content: "";
  position: absolute;
  inset: 0;
  transform: scaleY(2);
}

/* Hover-expand "lid" so the cursor can travel between toasts without leaving. */
[data-sonner-toast][data-expanded="true"]::after {
  content: "";
  position: absolute;
  left: 0;
  height: calc(var(--gap) + 1px);
  bottom: 100%;
  width: 100%;
}

/* mounted state — slide into resting position */
[data-sonner-toast][data-mounted="true"] {
  --y: translateY(0);
  opacity: 1;
}

/* collapsed receding toasts (behind the front one) */
[data-sonner-toast][data-expanded="false"][data-front="false"] {
  --scale: var(--toasts-before) * 0.05 + 1;
  --y: translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));
  height: var(--front-toast-height);
}

[data-sonner-toast] > * {
  transition: opacity 400ms;
}

[data-sonner-toast][data-x-position="right"] { right: 0; }
[data-sonner-toast][data-x-position="left"] { left: 0; }

/* hide content of receding toasts (we only show the front toast's text) */
[data-sonner-toast][data-expanded="false"][data-front="false"][data-styled="true"] > * {
  opacity: 0;
}

[data-sonner-toast][data-visible="false"] {
  opacity: 0;
  pointer-events: none;
}

/* expanded — all toasts spread out vertically by their measured offsets */
[data-sonner-toast][data-mounted="true"][data-expanded="true"] {
  --y: translateY(calc(var(--lift) * var(--offset)));
  height: var(--initial-height);
}

/* exit animations */
[data-sonner-toast][data-removed="true"][data-front="true"][data-swipe-out="false"] {
  --y: translateY(calc(var(--lift) * -100%));
  opacity: 0;
}
[data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="true"] {
  --y: translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));
  opacity: 0;
}
[data-sonner-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="false"] {
  --y: translateY(40%);
  opacity: 0;
  transition: transform 500ms, opacity 200ms;
}
[data-sonner-toast][data-removed="true"][data-front="false"]::before {
  height: calc(var(--initial-height) + 20%);
}

/* swiping (live drag) */
[data-sonner-toast][data-swiping="true"] {
  transform: var(--y) translateY(var(--swipe-amount-y, 0px)) translateX(var(--swipe-amount-x, 0px));
  transition: none;
}
[data-sonner-toast][data-swiped="true"] {
  -webkit-user-select: none;
  user-select: none;
}

/* swipe-out keyframes */
[data-sonner-toast][data-swipe-out="true"][data-y-position="bottom"],
[data-sonner-toast][data-swipe-out="true"][data-y-position="top"] {
  animation-duration: 200ms;
  animation-timing-function: ease-out;
  animation-fill-mode: forwards;
}
[data-sonner-toast][data-swipe-out="true"][data-swipe-direction="up"] {
  animation-name: st-swipe-out-up;
}
[data-sonner-toast][data-swipe-out="true"][data-swipe-direction="down"] {
  animation-name: st-swipe-out-down;
}
[data-sonner-toast][data-swipe-out="true"][data-swipe-direction="left"] {
  animation-name: st-swipe-out-left;
}
[data-sonner-toast][data-swipe-out="true"][data-swipe-direction="right"] {
  animation-name: st-swipe-out-right;
}

@keyframes st-swipe-out-up {
  from { transform: var(--y) translateY(var(--swipe-amount-y)); opacity: 1; }
  to   { transform: var(--y) translateY(calc(var(--swipe-amount-y) - 100%)); opacity: 0; }
}
@keyframes st-swipe-out-down {
  from { transform: var(--y) translateY(var(--swipe-amount-y)); opacity: 1; }
  to   { transform: var(--y) translateY(calc(var(--swipe-amount-y) + 100%)); opacity: 0; }
}
@keyframes st-swipe-out-left {
  from { transform: var(--y) translateX(var(--swipe-amount-x)); opacity: 1; }
  to   { transform: var(--y) translateX(calc(var(--swipe-amount-x) - 100%)); opacity: 0; }
}
@keyframes st-swipe-out-right {
  from { transform: var(--y) translateX(var(--swipe-amount-x)); opacity: 1; }
  to   { transform: var(--y) translateX(calc(var(--swipe-amount-x) + 100%)); opacity: 0; }
}

/* mobile: rail spans width with margins */
@media (max-width: 600px) {
  [data-sonner-toaster] {
    position: fixed;
    right: var(--mobile-offset-right);
    left: var(--mobile-offset-left);
    width: 100%;
  }
  [data-sonner-toaster] [data-sonner-toast] {
    left: 0;
    right: 0;
    width: calc(100% - var(--mobile-offset-left) * 2);
  }
  [data-sonner-toaster][data-y-position="bottom"] {
    bottom: var(--mobile-offset-bottom);
  }
  [data-sonner-toaster][data-y-position="top"] {
    top: var(--mobile-offset-top);
  }
  [data-sonner-toaster][data-x-position="center"] {
    left: var(--mobile-offset-left);
    right: var(--mobile-offset-right);
    transform: none;
  }
}

/* reduce-motion — kill all transitions/animations (matches Sonner exactly) */
@media (prefers-reduced-motion) {
  [data-sonner-toast],
  [data-sonner-toast] > * {
    transition: none !important;
    animation: none !important;
  }
}

/* ----------------------------------------------------------------------
 * shy-tomato token overrides.
 *
 * The vendored toast.css ships token-agnostic fallbacks (white surface,
 * #111 text, fixed shadow + radius). Wire them into the existing shy-tomato
 * token sheet here so the rail picks up the same surface, border, text,
 * shadow, and typography vocabulary as the rest of the app — and so a
 * future light/dark / token rename propagates automatically.
 *
 * Selectors mirror the Sonner ones the consumer is expected to override.
 * --------------------------------------------------------------------*/
[data-sonner-toaster] {
  /* shy-tomato body font (Outfit). Sonner's default sans stack would
     pop a different system font and break the page's typographic rhythm. */
  font-family: var(--font-body);
  /* Match the rest of the app's container radii. tokens.css --radius-md = 12px. */
  --border-radius: var(--radius-md);
}

[data-sonner-toast][data-styled="true"] {
  background: var(--md-surface-container-low);
  color: var(--md-on-surface);
  border-color: var(--md-border-muted);
  /* tokens.css --shadow-md is the elevation we use for the recipe preview
     panel and other lifted surfaces — same family as Sonner's default. */
  box-shadow: var(--shadow-md);
  /* Slight density bump over the 13px default — shy-tomato body copy
     is 14-15px at this surface. */
  font-size: 14px;
  /* Action button (Undo) colors — dark pill on light surface. */
  --st-toast-action-bg: var(--md-on-surface);
  --st-toast-action-text: var(--md-surface-container-low);
}

[data-sonner-toast][data-styled="true"] [data-title] {
  /* Outfit is geometric — 1.4 line-height reads better than the 1.5 default
     for a one-line toast title. */
  line-height: 1.4;
}

[data-sonner-toast][data-styled="true"] [data-button] {
  border-radius: var(--radius-sm);
  font-family: inherit;
  height: 28px;
  padding-inline: var(--space-3);
}
