File size: 293,012 Bytes
42f73ba
 
 
 
 
 
 
 
 
 
71f2499
42f73ba
 
9b549f2
42f73ba
 
 
 
 
 
 
 
 
71f2499
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b549f2
 
be2dec1
9b549f2
be2dec1
 
9b549f2
 
be2dec1
 
 
 
 
 
 
 
9b549f2
 
 
 
 
 
 
 
 
 
 
 
 
be2dec1
9b549f2
 
 
be2dec1
9b549f2
 
 
 
 
be2dec1
9b549f2
 
be2dec1
9b549f2
 
be2dec1
 
 
 
 
9b549f2
 
 
 
 
71f2499
 
 
9b549f2
71f2499
 
17d3586
71f2499
 
 
 
 
17d3586
71f2499
 
 
 
9b549f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71f2499
9b549f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be2dec1
9b549f2
 
be2dec1
 
 
 
 
 
 
 
 
9b549f2
be2dec1
 
 
9b549f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17d3586
 
71f2499
 
42f73ba
 
 
a740077
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a740077
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77de16a
42f73ba
 
 
 
77de16a
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77de16a
 
 
 
 
 
 
 
 
 
 
 
 
 
42f73ba
 
 
 
 
 
 
 
77de16a
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2c144e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb373e
 
e99c86d
adb373e
 
 
 
 
 
 
e99c86d
 
adb373e
e99c86d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb373e
 
e99c86d
adb373e
 
e99c86d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb373e
 
 
e99c86d
adb373e
e99c86d
 
 
 
 
 
 
 
 
adb373e
 
 
e99c86d
adb373e
e99c86d
 
 
 
 
 
adb373e
 
e99c86d
adb373e
e99c86d
 
 
 
adb373e
e99c86d
 
 
 
adb373e
e99c86d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb373e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9d8d7a
adb373e
 
 
 
 
c9d8d7a
adb373e
c9d8d7a
 
adb373e
c9d8d7a
adb373e
 
 
 
 
 
c9d8d7a
adb373e
c9d8d7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb373e
 
c9d8d7a
adb373e
c9d8d7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb373e
c9d8d7a
adb373e
 
 
 
c9d8d7a
 
adb373e
c9d8d7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb373e
c9d8d7a
 
 
adb373e
c9d8d7a
 
 
 
 
adb373e
c9d8d7a
 
adb373e
 
c9d8d7a
 
adb373e
 
c9d8d7a
 
 
 
 
 
adb373e
 
 
c9d8d7a
adb373e
c9d8d7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adb373e
 
 
 
 
 
 
 
 
 
 
 
bb153f4
 
 
 
 
 
 
f60e4fa
 
bb153f4
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
f60e4fa
bb153f4
 
 
 
 
 
 
 
 
 
 
f5d0371
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb153f4
 
 
 
 
 
 
 
 
 
42f73ba
 
 
b2c144e
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2c144e
 
42f73ba
 
b2c144e
 
 
 
 
 
 
42f73ba
 
 
 
 
 
 
 
 
 
 
 
b2c144e
 
 
 
 
42f73ba
 
 
 
 
 
 
 
adb373e
 
e99c86d
adb373e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e99c86d
adb373e
e99c86d
adb373e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9d8d7a
adb373e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9d8d7a
adb373e
c9d8d7a
adb373e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5d0371
bb153f4
f5d0371
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71f2499
 
 
 
 
9b549f2
71f2499
 
9b549f2
 
 
71f2499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17d3586
71f2499
 
 
 
 
9b549f2
17d3586
 
 
 
9b549f2
 
 
 
 
 
 
 
71f2499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17d3586
71f2499
 
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a740077
 
 
 
 
 
 
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37ce01e
 
42f73ba
 
 
37ce01e
 
42f73ba
 
 
37ce01e
 
42f73ba
 
 
37ce01e
 
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37ce01e
42f73ba
 
 
 
 
 
 
 
0eec56c
 
 
 
 
42f73ba
0eec56c
42f73ba
 
 
 
 
 
 
 
 
adb373e
 
e99c86d
adb373e
e99c86d
 
adb373e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9d8d7a
adb373e
c9d8d7a
 
adb373e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb153f4
 
f5d0371
bb153f4
f5d0371
 
bb153f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42f73ba
 
 
 
a740077
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
"""
AI Software Factory - Space AC: Design Variations
Enhanced Gradio UI with visual JSON display + FastAPI
"""

import gradio as gr
from fastapi import FastAPI
from agents.moodboard_analyzer import MoodboardAnalyzer
from agents.design_variation_generator import DesignVariationGenerator
from agents.flutter_screen_generator import FlutterScreenGenerator
from agents.simple_flutter_generator import SimpleFlutterGenerator
import json
import os
import requests
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

# Initialize agents
moodboard_analyzer = MoodboardAnalyzer()
design_variation_generator = DesignVariationGenerator()
flutter_screen_generator = FlutterScreenGenerator()
simple_flutter_generator = SimpleFlutterGenerator()

# FastAPI app for orchestrator
app = FastAPI(
    title="Space AC: Design Variations",
    description="Design system generation agents",
    version="1.0.0"
)


@app.get("/health")
async def health():
    return {
        "status": "healthy",
        "space": "ac-design",
        "agents": ["moodboard_analyzer", "design_variation_generator", "flutter_screen_generator"]
    }


@app.post("/api/moodboard-analyzer")
async def moodboard_analyzer_endpoint(data: dict):
    """
    API endpoint for Moodboard Analyzer

    Input:
        reference_images: List of image URLs/descriptions
        mood_keywords: List of mood keywords

    Output:
        analysis: Color palettes, typography, UI patterns, insights
    """
    try:
        result = moodboard_analyzer.process(data)
        return {
            "success": True,
            "agent": "moodboard_analyzer",
            "output": result
        }
    except Exception as e:
        return {
            "success": False,
            "error": str(e)
        }


@app.post("/api/design-variation-generator")
async def design_variation_generator_endpoint(data: dict):
    """
    API endpoint for Design Variation Generator

    Input:
        moodboard_analysis: Output from AC1
        wireframe: Wireframe description
        app_context: App context info

    Output:
        themes: List of 4 design theme variations
    """
    try:
        result = design_variation_generator.process(data)
        return {
            "success": True,
            "agent": "design_variation_generator",
            "output": result
        }
    except Exception as e:
        return {
            "success": False,
            "error": str(e)
        }


@app.post("/api/flutter-screen-generator")
async def flutter_screen_generator_endpoint(data: dict):
    """
    API endpoint for Flutter Screen Generator (AC3)

    Input:
        theme: Complete theme from AC2
        app_type: Type of app (fitness, banking, rider, etc.)
        screens: List of screen names to generate

    Output:
        screens: List of generated screens with Flutter/Dart code
    """
    try:
        result = flutter_screen_generator.process(data)
        return {
            "success": True,
            "agent": "flutter_screen_generator",
            "output": result
        }
    except Exception as e:
        return {
            "success": False,
            "error": str(e)
        }


def create_color_palette_html(palettes):
    """Create HTML visualization for color palettes"""

    html = """
    <style>
        .palette-container {
            display: flex;
            flex-direction: column;
            gap: 20px;
            padding: 10px;
        }
        .palette-card {
            border: 1px solid #e0e0e0;
            border-radius: 12px;
            padding: 20px;
            background: white;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        .palette-header {
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 8px;
            color: #333;
        }
        .palette-mood {
            color: #666;
            font-style: italic;
            margin-bottom: 15px;
        }
        .color-row {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
        }
        .color-box {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 5px;
        }
        .color-swatch {
            width: 80px;
            height: 80px;
            border-radius: 8px;
            border: 2px solid #ddd;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .color-code {
            font-family: monospace;
            font-size: 12px;
            font-weight: bold;
            color: #444;
        }
    </style>

    <div class="palette-container">
    """

    for palette in palettes:
        html += f"""
        <div class="palette-card">
            <div class="palette-header">🎨 {palette['name']}</div>
            <div class="palette-mood">{palette['mood']}</div>
            <div class="color-row">
        """

        for color in palette['colors']:
            html += f"""
                <div class="color-box">
                    <div class="color-swatch" style="background-color: {color};"></div>
                    <div class="color-code">{color}</div>
                </div>
            """

        html += """
            </div>
        </div>
        """

    html += """
    </div>
    """

    return html


def create_typography_html(typography_trends):
    """Create HTML visualization for typography"""

    html = """
    <style>
        .typo-container {
            display: flex;
            flex-direction: column;
            gap: 15px;
            padding: 10px;
        }
        .typo-card {
            border-left: 4px solid #007AFF;
            padding: 15px 20px;
            background: #f8f9fa;
            border-radius: 8px;
        }
        .typo-font {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 8px;
            color: #333;
        }
        .typo-usage {
            display: inline-block;
            background: #007AFF;
            color: white;
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 12px;
            margin-bottom: 8px;
        }
        .typo-char {
            color: #666;
            font-size: 14px;
        }
    </style>

    <div class="typo-container">
    """

    for typo in typography_trends:
        html += f"""
        <div class="typo-card">
            <div class="typo-font">✍️ {typo['font_family']}</div>
            <div class="typo-usage">{typo['usage']}</div>
            <div class="typo-char">{typo['characteristics']}</div>
        </div>
        """

    html += """
    </div>
    """

    return html


def create_ui_patterns_html(ui_patterns):
    """Create HTML visualization for UI patterns"""

    html = """
    <style>
        .pattern-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 15px;
            padding: 10px;
        }
        .pattern-card {
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            padding: 15px;
            background: white;
            transition: transform 0.2s;
        }
        .pattern-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        }
        .pattern-name {
            font-weight: bold;
            font-size: 16px;
            margin-bottom: 8px;
            color: #333;
        }
        .pattern-freq {
            display: inline-block;
            background: #34C759;
            color: white;
            padding: 3px 10px;
            border-radius: 10px;
            font-size: 11px;
            margin-bottom: 8px;
        }
        .pattern-freq.common {
            background: #FF9500;
        }
        .pattern-freq.rare {
            background: #8E8E93;
        }
        .pattern-examples {
            color: #666;
            font-size: 13px;
            font-style: italic;
        }
    </style>

    <div class="pattern-container">
    """

    for pattern in ui_patterns:
        freq_class = pattern.get('frequency', 'common').replace(' ', '-').lower()
        freq_label = pattern.get('frequency', 'common')

        html += f"""
        <div class="pattern-card">
            <div class="pattern-name">🧩 {pattern['pattern']}</div>
            <div class="pattern-freq {freq_class}">{freq_label}</div>
        """

        if 'examples' in pattern:
            examples_text = ', '.join(pattern['examples'][:3])
            html += f"""
            <div class="pattern-examples">Examples: {examples_text}</div>
            """

        html += """
        </div>
        """

    html += """
    </div>
    """

    return html


def create_theme_card_html(theme: dict, theme_number: int) -> str:
    """Create HTML card for a single design theme"""

    html = f"""
    <style>
        .theme-card-{theme_number} {{
            border: 2px solid #e0e0e0;
            border-radius: 16px;
            padding: 24px;
            background: white;
            box-shadow: 0 4px 12px rgba(0,0,0,0.08);
            transition: transform 0.3s, box-shadow 0.3s;
            height: 100%;
            display: flex;
            flex-direction: column;
        }}
        .theme-card-{theme_number}:hover {{
            transform: translateY(-4px);
            box-shadow: 0 8px 24px rgba(0,0,0,0.12);
            border-color: #007AFF;
        }}
        .theme-header-{theme_number} {{
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 16px;
        }}
        .theme-name-{theme_number} {{
            font-size: 22px;
            font-weight: bold;
            color: #1C1C1E;
        }}
        .theme-badge-{theme_number} {{
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 11px;
            font-weight: 600;
        }}
        .theme-mood-{theme_number} {{
            color: #8E8E93;
            font-style: italic;
            margin-bottom: 20px;
            font-size: 14px;
        }}
        .theme-section-{theme_number} {{
            margin-bottom: 16px;
        }}
        .theme-section-title-{theme_number} {{
            font-size: 13px;
            font-weight: 600;
            color: #666;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 8px;
        }}
        .theme-colors-{theme_number} {{
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
        }}
        .theme-color-box-{theme_number} {{
            width: 32px;
            height: 32px;
            border-radius: 6px;
            border: 1px solid rgba(0,0,0,0.1);
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }}
        .theme-detail-{theme_number} {{
            font-size: 13px;
            color: #444;
            line-height: 1.6;
            padding: 8px;
            background: #f8f9fa;
            border-radius: 6px;
            margin-bottom: 8px;
        }}
        .theme-select-btn-{theme_number} {{
            margin-top: auto;
            padding: 12px 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border: none;
            border-radius: 8px;
            font-weight: 600;
            cursor: pointer;
            text-align: center;
            transition: transform 0.2s;
        }}
        .theme-select-btn-{theme_number}:hover {{
            transform: scale(1.05);
        }}
    </style>

    <div class="theme-card-{theme_number}">
        <div class="theme-header-{theme_number}">
            <div class="theme-name-{theme_number}">🎨 {theme.get('name', 'Theme')}</div>
            <div class="theme-badge-{theme_number}">{theme.get('style', '').upper()}</div>
        </div>

        <div class="theme-mood-{theme_number}">{theme.get('mood', '')}</div>

        <div class="theme-section-{theme_number}">
            <div class="theme-section-title-{theme_number}">Colors</div>
            <div class="theme-colors-{theme_number}">
    """

    # Add color swatches
    palette = theme.get('palette', {})
    for color_name, color_value in list(palette.items())[:6]:  # Show first 6 colors
        html += f'<div class="theme-color-box-{theme_number}" style="background-color: {color_value};" title="{color_name}: {color_value}"></div>'

    html += f"""
            </div>
        </div>

        <div class="theme-section-{theme_number}">
            <div class="theme-section-title-{theme_number}">Typography</div>
            <div class="theme-detail-{theme_number}">
                Display: {theme.get('typography', {}).get('display', {}).get('font_family', 'System')}<br>
                Body: {theme.get('typography', {}).get('body', {}).get('font_family', 'System')}
            </div>
        </div>

        <div class="theme-section-{theme_number}">
            <div class="theme-section-title-{theme_number}">Components</div>
            <div class="theme-detail-{theme_number}">
                {theme.get('component_style', {}).get('buttons', 'Standard buttons')}
            </div>
        </div>

        <div class="theme-section-{theme_number}">
            <div class="theme-section-title-{theme_number}">Animations</div>
            <div class="theme-detail-{theme_number}">
                {theme.get('animations', {}).get('style', 'Standard animations')}
                <br><small>Speed: {theme.get('animations', {}).get('speed', 'Medium')}</small>
            </div>
        </div>

        <button class="theme-select-btn-{theme_number}">Select This Theme →</button>
    </div>
    """

    return html


def create_themes_grid_html(themes: list) -> str:
    """Create grid of all 4 themes"""

    html = """
    <style>
        .themes-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 24px;
            padding: 20px;
        }
        @media (max-width: 768px) {
            .themes-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>

    <div class="themes-grid">
    """

    for idx, theme in enumerate(themes, 1):
        html += create_theme_card_html(theme, idx)

    html += """
    </div>
    """

    return html


def create_preview_gallery_html(previews: list) -> str:
    """Create HTML gallery for screen previews"""

    html = """
    <style>
        .preview-gallery {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
            gap: 24px;
            padding: 20px;
        }
        .preview-card {
            border: 2px solid #e0e0e0;
            border-radius: 16px;
            overflow: hidden;
            background: white;
            box-shadow: 0 4px 12px rgba(0,0,0,0.08);
            transition: transform 0.3s, box-shadow 0.3s;
        }
        .preview-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 8px 24px rgba(0,0,0,0.12);
            border-color: #007AFF;
        }
        .preview-image-container {
            position: relative;
            width: 100%;
            background: #f5f5f5;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 400px;
        }
        .preview-image {
            width: 100%;
            height: auto;
            display: block;
        }
        .preview-placeholder {
            width: 100%;
            height: 400px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 18px;
            font-weight: 600;
        }
        .preview-info {
            padding: 16px;
        }
        .preview-screen-name {
            font-size: 18px;
            font-weight: bold;
            color: #1C1C1E;
            margin-bottom: 8px;
            text-transform: capitalize;
        }
        .preview-status {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 11px;
            font-weight: 600;
            margin-bottom: 8px;
        }
        .status-generated {
            background: #34C759;
            color: white;
        }
        .status-placeholder {
            background: #FF9500;
            color: white;
        }
        .status-error {
            background: #FF3B30;
            color: white;
        }
        .preview-message {
            font-size: 12px;
            color: #8E8E93;
            margin-top: 8px;
        }
        @media (max-width: 768px) {
            .preview-gallery {
                grid-template-columns: 1fr;
            }
        }
    </style>

    <div class="preview-gallery">
    """

    for preview in previews:
        screen = preview.get("screen", "Screen")
        image_url = preview.get("image_url", "")
        status = preview.get("status", "generated")
        message = preview.get("message", "")

        # Status badge
        status_class = {
            "generated": "status-generated",
            "placeholder": "status-placeholder",
            "error": "status-error",
            "timeout": "status-error"
        }.get(status, "status-placeholder")

        status_text = {
            "generated": "✅ GENERATED",
            "placeholder": "⚠️ PLACEHOLDER",
            "error": "❌ ERROR",
            "timeout": "⏱️ TIMEOUT"
        }.get(status, "UNKNOWN")

        html += f"""
        <div class="preview-card">
            <div class="preview-image-container">
        """

        if image_url and status == "generated":
            html += f'<img src="{image_url}" alt="{screen} screen" class="preview-image" />'
        else:
            html += f'<div class="preview-placeholder">📱 {screen.upper()}</div>'

        html += f"""
            </div>
            <div class="preview-info">
                <div class="preview-screen-name">📱 {screen}</div>
                <div class="preview-status {status_class}">{status_text}</div>
        """

        if message:
            html += f'<div class="preview-message">{message}</div>'

        html += """
            </div>
        </div>
        """

    html += """
    </div>
    """

    return html


# Gradio UI functions
def analyze_moodboard(
    image_descriptions: str,
    mood_keywords: str
):
    """
    Gradio interface function for Moodboard Analyzer with enhanced visual output
    """

    # Parse inputs
    descriptions = [d.strip() for d in image_descriptions.split('\n') if d.strip()]
    keywords = [k.strip() for k in mood_keywords.split(',') if k.strip()]

    # Prepare input data
    reference_images = [
        {"description": desc, "url": ""} for desc in descriptions
    ]

    input_data = {
        "reference_images": reference_images,
        "mood_keywords": keywords
    }

    # Process
    result = moodboard_analyzer.process(input_data)

    # Format output
    analysis = result.get("analysis", {})

    # Create visual HTML components
    color_palette_html = create_color_palette_html(analysis.get("color_palettes", []))
    typography_html = create_typography_html(analysis.get("typography_trends", []))
    ui_patterns_html = create_ui_patterns_html(analysis.get("ui_patterns", []))

    # Layout styles markdown
    layout_md = "## 📐 Layout Styles\n\n"
    for style in analysis.get("layout_styles", []):
        layout_md += f"- {style}\n"

    # Insights markdown
    insights_md = "## 💡 Design Insights\n\n"
    insights_md += "```\n" + analysis.get("insights", "") + "\n```"

    # JSON output
    json_output = json.dumps(analysis, indent=2)

    return (
        color_palette_html,
        typography_html,
        ui_patterns_html,
        layout_md,
        insights_md,
        json_output,
        analysis  # Return raw data for state
    )


def generate_design_themes(
    moodboard_analysis_json: str,
    wireframe_description: str
):
    """
    Generate 4 design theme variations from moodboard analysis
    """

    try:
        # Parse moodboard analysis
        moodboard_analysis = json.loads(moodboard_analysis_json)
    except:
        return (
            "<p style='color: red;'>Error: Invalid moodboard analysis. Please run AC1 first.</p>",
            "{}"
        )

    # Prepare input for AC2
    input_data = {
        "moodboard_analysis": moodboard_analysis,
        "wireframe": wireframe_description,
        "app_context": {
            "type": "mobile_app"
        }
    }

    # Generate themes
    result = design_variation_generator.process(input_data)
    themes = result.get("themes", [])

    if not themes:
        return (
            "<p style='color: red;'>No themes generated</p>",
            "{}"
        )

    # Create visual grid
    themes_grid_html = create_themes_grid_html(themes)

    # JSON output
    json_output = json.dumps(result, indent=2)

    return (
        themes_grid_html,
        json_output,
        result  # Return raw data for state
    )


def create_anonymous_gist(code: str, description: str = "Flutter code from AI Software Factory") -> str:
    """
    Create a GitHub Gist with the generated code
    Returns the Gist ID for use with DartPad

    Requires GITHUB_TOKEN environment variable for authentication
    """
    try:
        # Get GitHub token from environment
        github_token = os.getenv("GITHUB_TOKEN", "").strip()

        if not github_token:
            print("❌ GITHUB_TOKEN not configured - Gist creation requires authentication")
            print("   Add GITHUB_TOKEN to HuggingFace Space Secrets")
            return None

        url = "https://api.github.com/gists"
        payload = {
            "description": description,
            "public": True,
            "files": {
                "main.dart": {
                    "content": code
                }
            }
        }

        headers = {
            "Accept": "application/vnd.github+json",
            "Authorization": f"Bearer {github_token}",
            "X-GitHub-Api-Version": "2022-11-28"
        }

        print(f"📤 Creating Gist with GitHub API (authenticated)...")
        response = requests.post(url, json=payload, headers=headers, timeout=10)
        response.raise_for_status()

        gist_data = response.json()
        gist_id = gist_data["id"]
        gist_url = gist_data.get("html_url", f"https://gist.github.com/{gist_id}")

        print(f"✅ Created Gist: {gist_id}")
        print(f"   URL: {gist_url}")
        return gist_id

    except requests.exceptions.HTTPError as e:
        print(f"❌ Gist creation failed (HTTP {e.response.status_code}): {e}")
        if e.response.status_code == 401:
            print("   Check that GITHUB_TOKEN is valid and has 'gist' scope")
        return None
    except Exception as e:
        print(f"❌ Gist creation failed: {e}")
        return None


def generate_simple_flutter(prompt: str):
    """
    Simple Flutter generation: prompt -> DeepSeek -> code
    Automatically creates Gist and embeds in DartPad
    """
    if not prompt or not prompt.strip():
        return ("", "<p style='color: red;'>Please enter a prompt</p>", "")

    result = simple_flutter_generator.generate(prompt)

    if not result["success"]:
        error_msg = result.get("error", "Unknown error")
        return ("", f"<p style='color: red;'>❌ Error: {error_msg}</p>", "")

    code = result["code"]
    lines = result["lines"]

    # Create anonymous Gist
    print("📤 Creating anonymous Gist...")
    gist_id = create_anonymous_gist(code, f"Flutter code: {prompt[:100]}")

    if gist_id:
        # Success - embed DartPad with code loaded
        dartpad_url = f"https://dartpad.dev/embed-flutter.html?id={gist_id}&theme=dark"
        gist_url = f"https://gist.github.com/{gist_id}"

        summary_html = f"""
        <div style='padding: 20px; background: #f0f9ff; border-radius: 8px; border-left: 4px solid #10b981;'>
            <h3 style='margin: 0 0 10px 0; color: #059669;'>✅ Codice Generato e Caricato in DartPad</h3>
            <p style='margin: 5px 0;'><strong>Prompt:</strong> {prompt}</p>
            <p style='margin: 5px 0;'><strong>Righe di codice:</strong> {lines}</p>
            <p style='margin: 5px 0;'><strong>Gist ID:</strong> <code>{gist_id}</code></p>
            <div style='margin-top: 15px; padding: 10px; background: white; border-radius: 4px; border: 1px solid #10b981;'>
                <p style='margin: 5px 0; color: #059669; font-weight: bold;'>🎉 Il codice è già caricato nel DartPad qui sotto!</p>
                <p style='margin: 5px 0;'>Clicca il pulsante "▶ Run" nel DartPad per eseguire l'app</p>
                <p style='margin: 10px 0 5px 0; font-size: 13px;'>
                    📎 Link Gist: <a href='{gist_url}' target='_blank' style='color: #2563eb;'>{gist_url}</a>
                </p>
            </div>
        </div>
        """

        dartpad_html = f"""
        <div style='border: 2px solid #10b981; border-radius: 8px; overflow: hidden;'>
            <div style='background: linear-gradient(135deg, #059669 0%, #10b981 100%); color: white; padding: 12px; font-weight: bold; display: flex; justify-content: space-between; align-items: center;'>
                <span>📱 DartPad - Codice Automaticamente Caricato</span>
                <a href='https://dartpad.dev/?id={gist_id}' target='_blank' style='background: white; color: #059669; padding: 6px 12px; border-radius: 4px; text-decoration: none; font-size: 13px;'>
                    🚀 Apri in DartPad Full Screen
                </a>
            </div>
            <iframe
                src="{dartpad_url}"
                style="width:100%; height:700px; border:none;"
                allow="clipboard-write">
            </iframe>
        </div>
        """
    else:
        # Fallback - Gist creation failed
        summary_html = f"""
        <div style='padding: 20px; background: #fff3cd; border-radius: 8px; border-left: 4px solid #ffc107;'>
            <h3 style='margin: 0 0 10px 0; color: #856404;'>⚠️ Codice Generato (Auto-load DartPad non disponibile)</h3>
            <p style='margin: 5px 0;'><strong>Prompt:</strong> {prompt}</p>
            <p style='margin: 5px 0;'><strong>Righe di codice:</strong> {lines}</p>
            <div style='margin: 10px 0; padding: 10px; background: #fff; border-radius: 4px; border-left: 3px solid #ffc107;'>
                <p style='margin: 0 0 5px 0; font-weight: bold; color: #856404;'>ℹ️ Configurazione richiesta:</p>
                <p style='margin: 5px 0; font-size: 13px;'>Per abilitare il caricamento automatico in DartPad, l'admin dello Space deve:</p>
                <ol style='margin: 5px 0; padding-left: 20px; font-size: 13px;'>
                    <li>Creare un GitHub Personal Access Token con scope "gist"</li>
                    <li>Aggiungerlo come Secret "GITHUB_TOKEN" nelle impostazioni dello Space</li>
                </ol>
            </div>
            <p style='margin: 10px 0 5px 0; color: #856404; font-weight: bold;'>Come testare manualmente:</p>
            <ol style='margin: 5px 0; padding-left: 20px;'>
                <li>Espandi la sezione "💻 Codice Sorgente" qui sotto</li>
                <li>Copia tutto il codice</li>
                <li>Apri <a href='https://dartpad.dev' target='_blank' style='color: #2563eb;'>dartpad.dev</a> in una nuova tab</li>
                <li>Incolla il codice e clicca "Run"</li>
            </ol>
        </div>
        """

        dartpad_html = """
        <div style='border: 2px solid #ffc107; border-radius: 8px; overflow: hidden;'>
            <div style='background: #ffc107; color: #000; padding: 10px; font-weight: bold;'>
                ⚠️ DartPad Manuale - Incolla il codice qui
            </div>
            <iframe
                src="https://dartpad.dev/embed-flutter.html?theme=dark&run=false"
                style="width:100%; height:600px; border:none;"
                allow="clipboard-write">
            </iframe>
        </div>
        """

    return (code, summary_html, dartpad_html)


def generate_flutter_screens(
    theme_json: str,
    app_type: str,
    custom_prompt: str,
    screens_text: str
):
    """
    Generate Flutter/Dart screen code from a selected theme
    """

    try:
        # Parse theme JSON
        theme_data = json.loads(theme_json)

        # Get theme from the result
        if "themes" in theme_data:
            # Full AC2 output - use first theme
            theme = theme_data["themes"][0]
        else:
            # Single theme object
            theme = theme_data
    except:
        return (
            "",
            "",
            "",
            "<p style='color: red;'>❌ Error: Invalid theme JSON. Please run AC2 first and paste a theme.</p>"
        )

    # Parse screens list
    screens = [s.strip() for s in screens_text.split(',') if s.strip()]
    if not screens:
        screens = ["home", "detail", "profile"]

    # Prepare input for AC3
    input_data = {
        "theme": theme,
        "app_type": app_type,
        "custom_prompt": custom_prompt,  # Add custom prompt
        "screens": screens[:3]  # Max 3 screens
    }

    # Generate Flutter screens
    result = flutter_screen_generator.process(input_data)
    screens_data = result.get("screens", [])

    # Debug logging
    print(f"🔍 DEBUG: Result keys: {result.keys()}")
    print(f"🔍 DEBUG: Screens count: {len(screens_data)}")
    if "error" in result:
        print(f"❌ DEBUG: Error in result: {result['error']}")

    if not screens_data or len(screens_data) < 4:
        error_msg = result.get("error", "Unknown error")
        empty = "<p style='color: red;'>❌ Error generating backgrounds</p>"
        return (
            f"<p style='color: red;'>❌ No screens generated</p><p>Error: {error_msg}</p>",
            empty, "", empty, "", empty, "", empty, ""
        )

    # Get theme colors
    palette = theme.get("palette", {})
    primary = palette.get("primary", "#FF6D00")
    secondary = palette.get("secondary", "#FFE082")
    accent = palette.get("accent", "#FFA726")

    def create_preview(variant_data, code):
        """Create HTML preview for a complete variant (background + header + footer + cards)"""
        bg_style = variant_data.get("bg_style", "gradient_linear")
        header_type = variant_data.get("header_type", "minimal")
        footer_type = variant_data.get("footer_type", "minimal_icons")
        variant_name = variant_data.get("name", bg_style.replace('_', ' ').title())
        card_ids = variant_data.get("cards", [])

        # Background layer
        if bg_style == "waves":
            preview_bg = f"background: linear-gradient(to bottom, {primary}20, {secondary}33, {accent}20); position: relative; overflow: hidden;"
            bg_layer = f"""
            <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 430 932" preserveAspectRatio="none">
                <path d="M 0,140 Q 107.5,75 215,140 T 430,130 L 430,0 L 0,0 Z" fill="{primary}" opacity="0.4"/>
                <path d="M 0,465 Q 129,418 215,485 T 430,465 L 430,279 L 0,279 Z" fill="{secondary}" opacity="0.35"/>
                <path d="M 0,820 Q 107.5,763 215,801 T 430,792 L 430,932 L 0,932 Z" fill="{accent}" opacity="0.3"/>
            </svg>
            """
        elif bg_style == "gradient_linear":
            preview_bg = f"background: linear-gradient(135deg, {primary}, {secondary}, {accent});"
            bg_layer = ""
        elif bg_style == "gradient_radial":
            preview_bg = f"background: radial-gradient(circle, {primary}, {secondary}, {accent});"
            bg_layer = ""
        else:  # geometric
            preview_bg = f"background: linear-gradient(135deg, {primary}33, {secondary}4D);"
            bg_layer = f"""
            <div style="position: absolute; width: 100%; height: 100%; top: 0; left: 0; overflow: hidden;">
                <div style="position: absolute; left: 20%; top: 15%; width: 40%; padding-top: 40%; background: {primary}; opacity: 0.3; border-radius: 50%;"></div>
                <div style="position: absolute; right: 10%; bottom: 30%; width: 35%; padding-top: 35%; background: {accent}; opacity: 0.25; border-radius: 50%;"></div>
                <div style="position: absolute; left: 50%; top: 45%; width: 25%; padding-top: 25%; background: {secondary}; opacity: 0.2; border-radius: 50%; transform: translate(-50%, -50%);"></div>
                <div style="position: absolute; right: 8%; top: 10%; width: 30%; height: 20%; background: {accent}; opacity: 0.15; border-radius: 20px;"></div>
            </div>
            """

        # Header layer
        if header_type == "avatar_search":
            header_html = f"""
            <div style="position: absolute; top: 50px; left: 0; right: 0; padding: 0 20px; z-index: 20; display: flex; justify-content: space-between; align-items: center;">
                <div style="width: 40px; height: 40px; border-radius: 50%; background: {primary}; border: 2px solid #fff;"></div>
                <div style="flex: 1; margin: 0 12px; height: 40px; background: rgba(255,255,255,0.9); border-radius: 20px; display: flex; align-items: center; padding: 0 15px; color: #666; font-size: 13px;">🔍 Search...</div>
                <div style="width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.2); display: flex; align-items: center; justify-content: center; font-size: 18px;">🔔</div>
            </div>
            """
        elif header_type == "tabs":
            header_html = f"""
            <div style="position: absolute; top: 50px; left: 0; right: 0; padding: 0 20px; z-index: 20;">
                <div style="color: #fff; font-size: 22px; font-weight: bold; margin-bottom: 12px;">Dashboard</div>
                <div style="display: flex; gap: 8px;">
                    <div style="padding: 8px 16px; background: {primary}; color: #fff; border-radius: 20px; font-size: 12px;">All</div>
                    <div style="padding: 8px 16px; background: rgba(255,255,255,0.2); color: #fff; border-radius: 20px; font-size: 12px;">Active</div>
                    <div style="padding: 8px 16px; background: rgba(255,255,255,0.2); color: #fff; border-radius: 20px; font-size: 12px;">Completed</div>
                </div>
            </div>
            """
        elif header_type == "stats_header":
            header_html = f"""
            <div style="position: absolute; top: 50px; left: 0; right: 0; padding: 0 20px; z-index: 20;">
                <div style="display: flex; justify-content: space-around; background: rgba(255,255,255,0.15); backdrop-filter: blur(10px); border-radius: 16px; padding: 16px;">
                    <div style="text-align: center;"><div style="color: #fff; font-size: 20px; font-weight: bold;">24</div><div style="color: rgba(255,255,255,0.7); font-size: 11px;">Active</div></div>
                    <div style="text-align: center;"><div style="color: #fff; font-size: 20px; font-weight: bold;">156</div><div style="color: rgba(255,255,255,0.7); font-size: 11px;">Total</div></div>
                    <div style="text-align: center;"><div style="color: #fff; font-size: 20px; font-weight: bold;">4.8</div><div style="color: rgba(255,255,255,0.7); font-size: 11px;">Rating</div></div>
                </div>
            </div>
            """
        elif header_type == "collapsible":
            header_html = f"""
            <div style="position: absolute; top: 50px; left: 0; right: 0; padding: 0 20px; z-index: 20;">
                <div style="background: rgba(255,255,255,0.15); backdrop-filter: blur(10px); border-radius: 16px; padding: 20px;">
                    <div style="color: #fff; font-size: 24px; font-weight: bold;">Welcome Back!</div>
                    <div style="color: rgba(255,255,255,0.8); font-size: 13px; margin-top: 4px;">Ready to continue your journey?</div>
                </div>
            </div>
            """
        else:  # minimal
            header_html = f"""
            <div style="position: absolute; top: 50px; left: 0; right: 0; padding: 0 20px; z-index: 20;">
                <div style="color: #fff; font-size: 26px; font-weight: bold; text-shadow: 0 2px 8px rgba(0,0,0,0.2);">Home</div>
            </div>
            """

        # Footer layer
        if footer_type == "floating_fab":
            footer_html = f"""
            <div style="position: absolute; bottom: 0; left: 0; right: 0; height: 80px; background: rgba(255,255,255,0.95); backdrop-filter: blur(10px); border-radius: 28px 28px 0 0; display: flex; justify-content: space-around; align-items: center; z-index: 20;">
                <div style="font-size: 22px;">🏠</div>
                <div style="font-size: 22px; opacity: 0.5;">📊</div>
                <div style="width: 56px; height: 56px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; font-size: 28px; margin-top: -40px; box-shadow: 0 8px 16px rgba(0,0,0,0.15);">➕</div>
                <div style="font-size: 22px; opacity: 0.5;">🔔</div>
                <div style="font-size: 22px; opacity: 0.5;">👤</div>
            </div>
            """
        elif footer_type == "animated_pills":
            footer_html = f"""
            <div style="position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; background: rgba(255,255,255,0.95); padding: 12px 20px; border-radius: 30px; box-shadow: 0 8px 24px rgba(0,0,0,0.15); z-index: 20;">
                <div style="display: flex; align-items: center; gap: 6px; padding: 8px 16px; background: {primary}; color: #fff; border-radius: 20px; font-size: 11px;"><span style="font-size: 16px;">🏠</span> Home</div>
                <div style="display: flex; align-items: center; gap: 6px; padding: 8px 12px; color: #666; font-size: 16px;">📊</div>
                <div style="display: flex; align-items: center; gap: 6px; padding: 8px 12px; color: #666; font-size: 16px;">👤</div>
            </div>
            """
        elif footer_type == "classic_expanded":
            footer_html = f"""
            <div style="position: absolute; bottom: 0; left: 0; right: 0; height: 70px; background: #fff; border-top: 1px solid #eee; display: flex; justify-content: space-around; align-items: center; z-index: 20;">
                <div style="text-align: center;"><div style="font-size: 22px; color: {primary};">🏠</div><div style="font-size: 10px; color: {primary}; margin-top: 2px;">Home</div></div>
                <div style="text-align: center;"><div style="font-size: 22px; opacity: 0.4;">📊</div><div style="font-size: 10px; opacity: 0.4; margin-top: 2px;">Stats</div></div>
                <div style="text-align: center;"><div style="font-size: 22px; opacity: 0.4;">🔔</div><div style="font-size: 10px; opacity: 0.4; margin-top: 2px;">Alerts</div></div>
                <div style="text-align: center;"><div style="font-size: 22px; opacity: 0.4;">👤</div><div style="font-size: 10px; opacity: 0.4; margin-top: 2px;">Profile</div></div>
            </div>
            """
        elif footer_type == "gesture_bar":
            footer_html = f"""
            <div style="position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); width: 140px; height: 5px; background: rgba(255,255,255,0.3); border-radius: 10px; z-index: 20;"></div>
            """
        else:  # minimal_icons
            footer_html = f"""
            <div style="position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 24px; background: rgba(255,255,255,0.2); backdrop-filter: blur(10px); padding: 14px 32px; border-radius: 30px; z-index: 20;">
                <div style="font-size: 22px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));">🏠</div>
                <div style="font-size: 22px; opacity: 0.5; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));">📊</div>
                <div style="font-size: 22px; opacity: 0.5; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));">🔔</div>
                <div style="font-size: 22px; opacity: 0.5; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));">👤</div>
            </div>
            """

        # Generate cards HTML for the content area
        cards_html = ""
        if card_ids:
            cards_html = '<div style="position: absolute; top: 140px; left: 0; right: 0; bottom: 90px; padding: 0 16px; overflow-y: auto; z-index: 15; display: flex; flex-direction: column; gap: 12px;">'
            for card_id in card_ids[:4]:  # Max 4 cards in preview
                try:
                    card_html = render_card_html(card_id, primary, secondary, accent)
                    # Wrap card in a container with scale to fit preview
                    cards_html += f'<div style="transform: scale(0.85); transform-origin: top center; margin: -8px 0;">{card_html}</div>'
                except:
                    # Skip cards that fail to render
                    pass
            cards_html += '</div>'

        return f"""
        <div style="width: 100%; padding: 20px; background: #000; border-radius: 16px;">
            <div style="margin: 0 auto; max-width: 380px;">
                <div style="background: #000; padding: 15px; border-radius: 28px; box-shadow: 0 15px 40px rgba(0,0,0,0.5);">
                    <div style="width: 100%; padding-top: 216%; border-radius: 20px; {preview_bg} position: relative; overflow: hidden;">
                        {bg_layer}
                        <div style="position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: 140px; height: 24px; background: #000; border-radius: 16px; border: 1px solid rgba(255,255,255,0.1); z-index: 10;"></div>
                        {header_html}
                        {cards_html}
                        {footer_html}
                    </div>
                </div>
                <p style="color: #fff; text-align: center; margin-top: 15px; font-size: 13px;">✨ {variant_name}</p>
            </div>
        </div>
        """

    # Extract all 4 screens
    previews = []
    codes = []
    variant_names = []
    for i, screen in enumerate(screens_data[:4]):
        code = screen.get("code", "")
        preview = create_preview(screen, code)
        previews.append(preview)
        codes.append(code)
        variant_names.append(screen.get("name", f"Variant {i+1}"))

    # Create summary with variant details
    variant_list_html = ""
    for i, screen in enumerate(screens_data[:4]):
        variant_list_html += f"""
        <div style='background: #fff; padding: 12px; margin-bottom: 8px; border-radius: 8px; border-left: 3px solid #007AFF;'>
            <strong>{screen.get('name', f'Variant {i+1}')}</strong><br/>
            <span style='font-size: 12px; color: #666;'>
                Background: {screen.get('bg_style', 'N/A')} |
                Header: {screen.get('header_type', 'N/A')} |
                Footer: {screen.get('footer_type', 'N/A')}
            </span>
        </div>
        """

    summary_html = f"""
    <div style='padding: 20px; background: #f0f9ff; border-radius: 12px; border-left: 4px solid #007AFF;'>
        <h3 style='margin-top: 0; color: #007AFF;'>✅ 4 AI-Generated Variants Created!</h3>
        <p><strong>Theme:</strong> {theme.get('name', 'Unknown')}</p>
        <p><strong>App Type:</strong> {app_type.capitalize()}</p>
        <p><strong>Total Lines:</strong> {result.get('total_lines', 0)}</p>
        <div style='margin-top: 12px;'>
            <strong>Variants:</strong>
            {variant_list_html}
        </div>
        <p style='margin-bottom: 0; margin-top: 12px;'><strong>Status:</strong> Ready! 🎨 Each variant intelligently combines background, header, and footer based on your theme style.</p>
    </div>
    """

    return (
        summary_html,
        previews[0], codes[0],  # waves
        previews[1], codes[1],  # linear
        previews[2], codes[2],  # radial
        previews[3], codes[3]   # geometric
    )


def render_background_html(bg_id: str, bg_info: dict, primary: str, secondary: str, accent: str) -> str:
    """
    Generate HTML/CSS for a single background preview
    Returns HTML div with the background rendered
    """
    bg_name = bg_info['name']
    bg_category = bg_info['category']

    # Common container style
    base_style = "width: 150px; height: 250px; border-radius: 12px; position: relative; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.15);"

    # Generate background based on type
    if "gradient_linear" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(135deg, {primary}, {secondary}, {accent});"
        bg_layer = ""
    elif "gradient_radial" in bg_id:
        bg_style = f"{base_style} background: radial-gradient(circle at 30% 40%, {primary}, {secondary} 50%, {accent});"
        bg_layer = ""
    elif "gradient_angular" in bg_id:
        bg_style = f"{base_style} background: conic-gradient(from 45deg, {primary}, {secondary}, {accent}, {primary});"
        bg_layer = ""
    elif "gradient_sweep" in bg_id:
        bg_style = f"{base_style} background: conic-gradient(from 0deg at 50% 50%, {primary}, {secondary}, {accent}, {primary});"
        bg_layer = ""
    elif "gradient_diagonal" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(45deg, {primary} 0%, {secondary} 50%, {accent} 100%);"
        bg_layer = ""
    elif "gradient_mesh" in bg_id:
        bg_style = f"{base_style} background: radial-gradient(at 20% 30%, {primary} 0%, transparent 50%), radial-gradient(at 80% 70%, {secondary} 0%, transparent 50%), radial-gradient(at 50% 50%, {accent} 0%, transparent 50%), linear-gradient(135deg, {primary}20, {secondary}30);"
        bg_layer = ""
    elif "waves_smooth" in bg_id or "waves_sharp" in bg_id or "waves_layered" in bg_id or "waves_curved" in bg_id or "waves_minimal" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(to bottom, {primary}20, {secondary}33, {accent}20);"
        bg_layer = f"""
        <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 150 250" preserveAspectRatio="none">
            <path d="M 0,60 Q 37.5,30 75,60 T 150,55 L 150,0 L 0,0 Z" fill="{primary}" opacity="0.4"/>
            <path d="M 0,150 Q 45,130 75,155 T 150,150 L 150,90 L 0,90 Z" fill="{secondary}" opacity="0.35"/>
            <path d="M 0,210 Q 37.5,190 75,205 T 150,202 L 150,250 L 0,250 Z" fill="{accent}" opacity="0.3"/>
        </svg>
        """
    elif "geometric_circles" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(135deg, {primary}33, {secondary}4D);"
        bg_layer = f"""
        <div style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;">
            <div style="position: absolute; left: 15%; top: 12%; width: 35%; padding-top: 35%; background: {primary}; opacity: 0.3; border-radius: 50%;"></div>
            <div style="position: absolute; right: 8%; bottom: 25%; width: 30%; padding-top: 30%; background: {accent}; opacity: 0.25; border-radius: 50%;"></div>
            <div style="position: absolute; left: 45%; top: 40%; width: 22%; padding-top: 22%; background: {secondary}; opacity: 0.2; border-radius: 50%;"></div>
        </div>
        """
    elif "geometric_triangles" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(135deg, {primary}1A, {secondary}26);"
        bg_layer = f"""
        <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 150 250">
            <polygon points="30,50 60,10 90,50" fill="{primary}" opacity="0.3"/>
            <polygon points="80,120 110,80 140,120" fill="{secondary}" opacity="0.3"/>
            <polygon points="20,180 50,140 80,180" fill="{accent}" opacity="0.25"/>
        </svg>
        """
    elif "geometric_hexagons" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(to bottom, {primary}1A, {secondary}26);"
        bg_layer = f"""
        <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 150 250">
            <polygon points="75,30 95,40 95,60 75,70 55,60 55,40" fill="{primary}" opacity="0.3" stroke="{primary}" stroke-width="1"/>
            <polygon points="45,100 65,110 65,130 45,140 25,130 25,110" fill="{secondary}" opacity="0.3" stroke="{secondary}" stroke-width="1"/>
            <polygon points="105,160 125,170 125,190 105,200 85,190 85,170" fill="{accent}" opacity="0.25" stroke="{accent}" stroke-width="1"/>
        </svg>
        """
    elif "geometric_grid" in bg_id:
        bg_style = f"{base_style} background: repeating-linear-gradient(0deg, transparent, transparent 19px, {primary}40 19px, {primary}40 20px), repeating-linear-gradient(90deg, transparent, transparent 19px, {secondary}40 19px, {secondary}40 20px), {accent}0D;"
        bg_layer = ""
    elif "geometric_stripes" in bg_id:
        bg_style = f"{base_style} background: repeating-linear-gradient(45deg, {primary}40, {primary}40 10px, {secondary}40 10px, {secondary}40 20px, {accent}30 20px, {accent}30 30px);"
        bg_layer = ""
    elif "geometric_diamonds" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(135deg, {primary}1A 25%, transparent 25%), linear-gradient(225deg, {secondary}1A 25%, transparent 25%), linear-gradient(45deg, {accent}1A 25%, transparent 25%), linear-gradient(315deg, {primary}26 25%, {secondary}0D 25%);"
        bg_layer = ""
    elif "organic_blobs" in bg_id or "organic_fluid" in bg_id:
        bg_style = f"{base_style} background: {secondary}26;"
        bg_layer = f"""
        <svg style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" viewBox="0 0 150 250">
            <path d="M 30,40 Q 50,20 70,40 T 110,50 Q 120,70 100,90 T 60,80 Q 40,70 30,40 Z" fill="{primary}" opacity="0.4"/>
            <path d="M 80,140 Q 100,120 120,140 T 140,180 Q 130,200 110,190 T 80,170 Q 70,150 80,140 Z" fill="{accent}" opacity="0.3"/>
        </svg>
        """
    elif "organic_noise" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(135deg, {primary}33, {secondary}4D); filter: contrast(170%) brightness(1000%);"
        bg_layer = f'<div style="position: absolute; width: 100%; height: 100%; background: url(\'data:image/svg+xml,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noise"%3E%3CfeTurbulence baseFrequency="0.9" /%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noise)" opacity="0.15"/%3E%3C/svg%3E\'); background-size: 100px 100px;"></div>'
    elif "organic_clouds" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(to bottom, {primary}40, {secondary}60, {accent}40);"
        bg_layer = f"""
        <div style="position: absolute; width: 100%; height: 100%;">
            <div style="position: absolute; left: 10%; top: 15%; width: 50px; height: 25px; background: white; opacity: 0.3; border-radius: 50%;"></div>
            <div style="position: absolute; left: 25%; top: 10%; width: 40px; height: 30px; background: white; opacity: 0.25; border-radius: 50%;"></div>
            <div style="position: absolute; right: 15%; top: 40%; width: 45px; height: 28px; background: white; opacity: 0.3; border-radius: 50%;"></div>
        </div>
        """
    elif "pattern_dots" in bg_id:
        bg_style = f"{base_style} background: radial-gradient(circle, {primary} 2px, transparent 2px); background-size: 20px 20px; background-color: {secondary}1A;"
        bg_layer = ""
    elif "pattern_lines" in bg_id:
        bg_style = f"{base_style} background: repeating-linear-gradient(0deg, {primary}60, {primary}60 2px, transparent 2px, transparent 10px), {secondary}1A;"
        bg_layer = ""
    elif "pattern_chevron" in bg_id:
        bg_style = f"{base_style} background: repeating-linear-gradient(45deg, {primary}40, {primary}40 10px, {secondary}40 10px, {secondary}40 20px);"
        bg_layer = ""
    elif "pattern_zigzag" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(135deg, {primary}40 25%, transparent 25%), linear-gradient(225deg, {secondary}40 25%, transparent 25%), linear-gradient(315deg, {accent}30 25%, transparent 25%); background-size: 20px 20px;"
        bg_layer = ""
    elif "abstract_crystalline" in bg_id or "abstract_voronoi" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(135deg, {primary}26, {secondary}33, {accent}26);"
        bg_layer = f"""
        <svg style="position: absolute; width: 100%; height: 100%;" viewBox="0 0 150 250">
            <polygon points="30,20 60,50 40,80 10,70" fill="{primary}" opacity="0.3"/>
            <polygon points="70,30 110,40 100,80 80,90" fill="{secondary}" opacity="0.3"/>
            <polygon points="20,120 50,140 30,180 0,160" fill="{accent}" opacity="0.25"/>
            <polygon points="90,120 130,130 120,180 85,170" fill="{primary}" opacity="0.3"/>
        </svg>
        """
    elif "abstract_particles" in bg_id:
        bg_style = f"{base_style} background: {secondary}1A;"
        bg_layer = f"""
        <svg style="position: absolute; width: 100%; height: 100%;" viewBox="0 0 150 250">
            <circle cx="30" cy="40" r="3" fill="{primary}" opacity="0.6"/>
            <circle cx="70" cy="25" r="2" fill="{secondary}" opacity="0.5"/>
            <circle cx="110" cy="50" r="2.5" fill="{accent}" opacity="0.5"/>
            <circle cx="40" cy="90" r="2" fill="{primary}" opacity="0.4"/>
            <circle cx="90" cy="110" r="3" fill="{secondary}" opacity="0.6"/>
            <circle cx="120" cy="140" r="2" fill="{accent}" opacity="0.5"/>
            <circle cx="50" cy="170" r="2.5" fill="{primary}" opacity="0.5"/>
            <circle cx="100" cy="200" r="2" fill="{secondary}" opacity="0.4"/>
            <line x1="30" y1="40" x2="70" y2="25" stroke="{primary}" opacity="0.2" stroke-width="1"/>
            <line x1="70" y1="25" x2="110" y2="50" stroke="{secondary}" opacity="0.2" stroke-width="1"/>
            <line x1="40" y1="90" x2="90" y2="110" stroke="{accent}" opacity="0.2" stroke-width="1"/>
        </svg>
        """
    elif "abstract_rays" in bg_id:
        bg_style = f"{base_style} background: radial-gradient(circle at 50% 120%, {primary}, {secondary} 40%, {accent} 80%);"
        bg_layer = ""
    elif "abstract_constellation" in bg_id:
        bg_style = f"{base_style} background: linear-gradient(to bottom, {primary}1A, {secondary}26, {accent}1A);"
        bg_layer = f"""
        <svg style="position: absolute; width: 100%; height: 100%;" viewBox="0 0 150 250">
            <circle cx="40" cy="30" r="2" fill="white" opacity="0.8"/>
            <circle cx="80" cy="50" r="2.5" fill="white" opacity="0.9"/>
            <circle cx="110" cy="40" r="2" fill="white" opacity="0.7"/>
            <circle cx="30" cy="100" r="2" fill="white" opacity="0.8"/>
            <circle cx="100" cy="120" r="2.5" fill="white" opacity="0.9"/>
            <circle cx="60" cy="180" r="2" fill="white" opacity="0.7"/>
            <circle cx="120" cy="200" r="2" fill="white" opacity="0.8"/>
            <line x1="40" y1="30" x2="80" y2="50" stroke="white" opacity="0.3" stroke-width="0.5"/>
            <line x1="80" y1="50" x2="110" y2="40" stroke="white" opacity="0.3" stroke-width="0.5"/>
            <line x1="30" y1="100" x2="100" y2="120" stroke="white" opacity="0.3" stroke-width="0.5"/>
            <line x1="60" y1="180" x2="120" y2="200" stroke="white" opacity="0.3" stroke-width="0.5"/>
        </svg>
        """
    else:
        # Fallback: simple gradient
        bg_style = f"{base_style} background: linear-gradient(135deg, {primary}, {secondary});"
        bg_layer = ""

    return f"""
    <div style="{bg_style}">
        {bg_layer}
    </div>
    """


def render_header_html(header_id: str, header_info: dict, primary: str, secondary: str, accent: str) -> str:
    """
    Generate HTML/CSS for a single header preview (20 realistic headers)
    Returns HTML div with the header rendered
    """
    header_name = header_info['name']

    # Common container style
    base_style = "width: 300px; height: 100px; border-radius: 12px 12px 0 0; position: relative; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: linear-gradient(135deg, {}, {});".format(primary, secondary)

    # SOCIAL & PROFILE (5)
    if header_id == "profile_avatar_menu":
        content = f"""
        <div style="padding: 14px; display: flex; align-items: center; gap: 12px;">
            <div style="width: 44px; height: 44px; border-radius: 50%; background: white; display: flex; align-items: center; justify-content: center; font-size: 24px;">👤</div>
            <div style="flex: 1;">
                <div style="color: white; font-size: 15px; font-weight: 700;">John Doe</div>
                <div style="color: rgba(255,255,255,0.8); font-size: 11px;">📍 San Francisco, CA</div>
            </div>
            <div style="color: white; font-size: 24px; cursor: pointer;">☰</div>
        </div>
        """
    elif header_id == "avatar_notification_cart":
        content = f"""
        <div style="padding: 14px; display: flex; align-items: center; gap: 14px;">
            <div style="width: 40px; height: 40px; border-radius: 50%; background: {accent}; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px;">👤</div>
            <div style="flex: 1;"></div>
            <div style="position: relative; color: white; font-size: 22px;">
                🔔
                <div style="position: absolute; top: -4px; right: -4px; background: #FF3B30; border-radius: 50%; width: 16px; height: 16px; font-size: 9px; display: flex; align-items: center; justify-content: center; font-weight: 700;">3</div>
            </div>
            <div style="position: relative; color: white; font-size: 22px;">
                🛒
                <div style="position: absolute; top: -4px; right: -4px; background: #FF3B30; border-radius: 50%; width: 16px; height: 16px; font-size: 9px; display: flex; align-items: center; justify-content: center; font-weight: 700;">2</div>
            </div>
        </div>
        """
    elif header_id == "profile_stats_share":
        content = f"""
        <div style="padding: 12px; display: flex; align-items: center; gap: 10px;">
            <div style="width: 50px; height: 50px; border-radius: 50%; background: white; display: flex; align-items: center; justify-content: center; font-size: 26px;">👤</div>
            <div style="flex: 1; display: flex; gap: 12px; font-size: 11px; color: white;">
                <div style="text-align: center;">
                    <div style="font-weight: 700; font-size: 15px;">245</div>
                    <div style="opacity: 0.8;">Followers</div>
                </div>
                <div style="text-align: center;">
                    <div style="font-weight: 700; font-size: 15px;">189</div>
                    <div style="opacity: 0.8;">Following</div>
                </div>
            </div>
            <div style="color: white; font-size: 20px;">📤</div>
        </div>
        """
    elif header_id == "social_search_filter":
        content = f"""
        <div style="padding: 14px; display: flex; align-items: center; gap: 10px;">
            <div style="flex: 1; background: rgba(255,255,255,0.2); border-radius: 20px; padding: 10px 14px; font-size: 13px; color: rgba(255,255,255,0.9); display: flex; align-items: center; gap: 8px;">
                <span>🔍</span>
                <span>Search posts...</span>
            </div>
            <div style="color: white; font-size: 22px;">⚙️</div>
            <div style="color: white; font-size: 22px;">🎚️</div>
        </div>
        """
    elif header_id == "messenger_header":
        content = f"""
        <div style="padding: 14px; display: flex; align-items: center; gap: 12px;">
            <div style="color: white; font-size: 22px;">←</div>
            <div style="width: 40px; height: 40px; border-radius: 50%; background: white; display: flex; align-items: center; justify-content: center; font-size: 20px;">👤</div>
            <div style="flex: 1; color: white;">
                <div style="font-weight: 700; font-size: 14px;">Sarah Johnson</div>
                <div style="opacity: 0.8; font-size: 11px;">Active now</div>
            </div>
            <div style="color: white; font-size: 22px;">📞</div>
            <div style="color: white; font-size: 22px;">📹</div>
        </div>
        """

    # LOCATION & DELIVERY (4)
    elif header_id == "location_picker":
        content = f"""
        <div style="padding: 14px; display: flex; align-items: center; gap: 10px;">
            <div style="color: white; font-size: 24px;">📍</div>
            <div style="flex: 1; color: white;">
                <div style="font-size: 11px; opacity: 0.8;">Deliver to</div>
                <div style="font-weight: 700; font-size: 14px;">1234 Market St, SF ▼</div>
            </div>
            <div style="color: white; font-size: 20px;">🔔</div>
        </div>
        """
    elif header_id == "delivery_address_time":
        content = f"""
        <div style="padding: 12px; color: white;">
            <div style="display: flex; align-items: center; gap: 8px; margin-bottom: 6px;">
                <span style="font-size: 16px;">📍</span>
                <span style="font-size: 13px; font-weight: 600;">1234 Market Street</span>
                <span style="margin-left: auto; font-size: 11px; background: rgba(255,255,255,0.2); padding: 4px 8px; border-radius: 12px;">Change</span>
            </div>
            <div style="font-size: 11px; opacity: 0.9; display: flex; align-items: center; gap: 6px;">
                <span>⏱️</span>
                <span>Delivery in 25-30 mins</span>
            </div>
        </div>
        """
    elif header_id == "map_search_location":
        content = f"""
        <div style="padding: 14px;">
            <div style="background: rgba(255,255,255,0.95); border-radius: 24px; padding: 10px 14px; display: flex; align-items: center; gap: 10px;">
                <span style="font-size: 18px;">📍</span>
                <input style="border: none; background: transparent; flex: 1; font-size: 13px;" placeholder="Search location..."/>
                <span style="font-size: 18px; color: {primary};">🎯</span>
            </div>
        </div>
        """
    elif header_id == "ride_pickup_header":
        content = f"""
        <div style="padding: 12px; color: white; font-size: 12px;">
            <div style="display: flex; align-items: center; gap: 8px; margin-bottom: 8px;">
                <span style="font-size: 14px;">🟢</span>
                <span style="font-weight: 600;">Home - 123 Main St</span>
            </div>
            <div style="display: flex; align-items: center; gap: 8px;">
                <span style="font-size: 14px;">🔴</span>
                <span style="font-weight: 600;">Office - 456 Market St</span>
                <span style="margin-left: auto; font-size: 18px;">🔄</span>
            </div>
        </div>
        """

    # E-COMMERCE (3)
    elif header_id == "shop_cart_wishlist":
        content = f"""
        <div style="padding: 14px; display: flex; align-items: center; gap: 14px;">
            <div style="color: white; font-size: 20px; font-weight: 700;">🏪 ShopApp</div>
            <div style="flex: 1; background: rgba(255,255,255,0.2); border-radius: 20px; padding: 8px 12px;">
                <span style="color: rgba(255,255,255,0.9); font-size: 12px;">🔍 Search products...</span>
            </div>
            <div style="color: white; font-size: 20px;">❤️</div>
            <div style="position: relative; color: white; font-size: 20px;">
                🛒
                <div style="position: absolute; top: -6px; right: -6px; background: #FF3B30; border-radius: 50%; width: 16px; height: 16px; font-size: 9px; display: flex; align-items: center; justify-content: center; font-weight: 700;">5</div>
            </div>
        </div>
        """
    elif header_id == "category_filter_sort":
        content = f"""
        <div style="padding: 14px;">
            <div style="display: flex; gap: 8px; align-items: center;">
                <div style="flex: 1; background: rgba(255,255,255,0.2); color: white; border-radius: 20px; padding: 8px 12px; font-size: 12px; font-weight: 600;">
                    Electronics ▼
                </div>
                <div style="background: rgba(255,255,255,0.2); color: white; border-radius: 20px; padding: 8px 12px; font-size: 12px;">
                    🎚️ Filter
                </div>
                <div style="background: rgba(255,255,255,0.2); color: white; border-radius: 20px; padding: 8px 12px; font-size: 12px;">
                    ⬍ Sort
                </div>
            </div>
        </div>
        """
    elif header_id == "product_search_scan":
        content = f"""
        <div style="padding: 14px;">
            <div style="background: rgba(255,255,255,0.95); border-radius: 24px; padding: 10px 14px; display: flex; align-items: center; gap: 10px;">
                <span style="font-size: 18px;">🔍</span>
                <input style="border: none; background: transparent; flex: 1; font-size: 13px;" placeholder="Search products..."/>
                <span style="font-size: 18px; color: {primary};">📷</span>
                <span style="font-size: 18px; color: {primary};">🎤</span>
            </div>
        </div>
        """

    # FINANCE & WALLET (3)
    elif header_id == "wallet_balance_qr":
        content = f"""
        <div style="padding: 12px; display: flex; align-items: center; gap: 12px;">
            <div style="width: 44px; height: 44px; border-radius: 50%; background: white; display: flex; align-items: center; justify-content: center; font-size: 24px;">👤</div>
            <div style="flex: 1; color: white;">
                <div style="font-size: 11px; opacity: 0.8;">Total Balance</div>
                <div style="font-weight: 700; font-size: 20px;">$2,458.50</div>
            </div>
            <div style="background: white; padding: 8px; border-radius: 8px; font-size: 20px;">📱</div>
        </div>
        """
    elif header_id == "banking_accounts_menu":
        content = f"""
        <div style="padding: 14px; color: white;">
            <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 6px;">
                <div style="flex: 1; font-weight: 700; font-size: 13px;">Checking Account ▼</div>
                <div style="font-size: 22px;">☰</div>
            </div>
            <div style="font-size: 20px; font-weight: 700;">$12,345.67</div>
        </div>
        """
    elif header_id == "crypto_portfolio_refresh":
        content = f"""
        <div style="padding: 14px; color: white;">
            <div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px;">
                <div style="font-size: 11px; opacity: 0.8;">Portfolio Value</div>
                <div style="font-size: 18px;">🔄</div>
            </div>
            <div style="display: flex; align-items: baseline; gap: 10px;">
                <div style="font-size: 22px; font-weight: 700;">$45,678</div>
                <div style="font-size: 13px; color: #34C759;">+2.45% ↗</div>
            </div>
        </div>
        """

    # HEALTH & FITNESS (2)
    elif header_id == "fitness_streak_profile":
        content = f"""
        <div style="padding: 12px; display: flex; align-items: center; gap: 12px;">
            <div style="width: 48px; height: 48px; border-radius: 50%; background: white; display: flex; align-items: center; justify-content: center; font-size: 26px;">💪</div>
            <div style="flex: 1; color: white;">
                <div style="font-weight: 700; font-size: 15px;">Sarah's Fitness</div>
                <div style="font-size: 11px; opacity: 0.9;">🔥 7 day streak</div>
            </div>
            <div style="background: rgba(255,255,255,0.2); padding: 6px 10px; border-radius: 16px; font-size: 11px; color: white; font-weight: 600;">
                🏆 Level 12
            </div>
        </div>
        """
    elif header_id == "workout_timer_pause":
        content = f"""
        <div style="padding: 14px; text-align: center; color: white;">
            <div style="font-size: 11px; opacity: 0.8; margin-bottom: 4px;">WORKOUT IN PROGRESS</div>
            <div style="display: flex; justify-content: center; align-items: center; gap: 16px;">
                <div style="font-size: 20px;">⏭️</div>
                <div style="font-size: 28px; font-weight: 700;">12:34</div>
                <div style="font-size: 24px;">⏸️</div>
            </div>
        </div>
        """

    # MEDIA & ENTERTAINMENT (3)
    elif header_id == "video_player_controls":
        content = f"""
        <div style="padding: 14px; display: flex; align-items: center; gap: 12px;">
            <div style="color: white; font-size: 22px;">←</div>
            <div style="flex: 1; color: white;">
                <div style="font-weight: 600; font-size: 13px;">How to Code in Python</div>
                <div style="opacity: 0.8; font-size: 11px;">TechChannel • 1.2M views</div>
            </div>
            <div style="color: white; font-size: 20px;">📡</div>
            <div style="color: white; font-size: 20px;">⋮</div>
        </div>
        """
    elif header_id == "music_player_header":
        content = f"""
        <div style="padding: 16px; display: flex; align-items: center; gap: 12px;">
            <div style="color: white; font-size: 22px;">←</div>
            <div style="flex: 1; color: white; text-align: center;">
                <div style="font-weight: 700; font-size: 15px;">Blinding Lights</div>
                <div style="opacity: 0.8; font-size: 12px;">The Weeknd</div>
            </div>
            <div style="color: white; font-size: 22px;">❤️</div>
        </div>
        """
    elif header_id == "news_category_tabs":
        content = f"""
        <div style="padding: 12px; color: white;">
            <div style="font-size: 18px; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between;">
                <span>📰 NewsApp</span>
                <span style="font-size: 20px;">🔖</span>
            </div>
            <div style="display: flex; gap: 14px; font-size: 12px; font-weight: 600;">
                <span style="border-bottom: 2px solid white; padding-bottom: 4px;">Top</span>
                <span style="opacity: 0.6;">Tech</span>
                <span style="opacity: 0.6;">Sports</span>
                <span style="opacity: 0.6;">World</span>
            </div>
        </div>
        """
    else:
        content = "<div style='padding: 20px; color: white;'>Header Preview</div>"

    return f"""
    <div style="{base_style}">
        {content}
    </div>
    """


def render_footer_html(footer_id: str, footer_info: dict, primary: str, secondary: str, accent: str) -> str:
    """
    Generate HTML/CSS for a single footer preview (30 footer layouts)
    Returns HTML div with the footer rendered
    """
    footer_name = footer_info['name']

    # Common container style
    base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: visible; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: white;"

    # CLASSIC TAB BARS (6)
    if footer_id == "classic_4_icons":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 20px; border-top: 1px solid #eee;">
            <div style="color: {primary}; font-size: 24px;">🏠</div>
            <div style="color: #999; font-size: 24px;">🔍</div>
            <div style="color: #999; font-size: 24px;">❤️</div>
            <div style="color: #999; font-size: 24px;">👤</div>
        </div>
        """
    elif footer_id == "classic_5_icons":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 16px; border-top: 1px solid #eee;">
            <div style="text-align: center;">
                <div style="color: {primary}; font-size: 20px;">🏠</div>
                <div style="color: {primary}; font-size: 8px; margin-top: 2px; font-weight: 600;">Home</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 20px;">🔍</div>
                <div style="color: #999; font-size: 8px; margin-top: 2px;">Search</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 20px;">➕</div>
                <div style="color: #999; font-size: 8px; margin-top: 2px;">Add</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 20px;">❤️</div>
                <div style="color: #999; font-size: 8px; margin-top: 2px;">Likes</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 20px;">👤</div>
                <div style="color: #999; font-size: 8px; margin-top: 2px;">Profile</div>
            </div>
        </div>
        """
    elif footer_id == "compact_icons_badge":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 24px; border-top: 1px solid #eee;">
            <div style="color: {primary}; font-size: 22px;">🏠</div>
            <div style="color: #999; font-size: 22px;">🔍</div>
            <div style="position: relative; color: #999; font-size: 22px;">
                🔔
                <div style="position: absolute; top: -4px; right: -4px; background: #FF3B30; border-radius: 50%; width: 12px; height: 12px; font-size: 8px; display: flex; align-items: center; justify-content: center; color: white; font-weight: 700;">5</div>
            </div>
            <div style="color: #999; font-size: 22px;">👤</div>
        </div>
        """
    elif footer_id == "labeled_vertical":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 20px; border-top: 2px solid #f0f0f0;">
            <div style="text-align: center;">
                <div style="color: {primary}; font-size: 24px; margin-bottom: 2px;">🏠</div>
                <div style="color: {primary}; font-size: 9px; font-weight: 700;">Home</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 24px; margin-bottom: 2px;">🔍</div>
                <div style="color: #999; font-size: 9px;">Explore</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 24px; margin-bottom: 2px;">❤️</div>
                <div style="color: #999; font-size: 9px;">Saved</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 24px; margin-bottom: 2px;">👤</div>
                <div style="color: #999; font-size: 9px;">Profile</div>
            </div>
        </div>
        """
    elif footer_id == "colored_active":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 16px; border-top: 1px solid #eee;">
            <div style="background: {primary}; color: white; padding: 8px 16px; border-radius: 20px; font-size: 18px;">🏠</div>
            <div style="color: #999; font-size: 22px;">🔍</div>
            <div style="color: #999; font-size: 22px;">❤️</div>
            <div style="color: #999; font-size: 22px;">👤</div>
        </div>
        """
    elif footer_id == "icon_label_inline":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 12px; border-top: 1px solid #eee;">
            <div style="display: flex; align-items: center; gap: 6px; color: {primary};">
                <span style="font-size: 18px;">🏠</span>
                <span style="font-size: 11px; font-weight: 600;">Home</span>
            </div>
            <div style="display: flex; align-items: center; gap: 6px; color: #999;">
                <span style="font-size: 18px;">🔍</span>
                <span style="font-size: 11px;">Search</span>
            </div>
            <div style="color: #999; font-size: 18px;">❤️</div>
            <div style="color: #999; font-size: 18px;">👤</div>
        </div>
        """

    # FLOATING & FAB STYLES (5)
    elif footer_id == "floating_rounded":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: visible; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: transparent;"
        content = f"""
        <div style="position: absolute; bottom: 8px; left: 16px; right: 16px; background: white; border-radius: 24px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); height: 56px; display: flex; justify-content: space-around; align-items: center; padding: 0 16px;">
            <div style="color: {primary}; font-size: 22px;">🏠</div>
            <div style="color: #999; font-size: 22px;">🔍</div>
            <div style="color: #999; font-size: 22px;">❤️</div>
            <div style="color: #999; font-size: 22px;">👤</div>
        </div>
        """
    elif footer_id == "floating_fab_center":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: visible; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: transparent;"
        content = f"""
        <div style="position: absolute; bottom: 8px; left: 16px; right: 16px; background: white; border-radius: 24px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); height: 56px; display: flex; justify-content: space-around; align-items: center; padding: 0 16px; position: relative;">
            <div style="color: #999; font-size: 20px;">🏠</div>
            <div style="color: #999; font-size: 20px;">🔍</div>
            <div style="width: 54px; height: 54px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 28px; position: absolute; left: 50%; transform: translateX(-50%) translateY(-50%); box-shadow: 0 4px 12px rgba(0,0,0,0.2); top: 0;">+</div>
            <div style="color: #999; font-size: 20px;">❤️</div>
            <div style="color: #999; font-size: 20px;">👤</div>
        </div>
        """
    elif footer_id == "floating_translucent":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: visible; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: transparent;"
        content = f"""
        <div style="position: absolute; bottom: 8px; left: 16px; right: 16px; background: rgba(255,255,255,0.85); backdrop-filter: blur(10px); border-radius: 24px; box-shadow: 0 4px 16px rgba(0,0,0,0.1); height: 56px; display: flex; justify-content: space-around; align-items: center; padding: 0 16px; border: 1px solid rgba(255,255,255,0.3);">
            <div style="color: {primary}; font-size: 22px;">🏠</div>
            <div style="color: #999; font-size: 22px;">🔍</div>
            <div style="color: #999; font-size: 22px;">❤️</div>
            <div style="color: #999; font-size: 22px;">👤</div>
        </div>
        """
    elif footer_id == "floating_pills_bar":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: visible; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: transparent;"
        content = f"""
        <div style="position: absolute; bottom: 8px; left: 16px; right: 16px; background: white; border-radius: 28px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); height: 56px; display: flex; justify-content: space-around; align-items: center; padding: 0 12px;">
            <div style="background: {primary}; color: white; padding: 8px 12px; border-radius: 18px; font-size: 11px; font-weight: 600;">🏠 Home</div>
            <div style="color: #999; font-size: 20px;">🔍</div>
            <div style="color: #999; font-size: 20px;">❤️</div>
            <div style="color: #999; font-size: 20px;">👤</div>
        </div>
        """
    elif footer_id == "dual_fab":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: visible; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: transparent;"
        content = f"""
        <div style="position: absolute; bottom: 8px; left: 16px; right: 16px; display: flex; justify-content: space-between; align-items: center;">
            <div style="width: 50px; height: 50px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px; box-shadow: 0 4px 12px rgba(0,0,0,0.2);">🏠</div>
            <div style="width: 50px; height: 50px; border-radius: 50%; background: {secondary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px; box-shadow: 0 4px 12px rgba(0,0,0,0.2);">+</div>
        </div>
        """

    # CURVED & SHAPED DESIGNS (5)
    elif footer_id == "curved_top":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: white;"
        content = f"""
        <div style="position: absolute; top: -20px; left: 0; right: 0; height: 90px; background: white; border-radius: 50% 50% 0 0 / 40px 40px 0 0;">
            <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 24px 20px 0;">
                <div style="color: {primary}; font-size: 22px;">🏠</div>
                <div style="color: #999; font-size: 22px;">🔍</div>
                <div style="color: #999; font-size: 22px;">❤️</div>
                <div style="color: #999; font-size: 22px;">👤</div>
            </div>
        </div>
        """
    elif footer_id == "notched_center":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: visible; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: white;"
        content = f"""
        <div style="position: relative; height: 100%; display: flex; justify-content: space-around; align-items: center; padding: 0 20px;">
            <div style="position: absolute; top: -10px; left: 50%; transform: translateX(-50%); width: 60px; height: 30px; background: white; border-radius: 30px 30px 0 0;"></div>
            <div style="color: #999; font-size: 20px;">🏠</div>
            <div style="color: #999; font-size: 20px;">🔍</div>
            <div style="width: 50px; height: 50px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 28px; position: absolute; left: 50%; transform: translateX(-50%) translateY(-50%); box-shadow: 0 4px 12px rgba(0,0,0,0.2); top: 0;">+</div>
            <div style="color: #999; font-size: 20px;">❤️</div>
            <div style="color: #999; font-size: 20px;">👤</div>
        </div>
        """
    elif footer_id == "wave_top":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: white;"
        content = f"""
        <svg style="position: absolute; top: -15px; left: 0; width: 100%; height: 20px;" viewBox="0 0 300 20" preserveAspectRatio="none">
            <path d="M0,10 Q75,0 150,10 T300,10 L300,20 L0,20 Z" fill="white"/>
        </svg>
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 20px;">
            <div style="color: {primary}; font-size: 22px;">🏠</div>
            <div style="color: #999; font-size: 22px;">🔍</div>
            <div style="color: #999; font-size: 22px;">❤️</div>
            <div style="color: #999; font-size: 22px;">👤</div>
        </div>
        """
    elif footer_id == "island_bar":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: visible; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: transparent;"
        content = f"""
        <div style="position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); background: white; border-radius: 28px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); height: 52px; display: flex; justify-content: space-around; align-items: center; padding: 0 24px; gap: 28px;">
            <div style="color: {primary}; font-size: 22px;">🏠</div>
            <div style="color: #999; font-size: 22px;">🔍</div>
            <div style="color: #999; font-size: 22px;">❤️</div>
            <div style="color: #999; font-size: 22px;">👤</div>
        </div>
        """
    elif footer_id == "arc_active":
        base_style = "width: 300px; height: 70px; border-radius: 0 0 12px 12px; position: relative; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.15); background: white;"
        content = f"""
        <div style="position: absolute; top: 0; left: 20px; width: 52px; height: 4px; background: {primary}; border-radius: 0 0 4px 4px;"></div>
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 20px;">
            <div style="color: {primary}; font-size: 22px;">🏠</div>
            <div style="color: #999; font-size: 22px;">🔍</div>
            <div style="color: #999; font-size: 22px;">❤️</div>
            <div style="color: #999; font-size: 22px;">👤</div>
        </div>
        """

    # SEGMENTED & PILLS (5)
    elif footer_id == "segmented_control":
        content = f"""
        <div style="display: flex; justify-content: center; align-items: center; height: 100%; padding: 0 16px;">
            <div style="background: #f0f0f0; border-radius: 24px; padding: 4px; display: flex; gap: 4px;">
                <div style="background: {primary}; color: white; padding: 8px 20px; border-radius: 20px; font-size: 11px; font-weight: 600;">Home</div>
                <div style="background: transparent; color: #666; padding: 8px 20px; border-radius: 20px; font-size: 11px; font-weight: 600;">Search</div>
                <div style="background: transparent; color: #666; padding: 8px 20px; border-radius: 20px; font-size: 11px; font-weight: 600;">Profile</div>
            </div>
        </div>
        """
    elif footer_id == "pill_buttons":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 12px;">
            <div style="background: {primary}; color: white; padding: 10px 16px; border-radius: 22px; font-size: 12px; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">🏠 Home</div>
            <div style="background: #f5f5f5; color: #666; padding: 10px 16px; border-radius: 22px; font-size: 12px; font-weight: 600;">🔍</div>
            <div style="background: #f5f5f5; color: #666; padding: 10px 16px; border-radius: 22px; font-size: 12px; font-weight: 600;">👤</div>
        </div>
        """
    elif footer_id == "grouped_pills":
        content = f"""
        <div style="display: flex; justify-content: center; align-items: center; height: 100%; padding: 0 16px;">
            <div style="background: #f8f8f8; border-radius: 26px; padding: 6px 8px; display: flex; gap: 8px;">
                <div style="background: {primary}; color: white; padding: 8px 16px; border-radius: 20px; font-size: 11px; font-weight: 600;">🏠</div>
                <div style="color: #666; padding: 8px 16px; font-size: 18px;">🔍</div>
                <div style="color: #666; padding: 8px 16px; font-size: 18px;">❤️</div>
                <div style="color: #666; padding: 8px 16px; font-size: 18px;">👤</div>
            </div>
        </div>
        """
    elif footer_id == "slider_nav":
        content = f"""
        <div style="position: relative; height: 100%; border-top: 1px solid #eee;">
            <div style="position: absolute; bottom: 0; left: 20px; width: 52px; height: 3px; background: {primary}; border-radius: 3px 3px 0 0;"></div>
            <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 20px;">
                <div style="color: {primary}; font-size: 22px;">🏠</div>
                <div style="color: #999; font-size: 22px;">🔍</div>
                <div style="color: #999; font-size: 22px;">❤️</div>
                <div style="color: #999; font-size: 22px;">👤</div>
            </div>
        </div>
        """
    elif footer_id == "morphing_pills":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 12px; background: #fafafa;">
            <div style="background: {primary}; color: white; padding: 10px 18px; border-radius: 24px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 6px;">🏠 Home</div>
            <div style="color: #999; font-size: 20px; padding: 8px;">🔍</div>
            <div style="color: #999; font-size: 20px; padding: 8px;">❤️</div>
            <div style="color: #999; font-size: 20px; padding: 8px;">👤</div>
        </div>
        """

    # MINIMALIST & GESTURE (4)
    elif footer_id == "minimal_dots":
        content = f"""
        <div style="display: flex; justify-content: center; align-items: center; height: 100%; gap: 12px;">
            <div style="width: 8px; height: 8px; border-radius: 50%; background: {primary};"></div>
            <div style="width: 6px; height: 6px; border-radius: 50%; background: #ddd;"></div>
            <div style="width: 6px; height: 6px; border-radius: 50%; background: #ddd;"></div>
            <div style="width: 6px; height: 6px; border-radius: 50%; background: #ddd;"></div>
        </div>
        """
    elif footer_id == "gesture_swipe":
        content = f"""
        <div style="display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%; gap: 4px; background: rgba(250,250,250,0.95);">
            <div style="width: 40px; height: 4px; background: #ccc; border-radius: 2px;"></div>
            <div style="font-size: 8px; color: #999; text-transform: uppercase; letter-spacing: 0.5px;">Swipe</div>
        </div>
        """
    elif footer_id == "thin_bar":
        content = f"""
        <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 30px; border-top: 1px solid #f0f0f0;">
            <div style="width: 24px; height: 3px; background: {primary}; border-radius: 2px;"></div>
            <div style="width: 18px; height: 3px; background: #ddd; border-radius: 2px;"></div>
            <div style="width: 18px; height: 3px; background: #ddd; border-radius: 2px;"></div>
            <div style="width: 18px; height: 3px; background: #ddd; border-radius: 2px;"></div>
        </div>
        """
    elif footer_id == "invisible_tap":
        content = f"""
        <div style="position: relative; height: 100%; border-top: 1px solid #f8f8f8;">
            <div style="position: absolute; top: 0; left: 20px; width: 52px; height: 2px; background: {primary};"></div>
            <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 20px; opacity: 0.3;">
                <div style="font-size: 18px;">🏠</div>
                <div style="font-size: 18px;">🔍</div>
                <div style="font-size: 18px;">❤️</div>
                <div style="font-size: 18px;">👤</div>
            </div>
        </div>
        """

    # ADVANCED & INTERACTIVE (5)
    elif footer_id == "expandable_drawer":
        content = f"""
        <div style="position: relative; height: 100%; background: white; border-top: 1px solid #eee;">
            <div style="display: flex; justify-content: center; padding-top: 6px;">
                <div style="width: 40px; height: 4px; background: #ddd; border-radius: 2px;"></div>
            </div>
            <div style="display: flex; justify-content: space-around; align-items: center; padding: 8px 20px;">
                <div style="color: {primary}; font-size: 20px;">🏠</div>
                <div style="color: #999; font-size: 20px;">🔍</div>
                <div style="color: #999; font-size: 20px;">❤️</div>
                <div style="color: #999; font-size: 20px;">☰</div>
            </div>
        </div>
        """
    elif footer_id == "grid_menu":
        content = f"""
        <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 12px 16px; background: #fafafa; border-top: 1px solid #eee;">
            <div style="text-align: center;">
                <div style="color: {primary}; font-size: 18px;">🏠</div>
                <div style="font-size: 7px; color: {primary}; margin-top: 2px; font-weight: 600;">Home</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 18px;">🔍</div>
                <div style="font-size: 7px; color: #999; margin-top: 2px;">Search</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 18px;">❤️</div>
                <div style="font-size: 7px; color: #999; margin-top: 2px;">Saved</div>
            </div>
            <div style="text-align: center;">
                <div style="color: #999; font-size: 18px;">👤</div>
                <div style="font-size: 7px; color: #999; margin-top: 2px;">Profile</div>
            </div>
        </div>
        """
    elif footer_id == "carousel_nav":
        content = f"""
        <div style="display: flex; align-items: center; height: 100%; padding: 0 12px; gap: 8px; overflow-x: auto; border-top: 1px solid #eee;">
            <div style="background: {primary}; color: white; padding: 8px 14px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap;">🏠 Home</div>
            <div style="background: #f5f5f5; color: #666; padding: 8px 14px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap;">🔍 Search</div>
            <div style="background: #f5f5f5; color: #666; padding: 8px 14px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap;">❤️ Saved</div>
            <div style="background: #f5f5f5; color: #666; padding: 8px 14px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap;">👤 Profile</div>
        </div>
        """
    elif footer_id == "context_aware":
        content = f"""
        <div style="position: relative; height: 100%; background: rgba(255,255,255,0.9); backdrop-filter: blur(10px); border-top: 1px solid rgba(0,0,0,0.05);">
            <div style="display: flex; justify-content: space-around; align-items: center; height: 100%; padding: 0 20px;">
                <div style="color: {primary}; font-size: 22px; opacity: 1;">🏠</div>
                <div style="color: #999; font-size: 18px; opacity: 0.6;">🔍</div>
                <div style="color: #999; font-size: 18px; opacity: 0.6;">❤️</div>
                <div style="color: #999; font-size: 18px; opacity: 0.6;">👤</div>
            </div>
        </div>
        """
    elif footer_id == "nested_menu":
        content = f"""
        <div style="position: relative; height: 100%; background: white; border-top: 1px solid #eee;">
            <div style="display: flex; justify-content: space-around; align-items: flex-start; padding: 6px 16px;">
                <div style="text-align: center;">
                    <div style="color: {primary}; font-size: 20px;">🏠</div>
                    <div style="font-size: 7px; color: {primary}; margin-top: 2px; font-weight: 600;">Home</div>
                    <div style="display: flex; gap: 2px; margin-top: 2px; justify-content: center;">
                        <div style="width: 3px; height: 3px; border-radius: 50%; background: {primary};"></div>
                        <div style="width: 3px; height: 3px; border-radius: 50%; background: {primary}; opacity: 0.3;"></div>
                    </div>
                </div>
                <div style="text-align: center;">
                    <div style="color: #999; font-size: 20px;">🔍</div>
                    <div style="font-size: 7px; color: #999; margin-top: 2px;">Explore</div>
                </div>
                <div style="text-align: center;">
                    <div style="color: #999; font-size: 20px;">❤️</div>
                    <div style="font-size: 7px; color: #999; margin-top: 2px;">Saved</div>
                </div>
                <div style="text-align: center;">
                    <div style="color: #999; font-size: 20px;">👤</div>
                    <div style="font-size: 7px; color: #999; margin-top: 2px;">Profile</div>
                </div>
            </div>
        </div>
        """
    else:
        content = "<div style='padding: 20px; color: #333;'>Footer Preview</div>"

    return f"""
    <div style="{base_style}">
        {content}
    </div>
    """


def render_card_html(card_id: str, card_info: dict, primary: str, secondary: str, accent: str) -> str:
    """
    Generate HTML/CSS for a single card preview (30 card types)
    Returns HTML div with the card rendered
    """
    card_name = card_info['name']

    # Common container style - responsive with max-width
    base_style = "width: 100%; max-width: 180px; min-height: 240px; border-radius: 12px; position: relative; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; display: flex; flex-direction: column;"

    # PRODUCT & SHOPPING (6)
    if card_id == "product_vertical":
        content = f"""
        <div style="background: #f5f5f5; height: 140px; display: flex; align-items: center; justify-content: center; font-size: 48px;">📱</div>
        <div style="padding: 12px; flex: 1; display: flex; flex-direction: column; gap: 6px;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Product Name</div>
            <div style="font-size: 11px; color: #666;">Short description</div>
            <div style="margin-top: auto; font-weight: 700; font-size: 16px; color: {primary};">$99.00</div>
        </div>
        """
    elif card_id == "product_horizontal":
        base_style = "width: 100%; max-width: 280px; height: 100px; border-radius: 12px; position: relative; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; display: flex;"
        content = f"""
        <div style="width: 100px; min-width: 100px; background: #f5f5f5; display: flex; align-items: center; justify-content: center; font-size: 36px;">📱</div>
        <div style="padding: 12px; flex: 1; display: flex; flex-direction: column; justify-content: space-between;">
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333;">Product Name</div>
                <div style="font-size: 10px; color: #666;">Category</div>
            </div>
            <div style="font-weight: 700; font-size: 14px; color: {primary};">$99.00</div>
        </div>
        """
    elif card_id == "product_badge":
        content = f"""
        <div style="position: relative; background: #f5f5f5; height: 140px; display: flex; align-items: center; justify-content: center; font-size: 48px;">
            📱
            <div style="position: absolute; top: 8px; right: 8px; background: #FF3B30; color: white; padding: 4px 10px; border-radius: 12px; font-size: 10px; font-weight: 700;">SALE</div>
        </div>
        <div style="padding: 12px; flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Product Name</div>
            <div style="display: flex; align-items: center; gap: 8px;">
                <div style="font-weight: 700; font-size: 16px; color: {primary};">$79.00</div>
                <div style="font-size: 12px; color: #999; text-decoration: line-through;">$99.00</div>
            </div>
        </div>
        """
    elif card_id == "product_rating":
        content = f"""
        <div style="background: #f5f5f5; height: 140px; display: flex; align-items: center; justify-content: center; font-size: 48px;">📱</div>
        <div style="padding: 12px; flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 6px;">Product Name</div>
            <div style="display: flex; align-items: center; gap: 4px; margin-bottom: 8px;">
                <span style="color: #FFB800;">⭐⭐⭐⭐⭐</span>
                <span style="font-size: 10px; color: #666;">(245)</span>
            </div>
            <div style="font-weight: 700; font-size: 16px; color: {primary};">$99.00</div>
        </div>
        """
    elif card_id == "product_grid_compact":
        base_style = "width: 100%; max-width: 140px; min-height: 180px; border-radius: 12px; position: relative; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; display: flex; flex-direction: column;"
        content = f"""
        <div style="background: #f5f5f5; height: 120px; display: flex; align-items: center; justify-content: center; font-size: 40px;">📱</div>
        <div style="padding: 8px;">
            <div style="font-weight: 600; font-size: 11px; color: #333; margin-bottom: 4px;">Item</div>
            <div style="font-weight: 700; font-size: 13px; color: {primary};">$99</div>
        </div>
        """
    elif card_id == "product_featured":
        base_style = "width: 100%; max-width: 280px; height: 200px; border-radius: 12px; position: relative; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: linear-gradient(135deg, {primary}, {secondary});"
        content = f"""
        <div style="position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; padding: 16px; background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);">
            <div style="color: white; font-size: 11px; opacity: 0.9; margin-bottom: 4px;">FEATURED</div>
            <div style="color: white; font-weight: 700; font-size: 18px; margin-bottom: 4px;">Premium Product</div>
            <div style="color: white; font-size: 20px; font-weight: 700;">$199.00</div>
        </div>
        """

    # PROFILE & SOCIAL (5)
    elif card_id == "profile_user_card":
        content = f"""
        <div style="padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 10px;">
            <div style="width: 64px; height: 64px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 32px;">👤</div>
            <div style="text-align: center;">
                <div style="font-weight: 700; font-size: 14px; color: #333;">John Doe</div>
                <div style="font-size: 11px; color: #666; margin-top: 2px;">@johndoe</div>
            </div>
            <div style="font-size: 11px; color: #666; text-align: center;">Creative designer & developer passionate about UI/UX</div>
            <button style="background: {primary}; color: white; border: none; padding: 8px 24px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-top: 4px;">Follow</button>
        </div>
        """
    elif card_id == "profile_stats_card":
        content = f"""
        <div style="padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 10px;">
            <div style="width: 60px; height: 60px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 30px;">👤</div>
            <div style="text-align: center;">
                <div style="font-weight: 700; font-size: 14px; color: #333;">Sarah Smith</div>
                <div style="font-size: 10px; color: #666;">Product Designer</div>
            </div>
            <div style="display: flex; gap: 16px; margin-top: 4px;">
                <div style="text-align: center;">
                    <div style="font-weight: 700; font-size: 14px; color: #333;">2.5K</div>
                    <div style="font-size: 9px; color: #666;">Followers</div>
                </div>
                <div style="text-align: center;">
                    <div style="font-weight: 700; font-size: 14px; color: #333;">856</div>
                    <div style="font-size: 9px; color: #666;">Posts</div>
                </div>
                <div style="text-align: center;">
                    <div style="font-weight: 700; font-size: 14px; color: #333;">12K</div>
                    <div style="font-size: 9px; color: #666;">Likes</div>
                </div>
            </div>
        </div>
        """
    elif card_id == "social_post_card":
        base_style = "width: 100%; max-width: 280px; min-height: 280px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="padding: 12px; display: flex; align-items: center; gap: 10px;">
            <div style="width: 40px; height: 40px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px;">👤</div>
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333;">Jane Cooper</div>
                <div style="font-size: 10px; color: #666;">2 hours ago</div>
            </div>
        </div>
        <div style="padding: 0 12px 12px; font-size: 12px; color: #333;">Just launched my new project! 🚀 Check it out!</div>
        <div style="background: #f0f0f0; height: 140px; display: flex; align-items: center; justify-content: center; font-size: 48px;">🎨</div>
        <div style="padding: 12px; display: flex; gap: 16px; border-top: 1px solid #eee; font-size: 11px; color: #666;">
            <span>❤️ 245</span>
            <span>💬 32</span>
            <span>📤 12</span>
        </div>
        """
    elif card_id == "social_story_card":
        base_style = "width: 100%; max-width: 100px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); position: relative;"
        content = f"""
        <div style="position: absolute; inset: 2px; border-radius: 10px; background: linear-gradient(135deg, {primary}, {secondary}); display: flex; align-items: center; justify-content: center; color: white; font-size: 40px;">👤</div>
        <div style="position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; color: white; font-size: 10px; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,0.5);">Sarah</div>
        """
    elif card_id == "contact_card":
        content = f"""
        <div style="padding: 16px; display: flex; flex-direction: column; gap: 10px;">
            <div style="display: flex; align-items: center; gap: 12px;">
                <div style="width: 50px; height: 50px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px;">👤</div>
                <div style="flex: 1;">
                    <div style="font-weight: 700; font-size: 13px; color: #333;">Mike Johnson</div>
                    <div style="font-size: 10px; color: #666;">Software Engineer</div>
                </div>
            </div>
            <div style="display: flex; flex-direction: column; gap: 6px; font-size: 11px;">
                <div style="display: flex; align-items: center; gap: 6px; color: #666;">
                    <span>📧</span>
                    <span>mike@email.com</span>
                </div>
                <div style="display: flex; align-items: center; gap: 6px; color: #666;">
                    <span>📱</span>
                    <span>+1 234 567 8900</span>
                </div>
            </div>
            <div style="display: flex; gap: 8px; margin-top: 4px;">
                <button style="flex: 1; background: {primary}; color: white; border: none; padding: 8px; border-radius: 8px; font-size: 11px; font-weight: 600;">Message</button>
                <button style="flex: 1; background: #f0f0f0; color: #333; border: none; padding: 8px; border-radius: 8px; font-size: 11px; font-weight: 600;">Call</button>
            </div>
        </div>
        """

    # CONTENT & MEDIA (5)
    elif card_id == "article_card":
        base_style = "width: 100%; max-width: 280px; min-height: 260px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: #f0f0f0; height: 140px; display: flex; align-items: center; justify-content: center; font-size: 48px;">📰</div>
        <div style="padding: 14px;">
            <div style="font-size: 10px; color: {primary}; font-weight: 600; margin-bottom: 6px;">TECHNOLOGY</div>
            <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 8px;">The Future of AI in Design</div>
            <div style="font-size: 11px; color: #666; line-height: 1.4; margin-bottom: 10px;">Discover how artificial intelligence is revolutionizing the creative industry...</div>
            <div style="font-size: 10px; color: #999;">⏱️ 5 min read</div>
        </div>
        """
    elif card_id == "video_card":
        base_style = "width: 100%; max-width: 280px; height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); position: relative;"
        content = f"""
        <div style="position: absolute; inset: 0; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; align-items: center; justify-content: center; color: white; font-size: 64px;">▶️</div>
        <div style="position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,0.7); color: white; padding: 4px 8px; border-radius: 6px; font-size: 10px; font-weight: 600;">12:45</div>
        <div style="position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); padding: 12px; color: white;">
            <div style="font-weight: 700; font-size: 13px;">How to Build Apps</div>
            <div style="font-size: 10px; opacity: 0.9; margin-top: 2px;">12K views • 2 days ago</div>
        </div>
        """
    elif card_id == "podcast_card":
        base_style = "width: 100%; max-width: 280px; height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; display: flex;"
        content = f"""
        <div style="width: 120px; background: linear-gradient(135deg, {primary}, {secondary}); display: flex; align-items: center; justify-content: center; font-size: 48px; color: white;">🎙️</div>
        <div style="flex: 1; padding: 12px; display: flex; flex-direction: column; justify-content: space-between;">
            <div>
                <div style="font-weight: 700; font-size: 12px; color: #333;">Tech Talk #42</div>
                <div style="font-size: 10px; color: #666; margin-top: 2px;">The Future of Web3</div>
            </div>
            <div style="display: flex; align-items: center; gap: 8px;">
                <button style="width: 32px; height: 32px; border-radius: 50%; background: {primary}; color: white; border: none; display: flex; align-items: center; justify-content: center; font-size: 12px;">▶️</button>
                <div style="font-size: 10px; color: #666;">45:30</div>
            </div>
        </div>
        """
    elif card_id == "news_headline":
        base_style = "width: 100%; max-width: 280px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; display: flex; gap: 12px; padding: 10px;"
        content = f"""
        <div style="width: 60px; height: 60px; border-radius: 8px; background: #f0f0f0; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 24px;">📰</div>
        <div style="flex: 1; display: flex; flex-direction: column; justify-content: space-between;">
            <div style="font-weight: 600; font-size: 12px; color: #333; line-height: 1.3;">Breaking: Major Tech Announcement Today</div>
            <div style="font-size: 9px; color: #999;">2 hours ago • Tech News</div>
        </div>
        """
    elif card_id == "blog_featured":
        base_style = "width: 100%; max-width: 280px; height: 240px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); position: relative;"
        content = f"""
        <div style="position: absolute; inset: 0; background: linear-gradient(135deg, {primary}, {secondary});"></div>
        <div style="position: absolute; top: 12px; left: 12px; background: white; color: {primary}; padding: 4px 10px; border-radius: 16px; font-size: 9px; font-weight: 700;">FEATURED</div>
        <div style="position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); padding: 16px; color: white;">
            <div style="font-size: 10px; opacity: 0.9; margin-bottom: 4px;">DESIGN</div>
            <div style="font-weight: 700; font-size: 16px; margin-bottom: 4px;">Creating Beautiful User Experiences</div>
            <div style="font-size: 10px; opacity: 0.8;">by Sarah Johnson • 8 min read</div>
        </div>
        """

    # STATS & ANALYTICS (4)
    elif card_id == "stats_metric":
        base_style = "width: 100%; max-width: 160px; height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; justify-content: space-between;"
        content = f"""
        <div style="width: 40px; height: 40px; border-radius: 10px; background: {primary}20; color: {primary}; display: flex; align-items: center; justify-content: center; font-size: 20px;">📊</div>
        <div>
            <div style="font-size: 24px; font-weight: 700; color: #333; margin-bottom: 2px;">2,458</div>
            <div style="font-size: 11px; color: #666;">Total Sales</div>
            <div style="font-size: 10px; color: #34C759; font-weight: 600; margin-top: 4px;">↗ +12.5%</div>
        </div>
        """
    elif card_id == "stats_comparison":
        base_style = "width: 100%; max-width: 240px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; gap: 16px;"
        content = f"""
        <div style="flex: 1; text-align: center;">
            <div style="font-size: 20px; font-weight: 700; color: #333;">1,234</div>
            <div style="font-size: 10px; color: #666; margin-top: 2px;">This Month</div>
            <div style="font-size: 10px; color: #34C759; font-weight: 600; margin-top: 4px;">↗ +18%</div>
        </div>
        <div style="width: 1px; background: #eee;"></div>
        <div style="flex: 1; text-align: center;">
            <div style="font-size: 20px; font-weight: 700; color: #333;">1,045</div>
            <div style="font-size: 10px; color: #666; margin-top: 2px;">Last Month</div>
            <div style="font-size: 10px; color: #666; font-weight: 600; margin-top: 4px;">— 0%</div>
        </div>
        """
    elif card_id == "stats_progress":
        base_style = "width: 100%; max-width: 200px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; justify-content: space-between;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: center;">
            <div style="font-weight: 600; font-size: 12px; color: #333;">Goal Progress</div>
            <div style="font-weight: 700; font-size: 14px; color: {primary};">75%</div>
        </div>
        <div>
            <div style="height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden;">
                <div style="width: 75%; height: 100%; background: {primary}; border-radius: 4px;"></div>
            </div>
            <div style="font-size: 10px; color: #666; margin-top: 6px;">750 / 1000 completed</div>
        </div>
        """
    elif card_id == "stats_chart":
        base_style = "width: 100%; max-width: 200px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Weekly Stats</div>
        <div style="font-size: 10px; color: #666; margin-bottom: 12px;">Last 7 days</div>
        <div style="display: flex; align-items: flex-end; gap: 6px; height: 60px;">
            <div style="flex: 1; background: {primary}; opacity: 0.4; height: 40%; border-radius: 4px 4px 0 0;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.6; height: 60%; border-radius: 4px 4px 0 0;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.5; height: 50%; border-radius: 4px 4px 0 0;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.8; height: 80%; border-radius: 4px 4px 0 0;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.9; height: 90%; border-radius: 4px 4px 0 0;"></div>
            <div style="flex: 1; background: {primary}; height: 100%; border-radius: 4px 4px 0 0;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.7; height: 70%; border-radius: 4px 4px 0 0;"></div>
        </div>
        """

    # MESSAGING & NOTIFICATIONS (4)
    elif card_id == "message_preview":
        base_style = "width: 100%; max-width: 280px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; display: flex; align-items: center; gap: 12px; padding: 12px;"
        content = f"""
        <div style="width: 48px; height: 48px; border-radius: 50%; background: {primary}; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px;">👤</div>
        <div style="flex: 1; min-width: 0;">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px;">
                <div style="font-weight: 700; font-size: 13px; color: #333;">Alice Brown</div>
                <div style="font-size: 9px; color: #999;">2m</div>
            </div>
            <div style="font-size: 11px; color: #666; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">Hey! Did you see the new design?</div>
        </div>
        <div style="width: 8px; height: 8px; border-radius: 50%; background: {primary}; flex-shrink: 0;"></div>
        """
    elif card_id == "notification_card":
        content = f"""
        <div style="padding: 14px; display: flex; gap: 12px;">
            <div style="width: 40px; height: 40px; border-radius: 50%; background: {primary}20; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: {primary}; font-size: 20px;">🔔</div>
            <div style="flex: 1;">
                <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 4px;">
                    <div style="font-weight: 700; font-size: 12px; color: #333;">New Message</div>
                    <div style="width: 6px; height: 6px; border-radius: 50%; background: {primary};"></div>
                </div>
                <div style="font-size: 11px; color: #666; line-height: 1.4; margin-bottom: 6px;">You have a new message from the support team</div>
                <div style="font-size: 9px; color: #999;">5 minutes ago</div>
            </div>
        </div>
        """
    elif card_id == "alert_card":
        base_style = "width: 100%; max-width: 280px; min-height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: #FFF3CD; border: 1px solid #FFE69C;"
        content = f"""
        <div style="padding: 14px; display: flex; gap: 12px; align-items: start;">
            <div style="font-size: 20px;">⚠️</div>
            <div style="flex: 1;">
                <div style="font-weight: 700; font-size: 12px; color: #856404; margin-bottom: 4px;">Warning</div>
                <div style="font-size: 11px; color: #856404;">Your storage is almost full. Please free up some space.</div>
            </div>
            <button style="background: transparent; border: none; color: #856404; font-size: 16px; cursor: pointer;">×</button>
        </div>
        """
    elif card_id == "chat_bubble":
        base_style = "width: 100%; max-width: 220px; min-height: 60px; border-radius: 16px 16px 16px 4px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: {primary}; padding: 12px; position: relative;"
        content = f"""
        <div style="color: white; font-size: 12px; line-height: 1.4; margin-bottom: 4px;">Hey! How are you doing? I wanted to check in about the project.</div>
        <div style="text-align: right; font-size: 9px; color: rgba(255,255,255,0.8);">2:45 PM</div>
        """

    # SPECIAL CARDS (6)
    elif card_id == "pricing_plan":
        base_style = "width: 100%; max-width: 200px; min-height: 280px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; border: 2px solid #eee;"
        content = f"""
        <div style="padding: 20px; text-align: center; background: {primary}10;">
            <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 8px;">Pro Plan</div>
            <div style="font-size: 32px; font-weight: 700; color: {primary}; margin-bottom: 4px;">$29<span style="font-size: 14px; font-weight: 400;">/mo</span></div>
        </div>
        <div style="padding: 20px; display: flex; flex-direction: column; gap: 8px;">
            <div style="font-size: 11px; color: #666; display: flex; align-items: center; gap: 6px;">✓ 100 Projects</div>
            <div style="font-size: 11px; color: #666; display: flex; align-items: center; gap: 6px;">✓ Unlimited Storage</div>
            <div style="font-size: 11px; color: #666; display: flex; align-items: center; gap: 6px;">✓ Priority Support</div>
            <div style="font-size: 11px; color: #666; display: flex; align-items: center; gap: 6px;">✓ Analytics</div>
            <button style="width: 100%; background: {primary}; color: white; border: none; padding: 10px; border-radius: 8px; font-size: 12px; font-weight: 600; margin-top: 8px;">Get Started</button>
        </div>
        """
    elif card_id == "review_card":
        content = f"""
        <div style="padding: 16px;">
            <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
                <div style="width: 40px; height: 40px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px;">👤</div>
                <div style="flex: 1;">
                    <div style="font-weight: 700; font-size: 12px; color: #333;">Emily Davis</div>
                    <div style="color: #FFB800; font-size: 12px;">⭐⭐⭐⭐⭐</div>
                </div>
            </div>
            <div style="font-size: 11px; color: #666; line-height: 1.5; margin-bottom: 8px;">"Amazing product! Exceeded all my expectations. Highly recommend to anyone looking for quality."</div>
            <div style="font-size: 9px; color: #999;">2 days ago</div>
        </div>
        """
    elif card_id == "event_card":
        base_style = "width: 100%; max-width: 280px; height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; display: flex;"
        content = f"""
        <div style="width: 80px; background: {primary}; color: white; display: flex; flex-direction: column; align-items: center; justify-content: center;">
            <div style="font-size: 28px; font-weight: 700;">24</div>
            <div style="font-size: 11px; opacity: 0.9;">DEC</div>
        </div>
        <div style="flex: 1; padding: 14px; display: flex; flex-direction: column; justify-content: space-between;">
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Tech Conference 2024</div>
                <div style="font-size: 10px; color: #666; display: flex; align-items: center; gap: 4px;">📍 San Francisco, CA</div>
            </div>
            <div style="font-size: 10px; color: #666;">👥 245 attending</div>
        </div>
        """
    elif card_id == "offer_coupon":
        base_style = "width: 100%; max-width: 260px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; border: 2px dashed {primary}; position: relative;"
        content = f"""
        <div style="padding: 20px; text-align: center;">
            <div style="font-size: 10px; color: {primary}; font-weight: 600; margin-bottom: 8px;">SPECIAL OFFER</div>
            <div style="font-size: 32px; font-weight: 700; color: {primary}; margin-bottom: 4px;">25% OFF</div>
            <div style="font-size: 11px; color: #666; margin-bottom: 12px;">On your next purchase</div>
            <div style="background: {primary}10; padding: 8px 16px; border-radius: 8px; display: inline-block;">
                <div style="font-size: 10px; color: #666; margin-bottom: 2px;">Code:</div>
                <div style="font-weight: 700; font-size: 14px; color: {primary}; letter-spacing: 1px;">SAVE25</div>
            </div>
            <div style="font-size: 9px; color: #999; margin-top: 8px;">Expires in 3 days</div>
        </div>
        """
    elif card_id == "weather_card":
        base_style = "width: 100%; max-width: 200px; height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: linear-gradient(135deg, {primary}, {secondary}); color: white; padding: 20px;"
        content = f"""
        <div style="text-align: center;">
            <div style="font-size: 12px; opacity: 0.9; margin-bottom: 8px;">San Francisco</div>
            <div style="font-size: 64px; margin-bottom: 8px;">☀️</div>
            <div style="font-size: 40px; font-weight: 700; margin-bottom: 4px;">72°</div>
            <div style="font-size: 11px; opacity: 0.9; margin-bottom: 16px;">Sunny</div>
            <div style="display: flex; justify-content: space-around; font-size: 10px;">
                <div>H: 78°</div>
                <div>L: 65°</div>
            </div>
        </div>
        """
    elif card_id == "ticket_card":
        base_style = "width: 100%; max-width: 280px; height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; position: relative;"
        content = f"""
        <div style="padding: 20px; padding-bottom: 16px;">
            <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 8px;">Concert Night 2024</div>
            <div style="font-size: 11px; color: #666; margin-bottom: 4px;">📅 Dec 25, 2024 • 8:00 PM</div>
            <div style="font-size: 11px; color: #666; margin-bottom: 12px;">📍 Madison Square Garden</div>
            <div style="font-size: 10px; color: #666; margin-bottom: 4px;">Seat: A-12 | Row: 5</div>
        </div>
        <div style="position: absolute; bottom: 0; left: 0; right: 0; height: 40px; background: {primary}10; border-top: 2px dashed {primary}; display: flex; align-items: center; justify-content: center;">
            <div style="font-family: monospace; font-size: 14px; font-weight: 700; letter-spacing: 2px; color: #333;">|||||||||||||||</div>
        </div>
        """

    # E-COMMERCE EXTENDED (15)
    elif card_id == "cart_item":
        base_style = "width: 100%; max-width: 300px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; display: flex; gap: 12px; padding: 12px;"
        content = f"""
        <div style="width: 76px; height: 76px; border-radius: 8px; background: #f5f5f5; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 36px;">👟</div>
        <div style="flex: 1; display: flex; flex-direction: column; justify-content: space-between;">
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333;">Running Shoes</div>
                <div style="font-size: 10px; color: #666;">Size: 42, Color: Blue</div>
            </div>
            <div style="display: flex; justify-content: space-between; align-items: center;">
                <div style="display: flex; align-items: center; gap: 8px; background: #f5f5f5; border-radius: 6px; padding: 4px;">
                    <button style="width: 24px; height: 24px; border: none; background: transparent; color: #666; font-size: 16px;">-</button>
                    <span style="font-size: 12px; font-weight: 600;">2</span>
                    <button style="width: 24px; height: 24px; border: none; background: transparent; color: {primary}; font-size: 16px;">+</button>
                </div>
                <div style="font-weight: 700; font-size: 16px; color: {primary};">$158.00</div>
            </div>
        </div>
        """
    elif card_id == "wishlist_item":
        base_style = "width: 100%; max-width: 200px; min-height: 260px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="position: relative; background: #f5f5f5; height: 160px; display: flex; align-items: center; justify-content: center; font-size: 56px;">
            👟
            <div style="position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border-radius: 50%; background: white; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 4px rgba(0,0,0,0.1);">❤️</div>
        </div>
        <div style="padding: 12px;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 6px;">Running Shoes</div>
            <div style="font-weight: 700; font-size: 16px; color: {primary};">$79.00</div>
        </div>
        """
    elif card_id == "checkout_step":
        base_style = "width: 100%; max-width: 300px; min-height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 12px;">
            <div style="width: 32px; height: 32px; border-radius: 50%; background: {primary}; color: white; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700;">2</div>
            <div style="font-weight: 700; font-size: 14px; color: #333;">Shipping Address</div>
        </div>
        <div style="height: 4px; background: #eee; border-radius: 2px; overflow: hidden;">
            <div style="width: 50%; height: 100%; background: {primary};"></div>
        </div>
        """
    elif card_id == "shipping_option":
        base_style = "width: 100%; max-width: 280px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 20px; height: 20px; border-radius: 50%; border: 2px solid {primary}; display: flex; align-items: center; justify-content: center;">
            <div style="width: 12px; height: 12px; border-radius: 50%; background: {primary};"></div>
        </div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Express Delivery</div>
            <div style="font-size: 11px; color: #666;">Arrives tomorrow</div>
        </div>
        <div style="font-weight: 700; font-size: 14px; color: {primary};">$9.99</div>
        """
    elif card_id == "product_review":
        content = f"""
        <div style="padding: 14px;">
            <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
                <div style="width: 36px; height: 36px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 18px;">👤</div>
                <div style="flex: 1;">
                    <div style="font-weight: 700; font-size: 12px; color: #333;">John Doe <span style="background: {primary}20; color: {primary}; padding: 2px 6px; border-radius: 4px; font-size: 9px; margin-left: 4px;">✓ Verified</span></div>
                    <div style="color: #FFB800; font-size: 12px;">⭐⭐⭐⭐⭐</div>
                </div>
            </div>
            <div style="font-size: 11px; color: #666; line-height: 1.4; margin-bottom: 8px;">Great product! Exactly as described. Fast shipping too.</div>
            <div style="font-size: 10px; color: #999;">👍 45 people found this helpful</div>
        </div>
        """
    elif card_id == "category_grid":
        base_style = "width: 100%; max-width: 120px; height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;"
        content = f"""
        <div style="width: 48px; height: 48px; border-radius: 10px; background: {primary}20; color: {primary}; display: flex; align-items: center; justify-content: center; font-size: 28px;">👕</div>
        <div style="font-weight: 600; font-size: 12px; color: #333; text-align: center;">Clothing</div>
        <div style="font-size: 10px; color: #666;">245 items</div>
        """
    elif card_id == "filter_chip":
        base_style = "width: 100%; max-width: 100px; height: 36px; border-radius: 18px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: {primary}; color: white; padding: 0 12px; display: flex; align-items: center; justify-content: center; gap: 6px;"
        content = f"""
        <span style="font-size: 12px; font-weight: 600;">On Sale</span>
        <span style="font-size: 14px;">×</span>
        """
    elif card_id == "order_summary":
        base_style = "width: 100%; max-width: 280px; min-height: 180px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 12px;">Order Summary</div>
        <div style="display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px;">
            <div style="display: flex; justify-content: space-between; font-size: 12px; color: #666;">
                <span>Subtotal (3 items)</span>
                <span>$237.00</span>
            </div>
            <div style="display: flex; justify-content: space-between; font-size: 12px; color: #666;">
                <span>Shipping</span>
                <span>$9.99</span>
            </div>
            <div style="display: flex; justify-content: space-between; font-size: 12px; color: {primary};">
                <span>Discount</span>
                <span>-$20.00</span>
            </div>
        </div>
        <div style="border-top: 1px solid #eee; padding-top: 12px; display: flex; justify-content: space-between; align-items: center;">
            <span style="font-weight: 700; font-size: 14px; color: #333;">Total</span>
            <span style="font-weight: 700; font-size: 18px; color: {primary};">$226.99</span>
        </div>
        """
    elif card_id == "payment_method":
        base_style = "width: 100%; max-width: 280px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 48px; height: 32px; border-radius: 6px; background: linear-gradient(135deg, {primary}, {secondary}); display: flex; align-items: center; justify-content: center; color: white; font-size: 10px; font-weight: 700;">VISA</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">•••• 4242</div>
            <div style="font-size: 10px; color: #666;">Expires 12/25</div>
        </div>
        <div style="background: {primary}20; color: {primary}; padding: 4px 8px; border-radius: 6px; font-size: 9px; font-weight: 600;">DEFAULT</div>
        """
    elif card_id == "order_tracking":
        base_style = "width: 100%; max-width: 300px; min-height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 16px;">Order #12345</div>
        <div style="display: flex; flex-direction: column; gap: 16px;">
            <div style="display: flex; align-items: start; gap: 12px;">
                <div style="width: 24px; height: 24px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 12px;">✓</div>
                <div style="flex: 1;">
                    <div style="font-weight: 600; font-size: 12px; color: #333;">Order Placed</div>
                    <div style="font-size: 10px; color: #666;">Dec 15, 2:30 PM</div>
                </div>
            </div>
            <div style="display: flex; align-items: start; gap: 12px;">
                <div style="width: 24px; height: 24px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 12px;">✓</div>
                <div style="flex: 1;">
                    <div style="font-weight: 600; font-size: 12px; color: #333;">Shipped</div>
                    <div style="font-size: 10px; color: #666;">Dec 16, 10:00 AM</div>
                </div>
            </div>
            <div style="display: flex; align-items: start; gap: 12px;">
                <div style="width: 24px; height: 24px; border-radius: 50%; background: #eee; color: #999; display: flex; align-items: center; justify-content: center; font-size: 12px;">3</div>
                <div style="flex: 1;">
                    <div style="font-weight: 600; font-size: 12px; color: #666;">Delivered</div>
                    <div style="font-size: 10px; color: #999;">Estimated: Dec 18</div>
                </div>
            </div>
        </div>
        """
    elif card_id == "brand_showcase":
        base_style = "width: 100%; max-width: 200px; min-height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 10px;"
        content = f"""
        <div style="width: 80px; height: 80px; border-radius: 12px; background: #f5f5f5; display: flex; align-items: center; justify-content: center; font-size: 40px;">🏷️</div>
        <div style="font-weight: 700; font-size: 14px; color: #333; text-align: center;">Nike</div>
        <div style="font-size: 10px; color: #666;">1,234 products</div>
        <button style="background: {primary}; color: white; border: none; padding: 8px 20px; border-radius: 20px; font-size: 11px; font-weight: 600; margin-top: 4px;">Follow</button>
        """
    elif card_id == "size_selector":
        base_style = "width: 100%; max-width: 240px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 600; font-size: 12px; color: #333; margin-bottom: 10px;">Select Size</div>
        <div style="display: flex; gap: 8px;">
            <div style="width: 44px; height: 44px; border-radius: 8px; border: 1px solid #ddd; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #666;">S</div>
            <div style="width: 44px; height: 44px; border-radius: 8px; border: 2px solid {primary}; background: {primary}10; display: flex; align-items: center; justify-content: center; font-size: 12px; color: {primary}; font-weight: 700;">M</div>
            <div style="width: 44px; height: 44px; border-radius: 8px; border: 1px solid #ddd; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #666;">L</div>
            <div style="width: 44px; height: 44px; border-radius: 8px; border: 1px solid #ddd; background: #f5f5f5; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #ccc;">XL</div>
        </div>
        """
    elif card_id == "color_picker":
        base_style = "width: 100%; max-width: 200px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 600; font-size: 12px; color: #333; margin-bottom: 10px;">Color: <span style="color: #666;">Ocean Blue</span></div>
        <div style="display: flex; gap: 8px;">
            <div style="width: 36px; height: 36px; border-radius: 50%; background: #1E40AF; border: 3px solid {primary};"></div>
            <div style="width: 36px; height: 36px; border-radius: 50%; background: #DC2626; border: 1px solid #ddd;"></div>
            <div style="width: 36px; height: 36px; border-radius: 50%; background: #059669; border: 1px solid #ddd;"></div>
            <div style="width: 36px; height: 36px; border-radius: 50%; background: #1F2937; border: 1px solid #ddd;"></div>
        </div>
        """
    elif card_id == "flash_sale":
        base_style = "width: 100%; max-width: 240px; min-height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: linear-gradient(135deg, #FF3B30, #FF9500);"
        content = f"""
        <div style="padding: 16px; color: white;">
            <div style="font-size: 10px; font-weight: 600; margin-bottom: 4px;">FLASH SALE</div>
            <div style="font-size: 24px; font-weight: 700; margin-bottom: 8px;">50% OFF</div>
            <div style="display: flex; gap: 6px; margin-bottom: 12px;">
                <div style="background: rgba(0,0,0,0.3); padding: 6px; border-radius: 6px; font-size: 18px; font-weight: 700;">02</div>
                <div style="font-size: 18px; font-weight: 700;">:</div>
                <div style="background: rgba(0,0,0,0.3); padding: 6px; border-radius: 6px; font-size: 18px; font-weight: 700;">34</div>
                <div style="font-size: 18px; font-weight: 700;">:</div>
                <div style="background: rgba(0,0,0,0.3); padding: 6px; border-radius: 6px; font-size: 18px; font-weight: 700;">56</div>
            </div>
        </div>
        <div style="background: #f5f5f5; height: 80px; display: flex; align-items: center; justify-content: center; font-size: 40px;">📱</div>
        """
    elif card_id == "related_products":
        base_style = "width: 100%; max-width: 120px; min-height: 180px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: #f5f5f5; height: 120px; display: flex; align-items: center; justify-content: center; font-size: 48px;">📱</div>
        <div style="padding: 10px;">
            <div style="font-weight: 600; font-size: 11px; color: #333; margin-bottom: 4px;">Product Name</div>
            <div style="font-weight: 700; font-size: 13px; color: {primary};">$49</div>
        </div>
        """

    # SOCIAL EXTENDED (10)
    elif card_id == "comment_thread":
        base_style = "width: 100%; max-width: 300px; min-height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px;"
        content = f"""
        <div style="display: flex; gap: 10px;">
            <div style="width: 32px; height: 32px; border-radius: 50%; background: {primary}; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px;">👤</div>
            <div style="flex: 1;">
                <div style="font-weight: 700; font-size: 12px; color: #333; margin-bottom: 4px;">Alex Kim <span style="font-size: 10px; color: #999; font-weight: 400;">• 2h ago</span></div>
                <div style="font-size: 11px; color: #666; line-height: 1.4; margin-bottom: 6px;">This is amazing! Can't wait to try it out.</div>
                <div style="display: flex; gap: 12px; font-size: 10px; color: #999;">
                    <span>👍 12</span>
                    <span>💬 Reply</span>
                </div>
            </div>
        </div>
        """
    elif card_id == "reaction_bar":
        base_style = "width: 100%; max-width: 200px; height: 48px; border-radius: 24px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 8px 16px; display: flex; align-items: center; justify-content: space-around; gap: 8px;"
        content = f"""
        <span style="font-size: 20px;">👍</span>
        <span style="font-size: 20px;">❤️</span>
        <span style="font-size: 20px;">😂</span>
        <span style="font-size: 20px;">😮</span>
        <span style="font-size: 20px;">😢</span>
        """
    elif card_id == "share_sheet":
        base_style = "width: 100%; max-width: 280px; min-height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 16px;">Share</div>
        <div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;">
            <div style="display: flex; flex-direction: column; align-items: center; gap: 6px;">
                <div style="width: 48px; height: 48px; border-radius: 50%; background: #1877F2; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px;">f</div>
                <div style="font-size: 9px; color: #666;">Facebook</div>
            </div>
            <div style="display: flex; flex-direction: column; align-items: center; gap: 6px;">
                <div style="width: 48px; height: 48px; border-radius: 50%; background: #1DA1F2; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px;">𝕏</div>
                <div style="font-size: 9px; color: #666;">Twitter</div>
            </div>
            <div style="display: flex; flex-direction: column; align-items: center; gap: 6px;">
                <div style="width: 48px; height: 48px; border-radius: 50%; background: #25D366; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px;">💬</div>
                <div style="font-size: 9px; color: #666;">WhatsApp</div>
            </div>
            <div style="display: flex; flex-direction: column; align-items: center; gap: 6px;">
                <div style="width: 48px; height: 48px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px;">🔗</div>
                <div style="font-size: 9px; color: #666;">Copy</div>
            </div>
        </div>
        """
    elif card_id == "follower_item":
        base_style = "width: 100%; max-width: 280px; height: 72px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 48px; height: 48px; border-radius: 50%; background: {primary}; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px;">👤</div>
        <div style="flex: 1; min-width: 0;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Emma Watson</div>
            <div style="font-size: 10px; color: #666;">Followed by john_doe + 12 others</div>
        </div>
        <button style="background: {primary}; color: white; border: none; padding: 6px 16px; border-radius: 6px; font-size: 11px; font-weight: 600;">Follow</button>
        """
    elif card_id == "story_ring":
        base_style = "width: 100%; max-width: 80px; height: 100px; display: flex; flex-direction: column; align-items: center; gap: 6px;"
        content = f"""
        <div style="width: 68px; height: 68px; border-radius: 50%; padding: 3px; background: linear-gradient(135deg, {primary}, {secondary});">
            <div style="width: 62px; height: 62px; border-radius: 50%; background: white; padding: 2px;">
                <div style="width: 58px; height: 58px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 28px;">👤</div>
            </div>
        </div>
        <div style="font-size: 10px; color: #333; font-weight: 500;">John</div>
        """
    elif card_id == "reel_preview":
        base_style = "width: 100%; max-width: 160px; height: 280px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); position: relative;"
        content = f"""
        <div style="position: absolute; inset: 0; background: linear-gradient(135deg, #667eea, #764ba2); display: flex; align-items: center; justify-content: center; color: white; font-size: 48px;">▶️</div>
        <div style="position: absolute; top: 8px; left: 8px; background: rgba(0,0,0,0.6); color: white; padding: 4px 8px; border-radius: 6px; font-size: 10px; font-weight: 600;">0:45</div>
        <div style="position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); padding: 12px; color: white;">
            <div style="font-size: 10px; opacity: 0.9;">👁️ 12.5K views</div>
        </div>
        """
    elif card_id == "live_streaming":
        base_style = "width: 100%; max-width: 260px; height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); position: relative;"
        content = f"""
        <div style="position: absolute; inset: 0; background: linear-gradient(135deg, {primary}, {secondary});"></div>
        <div style="position: absolute; top: 8px; left: 8px; background: #FF3B30; color: white; padding: 4px 10px; border-radius: 6px; font-size: 10px; font-weight: 700;">🔴 LIVE</div>
        <div style="position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,0.6); color: white; padding: 4px 8px; border-radius: 6px; font-size: 10px; font-weight: 600;">👁️ 2.3K</div>
        <div style="position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); padding: 12px; color: white;">
            <div style="font-weight: 700; font-size: 13px;">Tech Talk Live</div>
            <div style="font-size: 10px; opacity: 0.9;">with @johndoe</div>
        </div>
        """
    elif card_id == "poll_card":
        base_style = "width: 100%; max-width: 280px; min-height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 12px;">Which feature do you want next?</div>
        <div style="display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px;">
            <div style="position: relative; background: #f5f5f5; border-radius: 8px; padding: 10px; overflow: hidden;">
                <div style="position: absolute; left: 0; top: 0; bottom: 0; width: 65%; background: {primary}20; border-radius: 8px;"></div>
                <div style="position: relative; display: flex; justify-content: space-between; font-size: 11px;">
                    <span style="font-weight: 600; color: #333;">Dark Mode</span>
                    <span style="color: {primary}; font-weight: 700;">65%</span>
                </div>
            </div>
            <div style="position: relative; background: #f5f5f5; border-radius: 8px; padding: 10px;">
                <div style="position: relative; display: flex; justify-content: space-between; font-size: 11px;">
                    <span style="color: #666;">Notifications</span>
                    <span style="color: #666;">35%</span>
                </div>
            </div>
        </div>
        <div style="font-size: 10px; color: #999;">1,234 votes • 2 days left</div>
        """
    elif card_id == "mention_tag":
        base_style = "width: 100%; max-width: 120px; height: 36px; border-radius: 18px; overflow: hidden; box-shadow: 0 2px 4px rgba(0,0,0,0.1); background: {primary}10; color: {primary}; padding: 0 14px; display: flex; align-items: center; justify-content: center;"
        content = f"""
        <span style="font-size: 13px; font-weight: 600;">@johndoe</span>
        """
    elif card_id == "group_member":
        base_style = "width: 100%; max-width: 280px; height: 72px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 48px; height: 48px; border-radius: 50%; background: {primary}; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px;">👤</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Sarah Johnson <span style="background: #FFB800; color: white; padding: 2px 6px; border-radius: 4px; font-size: 9px; margin-left: 4px;">ADMIN</span></div>
            <div style="font-size: 10px; color: #666;">Joined 3 months ago</div>
        </div>
        <button style="color: #666; background: transparent; border: none; font-size: 18px;">⋮</button>
        """

    # FINANCE & BANKING (10)
    elif card_id == "account_balance":
        base_style = "width: 100%; max-width: 280px; min-height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: linear-gradient(135deg, {primary}, {secondary}); padding: 16px; color: white;"
        content = f"""
        <div style="font-size: 11px; opacity: 0.9; margin-bottom: 6px;">Checking Account</div>
        <div style="font-size: 28px; font-weight: 700; margin-bottom: 8px;">$12,459.32</div>
        <div style="font-size: 10px; opacity: 0.8;">**** 4242</div>
        """
    elif card_id == "transaction_item":
        base_style = "width: 100%; max-width: 300px; height: 72px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 44px; height: 44px; border-radius: 10px; background: {primary}20; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: {primary}; font-size: 20px;">🏪</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Amazon</div>
            <div style="font-size: 10px; color: #666;">Shopping • Today at 2:30 PM</div>
        </div>
        <div style="font-weight: 700; font-size: 14px; color: #333;">-$49.99</div>
        """
    elif card_id == "credit_card":
        base_style = "width: 100%; max-width: 320px; height: 200px; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 16px rgba(0,0,0,0.2); background: linear-gradient(135deg, {primary}, {secondary}); padding: 20px; color: white; position: relative;"
        content = f"""
        <div style="font-size: 24px; margin-bottom: 40px;">💳</div>
        <div style="font-size: 18px; font-weight: 600; letter-spacing: 2px; margin-bottom: 16px;">**** **** **** 4242</div>
        <div style="display: flex; justify-content: space-between; align-items: end;">
            <div>
                <div style="font-size: 9px; opacity: 0.8;">VALID THRU</div>
                <div style="font-size: 12px; font-weight: 600;">12/25</div>
            </div>
            <div style="font-size: 20px; font-weight: 700; opacity: 0.9;">VISA</div>
        </div>
        """
    elif card_id == "transfer_form":
        base_style = "width: 100%; max-width: 280px; min-height: 180px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 16px;">Transfer Money</div>
        <div style="margin-bottom: 12px;">
            <div style="font-size: 11px; color: #666; margin-bottom: 6px;">To</div>
            <div style="background: #f5f5f5; border-radius: 8px; padding: 10px; font-size: 12px; color: #333;">John Doe (**** 5678)</div>
        </div>
        <div style="margin-bottom: 16px;">
            <div style="font-size: 11px; color: #666; margin-bottom: 6px;">Amount</div>
            <div style="background: #f5f5f5; border-radius: 8px; padding: 10px; font-size: 20px; font-weight: 700; color: {primary};">$500.00</div>
        </div>
        <button style="width: 100%; background: {primary}; color: white; border: none; padding: 12px; border-radius: 8px; font-size: 13px; font-weight: 600;">Confirm Transfer</button>
        """
    elif card_id == "investment_item":
        base_style = "width: 100%; max-width: 280px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 10px;">
            <div>
                <div style="font-weight: 700; font-size: 14px; color: #333;">AAPL</div>
                <div style="font-size: 10px; color: #666;">Apple Inc.</div>
            </div>
            <div style="text-align: right;">
                <div style="font-weight: 700; font-size: 14px; color: #333;">$178.45</div>
                <div style="font-size: 11px; color: #34C759; font-weight: 600;">+2.34%</div>
            </div>
        </div>
        <div style="display: flex; align-items: end; gap: 2px; height: 30px;">
            <div style="flex: 1; background: {primary}; opacity: 0.4; height: 40%;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.5; height: 60%;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.6; height: 50%;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.7; height: 70%;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.8; height: 85%;"></div>
            <div style="flex: 1; background: {primary}; height: 100%;"></div>
        </div>
        """
    elif card_id == "crypto_wallet":
        base_style = "width: 100%; max-width: 260px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 12px;">
            <div style="width: 40px; height: 40px; border-radius: 50%; background: #F7931A; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px; font-weight: 700;">₿</div>
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333;">Bitcoin</div>
                <div style="font-size: 10px; color: #666;">BTC</div>
            </div>
        </div>
        <div style="display: flex; justify-content: space-between; align-items: end;">
            <div>
                <div style="font-size: 18px; font-weight: 700; color: #333;">0.0245 BTC</div>
                <div style="font-size: 11px; color: #666;">≈ $1,089.50</div>
            </div>
            <div style="font-size: 11px; color: #34C759; font-weight: 600;">+5.2%</div>
        </div>
        """
    elif card_id == "bill_payment":
        base_style = "width: 100%; max-width: 280px; height: 90px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 56px; height: 56px; border-radius: 12px; background: {primary}20; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: {primary}; font-size: 28px;">⚡</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Electricity Bill</div>
            <div style="font-size: 10px; color: #666;">Due: Dec 25, 2024</div>
            <div style="font-size: 16px; font-weight: 700; color: #FF3B30; margin-top: 4px;">$124.50</div>
        </div>
        <button style="background: {primary}; color: white; border: none; padding: 8px 16px; border-radius: 8px; font-size: 11px; font-weight: 600;">Pay</button>
        """
    elif card_id == "budget_category":
        base_style = "width: 100%; max-width: 260px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
            <div style="width: 36px; height: 36px; border-radius: 8px; background: {primary}20; display: flex; align-items: center; justify-content: center; color: {primary}; font-size: 18px;">🍔</div>
            <div style="flex: 1;">
                <div style="font-weight: 700; font-size: 13px; color: #333;">Food & Dining</div>
                <div style="font-size: 11px; color: #666;">$450 of $600</div>
            </div>
        </div>
        <div style="height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden;">
            <div style="width: 75%; height: 100%; background: {primary}; border-radius: 4px;"></div>
        </div>
        <div style="font-size: 10px; color: #666; margin-top: 6px; text-align: right;">$150 remaining</div>
        """
    elif card_id == "loan_summary":
        base_style = "width: 100%; max-width: 280px; min-height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 12px;">Home Loan</div>
        <div style="display: flex; flex-direction: column; gap: 8px;">
            <div style="display: flex; justify-content: space-between; font-size: 11px;">
                <span style="color: #666;">Outstanding</span>
                <span style="font-weight: 700; color: #333;">$245,000</span>
            </div>
            <div style="display: flex; justify-content: space-between; font-size: 11px;">
                <span style="color: #666;">Monthly EMI</span>
                <span style="font-weight: 700; color: #333;">$1,850</span>
            </div>
            <div style="display: flex; justify-content: space-between; font-size: 11px;">
                <span style="color: #666;">Next Payment</span>
                <span style="font-weight: 700; color: {primary};">Jan 1, 2025</span>
            </div>
        </div>
        """
    elif card_id == "statement_month":
        base_style = "width: 100%; max-width: 240px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; align-items: center; justify-content: space-between;"
        content = f"""
        <div>
            <div style="font-weight: 700; font-size: 14px; color: #333;">December 2024</div>
            <div style="font-size: 12px; color: #666; margin-top: 4px;">Total Spent</div>
            <div style="font-size: 18px; font-weight: 700; color: {primary}; margin-top: 4px;">$3,245.80</div>
        </div>
        <button style="width: 40px; height: 40px; border-radius: 50%; background: {primary}20; color: {primary}; border: none; font-size: 18px;">📄</button>
        """

    # HEALTH & FITNESS (10)
    elif card_id == "workout_exercise":
        base_style = "width: 100%; max-width: 280px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 10px;">
            <div>
                <div style="font-weight: 700; font-size: 14px; color: #333;">Push-ups</div>
                <div style="font-size: 11px; color: #666;">Chest • Triceps</div>
            </div>
            <div style="width: 44px; height: 44px; border-radius: 10px; background: {primary}20; display: flex; align-items: center; justify-content: center; color: {primary}; font-size: 22px;">💪</div>
        </div>
        <div style="display: flex; gap: 16px; font-size: 12px; color: #666;">
            <div><span style="font-weight: 700; color: #333;">3</span> sets</div>
            <div><span style="font-weight: 700; color: #333;">15</span> reps</div>
            <div><span style="font-weight: 700; color: #333;">60s</span> rest</div>
        </div>
        """
    elif card_id == "nutrition_log":
        base_style = "width: 100%; max-width: 300px; height: 90px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; gap: 12px;"
        content = f"""
        <div style="width: 56px; height: 56px; border-radius: 12px; background: #f5f5f5; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 32px;">🥗</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Grilled Chicken Salad</div>
            <div style="font-size: 18px; font-weight: 700; color: {primary}; margin-bottom: 4px;">245 cal</div>
            <div style="font-size: 10px; color: #666;">P: 32g • C: 12g • F: 8g</div>
        </div>
        """
    elif card_id == "step_counter":
        base_style = "width: 100%; max-width: 160px; height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;"
        content = f"""
        <div style="width: 100px; height: 100px; border-radius: 50%; border: 8px solid {primary}20; border-top-color: {primary}; display: flex; align-items: center; justify-content: center; position: relative; transform: rotate(270deg);">
            <div style="transform: rotate(90deg); text-align: center;">
                <div style="font-size: 24px; font-weight: 700; color: #333;">8,234</div>
                <div style="font-size: 10px; color: #666;">steps</div>
            </div>
        </div>
        <div style="font-size: 11px; color: #666;">Goal: 10,000</div>
        """
    elif card_id == "heart_rate":
        base_style = "width: 100%; max-width: 240px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 10px;">
            <div style="font-size: 36px; color: #FF3B30;">❤️</div>
            <div>
                <div style="font-size: 28px; font-weight: 700; color: #333;">72 <span style="font-size: 14px; font-weight: 400; color: #666;">BPM</span></div>
                <div style="font-size: 11px; color: {primary}; font-weight: 600;">Normal</div>
            </div>
        </div>
        <div style="display: flex; align-items: end; gap: 2px; height: 20px;">
            <div style="flex: 1; background: #FF3B30; opacity: 0.4; height: 40%;"></div>
            <div style="flex: 1; background: #FF3B30; opacity: 0.5; height: 60%;"></div>
            <div style="flex: 1; background: #FF3B30; opacity: 0.6; height: 55%;"></div>
            <div style="flex: 1; background: #FF3B30; opacity: 0.7; height: 70%;"></div>
            <div style="flex: 1; background: #FF3B30; opacity: 0.8; height: 65%;"></div>
            <div style="flex: 1; background: #FF3B30; height: 80%;"></div>
        </div>
        """
    elif card_id == "sleep_tracker":
        base_style = "width: 100%; max-width: 280px; min-height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 12px;">
            <div>
                <div style="font-weight: 700; font-size: 14px; color: #333;">Sleep Quality</div>
                <div style="font-size: 11px; color: #666;">Last night</div>
            </div>
            <div style="font-size: 32px;">🌙</div>
        </div>
        <div style="font-size: 36px; font-weight: 700; color: {primary}; margin-bottom: 8px;">7h 32m</div>
        <div style="display: flex; gap: 12px; font-size: 11px; color: #666;">
            <div>Deep: 2h 15m</div>
            <div>Light: 4h 45m</div>
            <div>REM: 32m</div>
        </div>
        """
    elif card_id == "water_intake":
        base_style = "width: 100%; max-width: 200px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; justify-content: space-between;"
        content = f"""
        <div>
            <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 8px;">Water Intake</div>
            <div style="display: flex; gap: 6px; margin-bottom: 10px;">
                <div style="width: 24px; height: 32px; border-radius: 4px; background: {primary};"></div>
                <div style="width: 24px; height: 32px; border-radius: 4px; background: {primary};"></div>
                <div style="width: 24px; height: 32px; border-radius: 4px; background: {primary};"></div>
                <div style="width: 24px; height: 32px; border-radius: 4px; background: {primary}; opacity: 0.5;"></div>
                <div style="width: 24px; height: 32px; border-radius: 4px; background: #eee;"></div>
                <div style="width: 24px; height: 32px; border-radius: 4px; background: #eee;"></div>
            </div>
            <div style="font-size: 11px; color: #666;">6 of 8 glasses</div>
        </div>
        <button style="width: 100%; background: {primary}; color: white; border: none; padding: 10px; border-radius: 8px; font-size: 12px; font-weight: 600;">+ Add Glass</button>
        """
    elif card_id == "bmi_calculator":
        base_style = "width: 100%; max-width: 220px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333;">Body Mass Index</div>
        <div style="font-size: 48px; font-weight: 700; color: {primary};">22.5</div>
        <div style="background: {primary}20; color: {primary}; padding: 6px 16px; border-radius: 16px; font-size: 12px; font-weight: 600;">Normal Weight</div>
        <div style="font-size: 10px; color: #666;">Height: 175cm • Weight: 69kg</div>
        """
    elif card_id == "calorie_goal":
        base_style = "width: 100%; max-width: 240px; height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 16px;">Daily Calories</div>
        <div style="display: flex; justify-content: space-around; margin-bottom: 16px;">
            <div style="text-align: center;">
                <div style="font-size: 20px; font-weight: 700; color: {primary};">1,850</div>
                <div style="font-size: 10px; color: #666;">Consumed</div>
            </div>
            <div style="text-align: center;">
                <div style="font-size: 20px; font-weight: 700; color: #34C759;">420</div>
                <div style="font-size: 10px; color: #666;">Burned</div>
            </div>
        </div>
        <div style="text-align: center;">
            <div style="font-size: 24px; font-weight: 700; color: #333; margin-bottom: 4px;">1,430</div>
            <div style="font-size: 11px; color: #666;">Remaining of 2,000</div>
        </div>
        """
    elif card_id == "meditation_session":
        base_style = "width: 100%; max-width: 260px; height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: linear-gradient(135deg, {primary}, {secondary}); padding: 20px; color: white; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;"
        content = f"""
        <div style="font-size: 48px;">🧘</div>
        <div style="font-weight: 700; font-size: 16px;">Mindful Breathing</div>
        <div style="font-size: 13px; opacity: 0.9;">10 minutes</div>
        <button style="width: 60px; height: 60px; border-radius: 50%; background: white; color: {primary}; border: none; font-size: 24px; display: flex; align-items: center; justify-content: center; margin-top: 8px;">▶️</button>
        """
    elif card_id == "weight_progress":
        base_style = "width: 100%; max-width: 280px; min-height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 12px;">Weight Progress</div>
        <div style="display: flex; justify-content: space-around; margin-bottom: 16px;">
            <div style="text-align: center;">
                <div style="font-size: 10px; color: #666; margin-bottom: 4px;">Current</div>
                <div style="font-size: 24px; font-weight: 700; color: #333;">69kg</div>
            </div>
            <div style="text-align: center;">
                <div style="font-size: 10px; color: #666; margin-bottom: 4px;">Goal</div>
                <div style="font-size: 24px; font-weight: 700; color: {primary};">65kg</div>
            </div>
            <div style="text-align: center;">
                <div style="font-size: 10px; color: #666; margin-bottom: 4px;">Change</div>
                <div style="font-size: 24px; font-weight: 700; color: #34C759;">-2kg</div>
            </div>
        </div>
        <div style="display: flex; align-items: end; gap: 3px; height: 40px;">
            <div style="flex: 1; background: {primary}; opacity: 0.4; height: 100%;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.5; height: 95%;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.6; height: 90%;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.7; height: 85%;"></div>
            <div style="flex: 1; background: {primary}; opacity: 0.8; height: 80%;"></div>
            <div style="flex: 1; background: {primary}; height: 75%;"></div>
        </div>
        """

    # EDUCATION & LEARNING (8)
    elif card_id == "course_card":
        base_style = "width: 100%; max-width: 280px; min-height: 280px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: linear-gradient(135deg, {primary}, {secondary}); height: 140px; display: flex; align-items: center; justify-content: center; color: white; font-size: 56px;">📚</div>
        <div style="padding: 14px;">
            <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 6px;">Complete Web Development Bootcamp</div>
            <div style="font-size: 11px; color: #666; margin-bottom: 8px;">by Dr. Angela Yu</div>
            <div style="display: flex; align-items: center; gap: 8px; margin-bottom: 8px;">
                <div style="color: #FFB800; font-size: 11px;">⭐⭐⭐⭐⭐</div>
                <div style="font-size: 10px; color: #666;">(12,345)</div>
            </div>
            <div style="display: flex; justify-content: space-between; align-items: center;">
                <div style="font-size: 10px; color: #666;">👥 45,234 students</div>
                <div style="font-weight: 700; font-size: 18px; color: {primary};">$89.99</div>
            </div>
        </div>
        """
    elif card_id == "lesson_item":
        base_style = "width: 100%; max-width: 300px; height: 72px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 44px; height: 44px; border-radius: 50%; background: {primary}; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px; font-weight: 700;">5</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Introduction to React Hooks</div>
            <div style="font-size: 10px; color: #666;">⏱️ 18 min • 📹 Video</div>
        </div>
        <div style="width: 20px; height: 20px; border-radius: 50%; background: #34C759; display: flex; align-items: center; justify-content: center; color: white; font-size: 12px;">✓</div>
        """
    elif card_id == "quiz_question":
        base_style = "width: 100%; max-width: 300px; min-height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 16px;">Question 3 of 10</div>
        <div style="font-size: 13px; color: #333; margin-bottom: 16px; line-height: 1.4;">What is the correct way to create a useState hook in React?</div>
        <div style="display: flex; flex-direction: column; gap: 10px;">
            <div style="padding: 12px; border-radius: 8px; background: #f5f5f5; font-size: 12px; color: #666; cursor: pointer;">A) const [state, setState] = useState()</div>
            <div style="padding: 12px; border-radius: 8px; border: 2px solid {primary}; background: {primary}10; font-size: 12px; color: #333; font-weight: 600;">B) const [state, setState] = useState(initialValue)</div>
            <div style="padding: 12px; border-radius: 8px; background: #f5f5f5; font-size: 12px; color: #666;">C) useState(state, setState)</div>
            <div style="padding: 12px; border-radius: 8px; background: #f5f5f5; font-size: 12px; color: #666;">D) const state = useState()</div>
        </div>
        """
    elif card_id == "certificate_card":
        base_style = "width: 100%; max-width: 320px; height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: linear-gradient(135deg, #f5f5f5, #e0e0e0); padding: 20px; position: relative; border: 4px solid {primary};"
        content = f"""
        <div style="text-align: center; color: #333;">
            <div style="font-size: 11px; color: #666; margin-bottom: 8px;">CERTIFICATE OF COMPLETION</div>
            <div style="font-size: 18px; font-weight: 700; margin-bottom: 12px; color: {primary};">Web Development Bootcamp</div>
            <div style="font-size: 13px; margin-bottom: 16px;">Awarded to <strong>John Doe</strong></div>
            <div style="font-size: 10px; color: #666; margin-bottom: 12px;">Completed on December 15, 2024</div>
            <div style="font-size: 32px; color: {primary};">🏆</div>
        </div>
        """
    elif card_id == "learning_progress":
        base_style = "width: 100%; max-width: 260px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 8px;">JavaScript Masterclass</div>
        <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
            <div style="font-size: 11px; color: #666;">12 of 24 modules</div>
            <div style="font-weight: 700; font-size: 16px; color: {primary};">50%</div>
        </div>
        <div style="height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden;">
            <div style="width: 50%; height: 100%; background: {primary}; border-radius: 4px;"></div>
        </div>
        """
    elif card_id == "assignment_card":
        base_style = "width: 100%; max-width: 280px; min-height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 10px;">
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333;">Build a React Todo App</div>
                <div style="font-size: 10px; color: #666; margin-top: 4px;">Due: Dec 20, 2024</div>
            </div>
            <div style="background: #FFB800; color: white; padding: 4px 10px; border-radius: 12px; font-size: 9px; font-weight: 600;">PENDING</div>
        </div>
        <button style="width: 100%; background: {primary}; color: white; border: none; padding: 10px; border-radius: 8px; font-size: 12px; font-weight: 600; margin-top: 8px;">📎 Upload Submission</button>
        """
    elif card_id == "grade_item":
        base_style = "width: 100%; max-width: 260px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; align-items: center; justify-content: space-between;"
        content = f"""
        <div>
            <div style="font-weight: 700; font-size: 13px; color: #333;">Mathematics</div>
            <div style="font-size: 10px; color: #666; margin-top: 4px;">Final Exam • 85/100 points</div>
        </div>
        <div style="width: 56px; height: 56px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px; font-weight: 700;">A</div>
        """
    elif card_id == "study_streak":
        base_style = "width: 100%; max-width: 180px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;"
        content = f"""
        <div style="font-size: 56px;">🔥</div>
        <div style="font-size: 32px; font-weight: 700; color: {primary};">15</div>
        <div style="font-weight: 600; font-size: 13px; color: #333;">Day Streak</div>
        <div style="font-size: 10px; color: #666;">Keep it up!</div>
        """

    # TRAVEL & TOURISM (8) - FOOD & RESTAURANT (8) - REAL ESTATE (7) - MUSIC & AUDIO (7) - GAMING (6) - PRODUCTIVITY (6) - DASHBOARD WIDGETS (8)
    elif card_id == "flight_card":
        base_style = "width: 100%; max-width: 320px; min-height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px;">
            <div style="text-align: center;">
                <div style="font-size: 20px; font-weight: 700; color: #333;">LAX</div>
                <div style="font-size: 10px; color: #666;">10:30 AM</div>
            </div>
            <div style="flex: 1; display: flex; flex-direction: column; align-items: center; margin: 0 12px;">
                <div style="font-size: 24px; color: {primary};">✈️</div>
                <div style="width: 100%; height: 2px; background: {primary}; margin: 4px 0;"></div>
                <div style="font-size: 9px; color: #666;">2h 45m • Direct</div>
            </div>
            <div style="text-align: center;">
                <div style="font-size: 20px; font-weight: 700; color: #333;">JFK</div>
                <div style="font-size: 10px; color: #666;">1:15 PM</div>
            </div>
        </div>
        <div style="display: flex; justify-content: space-between; align-items: center;">
            <div style="font-size: 11px; color: #666;">Delta Airlines</div>
            <div style="font-weight: 700; font-size: 18px; color: {primary};">$299</div>
        </div>
        """
    elif card_id == "hotel_listing":
        base_style = "width: 100%; max-width: 280px; min-height: 240px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: linear-gradient(135deg, {primary}, {secondary}); height: 140px; display: flex; align-items: center; justify-content: center; font-size: 56px; color: white;">🏨</div>
        <div style="padding: 12px;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Grand Hotel Downtown</div>
            <div style="color: #FFB800; font-size: 11px; margin-bottom: 6px;">⭐⭐⭐⭐⭐</div>
            <div style="font-size: 10px; color: #666; margin-bottom: 8px;">📍 Times Square, New York • WiFi, Pool, Gym</div>
            <div style="display: flex; justify-content: space-between; align-items: center;">
                <div style="font-size: 10px; color: #666;">per night</div>
                <div style="font-weight: 700; font-size: 18px; color: {primary};">$189</div>
            </div>
        </div>
        """
    elif card_id == "booking_confirm":
        base_style = "width: 100%; max-width: 300px; min-height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="text-align: center; margin-bottom: 16px;">
            <div style="font-weight: 700; font-size: 14px; color: {primary}; margin-bottom: 8px;">Booking Confirmed</div>
            <div style="font-size: 11px; color: #666;">ID: BK-12345678</div>
        </div>
        <div style="background: #f5f5f5; border-radius: 8px; padding: 12px; margin-bottom: 12px; font-size: 11px;">
            <div style="margin-bottom: 6px;"><strong>Grand Hotel</strong></div>
            <div style="color: #666;">Check-in: Dec 20, 2024</div>
            <div style="color: #666;">Check-out: Dec 22, 2024</div>
            <div style="color: #666;">2 Guests • 1 Room</div>
        </div>
        <div style="text-align: center;">
            <div style="width: 120px; height: 120px; background: white; border: 2px solid #ddd; border-radius: 8px; display: flex; align-items: center; justify-content: center; margin: 0 auto; font-size: 80px;">⬛</div>
        </div>
        """
    elif card_id == "destination_card":
        base_style = "width: 100%; max-width: 240px; height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); position: relative;"
        content = f"""
        <div style="position: absolute; inset: 0; background: linear-gradient(135deg, {primary}, {secondary});"></div>
        <div style="position: absolute; top: 8px; right: 8px; background: #FF3B30; color: white; padding: 4px 10px; border-radius: 12px; font-size: 9px; font-weight: 700;">HOT DEAL</div>
        <div style="position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(to top, rgba(0,0,0,0.8), transparent); padding: 16px; color: white;">
            <div style="font-size: 24px; margin-bottom: 4px;">🗼</div>
            <div style="font-weight: 700; font-size: 16px; margin-bottom: 2px;">Paris</div>
            <div style="font-size: 10px; opacity: 0.9;">France • From $599</div>
        </div>
        """
    elif card_id == "itinerary_day":
        base_style = "width: 100%; max-width: 300px; min-height: 180px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 14px;">Day 2 - Paris</div>
        <div style="display: flex; flex-direction: column; gap: 12px;">
            <div style="display: flex; gap: 10px;">
                <div style="font-size: 11px; color: #666; width: 50px;">09:00</div>
                <div>
                    <div style="font-weight: 600; font-size: 12px; color: #333;">Eiffel Tower</div>
                    <div style="font-size: 10px; color: #666;">📍 Champ de Mars</div>
                </div>
            </div>
            <div style="display: flex; gap: 10px;">
                <div style="font-size: 11px; color: #666; width: 50px;">13:00</div>
                <div>
                    <div style="font-weight: 600; font-size: 12px; color: #333;">Louvre Museum</div>
                    <div style="font-size: 10px; color: #666;">📍 Rue de Rivoli</div>
                </div>
            </div>
            <div style="display: flex; gap: 10px;">
                <div style="font-size: 11px; color: #666; width: 50px;">19:00</div>
                <div>
                    <div style="font-weight: 600; font-size: 12px; color: #333;">Seine River Cruise</div>
                    <div style="font-size: 10px; color: #666;">📍 Port de la Bourdonnais</div>
                </div>
            </div>
        </div>
        """
    elif card_id == "map_location":
        base_style = "width: 100%; max-width: 280px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; gap: 12px;"
        content = f"""
        <div style="width: 72px; height: 72px; border-radius: 10px; background: {primary}20; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 36px;">📍</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Central Park</div>
            <div style="font-size: 10px; color: #666; margin-bottom: 6px;">5th Ave, New York, NY</div>
            <div style="font-size: 11px; color: {primary}; font-weight: 600;">2.5 km away</div>
        </div>
        <button style="width: 40px; height: 40px; border-radius: 50%; background: {primary}; color: white; border: none; font-size: 18px;">→</button>
        """
    elif card_id == "travel_review":
        base_style = "width: 100%; max-width: 280px; min-height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px;"
        content = f"""
        <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
            <div style="width: 40px; height: 40px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px;">👤</div>
            <div style="flex: 1;">
                <div style="font-weight: 700; font-size: 12px; color: #333;">Maria Garcia</div>
                <div style="color: #FFB800; font-size: 11px;">⭐⭐⭐⭐⭐</div>
            </div>
        </div>
        <div style="font-size: 11px; color: #666; line-height: 1.4; margin-bottom: 8px;">"Amazing experience! The hotel was perfect and the location was great."</div>
        <div style="font-size: 10px; color: #999;">📷 3 photos • 👍 24 helpful • 2 weeks ago</div>
        """
    elif card_id == "passport_info":
        base_style = "width: 100%; max-width: 280px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Passport</div>
            <div style="font-size: 28px;">📘</div>
        </div>
        <div style="font-size: 11px; color: #666; margin-bottom: 4px;">Number: <strong>A12345678</strong></div>
        <div style="font-size: 11px; color: #666; margin-bottom: 4px;">Nationality: United States</div>
        <div style="font-size: 11px; color: #FF3B30; font-weight: 600;">Expires: Mar 15, 2025</div>
        """
    elif card_id == "menu_item":
        base_style = "width: 100%; max-width: 280px; min-height: 240px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: #f5f5f5; height: 140px; display: flex; align-items: center; justify-content: center; font-size: 64px;">🍔</div>
        <div style="padding: 12px;">
            <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 6px;">Classic Burger</div>
            <div style="font-size: 11px; color: #666; line-height: 1.4; margin-bottom: 10px;">Beef patty, lettuce, tomato, cheese, special sauce</div>
            <div style="display: flex; justify-content: space-between; align-items: center;">
                <div style="font-weight: 700; font-size: 18px; color: {primary};">$12.99</div>
                <button style="background: {primary}; color: white; border: none; padding: 8px 16px; border-radius: 8px; font-size: 11px; font-weight: 600;">Add to Cart</button>
            </div>
        </div>
        """
    elif card_id == "recipe_card":
        base_style = "width: 100%; max-width: 280px; min-height: 260px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: linear-gradient(135deg, {primary}, {secondary}); height: 140px; display: flex; align-items: center; justify-content: center; font-size: 64px; color: white;">🍝</div>
        <div style="padding: 14px;">
            <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 8px;">Spaghetti Carbonara</div>
            <div style="display: flex; gap: 16px; font-size: 11px; color: #666; margin-bottom: 10px;">
                <div>⏱️ 25 min</div>
                <div>👨‍🍳 Medium</div>
                <div>🍽️ 4 servings</div>
            </div>
            <div style="display: flex; align-items: center; gap: 6px;">
                <div style="color: #FFB800; font-size: 11px;">⭐⭐⭐⭐⭐</div>
                <div style="font-size: 10px; color: #666;">(2.5K reviews)</div>
            </div>
        </div>
        """
    elif card_id == "order_item":
        base_style = "width: 100%; max-width: 300px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; gap: 12px;"
        content = f"""
        <div style="width: 76px; height: 76px; border-radius: 8px; background: #f5f5f5; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 40px;">🍕</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Margherita Pizza</div>
            <div style="font-size: 10px; color: #666; margin-bottom: 6px;">x2 • Large • Extra cheese</div>
            <div style="font-weight: 700; font-size: 16px; color: {primary};">$28.00</div>
        </div>
        """
    elif card_id == "reservation_slot":
        base_style = "width: 100%; max-width: 240px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; align-items: center; justify-content: space-between;"
        content = f"""
        <div>
            <div style="font-weight: 700; font-size: 18px; color: #333; margin-bottom: 4px;">7:30 PM</div>
            <div style="font-size: 11px; color: #666;">4 seats available</div>
        </div>
        <button style="background: {primary}; color: white; border: none; padding: 10px 20px; border-radius: 8px; font-size: 12px; font-weight: 600;">Book</button>
        """
    elif card_id == "delivery_tracker":
        base_style = "width: 100%; max-width: 300px; min-height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 14px;">Order #5678</div>
        <div style="background: {primary}20; border-radius: 10px; padding: 12px; margin-bottom: 12px;">
            <div style="font-weight: 600; font-size: 13px; color: {primary}; margin-bottom: 6px;">🚗 Out for Delivery</div>
            <div style="font-size: 11px; color: #666;">Your order will arrive in 15-20 minutes</div>
        </div>
        <div style="display: flex; align-items: center; gap: 10px;">
            <div style="width: 44px; height: 44px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 22px;">👤</div>
            <div>
                <div style="font-weight: 600; font-size: 12px; color: #333;">John Driver</div>
                <div style="font-size: 10px; color: #666;">⭐ 4.9 • 245 deliveries</div>
            </div>
        </div>
        """
    elif card_id == "restaurant_rating":
        base_style = "width: 100%; max-width: 260px; height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="text-align: center; margin-bottom: 12px;">
            <div style="font-size: 32px; font-weight: 700; color: {primary}; margin-bottom: 4px;">4.5</div>
            <div style="color: #FFB800; font-size: 14px; margin-bottom: 4px;">⭐⭐⭐⭐⭐</div>
            <div style="font-size: 10px; color: #666;">Based on 1,234 reviews</div>
        </div>
        <div style="display: flex; justify-content: space-around; font-size: 10px;">
            <div style="text-align: center;">
                <div style="font-weight: 700; color: #333;">4.6</div>
                <div style="color: #666;">Food</div>
            </div>
            <div style="text-align: center;">
                <div style="font-weight: 700; color: #333;">4.4</div>
                <div style="color: #666;">Service</div>
            </div>
            <div style="text-align: center;">
                <div style="font-weight: 700; color: #333;">4.5</div>
                <div style="color: #666;">Ambience</div>
            </div>
        </div>
        """
    elif card_id == "ingredient_list":
        base_style = "width: 100%; max-width: 260px; height: 60px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <input type="checkbox" style="width: 20px; height: 20px; accent-color: {primary};">
        <div style="flex: 1;">
            <div style="font-weight: 600; font-size: 12px; color: #333;">Tomatoes</div>
            <div style="font-size: 10px; color: #666;">4 medium</div>
        </div>
        """
    elif card_id == "dietary_tag":
        base_style = "width: 100%; max-width: 100px; height: 32px; border-radius: 16px; overflow: hidden; box-shadow: 0 2px 4px rgba(0,0,0,0.1); background: #34C759; color: white; padding: 0 12px; display: flex; align-items: center; justify-content: center; gap: 4px;"
        content = f"""
        <span style="font-size: 14px;">🌱</span>
        <span style="font-size: 11px; font-weight: 600;">Vegan</span>
        """
    elif card_id == "property_listing":
        base_style = "width: 100%; max-width: 300px; min-height: 280px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: linear-gradient(135deg, {primary}, {secondary}); height: 160px; display: flex; align-items: center; justify-content: center; font-size: 64px; color: white;">🏠</div>
        <div style="padding: 14px;">
            <div style="font-weight: 700; font-size: 16px; color: {primary}; margin-bottom: 6px;">$425,000</div>
            <div style="font-weight: 600; font-size: 13px; color: #333; margin-bottom: 6px;">Modern Downtown Apartment</div>
            <div style="font-size: 11px; color: #666; margin-bottom: 8px;">📍 123 Main St, New York</div>
            <div style="display: flex; gap: 12px; font-size: 11px; color: #666;">
                <div>🛏️ 2 beds</div>
                <div>🚿 2 baths</div>
                <div>📐 1,200 sqft</div>
            </div>
        </div>
        """
    elif card_id == "agent_card":
        base_style = "width: 100%; max-width: 240px; min-height: 180px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 10px;"
        content = f"""
        <div style="width: 80px; height: 80px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 40px;">👤</div>
        <div style="text-align: center;">
            <div style="font-weight: 700; font-size: 14px; color: #333;">Sarah Johnson</div>
            <div style="font-size: 11px; color: #666; margin-top: 2px;">Real Estate Agent</div>
        </div>
        <div style="font-size: 11px; color: #666; text-align: center;">245 properties sold • ⭐ 4.9</div>
        <button style="width: 100%; background: {primary}; color: white; border: none; padding: 10px; border-radius: 8px; font-size: 12px; font-weight: 600;">Contact</button>
        """
    elif card_id == "virtual_tour":
        base_style = "width: 100%; max-width: 240px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: linear-gradient(135deg, {primary}, {secondary}); padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: white;"
        content = f"""
        <div style="font-size: 48px;">🔄</div>
        <div style="font-weight: 700; font-size: 14px;">360° Virtual Tour</div>
        <div style="font-size: 11px; opacity: 0.9;">Living Room</div>
        <button style="background: white; color: {primary}; border: none; padding: 8px 20px; border-radius: 8px; font-size: 11px; font-weight: 600;">View Tour</button>
        """
    elif card_id == "mortgage_calc":
        base_style = "width: 100%; max-width: 280px; min-height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 14px;">Mortgage Calculator</div>
        <div style="display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px;">
            <div style="display: flex; justify-content: space-between; font-size: 11px;">
                <span style="color: #666;">Loan Amount</span>
                <span style="font-weight: 700; color: #333;">$340,000</span>
            </div>
            <div style="display: flex; justify-content: space-between; font-size: 11px;">
                <span style="color: #666;">Interest Rate</span>
                <span style="font-weight: 700; color: #333;">6.5%</span>
            </div>
            <div style="display: flex; justify-content: space-between; font-size: 11px;">
                <span style="color: #666;">Term</span>
                <span style="font-weight: 700; color: #333;">30 years</span>
            </div>
        </div>
        <div style="background: {primary}10; border-radius: 8px; padding: 12px; text-align: center;">
            <div style="font-size: 10px; color: #666; margin-bottom: 4px;">Monthly Payment</div>
            <div style="font-size: 24px; font-weight: 700; color: {primary};">$2,148</div>
        </div>
        """
    elif card_id == "property_compare":
        base_style = "width: 100%; max-width: 320px; min-height: 180px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 14px;">Property Comparison</div>
        <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px;">
            <div style="background: #f5f5f5; border-radius: 8px; padding: 10px;">
                <div style="font-weight: 600; font-size: 12px; color: #333; margin-bottom: 8px;">Property A</div>
                <div style="font-size: 10px; color: #666; margin-bottom: 3px;">$425,000</div>
                <div style="font-size: 10px; color: #666; margin-bottom: 3px;">2 beds • 2 baths</div>
                <div style="font-size: 10px; color: #666;">1,200 sqft</div>
            </div>
            <div style="background: {primary}10; border-radius: 8px; padding: 10px; border: 2px solid {primary};">
                <div style="font-weight: 600; font-size: 12px; color: #333; margin-bottom: 8px;">Property B</div>
                <div style="font-size: 10px; color: #666; margin-bottom: 3px;">$399,000</div>
                <div style="font-size: 10px; color: #666; margin-bottom: 3px;">2 beds • 1 bath</div>
                <div style="font-size: 10px; color: #666;">1,100 sqft</div>
            </div>
        </div>
        """
    elif card_id == "favorite_property":
        base_style = "width: 100%; max-width: 280px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; gap: 12px;"
        content = f"""
        <div style="width: 76px; height: 76px; border-radius: 8px; background: {primary}20; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 36px;">🏠</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">$425,000</div>
            <div style="font-size: 11px; color: #666; margin-bottom: 6px;">123 Main St, NY</div>
            <div style="font-size: 10px; color: #666;">2 beds • 2 baths</div>
        </div>
        <button style="color: #FF3B30; background: transparent; border: none; font-size: 24px;">❤️</button>
        """
    elif card_id == "open_house":
        base_style = "width: 100%; max-width: 260px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 10px;">
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333;">Open House</div>
                <div style="font-size: 11px; color: #666; margin-top: 4px;">Saturday, Dec 21</div>
                <div style="font-size: 11px; color: #666;">10:00 AM - 2:00 PM</div>
            </div>
            <div style="font-size: 32px;">🏠</div>
        </div>
        <div style="font-size: 10px; color: #666;">📍 123 Oak Street, Brooklyn</div>
        """
    elif card_id == "playlist_card":
        base_style = "width: 100%; max-width: 200px; min-height: 240px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: linear-gradient(135deg, {primary}, {secondary}); height: 160px; display: flex; align-items: center; justify-content: center; font-size: 64px; color: white;">🎵</div>
        <div style="padding: 12px;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Chill Vibes</div>
            <div style="font-size: 10px; color: #666; margin-bottom: 8px;">Created by Spotify • 50 songs</div>
            <button style="width: 100%; background: {primary}; color: white; border: none; padding: 10px; border-radius: 8px; font-size: 12px; font-weight: 600;">▶️ Play</button>
        </div>
        """
    elif card_id == "song_item":
        base_style = "width: 100%; max-width: 300px; height: 72px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 48px; height: 48px; border-radius: 6px; background: {primary}; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px;">🎵</div>
        <div style="flex: 1; min-width: 0;">
            <div style="font-weight: 700; font-size: 13px; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">Blinding Lights</div>
            <div style="font-size: 10px; color: #666;">The Weeknd</div>
        </div>
        <div style="font-size: 11px; color: #666;">3:20</div>
        <button style="color: #666; background: transparent; border: none; font-size: 18px;">⋮</button>
        """
    elif card_id == "album_cover":
        base_style = "width: 100%; max-width: 200px; height: 240px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; flex-direction: column; gap: 10px;"
        content = f"""
        <div style="width: 176px; height: 176px; border-radius: 8px; background: linear-gradient(135deg, {primary}, {secondary}); display: flex; align-items: center; justify-content: center; color: white; font-size: 64px;">💿</div>
        <div>
            <div style="font-weight: 700; font-size: 13px; color: #333;">After Hours</div>
            <div style="font-size: 11px; color: #666;">The Weeknd • 2020</div>
        </div>
        """
    elif card_id == "artist_profile":
        base_style = "width: 100%; max-width: 240px; min-height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 10px;"
        content = f"""
        <div style="width: 100px; height: 100px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 48px;">🎤</div>
        <div style="text-align: center;">
            <div style="font-weight: 700; font-size: 16px; color: #333;">The Weeknd</div>
            <div style="font-size: 11px; color: #666; margin-top: 4px;">85M monthly listeners</div>
        </div>
        <button style="width: 100%; background: {primary}; color: white; border: none; padding: 10px; border-radius: 20px; font-size: 12px; font-weight: 600;">Follow</button>
        """
    elif card_id == "podcast_episode":
        base_style = "width: 100%; max-width: 300px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; gap: 12px;"
        content = f"""
        <div style="width: 76px; height: 76px; border-radius: 8px; background: {primary}; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 36px;">🎙️</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Episode 42: Future of AI</div>
            <div style="font-size: 10px; color: #666; margin-bottom: 6px;">Dec 15, 2024 • 45 min</div>
            <button style="background: {primary}; color: white; border: none; padding: 6px 16px; border-radius: 6px; font-size: 11px; font-weight: 600;">▶️ Play</button>
        </div>
        """
    elif card_id == "radio_station":
        base_style = "width: 100%; max-width: 200px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;"
        content = f"""
        <div style="width: 60px; height: 60px; border-radius: 50%; background: {primary}; display: flex; align-items: center; justify-content: center; color: white; font-size: 28px;">📻</div>
        <div style="text-align: center;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">Pop Hits Radio</div>
            <div style="font-size: 10px; color: #666; margin-top: 2px;">Now: Blinding Lights</div>
        </div>
        <button style="width: 100%; background: {primary}; color: white; border: none; padding: 8px; border-radius: 8px; font-size: 11px; font-weight: 600;">Tune In</button>
        """
    elif card_id == "equalizer_preset":
        base_style = "width: 100%; max-width: 240px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 12px;">Bass Boost</div>
        <div style="display: flex; align-items: end; justify-content: space-around; gap: 4px; height: 60px; margin-bottom: 12px;">
            <div style="width: 16px; background: {primary}; height: 100%; border-radius: 8px 8px 0 0;"></div>
            <div style="width: 16px; background: {primary}; opacity: 0.8; height: 85%; border-radius: 8px 8px 0 0;"></div>
            <div style="width: 16px; background: {primary}; opacity: 0.6; height: 60%; border-radius: 8px 8px 0 0;"></div>
            <div style="width: 16px; background: {primary}; opacity: 0.5; height: 50%; border-radius: 8px 8px 0 0;"></div>
            <div style="width: 16px; background: {primary}; opacity: 0.4; height: 45%; border-radius: 8px 8px 0 0;"></div>
            <div style="width: 16px; background: {primary}; opacity: 0.5; height: 55%; border-radius: 8px 8px 0 0;"></div>
        </div>
        <button style="width: 100%; background: {primary}; color: white; border: none; padding: 8px; border-radius: 8px; font-size: 11px; font-weight: 600;">Apply</button>
        """
    elif card_id == "achievement_badge":
        base_style = "width: 100%; max-width: 160px; height: 180px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;"
        content = f"""
        <div style="width: 80px; height: 80px; border-radius: 50%; background: linear-gradient(135deg, #FFD700, #FFA500); display: flex; align-items: center; justify-content: center; font-size: 40px; box-shadow: 0 4px 12px rgba(255,215,0,0.4);">🏆</div>
        <div style="text-align: center;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">First Victory</div>
            <div style="font-size: 10px; color: #666; margin-top: 4px;">100 points</div>
        </div>
        <div style="font-size: 9px; color: #999;">Unlocked: Dec 15, 2024</div>
        """
    elif card_id == "leaderboard_entry":
        base_style = "width: 100%; max-width: 300px; height: 72px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 36px; height: 36px; border-radius: 50%; background: {primary}; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px; font-weight: 700;">1</div>
        <div style="width: 40px; height: 40px; border-radius: 50%; background: {primary}20; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 20px;">👤</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333;">ProGamer123</div>
            <div style="font-size: 10px; color: #666;">Level 45</div>
        </div>
        <div style="font-weight: 700; font-size: 16px; color: {primary};">12,458</div>
        <div style="font-size: 11px; color: #34C759;">↗ +2</div>
        """
    elif card_id == "character_card":
        base_style = "width: 100%; max-width: 200px; min-height: 280px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white;"
        content = f"""
        <div style="background: linear-gradient(135deg, {primary}, {secondary}); height: 160px; display: flex; align-items: center; justify-content: center; font-size: 80px; color: white;">⚔️</div>
        <div style="padding: 14px;">
            <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 6px;">Warrior</div>
            <div style="font-size: 11px; color: #666; margin-bottom: 10px;">Level 24 • Epic</div>
            <div style="display: flex; flex-direction: column; gap: 6px; font-size: 10px; color: #666;">
                <div>⚡ Attack: 85</div>
                <div>🛡️ Defense: 72</div>
                <div>❤️ Health: 450</div>
            </div>
        </div>
        """
    elif card_id == "game_item":
        base_style = "width: 100%; max-width: 140px; height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 8px;"
        content = f"""
        <div style="width: 80px; height: 80px; border-radius: 10px; background: linear-gradient(135deg, #9333EA, #C026D3); display: flex; align-items: center; justify-content: center; font-size: 40px;">⚔️</div>
        <div style="text-align: center;">
            <div style="font-weight: 700; font-size: 12px; color: #333;">Legendary Sword</div>
            <div style="background: #9333EA; color: white; padding: 2px 8px; border-radius: 10px; font-size: 9px; font-weight: 600; margin-top: 4px;">LEGENDARY</div>
        </div>
        <div style="font-size: 11px; color: #666;">Quantity: 1</div>
        """
    elif card_id == "quest_card":
        base_style = "width: 100%; max-width: 280px; min-height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px;"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 10px;">
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Defeat the Dragon</div>
                <div style="font-size: 10px; color: #666;">Slay the ancient dragon in the Dark Cave</div>
            </div>
            <div style="font-size: 32px;">🐉</div>
        </div>
        <div style="margin-bottom: 8px;">
            <div style="display: flex; justify-content: space-between; font-size: 11px; color: #666; margin-bottom: 4px;">
                <span>Progress</span>
                <span style="font-weight: 700; color: #333;">3/5 defeated</span>
            </div>
            <div style="height: 6px; background: #f0f0f0; border-radius: 3px; overflow: hidden;">
                <div style="width: 60%; height: 100%; background: {primary}; border-radius: 3px;"></div>
            </div>
        </div>
        <div style="font-size: 11px; color: {primary}; font-weight: 600;">Reward: 500 Gold, Epic Armor</div>
        """
    elif card_id == "player_stats":
        base_style = "width: 100%; max-width: 260px; min-height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 12px;">Player Stats</div>
        <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;">
            <div style="font-size: 11px; color: #666;">Level 45</div>
            <div style="font-weight: 700; font-size: 14px; color: {primary};">12,458 XP</div>
        </div>
        <div style="height: 8px; background: #f0f0f0; border-radius: 4px; overflow: hidden; margin-bottom: 14px;">
            <div style="width: 65%; height: 100%; background: {primary}; border-radius: 4px;"></div>
        </div>
        <div style="display: flex; justify-content: space-around; font-size: 11px;">
            <div style="text-align: center;">
                <div style="font-weight: 700; color: #333;">3.5</div>
                <div style="color: #666;">K/D Ratio</div>
            </div>
            <div style="text-align: center;">
                <div style="font-weight: 700; color: #333;">68%</div>
                <div style="color: #666;">Win Rate</div>
            </div>
        </div>
        """
    elif card_id == "task_item":
        base_style = "width: 100%; max-width: 280px; height: 60px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <input type="checkbox" style="width: 20px; height: 20px; accent-color: {primary};">
        <div style="flex: 1; min-width: 0;">
            <div style="font-weight: 600; font-size: 13px; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">Finish project proposal</div>
            <div style="font-size: 10px; color: #666;">Due: Tomorrow • High priority</div>
        </div>
        """
    elif card_id == "note_card":
        base_style = "width: 100%; max-width: 220px; min-height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: #FFF9C4; padding: 14px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 8px;">Meeting Notes</div>
        <div style="font-size: 11px; color: #666; line-height: 1.4; margin-bottom: 10px;">Discussed Q4 strategy and team goals. Follow up with marketing...</div>
        <div style="display: flex; gap: 6px; margin-bottom: 8px;">
            <div style="background: rgba(0,0,0,0.1); color: #666; padding: 3px 8px; border-radius: 10px; font-size: 9px;">work</div>
            <div style="background: rgba(0,0,0,0.1); color: #666; padding: 3px 8px; border-radius: 10px; font-size: 9px;">important</div>
        </div>
        <div style="font-size: 9px; color: #999;">Dec 15, 2024</div>
        """
    elif card_id == "reminder_alert":
        base_style = "width: 100%; max-width: 280px; height: 80px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 44px; height: 44px; border-radius: 50%; background: {primary}20; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: {primary}; font-size: 24px;">🔔</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 4px;">Team Meeting</div>
            <div style="font-size: 10px; color: #666;">in 15 minutes</div>
        </div>
        <div style="display: flex; gap: 6px;">
            <button style="background: #f5f5f5; color: #666; border: none; padding: 6px 10px; border-radius: 6px; font-size: 10px; font-weight: 600;">Snooze</button>
            <button style="background: {primary}; color: white; border: none; padding: 6px 10px; border-radius: 6px; font-size: 10px; font-weight: 600;">OK</button>
        </div>
        """
    elif card_id == "timer_widget":
        base_style = "width: 100%; max-width: 180px; height: 180px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;"
        content = f"""
        <div style="width: 120px; height: 120px; border-radius: 50%; border: 8px solid {primary}20; border-top-color: {primary}; display: flex; align-items: center; justify-content: center;">
            <div style="font-size: 28px; font-weight: 700; color: #333;">15:00</div>
        </div>
        <div style="display: flex; gap: 10px;">
            <button style="width: 40px; height: 40px; border-radius: 50%; background: {primary}; color: white; border: none; font-size: 18px;">▶️</button>
            <button style="width: 40px; height: 40px; border-radius: 50%; background: #f5f5f5; color: #666; border: none; font-size: 18px;">⟳</button>
        </div>
        """
    elif card_id == "calendar_event":
        base_style = "width: 100%; max-width: 280px; height: 90px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 14px; border-left: 4px solid {primary};"
        content = f"""
        <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 8px;">
            <div>
                <div style="font-weight: 700; font-size: 13px; color: #333;">Product Launch Meeting</div>
                <div style="font-size: 11px; color: #666; margin-top: 4px;">⏱️ 2:00 PM - 3:30 PM</div>
            </div>
        </div>
        <div style="font-size: 10px; color: #666;">📍 Conference Room A • 👥 8 attendees</div>
        """
    elif card_id == "project_card":
        base_style = "width: 100%; max-width: 280px; min-height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 14px; color: #333; margin-bottom: 10px;">Website Redesign</div>
        <div style="display: flex; align-items: center; gap: 8px; margin-bottom: 12px;">
            <div style="display: flex; margin-left: -8px;">
                <div style="width: 28px; height: 28px; border-radius: 50%; background: {primary}; border: 2px solid white; display: flex; align-items: center; justify-content: center; font-size: 14px; color: white;">A</div>
                <div style="width: 28px; height: 28px; border-radius: 50%; background: {secondary}; border: 2px solid white; margin-left: -8px; display: flex; align-items: center; justify-content: center; font-size: 14px; color: white;">B</div>
                <div style="width: 28px; height: 28px; border-radius: 50%; background: #999; border: 2px solid white; margin-left: -8px; display: flex; align-items: center; justify-content: center; font-size: 10px; color: white;">+3</div>
            </div>
            <div style="font-size: 10px; color: #666;">5 members</div>
        </div>
        <div style="margin-bottom: 8px;">
            <div style="display: flex; justify-content: space-between; font-size: 11px; color: #666; margin-bottom: 4px;">
                <span>Progress</span>
                <span style="font-weight: 700; color: {primary};">75%</span>
            </div>
            <div style="height: 6px; background: #f0f0f0; border-radius: 3px; overflow: hidden;">
                <div style="width: 75%; height: 100%; background: {primary}; border-radius: 3px;"></div>
            </div>
        </div>
        <div style="font-size: 10px; color: #666;">Deadline: Dec 31, 2024</div>
        """
    elif card_id == "kpi_card":
        base_style = "width: 100%; max-width: 200px; height: 120px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px; display: flex; flex-direction: column; justify-content: space-between;"
        content = f"""
        <div style="font-size: 11px; color: #666; margin-bottom: 4px;">Revenue</div>
        <div style="font-size: 32px; font-weight: 700; color: #333; margin-bottom: 4px;">$124K</div>
        <div style="display: flex; align-items: center; gap: 6px;">
            <div style="font-size: 18px; color: #34C759;">↗</div>
            <div style="font-size: 13px; font-weight: 600; color: #34C759;">+12.5%</div>
        </div>
        """
    elif card_id == "pie_chart":
        base_style = "width: 100%; max-width: 240px; height: 200px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 12px;">Sales by Category</div>
        <div style="display: flex; justify-content: center; margin-bottom: 12px;">
            <div style="width: 100px; height: 100px; border-radius: 50%; background: conic-gradient({primary} 0% 40%, {secondary} 40% 75%, #FFB800 75% 100%);"></div>
        </div>
        <div style="display: flex; flex-direction: column; gap: 6px; font-size: 10px;">
            <div style="display: flex; align-items: center; gap: 6px;">
                <div style="width: 12px; height: 12px; border-radius: 2px; background: {primary};"></div>
                <span style="color: #666;">Electronics</span>
                <span style="margin-left: auto; font-weight: 700; color: #333;">40%</span>
            </div>
            <div style="display: flex; align-items: center; gap: 6px;">
                <div style="width: 12px; height: 12px; border-radius: 2px; background: {secondary};"></div>
                <span style="color: #666;">Clothing</span>
                <span style="margin-left: auto; font-weight: 700; color: #333;">35%</span>
            </div>
            <div style="display: flex; align-items: center; gap: 6px;">
                <div style="width: 12px; height: 12px; border-radius: 2px; background: #FFB800;"></div>
                <span style="color: #666;">Others</span>
                <span style="margin-left: auto; font-weight: 700; color: #333;">25%</span>
            </div>
        </div>
        """
    elif card_id == "line_graph":
        base_style = "width: 100%; max-width: 300px; height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 12px;">Monthly Revenue</div>
        <div style="position: relative; height: 80px; margin-bottom: 10px;">
            <svg viewBox="0 0 240 80" style="width: 100%; height: 100%;">
                <polyline points="0,60 40,45 80,50 120,30 160,35 200,15 240,20" fill="none" stroke="{primary}" stroke-width="3" />
                <polyline points="0,80 0,60 40,45 80,50 120,30 160,35 200,15 240,20 240,80" fill="{primary}" fill-opacity="0.1" />
            </svg>
        </div>
        <div style="display: flex; justify-content: space-between; font-size: 9px; color: #999;">
            <span>Jan</span>
            <span>Feb</span>
            <span>Mar</span>
            <span>Apr</span>
            <span>May</span>
            <span>Jun</span>
        </div>
        """
    elif card_id == "bar_chart":
        base_style = "width: 100%; max-width: 260px; height: 160px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 12px;">Weekly Activity</div>
        <div style="display: flex; align-items: end; justify-content: space-around; gap: 8px; height: 80px; margin-bottom: 10px;">
            <div style="display: flex; flex-direction: column; align-items: center; gap: 4px;">
                <div style="width: 24px; background: {primary}; opacity: 0.5; height: 40%; border-radius: 4px 4px 0 0;"></div>
                <div style="font-size: 9px; color: #666;">Mon</div>
            </div>
            <div style="display: flex; flex-direction: column; align-items: center; gap: 4px;">
                <div style="width: 24px; background: {primary}; opacity: 0.6; height: 60%; border-radius: 4px 4px 0 0;"></div>
                <div style="font-size: 9px; color: #666;">Tue</div>
            </div>
            <div style="display: flex; flex-direction: column; align-items: center; gap: 4px;">
                <div style="width: 24px; background: {primary}; height: 100%; border-radius: 4px 4px 0 0;"></div>
                <div style="font-size: 9px; color: #666;">Wed</div>
            </div>
            <div style="display: flex; flex-direction: column; align-items: center; gap: 4px;">
                <div style="width: 24px; background: {primary}; opacity: 0.7; height: 75%; border-radius: 4px 4px 0 0;"></div>
                <div style="font-size: 9px; color: #666;">Thu</div>
            </div>
            <div style="display: flex; flex-direction: column; align-items: center; gap: 4px;">
                <div style="width: 24px; background: {primary}; opacity: 0.8; height: 85%; border-radius: 4px 4px 0 0;"></div>
                <div style="font-size: 9px; color: #666;">Fri</div>
            </div>
        </div>
        """
    elif card_id == "metric_alert":
        base_style = "width: 100%; max-width: 280px; height: 100px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: #FFF3CD; border: 1px solid #FFE69C; padding: 14px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 44px; height: 44px; border-radius: 50%; background: #FFB800; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 24px;">⚠️</div>
        <div style="flex: 1;">
            <div style="font-weight: 700; font-size: 13px; color: #856404; margin-bottom: 4px;">High CPU Usage</div>
            <div style="font-size: 11px; color: #856404;">Server load at 92% - exceeds threshold</div>
        </div>
        <button style="background: transparent; color: #856404; border: 1px solid #856404; padding: 6px 12px; border-radius: 6px; font-size: 10px; font-weight: 600;">View</button>
        """
    elif card_id == "summary_widget":
        base_style = "width: 100%; max-width: 300px; min-height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 12px;">Summary • Last 7 days</div>
        <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px;">
            <div>
                <div style="font-size: 20px; font-weight: 700; color: {primary}; margin-bottom: 2px;">2,458</div>
                <div style="font-size: 10px; color: #666;">Users</div>
            </div>
            <div>
                <div style="font-size: 20px; font-weight: 700; color: {primary}; margin-bottom: 2px;">$12.5K</div>
                <div style="font-size: 10px; color: #666;">Revenue</div>
            </div>
            <div>
                <div style="font-size: 20px; font-weight: 700; color: {primary}; margin-bottom: 2px;">98.5%</div>
                <div style="font-size: 10px; color: #666;">Uptime</div>
            </div>
            <div>
                <div style="font-size: 20px; font-weight: 700; color: {primary}; margin-bottom: 2px;">4.8</div>
                <div style="font-size: 10px; color: #666;">Rating</div>
            </div>
        </div>
        """
    elif card_id == "activity_feed":
        base_style = "width: 100%; max-width: 300px; height: 72px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 12px; display: flex; align-items: center; gap: 12px;"
        content = f"""
        <div style="width: 40px; height: 40px; border-radius: 50%; background: {primary}20; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: {primary}; font-size: 20px;">✓</div>
        <div style="flex: 1;">
            <div style="font-size: 12px; color: #333; margin-bottom: 4px;"><strong>John Doe</strong> completed task <strong>"Design Review"</strong></div>
            <div style="font-size: 10px; color: #999;">2 hours ago</div>
        </div>
        """
    elif card_id == "heatmap_widget":
        base_style = "width: 100%; max-width: 300px; height: 140px; border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.1); background: white; padding: 16px;"
        content = f"""
        <div style="font-weight: 700; font-size: 13px; color: #333; margin-bottom: 10px;">Activity Heatmap</div>
        <div style="display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;">
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.2; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.4; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.6; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.3; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.8; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.5; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.7; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.4; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.9; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.6; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.3; border-radius: 2px;"></div>
            <div style="width: 14px; height: 14px; background: {primary}; opacity: 0.5; border-radius: 2px;"></div>
        </div>
        <div style="font-size: 9px; color: #999; margin-top: 8px;">Less activity ← → More activity</div>
        """

    else:
        content = "<div style='padding: 20px; color: #333;'>Card Preview</div>"

    return f"""
    <div style="{base_style}">
        {content}
    </div>
    """


def generate_background_gallery(theme_json: str = ""):
    """
    Generate HTML gallery of all 30 backgrounds organized by category
    Backgrounds are rendered directly with HTML/CSS using theme colors
    """
    from agents.flutter_screen_generator import FlutterScreenGenerator

    agent = FlutterScreenGenerator()
    catalog = agent.BACKGROUND_CATALOG

    # Parse theme or use defaults
    if theme_json and theme_json.strip():
        try:
            theme = json.loads(theme_json)
            palette = theme.get("palette", {})
            primary = palette.get("primary", "#007AFF")
            secondary = palette.get("secondary", "#5856D6")
            accent = palette.get("accent", "#FF9500")
            theme_name = theme.get("name", "Custom Theme")
            using_theme = True
        except:
            primary = "#007AFF"
            secondary = "#5856D6"
            accent = "#FF9500"
            theme_name = "Default"
            using_theme = False
    else:
        primary = "#007AFF"
        secondary = "#5856D6"
        accent = "#FF9500"
        theme_name = "Default"
        using_theme = False

    # Organize by category
    categories = {}
    for bg_id, info in catalog.items():
        cat = info['category']
        if cat not in categories:
            categories[cat] = []
        categories[cat].append((bg_id, info))

    theme_indicator = f"""
    <div style="background: #e7f3ff; padding: 12px; border-radius: 6px; margin-bottom: 16px; border-left: 4px solid {primary};">
        <strong>🎨 Tema applicato:</strong> {theme_name}<br/>
        <div style="display: flex; gap: 8px; margin-top: 8px; align-items: center;">
            <span style="font-size: 12px;">Colori:</span>
            <div style="width: 32px; height: 32px; border-radius: 4px; background: {primary}; border: 2px solid white; box-shadow: 0 2px 4px rgba(0,0,0,0.2);"></div>
            <div style="width: 32px; height: 32px; border-radius: 4px; background: {secondary}; border: 2px solid white; box-shadow: 0 2px 4px rgba(0,0,0,0.2);"></div>
            <div style="width: 32px; height: 32px; border-radius: 4px; background: {accent}; border: 2px solid white; box-shadow: 0 2px 4px rgba(0,0,0,0.2);"></div>
        </div>
    </div>
    """ if using_theme else """
    <div style="background: #fff3cd; padding: 12px; border-radius: 6px; margin-bottom: 16px; border-left: 4px solid #ffc107;">
        <strong>⚠️ Tema non applicato</strong><br/>
        <span style="font-size: 13px;">Inserisci un tema JSON sopra e clicca "Aggiorna con Tema Corrente" per vedere i background con i tuoi colori!</span>
    </div>
    """

    html_parts = [f"""
    <div style="background: #f5f5f5; padding: 20px; border-radius: 12px;">
        <h3 style="margin-top: 0;">🎨 Background Knowledge Base (30 Backgrounds)</h3>
        <p style="color: #666; margin-bottom: 12px;">Esplora tutti i background disponibili con i colori del tuo tema applicati automaticamente!</p>
        {theme_indicator}
    """]

    # Category order and icons
    category_config = {
        "gradients": {"icon": "🌈", "name": "Gradients", "desc": "Clean, modern backgrounds with color transitions"},
        "waves": {"icon": "🌊", "name": "Waves", "desc": "Dynamic, flowing backgrounds with movement"},
        "geometric": {"icon": "◼️", "name": "Geometric", "desc": "Modern patterns with shapes and structure"},
        "organic": {"icon": "🎨", "name": "Organic", "desc": "Creative, natural flowing shapes"},
        "patterns": {"icon": "📐", "name": "Patterns", "desc": "Structured, repeating design elements"},
        "abstract": {"icon": "✨", "name": "Abstract", "desc": "Premium, artistic compositions"}
    }

    for cat_key in ["gradients", "waves", "geometric", "organic", "patterns", "abstract"]:
        if cat_key not in categories:
            continue

        config = category_config.get(cat_key, {"icon": "•", "name": cat_key.title(), "desc": ""})
        items = categories[cat_key]

        html_parts.append(f"""
        <div style="background: white; padding: 16px; margin-bottom: 16px; border-radius: 8px; border-left: 4px solid #007AFF;">
            <h4 style="margin: 0 0 8px 0;">{config['icon']} {config['name']} ({len(items)})</h4>
            <p style="color: #666; font-size: 13px; margin: 0 0 12px 0;">{config['desc']}</p>
            <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px;">
        """)

        for bg_id, info in sorted(items, key=lambda x: x[0]):
            complexity_colors = {
                "simple": "#28a745",
                "medium": "#ffc107",
                "complex": "#dc3545"
            }
            complexity_color = complexity_colors.get(info['complexity'], "#6c757d")

            # Render background preview
            bg_preview = render_background_html(bg_id, info, primary, secondary, accent)

            html_parts.append(f"""
            <div style="background: white; padding: 12px; border-radius: 8px; border: 1px solid #dee2e6; display: flex; flex-direction: column; align-items: center; gap: 10px;">
                {bg_preview}
                <div style="width: 100%; text-align: center;">
                    <div style="font-weight: 600; font-size: 13px; margin-bottom: 4px;">{info['name']}</div>
                    <div style="font-size: 11px; color: #6c757d; margin-bottom: 6px;">
                        <code style="background: #e9ecef; padding: 2px 6px; border-radius: 3px; font-size: 10px;">{bg_id}</code>
                    </div>
                    <span style="background: {complexity_color}; color: white; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600;">
                        {info['complexity'].upper()}
                    </span>
                </div>
            </div>
            """)

        html_parts.append("</div></div>")

    html_parts.append("""
        <div style="margin-top: 20px; padding: 12px; background: #e7f3ff; border-radius: 6px; border-left: 3px solid #007AFF;">
            <p style="margin: 0; font-size: 13px; color: #004085;">
                <strong>💡 Anteprima Live:</strong> Tutti i 30 background sono renderizzati direttamente con i colori del tuo tema!
                Ogni preview mostra esattamente come apparirà il background nell'app con il tema selezionato.
                <br/><br/>
                <strong>📋 Per testare:</strong> Usa il selettore sotto per generare il codice Flutter/Dart completo di un background specifico
                e copiarlo su <a href="https://dartpad.dev" target="_blank" style="color: #007AFF; font-weight: 600;">DartPad</a> per vederlo in azione!
            </p>
        </div>
    </div>
    """)

    return "".join(html_parts)


def generate_header_gallery(theme_json: str = ""):
    """
    Generate HTML gallery of all 20 realistic headers
    Headers are rendered directly with HTML/CSS using theme colors
    """
    from agents.flutter_screen_generator import FlutterScreenGenerator

    agent = FlutterScreenGenerator()
    catalog = agent.HEADER_CATALOG

    # Parse theme or use defaults
    if theme_json and theme_json.strip():
        try:
            theme_data = json.loads(theme_json)
            palette = theme_data.get("palette", {})
            primary = palette.get("primary", "#2196F3")
            secondary = palette.get("secondary", "#FF9800")
            accent = palette.get("accent", "#4CAF50")
        except:
            primary = "#2196F3"
            secondary = "#FF9800"
            accent = "#4CAF50"
    else:
        primary = "#2196F3"
        secondary = "#FF9800"
        accent = "#4CAF50"

    # Start HTML
    html_parts = []
    html_parts.append("""
    <div style="background: #f8f9fa; padding: 24px; border-radius: 12px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;">
        <h3 style="margin-top: 0; color: #212529; font-size: 20px;">🎯 Header Catalog (20 Headers)</h3>
        <p style="color: #6c757d; font-size: 14px; margin-bottom: 24px;">
            20 header realistici con profilo, localizzazione, notifiche, cart e menu - renderizzati con i tuoi colori del tema
        </p>
    """)

    # Grid container
    html_parts.append("""
        <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; margin-top: 20px;">
    """)

    # Render each header
    for header_id, info in catalog.items():
        # Render header preview
        header_preview = render_header_html(header_id, info, primary, secondary, accent)

        # Complexity color
        complexity = info.get('complexity', 'simple')
        if complexity == "simple":
            complexity_color = "#28a745"
        elif complexity == "medium":
            complexity_color = "#ffc107"
        else:
            complexity_color = "#dc3545"

        html_parts.append(f"""
        <div style="background: white; padding: 16px; border-radius: 8px; border: 1px solid #dee2e6; display: flex; flex-direction: column; gap: 12px;">
            {header_preview}
            <div style="width: 100%; text-align: center;">
                <div style="font-weight: 600; font-size: 14px; margin-bottom: 4px;">{info['name']}</div>
                <div style="font-size: 11px; color: #6c757d; margin-bottom: 6px;">
                    <code style="background: #e9ecef; padding: 2px 6px; border-radius: 3px; font-size: 10px;">{header_id}</code>
                </div>
                <div style="font-size: 11px; color: #6c757d; margin-bottom: 6px;">{info['description']}</div>
                <span style="background: {complexity_color}; color: white; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600;">
                    {complexity.upper()}
                </span>
            </div>
        </div>
        """)

    html_parts.append("</div></div>")
    return "".join(html_parts)


def generate_footer_gallery(theme_json: str = ""):
    """
    Generate HTML gallery of all 30 footer layouts
    Footers are rendered directly with HTML/CSS using theme colors
    """
    from agents.flutter_screen_generator import FlutterScreenGenerator

    agent = FlutterScreenGenerator()
    catalog = agent.FOOTER_CATALOG

    # Parse theme or use defaults
    if theme_json and theme_json.strip():
        try:
            theme_data = json.loads(theme_json)
            palette = theme_data.get("palette", {})
            primary = palette.get("primary", "#2196F3")
            secondary = palette.get("secondary", "#FF9800")
            accent = palette.get("accent", "#4CAF50")
        except:
            primary = "#2196F3"
            secondary = "#FF9800"
            accent = "#4CAF50"
    else:
        primary = "#2196F3"
        secondary = "#FF9800"
        accent = "#4CAF50"

    # Start HTML
    html_parts = []
    html_parts.append("""
    <div style="background: #f8f9fa; padding: 24px; border-radius: 12px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;">
        <h3 style="margin-top: 0; color: #212529; font-size: 20px;">🎯 Footer Catalog (30 Footer Layouts)</h3>
        <p style="color: #6c757d; font-size: 14px; margin-bottom: 24px;">
            30 layout di footer/navigation bar diversi - classic tabs, floating bars, curved designs, pills, minimalist, advanced - renderizzati con i tuoi colori
        </p>
    """)

    # Grid container
    html_parts.append("""
        <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; margin-top: 20px;">
    """)

    # Render each footer
    for footer_id, info in catalog.items():
        # Render footer preview
        footer_preview = render_footer_html(footer_id, info, primary, secondary, accent)

        # Complexity color
        complexity = info.get('complexity', 'simple')
        if complexity == "simple":
            complexity_color = "#28a745"
        elif complexity == "medium":
            complexity_color = "#ffc107"
        else:
            complexity_color = "#dc3545"

        html_parts.append(f"""
        <div style="background: white; padding: 16px; border-radius: 8px; border: 1px solid #dee2e6; display: flex; flex-direction: column; gap: 12px;">
            {footer_preview}
            <div style="width: 100%; text-align: center;">
                <div style="font-weight: 600; font-size: 14px; margin-bottom: 4px;">{info['name']}</div>
                <div style="font-size: 11px; color: #6c757d; margin-bottom: 6px;">
                    <code style="background: #e9ecef; padding: 2px 6px; border-radius: 3px; font-size: 10px;">{footer_id}</code>
                </div>
                <div style="font-size: 11px; color: #6c757d; margin-bottom: 6px;">{info['description']}</div>
                <span style="background: {complexity_color}; color: white; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600;">
                    {complexity.upper()}
                </span>
            </div>
        </div>
        """)

    html_parts.append("</div></div>")
    return "".join(html_parts)


def generate_card_gallery(theme_json: str = ""):
    """
    Generate HTML gallery of all 30 card types
    Cards are rendered directly with HTML/CSS using theme colors
    """
    from agents.flutter_screen_generator import FlutterScreenGenerator

    agent = FlutterScreenGenerator()
    catalog = agent.CARD_CATALOG

    # Parse theme or use defaults
    if theme_json and theme_json.strip():
        try:
            theme_data = json.loads(theme_json)
            palette = theme_data.get("palette", {})
            primary = palette.get("primary", "#2196F3")
            secondary = palette.get("secondary", "#FF9800")
            accent = palette.get("accent", "#4CAF50")
        except:
            primary = "#2196F3"
            secondary = "#FF9800"
            accent = "#4CAF50"
    else:
        primary = "#2196F3"
        secondary = "#FF9800"
        accent = "#4CAF50"

    # Start HTML
    html_parts = []
    html_parts.append("""
    <div style="background: #f8f9fa; padding: 24px; border-radius: 12px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;">
        <h3 style="margin-top: 0; color: #212529; font-size: 20px;">🎴 Card Catalog (130+ Card Types)</h3>
        <p style="color: #6c757d; font-size: 14px; margin-bottom: 24px;">
            130+ tipologie di cards - e-commerce, social, finance, health, education, travel, food, real estate, music, gaming, productivity, dashboard - tutte renderizzate con i tuoi colori
        </p>
    """)

    # Grid container
    html_parts.append("""
        <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 20px; margin-top: 20px;">
    """)

    # Render each card
    for card_id, info in catalog.items():
        # Render card preview
        card_preview = render_card_html(card_id, info, primary, secondary, accent)

        # Complexity color
        complexity = info.get('complexity', 'simple')
        if complexity == "simple":
            complexity_color = "#28a745"
        elif complexity == "medium":
            complexity_color = "#ffc107"
        else:
            complexity_color = "#dc3545"

        html_parts.append(f"""
        <div style="background: white; padding: 16px; border-radius: 8px; border: 1px solid #dee2e6; display: flex; flex-direction: column; gap: 12px; align-items: center;">
            {card_preview}
            <div style="width: 100%; text-align: center;">
                <div style="font-weight: 600; font-size: 13px; margin-bottom: 4px;">{info['name']}</div>
                <div style="font-size: 10px; color: #6c757d; margin-bottom: 6px;">
                    <code style="background: #e9ecef; padding: 2px 6px; border-radius: 3px; font-size: 9px;">{card_id}</code>
                </div>
                <div style="font-size: 10px; color: #6c757d; margin-bottom: 6px;">{info['description']}</div>
                <span style="background: {complexity_color}; color: white; padding: 2px 8px; border-radius: 10px; font-size: 9px; font-weight: 600;">
                    {complexity.upper()}
                </span>
            </div>
        </div>
        """)

    html_parts.append("</div></div>")
    return "".join(html_parts)


def generate_single_background_preview(bg_id: str):
    """
    Generate preview code for a single background
    """
    if not bg_id:
        return "", "<p style='color: #999;'>Seleziona un background dalla galleria sopra</p>"

    # Default theme for preview
    theme = {
        "palette": {
            "primary": "#007AFF",
            "secondary": "#5856D6",
            "accent": "#FF9500",
            "background": "#FFFFFF"
        }
    }

    # Generate background-only code
    try:
        code = flutter_screen_generator._generate_background_only(theme, "generic", bg_id)

        # Get background info
        bg_info = flutter_screen_generator.BACKGROUND_CATALOG.get(bg_id, {})
        bg_name = bg_info.get("name", bg_id)
        bg_category = bg_info.get("category", "unknown")
        bg_complexity = bg_info.get("complexity", "unknown")

        # Create DartPad link
        import urllib.parse
        encoded_code = urllib.parse.quote(code)
        dartpad_link = f"https://dartpad.dev/?id={encoded_code[:100]}"  # Simplified

        preview_html = f"""
        <div style="background: white; padding: 20px; border-radius: 8px; border: 2px solid #007AFF;">
            <h4 style="margin-top: 0; color: #007AFF;">🎨 {bg_name}</h4>
            <div style="margin-bottom: 12px;">
                <span style="background: #e7f3ff; padding: 4px 10px; border-radius: 12px; font-size: 12px; margin-right: 8px;">
                    📁 {bg_category}
                </span>
                <span style="background: #fff3cd; padding: 4px 10px; border-radius: 12px; font-size: 12px;">
                    ⚡ {bg_complexity}
                </span>
            </div>
            <p style="color: #666; font-size: 13px; margin-bottom: 12px;">
                <strong>ID:</strong> <code style="background: #f8f9fa; padding: 2px 6px; border-radius: 3px;">{bg_id}</code>
            </p>
            <div style="background: #f8f9fa; padding: 12px; border-radius: 6px; margin-bottom: 12px;">
                <p style="margin: 0; font-size: 13px; color: #495057;">
                    <strong>📋 Come testare:</strong><br/>
                    1. Copia il codice Dart qui sotto<br/>
                    2. Vai su <a href="https://dartpad.dev" target="_blank" style="color: #007AFF; font-weight: 600;">DartPad.dev</a><br/>
                    3. Incolla e clicca "Run"<br/>
                    4. Vedi il background in azione! 🚀
                </p>
            </div>
            <p style="margin: 0; font-size: 12px; color: #28a745; font-weight: 600;">
                ✅ Codice generato: {len(code)} caratteri
            </p>
        </div>
        """

        return code, preview_html

    except Exception as e:
        error_html = f"""
        <div style="background: #fff3cd; padding: 15px; border-radius: 6px; border-left: 3px solid #ffc107;">
            <p style="margin: 0; color: #856404;">
                ⚠️ Errore durante la generazione: {str(e)}
            </p>
        </div>
        """
        return "", error_html


# Gradio interface
with gr.Blocks(
    title="Space AC: Design Variations",
    theme=gr.themes.Soft(
        primary_hue="blue",
        secondary_hue="purple"
    )
) as demo:

    gr.Markdown("""
    # 🎨 Space AC: Design Variations

    **AI-powered design system generation agents**

    Analyze app design references and extract actionable design insights.
    """)

    # State components to store data between tabs
    ac1_state = gr.State(value=None)  # Stores AC1 output JSON
    ac2_state = gr.State(value=None)  # Stores AC2 output JSON (all 4 themes)

    with gr.Tabs():

        # Tab 0: Simple Flutter Generator (NEW!)
        with gr.Tab("⚡ Simple Generator"):
            gr.Markdown("""
            # ⚡ Simple Flutter Generator

            **Prompt → DeepSeek → Flutter Code → DartPad Automatico** 🚀

            Niente preset, niente theme, niente complicazioni.
            Scrivi cosa vuoi, l'AI genera il codice Flutter e lo carica automaticamente in DartPad.

            ✨ **Novità:** Il codice viene automaticamente caricato nel DartPad embedded - clicca "Run" e basta!
            """)

            with gr.Row():
                with gr.Column(scale=1):
                    simple_prompt = gr.Textbox(
                        label="📝 Cosa vuoi generare?",
                        placeholder="Esempio:\n- Crea una schermata di login con email e password\n- Genera una home page per app fitness con statistiche\n- Fai una todo list app con checkbox e delete button",
                        lines=5,
                        value="Crea una schermata di login moderna con email, password e bottone login"
                    )

                    generate_simple_btn = gr.Button(
                        "🚀 Genera Codice Flutter",
                        variant="primary",
                        size="lg"
                    )

            # Results
            gr.Markdown("### 📱 Risultato")

            simple_summary = gr.HTML(
                value="<p style='text-align: center; color: #999; padding: 20px;'>Clicca 'Genera Codice Flutter' per iniziare...</p>"
            )

            # DartPad Embedded - PRIMO, ben visibile
            simple_dartpad = gr.HTML(
                value="<p style='text-align: center; color: #999; padding: 40px;'>Il DartPad embedded apparirà qui...</p>"
            )

            # Code Output - NASCOSTO in Accordion collassabile
            with gr.Accordion("💻 Codice Sorgente (clicca per espandere)", open=False):
                simple_code_output = gr.Code(
                    label="Codice Dart generato",
                    language="javascript",
                    lines=25,
                    value=""
                )

            # Examples
            gr.Examples(
                examples=[
                    ["Crea una schermata di login con email, password e social login buttons"],
                    ["Genera una home page per app fitness con cards di statistiche giornaliere"],
                    ["Fai una todo list con checkbox, testo e bottone delete per ogni item"],
                    ["Crea un profilo utente con avatar, nome, bio e bottoni follow/message"],
                    ["Genera una schermata settings con switch, slider e dropdown"],
                ],
                inputs=[simple_prompt],
                label="Prova questi esempi"
            )

            # Connect button
            generate_simple_btn.click(
                fn=generate_simple_flutter,
                inputs=[simple_prompt],
                outputs=[simple_code_output, simple_summary, simple_dartpad]
            )

        # Tab 1: Moodboard Analyzer
        with gr.Tab("🖼️ AC1: Moodboard Analyzer"):
            gr.Markdown("""
            ### Analyze Reference Images

            Provide descriptions of reference app screenshots or design inspirations.
            The agent will extract color palettes, typography trends, and UI patterns.
            """)

            with gr.Row():
                with gr.Column(scale=1):
                    image_descriptions = gr.Textbox(
                        label="Reference Image Descriptions",
                        placeholder="""Enter one description per line, for example:
Instagram home feed - dark mode, clean cards, bottom navigation
Uber driver app - dark theme, green accents, map view
Spotify player - dark background, vibrant album art, minimalist controls""",
                        lines=10
                    )

                    mood_keywords = gr.Textbox(
                        label="Mood Keywords (comma-separated)",
                        placeholder="energetic, gaming, modern, professional, playful",
                        value="modern, energetic"
                    )

                    analyze_btn = gr.Button(
                        "🔍 Analyze Moodboard",
                        variant="primary",
                        size="lg"
                    )

            # Visual Results Tabs
            gr.Markdown("### 📊 Analysis Results")

            with gr.Tabs():
                with gr.Tab("🎨 Color Palettes"):
                    color_palettes_html = gr.HTML(
                        label="Color Palettes",
                        value="<p style='text-align: center; color: #999; padding: 40px;'>Click 'Analyze Moodboard' to see color palettes here...</p>"
                    )

                with gr.Tab("✍️ Typography"):
                    typography_html = gr.HTML(
                        label="Typography Trends",
                        value="<p style='text-align: center; color: #999; padding: 40px;'>Typography trends will appear here...</p>"
                    )

                with gr.Tab("🧩 UI Patterns"):
                    ui_patterns_html = gr.HTML(
                        label="UI Patterns",
                        value="<p style='text-align: center; color: #999; padding: 40px;'>UI patterns will be displayed here...</p>"
                    )

                with gr.Tab("📐 Layout & Insights"):
                    layout_markdown = gr.Markdown(
                        value="Layout styles will appear here..."
                    )
                    insights_markdown = gr.Markdown(
                        value="Design insights will be generated here..."
                    )

                with gr.Tab("📄 JSON Data"):
                    json_output = gr.Code(
                        label="Complete Analysis JSON",
                        language="json",
                        lines=20,
                        value="{}"
                    )

            # Quick Action Button
            use_in_ac2_btn = gr.Button(
                "→ Use in AC2",
                variant="secondary",
                size="lg"
            )

            # Examples
            gr.Markdown("### 📝 Example Inputs")

            gr.Examples(
                examples=[
                    [
                        """Instagram home feed - dark mode with white text, clean cards with photos
Spotify player - dark background, vibrant green accents, minimalist controls
Uber driver app - dark theme with green accents, map interface, bold stats""",
                        "gaming, energetic, modern"
                    ],
                    [
                        """Banking app - white background, blue accents, professional typography
LinkedIn feed - white cards, blue buttons, clean layout
Notion - minimal design, subtle shadows, organized content""",
                        "professional, modern, clean"
                    ],
                    [
                        """Duolingo - playful colors, cartoon graphics, gamified interface
TikTok - dark mode, vibrant content, engaging animations
Snapchat - bright colors, fun filters, youthful design""",
                        "playful, fun, youthful"
                    ]
                ],
                inputs=[image_descriptions, mood_keywords],
                label="Try these examples"
            )

            # Connect button
            analyze_btn.click(
                fn=analyze_moodboard,
                inputs=[image_descriptions, mood_keywords],
                outputs=[
                    color_palettes_html,
                    typography_html,
                    ui_patterns_html,
                    layout_markdown,
                    insights_markdown,
                    json_output,
                    ac1_state  # Store AC1 output in state
                ]
            )

            # Note: use_in_ac2_btn click handler is defined after AC2 components are created

        # Tab 2: Design Variation Generator
        with gr.Tab("🎨 AC2: Design Variation Generator"):
            gr.Markdown("""
            ### Generate Design Theme Variations

            Take your moodboard analysis from AC1 and generate 4 complete design theme variations.
            Each theme will include colors, typography, spacing, and component styles.
            """)

            with gr.Row():
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Step 1:** First, run AC1 to analyze your moodboard
                    **Step 2:** Copy the JSON output from AC1
                    **Step 3:** Paste it below and add wireframe description
                    **Step 4:** Generate 4 design themes
                    """)

                    ac1_json_input = gr.Code(
                        label="Moodboard Analysis JSON (from AC1)",
                        language="json",
                        lines=10,
                        value='{\n  "analysis": {\n    "color_palettes": [],\n    "typography_trends": [],\n    "ui_patterns": []\n  }\n}'
                    )

                    # Connect use_in_ac2 button from AC1
                    use_in_ac2_btn.click(
                        fn=lambda ac1_data: json.dumps(ac1_data, indent=2) if ac1_data else "{}",
                        inputs=[ac1_state],
                        outputs=[ac1_json_input]
                    )

                    wireframe_input = gr.Textbox(
                        label="Wireframe Description",
                        placeholder="Describe your app wireframe: e.g., 'E-commerce app with product grid, shopping cart, and checkout flow'",
                        lines=5,
                        value="Mobile app with home screen, navigation bar, and content cards"
                    )

                    generate_themes_btn = gr.Button(
                        "✨ Generate 4 Design Themes",
                        variant="primary",
                        size="lg"
                    )

            # Results Section
            gr.Markdown("### 🎯 Generated Design Themes")

            with gr.Tabs():
                with gr.Tab("🎨 Visual Themes"):
                    themes_grid_html = gr.HTML(
                        label="Design Themes",
                        value="<p style='text-align: center; color: #999; padding: 40px;'>Click 'Generate 4 Design Themes' to see themes here...</p>"
                    )

                with gr.Tab("📄 JSON Data"):
                    themes_json_output = gr.Code(
                        label="Complete Themes JSON",
                        language="json",
                        lines=20,
                        value="{}"
                    )

            # Examples
            gr.Markdown("### 📝 Workflow Example")
            gr.Markdown("""
            **Complete Workflow:**

            1. Go to AC1 tab → Analyze moodboard → Copy JSON from "JSON Data" tab
            2. Come back to AC2 tab → Paste JSON in the input above
            3. Describe your wireframe
            4. Click "Generate 4 Design Themes"
            5. View 4 different design variations with complete design systems

            Each theme will include:
            - **Color Palette** - Primary, secondary, accent, neutral colors
            - **Typography** - Font families for display and body text
            - **Spacing System** - Consistent spacing scale
            - **Component Styles** - Button styles, card styles, etc.
            - **Animations** - Animation style and timing
            """)

            # Quick Action Buttons for each theme
            with gr.Row():
                use_theme1_btn = gr.Button("→ Use Theme 1 in AC3", variant="secondary", size="sm")
                use_theme2_btn = gr.Button("→ Use Theme 2 in AC3", variant="secondary", size="sm")
                use_theme3_btn = gr.Button("→ Use Theme 3 in AC3", variant="secondary", size="sm")
                use_theme4_btn = gr.Button("→ Use Theme 4 in AC3", variant="secondary", size="sm")

            # Connect button
            generate_themes_btn.click(
                fn=generate_design_themes,
                inputs=[ac1_json_input, wireframe_input],
                outputs=[themes_grid_html, themes_json_output, ac2_state]
            )

            # Note: use_theme buttons click handlers are defined after AC3 components are created

        # Tab 3: Flutter Screen Generator
        with gr.Tab("💻 AC3: Flutter Screen Generator"):
            gr.Markdown("""
            ### Generate Flutter/Dart Screen Code

            Take one of your design themes from AC2 and generate complete Flutter screens
            ready to run on **DartPad**! 🎨
            """)

            with gr.Row():
                with gr.Column(scale=1):
                    gr.Markdown("""
                    **Step 1:** Run AC2 to generate design themes
                    **Step 2:** Copy theme JSON from AC2
                    **Step 3:** Select app type
                    **Step 4:** Generate Flutter code
                    **Step 5:** Copy code to [DartPad](https://dartpad.dev)
                    """)

                    theme_json_input = gr.Code(
                        label="Theme JSON (from AC2)",
                        language="json",
                        lines=8,
                        value='{\n  "name": "Bold Energy",\n  "palette": {"primary": "#FF6B35"},\n  "typography": {}\n}'
                    )

                    # Connect use_theme buttons from AC2
                    use_theme1_btn.click(
                        fn=lambda ac2_data: json.dumps(ac2_data["themes"][0], indent=2) if ac2_data and "themes" in ac2_data and len(ac2_data["themes"]) > 0 else "{}",
                        inputs=[ac2_state],
                        outputs=[theme_json_input]
                    )
                    use_theme2_btn.click(
                        fn=lambda ac2_data: json.dumps(ac2_data["themes"][1], indent=2) if ac2_data and "themes" in ac2_data and len(ac2_data["themes"]) > 1 else "{}",
                        inputs=[ac2_state],
                        outputs=[theme_json_input]
                    )
                    use_theme3_btn.click(
                        fn=lambda ac2_data: json.dumps(ac2_data["themes"][2], indent=2) if ac2_data and "themes" in ac2_data and len(ac2_data["themes"]) > 2 else "{}",
                        inputs=[ac2_state],
                        outputs=[theme_json_input]
                    )
                    use_theme4_btn.click(
                        fn=lambda ac2_data: json.dumps(ac2_data["themes"][3], indent=2) if ac2_data and "themes" in ac2_data and len(ac2_data["themes"]) > 3 else "{}",
                        inputs=[ac2_state],
                        outputs=[theme_json_input]
                    )

                    app_type_dropdown = gr.Dropdown(
                        label="App Type",
                        choices=["fitness", "banking", "rider", "ecommerce", "social", "food", "travel", "health", "education", "generic"],
                        value="fitness"
                    )

                    custom_prompt = gr.Textbox(
                        label="📝 Prompt Personalizzato (cosa vuoi generare)",
                        placeholder="Esempio: Genera una home page per app fitness con statistiche, Crea una schermata login moderna, etc.",
                        lines=3,
                        value="Genera una home page per l'app con cards, header e footer"
                    )

                    screens_input = gr.Textbox(
                        label="Screens (comma-separated, max 3)",
                        placeholder="home, detail, profile",
                        lines=1,
                        value="home, detail, profile"
                    )

                    generate_flutter_btn = gr.Button(
                        "🚀 Generate Flutter Screens",
                        variant="primary",
                        size="lg"
                    )

            # Results Section
            gr.Markdown("### 📱 Generated Flutter Screens")

            summary_output = gr.HTML(
                value="<p style='text-align: center; color: #999; padding: 20px;'>Click 'Generate Flutter Screens' to create code...</p>"
            )

            with gr.Tabs():
                with gr.Tab("✨ Variant 1"):
                    preview_waves = gr.HTML(value="<p style='text-align: center; padding: 40px;'>Generate to see AI-powered variant...</p>")
                    with gr.Accordion("💻 View Dart Code", open=False):
                        code_waves = gr.Code(label="Dart Code - Variant 1", language="javascript", lines=15, value="")

                with gr.Tab("✨ Variant 2"):
                    preview_linear = gr.HTML(value="<p style='text-align: center; padding: 40px;'>Generate to see AI-powered variant...</p>")
                    with gr.Accordion("💻 View Dart Code", open=False):
                        code_linear = gr.Code(label="Dart Code - Variant 2", language="javascript", lines=15, value="")

                with gr.Tab("✨ Variant 3"):
                    preview_radial = gr.HTML(value="<p style='text-align: center; padding: 40px;'>Generate to see AI-powered variant...</p>")
                    with gr.Accordion("💻 View Dart Code", open=False):
                        code_radial = gr.Code(label="Dart Code - Variant 3", language="javascript", lines=15, value="")

                with gr.Tab("✨ Variant 4"):
                    preview_geometric = gr.HTML(value="<p style='text-align: center; padding: 40px;'>Generate to see AI-powered variant...</p>")
                    with gr.Accordion("💻 View Dart Code", open=False):
                        code_geometric = gr.Code(label="Dart Code - Variant 4", language="javascript", lines=15, value="")

            # Info Section
            gr.Markdown("### 💡 How to Use")
            gr.Markdown("""
            **AI-Powered Variants:**
            - 🤖 **Llama 3.1 70B** analyzes your theme + app type
            - ✨ Generates **4 unique variants** combining:
              - **Background** (waves/gradient_linear/gradient_radial/geometric)
              - **Header** (minimal/avatar_search/tabs/collapsible/stats_header)
              - **Footer** (minimal_icons/floating_fab/animated_pills/classic_expanded/gesture_bar)
            - 🎨 Each variant is contextually appropriate for your design

            **Generated Code:**
            - ✅ Complete, runnable Dart/Flutter code
            - ✅ Styled with your theme colors and typography
            - ✅ App-specific headers and footers
            - ✅ Mock data included
            - ✅ Ready for DartPad (~500-700 lines each)

            **To test:**
            1. Click on a variant tab above
            2. Copy the Dart code
            3. Go to [dartpad.dev](https://dartpad.dev)
            4. Paste and click "Run"
            5. See your AI-generated screen! 🎉

            **Supported App Types:**
            - **Fitness:** Stats headers, progress tracking, workout cards
            - **Banking:** Account balance, transaction lists, transfer buttons
            - **Rider:** Delivery stats, earnings, map previews
            - **E-commerce:** Product grids, cart, checkout flows
            - **Social:** Feed layouts, profile headers, post cards
            - **And more!**
            """)

            # Background Gallery Section
            gr.Markdown("---")
            with gr.Accordion("🎨 Background Gallery (30 Backgrounds)", open=False):
                gr.Markdown("""
                Esplora tutti i 30 background disponibili organizzati per categoria.
                Usa questa gallery per analizzare visualmente la knowledge base e testare ogni background.
                """)

                # Refresh button to update with new theme
                refresh_backgrounds_btn = gr.Button("🔄 Aggiorna con Tema Corrente", variant="secondary", size="sm")

                # Gallery HTML (reactive to theme changes) - show immediately with default theme
                default_theme_for_gallery = json.dumps({
                    "name": "Default Theme",
                    "palette": {"primary": "#2196F3", "secondary": "#FF9800", "accent": "#4CAF50"}
                })
                gallery_html = gr.HTML(
                    value=generate_background_gallery(default_theme_for_gallery)
                )

                # Connect refresh button
                refresh_backgrounds_btn.click(
                    fn=generate_background_gallery,
                    inputs=[theme_json_input],
                    outputs=[gallery_html]
                )

            # Header Gallery Section
            gr.Markdown("---")
            with gr.Accordion("🎯 Header Catalog (20 Headers)", open=False):
                gr.Markdown("""
                Tutti i 20 header realistici disponibili con preview renderizzate in HTML/CSS.
                Gli header includono profilo, localizzazione, notifiche, menu e altri elementi.
                """)

                # Refresh button to update with new theme
                refresh_headers_btn = gr.Button("🔄 Aggiorna Header con Tema Corrente", variant="secondary", size="sm")

                # Header Gallery HTML - show immediately with default theme
                header_gallery_html = gr.HTML(
                    value=generate_header_gallery(default_theme_for_gallery)
                )

                # Connect refresh button
                refresh_headers_btn.click(
                    fn=generate_header_gallery,
                    inputs=[theme_json_input],
                    outputs=[header_gallery_html]
                )

            # Footer Gallery Section
            gr.Markdown("---")
            with gr.Accordion("🎯 Footer Catalog (30 Footer Layouts)", open=False):
                gr.Markdown("""
                Tutti i 30 footer/navigation bar con layout diversi renderizzati in HTML/CSS.
                Classic tabs, floating bars, curved designs, pills, minimalist, advanced interactive.
                """)

                # Refresh button to update with new theme
                refresh_footers_btn = gr.Button("🔄 Aggiorna Footer con Tema Corrente", variant="secondary", size="sm")

                # Footer Gallery HTML - show immediately with default theme
                footer_gallery_html = gr.HTML(
                    value=generate_footer_gallery(default_theme_for_gallery)
                )

                # Connect refresh button
                refresh_footers_btn.click(
                    fn=generate_footer_gallery,
                    inputs=[theme_json_input],
                    outputs=[footer_gallery_html]
                )

            # Card Gallery Section
            gr.Markdown("---")
            with gr.Accordion("🎴 Card Catalog (130+ Card Types)", open=False):
                gr.Markdown("""
                Tutte le 130+ tipologie di cards renderizzate in HTML/CSS.
                E-commerce, Social, Finance, Health, Education, Travel, Food, Real Estate, Music, Gaming, Productivity, Dashboard - tutte con i tuoi colori del tema.
                """)

                # Refresh button to update with new theme
                refresh_cards_btn = gr.Button("🔄 Aggiorna Cards con Tema Corrente", variant="secondary", size="sm")

                # Card Gallery HTML - show immediately with default theme
                card_gallery_html = gr.HTML(
                    value=generate_card_gallery(default_theme_for_gallery)
                )

                # Connect refresh button
                refresh_cards_btn.click(
                    fn=generate_card_gallery,
                    inputs=[theme_json_input],
                    outputs=[card_gallery_html]
                )


            # Connect button
            generate_flutter_btn.click(
                fn=generate_flutter_screens,
                inputs=[theme_json_input, app_type_dropdown, custom_prompt, screens_input],
                outputs=[
                    summary_output,
                    preview_waves, code_waves,
                    preview_linear, code_linear,
                    preview_radial, code_radial,
                    preview_geometric, code_geometric
                ]
            )

        # Tab 4: API Documentation
        with gr.Tab("📡 API Documentation"):
            gr.Markdown("""
            ## REST API Endpoints

            ### POST /api/moodboard-analyzer

            Analyze a moodboard to extract design insights.

            **Request Body:**
            ```json
            {
              "reference_images": [
                {
                  "url": "https://example.com/screenshot.png",
                  "description": "Instagram home feed - dark mode"
                }
              ],
              "mood_keywords": ["energetic", "gaming", "modern"]
            }
            ```

            **Response:**
            ```json
            {
              "success": true,
              "agent": "moodboard_analyzer",
              "output": {
                "analysis": {
                  "color_palettes": [...],
                  "typography_trends": [...],
                  "ui_patterns": [...],
                  "layout_styles": [...],
                  "insights": "..."
                }
              }
            }
            ```

            ### Example using curl:

            ```bash
            curl -X POST https://oneweekapp-space-ac-design.hf.space/api/moodboard-analyzer \\
              -H "Content-Type: application/json" \\
              -d '{
                "reference_images": [
                  {"description": "Instagram dark mode", "url": ""}
                ],
                "mood_keywords": ["energetic", "gaming"]
              }'
            ```

            ### Example using Python:

            ```python
            import requests

            response = requests.post(
                "https://oneweekapp-space-ac-design.hf.space/api/moodboard-analyzer",
                json={
                    "reference_images": [
                        {"description": "Instagram dark mode", "url": ""}
                    ],
                    "mood_keywords": ["energetic", "gaming"]
                }
            )

            result = response.json()
            print(result["output"]["analysis"])
            ```

            ---

            ### POST /api/design-variation-generator

            Generate 4 design theme variations from moodboard analysis.

            **Request Body:**
            ```json
            {
              "moodboard_analysis": {
                "color_palettes": [...],
                "typography_trends": [...],
                "ui_patterns": [...]
              },
              "wireframe": "E-commerce app with product grid and checkout",
              "app_context": {
                "type": "mobile_app"
              }
            }
            ```

            **Response:**
            ```json
            {
              "success": true,
              "agent": "design_variation_generator",
              "output": {
                "themes": [
                  {
                    "name": "Bold Energy",
                    "style": "bold",
                    "mood": "Energetic and gaming-focused",
                    "palette": {...},
                    "typography": {...},
                    "spacing": {...},
                    "component_style": {...},
                    "animations": {...}
                  }
                ]
              }
            }
            ```

            ### Example using curl:

            ```bash
            curl -X POST https://oneweekapp-space-ac-design.hf.space/api/design-variation-generator \\\\
              -H "Content-Type: application/json" \\\\
              -d '{
                "moodboard_analysis": {...},
                "wireframe": "Social media app",
                "app_context": {"type": "mobile_app"}
              }'
            ```

            ---

            ### POST /api/flutter-screen-generator

            Generate Flutter/Dart code from design themes using AI planning (Llama 3.1 70B).

            **Request Body:**
            ```json
            {
              "theme": {
                "name": "Bold Energy",
                "palette": {...},
                "typography": {...},
                "spacing": {...}
              },
              "app_type": "fitness",
              "screens": ["home", "profile", "settings"]
            }
            ```

            **Response:**
            ```json
            {
              "success": true,
              "agent": "flutter_screen_generator",
              "output": {
                "screens": [
                  {
                    "name": "home",
                    "code": "import 'package:flutter/material.dart';\\n\\n// Full Dart code...",
                    "lines": 487,
                    "components": ["StatsCard", "HeroBanner"],
                    "status": "generated"
                  }
                ],
                "theme_name": "Bold Energy",
                "app_type": "fitness",
                "total_lines": 1420
              }
            }
            ```

            **Available app types:** fitness, banking, rider, ecommerce, social, etc.

            **Available screens:** home, profile, settings, detail, feed, search, cart, chat, onboarding, login

            **Note:** Requires `HF_TOKEN` environment variable for Llama 3.1 access. Returns fallback code if not configured.

            ## Health Check

            ### GET /health

            Check if the space is healthy.

            **Response:**
            ```json
            {
              "status": "healthy",
              "space": "ac-design",
              "agents": ["moodboard_analyzer"]
            }
            ```
            """)

        # Tab 3: About
        with gr.Tab("ℹ️ About"):
            gr.Markdown("""
            ## About Space AC

            **Space AC: Design Variations** is part of the AI Software Factory system.

            ### Agents in this Space:

            1. **AC1: Moodboard Analyzer** 🖼️ ✅ LIVE
               - Analyzes reference images and screenshots
               - Extracts color palettes with visual previews
               - Identifies UI patterns and typography trends
               - Generates design insights

            2. **AC2: Design Variation Generator** 🎨 ✅ LIVE
               - Generates 4 complete design themes
               - Defines design tokens (colors, typography, spacing)
               - Creates complete design system specifications
               - Visual theme cards with preview

            3. **AC3: Flutter Screen Generator** 💻 ✅ LIVE
               - Generates runnable Flutter/Dart code for DartPad
               - AI-powered planning with Llama 3.1 70B + Jinja2 templates
               - Creates 3 screens per theme with realistic components
               - Supports 10 app types (fitness, banking, rider, ecommerce, etc.)
               - 400-500 lines of production-ready Dart code per screen

            4. **AC4: Theme Comparator** 🎯 (Coming soon)
               - Compares design themes
               - Generates pros/cons analysis
               - Recommends best theme

            ### Technology Stack:

            - **UI Framework:** Gradio 5.49+
            - **API:** FastAPI 0.115+
            - **AI Models:**
              - Llama 3.2 Vision (11B) for image analysis (AC1)
              - Llama 3.1 (70B) for text generation and synthesis (AC2)
              - Llama 3.1 (70B) for Flutter code planning (AC3)
              - Jinja2 Templates for Dart code generation (AC3)

            ### Part of AI Software Factory

            This space is part of a larger system that generates complete Flutter applications
            from Notion wireframes to GitHub PRs in 50-70 minutes.

            **Learn more:** [GitHub Repository](https://github.com/sabatino81/AISoftwareFactory)

            ---

            **🔗 Quick Links:**
            - Live App: https://oneweekapp-space-ac-design.hf.space
            - Space Page: https://huggingface.co/spaces/OneWeekApp/space-ac-design
            - GitHub: https://github.com/sabatino81/AISoftwareFactory
            """)


# Mount Gradio on FastAPI
app = gr.mount_gradio_app(app, demo, path="/")


if __name__ == "__main__":
    demo.launch(ssr_mode=False)  # Disable SSR for HuggingFace Spaces compatibility