/**
 * Dashboard Insights Styles
 * =========================
 */

/* Insights Panel - Collapsible Container */
.insights-panel {
  background: var(--surface-color, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.insights-panel .insights-body {
  max-height: 600px;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 16px 16px 16px;
}

.insights-panel.collapsed .insights-body {
  max-height: 0;
  padding: 0 16px;
}

.insights-panel.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

/* Insights Container */
.insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  transition: background 0.2s;
}

.insights-panel.collapsed .insights-header {
  border-bottom: none;
}

.insights-header:hover {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
}

.insights-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.insights-header-left .insights-icon-svg {
  color: var(--primary-color, #3b82f6);
}

.insights-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  margin: 0;
}

.insights-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  background: var(--primary-color, #3b82f6);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: white;
}

.insights-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.collapse-icon {
  color: var(--text-tertiary, #94a3b8);
  transition: transform 0.3s ease;
}

.btn-refresh {
  padding: 6px;
  background: transparent;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-tertiary, #94a3b8);
  transition: all 0.2s;
}

.btn-refresh:hover {
  background: var(--surface-secondary, #f8fafc);
  color: var(--text-primary, #1e293b);
}

.btn-refresh i {
  width: 16px;
  height: 16px;
}

/* Insights List */
.insights-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Insight Card */
.insight-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid;
  border-radius: 12px;
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: left;
}

.insight-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.insight-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 10px;
  flex-shrink: 0;
  margin-top: 2px;
}

.insight-icon i {
  width: 22px;
  height: 22px;
}

.insight-content {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.insight-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}

.insight-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary, #1e293b);
}

.ai-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  color: white;
}

.ai-tag i {
  width: 10px;
  height: 10px;
}

.insight-message {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary, #475569);
  text-align: left;
}

.insight-action {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--primary-color, #3b82f6);
  text-decoration: none;
}

.insight-action:hover {
  text-decoration: underline;
}


/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface-color, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  transition: box-shadow 0.2s;
}

.stat-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--primary-light, #eff6ff);
  border-radius: 10px;
}

.stat-icon i {
  width: 22px;
  height: 22px;
  color: var(--primary-color, #3b82f6);
}

.stat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary, #1e293b);
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary, #64748b);
}

.stat-trend {
  display: flex;
  align-items: center;
}

.stat-trend i {
  width: 18px;
  height: 18px;
}

/* Loading State */
.insights-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-secondary, #64748b);
}

.insights-loading .spinner {
  width: 32px;
  height: 32px;
  margin-bottom: 12px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Error State */
.insights-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 20px;
  background: #fef2f2;
  border-radius: 12px;
  text-align: center;
}

.insights-error i {
  width: 32px;
  height: 32px;
  color: #dc2626;
  margin-bottom: 10px;
}

.insights-error span {
  color: #991b1b;
  margin-bottom: 12px;
}

.insights-error button {
  padding: 8px 16px;
  background: #dc2626;
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
}

/* Empty State */
.insights-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  text-align: center;
}

.insights-empty i {
  width: 48px;
  height: 48px;
  color: var(--text-tertiary, #94a3b8);
  margin-bottom: 16px;
}

.insights-empty h4 {
  margin: 0 0 8px 0;
  color: var(--text-primary, #1e293b);
}

.insights-empty p {
  margin: 0 0 16px 0;
  color: var(--text-secondary, #64748b);
}

.insights-empty .btn-primary {
  padding: 10px 20px;
  background: var(--primary-color, #3b82f6);
  border: none;
  border-radius: 8px;
  color: white;
  text-decoration: none;
  font-weight: 500;
}


/* Recommendations */
.recommendations-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recommendation-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--surface-color, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 10px;
}

.rec-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--primary-light, #eff6ff);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary-color, #3b82f6);
  flex-shrink: 0;
}

.rec-content {
  flex: 1;
}

.rec-content strong {
  display: block;
  font-size: 14px;
  color: var(--text-primary, #1e293b);
  margin-bottom: 4px;
}

.rec-content p {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary, #64748b);
}

.rec-action {
  padding: 6px 12px;
  background: var(--primary-color, #3b82f6);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: white;
  text-decoration: none;
  white-space: nowrap;
}

.rec-action:hover {
  background: var(--primary-hover, #2563eb);
}

.no-recommendations {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary, #64748b);
}

/* Floating Widget */
.insights-widget {
  position: fixed;
  bottom: 100px;
  right: 20px;
  z-index: 999;
}

.widget-toggle {
  position: relative;
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}

.widget-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.widget-toggle i {
  width: 24px;
  height: 24px;
  color: white;
}

.widget-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 600;
  color: white;
  display: none;
}

.widget-badge:not(:empty) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.widget-content {
  position: absolute;
  bottom: 60px;
  right: 0;
  width: 360px;
  max-height: 480px;
  background: var(--surface-color, #ffffff);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
}

.insights-widget:not(.collapsed) .widget-content {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-bottom: 1px solid #bfdbfe;
}

.widget-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #1e40af;
}

.widget-header button {
  padding: 4px;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: #64748b;
}

.widget-header button:hover {
  background: rgba(0, 0, 0, 0.05);
}

#widget-insights-container {
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .insight-icon {
    background: rgba(0, 0, 0, 0.2);
  }
  
  .stat-card {
    background: #1e293b;
    border-color: #334155;
  }
  
  .widget-content {
    background: #1e293b;
  }
  
  .widget-header {
    background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 100%);
    border-color: #2563eb;
  }
  
  .recommendation-item {
    background: #1e293b;
    border-color: #334155;
  }
}
