// Cleo Care — mobile app screens. Faithful recreation of the real app surfaces,
// composed from the design-system primitives in the bundle.
const { Button, Badge, Avatar, Card, SearchInput, SegmentedControl, AppBar, ProgressBar, Checkbox } =
  window.CleoCareDesignSystem_387d4e;
const D = window.CLEO_DATA;
const ICON = (n) => `../assets/icons/${n}.svg`;
const PNG = (n) => `../assets/icons/${n}.png`;

// ── shared bits ──────────────────────────────────────────────
function HomeHeader() {
  // Matches the real AppBar: pearlWhisper, avatar left, Cleo-AI + bell (badge) right.
  return (
    <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between',
      padding:'8px 16px 10px', background:'var(--cleo-200)', borderBottom:'1px solid #E5E7EB',
      boxShadow:'0 2px 3px rgba(0,0,0,.05)', position:'relative', zIndex:5 }}>
      <Avatar size="sm" name={D.user.name} />
      <div style={{ display:'flex', alignItems:'center', gap:6 }}>
        <button aria-label="Cleo IA" style={{ width:40, height:40, border:'none', background:'transparent', cursor:'pointer', padding:0 }}>
          <img src={PNG('cleo_ai_icon')} alt="" style={{ width:40, height:40, objectFit:'contain' }} />
        </button>
        <div style={{ position:'relative' }}>
          <button aria-label="Notifications" style={{ width:40, height:40, border:'none', background:'transparent', cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'center' }}>
            <img src={ICON('bell')} alt="" style={{ width:24, height:24 }} />
          </button>
          {D.unread > 0 && (
            <span style={{ position:'absolute', top:2, right:2, minWidth:20, height:20, padding:'0 5px', borderRadius:'50%', background:'var(--cleo-secondary)', border:'2px solid var(--cleo-200)', color:'#fff', fontSize:11, fontWeight:700, display:'flex', alignItems:'center', justifyContent:'center' }}>{D.unread}</span>
          )}
        </div>
      </div>
    </div>
  );
}

const MoonIcon = () => (
  <svg width="30" height="30" viewBox="0 0 24 24" fill="var(--cleo-secondary)"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg>
);

function Stars({ note }) {
  return (
    <span style={{ display:'inline-flex', alignItems:'center', gap:4, fontSize:12, color:'var(--text-tertiary)', fontWeight:600 }}>
      <svg width="13" height="13" viewBox="0 0 24 24" fill="var(--cleo-warning)"><path d="M12 2l2.9 6.3 6.9.7-5.1 4.6 1.4 6.8L12 17.8 5.9 20.4l1.4-6.8L2.2 9l6.9-.7z"/></svg>
      {note}
    </span>
  );
}

// Routine task row — pill-shaped; pink when overdue (bell), empty circle, product avatar, chevron-circle.
function TaskRow({ task, onToggle }) {
  const overdue = task.pastDue && !task.done;
  return (
    <div style={{ background: overdue ? '#FFEEF1' : 'var(--cleo-white)', borderRadius:'var(--radius-full)', boxShadow:'0 1px 2px rgba(0,0,0,.10)', padding:'12px 14px', display:'flex', alignItems:'center', gap:10 }}>
      <button onClick={onToggle} aria-label="Tâche" style={{ width:28, height:28, flex:'none', borderRadius:'50%', border:`2px solid var(--cleo-500)`, background: task.done ? 'var(--cleo-500)' : 'transparent', cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'center', padding:0, transition:'background var(--dur-fast)' }}>
        {task.done && <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#fff" strokeWidth="3.2" strokeLinecap="round" strokeLinejoin="round"><path d="M20 6L9 17l-5-5"/></svg>}
      </button>
      {overdue && (
        <svg width="20" height="20" viewBox="0 0 24 24" fill="var(--cleo-warning)" style={{ flex:'none' }}><path d="M12 2a6 6 0 0 0-6 6c0 4-1.5 5.5-2 6.5h16c-.5-1-2-2.5-2-6.5a6 6 0 0 0-6-6z"/><circle cx="12" cy="20" r="2"/></svg>
      )}
      <span style={{ flex:1, fontSize:16, fontWeight:600, color:'var(--text-strong)', whiteSpace:'nowrap', overflow:'hidden', textOverflow:'ellipsis', textDecoration: task.done?'line-through':'none', opacity: task.done?.6:1 }}>{task.name}</span>
      <span style={{ width:34, height:34, flex:'none', borderRadius:'50%', background:'var(--cleo-lavender-bg)', border:'2px solid var(--cleo-white)', display:'flex', alignItems:'center', justifyContent:'center' }}>
        <img src={ICON('soap')} alt="" style={{ width:17, height:17, opacity:.65 }} />
      </span>
      <img src={ICON('arrow_dropdown_down')} alt="" style={{ width:26, height:26, flex:'none' }} />
    </div>
  );
}

function RoutineCard({ routine }) {
  const [tasks, setTasks] = React.useState(routine.tasks);
  const done = tasks.filter(t=>t.done).length;
  const toggle = (id)=> setTasks(ts=>ts.map(t=>t.id===id?{...t,done:!t.done}:t));
  const allDone = done === tasks.length;
  return (
    <Card padding={20} style={{ boxShadow:'0 4px 14px rgba(21,16,77,.10)' }}>
      <div style={{ display:'flex', alignItems:'flex-start', justifyContent:'space-between', gap:8 }}>
        <div style={{ display:'flex', gap:12, flex:1, minWidth:0 }}>
          <div style={{ flex:'none', paddingTop:2 }}><MoonIcon /></div>
          <div style={{ minWidth:0 }}>
            <div style={{ fontSize:21, fontWeight:700, color:'var(--cleo-secondary)', lineHeight:1.2 }}>{routine.title}</div>
            <div style={{ marginTop:6 }}>
              <span style={{ fontSize:13, fontWeight:500, color:'var(--cleo-secondary)', background:'#E8E7F3', padding:'4px 12px', borderRadius:'var(--radius-full)' }}>{routine.period}</span>
            </div>
            <div style={{ fontSize:14, fontWeight:500, color:'var(--text-muted)', marginTop:8 }}>{done}/{tasks.length} tâches</div>
          </div>
        </div>
        <div style={{ display:'flex', alignItems:'center', gap:14, flex:'none', paddingTop:4 }}>
          <button aria-label="Partager" style={{ border:'none', background:'transparent', cursor:'pointer', padding:0 }}><img src={ICON('share')} alt="" style={{ width:20, height:20 }} /></button>
          <button aria-label="Modifier" style={{ border:'none', background:'transparent', cursor:'pointer', padding:0 }}><img src={ICON('edit')} alt="" style={{ width:19, height:19 }} /></button>
          <button aria-label="Supprimer" style={{ border:'none', background:'transparent', cursor:'pointer', padding:0 }}>
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#DC2626" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 6h18M8 6V4a1 1 0 011-1h6a1 1 0 011 1v2m2 0v14a1 1 0 01-1 1H6a1 1 0 01-1-1V6"/><path d="M10 11v6M14 11v6"/></svg>
          </button>
        </div>
      </div>
      <div style={{ margin:'16px 0' }}><ProgressBar value={(done/tasks.length)*100} height={10} /></div>
      <div style={{ display:'flex', flexDirection:'column', gap:14 }}>
        {tasks.map(t => <TaskRow key={t.id} task={t} onToggle={()=>toggle(t.id)} />)}
      </div>
      {!allDone && (
        <div style={{ display:'flex', justifyContent:'flex-end', marginTop:18 }}>
          <button style={{ display:'flex', alignItems:'center', gap:10, border:'1px solid var(--cleo-300)', background:'var(--cleo-white)', borderRadius:'var(--radius-full)', padding:'12px 22px', cursor:'pointer' }}>
            <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--cleo-secondary)" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z"/><circle cx="12" cy="12" r="3"/><path d="M4 4l16 16"/></svg>
            <span style={{ fontSize:16, fontWeight:600, color:'var(--cleo-secondary)' }}>Ne pas faire aujourd'hui</span>
          </button>
        </div>
      )}
    </Card>
  );
}

function SuggestionCard({ s, onOpen }) {
  return (
    <div style={{ width:230, flex:'none', background:'var(--cleo-white)', borderRadius:'var(--radius-3xl)', boxShadow:'var(--shadow-card)', overflow:'hidden' }}>
      <div style={{ height:96, background:'linear-gradient(135deg, var(--cleo-lavender-light), var(--cleo-lavender-bg))', display:'flex', alignItems:'center', justifyContent:'center' }}>
        <img src={ICON('self_care')} alt="" style={{ width:40, height:40, opacity:.6 }} />
      </div>
      <div style={{ padding:'12px 14px 14px' }}>
        <div style={{ fontSize:15, fontWeight:700, color:'var(--text-strong)', lineHeight:1.25 }}>{s.title}</div>
        <div style={{ display:'flex', alignItems:'center', gap:8, margin:'8px 0 12px' }}>
          <Avatar size="sm" name={s.creator} style={{ width:22, height:22 }} />
          <span style={{ fontSize:12, color:'var(--text-tertiary)' }}>{s.creator}</span>
          <span style={{ marginLeft:'auto' }}><Stars note={s.rating} /></span>
        </div>
        <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between' }}>
          <Badge text={`${s.steps} étapes`} variant="neutral" />
          <Button label="Utiliser" variant="primary" size="small" fullWidth={false} onClick={()=>onOpen?.(s)} />
        </div>
      </div>
    </div>
  );
}

// ── Home ─────────────────────────────────────────────────────
function HomeScreen() {
  return (
    <div style={{ background:'var(--cleo-200)', minHeight:'100%', paddingBottom:24 }}>
      <HomeHeader />
      <div style={{ padding:'22px 22px 0' }}>
        <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between', marginBottom:18 }}>
          <h1 style={{ margin:0, fontSize:30, fontWeight:700, color:'var(--cleo-secondary)' }}>Tes routines ☀️</h1>
          <button style={{ display:'flex', alignItems:'center', gap:8, border:'none', background:'transparent', cursor:'pointer', fontSize:17, fontWeight:600, color:'var(--cleo-secondary)' }}>
            Voir tout
            <img src={ICON('arrow_right')} alt="" style={{ width:22, height:22 }} />
          </button>
        </div>
      </div>
      <div style={{ display:'flex', flexDirection:'column', gap:20, padding:'0 22px' }}>
        {D.routines.map(r => <RoutineCard key={r.id} routine={r} />)}
      </div>

      <div style={{ padding:'26px 22px 0' }}>
        <Button label="Créer une nouvelle routine" variant="secondary" centered fullWidth />
      </div>

      <div style={{ margin:'30px 0 0' }}>
        <h2 style={{ margin:'0 22px 14px', fontSize:22, fontWeight:700, color:'var(--cleo-secondary)' }}>Routines suggérées</h2>
        <div style={{ display:'flex', gap:14, overflowX:'auto', padding:'0 22px 6px' }}>
          {D.suggestions.map(s => <SuggestionCard key={s.id} s={s} />)}
        </div>
      </div>

      <div style={{ textAlign:'center', padding:'28px 0 8px' }}>
        <img src="../assets/brand/cleo-logo.png" alt="Cleo Care" style={{ height:22, opacity:.4 }} />
        <div style={{ fontSize:11, color:'var(--text-muted)', marginTop:6 }}>Prenez soin de vous</div>
      </div>
    </div>
  );
}

// ── Essentiels (Mes produits) ────────────────────────────────
function ProductTile({ p, onOpen }) {
  const [liked, setLiked] = React.useState(!!p.liked);
  return (
    <div onClick={()=>onOpen?.(p)} style={{ cursor:'pointer', background:'var(--cleo-white)', borderRadius:'var(--radius-3xl)', boxShadow:'var(--shadow-card)', overflow:'hidden' }}>
      <div style={{ position:'relative', height:120, background:'linear-gradient(135deg, var(--cleo-lavender-light), var(--cleo-lavender-bg))', display:'flex', alignItems:'center', justifyContent:'center' }}>
        <img src={ICON('soap')} alt="" style={{ width:48, height:48, opacity:.55 }} />
        <button onClick={(e)=>{e.stopPropagation();setLiked(v=>!v);}} aria-label="Favori"
          style={{ position:'absolute', top:10, right:10, width:34, height:34, border:'none', borderRadius:'50%', background:'rgba(255,255,255,.92)', boxShadow:'var(--shadow-sm)', cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'center' }}>
          <img src={ICON(liked ? 'heart_full' : 'heart')} alt="" style={{ width:18, height:18 }} />
        </button>
      </div>
      <div style={{ padding:'12px 14px 14px' }}>
        <div style={{ fontSize:11, fontWeight:600, color:'var(--text-muted)', textTransform:'uppercase', letterSpacing:'.04em' }}>{p.marque}</div>
        <div style={{ fontSize:15, fontWeight:600, color:'var(--text-strong)', margin:'2px 0 8px', lineHeight:1.25 }}>{p.nom}</div>
        <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between' }}>
          <Stars note={p.note} />
          <Badge text={p.cat} variant="neutral" />
        </div>
      </div>
    </div>
  );
}

function EssentialsScreen({ onOpenProduct }) {
  const [q, setQ] = React.useState('');
  const match = (p) => !q || (p.nom + p.marque).toLowerCase().includes(q.toLowerCase());
  const liked = D.essentials.filter(p => p.liked && match(p));
  const others = D.essentials.filter(p => !p.liked && match(p));
  const Section = ({ title, items }) => items.length === 0 ? null : (
    <div style={{ marginBottom:8 }}>
      <h2 style={{ margin:'18px 0 14px', fontSize:22, fontWeight:700, color:'var(--cleo-secondary)' }}>{title}</h2>
      <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap:14 }}>
        {items.map(p => <ProductTile key={p.id} p={p} onOpen={onOpenProduct} />)}
      </div>
    </div>
  );
  return (
    <div style={{ background:'var(--cleo-200)', minHeight:'100%' }}>
      <div style={{ padding:'10px 16px 4px', background:'var(--cleo-200)' }}>
        <Avatar size="sm" name={D.user.name} />
      </div>
      <div style={{ display:'flex', alignItems:'center', gap:10, padding:'10px 22px 16px' }}>
        <div style={{ flex:1 }}>
          <SearchInput value={q} onChange={(e)=>setQ(e.target.value)} onClear={()=>setQ('')} placeholder="Rechercher" />
        </div>
        <button aria-label="Filtrer" style={{ width:46, height:46, flex:'none', borderRadius:'var(--radius-full)', border:'1px solid var(--cleo-300)', background:'var(--cleo-white)', cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'center' }}>
          <img src={ICON('filter')} alt="" style={{ width:22, height:22 }} />
        </button>
      </div>
      <div style={{ background:'var(--cleo-200)', borderTopLeftRadius:'var(--radius-4xl)', borderTopRightRadius:'var(--radius-4xl)', boxShadow:'0 -4px 12px rgba(21,16,77,.06)', padding:'4px 22px 24px', minHeight:480 }}>
        <Section title="Mes produits préférés 💜" items={liked} />
        <Section title="Tous mes produits 🧴" items={others} />
        {liked.length===0 && others.length===0 && (
          <div style={{ textAlign:'center', padding:'60px 20px', color:'var(--text-muted)' }}>Aucun produit trouvé</div>
        )}
      </div>
    </div>
  );
}

// ── Routines (calendrier + filtres période) ──────────────────
function RoutinesScreen() {
  const [period, setPeriod] = React.useState('all');
  const [sel, setSel] = React.useState(19);
  const dows = ['L','M','M','J','V','S','D'];
  // June 2026 starts on a Monday
  const days = Array.from({ length: 30 }, (_, i) => i + 1);
  const dots = { 5:'m', 12:'b', 19:'m', 20:'e', 26:'b' }; // m=matin e=soir b=both
  const Filter = ({ k, label, icon }) => {
    const on = period === k;
    return (
      <button onClick={()=>setPeriod(k)} style={{ display:'flex', alignItems:'center', gap:7, padding:'9px 16px', borderRadius:'var(--radius-full)', cursor:'pointer',
        border: on ? 'none' : '1px solid var(--cleo-300)', background: on ? 'var(--cleo-secondary)' : 'var(--cleo-white)',
        color: on ? '#fff' : 'var(--cleo-secondary)', fontSize:14, fontWeight:600, fontFamily:'var(--font-sans)' }}>
        {icon} {label}
      </button>
    );
  };
  const sun = (c) => <svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke={c} strokeWidth="2" strokeLinecap="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2M5 5l1.5 1.5M17.5 17.5L19 19M19 5l-1.5 1.5M6.5 17.5L5 19"/></svg>;
  const moon = (c) => <svg width="17" height="17" viewBox="0 0 24 24" fill={c}><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg>;
  const both = (c) => <img src={ICON('routine')} alt="" style={{ width:17, height:17, filter: c==='#fff'?'brightness(0) invert(1)':'none' }} />;
  return (
    <div style={{ background:'var(--cleo-200)', minHeight:'100%', paddingBottom:24 }}>
      <div style={{ padding:'10px 16px 4px' }}><Avatar size="sm" name={D.user.name} /></div>

      <div style={{ padding:'8px 22px 0' }}>
        <div style={{ background:'var(--cleo-white)', borderRadius:'var(--radius-3xl)', boxShadow:'var(--shadow-card)', padding:18 }}>
          <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between', marginBottom:14 }}>
            <img src={ICON('arrow_left')} alt="" style={{ width:22, height:22 }} />
            <span style={{ fontSize:16, fontWeight:600, color:'var(--cleo-secondary)' }}>juin 2026</span>
            <img src={ICON('arrow_right')} alt="" style={{ width:22, height:22 }} />
          </div>
          <div style={{ display:'grid', gridTemplateColumns:'repeat(7,1fr)', gap:2, marginBottom:6 }}>
            {dows.map((d,i) => <div key={i} style={{ textAlign:'center', fontSize:13, fontWeight:700, color:'var(--text-tertiary)' }}>{d}</div>)}
          </div>
          <div style={{ display:'grid', gridTemplateColumns:'repeat(7,1fr)', gap:2 }}>
            {days.map(d => {
              const on = d === sel;
              const dot = dots[d];
              return (
                <button key={d} onClick={()=>setSel(d)} style={{ border:'none', background:'transparent', cursor:'pointer', padding:'4px 0 8px', position:'relative' }}>
                  <span style={{ display:'flex', alignItems:'center', justifyContent:'center', width:32, height:32, margin:'0 auto', borderRadius:'50%', fontSize:14, fontWeight:700, fontFamily:'var(--font-sans)',
                    background: on ? 'var(--cleo-secondary)' : 'transparent', color: on ? '#fff' : 'var(--cleo-secondary)' }}>{d}</span>
                  {dot && !on && (
                    <span style={{ position:'absolute', bottom:2, left:'50%', transform:'translateX(-50%)', display:'flex', gap:2 }}>
                      {(dot==='m'||dot==='b') && <span style={{ width:5, height:5, borderRadius:'50%', background:'var(--cleo-warning)' }} />}
                      {(dot==='e'||dot==='b') && <span style={{ width:5, height:5, borderRadius:'50%', background:'var(--cleo-secondary)' }} />}
                    </span>
                  )}
                </button>
              );
            })}
          </div>
          <div style={{ marginTop:16 }}>
            <Button label="Créer une nouvelle routine" variant="secondary" centered fullWidth />
          </div>
        </div>
      </div>

      <div style={{ display:'flex', gap:12, justifyContent:'center', padding:'18px 22px 0' }}>
        <Filter k="all" label="Tous" icon={both(period==='all'?'#fff':'#15104D')} />
        <Filter k="morning" label="Matin" icon={sun(period==='morning'?'#fff':'#15104D')} />
        <Filter k="evening" label="Soir" icon={moon(period==='evening'?'#fff':'#15104D')} />
      </div>

      <div style={{ padding:'24px 22px 0' }}>
        <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between', marginBottom:16 }}>
          <h2 style={{ margin:0, fontSize:24, fontWeight:700, color:'var(--cleo-secondary)' }}>Tes routines ☀️</h2>
          <button style={{ display:'flex', alignItems:'center', gap:8, border:'none', background:'transparent', cursor:'pointer', fontSize:16, fontWeight:600, color:'var(--cleo-secondary)' }}>
            Voir tout <img src={ICON('arrow_right')} alt="" style={{ width:22, height:22 }} />
          </button>
        </div>
        <div style={{ display:'flex', flexDirection:'column', gap:20 }}>
          {D.routines.map(r => <RoutineCard key={r.id} routine={r} />)}
        </div>
      </div>
    </div>
  );
}

// ── Boutique (bientôt disponible) ────────────────────────────
function BoutiqueScreen({ onHome }) {
  return (
    <div style={{ background:'var(--cleo-200)', minHeight:'100%', display:'flex', flexDirection:'column' }}>
      <div style={{ padding:'10px 16px 4px' }}><Avatar size="sm" name={D.user.name} /></div>
      <div style={{ flex:1, display:'flex', alignItems:'center', justifyContent:'center', padding:'0 24px' }}>
        <div style={{ width:'100%', maxWidth:340, background:'var(--cleo-white)', borderRadius:'var(--radius-4xl)', boxShadow:'var(--shadow-card)', padding:'36px 28px', display:'flex', flexDirection:'column', alignItems:'center', textAlign:'center' }}>
          <div style={{ width:120, height:120, marginBottom:18, borderRadius:'var(--radius-full)', background:'var(--cleo-lavender-bg)', display:'flex', alignItems:'center', justifyContent:'center' }}>
            <img src={ICON('storefront')} alt="" style={{ width:70, height:70, opacity:.7 }} />
          </div>
          <h2 style={{ margin:'0 0 10px', fontSize:22, fontWeight:700, color:'var(--cleo-secondary)' }}>Bientôt disponible !</h2>
          <p style={{ margin:'0 0 24px', fontSize:14, lineHeight:1.5, color:'var(--text-muted)' }}>Notre boutique sera disponible dans une prochaine mise à jour avec une sélection de produits soigneusement choisis pour vous.</p>
          <Button label="Retourner à l'accueil" variant="secondary" centered fullWidth onClick={onHome} />
        </div>
      </div>
      <div style={{ textAlign:'center', padding:'20px 0' }}>
        <img src="../assets/brand/cleo-logo.png" alt="Cleo Care" style={{ height:20, opacity:.4 }} />
      </div>
    </div>
  );
}

// ── Product (scan result / detail) ──────────────────────────
function ProductScreen({ product, onBack }) {
  const ingredients = ['Acide hyaluronique', 'Glycérine', 'Niacinamide', 'Panthénol'];
  return (
    <div style={{ background:'var(--cleo-50)', minHeight:'100%' }}>
      <AppBar onBack={onBack} title="" trailing={
        <button aria-label="Partager" style={{ width:40, height:40, border:'none', borderRadius:'50%', background:'var(--cleo-white)', boxShadow:'var(--shadow-sm)', cursor:'pointer', display:'flex', alignItems:'center', justifyContent:'center' }}>
          <img src={ICON('share')} alt="" style={{ width:20, height:20 }} />
        </button>
      } />
      <div style={{ margin:'0 20px', height:240, borderRadius:'var(--radius-4xl)', background:'linear-gradient(135deg, var(--cleo-lavender-light), var(--cleo-lavender-bg))', display:'flex', alignItems:'center', justifyContent:'center' }}>
        <img src={ICON('soap')} alt="" style={{ width:96, height:96, opacity:.6 }} />
      </div>
      <div style={{ padding:'20px 20px 0' }}>
        <div style={{ display:'flex', alignItems:'center', gap:8, marginBottom:8 }}>
          <Badge text={product.cat || 'Soin'} />
          <Stars note={product.note} />
        </div>
        <div style={{ fontSize:12, fontWeight:600, color:'var(--text-muted)', textTransform:'uppercase', letterSpacing:'.04em' }}>{product.marque}</div>
        <h1 style={{ margin:'2px 0 0', fontSize:24, fontWeight:700, color:'var(--text-strong)' }}>{product.nom}</h1>
      </div>

      <h2 style={{ margin:'24px 20px 12px', fontSize:20, fontWeight:700, color:'var(--text-strong)' }}>Composition</h2>
      <div style={{ display:'flex', flexWrap:'wrap', gap:8, padding:'0 20px' }}>
        {ingredients.map(i => <Badge key={i} text={i} variant="neutral" />)}
        <Badge text="Sans parfum" variant="success" showDot />
      </div>

      <div style={{ padding:'24px 20px 28px', display:'flex', flexDirection:'column', gap:12 }}>
        <Button label="Ajouter à ma routine" variant="primary" centered iconLeft={<img src={ICON('routine')} alt="" style={{width:20,height:20,filter:'brightness(0) invert(1)'}}/>} />
        <Button label="Voir dans la boutique" variant="outline" centered />
      </div>
    </div>
  );
}

// ── Profile ─────────────────────────────────────────────────
function ProfileScreen() {
  const [notif, setNotif] = React.useState(true);
  const [dark, setDark] = React.useState(false);
  const { Switch } = window.CleoCareDesignSystem_387d4e;
  const Row = ({ icon, label, control }) => (
    <div style={{ display:'flex', alignItems:'center', gap:14, padding:'15px 0', borderBottom:'1px solid var(--cleo-100)' }}>
      <div style={{ width:38, height:38, flex:'none', borderRadius:'var(--radius-lg)', background:'var(--cleo-100)', display:'flex', alignItems:'center', justifyContent:'center' }}>
        <img src={ICON(icon)} alt="" style={{ width:20, height:20 }} />
      </div>
      <span style={{ flex:1, fontSize:15, fontWeight:500, color:'var(--text-secondary)' }}>{label}</span>
      {control || <img src={ICON('chevron_right')} alt="" style={{ width:18, height:18, opacity:.5 }} />}
    </div>
  );
  return (
    <div style={{ background:'var(--cleo-50)', minHeight:'100%' }}>
      <AppBar title="Mon profil" centerTitle />
      <div style={{ display:'flex', flexDirection:'column', alignItems:'center', gap:10, padding:'8px 20px 4px' }}>
        <Avatar size="xl" name={D.user.name} showEdit />
        <div style={{ textAlign:'center' }}>
          <div style={{ fontSize:20, fontWeight:700, color:'var(--text-strong)' }}>{D.user.name} Mbarga</div>
          <div style={{ fontSize:13, color:'var(--text-muted)' }}>{D.user.skin} · membre depuis 2024</div>
        </div>
      </div>
      <div style={{ display:'flex', gap:12, padding:'18px 20px 0' }}>
        {[['12','Produits'],['3','Routines'],['28','Jours']].map(([n,l]) => (
          <Card key={l} padding={14} style={{ flex:1, textAlign:'center' }}>
            <div style={{ fontSize:22, fontWeight:800, color:'var(--cleo-primary)' }}>{n}</div>
            <div style={{ fontSize:12, color:'var(--text-muted)', marginTop:2 }}>{l}</div>
          </Card>
        ))}
      </div>
      <div style={{ padding:'8px 20px 0' }}>
        <h2 style={{ margin:'24px 0 4px', fontSize:20, fontWeight:700, color:'var(--text-strong)' }}>Préférences</h2>
        <div style={{ padding:'0 2px' }}>
          <Row icon="bell" label="Notifications" control={<Switch checked={notif} onChange={setNotif} />} />
          <Row icon="dark_mode" label="Mode sombre" control={<Switch checked={dark} onChange={setDark} />} />
          <Row icon="face" label="Mon profil beauté" />
          <Row icon="settings" label="Paramètres du compte" />
        </div>
        <div style={{ padding:'20px 0 28px' }}>
          <Button label="Se déconnecter" variant="ghost" centered fullWidth
            iconLeft={<img src={ICON('logout')} alt="" style={{width:18,height:18}}/>} />
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { HomeScreen, EssentialsScreen, RoutinesScreen, BoutiqueScreen, ProfileScreen, ProductScreen });
