/* Mobile-First Responsive Design */
:root {
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

/* Hide desktop elements on mobile */
@media (max-width: 768px) {
    .header,
    .footer {
        display: none !important;
    }
    
    .main-content {
        padding-bottom: 80px;
        padding-top: 60px;
        min-height: calc(100vh - 140px);
    }
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(17, 17, 17, 0.98);
    backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.5rem;
    padding-bottom: calc(0.5rem + var(--safe-area-inset-bottom));
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 12px;
    transition: var(--transition);
    min-width: 56px;
    position: relative;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
}

.nav-item.active {
    color: var(--accent-primary);
    background: rgba(0, 255, 136, 0.1);
}

.nav-item.active::after {
    content: '';
    position: absolute;
    top: -2px;
    width: 4px;
    height: 4px;
    background: var(--accent-primary);
    border-radius: 50%;
}

.nav-icon {
    font-size: 1.4rem;
    margin-bottom: 0.25rem;
    transition: var(--transition);
    display: block;
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 600;
    transition: var(--transition);
}

.nav-item.active .nav-icon {
    transform: scale(1.1);
}

.nav-upload {
    background: var(--accent-gradient);
    color: #000 !important;
    border-radius: 50%;
    width: 52px;
    height: 52px;
    margin-top: -16px;
    box-shadow: 0 4px 20px rgba(0, 255, 136, 0.4);
    border: 3px solid var(--bg-primary);
}

.nav-upload .nav-icon {
    font-size: 1.6rem;
    margin-bottom: 0;
}

.nav-upload .nav-label {
    display: none;
}

/* Floating Action Button */
.fab {
    position: fixed;
    bottom: 150px;
    right: 16px;
    width: 56px;
    height: 56px;
    background: var(--accent-gradient);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 6px 25px rgba(0, 255, 136, 0.4);
    z-index: 999;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.fab:active {
    transform: scale(0.95);
    box-shadow: 0 4px 15px rgba(0, 255, 136, 0.6);
}

/* Mobile Header */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(17, 17, 17, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + var(--safe-area-inset-top));
    z-index: 1001;
    height: 60px;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: var(--transition);
}

.mobile-menu-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

.mobile-logo {
    cursor: pointer;
}

.mobile-logo img {
    height: 32px;
    width: auto;
    filter: drop-shadow(0 0 10px rgba(0, 255, 136, 0.3));
}

.mobile-actions {
    display: flex;
    gap: 0.5rem;
}

.mobile-action-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: var(--transition);
}

.mobile-action-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Mobile Search Overlay */
.mobile-search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 2000;
    display: none;
    flex-direction: column;
}

.mobile-search-overlay.active {
    display: flex;
}

.search-header {
    display: flex;
    align-items: center;
    padding: 1rem;
    padding-top: calc(1rem + var(--safe-area-inset-top));
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    gap: 0.75rem;
}

.search-back {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.5rem;
}

.search-input-container {
    flex: 1;
    position: relative;
}

#mobileSearchInput {
    width: 100%;
    padding: 0.875rem 2.5rem 0.875rem 1rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 1rem;
}


.search-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.5rem;
}

.search-results-mobile {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Mobile Menu Overlay */
.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 5, 5, 0.95);
    backdrop-filter: blur(10px);
    z-index: 2001;
    display: none;
}

.mobile-menu-overlay.active {
    display: block;
}

.mobile-menu-content {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    padding: 1.5rem;
    padding-bottom: calc(1.5rem + var(--safe-area-inset-bottom));
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.menu-user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.menu-user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--accent-primary);
}

.menu-user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.menu-user-details {
    display: flex;
    flex-direction: column;
}

.menu-user-details strong {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.menu-user-details span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.menu-guest h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.menu-guest p {
    color: var(--text-secondary);
}

.menu-close {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

.menu-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 12px;
    transition: var(--transition);
    font-weight: 500;
}

.menu-item:active {
    background: rgba(255, 255, 255, 0.1);
}

.menu-icon {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

/* Stories Section */
.stories-container {
    padding: 1rem 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.stories-container::-webkit-scrollbar {
    display: none;
}

.stories-scroll {
    display: flex;
    gap: 1rem;
    padding: 0 0.5rem;
}

.story-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 70px;
    cursor: pointer;
}

.story-avatar {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--accent-primary);
    position: relative;
}

.story-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.add-icon {
    font-size: 1.5rem;
}

.story-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-align: center;
}

/* Mobile Posts Feed */
.posts-feed {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 0 0.5rem;
}

.post-card-mobile {
    background: var(--bg-card);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.post-header-mobile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
}

.post-user-avatar-mobile {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
}

.post-user-avatar-mobile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.post-user-info-mobile {
    flex: 1;
}

.post-username-mobile {
    font-weight: 600;
    font-size: 0.95rem;
}

.post-time-mobile {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.post-more-mobile {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem;
}

.post-image-mobile {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.post-actions-mobile {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 1rem;
}

.post-action-group {
    display: flex;
    gap: 1rem;
}

.post-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.25rem;
    transition: var(--transition);
}

.post-action-btn:active {
    transform: scale(1.1);
}

.post-action-btn.active {
    color: var(--accent-primary);
}

.post-stats-mobile {
    padding: 0 1rem 0.75rem;
}

.post-likes-mobile {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.post-title-mobile {
    font-weight: 600;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.post-description-mobile {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Mobile Optimized Modals */
@media (max-width: 768px) {
    .modal-content {
        width: 95vw;
        max-width: none;
        margin: 0;
        border-radius: 0;
        height: 100vh;
        max-height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        transform: none;
        animation: modalSlideUp 0.3s ease;
    }
    
    @keyframes modalSlideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
    
    .modal-close {
        top: 1rem;
        right: 1rem;
        background: rgba(0, 0, 0, 0.5);
        color: white;
    }
    
    .upload-area {
        padding: 3rem 1rem;
    }
    
    .upload-icon {
        font-size: 3rem;
    }
}

/* Touch Optimizations */
@media (hover: none) and (pointer: coarse) {
    .post-card:hover {
        transform: none;
    }
    
    .btn-primary:active,
    .btn-secondary:active,
    .btn-upload:active {
        transform: scale(0.98);
    }
    
    .nav-item:active {
        background: rgba(255, 255, 255, 0.1);
    }
    
    .post-action-btn:active {
        transform: scale(1.1);
    }
}

/* Android Specific Optimizations */
@media (max-width: 768px) {
    /* Improve scrolling performance */
    .posts-feed,
    .stories-container,
    .search-results-mobile {
        -webkit-overflow-scrolling: touch;
        transform: translateZ(0);
    }
    
    /* Optimize animations */
    .post-card-mobile {
        transform: translateZ(0);
        will-change: transform;
    }
    
    /* Better tap targets */
    .nav-item,
    .post-action-btn,
    .mobile-action-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Optimize images */
    .post-image-mobile {
        loading: lazy;
        decoding: async;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #050505;
        --bg-secondary: #111111;
        --bg-card: #151515;
    }
}

/* High contrast support */
@media (prefers-contrast: high) {
    :root {
        --text-secondary: #ffffff;
        --text-muted: #cccccc;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Tablet Optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    .bottom-nav {
        display: none;
    }
    
    .mobile-header {
        display: none;
    }
    
    .header {
        display: flex !important;
    }
    
    .main-content {
        padding-top: 0;
        padding-bottom: 0;
    }
}

/* Large Mobile Devices */
@media (min-width: 481px) and (max-width: 768px) {
    .posts-feed {
        padding: 0 1rem;
    }
    
    .stories-container {
        padding: 1rem;
    }
}

/* Small Mobile Devices */
@media (max-width: 360px) {
    .nav-label {
        font-size: 0.6rem;
    }
    
    .nav-icon {
        font-size: 1.2rem;
    }
    
    .mobile-header {
        padding: 0.5rem;
    }
    
    .posts-feed {
        padding: 0 0.25rem;
    }
}

/* فقط برای موبایل - در دسکتاپ نمایش داده نمی‌شود */
@media (max-width: 768px) {
    /* Bottom Navigation - فقط در موبایل */
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(17, 17, 17, 0.98);
        backdrop-filter: blur(20px) saturate(180%);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        display: flex;
        justify-content: space-around;
        align-items: center;
        padding: 0.5rem;
        padding-bottom: calc(0.5rem + var(--safe-area-inset-bottom));
        z-index: 1000;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    }

    /* Floating Action Button - فقط در موبایل */
    .fab {
        position: fixed;
        bottom: 100px;
        right: 16px;
        width: 56px;
        height: 56px;
        background: var(--accent-gradient);
        border: none;
        border-radius: 50%;
        cursor: pointer;
        box-shadow: 0 6px 25px rgba(0, 255, 136, 0.4);
        z-index: 999;
        transition: var(--transition);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.4rem;
    }

    /* Mobile Header - فقط در موبایل */
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: rgba(17, 17, 17, 0.95);
        backdrop-filter: blur(20px);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 1rem;
        padding-top: calc(0.75rem + var(--safe-area-inset-top));
        z-index: 1001;
        height: 60px;
    }

    /* در دسکتاپ هدر اصلی نمایش داده می‌شود */
    .header {
        display: none !important;
    }
    
    .main-content {
        padding-bottom: 80px;
        padding-top: 60px;
        min-height: calc(100vh - 140px);
    }
}

/* در دسکتاپ (768px به بالا) */
@media (min-width: 769px) {
    /* مخفی کردن عناصر موبایل در دسکتاپ */
    .bottom-nav,
    .fab,
    .mobile-header,
    .mobile-search-overlay,
    .mobile-menu-overlay {
        display: none !important;
    }
    
    /* نمایش هدر اصلی در دسکتاپ */
    .header {
        display: block !important;
    }
    
    .main-content {
        padding-top: 3rem;
        padding-bottom: 3rem;
        min-height: calc(100vh - 160px);
    }
}