/* ============================================
   📱 RESPONSIVE DESIGN - MOBILE OPTIMIZATION
   ============================================ */

/* === Tablets & Small Laptops (768px - 1024px) === */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }

    .content-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
        gap: 15px;
    }

    .profile-header {
        padding: 20px;
    }

    .modal-content {
        max-width: 90%;
        margin: 20px;
    }
}

/* === Mobile Devices (max-width: 768px) === */
@media (max-width: 768px) {
    :root {
        --header-height: 60px;
        --sidebar-width: 100%;
    }

    /* Header Adjustments */
    .header {
        height: var(--header-height);
        padding: 0 15px;
    }

    .logo {
        font-size: 1.2rem;
    }

    .logo img {
        width: 35px;
        height: 35px;
    }

    .header-actions {
        gap: 8px;
    }

    .header-actions .icon-btn {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }

    /* Sidebar Mobile - COMPLETELY HIDDEN */
    #sidebar {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }

    /* Sidebar Toggle Button - HIDDEN ON MOBILE */
    #sidebarToggle {
        display: none !important;
    }


    /* Overlay for sidebar */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.3);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        z-index: 9998;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }


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

    /* Main Content Mobile Reset */
    .app {
        padding-top: 0 !important;
    }

    .main-content {
        margin-left: 0 !important;
        margin-top: 5px !important;
        padding: 0 10px !important;
        min-height: auto !important;
    }

    #stories-container {
        padding: 10px 5px !important;
        margin-bottom: 5px !important;
        margin-top: 70px !important;
        background: transparent !important;
        border-radius: 0 !important;
    }

    /* Force Remove Welcome Section and Its Space */
    .welcome-section {
        display: none !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }

    /* Fixed Top Navbar height adjustment */
    .content-section {
        padding: 0 10px !important;
        /* تصفير البادنج العلوي للأقسام */
    }

    /* Publish Cards - 3 Column Grid */
    .publish-cards {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
        overflow: visible !important;
        padding: 0 5px 5px 5px !important;
        margin-bottom: 5px !important;
    }

    .publish-card {
        min-width: 0 !important;
        padding: 12px 5px !important;
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        border-radius: 12px !important;
        background: rgba(255, 255, 255, 0.05) !important;
        backdrop-filter: blur(40px) saturate(150%);
        -webkit-backdrop-filter: blur(40px) saturate(150%);
        border: 1px solid var(--glass-border) !important;
    }

    .publish-card .card-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.2rem !important;
        margin-bottom: 5px !important;
    }

    .publish-card h3 {
        font-size: 0.75rem !important;
        margin: 0 !important;
        white-space: nowrap;
    }

    .publish-card p,
    .publish-card .card-features {
        display: none !important;
        /* إخفاء الوصف والمميزات لتوفير مساحة */
    }

    /* Content filters optimization */
    .content-filters {
        padding: 0 !important;
        margin: 5px 0 10px 0 !important;
        justify-content: center !important;
    }

    .filter-main {
        gap: 5px !important;
        display: flex !important;
        justify-content: center !important;
        width: 100% !important;
    }

    .filter-btn {
        padding: 6px 12px !important;
        font-size: 0.7rem !important;
        border-radius: 20px !important;
        min-width: unset !important;
        min-height: auto !important;
        margin: 0 !important;
    }

    /* Content Grid */
    .content-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
        margin-top: 5px !important;
    }

    /* Cards */
    .content-card {
        margin-bottom: 15px;
    }

    .card-header {
        padding: 12px;
    }

    .card-body {
        padding: 12px;
    }

    .profile-header {
        display: flex;
        flex-direction: column;
        padding: 0;
        background: transparent;
        align-items: center;
        width: 100%;
    }

    .profile-cover {
        height: 140px !important;
        width: 100%;
        border-radius: 0 0 20px 20px;
    }

    .profile-info {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        margin-top: -40px !important;
        width: 95% !important;
        background: rgba(255, 255, 255, 0.05) !important;
        backdrop-filter: blur(40px) saturate(150%);
        -webkit-backdrop-filter: blur(40px) saturate(150%);
        padding: 15px !important;
        border-radius: 20px !important;
        border: 1px solid var(--glass-border) !important;
        z-index: 10;
        position: relative;
    }

    .profile-avatar {
        width: 90px !important;
        height: 90px !important;
        border: 4px solid var(--secondary) !important;
        background: var(--secondary);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
        margin-bottom: 10px !important;
    }

    .profile-details {
        text-align: center;
        width: 100%;
    }

    .profile-name {
        font-size: 1.5rem !important;
        margin-bottom: 5px !important;
        color: var(--primary) !important;
    }

    .profile-bio {
        font-size: 0.9rem !important;
        margin-bottom: 5px !important;
        opacity: 0.8;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        width: 100%;
    }

    /* شريط الإحصائيات - بسيط ومرتب */
    .header-stats-bar {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        /* شبكة 2x2 لتوفير المساحة */
        width: 95% !important;
        background: rgba(255, 255, 255, 0.05) !important;
        padding: 15px !important;
        border-radius: 20px !important;
        margin: 15px 0 !important;
        gap: 15px !important;
    }

    /* أزرار الإجراءات - واضحة وغير متداخلة */
    .profile-actions-row {
        display: flex !important;
        width: 100% !important;
        gap: 10px !important;
        margin-top: 25px !important;
        /* زيادة المسافة الفاصلة عن النبذة */
        position: relative;
        z-index: 5;
    }

    .profile-actions-row button,
    .profile-actions-row .purple-btn {
        flex: 1 !important;
        height: 44px !important;
        border-radius: 12px !important;
        font-size: 0.85rem !important;
        padding: 0 5px !important;
    }


    /* شريط الإحصائيات - صف واحد أنيق */
    .h-stat {
        flex: none !important;
        margin: 0 !important;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
    }

    .h-stat i {
        font-size: 0.8rem !important;
        color: var(--primary);
    }

    .h-stat span {
        font-size: 0.9rem !important;
        font-weight: bold;
    }

    .h-stat small {
        font-size: 0.6rem !important;
        opacity: 0.7;
    }

    /* الأزرار - صف واحد يملأ العرض */
    .profile-stats {
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        gap: 15px !important;
        margin-top: 10px !important;
    }

    .stat-item {
        min-width: 60px !important;
        text-align: center;
    }

    .stat-item .stat-value {
        font-size: 1.1rem !important;
    }

    .stat-item .stat-label {
        font-size: 0.7rem !important;
    }

    /* تصغير عرض التقييم */
    .rating-display {
        flex-direction: column;
        gap: 2px !important;
    }

    .rating-stars {
        font-size: 0.8rem !important;
    }

    .rating-value {
        font-size: 1rem !important;
    }

    .rating-count {
        font-size: 0.7rem !important;
    }

    /* Modals */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 10px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header {
        padding: 15px;
    }

    .modal-body {
        padding: 15px;
    }

    /* Forms */
    .form-group {
        margin-bottom: 15px;
    }

    .form-input,
    .form-textarea,
    .form-select {
        font-size: 16px;
        /* Prevents zoom on iOS */
    }

    /* Buttons */
    .btn,
    .primary-btn,
    .secondary-btn {
        padding: 12px 20px;
        font-size: 0.95rem;
    }

    /* Search Bar */
    .search-container {
        max-width: 100%;
    }

    .search-bar {
        width: 100%;
    }

    /* Notifications Dropdown */
    .notifications-dropdown {
        position: fixed !important;
        top: 65px !important;
        right: 15px !important;
        left: auto !important;
        width: 320px !important;
        max-width: calc(100vw - 30px) !important;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5) !important;
    }

    /* Chat Interface - Full Screen Mobile Layout */
    .direct-chat-window,
    .chat-window {
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-width: 100% !important;
        border-radius: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        transform: none !important;
        z-index: 2002 !important;
        display: none;
        /* Default hidden */
        flex-direction: column !important;
        /* Use flexbox to fill height */
        background: var(--bg-color) !important;
        padding-top: env(safe-area-inset-top, 0px) !important;
    }

    .direct-chat-window[style*="display: flex"],
    .chat-window[style*="display: block"] {
        display: flex !important;
    }

    .direct-chat-header,
    .chat-header {
        flex-shrink: 0 !important;
    }

    .direct-chat-messages,
    .chat-list {
        flex: 1 !important;
        /* This makes the messages area fill the middle */
        height: auto !important;
        /* Let flex control height */
        overflow-y: auto !important;
        padding: 15px !important;
    }

    .direct-chat-input {
        flex-shrink: 0 !important;
        padding-bottom: env(safe-area-inset-bottom, 15px) !important;
    }

    /* Store Page */
    .store-grid {
        grid-template-columns: 1fr !important;
    }

    .store-item {
        padding: 15px;
    }

    /* Auth Page */
    .auth-container {
        padding: 25px;
        margin: 15px;
    }

    .auth-header h1 {
        font-size: 1.5rem;
    }

    /* Content Details Modal */
    .content-detail-modal .modal-content {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    /* Adjust content sections for better mobile view */
    .content-section {
        padding-top: 5px;
        /* تقليل المسافة البادئة للأقسام */
    }

    /* Comments Section */
    .comments-section {
        padding: 12px;
    }

    .comment-item {
        padding: 10px;
    }

    /* User Menu */
    .user-menu {
        right: 10px;
        left: auto;
        width: calc(100vw - 20px);
        max-width: 300px;
    }

    /* Wallet Modal */
    .wallet-stats {
        grid-template-columns: 1fr !important;
    }

    /* Video Player (Ads) */
    #adModal .modal-content {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }

    #video-wrapper {
        aspect-ratio: 16/9;
    }

    /* Draggable Chat Button Mobile Optimization */
    .chat-toggle-center,
    #chatToggleCenter {
        display: flex !important;
        /* Ensure it is visible */
        bottom: 90px !important;
        /* رفع الزر قليلاً ليكون فوق شريط التنقل بوضوح */
        right: 15px !important;
        width: 50px !important;
        /* إعادة الحجم المناسب */
        height: 50px !important;
        font-size: 1.2rem !important;
        z-index: 10002 !important;
        box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4) !important;
        border-radius: 50%;
        background: var(--primary);
        color: white;
        align-items: center;
        justify-content: center;
        position: fixed;
    }
}

/* === Small Mobile Devices (max-width: 480px) === */
@media (max-width: 480px) {
    :root {
        --header-height: 55px;
    }

    .header {
        padding: 0 10px;
    }

    .logo {
        font-size: 1rem;
    }

    .logo img {
        width: 30px;
        height: 30px;
    }

    .header-actions .icon-btn {
        width: 35px;
        height: 35px;
        font-size: 0.9rem;
    }

    .main-content {
        padding: 10px;
    }

    .content-card {
        border-radius: 12px;
    }

    .card-header h3 {
        font-size: 1rem;
    }

    .profile-cover {
        height: 150px;
    }

    .profile-avatar {
        width: 80px;
        height: 80px;
    }

    .profile-name {
        font-size: 1.2rem;
    }

    .stat-item h4 {
        font-size: 1.2rem;
    }

    .stat-item p {
        font-size: 0.8rem;
    }

    .btn,
    .primary-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .modal-header h2 {
        font-size: 1.2rem;
    }

    #sidebarToggle {
        width: 50px;
        height: 50px;
        bottom: 15px;
        right: 15px;
    }

    /* Reduce padding for small screens */
    .auth-container {
        padding: 20px;
    }

    .form-input,
    .form-textarea {
        padding: 10px;
    }

    /* Store items */
    .store-item h3 {
        font-size: 1.1rem;
    }

    .store-item .price {
        font-size: 1.3rem;
    }
}

/* === Landscape Mobile (max-height: 500px) === */
@media (max-height: 500px) and (orientation: landscape) {
    .modal-content {
        max-height: 95vh;
        overflow-y: auto;
    }

    .direct-chat-window {
        height: 95vh;
    }

    .chat-messages {
        height: calc(95vh - 140px);
    }

    #sidebarToggle {
        bottom: 10px;
        right: 10px;
        width: 45px;
        height: 45px;
    }
}

/* === Touch Device Optimizations === */
@media (hover: none) and (pointer: coarse) {

    /* Increase touch targets */
    .icon-btn,
    .action-btn,
    button {
        min-width: 44px;
        min-height: 44px;
    }

    /* Remove hover effects on touch devices */
    .content-card:hover {
        transform: none;
    }

    /* Better tap feedback */
    .btn:active,
    .icon-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }
}

/* === Print Styles === */
@media print {

    .header,
    #sidebar,
    #sidebarToggle,
    .floating-chat-btn,
    .notifications-dropdown,
    .user-menu {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .content-card {
        break-inside: avoid;
    }
}

.chat-open .bottom-navigation {
    display: none !important;
}