native-theme 0.6.1

Cross-platform native theme detection and loading for Rust GUI applications
Documentation
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
// Per-widget struct pairs: all 26 per-variant widgets + LayoutTheme use #[derive(ThemeWidget)].

use crate::Rgba;
use crate::model::border::{ResolvedWidgetBorder, WidgetBorderSpec};
use crate::model::{ArrowSide, DialogButtonOrder, FontSpec, ResolvedFontSpec, TabIndicatorSide};
use native_theme_derive::{ThemeFields, ThemeWidget};

// ── 2.2 Window / Application Chrome ────────────────────────────────────────

/// Window chrome: background, title bar colors, inactive states, geometry.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full_lg", font = "title_bar_font")]
pub struct WindowTheme {
    /// Main window background fill.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Active title bar background fill.
    #[theme(inherit_from = "defaults.surface_color")]
    pub title_bar_background: Option<Rgba>,
    /// Title bar background when the window is unfocused.
    pub inactive_title_bar_background: Option<Rgba>,
    /// Title bar text color when the window is unfocused.
    pub inactive_title_bar_text_color: Option<Rgba>,
    /// Title bar font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub title_bar_font: Option<FontSpec>,
    /// Window border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.3 Button ──────────────────────────────────────────────────────────────

/// Push button: colors, sizing, spacing, geometry.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "font")]
pub struct ButtonTheme {
    /// Default button background fill.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Primary / accent button background fill.
    #[theme(inherit_from = "defaults.accent_color")]
    pub primary_background: Option<Rgba>,
    /// Primary / accent button text/icon color.
    #[theme(inherit_from = "defaults.accent_text_color")]
    pub primary_text_color: Option<Rgba>,
    /// Minimum button width in logical pixels.
    #[serde(rename = "min_width_px")]
    #[theme(check = "non_negative")]
    pub min_width: Option<f32>,
    /// Minimum button height in logical pixels.
    #[serde(rename = "min_height_px")]
    #[theme(check = "non_negative")]
    pub min_height: Option<f32>,
    /// Space between icon and label.
    #[serde(rename = "icon_text_gap_px")]
    #[theme(check = "non_negative")]
    pub icon_text_gap: Option<f32>,
    /// Opacity multiplier when the button is disabled (0.0-1.0), applied to
    /// the whole button on top of its disabled colours (see
    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
    pub disabled_opacity: Option<f32>,
    /// Button background on hover.
    #[theme(inherit_from = "defaults.background_color")]
    pub hover_background: Option<Rgba>,
    /// Button text color on hover.
    pub hover_text_color: Option<Rgba>,
    /// Button text color when pressed/active.
    pub active_text_color: Option<Rgba>,
    /// Button text color when disabled.
    #[theme(inherit_from = "defaults.disabled_text_color")]
    pub disabled_text_color: Option<Rgba>,
    /// Button background when pressed/active.
    #[theme(category = "soft_option")]
    pub active_background: Option<Rgba>,
    /// Button background when disabled; `None`, the enabled background.
    #[theme(category = "soft_option")]
    pub disabled_background: Option<Rgba>,
    /// Background of a toggle button that is on (checked): Breeze's
    /// `Button` mixed an eighth towards `ButtonText`, WinUI's accent fill,
    /// libadwaita's pressed fill, Material's `secondary`. `None` where the
    /// platform states none (AppKit); a connector then shows the pressed
    /// pair, `active_background` and `active_text_color`
    /// (docs/platform-facts.md §2.3).
    #[theme(category = "soft_option")]
    pub checked_background: Option<Rgba>,
    /// Label color of a toggle button that is on; `None`, as for
    /// `checked_background`, the pressed pair's (docs/platform-facts.md §2.3).
    #[theme(category = "soft_option")]
    pub checked_text_color: Option<Rgba>,
    /// Button label font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Button border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.4 Text Input ──────────────────────────────────────────────────────────

/// Single-line and multi-line text input fields: everything of a multi-line
/// field but its padding, which is [`TextAreaTheme`]'s.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "font")]
pub struct InputTheme {
    /// Input field background fill.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Placeholder text color.
    #[theme(inherit_from = "defaults.muted_color")]
    pub placeholder_color: Option<Rgba>,
    /// Text cursor (caret) color.
    pub caret_color: Option<Rgba>,
    /// Text selection highlight color.
    #[theme(inherit_from = "defaults.text_selection_background")]
    pub selection_background: Option<Rgba>,
    /// Text color inside the selection highlight.
    #[theme(inherit_from = "defaults.text_selection_color")]
    pub selection_text_color: Option<Rgba>,
    /// Minimum field height in logical pixels.
    #[serde(rename = "min_height_px")]
    #[theme(check = "non_negative")]
    pub min_height: Option<f32>,
    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
    /// widget on top of its disabled colours (see
    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
    pub disabled_opacity: Option<f32>,
    /// Input text color when disabled.
    #[theme(inherit_from = "defaults.disabled_text_color")]
    pub disabled_text_color: Option<Rgba>,
    /// Border color when the input is hovered.
    #[theme(category = "soft_option")]
    pub hover_border_color: Option<Rgba>,
    /// Border color when the input has focus.
    #[theme(category = "soft_option")]
    pub focus_border_color: Option<Rgba>,
    /// Input background when disabled; `None`, the enabled background.
    #[theme(category = "soft_option")]
    pub disabled_background: Option<Rgba>,
    /// Input text font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Input border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.29 Text Area (multi-line) ──────────────────────────────────────────────

/// Multi-line text field: the padding in which it differs from the
/// single-line field. Everything else a text area shows -- its fill, text,
/// placeholder, caret, selection, states and font -- is [`InputTheme`]'s.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
pub struct TextAreaTheme {
    /// Text area border specification. Its padding sides are the multi-line
    /// field's own, `None` where the platform states none
    /// (docs/platform-facts.md §2.29); its colour, corner radius, line width
    /// and shadow inherit `input.border`'s: the platforms frame both fields
    /// alike.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.5 Checkbox / Radio Button ────────────────────────────────────────────

/// Checkbox and radio button theme: colors, indicator, label font, border, and interactive states.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "font")]
pub struct CheckboxTheme {
    /// Checkbox background color.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Indicator background when checked.
    #[theme(inherit_from = "defaults.accent_color")]
    pub checked_background: Option<Rgba>,
    /// Indicator (check mark / radio dot) color.
    #[theme(inherit_from = "defaults.accent_text_color")]
    pub indicator_color: Option<Rgba>,
    /// Side length of the checkbox indicator (square), or diameter of the
    /// radio indicator (circle), in logical pixels: the whole indicator, not
    /// the mark drawn inside it (docs/platform-facts.md:980).
    #[serde(rename = "indicator_width_px")]
    #[theme(check = "non_negative")]
    pub indicator_width: Option<f32>,
    /// Diameter of the radio indicator (circle) in logical pixels, where the
    /// platform sizes it apart from the checkbox's square: Material's radio is
    /// 20 across, its checkbox 18. `None` where the platform sizes both alike,
    /// and the radio is `indicator_width` across (docs/platform-facts.md §2.5).
    #[serde(rename = "radio_indicator_width_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub radio_indicator_width: Option<f32>,
    /// Diameter of the filled dot a selected radio button draws at the centre
    /// of its indicator, in logical pixels. `None` where the platform states
    /// no dot size: AppKit draws its own (docs/platform-facts.md §2.5).
    #[serde(rename = "radio_dot_diameter_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub radio_dot_diameter: Option<f32>,
    /// Stroke width of the check mark a checked checkbox draws, in logical
    /// pixels. `None` where the platform states none: WinUI's mark is a font
    /// glyph and AppKit publishes none (docs/platform-facts.md §2.5).
    #[serde(rename = "check_mark_stroke_width_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub check_mark_stroke_width: Option<f32>,
    /// Space between indicator and label.
    #[serde(rename = "label_gap_px")]
    #[theme(check = "non_negative")]
    pub label_gap: Option<f32>,
    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
    /// widget on top of its disabled colours (see
    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
    pub disabled_opacity: Option<f32>,
    /// Checkbox label text color when disabled.
    #[theme(inherit_from = "defaults.disabled_text_color")]
    pub disabled_text_color: Option<Rgba>,
    /// Checkbox background on hover.
    #[theme(category = "soft_option")]
    pub hover_background: Option<Rgba>,
    /// Checkbox background when disabled; `None`, the enabled box of its
    /// state (checked or unchecked).
    #[theme(category = "soft_option")]
    pub disabled_background: Option<Rgba>,
    /// Indicator background when unchecked.
    #[theme(category = "soft_option")]
    pub unchecked_background: Option<Rgba>,
    /// Border color when unchecked.
    #[theme(category = "soft_option")]
    pub unchecked_border_color: Option<Rgba>,
    /// Checkbox label font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Checkbox border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.6 Menu ────────────────────────────────────────────────────────────────

/// Popup and context menu appearance.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_layer(border_kind = "none")]
#[theme_inherit(font = "font")]
pub struct MenuTheme {
    /// Menu panel background fill.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Separator line color between menu items.
    #[theme(inherit_from = "defaults.border.color")]
    pub separator_color: Option<Rgba>,
    /// Height of a single menu item row. `None` where the platform states
    /// no row height: KDE's menu items size to their font
    /// (docs/platform-facts.md §2.6).
    #[serde(rename = "row_height_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub row_height: Option<f32>,
    /// Space between a menu item's icon and its label.
    #[serde(rename = "icon_text_gap_px")]
    #[theme(check = "non_negative")]
    pub icon_text_gap: Option<f32>,
    /// Menu item icon size in logical pixels.
    #[serde(rename = "icon_size_px")]
    #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
    pub icon_size: Option<f32>,
    /// Menu item background on hover.
    #[theme(inherit_from = "defaults.selection_background")]
    pub hover_background: Option<Rgba>,
    /// Menu item text color on hover.
    #[theme(inherit_from = "defaults.selection_text_color")]
    pub hover_text_color: Option<Rgba>,
    /// Disabled menu item text color.
    #[theme(inherit_from = "defaults.disabled_text_color")]
    pub disabled_text_color: Option<Rgba>,
    /// Menu item font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Menu border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.7 Tooltip ─────────────────────────────────────────────────────────────

/// Tooltip popup appearance.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "font")]
pub struct TooltipTheme {
    /// Tooltip background fill.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Maximum tooltip width before wrapping.
    #[serde(rename = "max_width_px")]
    #[theme(check = "non_negative")]
    pub max_width: Option<f32>,
    /// Tooltip font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Tooltip border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.8 Scrollbar ───────────────────────────────────────────────────────────

/// Scrollbar colors and geometry.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
pub struct ScrollbarTheme {
    /// Scrollbar track (gutter) color.
    pub track_color: Option<Rgba>,
    /// Scrollbar thumb color.
    #[theme(inherit_from = "defaults.muted_color")]
    pub thumb_color: Option<Rgba>,
    /// Thumb color on hover.
    #[theme(inherit_from = "defaults.muted_color")]
    pub thumb_hover_color: Option<Rgba>,
    /// Scrollbar groove width in logical pixels.
    #[serde(rename = "groove_width_px")]
    #[theme(check = "non_negative")]
    pub groove_width: Option<f32>,
    /// Minimum thumb length in logical pixels.
    #[serde(rename = "min_thumb_length_px")]
    #[theme(check = "non_negative")]
    pub min_thumb_length: Option<f32>,
    /// Width of the thumb rail within the scrollbar.
    #[serde(rename = "thumb_width_px")]
    #[theme(check = "non_negative")]
    pub thumb_width: Option<f32>,
    /// Whether the scrollbar overlays content instead of taking layout space.
    pub overlay_mode: Option<bool>,
    /// Thumb color when pressed/dragging.
    #[theme(category = "soft_option")]
    pub thumb_active_color: Option<Rgba>,
}

// ── 2.9 Slider ──────────────────────────────────────────────────────────────

/// Slider control colors and geometry.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
pub struct SliderTheme {
    /// Filled portion of the slider track.
    #[theme(inherit_from = "defaults.accent_color")]
    pub fill_color: Option<Rgba>,
    /// Unfilled track color.
    #[theme(inherit_from = "defaults.muted_color")]
    pub track_color: Option<Rgba>,
    /// Thumb (handle) color.
    #[theme(inherit_from = "defaults.surface_color")]
    pub thumb_color: Option<Rgba>,
    /// Track height in logical pixels.
    #[serde(rename = "track_height_px")]
    #[theme(check = "non_negative")]
    pub track_height: Option<f32>,
    /// Thumb diameter in logical pixels.
    #[serde(rename = "thumb_diameter_px")]
    #[theme(check = "non_negative")]
    pub thumb_diameter: Option<f32>,
    /// Tick mark length in logical pixels.
    #[serde(rename = "tick_mark_length_px")]
    #[theme(check = "non_negative")]
    pub tick_mark_length: Option<f32>,
    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
    /// widget on top of its disabled colours (see
    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
    pub disabled_opacity: Option<f32>,
    /// Thumb color on hover.
    #[theme(category = "soft_option")]
    pub thumb_hover_color: Option<Rgba>,
    /// Filled track color when disabled; `None`, the enabled colour (as for
    /// the two below).
    #[theme(category = "soft_option")]
    pub disabled_fill_color: Option<Rgba>,
    /// Unfilled track color when disabled.
    #[theme(category = "soft_option")]
    pub disabled_track_color: Option<Rgba>,
    /// Thumb color when disabled.
    #[theme(category = "soft_option")]
    pub disabled_thumb_color: Option<Rgba>,
}

// ── 2.10 Progress Bar ───────────────────────────────────────────────────────

/// Progress bar colors and geometry.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full")]
pub struct ProgressBarTheme {
    /// Filled progress bar color.
    #[theme(inherit_from = "defaults.accent_color")]
    pub fill_color: Option<Rgba>,
    /// Background track color.
    #[theme(inherit_from = "defaults.muted_color")]
    pub track_color: Option<Rgba>,
    /// Bar height in logical pixels.
    #[serde(rename = "track_height_px")]
    #[theme(check = "non_negative")]
    pub track_height: Option<f32>,
    /// Minimum bar width in logical pixels.
    #[serde(rename = "min_width_px")]
    #[theme(check = "non_negative")]
    pub min_width: Option<f32>,
    /// Progress bar border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.11 Tab Bar ─────────────────────────────────────────────────────────────

/// Tab bar colors and sizing.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_layer(border_kind = "none")]
#[theme_inherit(font = "font")]
pub struct TabTheme {
    /// Inactive tab background.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Active (selected) tab background.
    #[theme(inherit_from = "defaults.background_color")]
    pub active_background: Option<Rgba>,
    /// Active (selected) tab text color.
    #[theme(inherit_from = "defaults.text_color")]
    pub active_text_color: Option<Rgba>,
    /// Tab bar strip background.
    #[theme(inherit_from = "defaults.background_color")]
    pub bar_background: Option<Rgba>,
    /// Minimum tab width in logical pixels.
    #[serde(rename = "min_width_px")]
    #[theme(check = "non_negative")]
    pub min_width: Option<f32>,
    /// Minimum tab height in logical pixels.
    #[serde(rename = "min_height_px")]
    #[theme(check = "non_negative")]
    pub min_height: Option<f32>,
    /// Space between adjacent tabs in logical pixels. `None` where the
    /// platform states none: AppKit publishes no tab spacing
    /// (docs/platform-facts.md §2.11).
    #[serde(rename = "item_gap_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub item_gap: Option<f32>,
    /// Color of the line that marks the active tab: Breeze's `Highlight`
    /// strip, libadwaita's accent, Material's `primary` indicator. `None`
    /// where the platform marks the active tab without one, by its fill and
    /// border (docs/platform-facts.md §2.11); a connector draws the line only
    /// where the theme states its color, width and side.
    #[theme(category = "soft_option")]
    pub active_indicator_color: Option<Rgba>,
    /// Thickness of the active tab's indicator line in logical pixels:
    /// KDE 3, GNOME 4, Material 3 (docs/platform-facts.md §2.11).
    #[serde(rename = "active_indicator_width_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub active_indicator_width: Option<f32>,
    /// Which edge of the active tab its indicator line lies along, for tabs
    /// above their pages: KDE top, GNOME and Material bottom
    /// (docs/platform-facts.md §2.11).
    #[theme(category = "soft_option")]
    pub active_indicator_side: Option<TabIndicatorSide>,
    /// Tab text color on hover.
    pub hover_text_color: Option<Rgba>,
    /// Tab background on hover.
    #[theme(category = "soft_option")]
    pub hover_background: Option<Rgba>,
    /// Tab font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Tab border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.12 Sidebar ─────────────────────────────────────────────────────────────

/// Sidebar panel background, selection, and hover colors.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_layer(border_kind = "partial")]
#[theme_inherit(border_kind = "partial", font = "font")]
pub struct SidebarTheme {
    /// Sidebar panel background fill.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Selected item background color.
    #[theme(inherit_from = "defaults.selection_background")]
    pub selection_background: Option<Rgba>,
    /// Selected item text color.
    #[theme(inherit_from = "defaults.selection_text_color")]
    pub selection_text_color: Option<Rgba>,
    /// Hovered item background color.
    #[theme(inherit_from = "defaults.background_color")]
    pub hover_background: Option<Rgba>,
    /// Sidebar font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Sidebar border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.13 Toolbar ─────────────────────────────────────────────────────────────

/// Toolbar sizing, spacing, and font.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "font")]
pub struct ToolbarTheme {
    /// Toolbar background color.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Toolbar height in logical pixels. `None` where the platform states
    /// no toolbar height: KDE's toolbar sizes to its content, and GNOME's
    /// `.toolbar` sets no minimum height (docs/platform-facts.md §2.13).
    #[serde(rename = "bar_height_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub bar_height: Option<f32>,
    /// Horizontal space between toolbar items. `None` where the theme cites
    /// no source for one (docs/platform-facts.md §2.13 states it for every
    /// platform, but a colour scheme has none).
    #[serde(rename = "item_gap_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub item_gap: Option<f32>,
    /// Toolbar icon size in logical pixels.
    #[serde(rename = "icon_size_px")]
    #[theme(check = "non_negative", inherit_from = "defaults.icon_sizes.toolbar")]
    pub icon_size: Option<f32>,
    /// Toolbar label font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Toolbar border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.14 Status Bar ──────────────────────────────────────────────────────────

/// Status bar font and background.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_layer(border_kind = "partial")]
#[theme_inherit(border_kind = "partial", font = "font")]
pub struct StatusBarTheme {
    /// Status bar background color.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Status bar font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Status bar border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.15 List / Table ────────────────────────────────────────────────────────

/// List and table colors and row geometry.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "item_font")]
#[theme_inherit(font = "header_font")]
pub struct ListTheme {
    /// List background fill.
    pub background_color: Option<Rgba>,
    /// Alternate row background for striped lists.
    pub alternate_row_background: Option<Rgba>,
    /// Selected row highlight color.
    #[theme(inherit_from = "defaults.selection_background")]
    pub selection_background: Option<Rgba>,
    /// Text color inside a selected row.
    #[theme(inherit_from = "defaults.selection_text_color")]
    pub selection_text_color: Option<Rgba>,
    /// Column header background fill.
    #[theme(inherit_from = "defaults.surface_color")]
    pub header_background: Option<Rgba>,
    /// Grid line color between rows/columns.
    #[theme(inherit_from = "defaults.border.color")]
    pub grid_color: Option<Rgba>,
    /// Row height in logical pixels. `None` where the platform states no row
    /// height: KDE's rows size to their content, and GNOME's plain list sets
    /// no minimum height (docs/platform-facts.md §2.15).
    #[serde(rename = "row_height_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub row_height: Option<f32>,
    /// Hovered row background color.
    #[theme(inherit_from = "defaults.background_color")]
    pub hover_background: Option<Rgba>,
    /// Hovered row text color.
    pub hover_text_color: Option<Rgba>,
    /// Disabled row text color.
    #[theme(inherit_from = "defaults.disabled_text_color")]
    pub disabled_text_color: Option<Rgba>,
    /// List item font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub item_font: Option<FontSpec>,
    /// Column header font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub header_font: Option<FontSpec>,
    /// List border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.16 Popover / Dropdown ──────────────────────────────────────────────────

/// Popover / dropdown panel appearance.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full_lg", font = "font")]
pub struct PopoverTheme {
    /// Panel background fill.
    pub background_color: Option<Rgba>,
    /// Popover font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Popover border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.17 Splitter ────────────────────────────────────────────────────────────

/// Splitter handle width and color.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
pub struct SplitterTheme {
    /// Handle width in logical pixels.
    #[serde(rename = "divider_width_px")]
    #[theme(check = "non_negative")]
    pub divider_width: Option<f32>,
    /// Divider color.
    #[theme(inherit_from = "defaults.border.color")]
    pub divider_color: Option<Rgba>,
    /// Divider color on hover.
    pub hover_color: Option<Rgba>,
}

// ── 2.18 Separator ───────────────────────────────────────────────────────────

/// Separator line color and width.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
pub struct SeparatorTheme {
    /// Separator line color.
    #[theme(inherit_from = "defaults.border.color")]
    pub line_color: Option<Rgba>,
    /// Separator line width in logical pixels.
    #[serde(rename = "line_width_px")]
    #[theme(check = "non_negative", inherit_from = "defaults.border.line_width")]
    pub line_width: Option<f32>,
}

// ── 2.21 Switch / Toggle ─────────────────────────────────────────────────────

/// Toggle switch track, thumb, geometry, and interactive states.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
pub struct SwitchTheme {
    /// Track background when the switch is on.
    #[theme(inherit_from = "defaults.accent_color")]
    pub checked_background: Option<Rgba>,
    /// Track background when the switch is off.
    pub unchecked_background: Option<Rgba>,
    /// Thumb (knob) color; while the switch is off, `unchecked_thumb_background`
    /// where the theme states one.
    #[theme(inherit_from = "defaults.surface_color")]
    pub thumb_background: Option<Rgba>,
    /// Thumb color while the switch is off, where the platform colours it
    /// apart: Material's `outline`, WinUI's `TextFillColorSecondary`,
    /// libadwaita's `$slider_color`. `None` where the thumb is one colour in
    /// both states, `thumb_background` (docs/platform-facts.md §2.21).
    #[theme(category = "soft_option")]
    pub unchecked_thumb_background: Option<Rgba>,
    /// Track width in logical pixels.
    #[serde(rename = "track_width_px")]
    #[theme(check = "non_negative")]
    pub track_width: Option<f32>,
    /// Track height in logical pixels.
    #[serde(rename = "track_height_px")]
    #[theme(check = "non_negative")]
    pub track_height: Option<f32>,
    /// Thumb diameter in logical pixels; while the switch is off,
    /// `unchecked_thumb_diameter` where the theme states one.
    #[serde(rename = "thumb_diameter_px")]
    #[theme(check = "non_negative")]
    pub thumb_diameter: Option<f32>,
    /// Thumb diameter while the switch is off, in logical pixels, where the
    /// platform sizes it apart: Material's is 16 off, 24 on. `None` where the
    /// thumb is one size in both states, `thumb_diameter`
    /// (docs/platform-facts.md §2.21).
    #[serde(rename = "unchecked_thumb_diameter_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub unchecked_thumb_diameter: Option<f32>,
    /// Track corner radius in logical pixels.
    #[serde(rename = "track_radius_px")]
    #[theme(check = "non_negative")]
    pub track_radius: Option<f32>,
    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
    /// widget on top of its disabled colours (see
    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
    pub disabled_opacity: Option<f32>,
    /// Track hover color when checked (on).
    #[theme(category = "soft_option")]
    pub hover_checked_background: Option<Rgba>,
    /// Track hover color when unchecked (off).
    #[theme(category = "soft_option")]
    pub hover_unchecked_background: Option<Rgba>,
    /// Track color when disabled and checked; `None`, the enabled colour (as
    /// for the two below).
    #[theme(category = "soft_option")]
    pub disabled_checked_background: Option<Rgba>,
    /// Track color when disabled and unchecked.
    #[theme(category = "soft_option")]
    pub disabled_unchecked_background: Option<Rgba>,
    /// Thumb color when disabled.
    #[theme(category = "soft_option")]
    pub disabled_thumb_color: Option<Rgba>,
}

// ── 2.22 Dialog ──────────────────────────────────────────────────────────────

/// Dialog sizing, spacing, button order, fonts, border, and background.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full_lg", font = "title_font")]
#[theme_inherit(font = "body_font")]
pub struct DialogTheme {
    /// Dialog background color.
    pub background_color: Option<Rgba>,
    /// Minimum dialog width in logical pixels.
    #[serde(rename = "min_width_px")]
    #[theme(check = "non_negative", min_max_pair = "max_width")]
    pub min_width: Option<f32>,
    /// Maximum dialog width in logical pixels.
    #[serde(rename = "max_width_px")]
    #[theme(check = "non_negative")]
    pub max_width: Option<f32>,
    /// Minimum dialog height in logical pixels.
    #[serde(rename = "min_height_px")]
    #[theme(check = "non_negative", min_max_pair = "max_height")]
    pub min_height: Option<f32>,
    /// Maximum dialog height in logical pixels.
    #[serde(rename = "max_height_px")]
    #[theme(check = "non_negative")]
    pub max_height: Option<f32>,
    /// Horizontal space between dialog buttons.
    #[serde(rename = "button_gap_px")]
    #[theme(check = "non_negative")]
    pub button_gap: Option<f32>,
    /// Icon size for dialog type icons (warning, error, etc.).
    #[serde(rename = "icon_size_px")]
    #[theme(check = "non_negative")]
    pub icon_size: Option<f32>,
    /// Platform button order convention (e.g., OK/Cancel vs Cancel/OK).
    pub button_order: Option<DialogButtonOrder>,
    /// Dialog title font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub title_font: Option<FontSpec>,
    /// Dialog body font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub body_font: Option<FontSpec>,
    /// Dialog border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.23 Spinner / Progress Ring ─────────────────────────────────────────────

/// Spinner / indeterminate progress indicator.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
pub struct SpinnerTheme {
    /// Spinner arc fill color.
    pub fill_color: Option<Rgba>,
    /// Spinner outer diameter in logical pixels.
    #[serde(rename = "diameter_px")]
    #[theme(check = "non_negative")]
    pub diameter: Option<f32>,
    /// Minimum rendered size in logical pixels.
    #[serde(rename = "min_diameter_px")]
    #[theme(check = "non_negative")]
    pub min_diameter: Option<f32>,
    /// Arc stroke width in logical pixels.
    #[serde(rename = "stroke_width_px")]
    #[theme(check = "non_negative")]
    pub stroke_width: Option<f32>,
}

// ── 2.24 ComboBox / Dropdown Trigger ─────────────────────────────────────────

/// ComboBox / dropdown trigger sizing.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "font")]
pub struct ComboBoxTheme {
    /// ComboBox background color.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Minimum trigger height in logical pixels.
    #[serde(rename = "min_height_px")]
    #[theme(check = "non_negative")]
    pub min_height: Option<f32>,
    /// Minimum trigger width in logical pixels.
    #[serde(rename = "min_width_px")]
    #[theme(check = "non_negative")]
    pub min_width: Option<f32>,
    /// Dropdown arrow size in logical pixels.
    #[serde(rename = "arrow_icon_size_px")]
    #[theme(check = "non_negative")]
    pub arrow_icon_size: Option<f32>,
    /// Width of the arrow clickable area, in logical pixels. `None` where the
    /// theme states no width (docs/platform-facts.md §2.24): GNOME's dropdown
    /// draws its arrow inline, macOS's width is only a measured range
    /// (~16–18px), and the iOS and Material platform presets and the community
    /// colour-scheme presets cite none.
    #[serde(rename = "arrow_area_width_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub arrow_area_width: Option<f32>,
    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
    /// widget on top of its disabled colours (see
    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
    pub disabled_opacity: Option<f32>,
    /// ComboBox text color when disabled.
    #[theme(inherit_from = "defaults.disabled_text_color")]
    pub disabled_text_color: Option<Rgba>,
    /// ComboBox background on hover.
    #[theme(category = "soft_option")]
    pub hover_background: Option<Rgba>,
    /// ComboBox background when disabled; `None`, the enabled background.
    #[theme(category = "soft_option")]
    pub disabled_background: Option<Rgba>,
    /// ComboBox font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// ComboBox border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.25 Segmented Control ───────────────────────────────────────────────────

/// Segmented control sizing (macOS-primary; KDE uses tab bar metrics as proxy).
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "font")]
pub struct SegmentedControlTheme {
    /// Segmented control background color.
    #[theme(inherit_from = "defaults.background_color")]
    pub background_color: Option<Rgba>,
    /// Active segment background.
    #[theme(inherit_from = "defaults.accent_color")]
    pub active_background: Option<Rgba>,
    /// Active segment text color.
    #[theme(inherit_from = "defaults.accent_text_color")]
    pub active_text_color: Option<Rgba>,
    /// Segment height in logical pixels.
    #[serde(rename = "segment_height_px")]
    #[theme(check = "non_negative")]
    pub segment_height: Option<f32>,
    /// Width of the separator between segments.
    #[serde(rename = "separator_width_px")]
    #[theme(check = "non_negative")]
    pub separator_width: Option<f32>,
    /// Opacity multiplier when disabled (0.0-1.0), applied to the whole
    /// widget on top of its disabled colours (see
    /// [`ThemeDefaults::disabled_opacity`](crate::model::ThemeDefaults::disabled_opacity)).
    #[theme(range = "0.0..=1.0", inherit_from = "defaults.disabled_opacity")]
    pub disabled_opacity: Option<f32>,
    /// Segment background on hover.
    #[theme(category = "soft_option")]
    pub hover_background: Option<Rgba>,
    /// Segmented control font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Segmented control border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.26 Card / Container ────────────────────────────────────────────────────

/// Card / container colors and geometry.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_layer(border_kind = "none")]
pub struct CardTheme {
    /// Card background fill.
    #[theme(inherit_from = "defaults.surface_color")]
    pub background_color: Option<Rgba>,
    /// Card border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.27 Expander / Disclosure ───────────────────────────────────────────────

/// Expander / disclosure row geometry.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(border_kind = "full", font = "font")]
pub struct ExpanderTheme {
    /// Collapsed header row height in logical pixels.
    #[serde(rename = "header_height_px")]
    #[theme(check = "non_negative")]
    pub header_height: Option<f32>,
    /// Disclosure arrow size in logical pixels.
    #[serde(rename = "arrow_icon_size_px")]
    #[theme(check = "non_negative")]
    pub arrow_icon_size: Option<f32>,
    /// Expander header background on hover.
    #[theme(category = "soft_option")]
    pub hover_background: Option<Rgba>,
    /// Disclosure arrow/chevron color.
    #[theme(category = "soft_option")]
    pub arrow_color: Option<Rgba>,
    /// Which end of the header row the disclosure arrow sits at: before the
    /// title, or at the row's end. `None` where the theme states none
    /// (docs/platform-facts.md §2.27).
    #[theme(category = "soft_option")]
    pub arrow_side: Option<ArrowSide>,
    /// Space between the arrow's icon box (`arrow_icon_size` square) and the
    /// title after it, or, for a trailing arrow, the header content before
    /// it, in logical pixels. `None` where the platform states none: AppKit
    /// documents no disclosure geometry (docs/platform-facts.md §2.27).
    #[serde(rename = "arrow_gap_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub arrow_gap: Option<f32>,
    /// Horizontal distance from the expander's leading inner edge (inside
    /// its frame, where it has one) to the content it reveals, in logical
    /// pixels. `None` where the platform states none: AppKit documents no
    /// disclosure geometry (docs/platform-facts.md §2.27).
    #[serde(rename = "content_indent_px")]
    #[theme(category = "soft_option", check = "non_negative")]
    pub content_indent: Option<f32>,
    /// Whether the expander draws a frame (its `border`) around its header
    /// and the content it reveals: KDE's has none, libadwaita's and WinUI's
    /// are framed. `None` where the theme states none
    /// (docs/platform-facts.md §2.27).
    #[theme(category = "soft_option")]
    pub frame_enabled: Option<bool>,
    /// Expander font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
    /// Expander border specification.
    #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
    pub border: Option<WidgetBorderSpec>,
}

// ── 2.28 Link ────────────────────────────────────────────────────────────────

/// Hyperlink colors and underline setting.
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_inherit(font = "font")]
pub struct LinkTheme {
    /// Visited link text color.
    #[theme(inherit_from = "defaults.link_color")]
    pub visited_text_color: Option<Rgba>,
    /// Whether links are underlined.
    pub underline_enabled: Option<bool>,
    /// Link background fill (typically transparent).
    pub background_color: Option<Rgba>,
    /// Link background on hover.
    pub hover_background: Option<Rgba>,
    /// Link text color on hover.
    pub hover_text_color: Option<Rgba>,
    /// Link text color when pressed/active.
    pub active_text_color: Option<Rgba>,
    /// Link text color when disabled.
    #[theme(inherit_from = "defaults.disabled_text_color")]
    pub disabled_text_color: Option<Rgba>,
    /// Link font specification.
    #[theme(nested, resolved_type = "ResolvedFontSpec")]
    pub font: Option<FontSpec>,
}

// -- Layout (top-level, not per-variant) ------------------------------------------

/// Layout spacing constants shared between light and dark variants.
///
/// Unlike other widget themes, LayoutTheme lives on [`crate::Theme`] (top-level)
/// rather than [`crate::ThemeMode`] because spacing is variant-independent.
// Phase 93-05 G5: LayoutTheme keeps `skip_inventory` so it does NOT register
// in the per-variant WidgetFieldInfo registry (it is top-level, not per-variant),
// but also derives ThemeFields so lint_toml can look up its fields in the
// non-widget FieldInfo registry under the key "LayoutTheme".
#[derive(
    Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget, ThemeFields,
)]
#[serde_with::skip_serializing_none]
#[serde(default)]
#[theme_layer(skip_inventory)]
pub struct LayoutTheme {
    /// Space between adjacent widgets in logical pixels.
    #[serde(rename = "widget_gap_px")]
    #[theme(check = "non_negative")]
    pub widget_gap: Option<f32>,
    /// Padding inside containers in logical pixels.
    #[serde(rename = "container_margin_px")]
    #[theme(check = "non_negative")]
    pub container_margin: Option<f32>,
    /// Padding inside the main window in logical pixels.
    #[serde(rename = "window_margin_px")]
    #[theme(check = "non_negative")]
    pub window_margin: Option<f32>,
    /// Space between major content sections in logical pixels.
    #[serde(rename = "section_gap_px")]
    #[theme(check = "non_negative")]
    pub section_gap: Option<f32>,
}

#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, dead_code)]
mod tests {
    use super::*;
    use crate::Rgba;
    use crate::model::border::{ResolvedWidgetBorder, WidgetBorderSpec};
    use crate::model::font::FontSize;
    use crate::model::{DialogButtonOrder, FontSpec};

    // Test widget using derive (validates derive macro works in test context)
    /// Test widget for macro verification.
    #[derive(
        Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
    )]
    #[serde_with::skip_serializing_none]
    #[serde(default)]
    #[theme_layer(skip_inventory)]
    pub struct TestWidget {
        pub size: Option<f32>,
        pub label: Option<String>,
        #[theme(nested, resolved_type = "ResolvedFontSpec")]
        pub font: Option<FontSpec>,
    }

    // === ResolvedFontSpec tests ===

    #[test]
    fn resolved_font_spec_fields_are_concrete() {
        let rfs = ResolvedFontSpec {
            family: "Inter".into(),
            size: 14.0,
            defined_size: Some(crate::model::font::FontSize::Px(14.0)),
            weight: 400,
            style: crate::model::font::FontStyle::Normal,
            color: crate::Rgba::rgb(0, 0, 0),
        };
        assert_eq!(rfs.family.as_ref(), "Inter");
        assert_eq!(rfs.size, 14.0);
        assert_eq!(rfs.weight, 400);
    }

    // === derive(ThemeWidget) generated struct tests ===

    #[test]
    fn generated_option_struct_has_option_fields() {
        let w = TestWidget::default();
        assert!(w.size.is_none());
        assert!(w.label.is_none());
        assert!(w.font.is_none());
    }

    #[test]
    fn generated_option_struct_is_empty_by_default() {
        assert!(TestWidget::default().is_empty());
    }

    #[test]
    fn generated_option_struct_not_empty_when_size_set() {
        let w = TestWidget {
            size: Some(24.0),
            ..Default::default()
        };
        assert!(!w.is_empty());
    }

    #[test]
    fn generated_option_struct_not_empty_when_font_set() {
        let w = TestWidget {
            font: Some(FontSpec {
                size: Some(FontSize::Px(14.0)),
                ..Default::default()
            }),
            ..Default::default()
        };
        assert!(!w.is_empty());
    }

    #[test]
    fn generated_resolved_struct_has_concrete_fields() {
        let resolved = ResolvedTestWidget {
            size: 24.0,
            label: "Click me".into(),
            font: ResolvedFontSpec {
                family: "Inter".into(),
                size: 14.0,
                defined_size: Some(crate::model::font::FontSize::Px(14.0)),
                weight: 400,
                style: crate::model::font::FontStyle::Normal,
                color: crate::Rgba::rgb(0, 0, 0),
            },
        };
        assert_eq!(resolved.size, 24.0);
        assert_eq!(resolved.label, "Click me");
        assert_eq!(resolved.font.family.as_ref(), "Inter");
    }

    // === merge tests for generated structs ===

    #[test]
    fn generated_merge_option_field_overlay_wins() {
        let mut base = TestWidget {
            size: Some(20.0),
            ..Default::default()
        };
        let overlay = TestWidget {
            size: Some(24.0),
            ..Default::default()
        };
        base.merge(&overlay);
        assert_eq!(base.size, Some(24.0));
    }

    #[test]
    fn generated_merge_option_field_none_preserves_base() {
        let mut base = TestWidget {
            size: Some(20.0),
            ..Default::default()
        };
        let overlay = TestWidget::default();
        base.merge(&overlay);
        assert_eq!(base.size, Some(20.0));
    }

    #[test]
    fn generated_merge_optional_nested_both_some_merges_inner() {
        let mut base = TestWidget {
            font: Some(FontSpec {
                family: Some("Noto Sans".into()),
                size: Some(FontSize::Px(12.0)),
                weight: None,
                ..Default::default()
            }),
            ..Default::default()
        };
        let overlay = TestWidget {
            font: Some(FontSpec {
                family: None,
                size: None,
                weight: Some(700),
                ..Default::default()
            }),
            ..Default::default()
        };
        base.merge(&overlay);
        let font = base.font.as_ref().unwrap();
        assert_eq!(font.family.as_deref(), Some("Noto Sans")); // preserved
        assert_eq!(font.size, Some(FontSize::Px(12.0))); // preserved
        assert_eq!(font.weight, Some(700)); // overlay sets
    }

    #[test]
    fn generated_merge_optional_nested_none_plus_some_clones() {
        let mut base = TestWidget::default();
        let overlay = TestWidget {
            font: Some(FontSpec {
                family: Some("Inter".into()),
                size: Some(FontSize::Px(14.0)),
                weight: Some(400),
                ..Default::default()
            }),
            ..Default::default()
        };
        base.merge(&overlay);
        let font = base.font.as_ref().unwrap();
        assert_eq!(font.family.as_deref(), Some("Inter"));
        assert_eq!(font.size, Some(FontSize::Px(14.0)));
        assert_eq!(font.weight, Some(400));
    }

    #[test]
    fn generated_merge_optional_nested_some_plus_none_preserves_base() {
        let mut base = TestWidget {
            font: Some(FontSpec {
                family: Some("Inter".into()),
                size: Some(FontSize::Px(14.0)),
                weight: Some(400),
                ..Default::default()
            }),
            ..Default::default()
        };
        let overlay = TestWidget::default();
        base.merge(&overlay);
        let font = base.font.as_ref().unwrap();
        assert_eq!(font.family.as_deref(), Some("Inter"));
    }

    #[test]
    fn generated_merge_optional_nested_none_plus_none_stays_none() {
        let mut base = TestWidget::default();
        let overlay = TestWidget::default();
        base.merge(&overlay);
        assert!(base.font.is_none());
    }

    // === impl_merge! optional_nested clause direct tests ===

    // Verify the optional_nested clause directly on a FontSpec-containing struct
    #[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
    struct WithFont {
        name: Option<String>,
        font: Option<FontSpec>,
    }

    impl_merge!(WithFont {
        option { name }
        optional_nested { font }
    });

    #[test]
    fn impl_merge_optional_nested_none_none_stays_none() {
        let mut base = WithFont::default();
        let overlay = WithFont::default();
        base.merge(&overlay);
        assert!(base.font.is_none());
    }

    #[test]
    fn impl_merge_optional_nested_some_none_preserves_base() {
        let mut base = WithFont {
            font: Some(FontSpec {
                size: Some(FontSize::Px(12.0)),
                ..Default::default()
            }),
            ..Default::default()
        };
        let overlay = WithFont::default();
        base.merge(&overlay);
        assert_eq!(base.font.as_ref().unwrap().size, Some(FontSize::Px(12.0)));
    }

    #[test]
    fn impl_merge_optional_nested_none_some_clones_overlay() {
        let mut base = WithFont::default();
        let overlay = WithFont {
            font: Some(FontSpec {
                family: Some("Inter".into()),
                ..Default::default()
            }),
            ..Default::default()
        };
        base.merge(&overlay);
        assert_eq!(base.font.as_ref().unwrap().family.as_deref(), Some("Inter"));
    }

    #[test]
    fn impl_merge_optional_nested_some_some_merges_inner() {
        let mut base = WithFont {
            font: Some(FontSpec {
                family: Some("Noto".into()),
                size: Some(FontSize::Px(11.0)),
                weight: None,
                ..Default::default()
            }),
            ..Default::default()
        };
        let overlay = WithFont {
            font: Some(FontSpec {
                family: None,
                size: Some(FontSize::Px(14.0)),
                weight: Some(400),
                ..Default::default()
            }),
            ..Default::default()
        };
        base.merge(&overlay);
        let f = base.font.as_ref().unwrap();
        assert_eq!(f.family.as_deref(), Some("Noto")); // preserved
        assert_eq!(f.size, Some(FontSize::Px(14.0))); // overlay wins
        assert_eq!(f.weight, Some(400)); // overlay sets
    }

    #[test]
    fn impl_merge_optional_nested_is_empty_none() {
        let w = WithFont::default();
        assert!(w.is_empty());
    }

    #[test]
    fn impl_merge_optional_nested_is_empty_some_default() {
        // Some(FontSpec::default()) with all-None sub-fields counts as empty (D-2 fix).
        let w = WithFont {
            font: Some(FontSpec::default()),
            ..Default::default()
        };
        assert!(w.is_empty());
    }

    #[test]
    fn impl_merge_optional_nested_is_not_empty_when_populated() {
        let w = WithFont {
            font: Some(FontSpec {
                size: Some(FontSize::Px(14.0)),
                ..Default::default()
            }),
            ..Default::default()
        };
        assert!(!w.is_empty());
    }

    // === ButtonTheme tests ===

    #[test]
    fn button_theme_default_is_empty() {
        assert!(ButtonTheme::default().is_empty());
    }

    #[test]
    fn button_theme_not_empty_when_set() {
        let b = ButtonTheme {
            background_color: Some(Rgba::rgb(200, 200, 200)),
            min_width: Some(64.0),
            ..Default::default()
        };
        assert!(!b.is_empty());
    }

    #[test]
    fn button_theme_merge_font_optional_nested() {
        let mut base = ButtonTheme {
            font: Some(FontSpec {
                family: Some("Noto Sans".into()),
                size: Some(FontSize::Px(11.0)),
                weight: None,
                ..Default::default()
            }),
            ..Default::default()
        };
        let overlay = ButtonTheme {
            font: Some(FontSpec {
                family: None,
                weight: Some(700),
                ..Default::default()
            }),
            ..Default::default()
        };
        base.merge(&overlay);
        let f = base.font.as_ref().unwrap();
        assert_eq!(f.family.as_deref(), Some("Noto Sans")); // preserved
        assert_eq!(f.weight, Some(700)); // overlay
    }

    #[test]
    fn button_theme_toml_round_trip_with_font_and_border() {
        let b = ButtonTheme {
            background_color: Some(Rgba::rgb(200, 200, 200)),
            font: Some(FontSpec {
                family: Some("Inter".into()),
                size: Some(FontSize::Px(14.0)),
                weight: Some(400),
                ..Default::default()
            }),
            border: Some(WidgetBorderSpec {
                corner_radius: Some(4.0),
                ..Default::default()
            }),
            ..Default::default()
        };
        let toml_str = toml::to_string(&b).unwrap();
        let b2: ButtonTheme = toml::from_str(&toml_str).unwrap();
        assert_eq!(b, b2);
    }

    // === WindowTheme tests ===

    #[test]
    fn window_theme_has_new_fields() {
        let w = WindowTheme {
            inactive_title_bar_background: Some(Rgba::rgb(180, 180, 180)),
            inactive_title_bar_text_color: Some(Rgba::rgb(120, 120, 120)),
            title_bar_font: Some(FontSpec {
                weight: Some(700),
                ..Default::default()
            }),
            border: Some(WidgetBorderSpec {
                corner_radius: Some(4.0),
                shadow_enabled: Some(true),
                ..Default::default()
            }),
            ..Default::default()
        };
        assert!(!w.is_empty());
        assert!(w.inactive_title_bar_background.is_some());
        assert!(w.inactive_title_bar_text_color.is_some());
        assert!(w.title_bar_font.is_some());
        assert!(w.border.is_some());
    }

    #[test]
    fn window_theme_default_is_empty() {
        assert!(WindowTheme::default().is_empty());
    }

    // === DialogTheme tests ===

    #[test]
    fn dialog_theme_button_order_works() {
        let d = DialogTheme {
            button_order: Some(DialogButtonOrder::PrimaryRight),
            min_width: Some(300.0),
            ..Default::default()
        };
        assert_eq!(d.button_order, Some(DialogButtonOrder::PrimaryRight));
        assert_eq!(d.min_width, Some(300.0));
        assert!(!d.is_empty());
    }

    #[test]
    fn dialog_theme_button_order_toml_round_trip() {
        let d = DialogTheme {
            button_order: Some(DialogButtonOrder::PrimaryLeft),
            ..Default::default()
        };
        let toml_str = toml::to_string(&d).unwrap();
        let d2: DialogTheme = toml::from_str(&toml_str).unwrap();
        assert_eq!(d, d2);
    }

    #[test]
    fn dialog_theme_default_is_empty() {
        assert!(DialogTheme::default().is_empty());
    }

    // === SplitterTheme tests ===

    #[test]
    fn splitter_theme_single_field_merge() {
        let mut base = SplitterTheme {
            divider_width: Some(4.0),
            ..Default::default()
        };
        let overlay = SplitterTheme {
            divider_width: Some(6.0),
            ..Default::default()
        };
        base.merge(&overlay);
        assert_eq!(base.divider_width, Some(6.0));
    }

    #[test]
    fn splitter_theme_merge_none_preserves_base() {
        let mut base = SplitterTheme {
            divider_width: Some(4.0),
            ..Default::default()
        };
        let overlay = SplitterTheme::default();
        base.merge(&overlay);
        assert_eq!(base.divider_width, Some(4.0));
    }

    #[test]
    fn splitter_theme_default_is_empty() {
        assert!(SplitterTheme::default().is_empty());
    }

    #[test]
    fn splitter_theme_not_empty_when_set() {
        assert!(
            !SplitterTheme {
                divider_width: Some(4.0),
                ..Default::default()
            }
            .is_empty()
        );
    }

    // === SeparatorTheme tests ===

    #[test]
    fn separator_theme_single_field() {
        let s = SeparatorTheme {
            line_color: Some(Rgba::rgb(200, 200, 200)),
            ..Default::default()
        };
        assert!(!s.is_empty());
    }

    // === All 25 widget theme defaults are empty ===

    #[test]
    fn all_widget_theme_defaults_are_empty() {
        assert!(WindowTheme::default().is_empty());
        assert!(ButtonTheme::default().is_empty());
        assert!(InputTheme::default().is_empty());
        assert!(CheckboxTheme::default().is_empty());
        assert!(MenuTheme::default().is_empty());
        assert!(TooltipTheme::default().is_empty());
        assert!(ScrollbarTheme::default().is_empty());
        assert!(SliderTheme::default().is_empty());
        assert!(ProgressBarTheme::default().is_empty());
        assert!(TabTheme::default().is_empty());
        assert!(SidebarTheme::default().is_empty());
        assert!(ToolbarTheme::default().is_empty());
        assert!(StatusBarTheme::default().is_empty());
        assert!(ListTheme::default().is_empty());
        assert!(PopoverTheme::default().is_empty());
        assert!(SplitterTheme::default().is_empty());
        assert!(SeparatorTheme::default().is_empty());
        assert!(SwitchTheme::default().is_empty());
        assert!(DialogTheme::default().is_empty());
        assert!(SpinnerTheme::default().is_empty());
        assert!(ComboBoxTheme::default().is_empty());
        assert!(SegmentedControlTheme::default().is_empty());
        assert!(CardTheme::default().is_empty());
        assert!(ExpanderTheme::default().is_empty());
        assert!(LinkTheme::default().is_empty());
    }

    // === Representative TOML round-trips ===

    #[test]
    fn input_theme_toml_round_trip() {
        let t = InputTheme {
            background_color: Some(Rgba::rgb(255, 255, 255)),
            font: Some(FontSpec {
                family: Some("Noto Sans".into()),
                ..Default::default()
            }),
            border: Some(WidgetBorderSpec {
                color: Some(Rgba::rgb(180, 180, 180)),
                corner_radius: Some(4.0),
                ..Default::default()
            }),
            ..Default::default()
        };
        let toml_str = toml::to_string(&t).unwrap();
        let t2: InputTheme = toml::from_str(&toml_str).unwrap();
        assert_eq!(t, t2);
    }

    #[test]
    fn switch_theme_toml_round_trip() {
        let s = SwitchTheme {
            checked_background: Some(Rgba::rgb(0, 120, 215)),
            track_width: Some(40.0),
            track_height: Some(20.0),
            thumb_diameter: Some(14.0),
            track_radius: Some(10.0),
            ..Default::default()
        };
        let toml_str = toml::to_string(&s).unwrap();
        let s2: SwitchTheme = toml::from_str(&toml_str).unwrap();
        assert_eq!(s, s2);
    }

    #[test]
    fn card_theme_with_border() {
        let c = CardTheme {
            background_color: Some(Rgba::rgb(255, 255, 255)),
            border: Some(WidgetBorderSpec {
                corner_radius: Some(8.0),
                shadow_enabled: Some(true),
                ..Default::default()
            }),
        };
        assert!(!c.is_empty());
    }

    #[test]
    fn link_theme_has_underline_enabled_bool_field() {
        let l = LinkTheme {
            visited_text_color: Some(Rgba::rgb(100, 0, 200)),
            underline_enabled: Some(true),
            ..Default::default()
        };
        assert!(!l.is_empty());
        assert_eq!(l.underline_enabled, Some(true));
    }

    #[test]
    fn status_bar_theme_has_font_and_background() {
        let s = StatusBarTheme {
            background_color: Some(Rgba::rgb(240, 240, 240)),
            font: Some(FontSpec {
                size: Some(FontSize::Px(11.0)),
                ..Default::default()
            }),
            ..Default::default()
        };
        assert!(!s.is_empty());
    }

    // === SC4: Dual optional_nested (font + border) test widget ===

    // SC4: Verify derive handles dual optional_nested (font + border)
    /// Test widget with both font and border nested sub-structs.
    #[derive(
        Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize, ThemeWidget,
    )]
    #[serde_with::skip_serializing_none]
    #[serde(default)]
    #[theme_layer(skip_inventory)]
    pub struct DualNestedTestWidget {
        pub background: Option<Rgba>,
        pub min_height: Option<f32>,
        #[theme(nested, resolved_type = "ResolvedFontSpec")]
        pub font: Option<FontSpec>,
        #[theme(nested, resolved_type = "ResolvedWidgetBorder")]
        pub border: Option<WidgetBorderSpec>,
    }

    #[test]
    fn dual_nested_default_is_empty() {
        assert!(DualNestedTestWidget::default().is_empty());
    }

    #[test]
    fn dual_nested_field_names() {
        assert_eq!(DualNestedTestWidget::FIELD_NAMES.len(), 4);
        assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"background"));
        assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"min_height"));
        assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"font"));
        assert!(DualNestedTestWidget::FIELD_NAMES.contains(&"border"));
    }

    #[test]
    fn dual_nested_not_empty_when_font_set() {
        let w = DualNestedTestWidget {
            font: Some(FontSpec {
                family: Some("Inter".into()),
                ..Default::default()
            }),
            ..Default::default()
        };
        assert!(!w.is_empty());
    }

    #[test]
    fn dual_nested_not_empty_when_border_set() {
        let w = DualNestedTestWidget {
            border: Some(WidgetBorderSpec {
                color: Some(Rgba::rgb(100, 100, 100)),
                ..Default::default()
            }),
            ..Default::default()
        };
        assert!(!w.is_empty());
    }

    #[test]
    fn dual_nested_merge_both_nested() {
        let mut base = DualNestedTestWidget {
            font: Some(FontSpec {
                family: Some("Noto Sans".into()),
                ..Default::default()
            }),
            ..Default::default()
        };
        let overlay = DualNestedTestWidget {
            border: Some(WidgetBorderSpec {
                corner_radius: Some(4.0),
                ..Default::default()
            }),
            ..Default::default()
        };
        base.merge(&overlay);
        assert!(base.font.is_some());
        assert!(base.border.is_some());
        assert_eq!(
            base.font.as_ref().and_then(|f| f.family.as_deref()),
            Some("Noto Sans")
        );
        assert_eq!(
            base.border.as_ref().and_then(|b| b.corner_radius),
            Some(4.0)
        );
    }

    #[test]
    fn dual_nested_merge_inner_font_fields() {
        let mut base = DualNestedTestWidget {
            font: Some(FontSpec {
                family: Some("Noto Sans".into()),
                ..Default::default()
            }),
            ..Default::default()
        };
        let overlay = DualNestedTestWidget {
            font: Some(FontSpec {
                size: Some(FontSize::Px(14.0)),
                ..Default::default()
            }),
            ..Default::default()
        };
        base.merge(&overlay);
        let font = base.font.as_ref().unwrap();
        assert_eq!(font.family.as_deref(), Some("Noto Sans")); // preserved
        assert_eq!(font.size, Some(FontSize::Px(14.0))); // overlay sets
    }

    #[test]
    fn dual_nested_toml_round_trip() {
        let w = DualNestedTestWidget {
            background: Some(Rgba::rgb(240, 240, 240)),
            min_height: Some(32.0),
            font: Some(FontSpec {
                family: Some("Inter".into()),
                size: Some(FontSize::Px(14.0)),
                weight: Some(400),
                ..Default::default()
            }),
            border: Some(WidgetBorderSpec {
                color: Some(Rgba::rgb(180, 180, 180)),
                corner_radius: Some(4.0),
                line_width: Some(1.0),
                ..Default::default()
            }),
        };
        let toml_str = toml::to_string(&w).unwrap();
        let w2: DualNestedTestWidget = toml::from_str(&toml_str).unwrap();
        assert_eq!(w, w2);
    }

    // === LayoutTheme tests ===

    // === validate_widget() generation tests ===

    #[test]
    fn button_validate_widget_extracts_all_fields() {
        let button = ButtonTheme {
            background_color: Some(Rgba::rgb(200, 200, 200)),
            primary_background: Some(Rgba::rgb(0, 120, 215)),
            primary_text_color: Some(Rgba::rgb(255, 255, 255)),
            min_width: Some(80.0),
            min_height: Some(32.0),
            icon_text_gap: Some(8.0),
            disabled_opacity: Some(0.4),
            hover_background: Some(Rgba::rgb(210, 210, 210)),
            hover_text_color: Some(Rgba::rgb(0, 0, 0)),
            active_text_color: Some(Rgba::rgb(0, 0, 0)),
            disabled_text_color: Some(Rgba::rgb(128, 128, 128)),
            active_background: Some(Rgba::rgb(180, 180, 180)),
            disabled_background: Some(Rgba::rgb(220, 220, 220)),
            checked_background: Some(Rgba::rgb(190, 190, 190)),
            checked_text_color: None,
            font: Some(FontSpec {
                family: Some("Inter".into()),
                size: Some(FontSize::Px(14.0)),
                weight: Some(400),
                style: Some(crate::model::font::FontStyle::Normal),
                color: Some(Rgba::rgb(0, 0, 0)),
            }),
            border: Some(WidgetBorderSpec {
                color: Some(Rgba::rgb(100, 100, 100)),
                corner_radius: Some(4.0),
                line_width: Some(1.0),
                shadow_enabled: Some(false),
                padding_top: Some(6.0),
                padding_right: Some(12.0),
                padding_bottom: Some(6.0),
                padding_left: Some(12.0),
            }),
        };
        let mut missing = Vec::new();
        let resolved = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
        assert!(missing.is_empty(), "unexpected missing: {missing:?}");
        assert_eq!(resolved.background_color, Rgba::rgb(200, 200, 200));
        assert_eq!(resolved.min_width, 80.0);
        assert_eq!(resolved.font.family.as_ref(), "Inter");
        assert_eq!(resolved.font.size, 14.0);
        assert_eq!(resolved.border.corner_radius, 4.0);
        // soft_option fields pass through as Option
        assert_eq!(resolved.active_background, Some(Rgba::rgb(180, 180, 180)));
        assert_eq!(resolved.disabled_background, Some(Rgba::rgb(220, 220, 220)));
        assert_eq!(resolved.checked_background, Some(Rgba::rgb(190, 190, 190)));
        assert_eq!(resolved.checked_text_color, None);
    }

    #[test]
    fn button_validate_widget_records_missing_fields() {
        let button = ButtonTheme::default(); // all None
        let mut missing = Vec::new();
        let _ = ResolvedButtonTheme::validate_widget(&button, "button", 96.0, &mut missing);
        // option fields should be recorded as missing
        assert!(missing.contains(&"button.background_color".to_string()));
        assert!(missing.contains(&"button.min_width".to_string()));
        // font (optional_nested) should be recorded
        assert!(missing.contains(&"button.font".to_string()));
        // border (optional_nested) should be recorded
        assert!(missing.contains(&"button.border".to_string()));
        // soft_option fields should NOT be recorded as missing
        assert!(!missing.iter().any(|m| m.contains("active_background")));
        assert!(!missing.iter().any(|m| m.contains("disabled_background")));
    }

    // === LayoutTheme tests ===

    #[test]
    fn layout_theme_default_is_empty() {
        assert!(LayoutTheme::default().is_empty());
    }

    #[test]
    fn layout_theme_not_empty_when_widget_gap_set() {
        let l = LayoutTheme {
            widget_gap: Some(8.0),
            ..Default::default()
        };
        assert!(!l.is_empty());
    }

    #[test]
    fn layout_theme_field_names() {
        assert_eq!(LayoutTheme::FIELD_NAMES.len(), 4);
        assert!(LayoutTheme::FIELD_NAMES.contains(&"widget_gap_px"));
        assert!(LayoutTheme::FIELD_NAMES.contains(&"container_margin_px"));
        assert!(LayoutTheme::FIELD_NAMES.contains(&"window_margin_px"));
        assert!(LayoutTheme::FIELD_NAMES.contains(&"section_gap_px"));
    }

    #[test]
    fn layout_theme_toml_round_trip() {
        let l = LayoutTheme {
            widget_gap: Some(8.0),
            container_margin: Some(12.0),
            window_margin: Some(16.0),
            section_gap: Some(24.0),
        };
        let toml_str = toml::to_string(&l).unwrap();
        let l2: LayoutTheme = toml::from_str(&toml_str).unwrap();
        assert_eq!(l, l2);
    }

    #[test]
    fn layout_theme_merge() {
        let mut base = LayoutTheme {
            widget_gap: Some(6.0),
            container_margin: Some(10.0),
            ..Default::default()
        };
        let overlay = LayoutTheme {
            widget_gap: Some(8.0),
            section_gap: Some(24.0),
            ..Default::default()
        };
        base.merge(&overlay);
        // overlay widget_gap replaces base
        assert_eq!(base.widget_gap, Some(8.0));
        // base container_margin preserved
        assert_eq!(base.container_margin, Some(10.0));
        // overlay section_gap added
        assert_eq!(base.section_gap, Some(24.0));
        // window_margin stays None
        assert!(base.window_margin.is_none());
    }
}