/* =====================================================
   MOBILE OPTIMIZATION FOR PUBLIC PAGES
   ===================================================== */

/* Touch-friendly minimum sizes */
:root {
    --touch-target-min: 44px;
    --mobile-padding: 16px;
    --mobile-font-base: 16px;
}

/* Base responsive adjustments */
@media (max-width: 768px) {
    
    /* Prevent horizontal scroll */
    body {
        overflow-x: hidden;
    }
    
    /* Better text readability on mobile */
    body {
        font-size: var(--mobile-font-base);
        line-height: 1.6;
    }
    
    /* Touch-friendly buttons */
    button, 
    .btn,
    a.button {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        padding: 12px 16px;
        font-size: 16px;
    }
    
    /* Touch-friendly inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        min-height: var(--touch-target-min);
        font-size: 16px !important; /* Prevent zoom on iOS */
        padding: 12px;
    }
    
    /* Container padding */
    .container,
    .max-w-7xl {
        padding-left: var(--mobile-padding);
        padding-right: var(--mobile-padding);
    }
}

/* =====================================================
   NAVBAR MOBILE OPTIMIZATION
   ===================================================== */

@media (max-width: 768px) {
    nav {
        position: sticky;
        top: 0;
        z-index: 1000;
    }
    
    nav .flex.justify-between {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    nav .flex.items-center.space-x-4 {
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-end;
    }
    
    nav h1 {
        font-size: 16px;
    }
    
    nav button {
        font-size: 14px;
        padding: 8px 12px;
        white-space: nowrap;
    }
    
    nav #userEmail {
        font-size: 12px;
    }
    
    nav #userTimezone {
        font-size: 10px;
    }
    
    /* Hide less important nav items on very small screens */
    @media (max-width: 480px) {
        nav .text-right {
            order: 10;
            flex-basis: 100%;
            margin-top: 8px;
            text-align: center;
        }
    }
}

/* =====================================================
   DASHBOARD MOBILE OPTIMIZATION
   ===================================================== */

@media (max-width: 768px) {
    /* Stats cards */
    .grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }
    
    .grid.grid-cols-2,
    .grid.grid-cols-3,
    .grid.grid-cols-4 {
        grid-template-columns: 1fr !important;
    }
    
    /* Alert boxes */
    .border-l-4 {
        padding: 12px !important;
    }
    
    .border-l-4 .flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px;
    }
    
    .border-l-4 button {
        width: 100%;
    }
    
    /* Cards */
    .bg-white.rounded-lg.shadow-lg {
        padding: 16px !important;
        margin-bottom: 16px;
    }
    
    /* Card headers */
    .bg-white h2,
    .bg-white h3 {
        font-size: 18px !important;
    }
    
    .bg-white h4 {
        font-size: 16px !important;
    }
}

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

@media (max-width: 768px) {
    /* Make tables scrollable */
    .overflow-x-auto {
        margin: 0 -16px;
        padding: 0 16px;
    }
    
    table {
        font-size: 14px;
        min-width: 600px; /* Force horizontal scroll */
    }
    
    table th,
    table td {
        padding: 8px 12px;
        white-space: nowrap;
    }
    
    table th {
        font-size: 12px;
    }
    
    /* Alternative: Card-style table for better mobile UX */
    .table-mobile-cards {
        display: none;
    }
    
    @media (max-width: 640px) {
        table.hide-on-mobile {
            display: none;
        }
        
        .table-mobile-cards {
            display: block;
        }
        
        .table-mobile-cards .card-row {
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 12px;
            margin-bottom: 12px;
        }
        
        .table-mobile-cards .card-row .row-label {
            font-size: 12px;
            color: #6b7280;
            font-weight: 500;
            margin-bottom: 4px;
        }
        
        .table-mobile-cards .card-row .row-value {
            font-size: 14px;
            color: #111827;
            margin-bottom: 12px;
        }
        
        .table-mobile-cards .card-row .row-value:last-child {
            margin-bottom: 0;
        }
    }
}

/* =====================================================
   FORM MOBILE OPTIMIZATION
   ===================================================== */

@media (max-width: 768px) {
    /* Login/Register forms */
    .max-w-md {
        max-width: 100%;
        margin: 16px;
    }
    
    form .space-y-6 > * + * {
        margin-top: 16px;
    }
    
    form label {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    form input,
    form select,
    form textarea {
        font-size: 16px;
        padding: 12px;
    }
    
    /* 2FA code input */
    input[type="text"]#verificationCode {
        font-size: 24px;
        letter-spacing: 0.5em;
    }
}

/* =====================================================
   PAYMENT MODAL MOBILE OPTIMIZATION
   ===================================================== */

@media (max-width: 768px) {
    /* Modal fullscreen on mobile */
    .fixed.inset-0 > div {
        margin: 0 !important;
        max-width: 100% !important;
        height: 100% !important;
        border-radius: 0 !important;
        overflow-y: auto;
    }
    
    .fixed.inset-0 .bg-white {
        padding: 16px !important;
    }
    
    /* Payment method buttons */
    .grid.grid-cols-2.gap-4 {
        grid-template-columns: 1fr !important;
    }
    
    /* Network buttons */
    .flex.space-x-3 {
        flex-direction: column;
        gap: 12px;
    }
    
    .flex.space-x-3 button {
        width: 100%;
    }
    
    /* QR Code */
    #qrCode {
        max-width: 250px;
        margin: 0 auto;
    }
    
    /* Copy buttons */
    .flex.items-center.space-x-2 {
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px;
    }
    
    .flex.items-center.space-x-2 input {
        width: 100%;
    }
    
    .flex.items-center.space-x-2 button {
        width: 100%;
    }
}

/* =====================================================
   POSITIONS & ORDERS MOBILE OPTIMIZATION
   ===================================================== */

@media (max-width: 768px) {
    /* Position cards */
    #positionsContainer .bg-white {
        padding: 12px !important;
    }
    
    #positionsContainer h3 {
        font-size: 16px !important;
    }
    
    #positionsContainer .grid {
        grid-template-columns: 1fr !important;
        gap: 8px;
    }
    
    #positionsContainer .text-sm {
        font-size: 13px;
    }
    
    /* Action buttons in positions */
    #positionsContainer button {
        font-size: 13px;
        padding: 6px 12px;
    }
}

/* =====================================================
   REFERRAL DASHBOARD MOBILE OPTIMIZATION
   ===================================================== */

@media (max-width: 768px) {
    /* Referral link container */
    .flex.items-center.space-x-2 {
        flex-direction: column;
        gap: 12px;
    }
    
    .flex.items-center.space-x-2 input[readonly] {
        width: 100%;
        font-size: 12px;
        padding: 10px;
    }
    
    .flex.items-center.space-x-2 button {
        width: 100%;
    }
    
    /* Stats grid */
    .grid.grid-cols-1.md\\:grid-cols-2.lg\\:grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }
    
    @media (max-width: 480px) {
        .grid.grid-cols-1.md\\:grid-cols-2.lg\\:grid-cols-4 {
            grid-template-columns: 1fr !important;
        }
    }
}

/* =====================================================
   SETTINGS MODAL MOBILE OPTIMIZATION
   ===================================================== */

@media (max-width: 768px) {
    #settingsModal .bg-white {
        max-width: 100% !important;
        margin: 0 !important;
        height: 100vh !important;
        border-radius: 0 !important;
        overflow-y: auto;
    }
    
    #settingsModal h2 {
        font-size: 20px !important;
    }
    
    #settingsModal .space-y-6 > * + * {
        margin-top: 16px;
    }
}

/* =====================================================
   UTILITY CLASSES FOR MOBILE
   ===================================================== */

@media (max-width: 768px) {
    /* Hide on mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Show only on mobile */
    .show-mobile {
        display: block !important;
    }
    
    /* Text adjustments */
    .mobile-text-sm {
        font-size: 14px !important;
    }
    
    .mobile-text-xs {
        font-size: 12px !important;
    }
    
    /* Spacing adjustments */
    .mobile-p-4 {
        padding: 16px !important;
    }
    
    .mobile-m-4 {
        margin: 16px !important;
    }
    
    /* Full width on mobile */
    .mobile-w-full {
        width: 100% !important;
    }
}

/* =====================================================
   SCROLL OPTIMIZATION
   ===================================================== */

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

/* Better scroll for overflow elements */
.overflow-x-auto,
.overflow-y-auto {
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar but keep functionality */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* =====================================================
   LOADING STATES
   ===================================================== */

@media (max-width: 768px) {
    .animate-spin {
        width: 32px !important;
        height: 32px !important;
    }
    
    .loading-overlay {
        font-size: 14px;
    }
}

/* =====================================================
   TOAST NOTIFICATIONS MOBILE
   ===================================================== */

@media (max-width: 768px) {
    .toast,
    [class*="toast-"] {
        width: calc(100% - 32px) !important;
        left: 16px !important;
        right: 16px !important;
        font-size: 14px;
    }
}

/* =====================================================
   LANDSCAPE ORIENTATION (Mobile)
   ===================================================== */

@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce vertical padding in landscape */
    .py-8 {
        padding-top: 16px !important;
        padding-bottom: 16px !important;
    }
    
    nav {
        position: fixed;
        width: 100%;
    }
    
    body {
        padding-top: 60px;
    }
}

/* =====================================================
   iOS SAFE AREA SUPPORT
   ===================================================== */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    nav {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

/* =====================================================
   PRINT STYLES (Hide on print)
   ===================================================== */

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

/* =====================================================
   BOOTSTRAP MOBILE OPTIMIZATION (for referral-dashboard)
   ===================================================== */

@media (max-width: 768px) {
    /* Dashboard header */
    .dashboard-header {
        padding: 1rem 0 !important;
    }
    
    .dashboard-header h1 {
        font-size: 1.5rem !important;
    }
    
    .dashboard-header p {
        font-size: 0.9rem !important;
    }
    
    /* Stat cards */
    .stat-card {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }
    
    .stat-value {
        font-size: 1.5rem !important;
    }
    
    .stat-label {
        font-size: 0.8rem !important;
    }
    
    /* Referral code box */
    .referral-code-box {
        padding: 1rem !important;
    }
    
    .referral-code {
        font-size: 1.2rem !important;
        word-break: break-all;
    }
    
    /* Level badges */
    .level-badge {
        font-size: 0.8rem !important;
        padding: 0.4rem 0.8rem !important;
        margin: 0.3rem !important;
    }
    
    /* Tables */
    .table {
        font-size: 0.85rem !important;
    }
    
    .table th,
    .table td {
        padding: 0.5rem !important;
    }
    
    /* Bootstrap buttons */
    .btn {
        min-height: var(--touch-target-min);
        font-size: 0.9rem !important;
        padding: 0.5rem 1rem !important;
    }
    
    .btn-sm {
        font-size: 0.8rem !important;
        padding: 0.4rem 0.8rem !important;
    }
    
    /* Container padding */
    .container {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
    
    /* Tree structure */
    .tree-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .tree-node {
        min-width: 150px;
    }
    
    /* Navbar for Bootstrap */
    .navbar {
        padding: 0.5rem 1rem !important;
    }
    
    .navbar-brand {
        font-size: 1rem !important;
    }
    
    .nav-link {
        font-size: 0.9rem !important;
    }
}

@media (max-width: 480px) {
    /* Very small screens - stack everything */
    .row > div[class*="col-"] {
        margin-bottom: 1rem;
    }
    
    /* Hide tree on very small screens */
    .tree-container {
        display: none;
    }
    
    .tree-mobile-warning {
        display: block !important;
        background: #fff3cd;
        border: 1px solid #ffc107;
        padding: 1rem;
        border-radius: 0.5rem;
        text-align: center;
        margin: 1rem 0;
    }
}

