/**
 * Mobile Navigation Styles
 * Bottom tab bar and sheet menu for mobile devices
 */

/* ========================================
   CSS Variables for Mobile Navigation
   ======================================== */
:root {
    --ldr-mobile-max: 767px; /* canonical mobile breakpoint; JS reads this via getComputedStyle */
    --mobile-nav-height: 56px;
    /* 3-tier mobile nav clearance system:
       - minimal: lists, grids, nested containers where parent already has padding
       - standard: page containers, general content pages
       - extended: forms with bottom inputs (Settings), data tables (Metrics) */
    --mobile-nav-clearance-minimal: calc(80px + env(safe-area-inset-bottom));
    --mobile-nav-clearance-standard: calc(120px + env(safe-area-inset-bottom));
    --mobile-nav-clearance-extended: calc(160px + env(safe-area-inset-bottom));
    --mobile-nav-bg: var(--bg-secondary, #0a0a0f);
    --mobile-nav-border: var(--border-color, #333);
    --mobile-nav-active: var(--accent-primary, #6e4ff6);
    --mobile-nav-text: var(--text-secondary, #888);
    --mobile-nav-text-active: var(--accent-primary, #6e4ff6);
    --mobile-sheet-bg: var(--bg-primary, #1e1e2e);
    --mobile-sheet-handle: #444;
    --mobile-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   Bottom Navigation Bar
   ======================================== */
.ldr-mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-height);
    background: var(--mobile-nav-bg);
    border-top: 1px solid var(--mobile-nav-border);
    z-index: 1000;
    transform: translateY(100%);
    transition: transform var(--mobile-transition);

    /* Safe area for iPhone notch/home indicator */
    padding-bottom: env(safe-area-inset-bottom);
}

.ldr-mobile-bottom-nav.visible {
    transform: translateY(0);
}

/* Navigation tabs container */
.ldr-mobile-bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
}

/* Individual tab button */
.ldr-mobile-nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 0;
    background: none;
    border: none;
    color: var(--mobile-nav-text);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* Tab hover/focus states */
.ldr-mobile-nav-tab:hover {
    background: rgba(var(--accent-primary-rgb), 0.1);
}

.ldr-mobile-nav-tab:focus-visible {
    outline: 2px solid var(--mobile-nav-active);
    outline-offset: -2px;
}

/* Active tab */
.ldr-mobile-nav-tab.active {
    color: var(--mobile-nav-text-active);
}

/* Active indicator bar */
.ldr-mobile-nav-tab.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 2px;
    background: var(--mobile-nav-active);
    border-radius: 0 0 2px 2px;
}

/* Tab icon */
.ldr-mobile-nav-tab i {
    font-size: 20px;
    transition: transform 0.2s ease;
}

.ldr-mobile-nav-tab:active i {
    transform: scale(0.9);
}

/* Tab label.
   12px (= --text-xs) is the readability floor enforced by
   test_responsive_ui_comprehensive.js. Bottom-nav labels stay
   visually compact at 12px; the difference vs 11px is one pixel. */
.ldr-mobile-nav-label {
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* ========================================
   Sheet Menu
   ======================================== */
.ldr-mobile-sheet-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--mobile-sheet-bg);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform var(--mobile-transition);
    z-index: 2000;
    /* Allow more height for all menu sections - use dvh for dynamic viewport on mobile */
    max-height: calc(100vh - 60px);
    max-height: calc(100dvh - 60px); /* Fallback for browsers supporting dvh */
    flex-direction: column;
    box-shadow: 0 -4px 20px rgba(var(--shadow-color-rgb), 0.3);

    /* Safe area for iPhone */
    padding-bottom: env(safe-area-inset-bottom);

    /* CRITICAL: Use display:none when not active to prevent appearing in full-page screenshots.
       This completely removes the element from the rendering tree. */
    display: none;
    pointer-events: none;
}

.ldr-mobile-sheet-menu.active {
    display: flex;
    transform: translateY(0);
    pointer-events: auto;
}

/* Drag handle */
.ldr-mobile-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--mobile-sheet-handle);
    border-radius: 2px;
    margin: 12px auto 8px;
    cursor: grab;
    flex-shrink: 0;
}

.ldr-mobile-sheet-handle:active {
    cursor: grabbing;
}

/* Sheet content */
.ldr-mobile-sheet-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 0 20px;

    /* Smooth scrolling on iOS */
    -webkit-overflow-scrolling: touch;

    /* Scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: var(--mobile-sheet-handle) transparent;
}

.ldr-mobile-sheet-content::-webkit-scrollbar {
    width: 4px;
}

.ldr-mobile-sheet-content::-webkit-scrollbar-track {
    background: transparent;
}

.ldr-mobile-sheet-content::-webkit-scrollbar-thumb {
    background: var(--mobile-sheet-handle);
    border-radius: 2px;
}

/* Sheet sections */
.ldr-mobile-sheet-section {
    padding: 16px 16px 8px;
    border-bottom: 1px solid var(--mobile-nav-border);
}

.ldr-mobile-sheet-section:last-child {
    border-bottom: none;
}

.ldr-mobile-sheet-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--mobile-nav-text);
    margin-bottom: 12px;
    padding-left: 4px;
}

/* Sheet items container */
.ldr-mobile-sheet-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Sheet item button */
.ldr-mobile-sheet-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 8px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
}

.ldr-mobile-sheet-item:hover {
    background: rgba(var(--accent-primary-rgb), 0.1);
}

.ldr-mobile-sheet-item:focus-visible {
    outline: 2px solid var(--mobile-nav-active);
    outline-offset: -2px;
}

.ldr-mobile-sheet-item:active {
    background: rgba(var(--accent-primary-rgb), 0.2);
}

/* Sheet item icon */
.ldr-mobile-sheet-item i {
    width: 24px;
    font-size: 18px;
    text-align: center;
    color: var(--mobile-nav-text);
}

/* Sheet item label */
.ldr-mobile-sheet-label {
    flex: 1;
    font-weight: 400;
}

/* Sheet item badge */
.ldr-mobile-sheet-badge {
    background: var(--mobile-nav-active);
    color: white;
    /* 11px → --text-xs (12px), readability floor. */
    font-size: var(--text-xs);
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* ========================================
   Overlay
   ======================================== */
.ldr-mobile-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-color);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--mobile-transition);
    z-index: 1999;
}

.ldr-mobile-sheet-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* ========================================
   Responsive Behavior
   ======================================== */

/* Show mobile navigation on small screens */
@media (max-width: 767px) {
    /* Show mobile nav */
    .ldr-mobile-bottom-nav {
        display: flex;
    }

    .ldr-mobile-bottom-nav.visible {
        display: flex;
    }

    /* Adjust body padding for nav bar */
    body.ldr-has-mobile-nav {
        padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    }

    /* Hide desktop sidebar completely */
    .ldr-sidebar {
        display: none !important;
    }

    /* Adjust main content */
    .ldr-main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Hide mobile tab bar that was in the template */
    .ldr-mobile-tab-bar {
        display: none !important;
    }

    /* Ensure content doesn't go under nav - extra large padding to handle help panels */
    .ldr-page.active {
        padding-bottom: calc(var(--mobile-nav-height) + 100px + env(safe-area-inset-bottom));
        min-height: calc(100vh - var(--mobile-nav-height) - env(safe-area-inset-bottom));
    }

    /* Help panels need extra margin when expanded so dismissible checkbox is visible */
    .ldr-help-panel {
        margin-bottom: 2rem;
    }

    .ldr-help-panel-content {
        padding-bottom: 2rem;
    }

    .ldr-help-panel-dismiss {
        margin-bottom: 2rem;
        padding-bottom: 1rem;
    }

    /* Ensure last interactive elements have breathing room above mobile nav */
    .ldr-card:last-child {
        margin-bottom: 2rem;
    }

    /* Adjust top bar */
    .ldr-top-bar {
        left: 0 !important;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 991px) {
    /* Keep sidebar but collapsed */
    .ldr-sidebar {
        width: 60px;
    }

    /* Hide mobile navigation */
    .ldr-mobile-bottom-nav {
        display: none !important;
    }
}

/* Short viewport height - make sidebar ultra-compact */
/* Keep sidebar visible but minimize spacing to fit all items */
@media (min-width: 768px) and (max-height: 600px) {
    /* Ensure sidebar is visible */
    .ldr-sidebar {
        display: flex !important;
        visibility: visible !important;
        width: 200px !important;
    }
    .ldr-main-content {
        margin-left: 200px !important;
    }
    /* Ultra-compact sidebar for very short viewports */
    .ldr-sidebar-header {
        padding: 0.25rem 0.5rem !important;
    }
    .ldr-sidebar-header h2 {
        font-size: 0.9rem !important;
    }
    .ldr-sidebar-nav {
        padding: 0.125rem 0 !important;
    }
    .ldr-sidebar-nav li {
        min-height: 20px !important;
    }
    .ldr-sidebar-nav li a {
        padding: 0.15rem 0.5rem !important;
        font-size: 0.8rem !important;
    }
    .ldr-sidebar-section {
        margin-bottom: 0.15rem !important;
    }
    .ldr-sidebar-section-label {
        padding: 0.1rem 0.5rem !important;
        font-size: 0.5rem !important;
    }
    .ldr-sidebar-footer {
        padding: 0.25rem 0.5rem !important;
        font-size: 0.7rem !important;
    }
    .ldr-sidebar-footer p {
        margin: 0 !important;
    }
}

/* Extremely short viewport - hide footer, keep nav */
@media (min-width: 768px) and (max-height: 500px) {
    .ldr-sidebar-footer {
        display: none !important;
    }
    .ldr-sidebar-section-label {
        display: none !important;
    }
}

/* Mobile: Adjust top bar for narrow screens */
@media (max-width: 767px) {
    .ldr-top-bar {
        left: 0 !important;
    }
}

/* Desktop - ensure mobile nav is hidden (unless viewport is too short) */
@media (min-width: 992px) and (min-height: 601px) {
    .ldr-mobile-bottom-nav,
    .ldr-mobile-sheet-menu,
    .ldr-mobile-sheet-overlay {
        display: none !important;
    }
}

/* ========================================
   Animations
   ======================================== */

/* Slide up animation for sheet */
@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Fade in animation for overlay */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Ripple effect for buttons */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* Add ripple on tap (optional enhancement) */
.ldr-mobile-nav-tab::after,
.ldr-mobile-sheet-item::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    background: var(--mobile-nav-active);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
}

.ldr-mobile-nav-tab:active::after,
.ldr-mobile-sheet-item:active::after {
    animation: ripple 0.6s ease-out;
}

/* ========================================
   Accessibility
   ======================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .ldr-mobile-nav-tab.active {
        text-decoration: underline;
        font-weight: bold;
    }

    .ldr-mobile-sheet-item:focus {
        outline: 3px solid;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .ldr-mobile-bottom-nav,
    .ldr-mobile-sheet-menu,
    .ldr-mobile-sheet-overlay,
    .ldr-mobile-nav-tab,
    .ldr-mobile-sheet-item {
        transition: none !important;
        animation: none !important;
    }
}

/* ========================================
   Theme-specific mobile navigation styles
   ======================================== */
[data-theme="light"] {
    --mobile-nav-bg: #f5f5f5;
    --mobile-nav-border: #ddd;
    --mobile-nav-text: #4a4a4a;
    --mobile-sheet-bg: #fff;
    --mobile-sheet-handle: #ccc;
}

[data-theme="sepia"] {
    --mobile-nav-bg: #f4ecd8;
    --mobile-nav-border: #d4c4a8;
    --mobile-nav-text: #5c5244;
    --mobile-nav-active: #8b6914;
    --mobile-nav-text-active: #8b6914;
    --mobile-sheet-bg: #faf6ed;
    --mobile-sheet-handle: #c4b89a;
}

[data-theme="high-contrast"] {
    --mobile-nav-bg: #000000;
    --mobile-nav-border: #ffff00;
    --mobile-nav-text: #ffffff;
    --mobile-nav-active: #00ffff;
    --mobile-nav-text-active: #00ffff;
    --mobile-sheet-bg: #000000;
    --mobile-sheet-handle: #ffff00;
}

[data-theme="midnight"] {
    --mobile-nav-bg: #0d1526;
    --mobile-nav-border: #1e3a5f;
    --mobile-nav-text: #6b8ab3;
    --mobile-nav-active: #4a9eff;
    --mobile-nav-text-active: #4a9eff;
    --mobile-sheet-bg: #0a1628;
    --mobile-sheet-handle: #2a4a70;
}

[data-theme="ocean"] {
    --mobile-nav-bg: #0c1929;
    --mobile-nav-border: #1e3a5f;
    --mobile-nav-text: #7aa2c4;
    --mobile-nav-active: #00bcd4;
    --mobile-nav-text-active: #00bcd4;
    --mobile-sheet-bg: #0a1422;
    --mobile-sheet-handle: #2a4a6a;
}

[data-theme="forest"] {
    --mobile-nav-bg: #1a2416;
    --mobile-nav-border: #2d4025;
    --mobile-nav-text: #8ba07a;
    --mobile-nav-active: #4caf50;
    --mobile-nav-text-active: #4caf50;
    --mobile-sheet-bg: #151f12;
    --mobile-sheet-handle: #3a5030;
}

[data-theme="sunset"] {
    --mobile-nav-bg: #2d1b2d;
    --mobile-nav-border: #4a2c4a;
    --mobile-nav-text: #c4a3a3;
    --mobile-nav-active: #ff6b6b;
    --mobile-nav-text-active: #ff6b6b;
    --mobile-sheet-bg: #251828;
    --mobile-sheet-handle: #5a3a5a;
}

[data-theme="rose"] {
    --mobile-nav-bg: #2d1b24;
    --mobile-nav-border: #4a2c3a;
    --mobile-nav-text: #c4a3b0;
    --mobile-nav-active: #ff69b4;
    --mobile-nav-text-active: #ff69b4;
    --mobile-sheet-bg: #251820;
    --mobile-sheet-handle: #5a3a4a;
}

[data-theme="lavender"] {
    --mobile-nav-bg: #1e1b2d;
    --mobile-nav-border: #352c4a;
    --mobile-nav-text: #a8a3c4;
    --mobile-nav-active: #9370db;
    --mobile-nav-text-active: #9370db;
    --mobile-sheet-bg: #181525;
    --mobile-sheet-handle: #453a6a;
}

[data-theme="nord"] {
    --mobile-nav-bg: #2e3440;
    --mobile-nav-border: #3b4252;
    --mobile-nav-text: #81a1c1;
    --mobile-nav-active: #88c0d0;
    --mobile-nav-text-active: #88c0d0;
    --mobile-sheet-bg: #242933;
    --mobile-sheet-handle: #4c566a;
}

[data-theme="dracula"] {
    --mobile-nav-bg: #282a36;
    --mobile-nav-border: #44475a;
    --mobile-nav-text: #6272a4;
    --mobile-nav-active: #bd93f9;
    --mobile-nav-text-active: #bd93f9;
    --mobile-sheet-bg: #21222c;
    --mobile-sheet-handle: #555970;
}

[data-theme="monokai"] {
    --mobile-nav-bg: #272822;
    --mobile-nav-border: #3e3d32;
    --mobile-nav-text: #75715e;
    --mobile-nav-active: #a6e22e;
    --mobile-nav-text-active: #a6e22e;
    --mobile-sheet-bg: #1e1f1c;
    --mobile-sheet-handle: #4e4d42;
}

[data-theme="solarized-dark"] {
    --mobile-nav-bg: #002b36;
    --mobile-nav-border: #073642;
    --mobile-nav-text: #586e75;
    --mobile-nav-active: #268bd2;
    --mobile-nav-text-active: #268bd2;
    --mobile-sheet-bg: #001e26;
    --mobile-sheet-handle: #094152;
}

[data-theme="solarized-light"] {
    --mobile-nav-bg: #eee8d5;
    --mobile-nav-border: #ddd6c3;
    --mobile-nav-text: #657b83;
    --mobile-nav-active: #268bd2;
    --mobile-nav-text-active: #268bd2;
    --mobile-sheet-bg: #fdf6e3;
    --mobile-sheet-handle: #ccc6b3;
}

[data-theme="gruvbox-dark"] {
    --mobile-nav-bg: #282828;
    --mobile-nav-border: #3c3836;
    --mobile-nav-text: #928374;
    --mobile-nav-active: #fabd2f;
    --mobile-nav-text-active: #fabd2f;
    --mobile-sheet-bg: #1d2021;
    --mobile-sheet-handle: #504945;
}

[data-theme="gruvbox-light"] {
    --mobile-nav-bg: #f2e5bc;
    --mobile-nav-border: #e2d5ac;
    --mobile-nav-text: #7c6f64;
    --mobile-nav-active: #b57614;
    --mobile-nav-text-active: #b57614;
    --mobile-sheet-bg: #fbf1c7;
    --mobile-sheet-handle: #d2c59c;
}

[data-theme="tokyo-night"] {
    --mobile-nav-bg: #1a1b26;
    --mobile-nav-border: #24283b;
    --mobile-nav-text: #565f89;
    --mobile-nav-active: #7aa2f7;
    --mobile-nav-text-active: #7aa2f7;
    --mobile-sheet-bg: #16161e;
    --mobile-sheet-handle: #343b5a;
}

[data-theme="catppuccin"] {
    --mobile-nav-bg: #1e1e2e;
    --mobile-nav-border: #313244;
    --mobile-nav-text: #6c7086;
    --mobile-nav-active: #cba6f7;
    --mobile-nav-text-active: #cba6f7;
    --mobile-sheet-bg: #181825;
    --mobile-sheet-handle: #45475a;
}

[data-theme="one-dark"] {
    --mobile-nav-bg: #21252b;
    --mobile-nav-border: #2c313c;
    --mobile-nav-text: #5c6370;
    --mobile-nav-active: #61afef;
    --mobile-nav-text-active: #61afef;
    --mobile-sheet-bg: #1b1f23;
    --mobile-sheet-handle: #3e4451;
}
