/* =====================================================================
   OSE · Toast & success message
   ---------------------------------------------------------------------
   (a) Inline status message (.toast): the contact form's result, shown
       in place under the form, no redirect. Put an EMPTY role="status"
       container in the page first and insert the .toast into it on
       submit, so screen readers announce it.
   (b) Floating toast (.toast--floating) in a fixed .toast-region: bottom
       of the screen on phones (above the sticky contact bar), bottom-end
       corner from 64em. Created by showToast() in js/components/toast.js;
       closes with its button (44px) or Escape; success toasts also leave
       by themselves after --toast-dismiss-delay (paused while hovered or
       focused). Enter / exit motion is played by toast.js from the toast
       motion tokens (transform + opacity only).

   Markup
     <div role="status">                                ← empty until submit
       <div class="toast toast--success">
         <span class="toast__icon" aria-hidden="true"></span>
         <p class="toast__message">Cảm ơn! OSE đã nhận thông tin…</p>
       </div>
     </div>

     <div class="toast-region" data-js="toast" data-toast-region>
       <div class="toast toast--floating toast--error">
         <span class="toast__icon" aria-hidden="true"></span>
         <p class="toast__message">Chưa gửi được, vui lòng thử lại…</p>
         <button class="toast__close" type="button"
                 aria-label="Đóng thông báo"></button>
       </div>
     </div>

   Tones    neutral (base) · .toast--success · .toast--error
   States   close button: default · hover · focus (:focus-visible) ·
            active (pressed)
   Tokens   --toast-* only.
   JS       data-js="toast" → js/components/toast.js (close button,
            Escape, showToast({ message, tone }) helper)
   ===================================================================== */

@layer components {
  .toast {
    --_bg: var(--toast-bg);
    --_accent: var(--toast-accent);
    --_icon: var(--toast-icon);
    display: flex;
    align-items: flex-start;
    gap: var(--toast-gap);
    padding: var(--toast-padding);
    padding-inline-start: calc(var(--toast-padding) + var(--toast-accent-width));
    border: var(--toast-border-width) solid var(--toast-border);
    border-radius: var(--toast-radius);
    background-color: var(--_bg);
    color: var(--toast-text);
    font-size: var(--toast-font-size);
    line-height: var(--toast-leading);
    box-shadow: inset var(--toast-accent-width) 0 0 var(--_accent);
  }

  .toast--success {
    --_bg: var(--toast-success-bg);
    --_accent: var(--toast-success-accent);
    --_icon: var(--toast-success-icon);
  }

  .toast--error {
    --_bg: var(--toast-error-bg);
    --_accent: var(--toast-error-accent);
    --_icon: var(--toast-error-icon);
  }

  /* Icon box is one line tall, so the icon centres on the first line. */
  .toast__icon {
    flex: none;
    inline-size: var(--toast-icon-size);
    block-size: calc(var(--toast-font-size) * var(--toast-leading));
    background-color: var(--_accent);
    -webkit-mask: var(--_icon) center / contain no-repeat;
    mask: var(--_icon) center / contain no-repeat;
  }

  .toast__message {
    flex: 1;
    min-inline-size: 0;
    overflow-wrap: break-word;
  }

  /* Floating: an opaque base under the tone wash, plus elevation. */
  .toast--floating {
    inline-size: 100%;
    max-inline-size: var(--toast-max-width);
    background-color: var(--toast-floating-bg);
    background-image: linear-gradient(var(--_bg), var(--_bg));
    box-shadow: inset var(--toast-accent-width) 0 0 var(--_accent), var(--toast-shadow);
    pointer-events: auto;
  }

  /* Close button: a 44px hit area; negative margins keep it from
     growing the toast past one line of text. */
  .toast__close {
    flex: none;
    display: grid;
    place-items: center;
    inline-size: var(--toast-close-size);
    block-size: var(--toast-close-size);
    margin-block: calc((var(--toast-font-size) * var(--toast-leading) - var(--toast-close-size)) / 2);
    margin-inline-end: calc((var(--toast-font-size) * var(--toast-leading) - var(--toast-close-size)) / 2);
    padding: 0;
    border: 0;
    border-radius: var(--toast-close-radius);
    background-color: transparent;
    color: var(--toast-close-color);
    cursor: pointer;
    transition:
      background-color var(--toast-duration) var(--toast-ease),
      box-shadow var(--toast-duration) var(--toast-ease),
      transform var(--toast-duration) var(--toast-ease);
  }

  .toast__close::before {
    content: "";
    inline-size: var(--toast-close-icon-size);
    block-size: var(--toast-close-icon-size);
    background-color: currentColor;
    -webkit-mask: var(--toast-close-icon) center / contain no-repeat;
    mask: var(--toast-close-icon) center / contain no-repeat;
  }

  @media (hover: hover) {
    .toast__close:hover {
      background-color: var(--toast-close-bg-hover);
    }
  }

  .toast__close:focus-visible {
    box-shadow: var(--toast-focus-ring);
  }

  .toast__close:active {
    background-color: var(--toast-close-bg-active);
    transform: scale(var(--toast-close-press-scale));
  }

  /* -------------------------------------------------------------------
     Region: fixed stack for floating toasts. It lets clicks through;
     only the toasts themselves take pointer events.
     ------------------------------------------------------------------- */
  .toast-region {
    --_offset: var(--toast-region-offset);
    position: fixed;
    inset-inline: var(--toast-region-inset);
    inset-block-end: var(--_offset);
    z-index: var(--toast-z);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--toast-region-gap);
    pointer-events: none;
  }

  @media (min-width: 64em) {
    .toast-region {
      --_offset: var(--toast-region-offset-lg);
      align-items: flex-end;
    }
  }

  /* Forced colours: icons paint with background-color, which the UA
     resets to Canvas; paint them in the text colour instead. */
  @media (forced-colors: active) {
    .toast__icon,
    .toast__close::before {
      forced-color-adjust: none;
      background-color: CanvasText;
    }
  }
}
