// Screen: Missing Out / Deep Dive (Sections 4.7.3, 4.7.4, 4.8, 4.9) and Dashboard

function MissingOutPanel2Screen({ T, t, accent, theme, onNext }) {
  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}>Bảng 2 / 3</Kicker>
        <div style={{ height: 6 }} />
        <SerifTitle T={T} size={36}>Bạn đang bỏ lỡ điều gì?</SerifTitle>
        <div style={{ height: 16 }} />
        
        <Kicker T={T} accent={accent}>A — Hiệu suất 5 năm</Kicker>
        <div style={{ padding: "16px", borderRadius: 14, background: T.surface, border: `1px solid ${T.border}`, marginTop: 8 }}>
          <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 6 }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: accent.primary }}>Lucy Capital · VN Equity</span>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 16, color: accent.primary, fontWeight: 600 }}>+18.4%</span>
          </div>
          <div style={{ height: 6, borderRadius: 3, background: `${accent.primary}30`, overflow: "hidden", marginBottom: 14 }}>
            <div style={{ height: "100%", width: "100%", background: accent.primary }} />
          </div>
          
          <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 6 }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text }}>Chỉ số VN30</span>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 16, color: T.text, fontWeight: 600 }}>+9.1%</span>
          </div>
          <div style={{ height: 6, borderRadius: 3, background: T.borderStrong, overflow: "hidden", marginBottom: 14 }}>
            <div style={{ height: "100%", width: "49%", background: T.textDim }} />
          </div>
          
          <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 6 }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.textDim }}>Tiền gửi NH tốt nhất</span>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 16, color: T.textDim, fontWeight: 600 }}>+5.5%</span>
          </div>
          <div style={{ height: 6, borderRadius: 3, background: T.borderStrong, overflow: "hidden" }}>
            <div style={{ height: "100%", width: "30%", background: T.textDim }} />
          </div>
        </div>

        <div style={{ padding: "16px", borderRadius: 14, background: `linear-gradient(135deg, ${accent.primary}20, ${accent.primary}05)`, border: `1px solid ${accent.primary}40`, marginTop: 14 }}>
          <Kicker T={T} accent={accent}>Quy đổi VND</Kicker>
          <Body T={T} size={14} style={{ color: T.text, margin: "6px 0 12px" }}>Với <span style={{ fontFamily: FONTS.fraunces, color: T.text, fontSize: 16 }}>5 tỷ</span> ban đầu, sau 5 năm:</Body>
          <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8, borderBottom: `1px dashed ${T.borderStrong}`, paddingBottom: 8 }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 14, color: T.text }}>Tiền gửi NH</span>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 16, color: T.textDim }}>~6.5 tỷ</span>
          </div>
          <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8, borderBottom: `1px dashed ${T.borderStrong}`, paddingBottom: 8 }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 14, color: T.text }}>Lucy Capital VN Equity</span>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 16, color: accent.primary }}>~11.7 tỷ</span>
          </div>
          <div style={{ display: "flex", justifyContent: "space-between", paddingTop: 4 }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 15, color: accent.primary, fontWeight: 600 }}>Chênh lệch</span>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 20, color: accent.primary, fontWeight: 600 }}>+5.2 tỷ</span>
          </div>
        </div>

        <div style={{ height: 24 }} />
        <Kicker T={T} accent={accent}>B — Lợi ích quản lý chuyên nghiệp</Kicker>
        <div style={{ padding: "16px", borderRadius: 14, background: T.surface, border: `1px solid ${T.border}`, marginTop: 8 }}>
          <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
            {[
              "Không cần theo dõi thị trường hàng ngày.",
              "Quyết định dựa trên phân tích định lượng — không tin đồn.",
              "Quản lý rủi ro hệ thống — không đặt cược một cổ phiếu.",
              "Kỷ luật đầu tư — không bị chi phối bởi cảm xúc."
            ].map((text, i) => (
              <div key={i} style={{ display: "flex", gap: 8, alignItems: "flex-start" }}>
                <div style={{ width: 14, height: 14, borderRadius: "50%", background: `${accent.primary}20`, color: accent.primary, display: "flex", alignItems: "center", justifyContent: "center", marginTop: 2, flexShrink: 0, fontSize: 8 }}>●</div>
                <Body T={T} size={13} style={{ color: T.textMute }}>{text}</Body>
              </div>
            ))}
          </div>
        </div>

        <div style={{ height: 42 }} />
        <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
          <PrimaryButton onClick={onNext} accent={accent} T={T}>Nếu đầu tư khác đi</PrimaryButton>
        </div>
      </div>
    </div>
  );
}

function MissingOutPanel3Screen({ T, t, accent, theme, alloc, onNext }) {
  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}>Bảng 3 / 3</Kicker>
        <div style={{ height: 6 }} />
        <SerifTitle T={T} size={36}>Nếu bạn đầu tư khác đi…</SerifTitle>
        <div style={{ height: 12 }} />
        <Body T={T} size={14} style={{ color: T.text, marginBottom: 16, lineHeight: 1.5 }}>
          Mô phỏng: nếu <span style={{ fontFamily: FONTS.fraunces, color: accent.primary, fontSize: 18 }}>3 tỷ</span> tiền gửi của bạn được quản lý chuyên nghiệp từ <span style={{ fontFamily: FONTS.fraunces, color: T.text, fontSize: 16 }}>01/2022</span>.
        </Body>
        
        <div style={{ padding: "16px 12px 12px", borderRadius: 14, background: T.surface, border: `1px solid ${T.border}`, marginBottom: 16 }}>
          <svg viewBox="0 0 320 180" preserveAspectRatio="none" style={{ width: "100%", height: 180, display: "block" }}>
            <g style={{ stroke: T.borderStrong, strokeWidth: 1 }}>
              <line x1="0" y1="30" x2="320" y2="30"/>
              <line x1="0" y1="70" x2="320" y2="70"/>
              <line x1="0" y1="110" x2="320" y2="110"/>
              <line x1="0" y1="150" x2="320" y2="150"/>
            </g>
            <polyline fill="none" stroke={T.textDim} strokeWidth="2" points="10,140 50,136 90,132 130,128 170,124 210,120 250,116 290,112 310,110"/>
            <polyline fill="none" stroke={accent.primary} strokeWidth="3" strokeLinecap="round" points="10,140 50,128 90,134 130,108 170,150 210,90 250,72 290,50 310,38"/>
            <line x1="170" y1="20" x2="170" y2="160" stroke={accent.primary} strokeWidth="1" strokeDasharray="3,3" opacity="0.5"/>
            <text x="174" y="28" fill={accent.primary} fontSize="10" fontFamily={FONTS.ui} opacity="0.8">Q4'22 điều chỉnh</text>
            <circle cx="310" cy="38" r="4.5" fill={accent.primary}/>
            <circle cx="310" cy="110" r="4" fill={T.textDim}/>
          </svg>
          <div style={{ display: "flex", justifyContent: "space-between", marginTop: 12, fontFamily: FONTS.ui, fontSize: 11, color: T.textMute }}>
            <span>01/2022</span><span>04/2026</span>
          </div>
        </div>

        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12, marginBottom: 16 }}>
          <div style={{ padding: "16px", borderRadius: 14, background: T.surface, border: `1px solid ${T.border}`, textAlign: "center" }}>
            <div style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text }}>Tiền gửi NH</div>
            <div style={{ fontFamily: FONTS.fraunces, fontSize: 26, color: T.text, marginTop: 8 }}>3.7 tỷ</div>
            <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: T.textDim, marginTop: 4 }}>+22% (4 năm)</div>
          </div>
          <div style={{ padding: "16px", borderRadius: 14, background: `linear-gradient(135deg, ${accent.primary}15, transparent)`, border: `1px solid ${accent.primary}40`, textAlign: "center" }}>
            <div style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text }}>Lucy VN Equity</div>
            <div style={{ fontFamily: FONTS.fraunces, fontSize: 26, color: accent.primary, marginTop: 8 }}>5.9 tỷ</div>
            <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: accent.primary, marginTop: 4 }}>+96% (4 năm)</div>
          </div>
        </div>

        <div style={{ padding: "20px", borderRadius: 14, background: accent.primary, color: "#000", textAlign: "center" }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 13, fontWeight: 600, textTransform: "uppercase", letterSpacing: 0.5 }}>Chênh lệch</div>
          <div style={{ fontFamily: FONTS.fraunces, fontSize: 36, marginTop: 8, fontWeight: 600 }}>+ 2.2 tỷ đồng</div>
          <div style={{ fontFamily: FONTS.ui, fontSize: 13, marginTop: 6, opacity: 0.8 }}>Trên cùng 3 tỷ ban đầu</div>
        </div>

        <div style={{ height: 16 }} />
        <div style={{ padding: "12px", borderRadius: 8, background: "#3b82f608", border: `1px dashed #3b82f630` }}>
          <Body T={T} size={11} style={{ color: T.textDim, textAlign: "justify" }}>
            <strong>Lưu ý:</strong> Đây là mô phỏng dựa trên dữ liệu lịch sử và <strong>không đảm bảo lợi nhuận tương lai</strong>. Đầu tư luôn có rủi ro. Kết quả thực tế có thể khác biệt đáng kể.
          </Body>
        </div>

        <div style={{ height: 42 }} />
        <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
          <PrimaryButton onClick={onNext} accent={accent} T={T}>Thử phân bổ tối ưu</PrimaryButton>
        </div>
      </div>
    </div>
  );
}

function SimulatorScreen({ T, t, accent, theme, alloc, onNext }) {
  const [simAlloc, setSimAlloc] = React.useState(alloc);
  const [selectedScenario, setSelectedScenario] = React.useState(null);
  const [hoverScen, setHoverScen] = React.useState(null);
  const [activeScen, setActiveScen] = React.useState(null);

  const applyScenario = (type) => {
    setSelectedScenario(type);
    if (type === "safe") setSimAlloc({ bank: 45, realEstate: 15, stocks: 25, bonds: 5, gold: 10, crypto: 0 });
    if (type === "balanced") setSimAlloc({ bank: 25, realEstate: 15, stocks: 40, bonds: 10, gold: 10, crypto: 0 });
    if (type === "growth") setSimAlloc({ bank: 5, realEstate: 10, stocks: 70, bonds: 5, gold: 0, crypto: 10 });
    if (type === "optimal") setSimAlloc({ bank: 5, realEstate: 15, stocks: 65, bonds: 5, gold: 10, crypto: 0 });
  };

  const RET = { bank: 0.055, realEstate: 0.09, stocks: 0.18, bonds: 0.07, gold: 0.08, crypto: 0.40, cash: 0.02 };
  
  const sumW = (w) => Object.values(w).reduce((a, b) => a + (b || 0), 0) || 100;
  
  // Calculate simulation returns
  const wSim = sumW(simAlloc);
  const baseSimRet = Object.entries(simAlloc).reduce((acc, [k, v]) => acc + (v / wSim) * (RET[k] || 0), 0);
  // Lucy AI adds an "Alpha" (excess return) due to quantitative optimization and active management
  const alpha = selectedScenario === "optimal" ? 0.037 : (selectedScenario === "growth" ? 0.025 : (selectedScenario ? 0.015 : 0));
  const simRet = baseSimRet + alpha;
  
  // Calculate current user allocation returns
  const wCur = sumW(alloc);
  // Assume current allocation is unoptimized (retail investor penalty ~3% underperformance due to timing/fees/emotion)
  const curRet = Math.max(0.04, Object.entries(alloc).reduce((acc, [k, v]) => acc + (v / wCur) * (RET[k] || 0), 0) - 0.03);
  
  const score = Math.min(100, Math.round(40 + (simRet * 100 * 3.2)));
  const maxDrawdown = simRet > 0.16 ? "-18%" : simRet > 0.12 ? "-12%" : "-6%";

  const capital = 5; // Assuming 5B capital
  const sim5 = capital * Math.pow(1 + simRet, 5);
  const cur5 = capital * Math.pow(1 + curRet, 5);
  const delta5 = sim5 - cur5;
  const deltaPct = (simRet - curRet) * 100;

  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}>Mô phỏng</Kicker>
        <div style={{ height: 6 }} />
        <SerifTitle T={T} size={36}>Nếu bạn phân bổ khác đi?</SerifTitle>
        <div style={{ height: 16 }} />

        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 8, marginBottom: 20 }}>
          {[
            { id: "safe", label: "An toàn", desc: "8-10% /năm" },
            { id: "balanced", label: "Cân bằng", desc: "12-15% /năm" },
            { id: "growth", label: "Tăng trưởng", desc: "18-22% /năm" },
            { id: "optimal", label: "Tối ưu cho tôi", desc: "Gợi ý từ AI" }
          ].map(scen => {
            const isSel = selectedScenario === scen.id;
            const isHov = hoverScen === scen.id;
            const isAct = activeScen === scen.id;
            return (
              <button 
                key={scen.id} 
                onClick={() => applyScenario(scen.id)}
                onMouseEnter={() => setHoverScen(scen.id)}
                onMouseLeave={() => { setHoverScen(null); setActiveScen(null); }}
                onMouseDown={() => setActiveScen(scen.id)}
                onMouseUp={() => setActiveScen(null)}
                style={{
                  padding: "12px", borderRadius: 12, border: `1px solid ${isSel ? accent.primary : T.border}`,
                  background: isSel ? `${accent.primary}20` : (isAct ? T.surfaceStrong : (isHov ? T.surfaceStrong : T.surface)),
                  color: isSel ? accent.primary : T.text,
                  display: "flex", flexDirection: "column", alignItems: "flex-start", gap: 4,
                  cursor: "pointer", transition: "all 150ms",
                  transform: isAct ? "scale(0.97)" : (isHov ? "scale(1.02)" : "scale(1)"),
                  boxShadow: isSel ? `0 4px 12px ${accent.primaryGlow}` : "none",
                  zIndex: isHov ? 2 : 1
                }}>
                <div style={{ fontFamily: FONTS.ui, fontSize: 13, fontWeight: isSel ? 700 : 500 }}>{scen.label}</div>
                <div style={{ fontFamily: FONTS.ui, fontSize: 11, opacity: 0.7 }}>{scen.desc}</div>
              </button>
            );
          })}
        </div>

        {(() => {
          const colors = {
            bank: "#94A3B8",
            realEstate: "#64748B",
            stocks: accent.primary,
            bonds: "#475569",
            gold: "#CBD5E1",
            crypto: "#334155"
          };
          let cumulative = 0;
          const gradientStops = Object.entries(simAlloc).map(([k, v]) => {
            if (!v) return "";
            const pct = (v / wSim) * 100;
            const start = cumulative;
            cumulative += pct;
            const end = cumulative;
            return `${colors[k]} ${start}% ${end}%`;
          }).filter(Boolean).join(", ");
          
          return (
            <div style={{ padding: "20px", borderRadius: 14, background: T.surface, border: `1px solid ${T.border}`, marginBottom: 24, display: "flex", gap: 20, alignItems: "center" }}>
              <div style={{ width: 120, height: 120, borderRadius: "50%", background: `conic-gradient(${gradientStops})`, flexShrink: 0, boxShadow: "0 4px 12px rgba(0,0,0,0.1)" }} />
              <div style={{ flex: 1, display: "flex", flexDirection: "column", gap: 8 }}>
                {Object.entries(simAlloc).map(([key, val]) => {
                   if (val === 0) return null;
                   return (
                      <div key={key} style={{ display: "flex", alignItems: "center", gap: 8 }}>
                         <div style={{ width: 10, height: 10, borderRadius: 2, background: colors[key], flexShrink: 0 }} />
                         <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: T.text, flex: 1, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>{t[key]}</div>
                         <div style={{ fontFamily: FONTS.fraunces, fontSize: 13, color: T.text, fontWeight: 600 }}>{Math.round((val/wSim)*100)}%</div>
                      </div>
                   )
                })}
              </div>
            </div>
          );
        })()}

        <Kicker T={T} accent={accent}>Kết quả mô phỏng sau 5 năm</Kicker>
        <div style={{ padding: "20px", borderRadius: 16, background: `linear-gradient(165deg, ${T.surfaceStrong}, ${T.surface})`, border: `1px solid ${T.border}`, marginTop: 8, boxShadow: "inset 0 1px 0 rgba(255,255,255,0.05)" }}>
          <div style={{ display: "flex", justifyContent: "space-between", paddingBottom: 12, borderBottom: `1px solid ${T.borderStrong}` }}>
            <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text }}>Lợi nhuận trung bình</span>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 18, color: accent.primary, fontWeight: 700 }}>+{(simRet*100).toFixed(1)}% /năm</span>
          </div>
          
          <div style={{ display: "flex", justifyContent: "space-between", padding: "12px 0", borderBottom: `1px solid ${T.borderStrong}` }}>
            <div style={{ display: "flex", flexDirection: "column" }}>
              <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text }}>Ước tính tài sản</span>
              <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textDim }}>Vốn {capital} tỷ</span>
            </div>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 18, color: accent.primary, fontWeight: 700 }}>{sim5.toFixed(1)} tỷ</span>
          </div>

          <div style={{ display: "flex", justifyContent: "space-between", padding: "12px 0", borderBottom: `1px solid ${T.borderStrong}` }}>
            <div style={{ display: "flex", flexDirection: "column" }}>
              <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text }}>Biến động tối đa</span>
              <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textDim }}>Rủi ro giảm giá (Max Drawdown)</span>
            </div>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 16, color: T.text, fontWeight: 600 }}>{maxDrawdown}</span>
          </div>

          <div style={{ background: `${accent.primary}10`, margin: "12px -20px -20px -20px", padding: "16px 20px", borderRadius: "0 0 16px 16px", borderTop: `1px solid ${accent.primary}30` }}>
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
              <div style={{ display: "flex", flexDirection: "column" }}>
                <span style={{ fontFamily: FONTS.ui, fontSize: 13, color: accent.primary, fontWeight: 600 }}>Khác biệt so với hiện tại</span>
                <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textDim }}>Mức chênh lệch lợi nhuận sau 5 năm</span>
              </div>
              <div style={{ textAlign: "right" }}>
                <div style={{ fontFamily: FONTS.fraunces, fontSize: 20, color: accent.primary, fontWeight: 700 }}>+{delta5.toFixed(1)} tỷ</div>
                <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: accent.primary, fontWeight: 600 }}>+{Math.round(deltaPct)}% lợi nhuận/năm</div>
              </div>
            </div>
          </div>
        </div>

        <div style={{ marginTop: 16, padding: "12px", background: `${T.borderStrong}30`, borderRadius: 12, border: `1px dashed ${T.borderStrong}` }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: T.text, fontWeight: 600, marginBottom: 4 }}>💡 Diễn giải kết quả:</div>
          <Body T={T} size={11} style={{ color: T.textDim, textAlign: "justify", lineHeight: 1.5 }}>
            Nếu giữ nguyên danh mục phân bổ hiện tại, tài sản của bạn sau 5 năm ước tính chỉ đạt khoảng <b>{cur5.toFixed(1)} tỷ</b>. Nhưng nếu chuyển sang chiến lược <b>{selectedScenario === "optimal" ? "Tối ưu AI" : "Được chọn"}</b>, tài sản có thể tăng lên <b>{sim5.toFixed(1)} tỷ</b>. <br/><br/>Khoảng chênh lệch khổng lồ <b>{delta5.toFixed(1)} tỷ</b> đến từ sức mạnh của việc tối ưu hóa tỷ trọng, bắt đúng nhịp thị trường và loại bỏ yếu tố cảm xúc.
          </Body>
        </div>

        <div style={{ height: 32 }} />
        <PrimaryButton onClick={onNext} accent={accent} T={T}>Phân tích chiến lược Lucy AI</PrimaryButton>
      </div>
    </div>
  );
}

function FundPreviewScreen({ T, t, accent, theme, onNext, onRestart }) {
  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}>Chiến Lược Quản Lý Quỹ</Kicker>
        <div style={{ height: 10 }} />
        <SerifTitle T={T} size={28}>Để tài sản của bạn làm việc hiệu quả hơn</SerifTitle>
        <div style={{ height: 16 }} />
        <Body T={T} size={14} style={{ color: T.textDim, marginBottom: 24, lineHeight: 1.5 }}>
          Một cuộc trao đổi 30 phút với chuyên gia quản lý quỹ — không có áp lực, không phí tư vấn. Chúng tôi sẽ chia sẻ chiến lược phân bổ phù hợp với hồ sơ của bạn.
        </Body>

        <SerifTitle T={T} size={22}>Đội ngũ và chiến lược đứng sau công cụ này</SerifTitle>
        <div style={{ height: 16 }} />
        
        <div style={{ padding: "16px", borderRadius: 14, background: T.surface, border: `1px solid ${T.border}`, marginBottom: 16 }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 13.5, color: T.text, fontWeight: 600, marginBottom: 12 }}>Tại sao chúng tôi khác biệt?</div>
          <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
            {[
              { t: "Phân tích định lượng", b: "Mọi quyết định đầu tư đều dựa trên mô hình toán học, không phải tin đồn." },
              { t: "Minh bạch hoàn toàn", b: "Hiệu suất được kiểm toán độc lập. Luôn biết tiền đang ở đâu." },
              { t: "Quản lý rủi ro nghiêm ngặt", b: "Danh mục đa dạng hoá, có hệ thống dừng lỗ tự động." },
              { t: "Chứng chỉ quốc tế", b: "CFA charterholder với hơn 10 năm kinh nghiệm tại Việt Nam." }
            ].map((item, i) => (
              <div key={i}>
                <div style={{ fontFamily: FONTS.ui, fontSize: 12.5, color: accent.primary, fontWeight: 600 }}>{item.t}</div>
                <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: T.textMute, marginTop: 2 }}>{item.b}</div>
              </div>
            ))}
          </div>
        </div>

        <div style={{ padding: "16px", borderRadius: 14, background: `linear-gradient(155deg, ${accent.primarySoft}, transparent 80%)`, border: `1px solid ${accent.primary}40`, marginBottom: 24 }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 13.5, color: T.text, fontWeight: 600, marginBottom: 4 }}>Điều kiện tham gia</div>
          <Body T={T} size={12} style={{ color: T.textDim }}>Đầu tư tối thiểu: 2 tỷ đồng. Dành cho nhà đầu tư đủ điều kiện.</Body>
        </div>

        <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
          <PrimaryButton onClick={onNext} accent={accent} T={T}>📅 Đặt lịch tư vấn 30 phút</PrimaryButton>
          <SecondaryButton onClick={() => alert("Gửi yêu cầu tài liệu chi tiết (mock)")} accent={accent} T={T}>Nhận tài liệu</SecondaryButton>
        </div>
      </div>
    </div>
  );
}

function BookingFormScreen({ T, t, accent, theme, name, gender, setGender, onNext }) {
  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}>Liên Hệ Tư Vấn</Kicker>
        <div style={{ height: 10 }} />
        <SerifTitle T={T} size={28}>Để lại thông tin để chuyên gia hỗ trợ bạn</SerifTitle>
        <div style={{ height: 24 }} />
        
        <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
          <div>
            <div style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text, marginBottom: 8, fontWeight: 500 }}>Danh xưng</div>
            <select value={gender} onChange={(e) => setGender(e.target.value)} style={{ width: "100%", padding: "14px 16px", borderRadius: 12, border: `1px solid ${T.borderStrong}`, background: T.surface, color: T.text, fontFamily: FONTS.ui, fontSize: 15, outline: "none", appearance: "none" }}>
              <option value="anh">Anh</option>
              <option value="chị">Chị</option>
            </select>
          </div>
          <div>
            <div style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text, marginBottom: 8, fontWeight: 500 }}>Họ và tên</div>
            <input type="text" defaultValue={name || ""} placeholder="VD: Nguyễn Văn A" style={{ width: "100%", padding: "14px 16px", borderRadius: 12, border: `1px solid ${T.borderStrong}`, background: T.surface, color: T.text, fontFamily: FONTS.ui, fontSize: 15, outline: "none" }} />
          </div>
          <div>
            <div style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text, marginBottom: 8, fontWeight: 500 }}>Số điện thoại (Zalo)</div>
            <input type="tel" placeholder="09xxxx" style={{ width: "100%", padding: "14px 16px", borderRadius: 12, border: `1px solid ${T.borderStrong}`, background: T.surface, color: T.text, fontFamily: FONTS.ui, fontSize: 15, outline: "none" }} />
          </div>
          <div>
            <div style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.text, marginBottom: 8, fontWeight: 500 }}>Thời gian thuận tiện để liên hệ</div>
            <select style={{ width: "100%", padding: "14px 16px", borderRadius: 12, border: `1px solid ${T.borderStrong}`, background: T.surface, color: T.text, fontFamily: FONTS.ui, fontSize: 15, outline: "none", appearance: "none" }}>
              <option>Trong giờ hành chính</option>
              <option>Ngoài giờ hành chính</option>
              <option>Cuối tuần</option>
            </select>
          </div>
        </div>

        <div style={{ height: 32 }} />
        <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
          <PrimaryButton onClick={onNext} accent={accent} T={T}>Gửi thông tin</PrimaryButton>
        </div>
      </div>
    </div>
  );
}

function BookingConfirmScreen({ T, t, accent, theme, name, gender, onNext }) {
  return (
    <div style={{ position: "relative", minHeight: "100%", padding: "40px 22px 120px", display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center" }}>
      <AmbientBg T={T} accent={accent} theme={theme} variant="report" />
      <div style={{ position: "relative", zIndex: 1, textAlign: "center", width: "100%" }}>
        <div style={{ width: 64, height: 64, borderRadius: "50%", background: `${accent.primary}20`, color: accent.primary, display: "flex", alignItems: "center", justifyContent: "center", margin: "0 auto 24px" }}>
          <svg width="32" height="32" viewBox="0 0 24 24"><path d="M5 13l4 4L19 7" stroke="currentColor" strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
        </div>
        <SerifTitle T={T} size={32}>Cảm ơn {gender} {name || ""}</SerifTitle>
        <div style={{ height: 16 }} />
        <Body T={T} size={14} style={{ color: T.textDim, lineHeight: 1.6 }}>
          Chuyên gia của chúng tôi sẽ phản hồi qua Zalo trong 15 phút.
        </Body>
        
        <div style={{ height: 42 }} />
        <PrimaryButton onClick={onNext} accent={accent} T={T}>Xem Insights</PrimaryButton>
      </div>
    </div>
  );
}

// ---------------- DASHBOARD / TAB BAR VIEWS ----------------

function DashboardScreen({ T, t, accent, theme, alloc, name, onRestart, onGoToReport }) {
  const [activeTab, setActiveTab] = React.useState("pulse"); // pulse, insights, account

  return (
    <div style={{ display: "flex", flexDirection: "column", minHeight: "100%", background: T.bg }}>
      <div style={{ flex: 1, padding: "20px 22px 20px", position: "relative", zIndex: 1 }}>
        {activeTab === "pulse" && <MarketPulseTab T={T} t={t} accent={accent} name={name} score={47} onGoToInsights={() => setActiveTab("insights")} onGoToReport={onGoToReport} />}
        {activeTab === "insights" && <InsightsTab T={T} t={t} accent={accent} />}
        {activeTab === "account" && <AccountTab T={T} t={t} accent={accent} name={name} alloc={alloc} onRestart={onRestart} />}
      </div>

      {/* Tab Bar — sticky inside phone frame */}
      <div style={{ 
        position: "sticky", bottom: 0,
        width: "100%", height: 84, flexShrink: 0,
        background: T.surface, borderTop: `1px solid ${T.border}`,
        display: "flex", justifyContent: "space-around", alignItems: "center",
        paddingBottom: 20, zIndex: 100,
        backdropFilter: "blur(20px) saturate(180%)",
        WebkitBackdropFilter: "blur(20px) saturate(180%)",
      }}>
        <TabButton id="pulse" icon="M13 17l5-5-5-5M6 17l5-5-5-5" label="Market Pulse" active={activeTab === "pulse"} onClick={() => setActiveTab("pulse")} T={T} accent={accent} />
        <TabButton id="insights" icon="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9.5L18.5 7H20" label="Insights" active={activeTab === "insights"} onClick={() => setActiveTab("insights")} T={T} accent={accent} />
        <TabButton id="account" icon="M20 21v-2a4 4 0 00-4-4H8a4 4 0 00-4 4v2M12 11a4 4 0 100-8 4 4 0 000 8z" label="Account" active={activeTab === "account"} onClick={() => setActiveTab("account")} T={T} accent={accent} />
      </div>
    </div>
  );
}

function TabButton({ id, icon, label, active, onClick, T, accent }) {
  return (
    <button onClick={onClick} style={{ 
      display: "flex", flexDirection: "column", alignItems: "center", gap: 4,
      background: "none", border: "none", cursor: "pointer",
      color: active ? accent.primary : T.textMute,
      transition: "color 200ms"
    }}>
      <svg width="24" height="24" viewBox="0 0 24 24"><path d={icon} stroke="currentColor" strokeWidth="1.5" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
      <div style={{ fontFamily: FONTS.ui, fontSize: 10, fontWeight: 500 }}>{label}</div>
    </button>
  );
}

function MarketPulseTab({ T, t, accent, onGoToInsights, onGoToReport, name, score }) {
  const [timeframe, setTimeframe] = React.useState("year");
  const [chartHover, setChartHover] = React.useState(null);
  const [animIn, setAnimIn] = React.useState(false);
  const [hoverCard, setHoverCard] = React.useState(null);
  
  React.useEffect(() => { requestAnimationFrame(() => setAnimIn(true)); }, []);

  const userScore = score || 47;
  const opportunityCost = 450; // triệu

  // Chart data per timeframe
  const chartData = {
    month: { labels: ["T1","T2","T3","T4"], lucy: [5.0, 5.05, 5.10, 5.15], vn30: [5.0, 5.02, 5.04, 5.06], deposit: [5.0, 5.01, 5.02, 5.03] },
    quarter: { labels: ["Q1","Q2","Q3","Q4"], lucy: [5.0, 5.15, 5.30, 5.45], vn30: [5.0, 5.08, 5.15, 5.23], deposit: [5.0, 5.05, 5.09, 5.14] },
    year: { labels: ["2022","2023","2024","2025","2026"], lucy: [5.0, 5.20, 5.42, 5.65, 5.91], vn30: [5.0, 5.11, 5.22, 5.34, 5.46], deposit: [5.0, 5.07, 5.14, 5.21, 5.28] }
  };
  const cd = chartData[timeframe];
  const maxVal = Math.max(...cd.lucy, ...cd.vn30, ...cd.deposit);
  const minVal = Math.min(...cd.lucy, ...cd.vn30, ...cd.deposit) * 0.95;
  const range = maxVal - minVal;
  const chartH = 160;
  const toY = (v) => chartH - ((v - minVal) / range) * chartH;
  const toPath = (arr) => arr.map((v, i) => `${i === 0 ? "M" : "L"}${(i / (arr.length - 1)) * 100},${toY(v)}`).join(" ");

  const now = new Date();
  const hour = now.getHours();
  const greeting = hour < 12 ? "Chào buổi sáng" : hour < 18 ? "Chào buổi chiều" : "Chào buổi tối";
  const timeStr = `${now.getHours()}:${String(now.getMinutes()).padStart(2,"0")} — ${now.getDate()}/${now.getMonth()+1}/${now.getFullYear()}`;

  const metrics = [
    { label: "VN-Index", val: "1,245", chg: "+1.2%", pos: true },
    { label: "Lãi suất", val: "5.5%", chg: "-0.2%", pos: false },
    { label: "Vàng SJC", val: "89.5tr", chg: "+2.5%", pos: true },
    { label: "BĐS", val: "+4.2%", chg: "QoQ", pos: true }
  ];

  const featured = [
    { title: "Cơ hội từ sự phân hoá nhóm vốn hoá lớn", date: "15/05/2026", img: "https://images.unsplash.com/photo-1611974789855-9c2a0a7236a3?auto=format&fit=crop&w=400&q=80" },
    { title: "Xây dựng danh mục thích ứng chu kỳ mới", date: "02/05/2026", img: "https://images.unsplash.com/photo-1460925895917-afdab827c52f?auto=format&fit=crop&w=400&q=80" }
  ];

  const fadeStyle = (delay) => ({ opacity: animIn ? 1 : 0, transform: animIn ? "translateY(0)" : "translateY(16px)", transition: `opacity 600ms ${delay}ms, transform 600ms ${delay}ms` });

  return (
    <div>
      {/* Greeting */}
      <div style={fadeStyle(0)}>
        <div style={{ fontFamily: FONTS.fraunces, fontSize: 24, color: T.text, fontWeight: 500 }}>{greeting}, {name || "bạn"} 👋</div>
        <div style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textMute, marginTop: 4 }}>Cập nhật lúc {timeStr}</div>
      </div>
      <div style={{ height: 24 }} />

      {/* Hero Score Card */}
      <div style={{ ...fadeStyle(100), padding: "20px", borderRadius: 24, background: `linear-gradient(135deg, ${accent.primary}25, ${accent.primary}08)`, border: `1px solid ${accent.primary}40`, position: "relative", overflow: "hidden", boxShadow: `0 12px 32px ${accent.primary}15` }}>
        <div style={{ position: "absolute", top: -30, right: -30, width: 150, height: 150, borderRadius: "50%", background: `${accent.primary}10`, filter: "blur(20px)" }} />
        <div style={{ display: "flex", alignItems: "center", gap: 20 }}>
          <div style={{ position: "relative", width: 84, height: 84, flexShrink: 0 }}>
            <svg width="84" height="84" viewBox="0 0 84 84">
              <circle cx="42" cy="42" r="36" fill="none" stroke={`${T.borderStrong}`} strokeWidth="7" />
              <circle cx="42" cy="42" r="36" fill="none" stroke={accent.primary} strokeWidth="7" strokeLinecap="round"
                strokeDasharray={`${(userScore / 100) * 226} 226`} strokeDashoffset="0"
                transform="rotate(-90 42 42)"
                style={{ transition: "stroke-dasharray 1.5s cubic-bezier(0.2, 0.8, 0.2, 1)" }} />
            </svg>
            <div style={{ position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center" }}>
              <span style={{ fontFamily: FONTS.fraunces, fontSize: 28, color: accent.primary, fontWeight: 700 }}>{userScore}</span>
            </div>
          </div>
          <div style={{ flex: 1 }}>
            <div style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textMute, textTransform: "uppercase", letterSpacing: 1.2, fontWeight: 700 }}>Hiệu Quả Tài Sản</div>
            <div style={{ height: 8 }} />
            <div style={{ fontFamily: FONTS.ui, fontSize: 13, color: T.textDim, lineHeight: 1.4 }}>Chi phí cơ hội bị bỏ lỡ:</div>
            <div style={{ fontFamily: FONTS.fraunces, fontSize: 24, color: "#EF4444", fontWeight: 700, marginTop: 2 }}>~{opportunityCost} triệu</div>
            <div style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textMute, marginTop: 4, lineHeight: 1.4 }}>*(Mức lợi nhuận chênh lệch nếu bạn đã đầu tư cùng Lucy AI)</div>
          </div>
        </div>
        <div style={{ marginTop: 18, display: "flex", justifyContent: "flex-end" }}>
          <button 
            onClick={onGoToReport}
            style={{ 
              padding: "8px 16px", borderRadius: 10, background: accent.primary, color: "#000",
              fontFamily: FONTS.ui, fontSize: 12, fontWeight: 700, border: "none", cursor: "pointer",
              boxShadow: `0 4px 12px ${accent.primary}40`, transition: "all 200ms"
            }}>
            Báo cáo cá nhân →
          </button>
        </div>
      </div>
      <div style={{ height: 24 }} />

      {/* Portfolio Chart */}
      <div style={{ ...fadeStyle(200), background: T.surface, border: `1px solid ${T.border}`, borderRadius: 20, padding: "18px", boxShadow: "0 4px 20px rgba(0,0,0,0.05)" }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 16 }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 14, fontWeight: 600, color: T.text }}>Mô phỏng tài sản</div>
          <div style={{ display: "flex", gap: 4, background: T.bg, borderRadius: 10, padding: 3, border: `1px solid ${T.border}` }}>
            {[{k:"month",l:"Tháng"},{k:"quarter",l:"Quý"},{k:"year",l:"Năm"}].map(tf => (
              <button key={tf.k} onClick={() => { setTimeframe(tf.k); setChartHover(null); }} style={{
                fontFamily: FONTS.ui, fontSize: 11, fontWeight: timeframe === tf.k ? 600 : 500,
                padding: "6px 14px", border: "none", borderRadius: 8, cursor: "pointer",
                background: timeframe === tf.k ? accent.primary : "transparent",
                color: timeframe === tf.k ? "#000" : T.textDim,
                transition: "all 300ms cubic-bezier(0.4, 0, 0.2, 1)"
              }}>{tf.l}</button>
            ))}
          </div>
        </div>

        <div style={{ position: "relative" }}
          onMouseLeave={() => setChartHover(null)}
          onTouchEnd={() => setTimeout(() => setChartHover(null), 2000)}>
          <svg viewBox={`0 0 100 ${chartH}`} style={{ width: "100%", height: chartH, overflow: "visible" }} preserveAspectRatio="none">
            {[0, 0.25, 0.5, 0.75, 1].map((f, i) => (
              <line key={i} x1="0" x2="100" y1={chartH * f} y2={chartH * f} stroke={T.border} strokeWidth="0.5" opacity="0.6" />
            ))}
            <path d={toPath(cd.deposit)} fill="none" stroke={T.textMute} strokeWidth="1.2" strokeDasharray="3 3" opacity="0.4" style={{ transition: "d 500ms ease" }} />
            <path d={toPath(cd.vn30)} fill="none" stroke={T.textDim} strokeWidth="1.5" opacity="0.6" style={{ transition: "d 500ms ease" }} />
            <path d={toPath(cd.lucy)} fill="none" stroke={accent.primary} strokeWidth="2.5" style={{ transition: "d 500ms ease" }} />
            <path d={`${toPath(cd.lucy)} L100,${chartH} L0,${chartH} Z`} fill={`url(#lucyGrad)`} style={{ transition: "d 500ms ease" }} />
            <defs>
              <linearGradient id="lucyGrad" x1="0" y1="0" x2="0" y2="1">
                <stop offset="0%" stopColor={accent.primary} stopOpacity="0.25" />
                <stop offset="100%" stopColor={accent.primary} stopOpacity="0" />
              </linearGradient>
            </defs>
            {cd.labels.map((_, i) => {
              const x = (i / (cd.labels.length - 1)) * 100;
              return (
                <rect key={i} x={x - 100 / (cd.labels.length * 2)} y="0" width={100 / cd.labels.length} height={chartH}
                  fill="transparent" onMouseEnter={() => setChartHover(i)}
                  onTouchStart={() => setChartHover(i)} style={{ cursor: "crosshair" }} />
              );
            })}
            {chartHover !== null && (
              <g>
                <line x1={(chartHover / (cd.labels.length - 1)) * 100} x2={(chartHover / (cd.labels.length - 1)) * 100}
                  y1="0" y2={chartH} stroke={accent.primary} strokeWidth="0.8" strokeDasharray="4 2" />
                <circle cx={(chartHover / (cd.labels.length - 1)) * 100} cy={toY(cd.lucy[chartHover])} r="4" fill={accent.primary} stroke={T.surface} strokeWidth="2" />
              </g>
            )}
          </svg>

          {chartHover !== null && (
            <div style={{ position: "absolute", top: -10, left: "50%", transform: "translateX(-50%) translateY(-100%)", background: T.surfaceStrong, border: `1px solid ${accent.primary}40`, borderRadius: 12, padding: "10px 14px", zIndex: 10, minWidth: 160, boxShadow: "0 10px 30px rgba(0,0,0,0.2)", animation: "fadeIn 200ms ease-out" }}>
              <div style={{ fontFamily: FONTS.ui, fontSize: 10, color: T.textMute, marginBottom: 6, fontWeight: 600 }}>{cd.labels[chartHover]}</div>
              <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 2 }}>
                <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: accent.primary, fontWeight: 700 }}>Lucy:</span>
                <span style={{ fontFamily: FONTS.fraunces, fontSize: 12, color: accent.primary, fontWeight: 700 }}>{cd.lucy[chartHover].toFixed(2)} tỷ</span>
              </div>
              <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 2 }}>
                <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textDim }}>VN30:</span>
                <span style={{ fontFamily: FONTS.fraunces, fontSize: 12, color: T.textDim }}>{cd.vn30[chartHover].toFixed(2)} tỷ</span>
              </div>
              <div style={{ display: "flex", justifyContent: "space-between" }}>
                <span style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textMute }}>NH:</span>
                <span style={{ fontFamily: FONTS.fraunces, fontSize: 12, color: T.textMute }}>{cd.deposit[chartHover].toFixed(2)} tỷ</span>
              </div>
            </div>
          )}
        </div>

        <div style={{ display: "flex", justifyContent: "space-between", marginTop: 12 }}>
          {cd.labels.map((l, i) => <span key={i} style={{ fontFamily: FONTS.ui, fontSize: 10, color: T.textMute }}>{l}</span>)}
        </div>
        <div style={{ display: "flex", gap: 16, marginTop: 14 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 6 }}><div style={{ width: 12, height: 4, borderRadius: 2, background: accent.primary }} /><span style={{ fontFamily: FONTS.ui, fontSize: 10, color: T.textDim, fontWeight: 600 }}>Lucy AI</span></div>
          <div style={{ display: "flex", alignItems: "center", gap: 6 }}><div style={{ width: 12, height: 4, borderRadius: 2, background: T.textDim }} /><span style={{ fontFamily: FONTS.ui, fontSize: 10, color: T.textDim }}>VN30</span></div>
          <div style={{ display: "flex", alignItems: "center", gap: 6 }}><div style={{ width: 12, height: 2, borderRadius: 2, background: T.textMute, opacity: 0.5 }} /><span style={{ fontFamily: FONTS.ui, fontSize: 10, color: T.textDim }}>Gửi NH</span></div>
        </div>
      </div>
      <div style={{ height: 24 }} />

      {/* Performance Comparison */}
      <div style={{ ...fadeStyle(300), background: T.surface, border: `1px solid ${T.border}`, borderRadius: 20, padding: "20px", boxShadow: "0 4px 20px rgba(0,0,0,0.05)" }}>
        <div style={{ fontFamily: FONTS.ui, fontSize: 14, fontWeight: 700, color: T.text, marginBottom: 18 }}>So sánh hiệu suất 12 tháng</div>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr 1fr", gap: 10 }}>
          {[
            {n:"Lucy AI",p:"+18.2%",v:"5.91 tỷ",c:accent.primary,id:0},
            {n:"VN30",p:"+9.1%",v:"5.46 tỷ",c:T.text,id:1},
            {n:"Gửi NH",p:"+5.5%",v:"5.28 tỷ",c:T.textDim,id:2}
          ].map((h,i) => (
            <div 
              key={i} 
              onMouseEnter={() => setHoverCard(i)}
              onMouseLeave={() => setHoverCard(null)}
              style={{ 
                textAlign: "center", padding: "12px 4px", borderRadius: 12,
                background: hoverCard === i ? T.bg : "transparent",
                border: `1px solid ${hoverCard === i ? T.borderStrong : "transparent"}`,
                transition: "all 250ms ease",
                transform: hoverCard === i ? "translateY(-4px)" : "none"
              }}>
              <div style={{ fontFamily: FONTS.ui, fontSize: 10, color: T.textMute, marginBottom: 8, fontWeight: 600 }}>{h.n}</div>
              <div style={{ fontFamily: FONTS.fraunces, fontSize: 22, color: h.c, fontWeight: 700 }}>{h.p}</div>
              <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: T.textDim, marginTop: 4, fontWeight: 500 }}>{h.v}</div>
            </div>
          ))}
        </div>
        
        {/* Diễn giải chi tiết hiệu suất */}
        <div style={{ marginTop: 20, padding: "16px", background: `${accent.primary}10`, borderRadius: 16, border: `1px solid ${accent.primary}25` }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 13, color: accent.primary, fontWeight: 700, display: "flex", alignItems: "center", gap: 8, marginBottom: 6 }}>
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><polyline points="23 6 13.5 15.5 8.5 10.5 1 18"/><polyline points="17 6 23 6 23 12"/></svg>
            Hiệu quả sinh lời vượt trội
          </div>
          <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: T.textDim, lineHeight: 1.5 }}>
            Với cùng số vốn ban đầu (5 tỷ), danh mục tối ưu bởi Lucy AI mang lại lợi nhuận cao hơn <b>450 triệu</b> so với thị trường chung (VN30) và <b>630 triệu</b> so với gửi tiết kiệm ngân hàng trong vòng 1 năm qua.
          </div>
        </div>
      </div>
      <div style={{ height: 24 }} />



      {/* Market Indicators */}
      <div style={fadeStyle(400)}>
        <div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 12 }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 14, fontWeight: 600, color: T.text }}>Chỉ số thị trường</div>
          <div style={{ padding: "2px 8px", borderRadius: 6, background: "#10B98120", fontFamily: FONTS.ui, fontSize: 10, color: "#10B981", fontWeight: 600 }}>🟢 Tích cực</div>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10 }}>
          {metrics.map((m, i) => (
            <div key={i} style={{ background: T.surface, border: `1px solid ${T.border}`, borderRadius: 12, padding: "12px 14px", opacity: animIn ? 1 : 0, transform: animIn ? "scale(1)" : "scale(0.95)", transition: `all 400ms ${400 + i * 80}ms` }}>
              <div style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textDim, marginBottom: 4 }}>{m.label}</div>
              <div style={{ fontFamily: FONTS.ui, fontSize: 16, color: T.text, fontWeight: 700 }}>{m.val}</div>
              <div style={{ fontFamily: FONTS.ui, fontSize: 10, color: m.pos ? "#10B981" : "#EF4444", fontWeight: 600, marginTop: 2 }}>{m.chg}</div>
            </div>
          ))}
        </div>
      </div>
      <div style={{ height: 24 }} />

      {/* Featured Insights */}
      <div style={fadeStyle(600)}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 12 }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 14, fontWeight: 600, color: T.text }}>Tin chuyên sâu</div>
          <div onClick={onGoToInsights} style={{ fontFamily: FONTS.ui, fontSize: 12, color: accent.primary, fontWeight: 600, cursor: "pointer" }}>Xem tất cả →</div>
        </div>
        <div style={{ display: "flex", gap: 14, overflowX: "auto", paddingBottom: 8, scrollbarWidth: "none" }}>
          {featured.map((f, i) => (
            <div onClick={onGoToInsights} key={i} style={{ minWidth: 220, borderRadius: 14, overflow: "hidden", background: T.surface, border: `1px solid ${T.border}`, cursor: "pointer", transition: "transform 200ms" }}>
              <div style={{ height: 100, backgroundImage: `url(${f.img})`, backgroundSize: "cover", backgroundPosition: "center" }} />
              <div style={{ padding: "10px 12px" }}>
                <div style={{ fontFamily: FONTS.ui, fontSize: 9, color: T.textMute, marginBottom: 3 }}>{f.date}</div>
                <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: T.text, fontWeight: 600, lineHeight: 1.4 }}>{f.title}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

function InsightsTab({ T, t, accent }) {
  const articles = [
    { date: "15/05/2026", title: "Cơ hội từ sự phân hoá nhóm vốn hoá lớn", desc: "Thị trường tháng 5 chứng kiến sự dịch chuyển dòng tiền rõ nét. Nhóm vốn hoá lớn bắt đầu dẫn dắt.", tag: "Cổ phiếu", img: "https://images.unsplash.com/photo-1611974789855-9c2a0a7236a3?auto=format&fit=crop&w=400&q=80" },
    { date: "02/05/2026", title: "Xây dựng danh mục thích ứng với chu kỳ mới", desc: "Bối cảnh vĩ mô thay đổi đòi hỏi chiến lược phân bổ linh hoạt. Tiền gửi không còn là kênh trú ẩn tối ưu.", tag: "Chiến lược", img: "https://images.unsplash.com/photo-1460925895917-afdab827c52f?auto=format&fit=crop&w=400&q=80" },
    { date: "18/04/2026", title: "Động lực từ nhóm cổ phiếu Ngân hàng", desc: "Phân tích định lượng chỉ ra định giá nhóm Ngân hàng đang ở mức hấp dẫn nhất trong 3 năm qua.", tag: "Ngân hàng", img: "https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?auto=format&fit=crop&w=400&q=80" },
    { date: "05/04/2026", title: "Lạm phát và chiến lược bảo vệ sức mua", desc: "Cách bảo vệ tài sản của bạn khi áp lực lạm phát có dấu hiệu quay trở lại vào giữa năm.", tag: "Vĩ mô", img: "https://images.unsplash.com/photo-1526304640581-d334cdbbf45e?auto=format&fit=crop&w=400&q=80" },
    { date: "20/03/2026", title: "Giá vàng thế giới liên tục phá đỉnh lịch sử", desc: "Những động lực chính đứng sau đà tăng của vàng và tác động đến các kênh đầu tư khác.", tag: "Hàng hoá", img: "https://images.unsplash.com/photo-1579621970588-a35d0e7ab9b6?auto=format&fit=crop&w=400&q=80" },
    { date: "05/03/2026", title: "Vai trò của Bất động sản trong danh mục đa dạng", desc: "Giảm tỷ trọng Bất động sản trực tiếp và tăng tỷ trọng qua kênh chứng khoán.", tag: "Bất động sản", img: "https://images.unsplash.com/photo-1560518883-ce09059eeffa?auto=format&fit=crop&w=400&q=80" },
  ];

  return (
    <div>
      <SerifTitle T={T} size={28}>Insights</SerifTitle>
      <div style={{ height: 8 }} />
      <Body T={T} size={12} style={{ color: T.textMute }}>Góc nhìn từ chuyên gia về thị trường.</Body>
      <div style={{ height: 24 }} />

      <div style={{ display: "grid", gridTemplateColumns: "1fr", gap: 20 }}>
        {articles.map((art, i) => (
          <div key={i} style={{ borderRadius: 16, overflow: "hidden", background: T.surface, border: `1px solid ${T.border}`, display: "flex", flexDirection: "column" }}>
            <div style={{ height: 160, backgroundImage: `url(${art.img})`, backgroundSize: "cover", backgroundPosition: "center" }} />
            <div style={{ padding: "16px" }}>
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 10 }}>
                <div style={{ padding: "4px 10px", borderRadius: 8, background: `${accent.primary}15`, color: accent.primary, fontSize: 10, fontFamily: FONTS.ui, fontWeight: 700, textTransform: "uppercase", letterSpacing: 0.5 }}>{art.tag}</div>
                <div style={{ fontFamily: FONTS.ui, fontSize: 12, color: T.textMute }}>{art.date}</div>
              </div>
              <div style={{ fontFamily: FONTS.ui, fontSize: 16, color: T.text, fontWeight: 600, marginBottom: 8, lineHeight: 1.4 }}>{art.title}</div>
              <Body T={T} size={13} style={{ color: T.textDim, lineHeight: 1.5 }}>{art.desc}</Body>
            </div>
          </div>
        ))}
      </div>
    </div>
  );
}

function AccountTab({ T, t, accent, name, score, onRestart }) {
  const [animIn, setAnimIn] = React.useState(false);
  const [hoverAction, setHoverAction] = React.useState(null);

  React.useEffect(() => { requestAnimationFrame(() => setAnimIn(true)); }, []);
  const fadeStyle = (delay) => ({ opacity: animIn ? 1 : 0, transform: animIn ? "translateY(0)" : "translateY(16px)", transition: `opacity 600ms ${delay}ms, transform 600ms ${delay}ms` });

  const handleClear = () => {
    if (confirm("Bạn có muốn xoá toàn bộ dữ liệu và bắt đầu lại từ đầu?")) {
      localStorage.clear();
      window.location.reload();
    }
  };

  const userScore = score || 47;

  return (
    <div style={{ paddingBottom: 40 }}>
      {/* Profile Header */}
      <div style={{ ...fadeStyle(0), display: "flex", alignItems: "center", gap: 20, marginBottom: 32 }}>
        <div style={{ 
          width: 72, height: 72, borderRadius: 22, 
          background: `linear-gradient(135deg, ${accent.primary}, ${accent.primary}aa)`, 
          display: "flex", alignItems: "center", justifyContent: "center", flexShrink: 0,
          boxShadow: `0 12px 24px ${accent.primary}30`,
          transform: "rotate(-3deg)"
        }}>
          <span style={{ fontFamily: FONTS.fraunces, fontSize: 32, color: "#000", fontWeight: 700 }}>{(name || "K").charAt(0).toUpperCase()}</span>
        </div>
        <div style={{ flex: 1 }}>
          <div style={{ fontFamily: FONTS.fraunces, fontSize: 26, color: T.text, fontWeight: 500, letterSpacing: -0.5 }}>{name || "Khách hàng"}</div>
          <div style={{ display: "flex", alignItems: "center", gap: 6, marginTop: 6 }}>
            <div style={{ width: 8, height: 8, borderRadius: "50%", background: "#10B981", boxShadow: "0 0 8px #10B981" }} />
            <div style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textMute, textTransform: "uppercase", letterSpacing: 1.2, fontWeight: 700 }}>Hội viên Lucy Pro</div>
          </div>
        </div>
      </div>

      {/* Summary Cards */}
      <div style={{ ...fadeStyle(100), display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12, marginBottom: 32 }}>
        <div style={{ padding: "18px", borderRadius: 20, background: T.surface, border: `1px solid ${T.border}`, boxShadow: "0 4px 12px rgba(0,0,0,0.03)" }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 10, color: T.textMute, textTransform: "uppercase", marginBottom: 10, fontWeight: 700, letterSpacing: 0.5 }}>Điểm chẩn đoán</div>
          <div style={{ display: "flex", alignItems: "baseline", gap: 4 }}>
            <span style={{ fontFamily: FONTS.fraunces, fontSize: 32, color: accent.primary, fontWeight: 700 }}>{userScore}</span>
            <span style={{ fontFamily: FONTS.ui, fontSize: 14, color: T.textMute }}>/100</span>
          </div>
        </div>
        <div style={{ padding: "18px", borderRadius: 20, background: T.surface, border: `1px solid ${T.border}`, boxShadow: "0 4px 12px rgba(0,0,0,0.03)" }}>
          <div style={{ fontFamily: FONTS.ui, fontSize: 10, color: T.textMute, textTransform: "uppercase", marginBottom: 10, fontWeight: 700, letterSpacing: 0.5 }}>Khẩu vị rủi ro</div>
          <div style={{ fontFamily: FONTS.fraunces, fontSize: 20, color: T.text, fontWeight: 600, marginTop: 8 }}>Cân bằng</div>
        </div>
      </div>

      {/* Actions Section */}
      <div style={fadeStyle(200)}>
        <div style={{ fontFamily: FONTS.ui, fontSize: 12, fontWeight: 700, color: T.textMute, textTransform: "uppercase", letterSpacing: 1.5, marginBottom: 16, paddingLeft: 4 }}>Hành động ưu tiên</div>
        <div style={{ display: "flex", flexDirection: "column", gap: 12, marginBottom: 32 }}>
          <button 
            onMouseEnter={() => setHoverAction("restart")}
            onMouseLeave={() => setHoverAction(null)}
            onClick={onRestart} 
            style={{ 
              display: "flex", alignItems: "center", gap: 16, width: "100%", padding: "18px 20px", 
              borderRadius: 18, background: hoverAction === "restart" ? `${accent.primary}18` : `${accent.primary}08`, 
              border: `1px solid ${accent.primary}${hoverAction === "restart" ? "50" : "25"}`,
              cursor: "pointer", transition: "all 300ms cubic-bezier(0.4, 0, 0.2, 1)",
              transform: hoverAction === "restart" ? "translateX(4px)" : "none"
            }}>
            <div style={{ width: 40, height: 40, borderRadius: 12, background: accent.primary, display: "flex", alignItems: "center", justifyContent: "center", boxShadow: `0 4px 12px ${accent.primary}40` }}>
              <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#000" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><path d="M1 4v6h6M23 20v-6h-6"/><path d="M20.49 9A9 9 0 005.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 013.51 15"/></svg>
            </div>
            <div style={{ textAlign: "left" }}>
              <div style={{ fontFamily: FONTS.ui, fontSize: 15, color: accent.primary, fontWeight: 700 }}>Chẩn đoán lại</div>
              <div style={{ fontFamily: FONTS.ui, fontSize: 11, color: `${accent.primary}aa`, marginTop: 2 }}>Cập nhật tình hình tài sản mới nhất</div>
            </div>
          </button>
          
          <button 
            onMouseEnter={() => setHoverAction("consult")}
            onMouseLeave={() => setHoverAction(null)}
            onClick={() => window.open("https://zalo.me", "_blank")} 
            style={{ 
              display: "flex", alignItems: "center", gap: 16, width: "100%", padding: "18px 20px", 
              borderRadius: 18, background: hoverAction === "consult" ? T.surfaceStrong : T.surface, 
              border: `1px solid ${T.borderStrong}`,
              cursor: "pointer", transition: "all 300ms cubic-bezier(0.4, 0, 0.2, 1)",
              boxShadow: hoverAction === "consult" ? "0 8px 24px rgba(0,0,0,0.08)" : "none",
              transform: hoverAction === "consult" ? "translateX(4px)" : "none"
            }}>
            <div style={{ width: 40, height: 40, borderRadius: 12, background: T.bg, border: `1px solid ${T.border}`, display: "flex", alignItems: "center", justifyContent: "center" }}>
              <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke={T.text} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
            </div>
            <div style={{ textAlign: "left" }}>
              <div style={{ fontFamily: FONTS.ui, fontSize: 15, color: T.text, fontWeight: 600 }}>Liên hệ tư vấn viên</div>
              <div style={{ fontFamily: FONTS.ui, fontSize: 11, color: T.textMute, marginTop: 2 }}>Nhận hỗ trợ 1:1 từ chuyên gia Lucy</div>
            </div>
          </button>
        </div>
      </div>

      {/* Settings Section */}
      <div style={fadeStyle(300)}>
        <div style={{ fontFamily: FONTS.ui, fontSize: 12, fontWeight: 700, color: T.textMute, textTransform: "uppercase", letterSpacing: 1.5, marginBottom: 16, paddingLeft: 4 }}>Cài đặt hệ thống</div>
        <div style={{ borderRadius: 20, background: T.surface, border: `1px solid ${T.border}`, overflow: "hidden", boxShadow: "0 4px 12px rgba(0,0,0,0.03)" }}>
          <div style={{ padding: "16px 20px", display: "flex", justifyContent: "space-between", alignItems: "center", borderBottom: `1px solid ${T.border}` }}>
            <div style={{ display: "flex", alignItems: "center", gap: 12 }}>
              <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke={T.textDim} strokeWidth="2"><path d="M18 8A6 6 0 006 8c0 7-3 9-3 9h18s-3-2-3-9M13.73 21a2 2 0 01-3.46 0"/></svg>
              <span style={{ fontFamily: FONTS.ui, fontSize: 14, color: T.text, fontWeight: 500 }}>Thông báo thị trường</span>
            </div>
            <div style={{ width: 44, height: 24, borderRadius: 12, background: "#10B981", position: "relative", cursor: "pointer" }}>
              <div style={{ position: "absolute", right: 2, top: 2, width: 20, height: 20, borderRadius: "50%", background: "#fff", boxShadow: "0 2px 4px rgba(0,0,0,0.2)" }} />
            </div>
          </div>
          <button onClick={handleClear} style={{ 
            width: "100%", padding: "16px 20px", display: "flex", alignItems: "center", gap: 12,
            background: "none", border: "none", cursor: "pointer", color: "#EF4444"
          }}>
            <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><path d="M19 6L5 20M5 6l14 14"/></svg>
            <span style={{ fontFamily: FONTS.ui, fontSize: 14, fontWeight: 600 }}>Xoá dữ liệu & Reset App</span>
          </button>
        </div>
      </div>

      <div style={{ height: 48 }} />
      <div style={{ textAlign: "center", opacity: 0.3 }}>
        <div style={{ fontFamily: FONTS.ui, fontSize: 10, fontWeight: 700, letterSpacing: 1, textTransform: "uppercase" }}>Lucy AI Ecosystem</div>
        <div style={{ fontFamily: FONTS.ui, fontSize: 9, marginTop: 4 }}>v6.2.0 • build_46e6cbb1</div>
      </div>
    </div>
  );
}


Object.assign(window, { 
  MissingOutPanel2Screen, 
  MissingOutPanel3Screen, 
  SimulatorScreen, 
  FundPreviewScreen, 
  BookingFormScreen,
  BookingConfirmScreen,
  DashboardScreen
});
