Skip to main content

logicaffeine_web/ui/
responsive.rs

1//! Responsive design system and mobile styling utilities.
2//!
3//! Centralizes the mobile/responsive CSS shared across pages so behavior stays
4//! consistent across device sizes: the base utilities and the mobile tab bar.
5//!
6//! # Breakpoint Strategy
7//!
8//! Mobile-first approach with these breakpoints:
9//! - 768px: Tablets (primary mobile breakpoint, `--breakpoint-mobile`)
10//! - 1024px: Small laptops (`--breakpoint-tablet`)
11//!
12//! # Touch Target Standards
13//!
14//! Follows WCAG 2.5 guidelines:
15//! - Minimum: 44x44px
16//! - Comfortable: 48x48px
17//! - Large (primary actions): 56x56px
18//!
19//! # Usage
20//!
21//! Include the styles in the page component:
22//!
23//! ```no_run
24//! # use dioxus::prelude::*;
25//! use logicaffeine_web::ui::responsive::{MOBILE_BASE_STYLES, MOBILE_TAB_BAR_STYLES};
26//!
27//! # fn Example() -> Element {
28//! rsx! {
29//!     style { "{MOBILE_BASE_STYLES}" }
30//!     style { "{MOBILE_TAB_BAR_STYLES}" }
31//! }
32//! # }
33//! ```
34//!
35//! # CSS Classes
36//!
37//! | Class | Description |
38//! |-------|-------------|
39//! | `.desktop-only` | Hidden on mobile (≤768px) |
40//! | `.mobile-only` | Hidden on desktop (>768px) |
41//! | `.touch-target` | Minimum 44x44px touch area |
42//! | `.safe-top` | Respects notch/status bar |
43//! | `.safe-bottom` | Respects home indicator |
44//! | `.scroll-smooth` | iOS momentum scrolling |
45
46// =============================================================================
47// BREAKPOINTS, MEDIA QUERIES AND TOUCH
48// =============================================================================
49
50/// The widths and heights the layout changes at, in CSS pixels.
51pub mod breakpoints {
52    /// The widest phone held upright: iPhones are 390 to 430, Android phones 360 to 412.
53    pub const PHONE_MAX: u32 = 600;
54    /// The widest window that stacks the Studio's panels: an upright iPad mini (744) and iPad (768).
55    pub const MOBILE_MAX: u32 = 768;
56    /// The widest window the site's nav folds into its menu, and the widest upright tablet.
57    pub const TABLET_MAX: u32 = 1024;
58    /// The tallest window that is a phone turned on its side.
59    pub const SHORT_MAX: u32 = 500;
60    /// The narrowest phones, where the buttons tighten further.
61    pub const SMALL_PHONE_MAX: u32 = 480;
62    /// The width from which a frame on another page leaves its wider margins.
63    pub const FRAME_WIDE_MIN: u32 = 720;
64}
65
66/// The media queries the Studio's stylesheets and these shared ones use, by name. A stylesheet cannot
67/// read a custom property inside `@media`, so each query is written out in the CSS, and the one-Studio
68/// lock holds every `@media` the Studio draws from to one of [`media::ALL`]. The app's own `matchMedia`
69/// checks use the same strings.
70pub mod media {
71    /// A phone held upright.
72    pub const PHONE: &str = "(max-width: 600px)";
73    /// A phone or an upright tablet: the Studio's panels stack.
74    pub const MOBILE: &str = "(max-width: 768px)";
75    /// Wider than an upright tablet: the desktop's columns.
76    pub const DESKTOP: &str = "(min-width: 769px)";
77    /// An upright tablet the width of a small phone's landscape: iPad mini and iPad portrait.
78    pub const TABLET_PORTRAIT: &str = "(min-width: 601px) and (max-width: 768px)";
79    /// An upright tablet wider than 768px, an iPad Air or iPad Pro held upright, known by its finger.
80    pub const UPRIGHT_TABLET: &str = "(min-width: 769px) and (max-width: 1024px) and (orientation: portrait) and (pointer: coarse)";
81    /// A tablet turned on its side.
82    pub const TABLET_LANDSCAPE: &str = "(min-width: 769px) and (min-height: 501px) and (pointer: coarse)";
83    /// A phone turned on its side.
84    pub const PHONE_LANDSCAPE: &str = "(max-height: 500px) and (orientation: landscape)";
85    /// A finger, on any screen.
86    pub const COARSE: &str = "(pointer: coarse)";
87    /// A screen nothing hovers over.
88    pub const NO_HOVER: &str = "(hover: none)";
89    /// The narrowest phones.
90    pub const SMALL_PHONE: &str = "(max-width: 480px)";
91    /// Up to an upright tablet's width: the site's nav folds into its menu.
92    pub const TABLET: &str = "(max-width: 1024px)";
93    /// A small laptop or a tablet on its side: the menu's roomier layout.
94    pub const SMALL_LAPTOP: &str = "(min-width: 769px) and (max-width: 1024px)";
95    /// A frame on another page with room for its wider margins.
96    pub const FRAME_WIDE: &str = "(min-width: 720px)";
97    /// A reader who asked for less motion.
98    pub const REDUCED_MOTION: &str = "(prefers-reduced-motion: reduce)";
99
100    /// Where the Files tree is a drawer over the workbench, folded until the reader opens it: phones,
101    /// upright tablets, and a phone on its side.
102    pub const FILES_DRAWER: &[&str] = &[MOBILE, UPRIGHT_TABLET, PHONE_LANDSCAPE];
103    /// Where the panes show one at a time, or side by side in halves, so a pane's header folds nothing.
104    pub const PANES_FIXED: &[&str] = &[PHONE, PHONE_LANDSCAPE];
105
106    pub const ALL: &[&str] = &[
107        PHONE,
108        MOBILE,
109        DESKTOP,
110        TABLET_PORTRAIT,
111        UPRIGHT_TABLET,
112        TABLET_LANDSCAPE,
113        PHONE_LANDSCAPE,
114        COARSE,
115        NO_HOVER,
116        SMALL_PHONE,
117        TABLET,
118        SMALL_LAPTOP,
119        FRAME_WIDE,
120        REDUCED_MOTION,
121    ];
122}
123
124/// Touch targets, in CSS pixels (WCAG 2.5.5).
125pub mod touch {
126    /// The least a finger can press.
127    pub const MIN: u32 = 44;
128    /// A comfortable press.
129    pub const COMFORTABLE: u32 = 48;
130}
131
132// =============================================================================
133// BASE MOBILE STYLES
134// =============================================================================
135
136/// Include this in your root component (app.rs) for global mobile utilities
137pub const MOBILE_BASE_STYLES: &str = r#"
138/* ============================================ */
139/* MOBILE CSS VARIABLES                         */
140/* ============================================ */
141:root {
142    /* Touch targets */
143    --touch-min: 44px;
144    --touch-comfortable: 48px;
145    --touch-large: 56px;
146
147    /* Mobile spacing */
148    --mobile-padding: 12px;
149    --mobile-gap: 8px;
150
151    /* Safe area insets for notched devices */
152    --safe-top: env(safe-area-inset-top, 0px);
153    --safe-bottom: env(safe-area-inset-bottom, 0px);
154    --safe-left: env(safe-area-inset-left, 0px);
155    --safe-right: env(safe-area-inset-right, 0px);
156
157    /* Layout heights - standardized across app */
158    --header-height: 72px;
159    --footer-height-desktop: 280px;
160    --footer-height-tablet: 360px;
161    --footer-height-mobile: auto;
162
163    /* Standardized breakpoints (as CSS custom properties for reference) */
164    --breakpoint-mobile: 768px;
165    --breakpoint-tablet: 1024px;
166}
167
168/* ============================================ */
169/* MOBILE UTILITY CLASSES                       */
170/* ============================================ */
171
172/* Hide on mobile, show on desktop */
173.desktop-only {
174    display: block;
175}
176
177/* Show on mobile, hide on desktop */
178.mobile-only {
179    display: none;
180}
181
182@media (max-width: 768px) {
183    .desktop-only {
184        display: none !important;
185    }
186    .mobile-only {
187        display: block !important;
188    }
189    .mobile-only-flex {
190        display: flex !important;
191    }
192}
193
194/* Touch-friendly button base */
195.touch-target {
196    min-width: var(--touch-min);
197    min-height: var(--touch-min);
198    display: flex;
199    align-items: center;
200    justify-content: center;
201    cursor: pointer;
202    -webkit-tap-highlight-color: transparent;
203    touch-action: manipulation;
204}
205
206/* Safe area padding utilities */
207.safe-top {
208    padding-top: max(var(--mobile-padding), var(--safe-top));
209}
210
211.safe-bottom {
212    padding-bottom: max(var(--mobile-padding), var(--safe-bottom));
213}
214
215.safe-horizontal {
216    padding-left: max(var(--mobile-padding), var(--safe-left));
217    padding-right: max(var(--mobile-padding), var(--safe-right));
218}
219
220/* Smooth scrolling with momentum on iOS */
221.scroll-smooth {
222    -webkit-overflow-scrolling: touch;
223    scroll-behavior: smooth;
224}
225
226/* Prevent text selection on interactive elements */
227.no-select {
228    -webkit-user-select: none;
229    user-select: none;
230}
231
232/* Reduced motion support */
233@media (prefers-reduced-motion: reduce) {
234    *,
235    *::before,
236    *::after {
237        animation-duration: 0.01ms !important;
238        animation-iteration-count: 1 !important;
239        transition-duration: 0.01ms !important;
240    }
241}
242
243/* ============================================ */
244/* BODY SCROLL LOCK                            */
245/* ============================================ */
246
247/* Applied to body when mobile menu is open */
248body.menu-open {
249    overflow: hidden;
250    position: fixed;
251    width: 100%;
252    height: 100%;
253}
254
255/* ============================================ */
256/* HAMBURGER MENU & OVERLAY                    */
257/* ============================================ */
258
259/* Hamburger button */
260.hamburger-btn {
261    display: none;
262    width: var(--touch-comfortable);
263    height: var(--touch-comfortable);
264    padding: 0;
265    border: none;
266    background: transparent;
267    cursor: pointer;
268    -webkit-tap-highlight-color: transparent;
269    position: relative;
270    z-index: 1001;
271}
272
273.hamburger-icon {
274    width: 24px;
275    height: 18px;
276    position: relative;
277    display: flex;
278    flex-direction: column;
279    justify-content: space-between;
280}
281
282.hamburger-line {
283    width: 100%;
284    height: 2px;
285    background: var(--text-primary, #f0f0f0);
286    border-radius: 1px;
287    transition: all 0.3s ease;
288    transform-origin: center;
289}
290
291/* Hamburger to X animation */
292.hamburger-btn.open .hamburger-line:nth-child(1) {
293    transform: translateY(8px) rotate(45deg);
294}
295
296.hamburger-btn.open .hamburger-line:nth-child(2) {
297    opacity: 0;
298    transform: scaleX(0);
299}
300
301.hamburger-btn.open .hamburger-line:nth-child(3) {
302    transform: translateY(-8px) rotate(-45deg);
303}
304
305/* Mobile menu overlay */
306.mobile-menu-overlay {
307    position: fixed;
308    top: 0;
309    left: 0;
310    right: 0;
311    bottom: 0;
312    background: rgba(6, 8, 20, 0.98);
313    backdrop-filter: blur(20px);
314    -webkit-backdrop-filter: blur(20px);
315    z-index: 1000;
316    opacity: 0;
317    visibility: hidden;
318    transition: opacity 0.3s ease, visibility 0.3s ease;
319    display: flex;
320    flex-direction: column;
321    padding: calc(var(--header-height) + 20px) var(--mobile-padding) var(--mobile-padding);
322    overflow-y: auto;
323}
324
325.mobile-menu-overlay.open {
326    opacity: 1;
327    visibility: visible;
328}
329
330/* Mobile menu navigation links */
331.mobile-menu-nav {
332    display: flex;
333    flex-direction: column;
334    gap: 8px;
335    margin-bottom: 32px;
336}
337
338.mobile-menu-link {
339    display: flex;
340    align-items: center;
341    gap: 12px;
342    padding: 16px 20px;
343    border-radius: 12px;
344    background: rgba(255, 255, 255, 0.03);
345    color: var(--text-secondary, #b0b0b0);
346    text-decoration: none;
347    font-size: 18px;
348    font-weight: 500;
349    transition: all 0.2s ease;
350    border: 1px solid transparent;
351}
352
353.mobile-menu-link:active {
354    transform: scale(0.98);
355    background: rgba(255, 255, 255, 0.08);
356}
357
358.mobile-menu-link.active {
359    background: rgba(102, 126, 234, 0.15);
360    color: var(--text-primary, #f0f0f0);
361    border-color: rgba(102, 126, 234, 0.3);
362}
363
364.mobile-menu-link-icon {
365    font-size: 20px;
366    width: 24px;
367    text-align: center;
368}
369
370/* Mobile menu CTAs */
371.mobile-menu-ctas {
372    display: flex;
373    flex-direction: column;
374    gap: 12px;
375    margin-top: auto;
376    padding-top: 24px;
377    border-top: 1px solid rgba(255, 255, 255, 0.08);
378}
379
380.mobile-menu-cta {
381    display: flex;
382    align-items: center;
383    justify-content: center;
384    padding: 16px 24px;
385    border-radius: 12px;
386    font-size: 16px;
387    font-weight: 600;
388    text-decoration: none;
389    transition: all 0.2s ease;
390}
391
392.mobile-menu-cta.primary {
393    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
394    color: white;
395}
396
397.mobile-menu-cta.secondary {
398    background: rgba(255, 255, 255, 0.05);
399    border: 1px solid rgba(255, 255, 255, 0.1);
400    color: var(--text-primary, #f0f0f0);
401}
402
403/* Show hamburger on mobile/tablet */
404@media (max-width: 1024px) {
405    .hamburger-btn {
406        display: flex;
407        align-items: center;
408        justify-content: center;
409    }
410
411    .nav-links-desktop {
412        display: none !important;
413    }
414
415    .nav-ctas-desktop {
416        display: none !important;
417    }
418}
419
420/* ============================================ */
421/* TABLET-SPECIFIC ADJUSTMENTS                 */
422/* ============================================ */
423
424@media (min-width: 769px) and (max-width: 1024px) {
425    .mobile-menu-overlay {
426        padding: calc(var(--header-height) + 40px) 40px 40px;
427    }
428
429    .mobile-menu-link {
430        padding: 18px 24px;
431        font-size: 20px;
432    }
433
434    .mobile-menu-nav {
435        max-width: 400px;
436        margin: 0 auto 40px;
437    }
438
439    .mobile-menu-ctas {
440        max-width: 400px;
441        margin: auto auto 0;
442    }
443}
444"#;
445
446// =============================================================================
447// MOBILE TAB BAR COMPONENT STYLES
448// =============================================================================
449
450/// Reusable mobile tab bar styles - use for any tabbed interface on mobile
451pub const MOBILE_TAB_BAR_STYLES: &str = r#"
452/* Mobile Tab Bar Container */
453.mobile-tabs {
454    display: none;
455}
456
457@media (max-width: 768px) {
458    .mobile-tabs {
459        display: flex;
460        gap: 4px;
461        padding: 8px var(--mobile-padding, 12px);
462        background: rgba(0, 0, 0, 0.4);
463        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
464        overflow-x: auto;
465        -webkit-overflow-scrolling: touch;
466        flex-shrink: 0;
467        /* Hide scrollbar but keep functionality */
468        scrollbar-width: none;
469        -ms-overflow-style: none;
470    }
471
472    .mobile-tabs::-webkit-scrollbar {
473        display: none;
474    }
475
476    /* Individual Tab Button */
477    .mobile-tab {
478        flex: 1;
479        min-width: 0;
480        padding: 10px 8px;
481        border: none;
482        border-radius: 10px;
483        background: rgba(255, 255, 255, 0.05);
484        color: #888;
485        font-size: 13px;
486        font-weight: 500;
487        cursor: pointer;
488        transition: all 0.2s ease;
489        display: flex;
490        flex-direction: column;
491        align-items: center;
492        gap: 4px;
493        min-height: var(--touch-min, 44px);
494        -webkit-tap-highlight-color: transparent;
495    }
496
497    .mobile-tab-icon {
498        font-size: 18px;
499        line-height: 1;
500    }
501
502    .mobile-tab-label {
503        font-size: 11px;
504        white-space: nowrap;
505        overflow: hidden;
506        text-overflow: ellipsis;
507        max-width: 100%;
508    }
509
510    .mobile-tab:active {
511        background: rgba(255, 255, 255, 0.15);
512        transform: scale(0.97);
513    }
514
515    .mobile-tab.active {
516        background: rgba(102, 126, 234, 0.25);
517        color: #e8e8e8;
518        border: 1px solid rgba(102, 126, 234, 0.4);
519    }
520
521    /* Tab indicator dots (optional, for swipe hint) */
522    .mobile-tab-indicator {
523        display: flex;
524        justify-content: center;
525        gap: 6px;
526        padding: 6px;
527        background: rgba(0, 0, 0, 0.2);
528    }
529
530    .mobile-tab-dot {
531        width: 6px;
532        height: 6px;
533        border-radius: 50%;
534        background: rgba(255, 255, 255, 0.2);
535        transition: all 0.2s ease;
536    }
537
538    .mobile-tab-dot.active {
539        background: #667eea;
540        width: 18px;
541        border-radius: 3px;
542    }
543}
544
545/* Landscape mobile - horizontal tab layout */
546@media (max-height: 500px) and (orientation: landscape) {
547    .mobile-tabs {
548        padding: 4px 8px;
549    }
550
551    .mobile-tab {
552        padding: 6px 12px;
553        flex-direction: row;
554        gap: 6px;
555        min-height: 36px;
556    }
557
558    .mobile-tab-icon {
559        font-size: 16px;
560    }
561}
562"#;
563
564#[cfg(test)]
565#[path = "../../../../crates/logicaffeine_tests/unit/logicaffeine_web/ui/responsive/tests.rs"]
566mod tests;