/**
 * UX Polish Components (Faza 7 - UX-POLISH-001)
 *
 * Components:
 * - Confidence bars (AI matching)
 * - AI badges (processing/matched/unmatched)
 * - Stock badges (ok/low/critical/deficit with pulse)
 * - Learning animation ("Sistemul a învățat")
 */

/* ═══════════════════════════════════════════════════════════════════════════════
   CONFIDENCE BARS
   Height: 4px, Width: 60px
   Colors: verde (>=90%), galben (50-89%), rosu (<50%)
   ═══════════════════════════════════════════════════════════════════════════════ */

.confidence-bar {
  position: relative;
  width: 60px;
  height: 4px;
  background: var(--border, #e5e7eb);
  border-radius: 2px;
  overflow: hidden;
}

.confidence-bar__fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

/* Confidence levels */
.confidence-bar--high .confidence-bar__fill {
  background: linear-gradient(90deg, #10b981 0%, #34d399 100%);
}

.confidence-bar--medium .confidence-bar__fill {
  background: linear-gradient(90deg, #f59e0b 0%, #fbbf24 100%);
}

.confidence-bar--low .confidence-bar__fill {
  background: linear-gradient(90deg, #ef4444 0%, #f87171 100%);
}

/* With percentage label */
.confidence-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.confidence-indicator__percent {
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 32px;
}

.confidence-indicator--high .confidence-indicator__percent {
  color: #059669;
}

.confidence-indicator--medium .confidence-indicator__percent {
  color: #d97706;
}

.confidence-indicator--low .confidence-indicator__percent {
  color: #dc2626;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   AI BADGES
   Processing (albastru), Matched (verde), Suggestions (galben), Unmatched (rosu)
   ═══════════════════════════════════════════════════════════════════════════════ */

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

/* Processing - Blue with spinner */
.ai-badge--processing {
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.ai-badge--processing::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid rgba(59, 130, 246, 0.3);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: ai-spinner 0.8s linear infinite;
}

@keyframes ai-spinner {
  to { transform: rotate(360deg); }
}

/* Matched - Green */
.ai-badge--matched {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.ai-badge--matched::before {
  content: "✓";
  font-weight: bold;
}

/* Auto-matched - Green with sparkle */
.ai-badge--auto {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.ai-badge--auto::before {
  content: "✨";
}

/* Suggestions - Yellow/Amber */
.ai-badge--suggestions {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.ai-badge--suggestions::before {
  content: "?";
  font-weight: bold;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(245, 158, 11, 0.2);
  border-radius: 50%;
  font-size: 10px;
}

/* Unmatched - Red */
.ai-badge--unmatched {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.ai-badge--unmatched::before {
  content: "✕";
  font-weight: bold;
}

/* Manual selection badge */
.ai-badge--manual {
  background: rgba(107, 114, 128, 0.1);
  color: #4b5563;
  border: 1px solid rgba(107, 114, 128, 0.2);
}

.ai-badge--manual::before {
  content: "👤";
}


/* ═══════════════════════════════════════════════════════════════════════════════
   STOCK BADGES
   OK (verde), Low (galben), Critical (rosu), Deficit (rosu pulsand), Zero (gri)
   ═══════════════════════════════════════════════════════════════════════════════ */

.stock-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* OK - Green */
.stock-badge--ok {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* Low - Yellow */
.stock-badge--low {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

/* Critical - Red (static) */
.stock-badge--critical {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Deficit - Red with pulse animation */
.stock-badge--deficit {
  background: #fecaca;
  color: #7f1d1d;
  border: 1px solid #f87171;
  animation: stock-pulse 1.5s ease-in-out infinite;
}

@keyframes stock-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0);
    transform: scale(1.02);
  }
}

/* Zero - Gray */
.stock-badge--zero {
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
}

/* With icon variants */
.stock-badge--ok::before {
  content: "●";
  color: #22c55e;
  font-size: 8px;
}

.stock-badge--low::before {
  content: "●";
  color: #f59e0b;
  font-size: 8px;
}

.stock-badge--critical::before,
.stock-badge--deficit::before {
  content: "●";
  color: #ef4444;
  font-size: 8px;
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}


/* ═══════════════════════════════════════════════════════════════════════════════
   LEARNING ANIMATION
   "Sistemul a învățat" toast/badge when AI match is confirmed
   ═══════════════════════════════════════════════════════════════════════════════ */

.learning-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 10px 40px rgba(16, 185, 129, 0.3);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

.learning-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.learning-toast__icon {
  font-size: 1.25rem;
  animation: sparkle 0.6s ease-out;
}

@keyframes sparkle {
  0% { transform: scale(0) rotate(-180deg); }
  50% { transform: scale(1.3) rotate(0deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.learning-toast__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.learning-toast__title {
  font-weight: 600;
}

.learning-toast__detail {
  font-size: 0.75rem;
  opacity: 0.85;
}

/* Inline learning indicator (smaller, appears next to matched item) */
.learning-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 500;
  animation: fadeInScale 0.3s ease-out;
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.learning-indicator::before {
  content: "🧠";
  font-size: 0.8rem;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   AI MATCH RESULT ROW
   Complete component for showing AI match results inline
   ═══════════════════════════════════════════════════════════════════════════════ */

.match-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--surface-2, #f9fafb);
  border-radius: 8px;
  font-size: 0.875rem;
}

.match-result__confidence {
  flex-shrink: 0;
}

.match-result__product {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.match-result__name {
  font-weight: 500;
  color: var(--text, #1f2937);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.match-result__code {
  font-size: 0.75rem;
  color: var(--muted, #6b7280);
  font-family: ui-monospace, monospace;
  background: var(--surface, white);
  padding: 2px 6px;
  border-radius: 4px;
}

.match-result__actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   SUGGESTIONS LIST
   For AI match suggestions dropdown
   ═══════════════════════════════════════════════════════════════════════════════ */

.suggestions-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--surface, white);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.suggestion-item:hover {
  background: var(--surface-2, #f3f4f6);
}

.suggestion-item__confidence {
  flex-shrink: 0;
}

.suggestion-item__info {
  flex: 1;
  min-width: 0;
}

.suggestion-item__name {
  font-weight: 500;
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestion-item__code {
  font-size: 0.75rem;
  color: var(--muted, #6b7280);
}

.suggestion-item--selected {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
}


/* ═══════════════════════════════════════════════════════════════════════════════
   SKELETON LOADERS
   For AI processing states
   ═══════════════════════════════════════════════════════════════════════════════ */

.skeleton {
  background: linear-gradient(90deg,
    var(--surface-2, #f3f4f6) 25%,
    var(--surface, #e5e7eb) 50%,
    var(--surface-2, #f3f4f6) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton--text {
  height: 16px;
  width: 120px;
}

.skeleton--badge {
  height: 24px;
  width: 80px;
  border-radius: 12px;
}

.skeleton--bar {
  height: 4px;
  width: 60px;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   DARK THEME SUPPORT
   ═══════════════════════════════════════════════════════════════════════════════ */

:root.theme-dark .confidence-bar {
  background: #374151;
}

:root.theme-dark .ai-badge--processing {
  background: rgba(96, 165, 250, 0.15);
  color: #93c5fd;
  border-color: rgba(96, 165, 250, 0.25);
}

:root.theme-dark .ai-badge--matched,
:root.theme-dark .ai-badge--auto {
  background: rgba(52, 211, 153, 0.15);
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.25);
}

:root.theme-dark .ai-badge--suggestions {
  background: rgba(251, 191, 36, 0.15);
  color: #fcd34d;
  border-color: rgba(251, 191, 36, 0.25);
}

:root.theme-dark .ai-badge--unmatched {
  background: rgba(248, 113, 113, 0.15);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.25);
}

:root.theme-dark .stock-badge--ok {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
  border-color: rgba(34, 197, 94, 0.25);
}

:root.theme-dark .stock-badge--low {
  background: rgba(251, 191, 36, 0.15);
  color: #fcd34d;
  border-color: rgba(251, 191, 36, 0.25);
}

:root.theme-dark .stock-badge--critical,
:root.theme-dark .stock-badge--deficit {
  background: rgba(248, 113, 113, 0.15);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.25);
}

:root.theme-dark .stock-badge--zero {
  background: rgba(156, 163, 175, 0.15);
  color: #d1d5db;
  border-color: rgba(156, 163, 175, 0.25);
}

:root.theme-dark .match-result {
  background: var(--surface-2, #1f2937);
}

:root.theme-dark .suggestions-list {
  background: var(--surface, #111827);
  border-color: var(--border, #374151);
}

:root.theme-dark .suggestion-item:hover {
  background: var(--surface-2, #1f2937);
}

:root.theme-dark .learning-indicator {
  background: rgba(52, 211, 153, 0.15);
  color: #6ee7b7;
}
