/* ===========================
   AI Insights Page — Two-panel layout, flat design
   Uses app CSS variables (0px radius, Inter, theme-aware)
=========================== */

/* Layout: left panel + main content */
.ai-insights-wrapper {
  max-width: 1160px;
  margin: 0 auto;
}

/* ----- "AI is generating your insights" overlay ----- */
.ai-insights-content-wrap {
  min-height: 280px;
}

.ai-insights-generating-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  background-image:
    linear-gradient(rgba(180, 100, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(180, 100, 255, 0.06) 1px, transparent 1px);
  background-size: 24px 24px;
}

.ai-insights-generating-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.ai-insights-generating-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  height: 56px;
}

.ai-insights-generating-bars .ai-insights-bar {
  display: block;
  width: 10px;
  height: 48px;
  background: var(--brand-purple);
  border-radius: 2px;
  animation: ai-insights-bar 0.8s ease-in-out infinite both;
}

.ai-insights-generating-bars .ai-insights-bar:nth-child(1) { animation-delay: 0s; }
.ai-insights-generating-bars .ai-insights-bar:nth-child(2) { animation-delay: 0.1s; }
.ai-insights-generating-bars .ai-insights-bar:nth-child(3) { animation-delay: 0.2s; }
.ai-insights-generating-bars .ai-insights-bar:nth-child(4) { animation-delay: 0.3s; }
.ai-insights-generating-bars .ai-insights-bar:nth-child(5) { animation-delay: 0.4s; }

@keyframes ai-insights-bar {
  0%, 100% { transform: scaleY(0.35); opacity: 0.6; }
  50% { transform: scaleY(1); opacity: 1; }
}

.ai-insights-generating-text {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.ai-insights-layout {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 20px;
  align-items: start;
}

/* Left column on desktop: hero + main_rest stacked */
.ai-insights-layout .hero-insight {
  grid-column: 1;
  grid-row: 1;
}

.ai-main-rest {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  grid-column: 1;
  grid-row: 2;
}

.ai-right-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: var(--spacing-lg, 16px);
  grid-column: 2;
  grid-row: 1 / -1; /* Span all rows in right column */
}

/* ----- Health score card ----- */
.health-score-card {
  background: linear-gradient(135deg, rgba(180, 100, 255, 0.12), rgba(5, 150, 105, 0.08));
  border: 1px solid rgba(180, 100, 255, 0.25);
  border-radius: var(--card-border-radius, 0);
  padding: 18px;
  font-family: var(--font-family);
}

.hs-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 10px;
}

.hs-ring-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.hs-ring {
  position: relative;
  width: 80px;
  height: 80px;
}

.hs-ring-bg {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 8px solid var(--bg-tertiary);
}

.hs-ring-fill {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 8px solid transparent;
  border-top-color: var(--brand-green);
  border-right-color: var(--brand-green);
  transform: rotate(calc(-90deg + (var(--hs-pct, 0) * 3.6deg)));
}

.hs-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.hs-num {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
}

.hs-max {
  font-size: 9px;
  color: var(--text-muted);
}

.hs-grade {
  text-align: center;
  font-size: 11px;
  color: var(--brand-green);
  font-weight: 600;
  margin-bottom: 12px;
}

.hs-breakdown {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hs-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  gap: 8px;
}

.hs-row-label {
  color: var(--text-muted);
  flex-shrink: 0;
}

.hs-mini-bar {
  flex: 1;
  height: 3px;
  background: var(--bg-tertiary);
  border-radius: 99px;
  overflow: hidden;
  min-width: 0;
}

.hs-mini-bar > div {
  height: 100%;
  border-radius: 99px;
}


/* ----- Potential card ----- */
.potential-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--card-border-radius, 0);
  padding: 14px;
}

.potential-card .pot-h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 10px;
}

.pot-val {
  font-size: 26px;
  font-weight: 800;
  color: var(--brand-green);
}

.pot-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.5;
}

.pot-actions {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.pot-action-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

.pa-label {
  color: var(--text-muted);
}

.pa-val {
  color: var(--brand-green);
  font-weight: 600;
}

/* ----- Hero insight ----- */
.hero-insight {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--card-border-radius, 0);
  overflow: hidden;
  position: relative;
}

.hero-insight::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand-green), #14b8a6);
}

/* Force strict 50/50 split: override Bootstrap Col so each side gets exactly half */
.hero-body {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}

.hero-body > * {
  flex: 0 0 50%;
  max-width: 50%;
  min-width: 0;
  box-sizing: border-box;
}

@media (max-width: 767px) {
  .hero-body > * {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

.hero-left {
  padding: 24px;
  border-right: 1px solid var(--border-primary);
}

.hero-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  background: rgba(5, 150, 105, 0.12);
  color: var(--brand-green);
  padding: 4px 10px;
  border-radius: 0;
  margin-bottom: 14px;
}

.hero-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 6px;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.hero-stat {
  font-size: 42px;
  font-weight: 800;
  color: var(--brand-green);
  line-height: 1;
  margin-bottom: 4px;
}

.hero-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.hero-bullets {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-bottom: 20px;
}

.hero-bullet {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

.hero-bullet::before {
  content: '→ ';
  color: var(--brand-green);
  font-weight: 600;
}

.action-box {
  background: rgba(5, 150, 105, 0.12);
  border: 1px solid rgba(5, 150, 105, 0.3);
  border-radius: 0;
  padding: 14px;
}

.action-box-h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--brand-green);
  font-weight: 700;
  margin-bottom: 6px;
}

.action-box-p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}

.hero-right {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  flex: 1;
}

.chart-title {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Chart wrapper: flex child; inline style on wrapper sets height/overflow */
.hero-chart-wrap {
  flex: 1;
  min-height: 320px;
  min-width: 0;
  overflow: hidden;
}

/* ----- Main filter row (All Insights + pills + Sort) ----- */
.ai-filter-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 0;
}

.ai-filter-row-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  flex-shrink: 0;
}

.ai-filter-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-filter-pill {
  padding: 8px 18px;
  border-radius: 0;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-family);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--border-primary);
  color: var(--text-secondary);
  background: var(--bg-tertiary, #F3F3F3);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.ai-filter-pill:hover {
  border-color: var(--border-secondary);
  background: var(--bg-hover);
  color: var(--text-primary);
}

.ai-filter-pill.ai-filter-pill--active {
  border-color: var(--brand-purple);
  color: var(--brand-purple);
  background: rgba(180, 100, 255, 0.12);
  box-shadow: none;
}

/* ----- Insight grid & cards ----- */
.insight-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.insight-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--card-border-radius, 0);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
  border-top-width: 3px;
  border-top-style: solid;
}

.insight-card:hover {
  border-color: var(--border-secondary);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

.insight-card.expanded {
  border-color: rgba(180, 100, 255, 0.4);
  box-shadow: 0 0 0 1px rgba(180, 100, 255, 0.15);
  grid-column: 1 / -1;
}

/* Square card summary (2 per row) */
.ic-summary {
  padding: 16px 16px 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.ic-summary-square {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 14px 16px 32px;
  min-height: 0;
  aspect-ratio: 2;
  position: relative;
}

.ic-square-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 4px;
}

.ic-square-header .ic-num {
  display: none;
}

.ic-square-header .ic-category {
  margin-bottom: 0;
  font-size: 13px;
}

.ic-emoji-square {
  display: none;
}

.ic-title-square {
  flex: 1;
  font-size: 15px;
  line-height: 1.35;
  margin-bottom: 4px;
  margin-top: 2px;
  min-height: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.ic-square-metric {
  text-align: center;
  margin-top: 8px;
}

.ic-square-metric .ic-impact {
  font-size: 1.75rem;
  font-weight: 800;
}

.ic-square-metric .ic-impact-label {
  font-size: 12px;
}

.ic-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 20px;
}

.ic-emoji {
  font-size: 22px;
  flex-shrink: 0;
}

.ic-text {
  flex: 1;
  min-width: 0;
}

.ic-category {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 3px;
}

.ic-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.ic-right {
  text-align: right;
  flex-shrink: 0;
}

.ic-summary-square .ic-chevron {
  position: absolute;
  bottom: 12px;
  right: 12px;
  margin-left: 0;
}

.ic-impact {
  font-size: 14px;
  font-weight: 800;
}

.ic-impact.pos {
  color: var(--brand-green);
}

.ic-impact.neg {
  color: var(--brand-red);
}

.ic-impact.neu {
  color: var(--brand-yellow);
}

.ic-impact-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.ic-key-insight-block {
  margin-top: 12px;
  text-align: left;
  width: 100%;
  padding: 0 4px;
}

.ic-key-insight-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.ic-summary-key-insight {
  font-size: 12px;
  color: var(--text-primary);
  line-height: 1.35;
  text-align: left;
  margin-top: 0;
  padding: 0;
  min-height: 2.7em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ic-chevron {
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.25s;
  margin-left: 8px;
  flex-shrink: 0;
}

.insight-card.expanded .ic-chevron {
  transform: rotate(180deg);
  color: var(--brand-purple);
}

/* Expanded detail: hidden by default, grid when expanded */
.ic-detail {
  display: none;
  border-top: 1px solid var(--border-primary);
}

.insight-card.expanded .ic-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.ic-detail-left {
  padding: 20px 24px;
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  gap: 0;
  text-align: left;
}

.ic-detail-category {
  font-size: 0.75rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.ic-detail-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 20px;
}

.ic-detail-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35em;
  margin-bottom: 28px;
  background: var(--bg-quaternary);
  border: 1px solid var(--border-secondary);
  border-radius: 0;
  padding: 20px 24px;
}

.ic-detail-metric-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.ic-detail-metric-value.pos {
  color: var(--brand-green);
}

.ic-detail-metric-value.neg {
  color: var(--brand-red);
}

.ic-detail-metric-value.neu {
  color: var(--warning-yellow);
}

.ic-detail-metric-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
}

.ic-detail-metric-sentence {
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 6px;
  text-align: center;
  line-height: 1.5;
}

.ic-detail-key-insight-heading {
  font-size: 0.75rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.ic-detail-right {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ic-detail-left p {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.6;
  margin-bottom: 0;
  background: var(--bg-quaternary);
  border: 1px solid var(--border-secondary);
  border-left: 3px solid var(--border-secondary);
  border-radius: 0;
  padding: 14px 16px;
}

.ic-detail-left p + p {
  margin-top: 8px;
}

.ic-detail-text {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 16px 0;
}

.ic-action-mini {
  background: var(--bg-quaternary);
  border: 1px solid var(--border-secondary);
  border-left: 3px solid var(--brand-purple);
  border-radius: 0;
  padding: 14px 16px;
  margin-top: 8px;
}

.ic-action-mini-h5 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--brand-purple);
  font-weight: 700;
  margin-bottom: 4px;
}

.ic-action-mini-p {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.ic-detail-chart-placeholder {
  min-height: 120px;
}

/* Section divider */
.section-divider {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-divider-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  margin: 0;
}

.section-divider-line {
  flex: 1;
  height: 1px;
  background: var(--border-primary);
}

/* Insight tile — side pip accent (no top border) */
.insight-tile {
  transition: background-color 0.2s ease, border-color 0.2s ease;
  background-color: var(--bg-secondary) !important;
  border-radius: 0 !important;
  position: relative;
}

.insight-tile::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  height: 60%;
  width: 2px;
  background: var(--card-accent, var(--brand-purple));
}

.insight-tile:hover {
  background-color: var(--bg-hover) !important;
}

/* Stat/rec color classes (used in cards) */
.stat-expense { color: var(--brand-red); }
.stat-income { color: var(--brand-green); }
.stat-saving { color: var(--brand-yellow); }
.stat-health { color: var(--brand-purple); }
.stat-default { color: var(--text-primary); }

.recommendation-box { background: var(--bg-tertiary); }
.rec-expense { border-top: 5px solid var(--brand-red); }
.rec-income { border-top: 5px solid var(--brand-green); }
.rec-saving { border-top: 5px solid var(--brand-yellow); }
.rec-health { border-top: 5px solid var(--brand-purple); }
.rec-default { border-top: 5px solid var(--brand-green); }
