/* ------------------------------------------------------------------ toasts
   Loaded by all three layouts — site, admin and auth.

   It used to live in layout.css, which only the storefront loads. Every toast
   raised in the admin console and on the sign-in pages was therefore an
   unstyled <div> appended to the end of the document: the text was there, at
   the bottom of the page, in the body font, below the footer. "Saved" was
   being announced to nobody.

   Two things here are load-bearing rather than decorative:

   The container is a live region that exists from first paint, empty. A
   screen reader announces changes INSIDE a live region; one created at the
   moment of the message is not yet being watched, so the first toast of a
   session would be silent.

   The progress bar is a CSS animation driven by --toast-life, so pausing it
   on hover is one property change rather than arithmetic on a timer. The
   JavaScript pauses the timeout at the same moment, and the two stay honest
   with each other because both are paused by the same event.
   ------------------------------------------------------------------------ */

.toast-container{
  position: fixed;
  top: 90px;
  right: 20px;
  z-index: 900;             /* above modals, which stop at 400 */
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;     /* the gaps between toasts must not eat clicks */
}

.toast{
  pointer-events: auto;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 14px 14px 15px;
  border-radius: var(--radius-sm);
  background: rgba(20, 16, 13, .95);
  border: 1px solid var(--glass-border);
  border-left: 3px solid var(--kiln);
  box-shadow: var(--glass-shadow, 0 18px 40px rgba(0,0,0,.4));
  backdrop-filter: blur(16px);
  color: var(--bone, #f4ecdd);
  font-size: .86rem;
  overflow: hidden;
  animation: toast-in .34s cubic-bezier(.2,.8,.2,1);
  touch-action: pan-y;      /* leaves the horizontal axis to the drag handler */
}

.toast-out{ animation: toast-out .22s ease forwards; }

/* Dragged sideways to dismiss. Transform is set inline from JS; the
   transition is only here so letting go springs back. */
.toast.is-dragging{ transition: none; user-select: none; }
.toast.is-settling{ transition: transform .2s ease, opacity .2s ease; }

.toast-icon{
  width: 20px;
  height: 20px;
  flex: none;
  margin-top: 1px;
}

.toast-body{ min-width: 0; }

.toast-title{
  display: block;
  font-weight: 700;
  margin-bottom: 2px;
  line-height: 1.35;
}

.toast-message{
  display: block;
  line-height: 1.5;
  /* A pasted URL or a geocoded address has nothing to break on and would
     otherwise push the toast wider than its container. */
  overflow-wrap: anywhere;
}

.toast-count{
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(244, 236, 221, .14);
  font-family: var(--font-mono);
  font-size: .7rem;
  vertical-align: middle;
}

.toast-action{
  align-self: center;
  padding: 6px 12px;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: .78rem;
  cursor: pointer;
  white-space: nowrap;
}

.toast-action:hover{ background: rgba(244, 236, 221, .12); }

.toast-close{
  align-self: start;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--bone-dim, #b6a894);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.toast-close:hover{ color: var(--bone, #f4ecdd); background: rgba(244,236,221,.1); }

/* Where an action button is present the close button sits beside it rather
   than claiming its own column. */
.toast-tail{
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --------------------------------------------------------------- the clock */

.toast-progress{
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  transform-origin: left center;
  background: currentColor;
  opacity: .5;
  animation: toast-life linear forwards;
  animation-duration: var(--toast-life, 4200ms);
}

.toast.is-paused .toast-progress{ animation-play-state: paused; }
.toast.is-persistent .toast-progress{ display: none; }

@keyframes toast-life{ from{ transform: scaleX(1); } to{ transform: scaleX(0); } }
@keyframes toast-in{ from{ opacity:0; transform: translateX(28px) scale(.98); } to{ opacity:1; transform:none; } }
@keyframes toast-out{ from{ opacity:1; } to{ opacity:0; transform: translateX(28px); } }

/* ------------------------------------------------------------------ types */

.toast-success{ border-left-color: #4CAF7D; }
.toast-success .toast-icon{ color: #4CAF7D; }
.toast-success .toast-progress{ color: #4CAF7D; }

.toast-error{ border-left-color: var(--clay, #c23b22); }
.toast-error .toast-icon{ color: #ff8f78; }
.toast-error .toast-progress{ color: #ff8f78; }

.toast-warning{ border-left-color: var(--kiln, #c08a3e); }
.toast-warning .toast-icon{ color: var(--kiln, #c08a3e); }
.toast-warning .toast-progress{ color: var(--kiln, #c08a3e); }

.toast-info{ border-left-color: var(--kiln, #c08a3e); }
.toast-info .toast-icon{ color: var(--bone-dim, #b6a894); }
.toast-info .toast-progress{ color: var(--bone-dim, #b6a894); }

.toast-loading{ border-left-color: var(--bone-dim, #b6a894); }
.toast-loading .toast-icon{ color: var(--bone-dim, #b6a894); animation: toast-spin 1s linear infinite; }

@keyframes toast-spin{ to{ transform: rotate(360deg); } }

/* ----------------------------------------------------------------- phones */

@media (max-width: 720px){
  /* Top-anchored on a phone: the bottom of the screen is where the tab bar
     and the keyboard are, and a toast under either is a toast nobody sees. */
  .toast-container{
    top: 12px;
    left: 12px;
    right: 12px;
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce){
  .toast{ animation: none; }
  .toast-out{ animation: none; opacity: 0; }
  .toast-progress{ animation: none; display: none; }
  .toast-loading .toast-icon{ animation: none; }
  .toast.is-settling{ transition: none; }
}
