/**
 * Mobile Enhancements for NKST Makurdi Central Church
 * Ensures optimal mobile experience across all devices
 */

/* ========================================
   GLOBAL MOBILE OPTIMIZATIONS
   ======================================== */

/* Prevent horizontal scroll on mobile */
html, body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Better tap targets for mobile */
a, button, input, select, textarea, .btn {
    min-height: 44px;
    min-width: 44px;
}

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Remove tap highlight on mobile */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Touch active state for better feedback */
.touch-active {
    opacity: 0.7;
    transform: scale(0.98);
    transition: all 0.1s ease;
}

/* Better touch scrolling */
.scroll-container {
    -webkit-overflow-scrolling: touch;
}

/* ========================================
   FORM ELEMENTS - MOBILE
   ======================================== */

/* Prevent zoom on input focus (iOS) */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
textarea,
select {
    font-size: 16px !important;
}

/* Better mobile form styling */
@media (max-width: 768px) {
    .form-control {
        padding: 0.875rem 1rem;
        font-size: 16px;
        border-radius: 0.5rem;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .form-group {
        margin-bottom: 1.25rem;
    }

    label {
        font-size: 0.95rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
    }

    /* Full width buttons on mobile */
    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
        margin-bottom: 0.75rem;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(55, 42, 195, 0.2);
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
    }

    /* Specific styling for login button */
    #loginBtn {
        position: relative;
        z-index: 100;
        min-height: 48px;
        display: block;
        width: 100%;
    }

    /* Stack form actions vertically */
    .form-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    /* Ensure homepage sidebar is visible and properly styled on mobile */
    .main-content .sidebar {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem;
        width: 100% !important;
        position: static !important; /* Override any fixed positioning */
        left: auto !important;
        top: auto !important;
        height: auto !important;
        transform: none !important;
    }

    .main-content .sidebar-card {
        display: block !important;
        width: 100%;
        background: white;
        border-radius: 1rem;
        padding: 1.5rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        margin-bottom: 1rem;
    }

    /* Ensure login box is visible */
    #login,
    .sidebar-card {
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* ========================================
   NAVIGATION - MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Mobile header */
    .header {
        padding: 0.75rem 1rem;
    }

    .navbar {
        flex-wrap: wrap;
    }

    .nav-links {
        flex-direction: column;
        width: 100%;
        padding: 0;
    }

    .nav-links li {
        width: 100%;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .nav-links a {
        padding: 1rem;
        display: block;
    }

    /* Hamburger menu */
    .mobile-menu-toggle {
        display: block;
        font-size: 1.5rem;
        background: none;
        border: none;
        color: white;
        cursor: pointer;
        padding: 0.5rem;
    }

    .nav-links.mobile-hidden {
        display: none;
    }

    .nav-links.mobile-show {
        display: flex;
    }
}

/* ========================================
   CONTAINERS & LAYOUT - MOBILE
   ======================================== */

@media (max-width: 768px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
        padding-top: 1rem;
        padding-bottom: 1rem;
    }

    /* Grid layouts */
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Cards */
    .card {
        margin-bottom: 1rem;
        border-radius: 0.75rem;
    }

    /* Modals */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 1rem auto;
        border-radius: 1rem;
    }
}

/* ========================================
   TABLES - MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Responsive tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 0.5rem;
    }

    table {
        font-size: 0.875rem;
    }

    th, td {
        padding: 0.75rem 0.5rem;
        min-width: 100px;
    }

    /* Stack table on very small screens */
    @media (max-width: 480px) {
        .table-stack {
            display: block;
        }

        .table-stack thead {
            display: none;
        }

        .table-stack tbody,
        .table-stack tr,
        .table-stack td {
            display: block;
            width: 100%;
        }

        .table-stack tr {
            margin-bottom: 1rem;
            border: 1px solid #e5e7eb;
            border-radius: 0.5rem;
            padding: 1rem;
        }

        .table-stack td {
            text-align: right;
            padding: 0.5rem 0;
            border-bottom: 1px solid #f3f4f6;
        }

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

        .table-stack td:last-child {
            border-bottom: none;
        }
    }
}

/* ========================================
   IMAGES & MEDIA - MOBILE
   ======================================== */

@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }

    video {
        max-width: 100%;
        height: auto;
    }

    /* Gallery grids */
    .media-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    @media (max-width: 480px) {
        .media-grid {
            grid-template-columns: 1fr;
        }
    }
}

/* ========================================
   DASHBOARD - MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Dashboard cards */
    .dashboard-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1.5rem;
    }

    /* Quick actions */
    .quick-actions {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    @media (max-width: 480px) {
        .quick-actions {
            grid-template-columns: 1fr;
        }
    }

    /* Dashboard Sidebar (only apply to dashboard pages, not homepage) */
    .admin-sidebar,
    .dashboard-sidebar {
        position: fixed;
        left: -300px;
        top: 0;
        height: 100vh;
        width: 280px;
        background: white;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .admin-sidebar.mobile-open,
    .dashboard-sidebar.mobile-open {
        left: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }
}

/* ========================================
   PWA INSTALL PROMPT - ALL DEVICES
   ======================================== */

.pwa-install-prompt {
    position: fixed;
    bottom: -200px;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    padding: 1.5rem;
    z-index: 9999;
    transition: bottom 0.3s ease;
    border-top-left-radius: 1rem;
    border-top-right-radius: 1rem;
}

.pwa-install-prompt.show {
    bottom: 0;
}

.pwa-install-prompt .prompt-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.pwa-install-prompt .app-icon {
    width: 60px;
    height: 60px;
    border-radius: 1rem;
    object-fit: cover;
}

.pwa-install-prompt .prompt-text h3 {
    margin: 0 0 0.25rem 0;
    font-size: 1.1rem;
    color: #1f2937;
}

.pwa-install-prompt .prompt-text p {
    margin: 0;
    font-size: 0.875rem;
    color: #6b7280;
}

.pwa-install-prompt .prompt-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.pwa-install-prompt .btn-install {
    flex: 1;
    background: #372ac3;
    color: white;
    border: none;
    padding: 0.875rem;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
}

.pwa-install-prompt .btn-dismiss {
    padding: 0.875rem 1.5rem;
    background: #f3f4f6;
    border: none;
    border-radius: 0.5rem;
    color: #6b7280;
    cursor: pointer;
}

.pwa-install-prompt .btn-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #9ca3af;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

/* ========================================
   iOS SPECIFIC STYLES
   ======================================== */

/* iOS safe area insets */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .header {
        padding-top: max(0.75rem, env(safe-area-inset-top));
    }

    .footer {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }

    .chat-input-area,
    .fixed-bottom {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* iOS share button styling */
.ios-share-instruction {
    display: none;
    background: #f0f9ff;
    border: 1px solid #0500ff;
    border-radius: 0.5rem;
    padding: 1rem;
    margin: 1rem 0;
    font-size: 0.875rem;
    color: #372ac3;
}

.is-ios .ios-share-instruction {
    display: block;
}

/* ========================================
   ANDROID SPECIFIC STYLES
   ======================================== */

/* Android notification styles */
.android-notification {
    background: #10b981;
    color: white;
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

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

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #0500ff;
    outline-offset: 2px;
}

/* Skip to main content */
.skip-to-main {
    position: absolute;
    left: -9999px;
    z-index: 999;
    padding: 1rem;
    background: #372ac3;
    color: white;
    text-decoration: none;
}

.skip-to-main:focus {
    left: 0;
    top: 0;
}

/* ========================================
   LOADING STATES - MOBILE
   ======================================== */

.loading-skeleton {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ========================================
   OFFLINE INDICATOR
   ======================================== */

.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #e10000;
    color: white;
    padding: 0.75rem;
    text-align: center;
    font-size: 0.875rem;
    z-index: 9998;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-indicator.show {
    transform: translateY(0);
}

/* ========================================
   RESPONSIVE UTILITIES
   ======================================== */

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

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

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

/* Responsive text sizes */
@media (max-width: 768px) {
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    p, li, span {
        font-size: 0.95rem;
        line-height: 1.6;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .no-print {
        display: none !important;
    }

    body {
        background: white;
    }

    a {
        text-decoration: underline;
    }
}

/* ========================================
   CRITICAL MOBILE FIXES - FINAL OVERRIDES
   ======================================== */

/* Force sidebar visibility on all mobile devices - CRITICAL FIX */
@media (max-width: 768px) {
    /* Override any styles hiding the sidebar on mobile */
    .main-content {
        display: block !important;
    }

    .main-content .sidebar {
        display: flex !important;
        flex-direction: column !important;
        position: relative !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        height: auto !important;
        transform: translateX(0) !important;
        margin-top: 2rem;
        padding: 0 1rem;
    }

    .main-content .sidebar-card {
        display: block !important;
        position: relative !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Ensure login form is visible and functional */
    #login {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    #loginForm {
        display: block !important;
    }

    #loginBtn {
        pointer-events: auto !important;
        display: block !important;
    }
}
