rustango-cms 0.4.0

A page-tree content management system for Rust, built on rustango
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
<!DOCTYPE html>
<html lang="{{ LANG | default(value='en') }}" dir="{{ LANG_DIR | default(value='ltr') }}" data-theme="{{ theme_default_mode | default(value="light") }}" data-theme-name="{{ theme_slug | default(value="") }}" class="theme-{{ theme_slug | default(value="default") }}"{% if user_timezone %} data-user-tz-pref="{{ user_timezone }}"{% endif %}{% if tenant_default_timezone %} data-tenant-default-tz="{{ tenant_default_timezone }}"{% endif %}{% if tenant_slug %} data-tenant-slug="{{ tenant_slug }}"{% endif %}>
<head>
    {# Synchronous "no-flash" block: read saved mode preference from
       localStorage BEFORE first paint so the dark/light/system pick
       lands before the chrome renders. Editors who switch the active
       theme via the picker still get an instant repaint, but
       per-visitor mode is sticky across page loads. #}
    <script>
      // No-flash preference loader. Runs BEFORE first paint so the
      // dark/light pick, text-scale, and high-contrast preferences
      // land before chrome renders. "system" mode clears the
      // data-theme attribute so @media (prefers-color-scheme: dark)
      // in cms.css can take over.
      (function() {
        try {
          var m = localStorage.getItem('rcms-admin-mode');
          if (m === 'light' || m === 'dark') {
            document.documentElement.setAttribute('data-theme', m);
          } else {
            document.documentElement.removeAttribute('data-theme');
          }
          var scale = localStorage.getItem('rcms-admin-text-scale');
          if (scale === 's' || scale === 'l' || scale === 'xl') {
            document.documentElement.setAttribute('data-text-scale', scale);
          } else {
            document.documentElement.removeAttribute('data-text-scale');
          }
          if (localStorage.getItem('rcms-admin-high-contrast') === '1') {
            document.documentElement.setAttribute('data-high-contrast', '');
          } else {
            document.documentElement.removeAttribute('data-high-contrast');
          }
          // #271 — sidebar collapse (icons-only). Per-tenant key so
          // a user toggling on one tenant doesn't carry that pick
          // across to another tenant they administer. Read BEFORE
          // first paint to avoid the layout jump.
          var slug = document.documentElement.getAttribute('data-tenant-slug') || '';
          var collapsed = localStorage.getItem('rcms-admin-sidebar-collapsed:' + slug);
          if (collapsed === '1') {
            document.documentElement.setAttribute('data-sidebar-collapsed', '');
          } else {
            document.documentElement.removeAttribute('data-sidebar-collapsed');
          }
        } catch (e) { /* ignore */ }
      })();
    </script>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %}{{ site_name | default(value="CMS Admin") }}{% endblock %}</title>
    {% include "rcms_admin/_brand_icons.html" %}
    {# Fonts — Hanken Grotesk for UI + Literata for editor body
       surfaces. The per-tenant `theme_font_url` (loaded second)
       overrides via a different family if the theme supplies one. #}
    {% if theme_font_url %}<link rel="stylesheet" href="{{ theme_font_url }}">{% endif %}
    {# Bundled MD3 design system — single source of truth for all
       admin chrome. Host apps override by dropping
       static/cms_admin/cms.css in their project root. #}
    <link rel="stylesheet" href="/cms-admin/static/fonts.css?v={{ cms_asset_version() }}">
    <link rel="stylesheet" href="/cms-admin/static/cms.css?v={{ cms_asset_version() }}">
    {# Active admin theme — emitted as a <style> block with CSS
       custom properties on :root + [data-theme="dark"]. Generated by
       theme::emit_css() against the row flagged is_admin_default.
       Loaded AFTER cms.css so tenant overrides cascade over the
       bundled defaults.
       Defaulted to empty so handlers that don't call
       `add_admin_theme` (e.g. media_upload, error renders) don't
       crash the template — the MD3 chrome from cms.css is still
       fully usable without the per-tenant overlay. #}
    {{ theme_css | default(value="") | safe }}
    {# #422 — plugin-injected global admin CSS (insert_global_admin_css). #}
    {% for css in admin_css_blobs | default(value=[]) %}
        <style>{{ css | safe }}</style>
    {% endfor %}
    {% block extra_head %}{% endblock %}
</head>
<body class="rcms-admin">
    <input type="checkbox" id="__nav_toggle" hidden>
    <label for="__nav_toggle" class="rcms-nav-backdrop"></label>

    <aside class="rcms-sidebar">
        <div class="rcms-sidebar-brand has-logo">
            {#- The site's mark and name: the logo uploaded under Settings →
                Branding, else the Rustango CMS icon (light or dark with the
                theme), always beside the site name. -#}
            <a href="{{ url(name='rcms-admin:dashboard') }}" class="rcms-sidebar-brand-mark" aria-hidden="true" tabindex="-1">
                {%- if branding_logo_url %}
                <img src="{{ branding_logo_url }}" alt="" width="36" height="36">
                {%- else %}
                <img src="/cms-admin/static/brand/icon-light.png?v={{ cms_asset_version() }}" alt="" class="rcms-brand-for-light" width="36" height="36">
                <img src="/cms-admin/static/brand/icon-dark.png?v={{ cms_asset_version() }}" alt="" class="rcms-brand-for-dark" width="36" height="36">
                {%- endif %}
            </a>
            <h1>{{ site_name | default(value="Rustango CMS") }}</h1>
            {# #271 — collapse / expand toggle. Sits at the top of
               the sidebar (right of the brand); clicking shrinks the
               sidebar to an icons-only rail
               (`html[data-sidebar-collapsed]` selector) and persists
               the pick per tenant in localStorage. The no-flash
               <script> in <head> reads the same key before first
               paint, so reloads don't flicker. #}
            <button type="button"
                    class="rcms-sidebar-collapse-toggle"
                    data-sidebar-collapse-toggle
                    aria-label="{{ "Collapse sidebar to icons" | translate(locale=LANG) }}">
                <span class="material-symbols-rounded">chevron_left</span>
            </button>
        </div>
        {# #77 — Global search. Lives in the sidebar rather than the
           topbar: search is navigation, and the topbar's three-child
           layout gave it no natural home — it stranded mid-row between
           the page title and the page actions. Here it also survives
           the mobile breakpoint, where the topbar copy was simply
           hidden. The `/` shortcut and the autocomplete dropdown are
           wired by document-level selectors in cms-ux.js, so the markup
           moves without touching the JS. #}
        <div class="rcms-sidebar-search rcms-relative" data-search-root>
            <form method="get" action="{{ url(name='rcms-admin:search') }}"
                  class="rcms-search-input rcms-search-input--sidebar"
                  title="{{ "Search…  press /" | translate(locale=LANG) }}">
                <span class="material-symbols-rounded sm">search</span>
                <input type="search" name="q" placeholder="{{ "Search…  press /" | translate(locale=LANG) }}"
                       data-search-input autocomplete="off">
            </form>
            {# Anchored inside the sidebar on purpose: `.rcms-sidebar` is
               `overflow-y: auto`, so a dropdown escaping its box would be
               clipped. It spans the rail width and scrolls itself. #}
            <div data-search-dropdown class="rcms-sidebar-search-dropdown" style="display: none;"></div>
        </div>
        <nav class="rcms-sidebar-nav">
            {# Sidebar gating (#33): a link renders when one of the
               following is true —
                 1. `sidebar_gating` is false (anon flows / handlers
                    that don't call add_user_chrome yet),
                 2. the user is a superuser,
                 3. the resource's `<prefix>.view` codename is in the
                    pre-computed `allowed_resources` set.
               When false, the item is omitted from the DOM entirely. #}
            <div class="rcms-sidebar-section">{{ "Content" | translate(locale=LANG) }}</div>
            {% if not sidebar_gating or user_is_superuser or "cms_page.view" in allowed_resources %}
            <a href="{{ url(name='rcms-admin:pages:list') }}" class="rcms-sidebar-link{% if active_tab == "pages" %} active{% endif %}">
                <span class="material-symbols-rounded">article</span> {{ "Pages" | translate(locale=LANG) }}
            </a>
            {% endif %}
            {# #557 — Taxonomies (categories + custom vocabularies). #}
            <a href="{{ url(name='rcms-admin:taxonomies:list') }}" class="rcms-sidebar-link{% if active_tab == "taxonomies" %} active{% endif %}">
                <span class="material-symbols-rounded">category</span> {{ "Taxonomies" | translate(locale=LANG) }}
            </a>
            {% if not sidebar_gating or user_is_superuser or "cms_library.view" in allowed_resources %}
            <a href="{{ url(name='rcms-admin:library:list') }}" class="rcms-sidebar-link{% if active_tab == "library" %} active{% endif %}">
                <span class="material-symbols-rounded">library_books</span> {{ "Library" | translate(locale=LANG) }}
            </a>
            {# FB-03 (#536) — dedicated Forms area: its own list with per-form
               submission counts (forms stay snippet-backed underneath). #}
            <a href="/cms-admin/forms" class="rcms-sidebar-link{% if active_tab == "forms" %} active{% endif %}">
                <span class="material-symbols-rounded">dynamic_form</span> {{ "Forms" | translate(locale=LANG) }}
            </a>
            {% endif %}
            {% if not sidebar_gating or user_is_superuser or "cms_media.view" in allowed_resources %}
            {# #272 — Media group. Wrapping "All media" + "Unused"
               under a collapsible parent keeps the icon rail clean
               while the variant pages remain discoverable. The
               group auto-opens whenever the visitor is on either
               of the two media routes. #}
            {% set media_active = active_tab == "media" or active_tab == "media-unused" %}
            <details class="rcms-sidebar-group{% if media_active %} active{% endif %}"
                     data-sidebar-group="media"
                     {% if media_active %}open{% endif %}>
                <summary class="rcms-sidebar-link rcms-sidebar-group-summary">
                    <span class="material-symbols-rounded">image</span>
                    <span class="rcms-sidebar-group-label">{{ "Media" | translate(locale=LANG) }}</span>
                    <span class="material-symbols-rounded rcms-sidebar-group-chevron">expand_more</span>
                </summary>
                <div class="rcms-sidebar-group-items">
                    <a href="{{ url(name='rcms-admin:media:list') }}" class="rcms-sidebar-link{% if active_tab == "media" %} active{% endif %}">
                        <span class="material-symbols-rounded">photo_library</span> {{ "All media" | translate(locale=LANG) }}
                    </a>
                    <a href="{{ url(name='rcms-admin:media:unused') }}" class="rcms-sidebar-link{% if active_tab == "media-unused" %} active{% endif %}">
                        <span class="material-symbols-rounded">cleaning_services</span> {{ "Unused" | translate(locale=LANG) }}
                    </a>
                </div>
            </details>
            {% endif %}
            {% if not sidebar_gating or user_is_superuser or "cms_document.view" in allowed_resources %}
            <a href="{{ url(name='rcms-admin:documents:list') }}" class="rcms-sidebar-link{% if active_tab == "documents" %} active{% endif %}">
                <span class="material-symbols-rounded">description</span> {{ "Documents" | translate(locale=LANG) }}
            </a>
            {% endif %}

            <div class="rcms-sidebar-section">{{ "Site" | translate(locale=LANG) }}</div>
            {% if not sidebar_gating or user_is_superuser or "cms_redirect.view" in allowed_resources %}
            <a href="{{ url(name='rcms-admin:redirects:list') }}" class="rcms-sidebar-link{% if active_tab == "redirects" %} active{% endif %}">
                <span class="material-symbols-rounded">swap_horiz</span> {{ "Redirects" | translate(locale=LANG) }}
            </a>
            {% endif %}
            {# Gated on the same codename the handler enforces, so the link
               never leads somewhere the click is refused. #}
            {% if not sidebar_gating or user_is_superuser or "cms_notification.manage" in allowed_resources %}
            <a href="/cms-admin/notifications" class="rcms-sidebar-link{% if active_tab == "notifications" %} active{% endif %}">
                <span class="material-symbols-rounded">notifications</span> {{ "Notifications" | translate(locale=LANG) }}
            </a>
            {% endif %}
            {# Gated on the same codename the handler enforces, so the link
               never leads somewhere the click is refused. #}
            {% if not sidebar_gating or user_is_superuser or "cms_site.manage" in allowed_resources %}
            <a href="/cms-admin/sites" class="rcms-sidebar-link{% if active_tab == "sites" %} active{% endif %}">
                <span class="material-symbols-rounded">language</span> {{ "Sites" | translate(locale=LANG) }}
            </a>
            {% endif %}
            {% if not sidebar_gating or user_is_superuser or "cms_navigation_menu.view" in allowed_resources %}
            <a href="{{ url(name='rcms-admin:navigation:list') }}" class="rcms-sidebar-link{% if active_tab == "navigation" %} active{% endif %}">
                <span class="material-symbols-rounded">menu</span> {{ "Navigation" | translate(locale=LANG) }}
            </a>
            {% endif %}
            {# #272 — Reports group. Native <details> handles the
               collapse/expand; the small JS hook in cms-ux.js
               mirrors open/closed state into a per-tenant
               localStorage key so the pick survives reloads. The
               `open` attribute is set server-side whenever any of
               the report tabs is the current page, so visitors
               land on the report without having to expand the
               group. #}
            {% if not sidebar_gating or user_is_superuser or "cms_history.view" in allowed_resources %}
            {% set reports_active = active_tab is starting_with("reports") or active_tab is starting_with("report:") %}
            <details class="rcms-sidebar-group{% if reports_active %} active{% endif %}"
                     data-sidebar-group="reports"
                     {% if reports_active %}open{% endif %}>
                <summary class="rcms-sidebar-link rcms-sidebar-group-summary">
                    <span class="material-symbols-rounded">analytics</span>
                    <span class="rcms-sidebar-group-label">{{ "Reports" | translate(locale=LANG) }}</span>
                    <span class="material-symbols-rounded rcms-sidebar-group-chevron">expand_more</span>
                </summary>
                <div class="rcms-sidebar-group-items">
                    <a href="/cms-admin/analytics" class="rcms-sidebar-link{% if active_tab == "analytics" %} active{% endif %}">
                        <span class="material-symbols-rounded">monitoring</span> {{ "Analytics" | translate(locale=LANG) }}
                    </a>
                    <a href="{{ url(name='rcms-admin:reports:aging') }}" class="rcms-sidebar-link{% if active_tab == "reports" %} active{% endif %}">
                        <span class="material-symbols-rounded">hourglass_top</span> {{ "Aging pages" | translate(locale=LANG) }}
                    </a>
                    <a href="{{ url(name='rcms-admin:reports:locked-pages') }}" class="rcms-sidebar-link{% if active_tab == "reports-locked" %} active{% endif %}">
                        <span class="material-symbols-rounded">lock_clock</span> {{ "Locked pages" | translate(locale=LANG) }}
                    </a>
                    <a href="{{ url(name='rcms-admin:reports:workflows') }}" class="rcms-sidebar-link{% if active_tab == "reports-workflows" %} active{% endif %}">
                        <span class="material-symbols-rounded">timeline</span> {{ "Workflow report" | translate(locale=LANG) }}
                    </a>
                    <a href="{{ url(name='rcms-admin:reports:revisions') }}" class="rcms-sidebar-link{% if active_tab == "reports-revisions" %} active{% endif %}">
                        <span class="material-symbols-rounded">history</span> {{ "Revision storage" | translate(locale=LANG) }}
                    </a>
                    <a href="{{ url(name='rcms-admin:reports:scheduled') }}" class="rcms-sidebar-link{% if active_tab == "reports-scheduled" %} active{% endif %}">
                        <span class="material-symbols-rounded">schedule</span> {{ "Scheduled pages" | translate(locale=LANG) }}
                    </a>
                    <a href="{{ url(name='rcms-admin:reports:search') }}" class="rcms-sidebar-link{% if active_tab == "reports-search" %} active{% endif %}">
                        <span class="material-symbols-rounded">push_pin</span> {{ "Search promotions" | translate(locale=LANG) }}
                    </a>
                    {# #439 — registry-driven reports (register_report!). #}
                    {% for r in registered_reports | default(value=[]) %}
                        <a href="/cms-admin/report/{{ r.slug }}" class="rcms-sidebar-link{% if active_tab == "report:" ~ r.slug %} active{% endif %}">
                            <span class="material-symbols-rounded">{{ r.icon | default(value="summarize") }}</span> {{ r.title | translate(locale=LANG) }}
                        </a>
                    {% endfor %}
                </div>
            </details>
            {% endif %}

            {# #272 — Utilities group. Collects the editorial-flow
               + content-modeling tools (History, Workflows, Locales,
               Page types) that don't live in any one section. Each
               child keeps its own permission gate so the visibility
               policy is unchanged; the group only changes the
               visual grouping. Auto-opens when any child route is
               active. #}
            {% set utilities_active = active_tab == "history" or active_tab == "workflows" or active_tab == "locales" or active_tab == "page-types" or active_tab == "components" %}
            <details class="rcms-sidebar-group{% if utilities_active %} active{% endif %}"
                     data-sidebar-group="utilities"
                     {% if utilities_active %}open{% endif %}>
                <summary class="rcms-sidebar-link rcms-sidebar-group-summary">
                    <span class="material-symbols-rounded">build</span>
                    <span class="rcms-sidebar-group-label">{{ "Utilities" | translate(locale=LANG) }}</span>
                    <span class="material-symbols-rounded rcms-sidebar-group-chevron">expand_more</span>
                </summary>
                <div class="rcms-sidebar-group-items">
                    {% if not sidebar_gating or user_is_superuser or "cms_history.view" in allowed_resources %}
                    <a href="{{ url(name='rcms-admin:history') }}" class="rcms-sidebar-link{% if active_tab == "history" %} active{% endif %}">
                        <span class="material-symbols-rounded">history</span> {{ "History" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                    {% if not sidebar_gating or user_is_superuser or "cms_workflow.view" in allowed_resources %}
                    <a href="{{ url(name='rcms-admin:workflows:list') }}" class="rcms-sidebar-link{% if active_tab == "workflows" %} active{% endif %}">
                        <span class="material-symbols-rounded">approval</span> {{ "Workflows" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                    {% if not sidebar_gating or user_is_superuser or "cms_locale.view" in allowed_resources %}
                    <a href="{{ url(name='rcms-admin:locales:list') }}" class="rcms-sidebar-link{% if active_tab == "locales" %} active{% endif %}">
                        <span class="material-symbols-rounded">language</span> {{ "Locales" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                    {% if not sidebar_gating or user_is_superuser or "cms_page_type.view" in allowed_resources %}
                    <a href="{{ url(name='rcms-admin:page-types') }}" class="rcms-sidebar-link{% if active_tab == "page-types" %} active{% endif %}">
                        <span class="material-symbols-rounded">category</span> {{ "Page types" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                    {# #563 — components library, Developer-gated (same codename as the field builder). #}
                    {% if not sidebar_gating or user_is_superuser or "cms_page_type.build" in allowed_resources %}
                    <a href="{{ url(name='rcms-admin:components:index') }}" class="rcms-sidebar-link{% if active_tab == "components" %} active{% endif %}">
                        <span class="material-symbols-rounded">extension</span> {{ "Components" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                </div>
            </details>

            <div class="rcms-sidebar-section">{{ "Settings" | translate(locale=LANG) }}</div>
            {# #272 — Management group. Operator-level admin
               (Users, Roles, framework Settings) collapsed under
               one parent so the day-to-day editor isn't staring at
               admin-only entries. Site settings stays at the top
               level since it's editor-facing content config (logo,
               favicon, brand). #}
            {% set management_active = active_tab == "users" or active_tab == "roles" or active_tab == "permissions" or active_tab == "settings" or active_tab == "security-log" %}
            <details class="rcms-sidebar-group{% if management_active %} active{% endif %}"
                     data-sidebar-group="management"
                     {% if management_active %}open{% endif %}>
                <summary class="rcms-sidebar-link rcms-sidebar-group-summary">
                    <span class="material-symbols-rounded">admin_panel_settings</span>
                    <span class="rcms-sidebar-group-label">{{ "Management" | translate(locale=LANG) }}</span>
                    <span class="material-symbols-rounded rcms-sidebar-group-chevron">expand_more</span>
                </summary>
                <div class="rcms-sidebar-group-items">
                    {% if not sidebar_gating or user_is_superuser or "rustango_users.view" in allowed_resources %}
                    <a href="{{ url(name='rcms-admin:users') }}" class="rcms-sidebar-link{% if active_tab == "users" %} active{% endif %}">
                        <span class="material-symbols-rounded">person</span> {{ "Users" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                    {% if not sidebar_gating or user_is_superuser or "rustango_roles.view" in allowed_resources %}
                    <a href="{{ url(name='rcms-admin:roles') }}" class="rcms-sidebar-link{% if active_tab == "roles" %} active{% endif %}">
                        <span class="material-symbols-rounded">key</span> {{ "Roles" | translate(locale=LANG) }}
                    </a>
                    {# #436 — read-only permission overview matrix. #}
                    <a href="/cms-admin/permissions" class="rcms-sidebar-link{% if active_tab == "permissions" %} active{% endif %}">
                        <span class="material-symbols-rounded">grid_on</span> {{ "Permissions" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                    {% if not sidebar_gating or user_is_superuser %}
                    <a href="{{ url(name='rcms-admin:security-log') }}" class="rcms-sidebar-link{% if active_tab == "security-log" %} active{% endif %}">
                        <span class="material-symbols-rounded">shield_person</span> {{ "Security log" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                    {% if not sidebar_gating or user_is_superuser or "cms_settings.view" in allowed_resources %}
                    <a href="{{ url(name='rcms-admin:settings') }}" class="rcms-sidebar-link{% if active_tab == "settings" %} active{% endif %}">
                        <span class="material-symbols-rounded">tune</span> {{ "Settings" | translate(locale=LANG) }}
                    </a>
                    <a href="{{ url(name='rcms-admin:sso-providers:list') }}" class="rcms-sidebar-link{% if active_tab == "sso-providers" %} active{% endif %}">
                        <span class="material-symbols-rounded">login</span> {{ "SSO Providers" | translate(locale=LANG) }}
                    </a>
                    {% endif %}
                </div>
            </details>
            {% if not sidebar_gating or user_is_superuser or "cms_settings.view" in allowed_resources %}
            {# Gated on `cms_template.edit` — templates are code-adjacent,
               see `admin::template_editor`. Same shape as the page-type
               builder's entry above. #}
            {% if not sidebar_gating or user_is_superuser or "cms_template.edit" in allowed_resources %}
            <a href="{{ url(name='rcms-admin:templates:list') }}" class="rcms-sidebar-link{% if active_tab == "templates" %} active{% endif %}">
                <span class="material-symbols-rounded">code_blocks</span> {{ "Templates" | translate(locale=LANG) }}
            </a>
            {% endif %}
            {% if not sidebar_gating or user_is_superuser %}
            <a href="{{ url(name='rcms-admin:site-theme') }}" class="rcms-sidebar-link{% if active_tab == "site-theme" %} active{% endif %}">
                <span class="material-symbols-rounded">palette</span> {{ "Site theme" | translate(locale=LANG) }}
            </a>
            {% endif %}
            <a href="{{ url(name='rcms-admin:site-settings:list') }}" class="rcms-sidebar-link{% if active_tab == "site-settings" %} active{% endif %}">
                <span class="material-symbols-rounded">settings_applications</span> {{ "Site settings" | translate(locale=LANG) }}
            </a>
            {% endif %}

            {# Custom admin pages (#23) — third-party crates register
               AdminPageHandlers via `register_admin_page!`; they
               surface here grouped by their declared section. Each
               page lives at /cms-admin/x/<slug>. #}
            {% if extra_admin_pages_by_section %}
                {% for section, items in extra_admin_pages_by_section %}
                    {% if items | length > 0 %}
                        <div class="rcms-sidebar-section">{{ section | translate(locale=LANG) }}</div>
                        {% for ap in items %}
                            <a href="{{ url(name='rcms-admin:custom-page', slug=ap.slug) }}" class="rcms-sidebar-link{% if active_tab == "custom:" ~ ap.slug %} active{% endif %}">
                                <span class="material-symbols-rounded">{{ ap.icon | default(value="extension") }}</span> {{ ap.label | translate(locale=LANG) }}
                            </a>
                        {% endfor %}
                    {% endif %}
                {% endfor %}
            {% endif %}

            {# #127 — Help section. Built-in entries (Docs + Keyboard
               shortcuts) ship from rustango-cms itself; plugins add
               more via `register_help_menu_item!`. The keyboard-shortcuts
               entry uses a sentinel href that JS intercepts to open
               the cheat-sheet modal in-page.
               #272 — Help wrapped in a collapsible `<details>` group
               so editors can hide rarely-accessed entries (docs,
               styleguide, shortcuts). Persistence + collapsed-rail
               handling are inherited from `.rcms-sidebar-group`. #}
            {% if help_menu_items and help_menu_items | length > 0 %}
                <details class="rcms-sidebar-group" data-sidebar-group="help">
                    <summary class="rcms-sidebar-link rcms-sidebar-group-summary">
                        <span class="material-symbols-rounded">help</span>
                        <span class="rcms-sidebar-group-label">{{ "Help" | translate(locale=LANG) }}</span>
                        <span class="material-symbols-rounded rcms-sidebar-group-chevron">expand_more</span>
                    </summary>
                    <div class="rcms-sidebar-group-items">
                        {% for mi in help_menu_items %}
                            {% if mi.href == "#kbd-cheatsheet" %}
                                <a href="#" class="rcms-sidebar-link" data-kbd-modal-open>
                                    <span class="material-symbols-rounded">{{ mi.icon | default(value="help") }}</span> {{ mi.label | translate(locale=LANG) }}
                                </a>
                            {% else %}
                                <a href="{{ mi.href }}" class="rcms-sidebar-link"
                                   {% if mi.href is starting_with("http") %}target="_blank" rel="noopener"{% endif %}>
                                    <span class="material-symbols-rounded">{{ mi.icon | default(value="help") }}</span> {{ mi.label | translate(locale=LANG) }}
                                </a>
                            {% endif %}
                        {% endfor %}
                    </div>
                </details>
            {% endif %}

            {# #107 — runtime-hook sidebar entries (`register_admin_menu_item!`).
               Backs the `register_admin_menu_item` hook. Lighter
               than `AdminPageHandler` — just a label + icon + href. #}
            {% if plugin_admin_menu_items and plugin_admin_menu_items | length > 0 %}
                <div class="rcms-sidebar-section">{{ "Plugins" | translate(locale=LANG) }}</div>
                {% for mi in plugin_admin_menu_items %}
                    <a href="{{ mi.href }}" class="rcms-sidebar-link{% if active_tab == "plugin:" ~ mi.key %} active{% endif %}">
                        <span class="material-symbols-rounded">{{ mi.icon | default(value="extension") }}</span> {{ mi.label | translate(locale=LANG) }}
                    </a>
                {% endfor %}
            {% endif %}
        </nav>
        <div class="rcms-sidebar-footer">
            {# #27 — appearance, text size, and high-contrast toggles
               moved out of here into `/cms-admin/me`. The no-flash
               script at the top of <head> still reads the same
               localStorage keys so existing preferences keep applying. #}
            {# #201 — profile pill: avatar (or initial) + display name. #}
            {% if user_username %}
                <a href="{{ url(name='rcms-admin:account') }}"
                   class="rcms-sidebar-profile rcms-flex rcms-items-center rcms-gap-2 rcms-py-2 rcms-px-0 rcms-no-underline rcms-text-inherit"
                   title="{{ "Edit profile" | translate(locale=LANG) }}">
                    {% if user_avatar_url %}
                        <img src="{{ user_avatar_url }}" alt=""
                             class="rcms-rounded-circle rcms-avatar rcms-avatar--sm">
                    {% else %}
                        <span class="rcms-rounded-circle rcms-inline-flex rcms-items-center rcms-text-xs rcms-fw-semibold rcms-avatar rcms-avatar--sm rcms-avatar-fallback rcms-justify-center">
                            {{ user_display_name | default(value=user_username) | truncate(length=1, end="") | upper }}
                        </span>
                    {% endif %}
                    <span class="rcms-text-xs">{{ user_display_name | default(value=user_username) }}</span>
                </a>
            {% endif %}
            {#- Back to the public site, at its home page. -#}
            <a href="/" class="rcms-sidebar-logout" title="{{ site_name | default(value='') }}">
                <span class="material-symbols-rounded">home</span> {{ "View site" | translate(locale=LANG) }}
            </a>
            <a href="{{ url(name='rcms-admin:account') }}" class="rcms-sidebar-logout" title="{{ "Appearance, text size, accessibility" | translate(locale=LANG) }}">
                <span class="material-symbols-rounded">tune</span> {{ "Preferences" | translate(locale=LANG) }}
            </a>
            {# #525 — the language switcher lives on Preferences, not here.
               Its open menu is a stack of full-width labels, which the
               collapsed rail has no room for — the options rendered one
               glyph per line. Preferences also saves the choice to the
               account via POST, where this was a state-changing GET. #}
            <form method="post" action="{{ url(name='rcms-admin:logout') }}" class="rcms-m-0">
                {{ csrf_token | csrf_input | safe }}
                <button type="submit" class="rcms-sidebar-logout" title="{{ "Sign out of the CMS admin" | translate(locale=LANG) }}">
                    <span class="material-symbols-rounded">logout</span> {{ "Sign out" | translate(locale=LANG) }}
                </button>
            </form>
            <span class="rcms-hint rcms-text-2xs" data-user-tz title="The CMS stores dates in UTC; the chrome localizes them to this timezone in the browser.">
                <span class="material-symbols-rounded sm">schedule</span> {{ "Detecting timezone…" | translate(locale=LANG) }}
            </span>
        </div>
    </aside>

    <main class="rcms-app-main">
        <header class="rcms-app-topbar">
            <div class="rcms-app-topbar-left">
                <label for="__nav_toggle" class="rcms-nav-toggle-label" aria-label="{{ "Toggle navigation" | translate(locale=LANG) }}"><span class="material-symbols-rounded">menu</span></label>
                {# Heading slot — list/index pages use the default page
                   title; the page-editor overrides it with inline
                   breadcrumbs + status chips so the bar stays dense. #}
                <h1 class="rcms-app-topbar-heading">{% block heading %}{% if heading %}{{ heading }}{% else %}{{ "Dashboard" | translate(locale=LANG) }}{% endif %}{% endblock %}</h1>
            </div>
            <div class="rcms-app-topbar-actions">
                {% block topbar_actions %}{% endblock %}
            </div>
        </header>

        {# Optional secondary bar — page-editor mounts the tab strip +
           preview controls here; list pages leave it empty so the row
           collapses. Sticky below the topbar via CSS. #}
        {% block action_bar %}{% endblock %}

        {# Standalone breadcrumbs row — only rendered when a child
           template opts in via `{% block breadcrumbs %}`. The page
           editor folds breadcrumbs into the topbar instead. #}
        {% block breadcrumbs %}{% endblock %}

        {# rustango::messages flash region — one-shot success / info /
           warning / error banners staged by POST handlers via
           `redirect_with_message`. Drained + cleared on every render
           through render_with_csrf in handlers.rs. #}
        {% if messages and messages | length > 0 %}
        <div class="rcms-app-flash" role="status" aria-live="polite">
            {% for msg in messages %}
                <div class="rcms-flash rcms-flash--{{ msg.level }}{% if msg.tags %} {{ msg.tags }}{% endif %}">
                    <span class="material-symbols-rounded rcms-flash-icon">
                        {% if msg.level == "success" %}check_circle
                        {% elif msg.level == "warning" %}warning
                        {% elif msg.level == "error" %}error
                        {% else %}info
                        {% endif %}
                    </span>
                    <span class="rcms-flash-body">{{ msg.body }}</span>
                </div>
            {% endfor %}
        </div>
        {% endif %}

        <div class="rcms-app-content">
            {% block content %}{% endblock %}
        </div>
    </main>
    <script src="/cms-admin/static/cms-ux.js?v={{ cms_asset_version() }}" defer></script>
    <script src="/cms-admin/static/stream_editor.js?v={{ cms_asset_version() }}" defer></script>
    <script src="/cms-admin/static/block_tree.js?v={{ cms_asset_version() }}" defer></script>
    {# #294 — TipTap richtext editor glue (small). It lazy-loads the ~312 KB
       engine bundle on demand, only when a RichText field is present on the
       page — so admin pages without one never fetch/parse it. #}
    <script src="/cms-admin/static/richtext-editor.js?v={{ cms_asset_version() }}" defer></script>
    <script>
      // Light / Dark / System toggle wiring. Reads + writes
      // localStorage['rcms-admin-mode'] (the same key the no-flash
      // script at the top of <head> consults on first paint).
      (function () {
        const STORAGE_KEY = "rcms-admin-mode";
        const buttons = document.querySelectorAll(".rcms-mode-toggle-btn[data-mode]");
        if (buttons.length === 0) return;

        const stored = (() => {
          try { return localStorage.getItem(STORAGE_KEY); } catch (e) { return null; }
        })();
        const current = stored === "light" || stored === "dark" ? stored : "system";

        const sync = (mode) => {
          buttons.forEach((b) => {
            const active = b.dataset.mode === mode;
            b.setAttribute("aria-checked", active ? "true" : "false");
            b.classList.toggle("active", active);
          });
        };
        sync(current);

        buttons.forEach((btn) => {
          btn.addEventListener("click", () => {
            const mode = btn.dataset.mode;
            try {
              if (mode === "system") localStorage.removeItem(STORAGE_KEY);
              else localStorage.setItem(STORAGE_KEY, mode);
            } catch (e) { /* ignore quota / private mode */ }
            if (mode === "light" || mode === "dark") {
              document.documentElement.setAttribute("data-theme", mode);
            } else {
              document.documentElement.removeAttribute("data-theme");
            }
            sync(mode);
          });
        });

        // Text-scale toggle (#14).
        const SCALE_KEY = "rcms-admin-text-scale";
        const scaleButtons = document.querySelectorAll(".rcms-text-scale-btn[data-text-scale]");
        if (scaleButtons.length > 0) {
          const storedScale = (() => {
            try { return localStorage.getItem(SCALE_KEY); } catch (e) { return null; }
          })();
          const currentScale = ["s", "m", "l", "xl"].includes(storedScale) ? storedScale : "m";
          const syncScale = (scale) => {
            scaleButtons.forEach((b) => {
              const active = b.dataset.textScale === scale;
              b.setAttribute("aria-checked", active ? "true" : "false");
              b.classList.toggle("active", active);
            });
          };
          syncScale(currentScale);
          scaleButtons.forEach((b) => {
            b.addEventListener("click", () => {
              const scale = b.dataset.textScale;
              try {
                if (scale === "m") localStorage.removeItem(SCALE_KEY);
                else localStorage.setItem(SCALE_KEY, scale);
              } catch (e) { /* ignore */ }
              if (scale === "m") document.documentElement.removeAttribute("data-text-scale");
              else document.documentElement.setAttribute("data-text-scale", scale);
              syncScale(scale);
            });
          });
        }

        // High-contrast toggle (#14).
        const CONTRAST_KEY = "rcms-admin-high-contrast";
        const contrastBtn = document.querySelector("[data-high-contrast-toggle]");
        if (contrastBtn) {
          const isOn = () => document.documentElement.hasAttribute("data-high-contrast");
          const syncContrast = () => {
            const on = isOn();
            contrastBtn.classList.toggle("active", on);
            contrastBtn.setAttribute("aria-pressed", on ? "true" : "false");
            const label = contrastBtn.querySelector("[data-high-contrast-label]");
            if (label) label.textContent = on ? "High contrast on" : "High contrast";
          };
          syncContrast();
          contrastBtn.addEventListener("click", () => {
            const next = !isOn();
            try {
              if (next) localStorage.setItem(CONTRAST_KEY, "1");
              else localStorage.removeItem(CONTRAST_KEY);
            } catch (e) { /* ignore */ }
            if (next) document.documentElement.setAttribute("data-high-contrast", "");
            else document.documentElement.removeAttribute("data-high-contrast");
            syncContrast();
          });
        }
      })();
    </script>
    <script>
      // Localize <time data-utc="..."> elements into the browser's
      // timezone (#13). The CMS stores all datetimes as UTC; tooltips
      // and absolute-time displays should read in the editor's local
      // time without a server-side timezone column. The element's
      // optional `data-format` picks a chunk of toLocaleString options:
      //   "datetime" (default) → "May 20, 2026, 2:14 PM"
      //   "date"               → "May 20, 2026"
      //   "time"               → "2:14 PM"
      // The element's text is replaced; the original UTC ISO is
      // preserved in `rcms-title` so editors can hover for the canonical
      // value.
      (function () {
        // Resolve the effective TZ in fallback order:
        //   1. Explicit per-user pref (#13 V1) on `data-user-tz-pref`.
        //   2. Tenant default (#13 V2) on `data-tenant-default-tz`,
        //      sourced from the `RUSTANGO_CMS_DEFAULT_TIMEZONE` env
        //      var so multi-tenant deployments can pin a sensible
        //      regional default without a DB schema change.
        //   3. Browser default via Intl.DateTimeFormat.
        const prefAttr = document.documentElement.getAttribute("data-user-tz-pref");
        const tenantAttr = document.documentElement.getAttribute("data-tenant-default-tz");
        let effectiveTz = "";
        try {
          effectiveTz = prefAttr || tenantAttr || Intl.DateTimeFormat().resolvedOptions().timeZone;
        } catch (e) { /* not supported — leave empty */ }

        // Fill the sidebar "Your timezone" indicator. Marks the
        // value as a pref when the explicit override is in play
        // so editors know where it came from.
        try {
          document
            .querySelectorAll("[data-user-tz]")
            .forEach((el) => {
              el.textContent = "";
              const icon = document.createElement("span");
              icon.className = "material-symbols-rounded sm";
              icon.textContent = "schedule";
              el.appendChild(icon);
              el.appendChild(
                document.createTextNode(" " + (effectiveTz || "—") + (prefAttr ? " (pref)" : ""))
              );
            });
        } catch (e) { /* ignore */ }

        // Datetime inputs: the server stores UTC, editors type their own
        // wall time. An input marked `data-utc` shows the stored moment in
        // the effective zone, and its form sends UTC back (`…Z`) — through
        // the `formdata` event, so autosave and preview posts convert too.
        // Without JS the input keeps the server's UTC value both ways.
        const pad = (n) => String(n).padStart(2, "0");
        // Offset (ms) of `tz` at instant `ms`: its wall time read as UTC, minus the instant.
        const zoneOffset = (ms, tz) => {
          const p = {};
          new Intl.DateTimeFormat("en-US", {
            timeZone: tz, hourCycle: "h23", year: "numeric", month: "2-digit",
            day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit",
          }).formatToParts(new Date(ms)).forEach((x) => { p[x.type] = x.value; });
          return Date.UTC(+p.year, +p.month - 1, +p.day, +p.hour, +p.minute, +p.second) - ms;
        };
        const utcToWall = (iso) => {
          const d = new Date(iso);
          if (Number.isNaN(d.getTime())) return "";
          const w = new Date(d.getTime() + (effectiveTz ? zoneOffset(d.getTime(), effectiveTz) : -d.getTimezoneOffset() * 60000));
          return `${w.getUTCFullYear()}-${pad(w.getUTCMonth() + 1)}-${pad(w.getUTCDate())}T${pad(w.getUTCHours())}:${pad(w.getUTCMinutes())}`;
        };
        const wallToUtc = (wall) => {
          const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(wall || "");
          if (!m) return wall;
          const asUtc = Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5]);
          let ms;
          if (effectiveTz) {
            // Two passes settle the offset across a DST change.
            ms = asUtc - zoneOffset(asUtc, effectiveTz);
            ms = asUtc - zoneOffset(ms, effectiveTz);
          } else {
            ms = new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5]).getTime();
          }
          return new Date(ms).toISOString().slice(0, 16) + "Z";
        };
        window.rcmsTimeZone = effectiveTz;
        const zoned = document.querySelectorAll('input[type="datetime-local"][data-utc]');
        zoned.forEach((input) => {
          const iso = input.getAttribute("data-utc");
          if (iso) input.value = utcToWall(iso);
        });
        const zonedForms = new Set([...zoned].map((i) => i.form).filter(Boolean));
        zonedForms.forEach((form) => {
          form.addEventListener("formdata", (e) => {
            form.querySelectorAll('input[type="datetime-local"][data-utc]').forEach((input) => {
              if (input.name && e.formData.has(input.name) && input.value) {
                e.formData.set(input.name, wallToUtc(input.value));
              }
            });
          });
        });

        const elements = document.querySelectorAll("time[data-utc]");
        if (elements.length === 0) return;
        const tzOpt = effectiveTz ? { timeZone: effectiveTz } : {};
        // #531 — format dates/times in the active admin locale (the <html lang>
        // set by the server's locale negotiation), not just the browser default,
        // so "May 20" / "20 mai" / "5月20日" follow the chosen UI language.
        const uiLocale = document.documentElement.getAttribute("lang") || undefined;
        const fmt = (d, mode) => {
          if (mode === "date")
            return d.toLocaleDateString(uiLocale, { dateStyle: "medium", ...tzOpt });
          if (mode === "time")
            return d.toLocaleTimeString(uiLocale, { timeStyle: "short", ...tzOpt });
          return d.toLocaleString(uiLocale, {
            dateStyle: "medium",
            timeStyle: "short",
            ...tzOpt,
          });
        };
        elements.forEach((el) => {
          const iso = el.getAttribute("data-utc");
          if (!iso) return;
          const d = new Date(iso);
          if (Number.isNaN(d.getTime())) return;
          const mode = el.dataset.format || "datetime";
          // Only rewrite if the placeholder content matches what the
          // server emitted — preserves any author-set override.
          if (!el.dataset.localized) {
            el.textContent = fmt(d, mode);
            el.title = iso + " (UTC)";
            el.dataset.localized = "1";
          }
        });
      })();
    </script>
    {% block scripts %}{% endblock %}
    {# #422 — plugin-injected global admin JS (insert_global_admin_js). #}
    {% for js in admin_js_blobs | default(value=[]) %}
        <script>{{ js | safe }}</script>
    {% endfor %}
</body>
</html>