/* ============================================================================
   Porto Guará Intelligence Dashboard — Enhancements CSS
   Market readiness improvements: confidence indicators, sparklines, velocity
   Created: 2026-06-18
   ============================================================================ */

/* ══════════════════════════════════════════════════════════════════════
   AI CONFIDENCE INDICATORS
   ══════════════════════════════════════════════════════════════════════ */
.confidence-indicator {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  margin: 0 0 16px 0;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  animation: slideInFromTop 0.3s var(--transition-spring);
}

.confidence-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.85rem;
}

.confidence-high .confidence-icon {
  background: var(--accent-dim);
}

.confidence-medium .confidence-icon {
  background: var(--warning-dim);
}

.confidence-low .confidence-icon {
  background: var(--danger-dim);
}

.confidence-content {
  flex: 1;
  min-width: 0;
}

.confidence-score {
  font-weight: 600;
  margin-bottom: 3px;
  line-height: 1.3;
}

.confidence-reason {
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

.confidence-help {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-color);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.confidence-help:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ══════════════════════════════════════════════════════════════════════
   SPARKLINES
   ══════════════════════════════════════════════════════════════════════ */
.sparkline-container {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  vertical-align: middle;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.sparkline-container:hover {
  opacity: 1;
}

.sparkline {
  display: block;
  filter: drop-shadow(0 0 2px currentColor);
}

/* Sparklines in KPI cards */
.stat-card .sparkline-container,
.kpi-card .sparkline-container {
  margin: 8px 0 0 0;
  justify-content: center;
}

/* Sparklines in tables */
td .sparkline-container {
  margin: 0 0 0 6px;
}

/* ══════════════════════════════════════════════════════════════════════
   VELOCITY/TREND INDICATORS
   ══════════════════════════════════════════════════════════════════════ */
.velocity-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
  vertical-align: middle;
  transition: all 0.2s;
  opacity: 0.85;
}

.velocity-indicator:hover {
  opacity: 1;
  transform: scale(1.05);
}

.velocity-increasing {
  background: rgba(0, 229, 160, 0.1);
}

.velocity-decreasing {
  background: rgba(239, 68, 68, 0.1);
}

.velocity-stable {
  background: rgba(139, 146, 178, 0.1);
}

.velocity-arrow {
  font-size: 0.85em;
  font-weight: 700;
}

.velocity-value {
  letter-spacing: 0.3px;
}

/* Velocity in headers and KPIs */
.header-stat .velocity-indicator,
.stat-value .velocity-indicator {
  font-size: 0.65rem;
  padding: 1px 5px;
}

/* ══════════════════════════════════════════════════════════════════════
   LIVE DATA PULSE ANIMATIONS
   ══════════════════════════════════════════════════════════════════════ */
@keyframes dataPulseUpdate {
  0% {
    box-shadow: 0 0 0 0 var(--accent-glow);
    background-color: var(--accent-dim);
  }
  50% {
    box-shadow: 0 0 8px 3px var(--accent-glow);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
    background-color: transparent;
  }
}

@keyframes dataPulseNew {
  from {
    opacity: 0;
    transform: translateY(-5px);
    background-color: var(--accent-dim);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    background-color: transparent;
  }
}

@keyframes dataPulseRemove {
  to {
    opacity: 0;
    transform: translateX(-10px);
  }
}

.data-pulse-update {
  animation: dataPulseUpdate 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.data-pulse-new {
  animation: dataPulseNew 0.5s cubic-bezier(0.2, 0, 0, 1);
}

.data-pulse-remove {
  animation: dataPulseRemove 0.4s cubic-bezier(0.4, 0, 1, 1);
}

/* Apply pulse to common data elements */
.stat-value.data-pulse-update,
.kpi-value.data-pulse-update,
.metric-value.data-pulse-update {
  border-radius: var(--radius-sm);
  padding: 2px 4px;
}

/* ══════════════════════════════════════════════════════════════════════
   STREAMING PROGRESS INDICATORS
   ══════════════════════════════════════════════════════════════════════ */
.streaming-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  color: var(--text-secondary);
  animation: fadeIn 0.3s;
}

.streaming-dots {
  display: flex;
  gap: 4px;
}

.streaming-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: streamingDot 1.4s infinite ease-in-out;
}

.streaming-dots span:nth-child(1) {
  animation-delay: 0s;
}

.streaming-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.streaming-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes streamingDot {
  0%, 60%, 100% {
    transform: scale(1);
    opacity: 0.4;
  }
  30% {
    transform: scale(1.3);
    opacity: 1;
  }
}

.streaming-progress {
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Enhanced analysis loading state with streaming indicator */
.analysis-loading {
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.analysis-loading .streaming-indicator {
  margin-top: 8px;
}

/* ══════════════════════════════════════════════════════════════════════
   PROGRESSIVE DISCLOSURE — Expandable detail panels
   ══════════════════════════════════════════════════════════════════════ */
.disclosure-summary {
  cursor: pointer;
  user-select: none;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.disclosure-summary:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.disclosure-icon {
  transition: transform 0.3s var(--transition-spring);
  color: var(--text-muted);
}

.disclosure-summary[aria-expanded="true"] .disclosure-icon {
  transform: rotate(180deg);
  color: var(--accent);
}

.disclosure-detail {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s var(--transition-spring), 
              opacity 0.3s ease,
              margin 0.3s ease;
  opacity: 0;
  margin-top: 0;
}

.disclosure-detail.expanded {
  max-height: 2000px;
  opacity: 1;
  margin-top: 12px;
}

/* ══════════════════════════════════════════════════════════════════════
   ANOMALY HEAT OVERLAYS
   ══════════════════════════════════════════════════════════════════════ */
.anomaly-overlay {
  position: relative;
}

.anomaly-heat {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: var(--radius-sm);
  transition: opacity 0.3s;
}

.anomaly-level-0 { background: transparent; } /* Normal */
.anomaly-level-1 { background: rgba(251, 191, 36, 0.1); } /* +1σ */
.anomaly-level-2 { background: rgba(245, 158, 11, 0.2); } /* +2σ */
.anomaly-level-3 { background: rgba(239, 68, 68, 0.3); } /* +3σ */

.anomaly-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.7rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 100;
}

.anomaly-overlay:hover .anomaly-tooltip {
  opacity: 1;
}

/* ══════════════════════════════════════════════════════════════════════
   RESPONSIVE ADJUSTMENTS
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .confidence-indicator {
    flex-direction: column;
    gap: 8px;
  }
  
  .sparkline-container {
    margin-left: 0;
    margin-top: 4px;
  }
  
  .velocity-indicator {
    font-size: 0.65rem;
    padding: 1px 4px;
  }
  
  .streaming-indicator {
    font-size: 0.7rem;
    padding: 5px 10px;
  }
}

/* ══════════════════════════════════════════════════════════════════════
   ACCESSIBILITY
   ══════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .data-pulse-update,
  .data-pulse-new,
  .data-pulse-remove,
  .sparkline-container,
  .velocity-indicator,
  .streaming-dots span,
  .disclosure-detail {
    animation: none;
    transition: none;
  }
  
  .disclosure-detail.expanded {
    max-height: none;
    opacity: 1;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .confidence-indicator {
    border: 2px solid currentColor;
  }
  
  .velocity-indicator {
    border: 1px solid currentColor;
  }
  
  .anomaly-heat {
    border: 2px dashed currentColor;
  }
}
