/* =========================================================
   TOAST NOTIFICATIONS
   Reusable user notification component
   Mobile-first / PWA safe
   ========================================================= */

/* ---------------------------------------------------------
   TOAST CONTAINER
   --------------------------------------------------------- */

.user-toast-container {
  position: fixed;

  /*
   * Keep the toast above:
   * - mobile navigation
   * - headers
   * - drawers
   * - dialogs
   * - PWA UI layers
   */
  z-index: 2147483000;

  display: flex;
  flex-direction: column;
  gap: 0.625rem;

  box-sizing: border-box;

  /*
   * Do not allow the container itself to block the page.
   */
  pointer-events: none;

  /*
   * Prevent unexpected width calculations on mobile.
   */
  width: calc(100vw - 1.5rem);
  max-width: 24rem;

  /*
   * Safe-area support for devices with display cutouts.
   */
  padding: 0;

  /*
   * Keep the container above the browser/PWA safe area.
   */
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

/* ---------------------------------------------------------
   TOP POSITIONS
   --------------------------------------------------------- */

.user-toast-container--top-left {
  top: 0.75rem;
  left: 0.75rem;
}

.user-toast-container--top-center {
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
}

.user-toast-container--top-right {
  top: 0.75rem;
  right: 0.75rem;
}

/* ---------------------------------------------------------
   BOTTOM POSITIONS
   --------------------------------------------------------- */

.user-toast-container--bottom-left {
  bottom: 0.75rem;
  left: 0.75rem;
}

.user-toast-container--bottom-center {
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
}

.user-toast-container--bottom-right {
  right: 0.75rem;
  bottom: 0.75rem;
}

/* ---------------------------------------------------------
   TOAST
   --------------------------------------------------------- */

.user-toast {
  width: 100%;
  min-width: 0;
  min-height: 3.5rem;

  display: flex;
  align-items: center;

  box-sizing: border-box;

  padding: 0.75rem 0.875rem;
  gap: 0.75rem;

  border: 1px solid rgb(65 65 65);
  border-radius: 0.75rem;

  background: rgb(28 28 28);
  color: rgb(235 235 235);

  box-shadow:
    5px 6px 12px rgb(0 0 0 / 70%),
    -2px -2px 6px rgb(255 255 255 / 3%);

  pointer-events: auto;

  /*
   * Prevent text and controls from overflowing
   * narrow mobile screens.
   */
  overflow: hidden;

  /*
   * Improve rendering on mobile browsers.
   */
  isolation: isolate;

  animation: user-toast-enter 180ms ease-out;
}

/* ---------------------------------------------------------
   ICON
   --------------------------------------------------------- */

.user-toast-icon {
  flex: 0 0 auto;

  width: 1.35rem;
  height: 1.35rem;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  color: rgb(175 36 36);
}

.user-toast-icon svg {
  width: 1.25rem;
  height: 1.25rem;

  stroke-width: 2.25;
}

/* ---------------------------------------------------------
   MESSAGE
   --------------------------------------------------------- */

.user-toast-message {
  min-width: 0;
  flex: 1 1 auto;

  color: rgb(235 235 235);

  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;

  /*
   * Important for long messages on narrow phones.
   */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ---------------------------------------------------------
   CLOSE BUTTON
   --------------------------------------------------------- */

.user-toast-close {
  flex: 0 0 auto;

  width: 2rem;
  min-width: 2rem;

  height: 2rem;
  min-height: 2rem;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 0;

  border: 0;
  border-radius: 0.5rem;

  background: transparent;
  color: rgb(125 125 125);

  cursor: pointer;

  /*
   * Prevent the browser from showing its default
   * mobile tap highlight.
   */
  -webkit-tap-highlight-color: transparent;

  /*
   * Better touch behavior.
   */
  touch-action: manipulation;

  transition:
    color 120ms ease,
    background 120ms ease;
}

.user-toast-close svg {
  width: 1rem;
  height: 1rem;

  stroke-width: 2.25;
}

/* ---------------------------------------------------------
   CLOSE BUTTON STATES
   --------------------------------------------------------- */

.user-toast-close:active {
  color: rgb(235 235 235);
  background: rgb(255 255 255 / 5%);
}

.user-toast-close:hover {
  color: rgb(235 235 235);
  background: rgb(255 255 255 / 5%);
}

.user-toast-close:focus-visible {
  outline: 2px solid rgb(175 36 36);
  outline-offset: 2px;
}

/* ---------------------------------------------------------
   TYPES
   --------------------------------------------------------- */

.user-toast--success {
  border-color: rgb(60 170 100);
}

.user-toast--success .user-toast-icon {
  color: rgb(60 170 100);
}

.user-toast--error {
  border-color: rgb(175 36 36);
}

.user-toast--error .user-toast-icon {
  color: rgb(220 70 70);
}

.user-toast--warning {
  border-color: rgb(210 155 55);
}

.user-toast--warning .user-toast-icon {
  color: rgb(225 175 70);
}

.user-toast--info {
  border-color: rgb(75 135 200);
}

.user-toast--info .user-toast-icon {
  color: rgb(95 155 220);
}

/* ---------------------------------------------------------
   ANIMATION
   --------------------------------------------------------- */

@keyframes user-toast-enter {
  from {
    opacity: 0;
    transform: translateY(-0.35rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------------------------------------------------------
   BOTTOM POSITION ANIMATION
   --------------------------------------------------------- */

.user-toast-container--bottom-left .user-toast,
.user-toast-container--bottom-center .user-toast,
.user-toast-container--bottom-right .user-toast {
  animation-name: user-toast-enter-bottom;
}

@keyframes user-toast-enter-bottom {
  from {
    opacity: 0;
    transform: translateY(0.35rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------------------------------------------------------
   REDUCED MOTION
   --------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .user-toast {
    animation: none;
  }
}

/* ---------------------------------------------------------
   TABLET / DESKTOP
   --------------------------------------------------------- */

@media (min-width: 40rem) {
  .user-toast-container {
    width: min(calc(100vw - 2rem), 26rem);
    max-width: 26rem;
  }

  .user-toast-container--top-left {
    top: 1rem;
    left: 1rem;
  }

  .user-toast-container--top-center {
    top: 1rem;
  }

  .user-toast-container--top-right {
    top: 1rem;
    right: 1rem;
  }

  .user-toast-container--bottom-left {
    bottom: 1rem;
    left: 1rem;
  }

  .user-toast-container--bottom-center {
    bottom: 1rem;
  }

  .user-toast-container--bottom-right {
    right: 1rem;
    bottom: 1rem;
  }
}

/* ---------------------------------------------------------
   MOBILE
   --------------------------------------------------------- */

@media (max-width: 39.999rem) {
  /*
   * Full available mobile width minus safe side margins.
   */
  .user-toast-container {
    width: calc(100vw - 1.5rem);
    max-width: none;
  }

  /*
   * Use explicit left/right boundaries for top-right.
   *
   * This is intentional on mobile. It makes the container
   * behave as a full-width mobile notification region rather
   * than relying on width + right positioning.
   */
  .user-toast-container--top-right {
    top: calc(0.75rem + env(safe-area-inset-top));

    left: 0.75rem;
    right: 0.75rem;

    width: auto;
    max-width: none;

    transform: none;
  }

  .user-toast-container--top-left {
    top: calc(0.75rem + env(safe-area-inset-top));

    left: 0.75rem;
    right: 0.75rem;

    width: auto;
    max-width: none;
  }

  .user-toast-container--top-center {
    top: calc(0.75rem + env(safe-area-inset-top));

    left: 0.75rem;
    right: 0.75rem;

    width: auto;
    max-width: none;

    transform: none;
  }

  /*
   * Bottom notifications account for the mobile
   * safe-area inset.
   */
  .user-toast-container--bottom-right {
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));

    left: 0.75rem;

    width: auto;
    max-width: none;
  }

  .user-toast-container--bottom-left {
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));

    left: 0.75rem;

    width: auto;
    max-width: none;
  }

  .user-toast-container--bottom-center {
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));

    left: 0.75rem;

    width: auto;
    max-width: none;

    transform: none;
  }

  /*
   * Slightly larger touch target on phones.
   */
  .user-toast-close {
    width: 2.25rem;
    min-width: 2.25rem;

    height: 2.25rem;
    min-height: 2.25rem;
  }
}

/* ---------------------------------------------------------
   VERY SMALL PHONES
   --------------------------------------------------------- */

@media (max-width: 22rem) {
  .user-toast-container {
    left: 0.5rem;
    right: 0.5rem;

    width: auto;
  }

  .user-toast-container--top-left,
  .user-toast-container--top-center,
  .user-toast-container--top-right {
    left: 0.5rem;
    right: 0.5rem;
  }

  .user-toast-container--bottom-left,
  .user-toast-container--bottom-center,
  .user-toast-container--bottom-right {
    left: 0.5rem;
    right: 0.5rem;
  }

  .user-toast {
    padding: 0.7rem 0.75rem;
    gap: 0.625rem;
  }

  .user-toast-message {
    font-size: 0.8rem;
  }
}
