/**
 * Ozark Oracle - Mobile Optimization
 * ===================================
 *
 * Makes Apokalypsis investigation platform work perfectly on phones.
 *
 * Add to all Apokalypsis HTML pages:
 * <link rel="stylesheet" href="mobile_optimized.css">
 *
 * Copyright (c) 2026 Tammy L Casey. All rights reserved.
 */

/* ============================================================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ============================================================================ */

/* Reduce animations on mobile (saves battery + performance) */
@media (max-width: 768px) {
    *, *::before, *::after {
        animation-duration: 0.3s !important;
        transition-duration: 0.2s !important;
    }
}

/* ============================================================================
   LARGE FILE OPTIMIZATION (directory.html, casefile.html)
   ============================================================================ */

/* On mobile, show only first 50 entries by default */
@media (max-width: 768px) {
    .dossier-list .dossier-item:nth-child(n+51) {
        display: none;
    }

    .dossier-list::after {
        content: '';
        display: block;
        text-align: center;
        padding: 20px;
        color: #888;
    }

    /* Show "Load More" button */
    #load-more-btn {
        display: block !important;
        width: 100%;
        padding: 15px;
        background: #FFD700;
        color: #000;
        border: none;
        font-weight: bold;
        font-size: 1em;
        cursor: pointer;
        margin-top: 20px;
    }
}

/* ============================================================================
   SIMPLIFIED 3D VISUALIZATION FOR MOBILE
   ============================================================================ */

@media (max-width: 768px) {
    /* Hide complex 3D/WebGL visualizations on mobile (NOT Leaflet maps, NOT Plotly 2D) */
    .nexus-map,
    .nexus-map-full,
    #crime-nexus-3d {
        display: none;
    }

    /* Show simplified list view instead */
    #mobile-simple-view {
        display: block !important;
        padding: 10px;
    }

    /* Add message explaining why 3D is hidden */
    .nexus-map::before,
    .nexus-map-full::before {
        content: '3D visualization disabled on mobile for performance. Use desktop for full experience.';
        display: block;
        padding: 20px;
        background: rgba(255, 215, 0, 0.1);
        border: 1px solid #FFD700;
        color: #FFD700;
        text-align: center;
        font-size: 0.9em;
    }
}

/* ============================================================================
   TOUCH-FRIENDLY CONTROLS
   ============================================================================ */

/* Larger touch targets on mobile (Apple recommends 44x44px minimum) */
/* Excludes nav hamburger/more buttons which have their own sizing */
@media (max-width: 768px) {
    button:not(.mn-hamburger):not(.mn-more-btn),
    .nav-btn,
    a.interactive {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 16px;
        font-size: 1em;
    }

    /* Larger form inputs */
    input[type="text"],
    input[type="search"],
    input[type="email"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 12px;
    }
}

/* ============================================================================
   MOBILE NAVIGATION IMPROVEMENTS
   ============================================================================ */

@media (max-width: 768px) {
    /* Hamburger menu - always visible, flex for centered icon */
    .mn-hamburger {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Desktop nav - hidden */
    .mn-links {
        display: none !important;
    }

    /* Mobile panel - MUST be hidden when [hidden] attribute present */
    #morgan-mobile-panel[hidden] {
        display: none !important;
    }

    /* Mobile panel - full screen when visible */
    #morgan-mobile-panel {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.98);
        z-index: 10000;
        overflow-y: auto;
        padding: 60px 20px 20px 20px;
    }

    /* Close button at top of mobile panel */
    #morgan-mobile-panel .mmp-close-btn {
        position: fixed;
        top: 10px;
        right: 15px;
        z-index: 10001;
        background: none;
        border: 1px solid #666;
        color: #ccc;
        font-size: 1.5em;
        width: 44px;
        height: 44px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }

    #morgan-mobile-panel .mmp-close-btn:hover {
        color: #FFD700;
        border-color: #FFD700;
    }

    #morgan-mobile-panel a {
        display: block;
        padding: 15px;
        font-size: 1.1em;
        border-bottom: 1px solid #333;
        color: #ccc;
        text-decoration: none;
    }

    #morgan-mobile-panel a:hover,
    #morgan-mobile-panel a.active {
        background: rgba(255, 215, 0, 0.1);
        color: #FFD700;
    }
}

/* ============================================================================
   MOBILE-SPECIFIC CONTROLS SIDEBAR
   ============================================================================ */

@media (max-width: 768px) {
    #controls {
        /* Move to bottom of screen on mobile */
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 50vh;
        border-radius: 12px 12px 0 0;
        /* Collapsible */
        transform: translateY(calc(100% - 50px));
        transition: transform 0.3s;
    }

    #controls.expanded {
        transform: translateY(0);
    }

    /* Drag handle for mobile */
    #controls::before {
        content: '';
        display: block;
        width: 50px;
        height: 4px;
        background: #666;
        border-radius: 2px;
        margin: 10px auto 15px auto;
        cursor: grab;
    }
}

/* ============================================================================
   TEXT READABILITY ON MOBILE
   ============================================================================ */

@media (max-width: 768px) {
    body {
        font-size: 16px; /* Prevents iOS auto-zoom */
        line-height: 1.5; /* Better readability */
    }

    /* Larger headings on mobile */
    h1 { font-size: 1.8em; }
    h2 { font-size: 1.5em; }
    h3 { font-size: 1.3em; }

    /* More spacing for readability */
    p {
        margin-bottom: 1em;
        line-height: 1.6;
    }

    /* Wider touch areas for lists */
    ul, ol {
        padding-left: 25px;
    }

    li {
        margin-bottom: 10px;
        line-height: 1.5;
    }
}

/* ============================================================================
   MOBILE IMAGE OPTIMIZATION
   ============================================================================ */

@media (max-width: 768px) {
    /* All images: responsive */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Hide decorative images on mobile (save bandwidth) */
    img[alt=""],
    img[role="presentation"] {
        display: none;
    }

    /* Lazy load images below fold */
    img[loading="lazy"] {
        background: #222; /* Placeholder color */
    }
}

/* ============================================================================
   MOBILE TABLE OPTIMIZATION
   ============================================================================ */

@media (max-width: 768px) {
    /* Tables become cards on mobile */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    /* OR convert to card layout */
    table.mobile-cards {
        display: block;
    }

    table.mobile-cards thead {
        display: none; /* Hide headers */
    }

    table.mobile-cards tbody,
    table.mobile-cards tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #333;
        border-radius: 6px;
        padding: 10px;
    }

    table.mobile-cards td {
        display: block;
        text-align: right;
        padding: 8px;
        border: none;
    }

    table.mobile-cards td::before {
        content: attr(data-label);
        float: left;
        font-weight: bold;
        color: #FFD700;
    }
}

/* ============================================================================
   MOBILE SEARCH RESULTS
   ============================================================================ */

@media (max-width: 768px) {
    #search-results .result-item {
        padding: 12px;
        margin-bottom: 10px;
    }

    #search-results .result-title {
        font-size: 1.1em;
        line-height: 1.3;
    }

    #search-results .result-snippet {
        font-size: 0.9em;
        line-height: 1.4;
    }
}

/* ============================================================================
   MOBILE PERFORMANCE - REDUCE COMPLEXITY
   ============================================================================ */

@media (max-width: 768px) {
    /* Disable expensive effects on mobile */
    .glass-effect,
    .blur-effect,
    .shadow-effect {
        backdrop-filter: none !important;
        box-shadow: none !important;
    }

    /* Simpler gradients */
    .gradient-bg {
        background: #111 !important;
    }

    /* No parallax on mobile (causes jank) */
    [data-parallax] {
        transform: none !important;
    }
}

/* ============================================================================
   MOBILE MODAL/OVERLAY FIX
   ============================================================================ */

@media (max-width: 768px) {
    /* Modals take full screen on mobile */
    .modal,
    .overlay-panel {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    /* Prevent body scroll when modal open */
    body.modal-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* ============================================================================
   MOBILE ACCESSIBILITY
   ============================================================================ */

@media (max-width: 768px) {
    /* Skip to content link - more prominent on mobile */
    .skip-link {
        position: absolute;
        top: 0;
        left: 0;
        background: #FFD700;
        color: #000;
        padding: 10px 15px;
        text-decoration: none;
        z-index: 10001;
        transform: translateY(-100%);
        transition: transform 0.3s;
    }

    .skip-link:focus {
        transform: translateY(0);
    }

    /* Ensure focus indicators are visible on mobile */
    a:focus,
    button:focus,
    input:focus {
        outline: 2px solid #FFD700;
        outline-offset: 2px;
    }
}

/* ============================================================================
   FLOATING CONFESSION BUTTON (Mobile-Optimized)
   ============================================================================ */

.floating-confess-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #FFD700;
    color: #000;
    padding: 15px 25px;
    border-radius: 30px;
    font-weight: bold;
    text-decoration: none;
    box-shadow: 0 4px 20px rgba(255, 215, 0, 0.6);
    z-index: 9998;
    font-size: 0.9em;
    transition: all 0.3s;
}

.floating-confess-btn:hover {
    background: #fff;
    box-shadow: 0 6px 30px rgba(255, 215, 0, 0.8);
    transform: translateY(-2px);
}

@media (max-width: 768px) {
    .floating-confess-btn {
        /* Larger on mobile */
        padding: 18px 30px;
        font-size: 1em;
        bottom: 15px;
        right: 15px;
        /* Pulse animation to draw attention */
        animation: pulse 2s infinite;
    }

    @keyframes pulse {
        0%, 100% {
            box-shadow: 0 4px 20px rgba(255, 215, 0, 0.6);
        }
        50% {
            box-shadow: 0 4px 40px rgba(255, 215, 0, 1);
        }
    }
}

/* ============================================================================
   LANDSCAPE MODE OPTIMIZATION
   ============================================================================ */

@media (max-width: 768px) and (orientation: landscape) {
    /* In landscape, navigation takes less space */
    #morgan-nav {
        padding: 5px 10px;
    }

    /* Controls sidebar - thinner in landscape */
    #controls {
        width: 200px;
        font-size: 0.85em;
    }

    /* More content visible */
    #map {
        height: calc(100vh - 50px);
    }
}

/* ============================================================================
   DARK MODE OPTIMIZATION (Most users on mobile use dark mode)
   ============================================================================ */

/* Respect system dark mode preference */
@media (prefers-color-scheme: dark) {
    /* Already dark, but ensure pure blacks for OLED */
    body {
        background: #000; /* True black for OLED battery savings */
    }

    .card, .panel {
        background: #0a0a0a;
    }
}

/* ============================================================================
   MOBILE DATA SAVING MODE
   ============================================================================ */

/* If user has data saver enabled, reduce content */
@media (prefers-reduced-data: reduce) {
    /* Don't autoload images */
    img {
        display: none;
    }

    /* Show text alternative */
    img::after {
        content: '[Image]';
        display: block;
        color: #666;
        font-size: 0.8em;
    }

    /* Simplify backgrounds */
    body {
        background: #000 !important;
    }
}

/* ============================================================================
   MOBILE-SPECIFIC UTILITY CLASSES
   ============================================================================ */

/* Hide on mobile */
.mobile-hide {
    display: block;
}

@media (max-width: 768px) {
    .mobile-hide {
        display: none !important;
    }
}

/* Show only on mobile */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }
}

/* Responsive text sizes */
.text-responsive {
    font-size: clamp(0.9em, 2.5vw, 1.2em);
}

/* Mobile-friendly spacing */
@media (max-width: 768px) {
    .section {
        padding: 15px;
        margin: 10px 0;
    }

    .container {
        padding: 10px;
    }
}
