/* =============================================================================
   toast.css — Toast Notification System for Optic Up
   Standalone — no @import. Uses CSS variables from variables.css (loaded separately).
   4 types: success, error, warning, info.
   Animations: entering (slide+fade in), leaving (slide+fade out), progress bar countdown.
   RTL: logical properties throughout — container at inset-inline-start (left in RTL).
   ============================================================================= */

/* --- Container: fixed top-start, stacks toasts vertically --- */
.toast-container {
  position: fixed;
  z-index: var(--z-toast, 2000);
  top: var(--space-lg);
  inset-inline-start: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

/* --- Toast item --- */
.toast {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 300px;
  max-width: 450px;
  padding: var(--space-sm) var(--space-md);
  background: var(--color-bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  border-inline-start: 4px solid var(--color-gray-400);
  overflow: hidden;
  pointer-events: auto;
}

/* --- Icon --- */
.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  color: var(--color-gray-400);
}

/* --- Content --- */
.toast-content {
  flex: 1;
  font-size: var(--font-size-sm);
  color: var(--color-gray-700);
  line-height: var(--line-height-normal);
}

/* --- Close button --- */
.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-gray-400);
  font-size: 1rem;
  padding: var(--space-xs);
  line-height: 1;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}
.toast-close:hover {
  color: var(--color-gray-700);
}
.toast-close:focus { outline: none; }
.toast-close:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  box-shadow: var(--shadow-focus);
}

/* --- Progress bar --- */
.toast-progress {
  position: absolute;
  bottom: 0;
  inset-inline-start: 0;
  height: 3px;
  width: 100%;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: var(--color-gray-400);
  animation: toast-progress var(--toast-duration, 5s) linear forwards;
}

/* --- Type variants: border + icon color + progress color --- */

/* Success */
.toast-success { border-inline-start-color: var(--color-success); }
.toast-success .toast-icon { color: var(--color-success); }
.toast-success .toast-progress { background: var(--color-success); }

/* Error */
.toast-error { border-inline-start-color: var(--color-error); }
.toast-error .toast-icon { color: var(--color-error); }
.toast-error .toast-progress { background: var(--color-error); }

/* Warning */
.toast-warning { border-inline-start-color: var(--color-warning); }
.toast-warning .toast-icon { color: var(--color-warning); }
.toast-warning .toast-progress { background: var(--color-warning); }

/* Info */
.toast-info { border-inline-start-color: var(--color-info); }
.toast-info .toast-icon { color: var(--color-info); }
.toast-info .toast-progress { background: var(--color-info); }

/* --- Animations --- */

/* Slide in from inline-start + fade in */
@keyframes toast-enter {
  from {
    opacity: 0;
    transform: translateX(calc(-1 * var(--space-xl)));
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Slide out to inline-start + fade out */
@keyframes toast-leave {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(calc(-1 * var(--space-xl)));
  }
}

/* Progress bar countdown */
@keyframes toast-progress {
  from { width: 100%; }
  to   { width: 0%; }
}

.toast-entering {
  animation: toast-enter var(--transition-slow) ease forwards;
}

.toast-leaving {
  animation: toast-leave var(--transition-normal) ease forwards;
  pointer-events: none;
}

/* --- Responsive: narrower toasts on small screens --- */
@media (max-width: 480px) {
  .toast-container {
    inset-inline-start: var(--space-sm);
    inset-inline-end: var(--space-sm);
  }
  .toast {
    min-width: 0;
    max-width: 100%;
  }
}
