/* ═══════════════════════════════════════════════════════════════
   EVIDENT — Toast & Notification System
   
   Critical for Pipeline v2.0 feedback:
   - Worker initialization success/failure
   - Model download complete
   - File processing errors
   - Background task updates
   
   Features:
   - 4 variants: success, error, warning, info
   - Auto-dismiss with progress bar
   - Action buttons support
   - Stacking/positioning
   - Reduced motion support
   ═══════════════════════════════════════════════════════════════ */

/* ── Toast Container ────────────────────────────────────────── */
.toast-container {
  position: fixed;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
  padding: 1rem;
}

/* Positions */
.toast-container--top-right {
  top: 0;
  right: 0;
}

.toast-container--top-left {
  top: 0;
  left: 0;
}

.toast-container--bottom-right {
  bottom: 0;
  right: 0;
  flex-direction: column-reverse;
}

.toast-container--bottom-left {
  bottom: 0;
  left: 0;
  flex-direction: column-reverse;
}

.toast-container--top-center {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

.toast-container--bottom-center {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column-reverse;
}

/* Mobile: full width at bottom */
@media (width <= 640px) {
  .toast-container {
    left: 0;
    right: 0;
    padding: 0.75rem;
  }

  .toast-container--top-right,
  .toast-container--top-left,
  .toast-container--top-center {
    top: auto;
    bottom: 0;
    transform: none;
    flex-direction: column-reverse;
  }

  .toast-container--bottom-right,
  .toast-container--bottom-left,
  .toast-container--bottom-center {
    transform: none;
  }
}

/* ── Toast Base ──────────────────────────────────────────────── */
.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem 1.25rem;
  background: white;
  border-radius: 12px;
  box-shadow:
    0 4px 6px -1px rgb(0 0 0 / 10%),
    0 10px 15px -3px rgb(0 0 0 / 10%),
    0 20px 25px -5px rgb(0 0 0 / 5%);
  border-left: 4px solid;
  pointer-events: auto;
  min-width: 320px;
  max-width: 480px;
  animation: toast-in 0.4s var(--ease-spring, cubic-bezier(0.22, 1, 0.36, 1));
}

@media (width <= 640px) {
  .toast {
    min-width: auto;
    max-width: none;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

/* Exit animation */
.toast--exiting {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
  }
}

/* ── Toast Variants ──────────────────────────────────────────── */

/* Success - Green */
.toast--success {
  border-left-color: #22c55e;
}

.toast--success .toast__icon {
  color: #22c55e;
}

/* Error - Red */
.toast--error {
  border-left-color: #ef4444;
}

.toast--error .toast__icon {
  color: #ef4444;
}

/* Warning - Amber */
.toast--warning {
  border-left-color: #f59e0b;
}

.toast--warning .toast__icon {
  color: #f59e0b;
}

/* Info - Blue */
.toast--info {
  border-left-color: #3b82f6;
}

.toast--info .toast__icon {
  color: #3b82f6;
}

/* ── Toast Structure ─────────────────────────────────────────── */
.toast__icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-top: 0.125rem;
}

.toast__content {
  flex: 1;
  min-width: 0;
}

.toast__title {
  font-weight: 600;
  font-size: 0.9375rem;
  color: #111827;
  margin: 0 0 0.25rem;
}

.toast__message {
  font-size: 0.875rem;
  color: #6b7280;
  margin: 0;
  line-height: 1.5;
}

.toast__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.toast__action {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.toast__action--primary {
  background: #3b82f6;
  color: white;
  border: none;
}

.toast__action--primary:hover {
  background: #2563eb;
}

.toast__action--secondary {
  background: transparent;
  color: #6b7280;
  border: 1px solid #e5e7eb;
}

.toast__action--secondary:hover {
  background: #f3f4f6;
  color: #374151;
}

/* ── Toast Close Button ──────────────────────────────────────── */
.toast__close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: #9ca3af;
  transition: all 0.15s ease;
  margin: -0.25rem -0.5rem -0.25rem 0;
}

.toast__close:hover {
  background: #f3f4f6;
  color: #374151;
}

/* ── Auto-Dismiss Progress ──────────────────────────────────── */
.toast__progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgb(0 0 0 / 5%);
  border-radius: 0 0 12px 12px;
  overflow: hidden;
}

.toast__progress-bar {
  height: 100%;
  background: currentcolor;
  opacity: 0.3;
  transform-origin: left;
  animation: toast-progress linear forwards;
}

@keyframes toast-progress {
  from {
    transform: scaleX(1);
  }

  to {
    transform: scaleX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast__progress-bar {
    animation: none;
    transform: scaleX(0);
  }
}

/* Variant progress colors */
.toast--success .toast__progress-bar {
  color: #22c55e;
}

.toast--error .toast__progress-bar {
  color: #ef4444;
}

.toast--warning .toast__progress-bar {
  color: #f59e0b;
}

.toast--info .toast__progress-bar {
  color: #3b82f6;
}

/* ── Persistent Toast (No auto-dismiss) ─────────────────────── */
.toast--persistent .toast__progress {
  display: none;
}

/* ── Compact Toast (for batch operations) ───────────────────── */
.toast--compact {
  padding: 0.75rem 1rem;
  min-width: auto;
}

.toast--compact .toast__icon {
  width: 20px;
  height: 20px;
}

.toast--compact .toast__title {
  font-size: 0.875rem;
}

.toast--compact .toast__message {
  font-size: 0.8125rem;
}

/* ── Toast with Progress Info ──────────────────────────────── */
.toast--with-progress {
  padding-bottom: 1.5rem;
}

.toast__progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: #6b7280;
}

.toast__progress-bar--detailed {
  margin-top: 0.5rem;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
}

.toast__progress-fill {
  height: 100%;
  background: currentcolor;
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ── Pipeline-Specific Toast Variants ───────────────────────── */

/* Worker initialized */
.toast--worker-ready {
  border-left-color: #8b5cf6;
}

.toast--worker-ready .toast__icon {
  color: #8b5cf6;
}

/* Model downloaded */
.toast--model-ready {
  border-left-color: #06b6d4;
}

.toast--model-ready .toast__icon {
  color: #06b6d4;
}

/* Processing complete */
.toast--processing-complete {
  border-left-color: #10b981;
}

.toast--processing-complete .toast__icon {
  color: #10b981;
}

/* Worker error (needs restart) */
.toast--worker-error {
  border-left-color: #dc2626;
  background: #fef2f2;
}

.toast--worker-error .toast__icon {
  color: #dc2626;
}

/* ── Notification Banner (inline, not toast) ────────────────── */
.notification-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
}

.notification-banner--success {
  background: #f0fdf4;
  color: #166534;
}

.notification-banner--error {
  background: #fef2f2;
  color: #991b1b;
}

.notification-banner--warning {
  background: #fffbeb;
  color: #92400e;
}

.notification-banner--info {
  background: #eff6ff;
  color: #1e40af;
}

.notification-banner__icon {
  flex-shrink: 0;
}

.notification-banner__content {
  flex: 1;
}

.notification-banner__close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  color: currentcolor;
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.notification-banner__close:hover {
  opacity: 1;
}

/* ── Inline Alert (for forms) ─────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
}

.alert--success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert--error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert--warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert--info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.alert__icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 0.125rem;
}

.alert__content {
  flex: 1;
}

.alert__title {
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.alert__message {
  margin: 0;
}

.alert__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* ── Premium Glass Toast (v2) ────────────────────────────────── */
/* Glass morphism upgrade for premium feel. Applied via .toast--glass */
.toast--glass {
  background: color-mix(in srgb, var(--color-surface, #ffffff) 85%, transparent);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid color-mix(in srgb, var(--color-on-surface, #0f172a) 8%, transparent);
  box-shadow:
    0 8px 32px rgb(0 0 0 / 12%),
    0 0 0 1px color-mix(in srgb, var(--color-on-surface, #0f172a) 4%, transparent),
    inset 0 1px 0 color-mix(in srgb, var(--color-on-surface, #0f172a) 4%, transparent);
}

.toast--glass .toast__title {
  color: var(--color-on-surface, #111827);
}

.toast--glass .toast__message {
  color: var(--color-on-surface-muted, #6b7280);
}

.toast--glass .toast__close:hover {
  background: color-mix(in srgb, var(--color-on-surface, #0f172a) 6%, transparent);
}

/* Glass variant accent glow */
.toast--glass.toast--success {
  border-left-color: var(--color-emerald, #22c55e);
  box-shadow:
    0 8px 32px rgb(0 0 0 / 12%),
    0 0 0 1px color-mix(in srgb, var(--color-emerald, #22c55e) 15%, transparent);
}

.toast--glass.toast--error {
  border-left-color: var(--color-ruby, #ef4444);
  box-shadow:
    0 8px 32px rgb(0 0 0 / 12%),
    0 0 0 1px color-mix(in srgb, var(--color-ruby, #ef4444) 15%, transparent);
}

.toast--glass.toast--warning {
  border-left-color: var(--color-topaz, #f59e0b);
  box-shadow:
    0 8px 32px rgb(0 0 0 / 12%),
    0 0 0 1px color-mix(in srgb, var(--color-topaz, #f59e0b) 15%, transparent);
}

.toast--glass.toast--info {
  border-left-color: var(--color-sapphire, #3b82f6);
  box-shadow:
    0 8px 32px rgb(0 0 0 / 12%),
    0 0 0 1px color-mix(in srgb, var(--color-sapphire, #3b82f6) 15%, transparent);
}

/* Dark mode glass toast */
@media (prefers-color-scheme: dark) {
  .toast--glass {
    background: color-mix(in srgb, var(--color-surface, oklch(15% 0.02 260)) 80%, transparent);
    border-color: color-mix(in srgb, var(--color-on-surface, #e2e8f0) 12%, transparent);
  }

  .toast--glass .toast__title {
    color: var(--color-on-surface, #e2e8f0);
  }

  .toast--glass .toast__message {
    color: var(--color-on-surface-muted, #94a3b8);
  }

  .toast--glass .toast__close:hover {
    background: color-mix(in srgb, var(--color-on-surface, #e2e8f0) 8%, transparent);
  }
}

[data-theme="dark"] .toast--glass {
  background: color-mix(in srgb, var(--color-surface, oklch(15% 0.02 260)) 80%, transparent);
  border-color: color-mix(in srgb, var(--color-on-surface, #e2e8f0) 12%, transparent);
}

[data-theme="dark"] .toast--glass .toast__title {
  color: var(--color-on-surface, #e2e8f0);
}

[data-theme="dark"] .toast--glass .toast__message {
  color: var(--color-on-surface-muted, #94a3b8);
}
