/*
 * ═══════════════════════════════════════════════════════════════
 * 🔔 Toast Notification System — Enterprise-Grade
 * Inspired by Stripe, Google Material 3, Apple HIG, Linear
 * Glassmorphism + Micro-animations + Full Responsive
 * ═══════════════════════════════════════════════════════════════
 */

/* ─── Toast Container ─────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--header-height, 60px) + 16px);
  right: 16px;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: 420px;
  width: calc(100% - 32px);
}

/* ─── Individual Toast ────────────────────────────────────── */
.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  border-radius: 14px;
  pointer-events: auto;
  overflow: hidden;
  cursor: default;
  width: 100%;

  /* Glassmorphism Base */
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.08),
    0 2px 8px rgba(0, 0, 0, 0.04),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);

  /* Entry Animation */
  animation: toast-slide-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  transform: translateX(120%);
  opacity: 0;
}

/* Dark Mode Toast */
html.dark .toast {
  background: rgba(30, 36, 54, 0.92);
  border-color: rgba(255, 255, 255, 0.06);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.3),
    0 2px 8px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* ─── Accent Bar (Left Edge) ─────────────────────────────── */
.toast::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 4px 0 0 4px;
}

/* ─── Type Variants ──────────────────────────────────────── */

/* SUCCESS */
.toast--success::before {
  background: linear-gradient(180deg, #34d399, #10b981);
}
.toast--success .toast__icon {
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  color: #059669;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}
html.dark .toast--success .toast__icon {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(52, 211, 153, 0.15));
  color: #34d399;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.15);
}

/* ERROR */
.toast--error::before {
  background: linear-gradient(180deg, #f87171, #ef4444);
}
.toast--error .toast__icon {
  background: linear-gradient(135deg, #fee2e2, #fecaca);
  color: #dc2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}
html.dark .toast--error .toast__icon {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(248, 113, 113, 0.15));
  color: #f87171;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
}

/* WARNING */
.toast--warning::before {
  background: linear-gradient(180deg, #fbbf24, #f59e0b);
}
.toast--warning .toast__icon {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #d97706;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
}
html.dark .toast--warning .toast__icon {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(251, 191, 36, 0.15));
  color: #fbbf24;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.15);
}

/* INFO */
.toast--info::before {
  background: linear-gradient(180deg, #60a5fa, #3b82f6);
}
.toast--info .toast__icon {
  background: linear-gradient(135deg, #dbeafe, #bfdbfe);
  color: #2563eb;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}
html.dark .toast--info .toast__icon {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(96, 165, 250, 0.15));
  color: #60a5fa;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

/* ─── Icon Badge ─────────────────────────────────────────── */
.toast__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 12px;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.toast:hover .toast__icon {
  transform: scale(1.08);
}

/* Animated checkmark for success */
.toast--success .toast__icon i {
  animation: toast-icon-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.3s both;
}

/* Shake for error */
.toast--error .toast__icon i {
  animation: toast-icon-shake 0.5s ease 0.3s both;
}

/* Bounce for warning */
.toast--warning .toast__icon i {
  animation: toast-icon-bounce 0.5s ease 0.3s both;
}

/* ─── Content ────────────────────────────────────────────── */
.toast__content {
  flex: 1;
  min-width: 0;
}

.toast__title {
  font-family: var(--font-display, 'Outfit', sans-serif);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main, #212B36);
  line-height: 1.3;
  margin-bottom: 2px;
}

html.dark .toast__title {
  color: #f1f5f9;
}

.toast__message {
  font-family: var(--font-body, 'Inter', sans-serif);
  font-size: 0.82rem;
  color: var(--text-muted, #637381);
  line-height: 1.5;
  word-break: break-word;
}

html.dark .toast__message {
  color: #94a3b8;
}

/* ─── Close Button ───────────────────────────────────────── */
.toast__close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--gray-400, #919EAB);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s ease;
  opacity: 0;
  transform: scale(0.8);
  -webkit-tap-highlight-color: transparent;
}

.toast:hover .toast__close {
  opacity: 1;
  transform: scale(1);
}

/* Always show close on touch devices */
@media (hover: none) {
  .toast__close {
    opacity: 0.6;
    transform: scale(1);
  }
}

.toast__close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-main, #212B36);
}

html.dark .toast__close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
}

/* ─── Progress Bar ───────────────────────────────────────── */
.toast__progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 0 14px 14px;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.toast:hover .toast__progress {
  animation-play-state: paused !important;
}

.toast--success .toast__progress {
  background: linear-gradient(90deg, #10b981, #34d399);
}
.toast--error .toast__progress {
  background: linear-gradient(90deg, #ef4444, #f87171);
}
.toast--warning .toast__progress {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}
.toast--info .toast__progress {
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

/* ─── Action Button (optional) ───────────────────────────── */
.toast__action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.toast--success .toast__action {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}
.toast--success .toast__action:hover {
  background: rgba(16, 185, 129, 0.2);
}

.toast--error .toast__action {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
}
.toast--error .toast__action:hover {
  background: rgba(239, 68, 68, 0.2);
}

.toast--warning .toast__action {
  background: rgba(245, 158, 11, 0.12);
  color: #d97706;
}
.toast--warning .toast__action:hover {
  background: rgba(245, 158, 11, 0.2);
}

.toast--info .toast__action {
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
}
.toast--info .toast__action:hover {
  background: rgba(59, 130, 246, 0.2);
}

html.dark .toast--success .toast__action { color: #34d399; }
html.dark .toast--error .toast__action { color: #f87171; }
html.dark .toast--warning .toast__action { color: #fbbf24; }
html.dark .toast--info .toast__action { color: #60a5fa; }

/* ═══════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════ */

@keyframes toast-slide-in {
  0% {
    transform: translateX(120%);
    opacity: 0;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toast-slide-out {
  0% {
    transform: translateX(0);
    opacity: 1;
    max-height: 200px;
    margin-bottom: 10px;
  }
  60% {
    transform: translateX(110%);
    opacity: 0;
  }
  100% {
    transform: translateX(110%);
    opacity: 0;
    max-height: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
  }
}

@keyframes toast-progress {
  from { width: 100%; }
  to { width: 0%; }
}

@keyframes toast-icon-pop {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes toast-icon-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

@keyframes toast-icon-bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
  60% { transform: translateY(2px); }
}

/* Toast leaving */
.toast--leaving {
  animation: toast-slide-out 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE — Mobile-First
   ═══════════════════════════════════════════════════════════ */

/* Mobile: Full width, bottom-anchored for thumb reach */
@media (max-width: 576px) {
  .toast-container {
    top: auto;
    bottom: calc(var(--safe-bottom, 0px) + 16px);
    left: 12px;
    right: 12px;
    max-width: 100%;
    width: auto;
    flex-direction: column-reverse;
  }

  .toast {
    padding: 14px 16px;
    border-radius: 12px;
    gap: 12px;
    animation-name: toast-slide-up;
  }

  .toast--leaving {
    animation-name: toast-slide-down;
  }

  .toast__icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 10px;
    font-size: 1rem;
  }

  .toast__title {
    font-size: 0.85rem;
  }

  .toast__message {
    font-size: 0.8rem;
  }

  .toast__close {
    opacity: 0.5;
    transform: scale(1);
    top: 8px;
    right: 8px;
  }
}

/* Mobile animation: slide from bottom */
@keyframes toast-slide-up {
  0% {
    transform: translateY(120%);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes toast-slide-down {
  0% {
    transform: translateY(0);
    opacity: 1;
    max-height: 200px;
    margin-bottom: 10px;
  }
  60% {
    transform: translateY(110%);
    opacity: 0;
  }
  100% {
    transform: translateY(110%);
    opacity: 0;
    max-height: 0;
    margin-bottom: 0;
    padding-top: 0;
    padding-bottom: 0;
  }
}

/* Tablet */
@media (min-width: 577px) and (max-width: 768px) {
  .toast-container {
    max-width: 380px;
    right: 16px;
  }
}

/* Large desktop */
@media (min-width: 1200px) {
  .toast-container {
    max-width: 440px;
    right: 24px;
  }
}

/* ═══════════════════════════════════════════════════════════
   ACCESSIBILITY — Reduced Motion
   ═══════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .toast {
    animation-duration: 0.01ms !important;
  }
  .toast--leaving {
    animation-duration: 0.01ms !important;
  }
  .toast__icon i {
    animation: none !important;
  }
  .toast__progress {
    animation-duration: 0.01ms !important;
  }
}
