/* ============================================================
   Phase 7: Real-Time Enhancements — Styles
   ============================================================ */

/* ------------------------------------------------------------
   7.4  Toast Notification System
   ------------------------------------------------------------ */

/* Stack container — bottom-right desktop, bottom-center mobile */
.toast-stack {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast, 9000);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  max-width: 400px;
  width: 100%;
  pointer-events: none;
}

@media (max-width: 767px) {
  .toast-stack {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    left: var(--space-3);
    right: var(--space-3);
    max-width: none;
    align-items: center;
  }
}

/* Individual toast */
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  pointer-events: auto;
  min-width: 280px;
  max-width: 100%;
  backdrop-filter: blur(8px);
  animation: toast-enter 0.3s ease-out;
}

.toast--dismissing {
  animation: toast-exit 0.3s ease-in forwards;
}

/* Type variants — left border accent */
.toast--info {
  border-left: 3px solid var(--info, var(--p-sky-400));
}
.toast--info .toast__icon {
  color: var(--info, var(--p-sky-400));
}

.toast--success {
  border-left: 3px solid var(--success);
}
.toast--success .toast__icon {
  color: var(--success);
}

.toast--warning {
  border-left: 3px solid var(--warning);
}
.toast--warning .toast__icon {
  color: var(--warning);
}

.toast--danger {
  border-left: 3px solid var(--danger);
}
.toast--danger .toast__icon {
  color: var(--danger);
}

.toast__icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.toast__message {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text);
  line-height: 1.4;
}

.toast__action {
  flex-shrink: 0;
  padding: var(--space-1) var(--space-2);
  background: transparent;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  color: var(--primary);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast);
}
.toast__action:hover {
  background: var(--primary-subtle);
}

.toast__close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.toast__close:hover {
  color: var(--text);
  background: var(--surface-alt);
}

/* Transition-group animations */
.toast-enter-active {
  animation: toast-enter 0.3s ease-out;
}
.toast-leave-active {
  animation: toast-exit 0.3s ease-in forwards;
}
.toast-move {
  transition: transform 0.3s ease;
}

@keyframes toast-enter {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

@media (max-width: 767px) {
  @keyframes toast-exit {
    0% {
      opacity: 1;
      transform: translateY(0);
    }
    100% {
      opacity: 0;
      transform: translateY(16px);
    }
  }
}

/* ------------------------------------------------------------
   7.1  Real-Time Lap Sync — Status Indicators
   ------------------------------------------------------------ */

/* Connection status badge */
.rt-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-family: var(--font-condensed);
  color: var(--text-muted);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
}
.rt-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.rt-status--connected .rt-status__dot {
  background: var(--success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}
.rt-status--connecting .rt-status__dot {
  background: var(--warning);
  animation: rt-pulse 1.5s ease-in-out infinite;
}
.rt-status--disconnected .rt-status__dot {
  background: var(--text-muted);
}
.rt-status--error .rt-status__dot {
  background: var(--danger);
}

@keyframes rt-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Sync flash on new lap row */
.rt-new-lap {
  animation: rt-row-flash 1.2s ease-out;
}
@keyframes rt-row-flash {
  0% { background: rgba(6,182,212,0.2); }
  100% { background: transparent; }
}

/* Conflict merge dialog */
.rt-conflict {
  background: var(--surface);
  border: 1px solid var(--warning);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin: var(--space-3) 0;
}
.rt-conflict__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  color: var(--warning);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
}
.rt-conflict__versions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.rt-conflict__version {
  padding: var(--space-3);
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.rt-conflict__version-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}
.rt-conflict__actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* ------------------------------------------------------------
   7.2  Live Nutrition Alert Indicators
   ------------------------------------------------------------ */

/* Inline alert badge on stat cards */
.nutrition-alert {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  font-family: var(--font-condensed);
  animation: nutrition-alert-pulse 2s ease-in-out infinite;
}
.nutrition-alert--warning {
  background: var(--warning-subtle);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.nutrition-alert--danger {
  background: var(--danger-subtle);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.nutrition-alert--success {
  background: var(--success-subtle);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
  animation: none;
}

@keyframes nutrition-alert-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Threshold progress bar (used inline on stat cards) */
.threshold-bar {
  position: relative;
  height: 4px;
  background: var(--surface-alt);
  border-radius: 2px;
  overflow: hidden;
  margin-top: var(--space-2);
}
.threshold-bar__fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease, background 0.3s ease;
}
.threshold-bar__fill--ok {
  background: var(--success);
}
.threshold-bar__fill--warning {
  background: var(--warning);
}
.threshold-bar__fill--danger {
  background: var(--danger);
}
.threshold-bar__marker {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 8px;
  background: var(--text-muted);
  transform: translateX(-50%);
}

/* ------------------------------------------------------------
   7.3  Connection Status Bar (top of page, optional)
   ------------------------------------------------------------ */
.rt-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-family: var(--font-condensed);
  text-align: center;
  transition: background 0.3s ease, max-height 0.3s ease;
  overflow: hidden;
}
.rt-banner--hidden {
  max-height: 0;
  padding: 0;
}
.rt-banner--connected {
  max-height: 32px;
  background: var(--success-subtle);
  color: var(--success);
}
.rt-banner--reconnecting {
  max-height: 32px;
  background: var(--warning-subtle);
  color: var(--warning);
}
.rt-banner--offline {
  max-height: 32px;
  background: var(--danger-subtle);
  color: var(--danger);
}
