// Simulation chart, opportunity cost callout, Deep Analysis screen, Deep Report screen

// ─── 5-YEAR ASSET SIMULATION ──────────────────────────────────────
function AssetSimulation({ T, t, accent, alloc }) {
  // Compute crude weighted CAGR for current vs Lucy
  // Asset return assumptions (annualised):
  const RET = { bank: 0.055, realEstate: 0.07, stocks: 0.13, bonds: 0.08, gold: 0.06, crypto: 0.18, cash: 0.02 };
  const SUG = { bank: 0.25, realEstate: 0.25, stocks: 0.25, bonds: 0.10, gold: 0.10, crypto: 0.05 };
  const sumW = (w) => Object.values(w).reduce((a, b) => a + (b || 0), 0) || 100;
  const wAlloc = sumW(alloc);
  const cur = Object.entries(alloc).reduce((acc, [k, v]) => acc + (v / wAlloc) * (RET[k] || 0), 0);
  const lucy = Object.entries(SUG).reduce((acc, [k, v]) => acc + v * (RET[k] || 0), 0);

  const capital = 5; // Tỷ
  const years = [0, 1, 2, 3, 4, 5];
  const curS = years.map(y => capital * Math.pow(1 + cur, y));
  const lucyS = years.map(y => capital * Math.pow(1 + lucy, y));
  const maxV = Math.max(...lucyS) * 1.05;

  // Chart geometry
  const W = 354, H = 220, padL = 30, padR = 12, padT = 14, padB = 28;
  const innerW = W - padL - padR, innerH = H - padT - padB;
  const x = (i) => padL + (innerW * i) / (years.length - 1);
  const y = (v) => padT + innerH - (v / maxV) * innerH;

  const curPath = curS.map((v, i) => `${i === 0 ? "M" : "L"}${x(i)},${y(v)}`).join(" ");
  const lucyPath = lucyS.map((v, i) => `${i === 0 ? "M" : "L"}${x(i)},${y(v)}`).join(" ");
  const lucyArea = `${lucyPath} L${x(years.length - 1)},${y(0)} L${x(0)},${y(0)} Z`;
  const curArea = `${curPath} L${x(years.length - 1)},${y(0)} L${x(0)},${y(0)} Z`;

  const opportunityM = Math.round((lucyS[5] - curS[5]) * 1000); // → million
  const tooltipIdx = 4;

  const yTicks = [0, 3, 5, 8, 10];

  return (
    <div>
      {/* Header */}
      <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 6 }}>
        <svg width="16" height="16" viewBox="0 0 16 16" fill="none">
          <path d="M2 12L6 7L9 10L14 4" stroke={accent.primary} strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
          <path d="M10 4H14V8" stroke={accent.primary} strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
        </svg>
        <span style={{ fontFamily: FONTS.fraunces, fontSize: 18, color: T.text, letterSpacing: -0.3 }}>{t.simTitle}</span>
      </div>
      <Body T={T} size={11.5} style={{ color: T.textMute, marginBottom: 14 }}>{t.simSub}</Body>

      {/* Chart */}
      <div style={{ position: "relative" }}>
        <svg width={W} height={H} viewBox={`0 0 ${W} ${H}`} style={{ display: "block" }}>
          <defs>
            <linearGradient id="lucyGrad" x1="0" x2="0" y1="0" y2="1">
              <stop offset="0%" stopColor={accent.primary} stopOpacity="0.3" />
              <stop offset="100%" stopColor={accent.primary} stopOpacity="0" />
            </linearGradient>
            <linearGradient id="curGrad" x1="0" x2="0" y1="0" y2="1">
              <stop offset="0%" stopColor={T.textMute} stopOpacity="0.18" />
              <stop offset="100%" stopColor={T.textMute} stopOpacity="0" />
            </linearGradient>
          </defs>
          {/* Y grid + labels */}
          {yTicks.map((v, i) => (
            <g key={i}>
              <line x1={padL} x2={W - padR} y1={y(v)} y2={y(v)} stroke={T.border} strokeDasharray="2 4" strokeWidth="1"/>
              <text x={padL - 6} y={y(v) + 3} fontFamily={FONTS.ui} fontSize="9" fill={T.textMute} textAnchor="end">{v}T</text>
            </g>
          ))}
          {/* areas */}
          <path d={curArea} fill="url(#curGrad)"/>
          <path d={lucyArea} fill="url(#lucyGrad)"/>
          {/* lines */}
          <path d={curPath} stroke={T.textDim} strokeWidth="2" fill="none" strokeLinecap="round"/>
          <path d={lucyPath} stroke={accent.primary} strokeWidth="2" fill="none" strokeLinecap="round" style={{ filter: `drop-shadow(0 0 4px ${accent.primaryGlow})` }}/>

          {/* Tooltip vertical line */}
          <line x1={x(tooltipIdx)} x2={x(tooltipIdx)} y1={padT} y2={H - padB} stroke={T.border} strokeWidth="1"/>
          <circle cx={x(tooltipIdx)} cy={y(curS[tooltipIdx])} r="4" fill={T.bg} stroke={T.textDim} strokeWidth="1.5"/>
          <circle cx={x(tooltipIdx)} cy={y(lucyS[tooltipIdx])} r="4" fill={T.bg} stroke={accent.primary} strokeWidth="1.5"/>

          {/* X labels */}
          {years.map(yr => (
            <text key={yr} x={x(yr)} y={H - 8} fontFamily={FONTS.ui} fontSize="9.5" fill={T.textMute} textAnchor="middle">
              {t.simYear} {yr}
            </text>
          ))}
        </svg>

        {/* Tooltip card */}
        <div style={{
          position: "absolute",
          left: x(tooltipIdx) - 130,
          top: y(Math.max(curS[tooltipIdx], lucyS[tooltipIdx])) - 70,
          background: T.bgElev,
          border: `1px solid ${T.borderStrong}`,
          borderRadius: 10,
          padding: "10px 12px",
          boxShadow: "0 8px 24px rgba(0,0,0,0.3)",
          minWidth: 170,
          pointerEvents: "none",
        }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 11, fontWeight: 600, color: T.text, marginBottom: 6 }}>{t.simYear} {tooltipIdx}</div>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 10, marginBottom: 4 }}>
            <span style={{ display: "flex", alignItems: "center", gap: 6, fontFamily: FONTS.ui, fontSize: 10.5, color: T.textDim }}>
              <span style={{ width: 7, height: 7, borderRadius: "50%", background: accent.primary }}/>
              {t.simLucy}:
            </span>
            <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: accent.primary, fontVariantNumeric: "tabular-nums", fontWeight: 600 }}>{lucyS[tooltipIdx].toFixed(1)} Tỷ</span>
          </div>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 10 }}>
            <span style={{ display: "flex", alignItems: "center", gap: 6, fontFamily: FONTS.ui, fontSize: 10.5, color: T.textDim }}>
              <span style={{ width: 7, height: 7, borderRadius: "50%", background: T.textDim }}/>
              {t.simCurrent}:
            </span>
            <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.text, fontVariantNumeric: "tabular-nums", fontWeight: 600 }}>{curS[tooltipIdx].toFixed(1)} Tỷ</span>
          </div>
        </div>
      </div>

      {/* Return on investment Chart */}
      <div style={{ height: 14 }} />
      <div style={{
        padding: "18px 16px", borderRadius: 14,
        background: `linear-gradient(135deg, ${T.surface}, ${T.surfaceStrong})`,
        border: `1px solid ${T.border}`,
      }}>
        <div style={{ fontFamily: FONTS.ui, fontSize: 11, letterSpacing: 0.5, color: T.textMute, textTransform: "uppercase", marginBottom: 18 }}>
          Hiệu suất sinh lời kỳ vọng (ROI)
        </div>
        
        {/* Lucy ROI */}
        <div style={{ marginBottom: 14 }}>
          <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8 }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 12.5, color: T.text, fontWeight: 500, display: "flex", alignItems: "center", gap: 6 }}>
              <span style={{ width: 8, height: 8, borderRadius: "50%", background: accent.primary, boxShadow: `0 0 4px ${accent.primaryGlow}` }}/>
              Đề xuất của Lucy
            </span>
            <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: accent.primary, fontWeight: 600, fontVariantNumeric: "tabular-nums" }}>{(lucy * 100).toFixed(1)}% / năm</span>
          </div>
          <div style={{ height: 6, background: T.borderStrong, borderRadius: 4, overflow: "hidden" }}>
            <div style={{ width: `${Math.min(100, lucy * 100 * 3)}%`, height: "100%", background: accent.primary, borderRadius: 4, transition: "width 1s cubic-bezier(0.2, 0.8, 0.2, 1)" }} />
          </div>
        </div>

        {/* Current ROI */}
        <div>
          <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8 }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 12.5, color: T.textDim, display: "flex", alignItems: "center", gap: 6 }}>
              <span style={{ width: 8, height: 8, borderRadius: "50%", background: T.textDim }}/>
              Danh mục hiện tại
            </span>
            <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text, fontWeight: 500, fontVariantNumeric: "tabular-nums" }}>{(cur * 100).toFixed(1)}% / năm</span>
          </div>
          <div style={{ height: 6, background: T.borderStrong, borderRadius: 4, overflow: "hidden" }}>
            <div style={{ width: `${Math.min(100, cur * 100 * 3)}%`, height: "100%", background: T.textDim, borderRadius: 4, transition: "width 1s cubic-bezier(0.2, 0.8, 0.2, 1)" }} />
          </div>
        </div>
      </div>

      {/* Opportunity cost callout */}
      <div style={{ height: 14 }} />
      <div style={{
        padding: "16px 16px",
        borderRadius: 14,
        background: `linear-gradient(155deg, ${accent.primarySoft}, transparent 80%)`,
        border: `1px solid ${accent.primary}40`,
        display: "flex", gap: 12, alignItems: "flex-start",
      }}>
        <div style={{
          width: 28, height: 28, borderRadius: 8, background: `${accent.primary}25`,
          display: "flex", alignItems: "center", justifyContent: "center", flexShrink: 0,
          border: `1px solid ${accent.primary}50`,
        }}>
          <svg width="14" height="14" viewBox="0 0 14 14" fill="none">
            <path d="M7 1L13 12H1L7 1Z" stroke={accent.primary} strokeWidth="1.4" strokeLinejoin="round" fill="none"/>
            <line x1="7" y1="5.5" x2="7" y2="8.5" stroke={accent.primary} strokeWidth="1.4" strokeLinecap="round"/>
            <circle cx="7" cy="10.5" r="0.8" fill={accent.primary}/>
          </svg>
        </div>
        <div style={{ flex: 1 }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 11.5, color: T.textDim, fontWeight: 500, marginBottom: 4 }}>{t.oppCostLabel}</div>
          <div style={{ fontFamily: FONTS.fraunces, fontSize: 26, color: T.text, letterSpacing: -0.5, lineHeight: 1, fontVariantNumeric: "tabular-nums", marginBottom: 6 }}>
            {opportunityM.toLocaleString()} <span style={{ fontSize: 16, color: T.textDim }}>Triệu</span>
          </div>
          <div style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textMute }}>{t.oppCostBody}</div>
        </div>
      </div>
    </div>
  );
}

// ─── DEEP ANALYSIS LOADING SCREEN ──────────────────────────────────
function DeepAnalysisScreen({ T, t, accent, theme, onDone }) {
  const steps = [t.deep1, t.deep2, t.deep3, t.deep4, t.deep5];
  const STEP_MS = 1700; // ~8.5s total
  const [active, setActive] = React.useState(0);
  const [done, setDone] = React.useState([]);
  const [progress, setProgress] = React.useState(0);

  React.useEffect(() => {
    if (active >= steps.length) {
      const id = setTimeout(() => onDone(), 700);
      return () => clearTimeout(id);
    }
    const id = setTimeout(() => {
      setDone(d => [...d, active]);
      setActive(a => a + 1);
    }, STEP_MS);
    return () => clearTimeout(id);
  }, [active]);

  React.useEffect(() => {
    const total = steps.length * STEP_MS;
    const start = Date.now();
    const id = setInterval(() => {
      const elapsed = Date.now() - start;
      setProgress(Math.min(100, (elapsed / total) * 100));
    }, 60);
    return () => clearInterval(id);
  }, []);

  return (
    <div style={{ position: "relative", minHeight: "100%", padding: "20px 22px 100px" }}>
      <AmbientBg T={T} accent={accent} theme={theme} />
      <div style={{ position: "relative", zIndex: 1, display: "flex", flexDirection: "column", alignItems: "center", paddingTop: 16 }}>
        <Kicker T={T} accent={accent}>{t.deepKicker}</Kicker>
        <div style={{ height: 16 }} />

        {/* Layered orb / network viz */}
        <DeepOrb size={180} accent={accent} theme={theme} T={T} />

        <div style={{ height: 22 }} />
        <SerifTitle T={T} size={32}>{t.deepTitle}</SerifTitle>
        <div style={{ height: 10 }} />
        <Body T={T} size={12.5} style={{ textAlign: "center", maxWidth: 320 }}>{t.deepSub}</Body>

        <div style={{ height: 24 }} />

        {/* Progress bar */}
        <div style={{ width: "100%", display: "flex", alignItems: "center", gap: 10, marginBottom: 18 }}>
          <div style={{ flex: 1, height: 3, background: T.surfaceStrong, borderRadius: 999, overflow: "hidden" }}>
            <div style={{ height: "100%", width: `${progress}%`, background: accent.primary, transition: "width 200ms linear", boxShadow: `0 0 8px ${accent.primaryGlow}` }} />
          </div>
          <span style={{ fontFamily: FONTS.ui, fontSize: 10.5, color: accent.primary, fontVariantNumeric: "tabular-nums", fontWeight: 600, minWidth: 30, textAlign: "right" }}>{Math.round(progress)}%</span>
        </div>

        {/* Step list */}
        <div style={{ width: "100%", display: "flex", flexDirection: "column" }}>
          {steps.map((s, i) => {
            const isDone = done.includes(i);
            const isActive = active === i;
            return (
              <div key={i} style={{
                display: "flex", alignItems: "center", gap: 12,
                padding: "13px 4px",
                borderTop: i === 0 ? `1px solid ${T.border}` : "none",
                borderBottom: `1px solid ${T.border}`,
                opacity: isDone || isActive ? 1 : 0.42,
                transition: "opacity 300ms",
              }}>
                <div style={{
                  width: 22, height: 22, borderRadius: "50%",
                  border: `1.5px solid ${isDone || isActive ? accent.primary : T.borderStrong}`,
                  background: isDone ? accent.primary : "transparent",
                  display: "flex", alignItems: "center", justifyContent: "center",
                  flexShrink: 0, transition: "all 200ms",
                }}>
                  {isDone ? (
                    <svg width="10" height="10" viewBox="0 0 11 11"><path d="M2 5.5L4.5 8L9 3" stroke="#0B0F19" strokeWidth="1.8" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
                  ) : isActive ? (
                    <div style={{ width: 7, height: 7, borderRadius: "50%", background: accent.primary, animation: "lucyPulse 1s ease-in-out infinite" }} />
                  ) : null}
                </div>
                <span style={{ flex: 1, fontFamily: FONTS.ui, fontSize: 12.5, color: T.text, fontWeight: isActive ? 600 : 400 }}>
                  {s}
                </span>
                {isActive && (
                  <span style={{ fontFamily: FONTS.ui, fontSize: 9.5, color: accent.primary, letterSpacing: 1, textTransform: "uppercase" }}>
                    <ScanDots />
                  </span>
                )}
              </div>
            );
          })}
        </div>
      </div>
    </div>
  );
}

function DeepOrb({ size, accent, theme, T }) {
  const cx = size / 2, cy = size / 2;
  return (
    <div style={{ position: "relative", width: size, height: size }}>
      <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`}>
        <defs>
          <radialGradient id="dorbCore" cx="50%" cy="50%" r="50%">
            <stop offset="0%" stopColor={accent.primary} stopOpacity="0.55"/>
            <stop offset="60%" stopColor={accent.primary} stopOpacity="0.1"/>
            <stop offset="100%" stopColor={accent.primary} stopOpacity="0"/>
          </radialGradient>
        </defs>
        {/* Glowing core */}
        <circle cx={cx} cy={cy} r={size/2 - 4} fill="url(#dorbCore)"/>
        {/* Rotating rings */}
        {[0, 1, 2].map(i => (
          <g key={i} style={{ transformOrigin: `${cx}px ${cy}px`, animation: `dorbSpin${i} ${6 + i*3}s linear infinite ${i % 2 ? "reverse" : ""}` }}>
            <circle cx={cx} cy={cy} r={size/2 - 18 - i*16} fill="none" stroke={accent.primary} strokeOpacity={0.35 - i*0.08} strokeWidth="1" strokeDasharray={i === 0 ? "4 6" : i === 1 ? "2 8" : "1 4"}/>
          </g>
        ))}
        {/* Orbiting nodes */}
        {[0, 1, 2, 3, 4].map(i => {
          const angle = (i / 5) * Math.PI * 2;
          const r = size/2 - 18 - (i % 3) * 16;
          const ox = cx + Math.cos(angle) * r;
          const oy = cy + Math.sin(angle) * r;
          return <circle key={i} cx={ox} cy={oy} r="2.5" fill={accent.primary} style={{ animation: `dorbBlink ${1.5 + i*0.3}s ease-in-out infinite ${i*0.2}s` }}/>;
        })}
        {/* Center mark */}
        <circle cx={cx} cy={cy} r="5" fill={accent.primary} style={{ filter: `drop-shadow(0 0 6px ${accent.primaryGlow})` }}/>
        <circle cx={cx} cy={cy} r="2" fill={T.bg}/>
      </svg>
      <style>{`
        @keyframes dorbSpin0 { to { transform: rotate(360deg); } }
        @keyframes dorbSpin1 { to { transform: rotate(360deg); } }
        @keyframes dorbSpin2 { to { transform: rotate(360deg); } }
        @keyframes dorbBlink { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
      `}</style>
    </div>
  );
}

// ─── DEEP REPORT (FULL) ───────────────────────────────────────────
function DeepReportScreen({ T, t, accent, theme, name, alloc, onRestart }) {
  const overall = 87;
  // Suggested portfolio
  const sug = [
    { label: t.bank, c: accent.chart[0], pct: 25 },
    { label: t.realEstate, c: accent.chart[1], pct: 25 },
    { label: t.stocks, c: accent.chart[2], pct: 25 },
    { label: t.bonds, c: accent.chart[3], pct: 10 },
    { label: t.gold, c: accent.chart[4], pct: 10 },
    { label: t.crypto, c: accent.chart[5], pct: 5 },
  ];

  return (
    <div style={{ position: "relative", minHeight: "100%", padding: "20px 22px 120px" }}>
      <AmbientBg T={T} accent={accent} theme={theme} variant="report" />
      <div style={{ position: "relative", zIndex: 1 }}>
        <Kicker T={T} accent={accent}>{t.deepReportKicker}</Kicker>
        <div style={{ height: 14 }} />
        <SerifTitle T={T} size={42}>{t.deepReportTitle}</SerifTitle>
        <div style={{ height: 8 }} />
        <Body T={T} size={12} style={{ color: T.textMute }}>
          {t.reportFor} <span style={{ color: T.text, fontWeight: 500 }}>{name || "Investor"}</span>
        </Body>

        <div style={{ height: 24 }} />

        {/* Big radial */}
        <div style={{ display: "flex", alignItems: "center", justifyContent: "center", padding: "10px 0 14px" }}>
          <RadialDial score={overall} accent={accent} T={T} size={170} variant="rings"/>
        </div>

        {/* 3 metric cards */}
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 8 }}>
          {[
            { n: "07", l: t.metricStrengths },
            { n: "04", l: t.metricWeaknesses },
            { n: "02", l: t.metricRisks },
          ].map(m => (
            <div key={m.l} style={{
              padding: "14px 10px", borderRadius: 12,
              background: T.surface, border: `1px solid ${T.border}`,
              textAlign: "center",
            }}>
              <div style={{ fontFamily: FONTS.fraunces, fontSize: 28, color: accent.primary, fontWeight: 400, lineHeight: 1, fontVariantNumeric: "tabular-nums" }}>{m.n}</div>
              <div style={{ fontFamily: FONTS.ui, fontSize: 9.5, color: T.textMute, marginTop: 6, letterSpacing: 0.4 }}>{m.l}</div>
            </div>
          ))}
        </div>

        <div style={{ height: 28 }} />

        {/* Section: Macro context */}
        <DeepSection T={T} accent={accent} index="01" title={t.sectionMacro}>
          <Body T={T} size={12.5} style={{ lineHeight: 1.6 }}>{t.macroBody}</Body>
          <div style={{ height: 14 }} />
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 8 }}>
            {[
              { l: "GDP 2026", v: "+6.4%", c: "#1D9E75" },
              { l: "CPI", v: "3.8%", c: accent.primary },
              { l: "Lãi suất", v: "↓ 4.5%", c: "#2B7FFF" },
              { l: "VN-Index P/E", v: "12.4×", c: T.text },
            ].map(s => (
              <div key={s.l} style={{ padding: "10px 12px", borderRadius: 10, background: T.surface, border: `1px solid ${T.border}` }}>
                <div style={{ fontFamily: FONTS.ui, fontSize: 9.5, color: T.textMute, letterSpacing: 0.6, textTransform: "uppercase" }}>{s.l}</div>
                <div style={{ fontFamily: FONTS.fraunces, fontSize: 20, color: s.c, marginTop: 2, fontVariantNumeric: "tabular-nums" }}>{s.v}</div>
              </div>
            ))}
          </div>
        </DeepSection>

        {/* Section: Suggested portfolio */}
        <DeepSection T={T} accent={accent} index="02" title={t.sectionPortfolio}>
          {/* Donut chart */}
          <div style={{ display: "flex", alignItems: "center", gap: 18 }}>
            <DonutChart items={sug} size={120} T={T} />
            <div style={{ flex: 1, display: "flex", flexDirection: "column", gap: 7 }}>
              {sug.map(s => (
                <div key={s.label} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 6 }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 7, minWidth: 0 }}>
                    <span style={{ width: 8, height: 8, borderRadius: 2, background: s.c, flexShrink: 0 }}/>
                    <span style={{ fontFamily: FONTS.ui, fontSize: 10.5, color: T.text, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>{s.label}</span>
                  </div>
                  <span style={{ fontFamily: FONTS.ui, fontSize: 10.5, color: T.textDim, fontVariantNumeric: "tabular-nums", fontWeight: 600 }}>{s.pct}%</span>
                </div>
              ))}
            </div>
          </div>
          {/* Expected metrics */}
          <div style={{ height: 14 }} />
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 8 }}>
            {[
              { l: t.expRet, v: `+11.2%`, sub: t.perYearLabel, c: accent.primary },
              { l: t.expVol, v: `9.4%`, sub: t.perYearLabel, c: T.text },
              { l: t.expSharpe, v: `1.18`, sub: "", c: T.text },
              { l: t.expMaxDD, v: `-12%`, sub: "", c: "#E24B4A" },
            ].map(s => (
              <div key={s.l} style={{ padding: "10px 12px", borderRadius: 10, background: T.surface, border: `1px solid ${T.border}` }}>
                <div style={{ fontFamily: FONTS.ui, fontSize: 9.5, color: T.textMute, letterSpacing: 0.6, textTransform: "uppercase" }}>{s.l}</div>
                <div style={{ fontFamily: FONTS.fraunces, fontSize: 20, color: s.c, marginTop: 2, fontVariantNumeric: "tabular-nums" }}>
                  {s.v}<span style={{ fontSize: 11, color: T.textMute, marginLeft: 2 }}>{s.sub}</span>
                </div>
              </div>
            ))}
          </div>
        </DeepSection>

        {/* Section: Roadmap */}
        <DeepSection T={T} accent={accent} index="03" title={t.sectionRoadmap}>
          <div style={{ display: "flex", flexDirection: "column" }}>
            {[
              { phase: "0–30 ngày", title: t.action1, body: "Chuyển dần từ tiền gửi sang trái phiếu chính phủ kỳ hạn ngắn." },
              { phase: "30–90 ngày", title: t.action2, body: "Mở vị thế VHM, FPT, MWG, VCB theo chiến lược DCA." },
              { phase: "90–180 ngày", title: t.action3, body: "Phân bổ vào trái phiếu doanh nghiệp xếp hạng A trở lên." },
            ].map((r, i, arr) => (
              <div key={i} style={{ display: "flex", gap: 12, paddingBottom: i === arr.length - 1 ? 0 : 16, position: "relative" }}>
                <div style={{ position: "relative", display: "flex", flexDirection: "column", alignItems: "center", flexShrink: 0 }}>
                  <div style={{ width: 10, height: 10, borderRadius: "50%", background: accent.primary, marginTop: 5, boxShadow: `0 0 0 4px ${accent.primarySoft}` }}/>
                  {i < arr.length - 1 && <div style={{ width: 1, flex: 1, background: T.borderStrong, marginTop: 4 }}/>}
                </div>
                <div style={{ flex: 1 }}>
                  <div style={{ fontFamily: FONTS.ui, fontSize: 9.5, color: accent.primary, letterSpacing: 1.2, textTransform: "uppercase", fontWeight: 600 }}>{r.phase}</div>
                  <div style={{ fontFamily: FONTS.fraunces, fontSize: 16, color: T.text, marginTop: 4, lineHeight: 1.3 }}>{r.title}</div>
                  <div style={{ fontFamily: FONTS.ui, fontSize: 11.5, color: T.textDim, marginTop: 5, lineHeight: 1.5 }}>{r.body}</div>
                </div>
              </div>
            ))}
          </div>
        </DeepSection>

        {/* Section: Risk */}
        <DeepSection T={T} accent={accent} index="04" title={t.sectionRisk}>
          {/* Risk bars */}
          {[
            { l: "Rủi ro thị trường", v: 0.42, c: "#E2A14B" },
            { l: "Rủi ro thanh khoản", v: 0.28, c: "#1D9E75" },
            { l: "Rủi ro lạm phát", v: 0.55, c: "#E24B4A" },
            { l: "Rủi ro tỷ giá", v: 0.32, c: accent.primary },
          ].map(r => (
            <div key={r.l} style={{ marginBottom: 10 }}>
              <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 5 }}>
                <span style={{ fontFamily: FONTS.ui, fontSize: 11.5, color: T.text }}>{r.l}</span>
                <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: r.c, fontWeight: 600, fontVariantNumeric: "tabular-nums" }}>{Math.round(r.v * 100)}%</span>
              </div>
              <div style={{ height: 6, borderRadius: 999, background: T.surfaceStrong, overflow: "hidden" }}>
                <div style={{ width: `${r.v * 100}%`, height: "100%", background: r.c, borderRadius: 999 }}/>
              </div>
            </div>
          ))}
        </DeepSection>

        {/* Lucy quote */}
        <div style={{
          position: "relative", padding: "22px 22px",
          borderRadius: 16,
          background: `linear-gradient(155deg, ${accent.primarySoft}, ${T.surface} 60%)`,
          border: `1px solid ${accent.primary}30`, overflow: "hidden",
        }}>
          <div style={{ fontFamily: FONTS.fraunces, fontSize: 56, color: accent.primary, position: "absolute", top: -4, left: 14, lineHeight: 1, opacity: 0.7 }}>“</div>
          <div style={{ paddingLeft: 24 }}>
            <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 10 }}>
              <LucyMark size={20} accent={accent.primary} />
              <span style={{ fontFamily: FONTS.ui, fontSize: 10.5, fontWeight: 600, color: accent.primary, letterSpacing: 1.2, textTransform: "uppercase" }}>{t.aiCommentary}</span>
            </div>
            <p style={{ fontFamily: FONTS.fraunces, fontSize: 16, color: T.text, lineHeight: 1.5, margin: 0, fontStyle: "italic", letterSpacing: -0.1 }}>
              {t.quote}
            </p>
          </div>
        </div>

        <div style={{ height: 22 }} />

        {/* Disclaimer */}
        <div style={{
          padding: "14px 16px", borderRadius: 12,
          border: `1px dashed ${T.borderStrong}`, background: "transparent",
        }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 9.5, fontWeight: 600, letterSpacing: 1.2, textTransform: "uppercase", color: T.textMute, marginBottom: 6 }}>{t.sectionDisclaimer}</div>
          <Body T={T} size={11} style={{ color: T.textDim, lineHeight: 1.55 }}>{t.disclaimerBody}</Body>
        </div>

        <div style={{ height: 24 }} />

        {/* CTAs */}
        <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
          <PrimaryButton onClick={() => alert("PDF download (mock)")} accent={accent} T={T}>{t.download}</PrimaryButton>
          <SecondaryButton onClick={() => alert("Booking (mock)")} accent={accent} T={T}>{t.bookConsult}</SecondaryButton>
          <GhostButton onClick={onRestart} T={T}>{t.restart}</GhostButton>
        </div>
      </div>
    </div>
  );
}

function DeepSection({ T, accent, index, title, children }) {
  return (
    <div style={{ marginBottom: 26 }}>
      <div style={{ display: "flex", alignItems: "baseline", gap: 10, marginBottom: 12, paddingBottom: 8, borderBottom: `1px solid ${T.border}` }}>
        <span style={{ fontFamily: FONTS.fraunces, fontSize: 13, color: accent.primary, fontVariantNumeric: "tabular-nums" }}>{index}</span>
        <span style={{ fontFamily: FONTS.fraunces, fontSize: 19, color: T.text, letterSpacing: -0.3 }}>{title}</span>
      </div>
      {children}
    </div>
  );
}

// Donut chart for suggested allocation
function DonutChart({ items, size, T }) {
  const r = size / 2 - 10, cx = size / 2, cy = size / 2;
  const c = 2 * Math.PI * r;
  let acc = 0;
  return (
    <div style={{ position: "relative", width: size, height: size, flexShrink: 0 }}>
      <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} style={{ transform: "rotate(-90deg)" }}>
        <circle cx={cx} cy={cy} r={r} stroke={T.surfaceStrong} strokeWidth="14" fill="none"/>
        {items.map((it, i) => {
          const dash = (it.pct / 100) * c;
          const offset = -acc * c / 100;
          acc += it.pct;
          return (
            <circle key={i} cx={cx} cy={cy} r={r} stroke={it.c} strokeWidth="14" fill="none"
              strokeDasharray={`${dash} ${c}`} strokeDashoffset={offset}/>
          );
        })}
      </svg>
      <div style={{ position: "absolute", inset: 0, display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center" }}>
        <div style={{ fontFamily: FONTS.ui, fontSize: 8.5, color: T.textMute, letterSpacing: 1.2, textTransform: "uppercase" }}>Lucy</div>
        <div style={{ fontFamily: FONTS.fraunces, fontSize: 24, color: T.text, lineHeight: 1, marginTop: 2 }}>100%</div>
      </div>
    </div>
  );
}

Object.assign(window, { AssetSimulation, DeepAnalysisScreen, DeepReportScreen });
