/* ========================================
   FD Toast — Dynamic Island–style feedback
   Fixed top-center; out of document flow (no layout shift).
   Owner: T1 primitive. Token colours only.
   Subtle fog (lighter than modal) with ease-in/out; clears before toast.
   ======================================== */

/* Subtle content fog — lighter than calendar/modal glass */
.fd-toast-fog {
  --fd-toast-fog-bg: color-mix(in srgb, var(--color-dark) 14%, transparent);
  --fd-toast-fog-blur: 4px;
  --fd-toast-fog-saturate: 120%;
  --fd-toast-fog-ease-in: cubic-bezier(0.33, 1, 0.68, 1);
  --fd-toast-fog-ease-out: cubic-bezier(0.32, 0, 0.67, 0);
  --fd-toast-fog-in-ms: 0.24s;
  --fd-toast-fog-out-ms: 0.33s;

  position: fixed;
  inset: 0;
  z-index: 1090;
  width: 100vw;
  height: 100vh;
  background-color: var(--fd-toast-fog-bg);
  -webkit-backdrop-filter: blur(var(--fd-toast-fog-blur)) saturate(var(--fd-toast-fog-saturate));
  backdrop-filter: blur(var(--fd-toast-fog-blur)) saturate(var(--fd-toast-fog-saturate));
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity var(--fd-toast-fog-out-ms) var(--fd-toast-fog-ease-out),
    visibility 0s linear var(--fd-toast-fog-out-ms);
}

.fd-toast-fog.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  cursor: default;
  transition:
    opacity var(--fd-toast-fog-in-ms) var(--fd-toast-fog-ease-in),
    visibility 0s linear 0s;
}

@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .fd-toast-fog {
    --fd-toast-fog-bg: rgba(0, 0, 0, 0.18);
  }
}

#fd-toast-host {
  --fd-toast-top: calc(0.75rem * var(--fd-ui-scale, 1));
  --fd-toast-max-width: min(32rem, calc(100vw - 2rem));
  --fd-toast-pill-h: 2.25rem;
  --fd-toast-radius: var(--radius-full);
  --fd-toast-ease: cubic-bezier(0.32, 0.72, 0, 1);
  --fd-toast-ease-out: cubic-bezier(0.4, 0, 0.2, 1);
  --fd-toast-duration: 0.288s;
  --fd-toast-bg: var(--color-dark);
  --fd-toast-fg: var(--text-inverse);
  --fd-toast-muted: color-mix(in srgb, var(--color-white) 62%, transparent);

  position: fixed;
  top: var(--fd-toast-top);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  width: max-content;
  max-width: var(--fd-toast-max-width);
  pointer-events: none;
  display: flex;
  justify-content: center;
}

.fd-toast-island {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  height: var(--fd-toast-pill-h);
  min-height: var(--fd-toast-pill-h);
  max-width: var(--fd-toast-max-width);
  padding: 0 var(--inset-sm);
  border: none;
  border-radius: var(--fd-toast-radius);
  background: var(--fd-toast-bg);
  color: var(--fd-toast-fg);
  box-shadow:
    var(--shadow-lg),
    0 0 0 var(--stroke-hairline) color-mix(in srgb, var(--color-white) 8%, transparent);
  overflow: hidden;
  white-space: nowrap;
  font-family: var(--font-family-primary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1.35;
  /* Compact seed — morphs open via explicit width from JS */
  width: 2.75rem;
  opacity: 0;
  transform: scale(0.72);
  transition:
    width var(--fd-toast-duration) var(--fd-toast-ease),
    height var(--fd-toast-duration) var(--fd-toast-ease),
    opacity 0.17s var(--fd-toast-ease-out),
    transform var(--fd-toast-duration) var(--fd-toast-ease),
    padding var(--fd-toast-duration) var(--fd-toast-ease),
    gap var(--fd-toast-duration) var(--fd-toast-ease),
    border-radius var(--fd-toast-duration) var(--fd-toast-ease);
  will-change: width, transform, opacity;
}

.fd-toast-island.is-compact {
  opacity: 1;
  transform: scale(1);
}

.fd-toast-island.is-expanded {
  /* 3-column row: icon | message | dismiss — even padding, vertically centered */
  height: auto;
  min-height: var(--fd-toast-pill-h);
  padding: var(--inset-sm) var(--inset-sm) var(--inset-sm) var(--inset-md);
  gap: var(--inset-sm);
  justify-content: flex-start;
  align-items: center;
  white-space: normal;
  border-radius: var(--radius-xl); /* 16px — was 1rem/14 off-ladder */
  opacity: 1;
  transform: scale(1);
}

.fd-toast-island.is-collapsing {
  width: 2.75rem !important;
  padding: 0 var(--inset-sm);
  gap: 0;
  justify-content: center;
  opacity: 0;
  transform: scale(0.72);
}

.fd-toast-island__icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  font-size: 1rem;
  line-height: 1;
  margin-inline: auto;
}

.fd-toast-island__icon--stack {
  width: auto;
  min-width: 1.35rem;
  justify-content: flex-start;
  padding-inline: 0.1rem;
}

.fd-toast-island__icon-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--color-white) 10%, transparent);
  box-shadow: 0 0 0 1.5px var(--fd-toast-bg, var(--color-dark));
  font-size: 0.95rem;
  line-height: 1;
}

.fd-toast-island__icon--stack .fd-toast-island__icon-chip + .fd-toast-island__icon-chip {
  margin-left: -0.42rem;
}

.fd-toast-island__icon-chip.is-pop,
.fd-toast-island__icon-more.is-pop {
  animation: fd-toast-icon-pop 0.23s var(--fd-toast-ease, cubic-bezier(0.32, 0.72, 0, 1));
}

@keyframes fd-toast-icon-pop {
  0% {
    transform: scale(0.55);
    opacity: 0.4;
  }
  60% {
    transform: scale(1.12);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.fd-toast-island__icon-more {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  margin-left: calc(-1 * var(--inset-xs));
  padding: 0 var(--inset-xs);
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--color-white) 14%, transparent);
  box-shadow: 0 0 0 1.5px var(--fd-toast-bg, var(--color-dark));
  color: var(--fd-toast-fg);
  font-size: 0.6875rem;
  font-weight: var(--font-weight-semibold, 600);
  line-height: 1;
  z-index: 6;
}

.fd-toast-island--success .fd-toast-island__icon,
.fd-toast-island--success .fd-toast-island__icon-chip {
  color: var(--status-success);
}

.fd-toast-island--danger .fd-toast-island__icon,
.fd-toast-island--danger .fd-toast-island__icon-chip {
  color: var(--color-white);
}

.fd-toast-island--danger .fd-toast-island__icon-chip {
  background: var(--status-error);
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--status-error) 55%, var(--fd-toast-bg));
}

/* Danger expanded — left accent + slightly stronger edge for WCAG cue */
.fd-toast-island--danger.is-expanded {
  box-shadow:
    var(--shadow-lg),
    0 0 0 var(--stroke-hairline) color-mix(in srgb, var(--status-error) 40%, transparent),
    inset 3px 0 0 0 var(--status-error);
}

.fd-toast-island.is-expanded .fd-toast-island__icon {
  margin: 0;
  width: 1.65rem;
  height: 1.65rem;
  font-size: 1.05rem;
  align-self: center;
}

/* Stacked chips need horizontal room — don't clamp to single-icon width */
.fd-toast-island.is-expanded .fd-toast-island__icon--stack {
  width: auto;
  min-width: 1.65rem;
  max-width: none;
  height: 1.65rem;
  flex-shrink: 0;
}

.fd-toast-island.is-expanded .fd-toast-island__icon-chip {
  width: 1.65rem;
  height: 1.65rem;
  font-size: 1rem;
}

.fd-toast-island__message strong {
  font-weight: var(--font-weight-semibold, 600);
  color: var(--fd-toast-fg);
}

.fd-toast-island--warning .fd-toast-island__icon,
.fd-toast-island--warning .fd-toast-island__icon-chip {
  color: var(--status-warning);
}

.fd-toast-island--info .fd-toast-island__icon,
.fd-toast-island--info .fd-toast-island__icon-chip {
  color: var(--interactive-primary);
}

.fd-toast-island__body {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(4px);
  transition:
    max-width var(--fd-toast-duration) var(--fd-toast-ease),
    opacity 0.13s var(--fd-toast-ease-out) 0.07s,
    transform 0.17s var(--fd-toast-ease) 0.06s;
}

.fd-toast-island.is-expanded .fd-toast-island__body {
  max-width: none;
  flex: 1 1 auto;
  min-width: 0;
  opacity: 1;
  transform: translateY(0);
  text-align: left;
}

.fd-toast-island.is-collapsing .fd-toast-island__body {
  max-width: 0;
  opacity: 0;
  transform: translateY(2px);
  transition-delay: 0s;
  transition-duration: 0.07s;
}

.fd-toast-island__message {
  display: block;
  max-width: 22rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fd-toast-fg);
}

/* Expanded — full message, left-aligned, wrap on word boundaries */
.fd-toast-island.is-expanded .fd-toast-island__message {
  max-width: none;
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  text-align: left;
  line-height: 1.4;
}

.fd-toast-island__dismiss {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0;
  height: 1.5rem;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--color-white) 12%, transparent);
  color: var(--fd-toast-muted);
  cursor: pointer;
  opacity: 0;
  overflow: hidden;
  transition:
    width var(--fd-toast-duration) var(--fd-toast-ease),
    opacity 0.12s ease 0.09s,
    background-color var(--transition-fast),
    color var(--transition-fast);
}

.fd-toast-island.is-expanded .fd-toast-island__dismiss {
  width: 1.5rem;
  height: 1.5rem;
  opacity: 1;
  margin: 0;
  align-self: center;
}

.fd-toast-island.is-collapsing .fd-toast-island__dismiss {
  width: 0;
  opacity: 0;
  transition-delay: 0s;
}

.fd-toast-island__dismiss:hover {
  background: color-mix(in srgb, var(--color-white) 20%, transparent);
  color: var(--fd-toast-fg);
}

.fd-toast-island__dismiss:focus-visible {
  outline: 2px solid var(--interactive-primary);
  outline-offset: 2px;
}

.fd-toast-island__dismiss .ti {
  font-size: 0.875rem;
  line-height: 1;
}

/* Auth pages — slightly higher so it clears the card edge on short viewports */
.fd-auth-page #fd-toast-host {
  --fd-toast-top: 1rem;
}

@media (prefers-reduced-motion: reduce) {
  .fd-toast-fog {
    --fd-toast-fog-in-ms: 0.15s;
    --fd-toast-fog-out-ms: 0.15s;
    --fd-toast-fog-blur: 0px;
  }

  #fd-toast-host {
    --fd-toast-duration: 0.01ms;
  }

  .fd-toast-island,
  .fd-toast-island__body,
  .fd-toast-island__dismiss {
    transition: opacity 0.15s ease !important;
    transform: none !important;
  }

  .fd-toast-island__icon-chip.is-pop,
  .fd-toast-island__icon-more.is-pop {
    animation: none !important;
  }

  .fd-toast-island.is-compact,
  .fd-toast-island.is-expanded {
    width: auto !important;
    max-width: var(--fd-toast-max-width) !important;
    height: auto !important;
    min-height: var(--fd-toast-pill-h);
    padding: var(--inset-sm) var(--inset-sm) var(--inset-sm) var(--inset-md);
    gap: var(--inset-sm);
    justify-content: flex-start;
    align-items: center;
    white-space: normal;
  }

  .fd-toast-island.is-compact .fd-toast-island__body,
  .fd-toast-island.is-expanded .fd-toast-island__body {
    max-width: none;
    opacity: 1;
    text-align: left;
  }

  .fd-toast-island.is-compact .fd-toast-island__message,
  .fd-toast-island.is-expanded .fd-toast-island__message {
    max-width: none;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    overflow-wrap: break-word;
    word-break: normal;
    text-align: left;
  }

  .fd-toast-island.is-compact .fd-toast-island__dismiss,
  .fd-toast-island.is-expanded .fd-toast-island__dismiss {
    width: 1.5rem;
    opacity: 1;
  }
}
