/* ============================================
   AI INSIGHTS - REDESIGNED
   Modern, engaging AI-powered insights page
   ============================================ */

/* AI Hero Section */
.ai-hero {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20px;
  padding: 32px;
  margin-top: 24px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  overflow: hidden;
}

/* Mobile: Ensure ai-hero doesn't block hamburger menu */
@media (max-width: 768px) {
  .ai-hero {
    position: relative !important;
    z-index: 1 !important;
  }
}

.ai-hero::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  pointer-events: none;
}

.ai-hero-content {
  position: relative;
  z-index: 1;
}

.ai-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.2);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  margin-bottom: 12px;
}

.ai-pulse {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

.ai-hero-title {
  font-size: 28px;
  font-weight: 800;
  color: white;
  margin: 0 0 8px 0;
}

.ai-hero-subtitle {
  font-size: 16px;
  color: rgba(255,255,255,0.9);
  margin: 0;
}

.btn-ai-refresh {
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.3);
  color: white;
  padding: 10px 20px;
  border-radius: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-ai-refresh:hover {
  background: rgba(255,255,255,0.3);
  transform: translateY(-2px);
}

/* Health Score Card - Redesigned */
.health-score-card {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 24px;
  transition: border-color 0.3s ease;
}

.health-score-card:hover {
  border-color: var(--primary-blue);
}

.health-score-main {
  display: flex;
  align-items: center;
  gap: 32px;
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}

.health-score-circle {
  position: relative;
  width: 140px;
  height: 140px;
  flex-shrink: 0;
}

.score-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-ring-bg {
  fill: none;
  stroke: var(--border-color);
  stroke-width: 10;
}

.score-ring-progress {
  fill: none;
  stroke: url(#scoreGradient);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 1.5s ease-out;
}

.score-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.score-number {
  font-size: 36px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.score-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

.health-score-info {
  flex: 1;
}

.health-score-info h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px 0;
}

.health-score-message {
  font-size: 15px;
  color: var(--text-secondary);
  margin: 0 0 16px 0;
  line-height: 1.5;
}

.health-score-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.health-tag {
  background: var(--bg-secondary);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Health Score Factors */
.health-score-factors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.factor-item {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
}

.factor-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.factor-icon {
  font-size: 18px;
}

.factor-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.factor-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.factor-bar {
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
}

.factor-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 1s ease-out;
}

.factor-fill.savings {
  background: linear-gradient(90deg, #10b981 0%, #34d399 100%);
}

.factor-fill.budget {
  background: linear-gradient(90deg, #f59e0b 0%, #fbbf24 100%);
}

.factor-fill.consistency {
  background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%);
}

/* AI Stats Row */
.ai-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.ai-stat-card {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.3s ease;
}

.ai-stat-card:hover {
  border-color: var(--primary-blue);
  transform: translateY(-2px);
}

.ai-stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.ai-stat-icon.income {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1) 0%, rgba(52, 211, 153, 0.2) 100%);
}

.ai-stat-icon.expense {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1) 0%, rgba(248, 113, 113, 0.2) 100%);
}

.ai-stat-icon.savings {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1) 0%, rgba(96, 165, 250, 0.2) 100%);
}

.ai-stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.ai-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Insights Tabs */
.insights-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.insight-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.insight-tab:hover {
  border-color: var(--primary-blue);
  color: var(--primary-blue);
}

.insight-tab.active {
  background: var(--primary-blue);
  border-color: var(--primary-blue);
  color: white;
}

.tab-icon {
  font-size: 16px;
}

/* Tab Content */
.insights-tab-content {
  margin-bottom: 24px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 0.3s ease-out;
}

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

/* New Insights Grid */
.insights-grid-new {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

/* Featured Insight Card */
.insight-card-featured {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #4A90E2 0%, #667eea 100%);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  color: white;
}

.featured-icon {
  font-size: 48px;
  flex-shrink: 0;
}

.featured-content {
  flex: 1;
}

.featured-content h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 8px 0;
}

.featured-content p {
  font-size: 14px;
  margin: 0;
  opacity: 0.9;
  line-height: 1.5;
}

.featured-action .btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
}

.featured-action .btn:hover {
  background: rgba(255,255,255,0.3);
}

/* New Insight Cards */
.insight-card-new {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 16px;
  padding: 20px;
  transition: all 0.3s ease;
}

.insight-card-new:hover {
  border-color: var(--primary-blue);
}

.insight-card-new.full-width {
  grid-column: 1 / -1;
}

.card-header-new {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.card-icon {
  font-size: 24px;
}

.card-header-new h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.card-body-new {
  min-height: 120px;
}

/* Insight Items - Redesigned */
.insight-item-new {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 10px;
  margin-bottom: 10px;
}

.insight-item-new:last-child {
  margin-bottom: 0;
}

.insight-item-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.insight-item-icon.positive {
  background: rgba(16, 185, 129, 0.1);
}

.insight-item-icon.negative {
  background: rgba(239, 68, 68, 0.1);
}

.insight-item-icon.neutral {
  background: rgba(59, 130, 246, 0.1);
}

.insight-item-content {
  flex: 1;
}

.insight-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.insight-item-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.insight-item-value {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
}

.insight-item-value.positive { color: #10b981; }
.insight-item-value.negative { color: #ef4444; }
.insight-item-value.neutral { color: var(--primary-blue); }

/* Category Bar */
.category-bar-item {
  margin-bottom: 12px;
}

.category-bar-item:last-child {
  margin-bottom: 0;
}

.category-bar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.category-bar-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.category-bar-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.category-bar-track {
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.category-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s ease-out;
}

/* AI Report Section */
.ai-report-section {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  padding: 24px;
}

.ai-report-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.ai-report-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.report-icon {
  font-size: 28px;
}

.ai-report-title h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.ai-report-date {
  font-size: 14px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 6px 14px;
  border-radius: 20px;
}

.ai-report-content {
  min-height: 200px;
}

/* Report Sections */
.report-block {
  margin-bottom: 24px;
}

.report-block:last-child {
  margin-bottom: 0;
}

.report-block-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.report-block-content {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
}

.report-block-content p {
  margin-bottom: 12px;
}

.report-block-content ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.report-block-content li {
  padding: 8px 0 8px 24px;
  position: relative;
}

.report-block-content li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--primary-blue);
  font-weight: 600;
}

/* Top Categories Grid */
.top-categories-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.category-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.category-card:hover {
  border-color: var(--primary-blue);
  transform: translateY(-2px);
}

.category-card-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 12px;
}

.category-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-card-amount {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-blue);
}

.report-highlight-box {
  background: linear-gradient(135deg, rgba(74, 144, 226, 0.1) 0%, rgba(102, 126, 234, 0.1) 100%);
  border-left: 4px solid var(--primary-blue);
  padding: 16px;
  border-radius: 8px;
  margin: 16px 0;
}

.report-highlight-box strong {
  color: var(--primary-blue);
}

/* Loading State */
.insight-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 12px;
}

.insight-loading p {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .ai-hero {
    flex-direction: column;
    text-align: center;
    padding: 24px 20px;
    margin-top: 16px;
    gap: 16px;
  }

  .ai-hero-title {
    font-size: 22px;
  }

  .ai-hero-subtitle {
    font-size: 14px;
  }

  .health-score-main {
    flex-direction: column;
    text-align: center;
    gap: 20px;
  }

  .health-score-circle {
    width: 120px;
    height: 120px;
  }

  .score-number {
    font-size: 28px;
  }

  .health-score-info h2 {
    font-size: 18px;
  }

  .health-score-tags {
    justify-content: center;
  }

  .health-score-factors {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* 3 cards per row for stats */
  .ai-stats-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .ai-stat-card {
    flex-direction: column;
    text-align: center;
    padding: 12px 8px;
    gap: 8px;
  }

  .ai-stat-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .ai-stat-value {
    font-size: 14px;
  }

  .ai-stat-label {
    font-size: 9px;
  }

  .insights-tabs {
    gap: 6px;
  }

  .insight-tab {
    padding: 10px 14px;
    font-size: 12px;
  }

  .tab-icon {
    font-size: 14px;
  }

  .insights-grid-new {
    grid-template-columns: 1fr;
  }

  .insight-card-featured {
    flex-direction: column;
    text-align: center;
    padding: 20px;
  }

  .featured-icon {
    font-size: 36px;
  }

  .insight-card-new {
    padding: 16px;
  }

  .ai-report-header {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .ai-report-title h2 {
    font-size: 18px;
  }

  .ai-report-section {
    padding: 16px;
  }

  /* Top Categories Grid - 3 per row on mobile */
  .top-categories-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .category-card {
    padding: 12px 8px;
  }

  .category-card-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
    margin-bottom: 8px;
  }

  .category-card-name {
    font-size: 11px;
    margin-bottom: 6px;
  }

  .category-card-amount {
    font-size: 13px;
  }

  .report-block {
    margin-bottom: 20px;
  }

  .report-block-title {
    font-size: 15px;
  }

  .report-block-content {
    font-size: 13px;
  }

  .report-highlight-box {
    padding: 12px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .ai-hero {
    padding: 20px 16px;
    margin-top: 24px;
    border-radius: 16px;
  }

  .ai-hero-title {
    font-size: 20px;
  }

  .ai-hero-subtitle {
    font-size: 13px;
  }

  .btn-ai-refresh {
    padding: 8px 16px;
    font-size: 14px;
  }

  .health-score-card {
    padding: 16px;
    border-radius: 16px;
  }

  .health-score-circle {
    width: 120px;
    height: 120px;
  }

  .score-number {
    font-size: 24px;
  }

  .health-score-info h2 {
    font-size: 16px;
  }

  .health-score-message {
    font-size: 13px;
  }

  .health-score-tag {
    font-size: 11px;
    padding: 4px 10px;
  }

  .ai-stats-row {
    gap: 6px;
    grid-template-columns: repeat(3, 1fr);
  }

  .ai-stat-card {
    padding: 10px 6px;
  }

  .ai-stat-icon {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .ai-stat-value {
    font-size: 12px;
  }

  .ai-stat-label {
    font-size: 8px;
  }

  /* Ensure proper container width */
  .main-content {
    padding: 0 12px;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Fix any overflow issues */
  .ai-insights-container {
    max-width: 100%;
    padding-top: 20px;
    overflow-x: hidden;
  }

  .insight-card-new,
  .recommendation-card,
  .trend-card {
    padding: 14px;
    border-radius: 12px;
  }
}

  .insight-tab {
    padding: 8px 12px;
    font-size: 11px;
  }

  .insight-tab span:last-child {
    display: none;
  }

  .tab-icon {
    font-size: 16px;
  }

  .ai-report-section {
    padding: 12px;
    border-radius: 16px;
  }

  /* Top Categories Grid - maintain 3 per row */
  .top-categories-grid {
    gap: 6px;
  }

  .category-card {
    padding: 10px 6px;
    border-radius: 10px;
  }

  .category-card-icon {
    width: 32px;
    height: 32px;
    font-size: 16px;
    margin-bottom: 6px;
    border-radius: 8px;
  }

  .category-card-name {
    font-size: 10px;
    margin-bottom: 4px;
  }

  .category-card-amount {
    font-size: 12px;
  }

  .report-block {
    margin-bottom: 16px;
  }

  .report-block-title {
    font-size: 14px;
    margin-bottom: 10px;
  }

  .report-block-content {
    font-size: 12px;
  }

  .report-highlight-box {
    padding: 10px;
    font-size: 12px;
  }

  .insight-item-new {
    padding: 10px;
    gap: 10px;
  }

  .insight-item-icon {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }

  .insight-item-title {
    font-size: 13px;
  }

  .insight-item-desc {
    font-size: 12px;
  }


/* Dark Mode Support */
[data-theme="dark"] .ai-hero {
  background: linear-gradient(135deg, #4c1d95 0%, #5b21b6 100%);
}

[data-theme="dark"] .health-score-card,
[data-theme="dark"] .ai-stat-card,
[data-theme="dark"] .insight-card-new,
[data-theme="dark"] .ai-report-section {
  background: var(--bg-card);
}

[data-theme="dark"] .factor-item,
[data-theme="dark"] .insight-item-new {
  background: rgba(255,255,255,0.05);
}


/* Empty State */
.insight-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 280px;
}

/* Spinner */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-lg {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Value colors */
.positive { color: #10b981; }
.negative { color: #ef4444; }
.neutral { color: var(--primary-blue); }
