/**
 * 🤖 AI Enhancements CSS - Tap Macro
 * Styles for enhanced AI features including predictive suggestions, insights, and smart tooltips
 */

/* AI Suggestions Container - hide when empty to prevent layout gaps */
#aiSuggestions {
  display: none;
  margin: 1rem 0;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#aiSuggestions:empty {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  min-height: 0 !important;
}

.ai-suggestion {
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.3s ease;
}

.ai-suggestion:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-color: var(--primary);
}

.ai-suggestion[data-confidence="0.8"] {
  border-left: 4px solid #2ecc71;
}

.ai-suggestion[data-confidence="0.7"] {
  border-left: 4px solid #f39c12;
}

.ai-suggestion[data-confidence="0.6"] {
  border-left: 4px solid #e74c3c;
}

.suggestion-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.suggestion-icon {
  font-size: 1.2rem;
  color: var(--primary);
}

.suggestion-title {
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.confidence-badge {
  background: var(--primary);
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.suggestion-content {
  margin-bottom: 0.5rem;
}

.suggestion-content p {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.4;
}

.suggestion-action {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.2s ease;
  margin-top: 0.5rem;
}

.suggestion-action:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.suggestion-reasoning {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.suggestion-explain-btn {
  margin-top: 0.5rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.suggestion-explain-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* AI Insights Container */
#aiInsights {
  margin: 1rem 0;
}

/* Home: insight cards in a multi-column grid to reduce vertical space */
.ai-insights-cards-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.ai-insights-cards-wrap:empty {
  display: none;
}

.ai-insights-cards-wrap .ai-insight {
  margin-bottom: 0;
}

/* Clickable AI Insights Card */
.stat-card.clickable {
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.stat-card.clickable:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.stat-card.clickable::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s;
}

.stat-card.clickable:hover::before {
  left: 100%;
}

.stat-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  opacity: 0.8;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  background-color: var(--bg-primary);
  margin: 5% auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-50px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
}

.modal-header h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.5rem;
}

.close {
  color: var(--text-muted);
  font-size: 2rem;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.3s ease;
}

.close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 2rem;
  max-height: 60vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  background: var(--bg-card);
}

/* Insights Grid in Modal */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.insight-card-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.insight-card-modal:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  border-color: var(--primary);
}

.insight-card-modal .insight-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.insight-card-modal .insight-category {
  background: var(--primary);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.insight-card-modal .insight-confidence {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.insight-card-modal .insight-title {
  margin: 0 0 0.75rem 0;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 600;
}

.insight-card-modal .insight-description {
  margin: 0 0 1rem 0;
  color: var(--text-secondary);
  line-height: 1.5;
}

.insight-card-modal .insight-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
}

.insight-card-modal .insight-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.insight-card-modal .insight-tag {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
}

.ai-insight {
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-insight[data-value="0.8"] {
  border-left: 4px solid #2ecc71;
}

.ai-insight[data-value="0.7"] {
  border-left: 4px solid #f39c12;
}

.ai-insight[data-value="0.6"] {
  border-left: 4px solid #e74c3c;
}

.insight-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.insight-icon {
  font-size: 1.2rem;
}

.insight-title {
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.value-badge {
  background: var(--accent);
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.insight-content {
  margin-bottom: 0.75rem;
}

.insight-content p {
  margin: 0 0 0.5rem 0;
  color: var(--text-secondary);
  line-height: 1.4;
}

.insight-explain-btn {
  margin-top: 0.25rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.insight-explain-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.insight-reasoning {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
}

.insight-recommendations {
  background: var(--bg-elevated);
  padding: 0.75rem;
  border-radius: 4px;
  margin-top: 0.5rem;
}

.insight-recommendations strong {
  color: var(--text-primary);
  display: block;
  margin-bottom: 0.25rem;
}

.insight-recommendations ul {
  margin: 0;
  padding-left: 1.25rem;
}

.insight-recommendations li {
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  line-height: 1.3;
}

.insight-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.insight-dismiss {
  background: var(--danger);
  color: white;
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: background 0.2s ease;
}

.insight-dismiss:hover {
  background: var(--danger-dark);
}

/* Input Suggestion Tooltips */
.input-suggestion-tooltip {
  position: absolute;
  z-index: 1000;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 0.75rem;
  max-width: 300px;
  animation: tooltipSlideIn 0.2s ease;
}

@keyframes tooltipSlideIn {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tooltip-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tooltip-icon {
  font-size: 1rem;
  color: var(--primary);
}

.tooltip-text {
  color: var(--text-secondary);
  font-size: 0.875rem;
  flex: 1;
}

.tooltip-apply {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  transition: background 0.2s ease;
}

.tooltip-apply:hover {
  background: var(--primary-dark);
}

/* AI Context Indicators */
.ai-context-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

.ai-context-indicator .icon {
  font-size: 0.875rem;
  color: var(--primary);
}

/* AI Learning Indicators */
.ai-learning-indicator {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 0.875rem;
  color: var(--text-secondary);
  z-index: 1000;
  animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.ai-learning-indicator .icon {
  color: var(--primary);
  margin-right: 0.5rem;
}

/* AI Mode Enhancement */
.ai-enhanced-mode {
  position: relative;
}

.ai-enhanced-mode::after {
  content: "🤖";
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 1rem;
  opacity: 0.7;
}

/* AI Prediction Highlights */
.ai-prediction-highlight {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-left: 0.5rem;
}

/* AI Confidence Indicators */
.ai-confidence-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.ai-confidence-indicator .bar {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.ai-confidence-indicator .bar-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

/* AI Smart Suggestions Panel */
.ai-suggestions-panel {
  position: fixed;
  top: 50%;
  right: 1rem;
  transform: translateY(-50%);
  width: 300px;
  max-height: 80vh;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  overflow-y: auto;
  animation: slideInRight 0.3s ease;
}

.ai-suggestions-panel .panel-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 8px 8px 0 0;
}

.ai-suggestions-panel .panel-title {
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ai-suggestions-panel .panel-content {
  padding: 1rem;
}

/* AI Contextual Help */
.ai-contextual-help {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 0.75rem;
  margin-top: 0.25rem;
  z-index: 100;
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* AI Pattern Recognition */
.ai-pattern-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.375rem;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

/* Responsive Design */
@media (max-width: 768px) {
  .ai-suggestions-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 50vh;
    transform: none;
    border-radius: 8px 8px 0 0;
  }

  .input-suggestion-tooltip {
    max-width: calc(100vw - 2rem);
    left: 1rem !important;
    right: 1rem !important;
  }

  .ai-suggestion {
    margin-bottom: 0.75rem;
    padding: 0.75rem;
  }

  .ai-insight {
    margin-bottom: 0.75rem;
    padding: 0.75rem;
  }
}

/* Dark Mode Enhancements */
[data-theme="dark"] .ai-suggestion {
  background: var(--bg-elevated-dark);
  border-color: var(--border-dark);
}

[data-theme="dark"] .ai-insight {
  background: var(--bg-elevated-dark);
  border-color: var(--border-dark);
}

[data-theme="dark"] .input-suggestion-tooltip {
  background: var(--bg-elevated-dark);
  border-color: var(--border-dark);
}

[data-theme="dark"] .ai-suggestions-panel {
  background: var(--bg-elevated-dark);
  border-color: var(--border-dark);
}

/* Print Styles */
@media print {

  .ai-suggestion,
  .ai-insight,
  .input-suggestion-tooltip,
  .ai-suggestions-panel,
  .ai-learning-indicator {
    display: none !important;
  }
}

/* 🚩 Safety Flags */
.safety-flags-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.safety-flag {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  animation: slideIn 0.3s ease;
}

.safety-flag.flag-danger {
  border-left: 5px solid #ef4444;
  background: rgba(239, 68, 68, 0.05);
}

.safety-flag.flag-warning {
  border-left: 5px solid #f59e0b;
  background: rgba(245, 158, 11, 0.05);
}

.safety-flag.flag-info {
  border-left: 5px solid #3b82f6;
  background: rgba(59, 130, 246, 0.05);
}

.flag-icon {
  font-size: 1.5rem;
  display: flex;
  align-items: center;
}

.flag-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
}

.flag-message {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

[data-theme="dark"] .safety-flag.flag-danger {
  background: rgba(239, 68, 68, 0.15);
}

[data-theme="dark"] .safety-flag.flag-warning {
  background: rgba(245, 158, 11, 0.15);
}

[data-theme="dark"] .safety-flag.flag-info {
  background: rgba(59, 130, 246, 0.15);
}