/**
 * Toast Notification System
 * Dark-first design with light theme support
 * Slide-in/out animations with progress bar
 */

/* ============================================
   Container
   ============================================ */
#toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
  max-height: calc(100vh - 3rem);
  overflow: visible;
}

/* ============================================
   Slide Animations
   ============================================ */
@keyframes toast-slide-in {
  from {
    transform: translateX(120%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toast-slide-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(120%);
    opacity: 0;
  }
}

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

/* ============================================
   Toast Base (Dark Theme Default)
   ============================================ */
.toast-notification {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-width: 300px;
  max-width: 380px;
  padding: 0.875rem 1rem;
  padding-right: 2.25rem;
  border-radius: 10px;
  background: #1a1f2e;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-left: 4px solid transparent;
  color: #e6edf3;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.875rem;
  line-height: 1.5;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.35),
    0 2px 8px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
  animation: toast-slide-in 0.4s ease-out forwards;
  overflow: hidden;
  cursor: default;
}

.toast-notification.toast-dismissing {
  animation: toast-slide-out 0.3s ease-in forwards;
}

/* ============================================
   Toast Icon
   ============================================ */
.toast-icon {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
}

/* ============================================
   Toast Content
   ============================================ */
.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-message {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.toast-undo {
  display: inline-block;
  margin-top: 0.375rem;
  padding: 0.125rem 0;
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  border: none;
  background: none;
  transition: opacity 0.15s ease;
}

.toast-undo:hover {
  opacity: 0.8;
}

/* ============================================
   Close Button
   ============================================ */
.toast-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: rgba(230, 237, 243, 0.4);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  padding: 0;
  transition: color 0.15s ease, background 0.15s ease;
}

.toast-close:hover {
  color: #e6edf3;
  background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   Progress Bar
   ============================================ */
.toast-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 0 0 10px;
  animation: toast-progress linear forwards;
}

.toast-notification:hover .toast-progress-bar {
  animation-play-state: paused;
}

/* ============================================
   Type: Success (Dark)
   ============================================ */
.toast-notification.toast-success {
  border-color: rgba(16, 185, 129, 0.3);
  border-left-color: #10b981;
}

.toast-notification.toast-success .toast-icon {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.toast-notification.toast-success .toast-progress-bar {
  background: #10b981;
}

.toast-notification.toast-success .toast-undo {
  color: #10b981;
}

/* ============================================
   Type: Error (Dark)
   ============================================ */
.toast-notification.toast-error {
  border-color: rgba(239, 68, 68, 0.3);
  border-left-color: #ef4444;
}

.toast-notification.toast-error .toast-icon {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.toast-notification.toast-error .toast-progress-bar {
  background: #ef4444;
}

.toast-notification.toast-error .toast-undo {
  color: #ef4444;
}

/* ============================================
   Type: Warning (Dark)
   ============================================ */
.toast-notification.toast-warning {
  border-color: rgba(245, 158, 11, 0.3);
  border-left-color: #f59e0b;
}

.toast-notification.toast-warning .toast-icon {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.toast-notification.toast-warning .toast-progress-bar {
  background: #f59e0b;
}

.toast-notification.toast-warning .toast-undo {
  color: #f59e0b;
}

/* ============================================
   Type: Info (Dark)
   ============================================ */
.toast-notification.toast-info {
  border-color: rgba(59, 130, 246, 0.3);
  border-left-color: #3b82f6;
}

.toast-notification.toast-info .toast-icon {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.toast-notification.toast-info .toast-progress-bar {
  background: #3b82f6;
}

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

/* ============================================
   Light Theme
   ============================================ */
html.theme-light .toast-notification {
  background: #ffffff;
  border-color: #e5e7eb;
  color: #1f2937;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.1),
    0 2px 8px rgba(0, 0, 0, 0.06);
}

html.theme-light .toast-close {
  color: rgba(31, 41, 55, 0.35);
}

html.theme-light .toast-close:hover {
  color: #1f2937;
  background: rgba(0, 0, 0, 0.06);
}

/* Light - Success */
html.theme-light .toast-notification.toast-success {
  border-color: rgba(5, 150, 105, 0.25);
  border-left-color: #059669;
}

html.theme-light .toast-notification.toast-success .toast-icon {
  background: rgba(5, 150, 105, 0.1);
  color: #059669;
}

html.theme-light .toast-notification.toast-success .toast-progress-bar {
  background: #059669;
}

html.theme-light .toast-notification.toast-success .toast-undo {
  color: #059669;
}

/* Light - Error */
html.theme-light .toast-notification.toast-error {
  border-color: rgba(220, 38, 38, 0.25);
  border-left-color: #dc2626;
}

html.theme-light .toast-notification.toast-error .toast-icon {
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
}

html.theme-light .toast-notification.toast-error .toast-progress-bar {
  background: #dc2626;
}

html.theme-light .toast-notification.toast-error .toast-undo {
  color: #dc2626;
}

/* Light - Warning */
html.theme-light .toast-notification.toast-warning {
  border-color: rgba(217, 119, 6, 0.25);
  border-left-color: #d97706;
}

html.theme-light .toast-notification.toast-warning .toast-icon {
  background: rgba(217, 119, 6, 0.1);
  color: #d97706;
}

html.theme-light .toast-notification.toast-warning .toast-progress-bar {
  background: #d97706;
}

html.theme-light .toast-notification.toast-warning .toast-undo {
  color: #d97706;
}

/* Light - Info */
html.theme-light .toast-notification.toast-info {
  border-color: rgba(37, 99, 235, 0.25);
  border-left-color: #2563eb;
}

html.theme-light .toast-notification.toast-info .toast-icon {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

html.theme-light .toast-notification.toast-info .toast-progress-bar {
  background: #2563eb;
}

html.theme-light .toast-notification.toast-info .toast-undo {
  color: #2563eb;
}

/* ============================================
   [data-theme="light"] support (alternate selector)
   ============================================ */
[data-theme="light"] .toast-notification {
  background: #ffffff;
  border-color: #e5e7eb;
  color: #1f2937;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.1),
    0 2px 8px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .toast-close {
  color: rgba(31, 41, 55, 0.35);
}

[data-theme="light"] .toast-close:hover {
  color: #1f2937;
  background: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .toast-notification.toast-success {
  border-color: rgba(5, 150, 105, 0.25);
  border-left-color: #059669;
}

[data-theme="light"] .toast-notification.toast-success .toast-icon {
  background: rgba(5, 150, 105, 0.1);
  color: #059669;
}

[data-theme="light"] .toast-notification.toast-success .toast-progress-bar {
  background: #059669;
}

[data-theme="light"] .toast-notification.toast-success .toast-undo {
  color: #059669;
}

[data-theme="light"] .toast-notification.toast-error {
  border-color: rgba(220, 38, 38, 0.25);
  border-left-color: #dc2626;
}

[data-theme="light"] .toast-notification.toast-error .toast-icon {
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
}

[data-theme="light"] .toast-notification.toast-error .toast-progress-bar {
  background: #dc2626;
}

[data-theme="light"] .toast-notification.toast-error .toast-undo {
  color: #dc2626;
}

[data-theme="light"] .toast-notification.toast-warning {
  border-color: rgba(217, 119, 6, 0.25);
  border-left-color: #d97706;
}

[data-theme="light"] .toast-notification.toast-warning .toast-icon {
  background: rgba(217, 119, 6, 0.1);
  color: #d97706;
}

[data-theme="light"] .toast-notification.toast-warning .toast-progress-bar {
  background: #d97706;
}

[data-theme="light"] .toast-notification.toast-warning .toast-undo {
  color: #d97706;
}

[data-theme="light"] .toast-notification.toast-info {
  border-color: rgba(37, 99, 235, 0.25);
  border-left-color: #2563eb;
}

[data-theme="light"] .toast-notification.toast-info .toast-icon {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
}

[data-theme="light"] .toast-notification.toast-info .toast-progress-bar {
  background: #2563eb;
}

[data-theme="light"] .toast-notification.toast-info .toast-undo {
  color: #2563eb;
}

/* ============================================
   Mobile Responsive (< 640px)
   ============================================ */
@media (max-width: 639px) {
  #toast-container {
    top: 1rem;
    right: 0.75rem;
    left: 0.75rem;
  }

  .toast-notification {
    min-width: 0;
    max-width: 100%;
    width: 100%;
  }
}

/* ============================================
   Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .toast-notification {
    animation-duration: 0.01ms;
  }

  .toast-notification.toast-dismissing {
    animation-duration: 0.01ms;
  }

  .toast-progress-bar {
    animation: none;
    width: 0%;
  }
}
