/* ==========================================================
   toast.css — app-wide toast notifications (DRY, single source
   of truth for ALL CRUD feedback: success / error / warning / info).

   Rendered by the x-toast component, which injects this stylesheet
   itself (@once) so a page only needs `<x-toast />` — no per-page
   <head> edit. It therefore loads after every page's group sheet and
   inline <style>, so nothing can accidentally override a toast. All
   selectors are namespaced under .toast-* and are used nowhere else.

   Do NOT redeclare .toast* in a page or group stylesheet.
   ========================================================== */

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10000; /* above modals/drawers (max in app: 9999) */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  /* the container spans a column of the viewport; only the toasts
     themselves are interactive, so clicks pass through the gaps. */
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 14px;
  border-radius: var(--radius-sm, 10px);
  border: 1px solid var(--border, #e2e8f0);
  border-left: 4px solid var(--toast-accent);
  background: var(--bg-card, #fff);
  box-shadow: 0 8px 28px rgba(15, 32, 68, 0.14);
  color: var(--text-main, #0f2044);
  font-family: inherit;
  animation: toast-in 0.28s cubic-bezier(0.21, 1.02, 0.73, 1) both;
}

/* type accents — mirror the app palette (base.css tokens) */
.toast-success { --toast-accent: var(--green, #16a34a);       --toast-tint: #dcfce7; }
.toast-error   { --toast-accent: var(--red, #dc2626);         --toast-tint: #fee2e2; }
.toast-warning { --toast-accent: var(--amber, #f59e0b);       --toast-tint: #fef3c7; }
.toast-info    { --toast-accent: var(--blue-accent, #2563eb); --toast-tint: #dbeafe; }

.toast-icon {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--toast-tint);
  color: var(--toast-accent);
}

.toast-body {
  flex: 1;
  /* long unbroken words (IDs, emails) wrap instead of widening the toast */
  min-width: 0;
}

.toast-title {
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.3;
  color: var(--toast-accent);
}

.toast-message {
  margin-top: 2px;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text-muted, #64748b);
}

.toast-close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.toast-close:hover { background: var(--bg, #f1f5fb); color: var(--text-main, #0f2044); }

/* auto-dismiss countdown; paused (via .toast-paused) on hover/focus so a
   toast can never disappear while it is being read or reached for. */
.toast-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  transform-origin: left;
  background: var(--toast-accent);
  opacity: 0.35;
  animation: toast-timer linear both;
  animation-duration: var(--toast-duration, 4000ms);
}

.toast { position: relative; overflow: hidden; }
.toast-paused .toast-timer { animation-play-state: paused; }

/* exit — set by JS, which removes the node on animationend */
.toast-leaving { animation: toast-out 0.2s ease-in both; }

/* re-fire of an already-visible toast (duplicate suppressed): pulse the
   existing one instead of stacking a second copy of the same message. */
.toast-repeat { animation: toast-pulse 0.3s ease-out; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0) scale(1); max-height: 200px; }
  to   { opacity: 0; transform: translateX(24px) scale(0.96); max-height: 0; padding-top: 0; padding-bottom: 0; margin-top: -10px; }
}

@keyframes toast-pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@keyframes toast-timer {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* ── tablet / mobile: full-width stack pinned under the sticky header ── */
@media (max-width: 640px) {
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
    width: auto;
    align-items: stretch;
  }
  .toast { padding: 12px; }
  .toast-message { font-size: 0.82rem; }
}

/* iOS safe-area (notch / dynamic island) on phones held in landscape */
@supports (padding: max(0px)) {
  @media (max-width: 640px) {
    .toast-container {
      top: max(10px, env(safe-area-inset-top));
      left: max(10px, env(safe-area-inset-left));
      right: max(10px, env(safe-area-inset-right));
    }
  }
}

/* ── reduced motion: keep the toast (it carries the CRUD result) but
   drop the movement; the timer bar still runs so auto-dismiss works. ── */
@media (prefers-reduced-motion: reduce) {
  .toast, .toast-leaving, .toast-repeat { animation: none; }
  .toast-leaving { opacity: 0; }
}
