/*!
 * THK Verlag — Cart-Toast & Cart-Badge-Feedback (v0.20.0.1)
 *
 * Visuelles Feedback beim Hinzufügen in den Warenkorb:
 *   - Toast-Notification rechts unten (slide-in von rechts)
 *   - Cart-Badge "Bump"-Animation (scale + bordeaux-flash)
 *   - Cart-Link Pulse (subtiler Ring um das Warenkorb-Icon)
 *
 * Eingebunden im site_head.php nach site.css, damit Variablen
 * (--thk-bordeaux, --space-*) verfügbar sind und der Cascade greift.
 *
 * Reduced-Motion respektiert: bei prefers-reduced-motion=reduce werden
 * Animationen durch einen einfachen Fade-In ersetzt.
 */

/* ── Toast-Container ─────────────────────────────────────────────── */
/* Position: oben rechts, unterhalb des Sticky-Headers (~5.5rem
   Kompensation für Header-Padding + Inhalt). Bewusst NICHT unten
   rechts — dort sitzt das Trusted-Shops-Trustbadge als fixed-Overlay,
   das wir nicht verdecken (und nicht von ihm verdeckt werden) wollen.
   Zusätzlicher Pluspunkt: der Toast steht jetzt in direkter Sichtachse
   zum Cart-Badge oben rechts — der visuelle Zusammenhang
   „Bestätigung + Badge-Update" wird so unmittelbar erkannt. */
.thk-toast-wrap {
  position: fixed;
  z-index: 9000;
  right: 1rem;
  top: 5.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: calc(100vw - 2rem);
  width: 360px;
}

/* Mobile: vollbreit oben, deutlich näher am Rand, damit der Toast nicht
   hinter dem Hamburger-Menü-Drawer landet, wenn der parallel offen wäre. */
@media (max-width: 600px) {
  .thk-toast-wrap {
    right: 0.5rem;
    left: 0.5rem;
    top: 0.75rem;
    width: auto;
    max-width: none;
    align-items: stretch;
  }
}

/* ── Toast-Karte ─────────────────────────────────────────────────── */
.thk-toast {
  pointer-events: auto;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
  border-left: 4px solid #6a994e;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.95rem;
  line-height: 1.35;
  color: #222;
  animation: thk-toast-in 280ms cubic-bezier(0.16, 1, 0.3, 1) both;
  opacity: 1;
  transition: opacity 220ms ease, transform 220ms ease;
}
.thk-toast--error    { border-left-color: #b3261e; }
.thk-toast--info     { border-left-color: #3a6db0; }
.thk-toast--warning  { border-left-color: #b58105; }

.thk-toast.is-leaving {
  opacity: 0;
  transform: translateX(20px);
}

.thk-toast__icon {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #eef4ee;
  color: #5a8442;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  line-height: 1;
}
.thk-toast--error .thk-toast__icon   { background: #fbeae9; color: #b3261e; }
.thk-toast--info .thk-toast__icon    { background: #e3edf7; color: #3a6db0; }
.thk-toast--warning .thk-toast__icon { background: #fdf3da; color: #8a6209; }

.thk-toast__body {
  flex: 1 1 auto;
  min-width: 0;
}
.thk-toast__title {
  font-weight: 600;
  margin: 0 0 0.1rem 0;
  color: #111;
}
.thk-toast__message {
  margin: 0;
  word-wrap: break-word;
}
.thk-toast__actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}
.thk-toast__action {
  display: inline-block;
  padding: 0.35rem 0.7rem;
  border-radius: 4px;
  background: var(--thk-bordeaux, #7a0f1e);
  color: #fff !important;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.2;
  transition: background 150ms ease, transform 80ms ease;
}
.thk-toast__action:hover { background: #5d0b16; }
.thk-toast__action:active { transform: translateY(1px); }
.thk-toast__action--ghost {
  background: transparent;
  color: #555 !important;
  border: 1px solid #d0d0d0;
}
.thk-toast__action--ghost:hover {
  background: #f4f4f4;
}

.thk-toast__close {
  flex: 0 0 auto;
  background: none;
  border: 0;
  color: #888;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0 0 0.25rem;
  margin: -0.15rem -0.25rem 0 0;
}
.thk-toast__close:hover { color: #222; }

/* ── Toast-Eingangs-Animation ───────────────────────────────────── */
@keyframes thk-toast-in {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@media (max-width: 600px) {
  @keyframes thk-toast-in {
    from { opacity: 0; transform: translateY(-20px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

/* ── Cart-Badge-Bump beim Hinzufügen ─────────────────────────────── */
.site-nav__cart-badge--bump,
.site-header__cart-mobile-badge--bump {
  animation: thk-badge-bump 600ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes thk-badge-bump {
  0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(122, 15, 30, 0.55); }
  25%  { transform: scale(1.4);  box-shadow: 0 0 0 6px rgba(122, 15, 30, 0.20); }
  50%  { transform: scale(0.95); box-shadow: 0 0 0 10px rgba(122, 15, 30, 0.05); }
  75%  { transform: scale(1.1);  box-shadow: 0 0 0 12px rgba(122, 15, 30, 0.00); }
  100% { transform: scale(1);    box-shadow: 0 0 0 0 rgba(122, 15, 30, 0.00); }
}

/* Variante ohne Pre-existing-Badge: das Badge wird beim ersten Add
   erst ins DOM eingefügt, also gibt es nichts zum Bumpen. In dem
   Fall pulst das ganze Cart-Icon kurz. */
.site-nav__cart--pulse > [aria-hidden="true"],
.site-header__cart-mobile--pulse > [aria-hidden="true"] {
  animation: thk-cart-pulse 700ms ease-out both;
  display: inline-block;
}
@keyframes thk-cart-pulse {
  0%   { transform: scale(1)    rotate(0); }
  25%  { transform: scale(1.25) rotate(-8deg); }
  60%  { transform: scale(0.95) rotate(4deg); }
  100% { transform: scale(1)    rotate(0); }
}

/* ── Reduced-Motion respektieren ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .thk-toast {
    animation: thk-toast-fade-in 180ms ease both;
  }
  @keyframes thk-toast-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
  .site-nav__cart-badge--bump,
  .site-header__cart-mobile-badge--bump,
  .site-nav__cart--pulse > [aria-hidden="true"],
  .site-header__cart-mobile--pulse > [aria-hidden="true"] {
    animation: none;
  }
}

/* ── Loading-State des Buy-Buttons ───────────────────────────────── */
.book__buy-btn.is-loading,
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  cursor: wait;
}
.book__buy-btn.is-loading::after,
.btn.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.1em;
  height: 1.1em;
  margin: -0.55em 0 0 -0.55em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: #fff;
  animation: thk-spin 720ms linear infinite;
}
@keyframes thk-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .book__buy-btn.is-loading::after,
  .btn.is-loading::after {
    animation: none;
    border-top-color: currentColor;
    opacity: 0.5;
  }
}
