/* ==========================================================================
   Toast Color Variables (Light Mode Default)
   ========================================================================== */
:root, [data-bs-theme="light"] {
  --toast-bg: rgba(255, 255, 255, 0.85);
  --toast-icon-bg: #f8fafc;
  --toast-title-color: #0f172a;
  --toast-msg-color: #64748b;
  --toast-progress-bg: rgba(0, 0, 0, 0.04);
  --toast-shadow: 0 10px 30px rgba(0, 0, 0, 0.08), 0 2px 10px rgba(0, 0, 0, 0.04);
  --toast-shadow-hover: 0 14px 34px rgba(0, 0, 0, 0.12), 0 4px 14px rgba(0, 0, 0, 0.06);
  --toast-close-invert: 0; /* Default close button color */
}

/* Dark Mode Variables (Triggers via System Settings OR Bootstrap Dark Data Attribute) */
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) {
    --toast-bg: rgba(30, 41, 59, 0.85);
    --toast-icon-bg: #0f172a;
    --toast-title-color: #f8fafc;
    --toast-msg-color: #94a3b8;
    --toast-progress-bg: rgba(255, 255, 255, 0.08);
    --toast-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 2px 10px rgba(0, 0, 0, 0.2);
    --toast-shadow-hover: 0 14px 34px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.25);
    --toast-close-invert: 1; /* Flips close button to white */
  }
}

[data-bs-theme="dark"] {
  --toast-bg: rgba(30, 41, 59, 0.85);
  --toast-icon-bg: #0f172a;
  --toast-title-color: #f8fafc;
  --toast-msg-color: #94a3b8;
  --toast-progress-bg: rgba(255, 255, 255, 0.08);
  --toast-shadow: 0 10px 30px rgba(0, 0, 0, 0.3), 0 2px 10px rgba(0, 0, 0, 0.2);
  --toast-shadow-hover: 0 14px 34px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.25);
  --toast-close-invert: 1;
}

/* ==========================================================================
   Refactored Components
   ========================================================================== */

.custom-toast-wrapper {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1080;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

/* Toast Card Component */
.modern-toast {
  pointer-events: auto;
  border: none;
  border-radius: 18px;
  overflow: hidden;
  background: var(--toast-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--toast-shadow);
  animation: toastSlideIn 0.45s ease;
  transition: all 0.3s ease;
}

.modern-toast:hover {
  transform: translateY(-2px);
  box-shadow: var(--toast-shadow-hover);
}

.toast-inner {
  padding: 14px 16px;
}

/* Dynamic Icon Circle Base */
.toast-icon-bg {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--toast-icon-bg);
  flex-shrink: 0;
  transition: background-color 0.3s ease;
}

/* Dynamic Content Elements */
.toast-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--toast-title-color);
  transition: color 0.3s ease;
}

.toast-message {
  font-size: 0.83rem;
  color: var(--toast-msg-color);
  margin-top: 2px;
  line-height: 1.4;
  transition: color 0.3s ease;
}

/* Theme-Aware Close Button */
.modern-toast .btn-close {
  opacity: 0.5;
  filter: invert(var(--toast-close-invert));
  transition: all 0.2s ease;
}

.modern-toast .btn-close:hover {
  opacity: 1;
  transform: scale(1.05);
}

/* Dynamic Progress Bar Config */
.toast-progress-container {
  height: 4px;
  background: var(--toast-progress-bg);
  width: 100%;
  overflow: hidden;
}

.toast-progress-bar {
  height: 100%;
  width: 100%;
  animation: toastProgress 5s linear forwards;
}

/* Edge Accents */
.toast-success { border-left: 4px solid #22c55e; }
.toast-danger, .toast-error { border-left: 4px solid #ef4444; }
.toast-warning { border-left: 4px solid #f59e0b; }
.toast-info { border-left: 4px solid #3b82f6; }

/* Responsive adjustments */
@media (max-width: 768px) {
  .custom-toast-wrapper {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: unset;
  }
}

/* Core Animations Framework Tokens */
@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastProgress {
  from { width: 100%; }
  to { width: 0%; }
}