/* One structural recipe for the public and console hosts. Neutral palette and
   tone tokens stay layered so the public brand mapping in components.css wins.
   The explicit console host maps its neutral tokens to the design system.
   Action variants and prose rules are unlayered to outrank generic controls. */
@layer components {
  .toasts {
    --toast-bg: #FFFFFF;
    --toast-fg: #52525B;
    --toast-line: #E4E4E7;
    --toast-radius: 12px;
    --toast-shadow: 0 4px 12px rgb(0 0 0 / .08);
    --toast-clearance: 0px;       /* set by the script from the page's bottom bar */
    --toast-gap: 1rem;            /* M177: the space under the stack, .75rem on a phone */

    position: fixed;
    z-index: var(--toast-z, 50);  /* over the console's phone drawer (39) and save bar (30) */
    right: 1rem;
    bottom: calc(var(--toast-gap) + var(--tabbar-h, 0px) + var(--toast-clearance));  /* M177: --tabbar-h is the console's bottom menu, 0 elsewhere */
    display: flex;
    flex-direction: column-reverse;  /* the newest card sits nearest the corner */
    gap: .5rem;
    width: min(24rem, calc(100vw - 2rem));
    pointer-events: none;
  }
  .toast-card {
    pointer-events: auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: start;
    column-gap: .625rem;
    padding: .75rem .875rem;
    background: var(--toast-bg);
    color: var(--toast-fg);
    border: 1px solid var(--toast-tone-line, var(--toast-line));
    border-radius: var(--toast-radius);
    box-shadow: var(--toast-shadow);
    animation: toast-in 300ms cubic-bezier(.2, 0, .2, 1) both;
  }
  .toast-card--success { --toast-tone: var(--toast-success-tone, #15803D); --toast-tone-line: #C6E6CE; }
  .toast-card--info    { --toast-tone: var(--toast-info-tone, #1D4ED8); --toast-tone-line: #C9D8F2; }
  .toast-card--warning { --toast-tone: var(--toast-warning-tone, #B45309); --toast-tone-line: #EEDCB5; }
  .toast-card--error   { --toast-tone: var(--toast-error-tone, #B91C1C); --toast-tone-line: #F0C9C4; }
  .toasts--console, .toast-card[data-toast-frozen] {
    --toast-bg: var(--c-paper, #fff);
    --toast-fg: var(--c-text, #52525b);
    --toast-line: var(--c-control-border, #e4e4e7);
    --toast-success-tone: var(--c-success-dark);
    --toast-info-tone: var(--c-info-dark);
    --toast-warning-tone: var(--c-warning-dark);
    --toast-error-tone: var(--c-error-dark);
    --toast-close-color: var(--c-base-dark);
    --toast-close-hover-bg: var(--c-surface);
    --toast-close-hover-color: var(--c-text);
    --toast-focus: var(--c-focus);
  }
  html[data-appearance="dark"] .toasts--console,
  html[data-appearance="dark"] .toast-card[data-toast-frozen] {
    /* The existing status error tone, paired with the dark paper. */
    --toast-error-tone: #f3998a;
  }
  .toasts--specimen { position: static; width: 100%; }
  .toast-card [hidden] { display: none; }
  .toast-card[data-toast-frozen] { animation: none; background: var(--c-paper, #fff); color: var(--c-text, #52525b); }
  .toast-card--leaving { animation: toast-out 200ms cubic-bezier(.2, 0, .2, 1) both; }

  @keyframes toast-in { from { opacity: 0; transform: translateY(50px) scale(.95); } to { opacity: 1; transform: none; } }
  @keyframes toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(20px); } }
  @media (prefers-reduced-motion: reduce) {
    .toast-card, .toast-card--leaving { animation: none; }
  }
  @media (max-width: 42.5rem) {
    .toasts { --toast-gap: .75rem; left: .75rem; right: .75rem; width: auto; }
  }
}

/* Button variants are unlayered so generic USWDS button rules cannot win. */
  .usa-button.usa-button--toast-undo, .usa-button.usa-button--toast-dismiss { margin: 0; min-width: 0; min-height: 0; width: auto; box-shadow: none; font-family: inherit; letter-spacing: normal; text-transform: none; }
  .usa-button.usa-button--toast-undo { grid-column: 2; justify-self: start; margin-top: .375rem; padding: 0; border: 0; background: none; font: inherit; font-size: .875rem; font-weight: 600; color: var(--toast-undo-color, inherit); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
  .usa-button.usa-button--toast-undo:hover,
  .usa-button.usa-button--toast-undo:active,
  .usa-button.usa-button--toast-undo.usa-button--hover,
  .usa-button.usa-button--toast-undo.usa-button--active { color: var(--toast-tone); background: transparent; }
  .usa-button.usa-button--toast-dismiss { grid-column: 3; grid-row: 1; position: relative; width: 1.375rem; height: 1.375rem; padding: 0; border: 0; border-radius: 4px; background: none; color: var(--toast-close-color, #71717A); font-size: 1rem; line-height: 1; cursor: pointer; }
  .usa-button.usa-button--toast-dismiss:hover,
  .usa-button.usa-button--toast-dismiss:active,
  .usa-button.usa-button--toast-dismiss.usa-button--hover,
  .usa-button.usa-button--toast-dismiss.usa-button--active { background: var(--toast-close-hover-bg, #F4F4F5); color: var(--toast-close-hover-color, #18181B); }
  .usa-button.usa-button--toast-undo:focus-visible, .usa-button.usa-button--toast-dismiss:focus-visible, .usa-button.usa-button--toast-undo.usa-focus, .usa-button.usa-button--toast-dismiss.usa-focus { outline: 2px solid var(--toast-focus, var(--toast-tone)); outline-offset: 2px; }

/* Transient text and icons retain their recipe beside generic console prose. */
  .toast-card__icon { grid-row: 1 / span 2; width: 1.125rem; height: 1.125rem; margin-top: .0625rem; color: var(--toast-tone); flex: 0 0 auto; }
  .toast-card__title { grid-column: 2; margin: 0; font-size: .875rem; font-weight: 600; line-height: 1.35; color: var(--toast-tone); }
  .toast-card__text { grid-column: 2; font-size: .875rem; font-weight: 400; line-height: 1.4; margin: 0; }
  .toast-card__title:not([hidden]) + .toast-card__text { margin-top: .125rem; }
