/* ============ Mobile Responsiveness Fixes ============ */

/* Global Mobile Adjustments */
@media (max-width: 1024px) {
    .container {
        padding: 0 var(--space-md);
    }
}

/* TABLET ONLY (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .dashboard-layout {
        display: grid;
        grid-template-columns: 240px 1fr;
        gap: var(--space-lg);
    }
}

/* MOBILE (< 768px) - CRITICAL FIX FOR COLUMN STACKING */
@media (max-width: 767px) {

    /* Force Stack Layout - Override any grids */
    .dashboard-layout {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
        grid-template-columns: 1fr !important;
        /* Safety */
    }

    /* Sidebar full width */
    .dashboard-sidebar {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        position: static !important;
        padding: 15px;
        margin-bottom: 10px;
        box-sizing: border-box;
    }

    /* Navbar Tweaks */
    .nav-container {
        padding: 10px;
        flex-wrap: wrap;
    }

    .logo {
        font-size: 1.1rem;
    }

    .nav-links {
        display: none !important;
    }

    .nav-right {
        gap: 10px;
    }

    .profile-avatar-large {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }

    /* Horizontal Scroll Sidebar Nav */
    .sidebar-nav {
        display: flex;
        overflow-x: auto;
        padding-bottom: 10px;
        gap: 10px;
        scroll-snap-type: x mandatory;
        width: 100%;
        /* Full width */
    }

    .nav-item {
        flex: 0 0 auto;
        border: 1px solid var(--border);
        white-space: nowrap;
        scroll-snap-align: start;
        padding: 8px 16px;
    }

    .dashboard-content {
        width: 100% !important;
        min-width: 100% !important;
    }

    /* Grid Stacking */
    .dashboard-grid {
        display: flex !important;
        /* Stack grids */
        flex-direction: column !important;
        gap: 15px !important;
    }

    .listings-grid,
    .info-grid,
    .steps-container {
        grid-template-columns: 1fr !important;
        display: grid;
    }

    /* Listing Cards - Full Width */
    .listing-card {
        width: 100% !important;
        box-sizing: border-box;
    }

    .steps-container {
        gap: 30px;
    }

    /* Card Adjustments */
    .intro-card {
        flex-direction: column;
        text-align: center;
        padding: 20px;
    }

    .intro-image {
        margin-top: 20px;
        display: flex;
        justify-content: center;
    }

    .intro-title {
        font-size: 1.5rem;
    }

    /* Listing Rows (Dashboard) */
    .listing-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .listing-row-thumb {
        width: 50px;
        height: 50px;
    }

    .listing-info {
        width: 100%;
    }

    .listing-actions {
        width: 100%;
        justify-content: space-between;
        margin-top: 10px;
    }

    .listing-actions .btn {
        flex: 1;
    }

    /* Matches Rows */
    .match-row {
        flex-direction: column;
        align-items: stretch;
        padding: 15px;
    }

    .match-thumb {
        width: 50px;
        height: 50px;
        margin-bottom: 10px;
    }

    .match-info h4 {
        font-size: 1rem;
    }

    .match-meta span {
        font-size: 0.8rem;
    }

    .match-actions {
        flex-direction: column;
        width: 100%;
    }

    .match-actions button {
        width: 100%;
        margin-top: 5px;
    }

    /* Detail Page Mobile */
    .detail-hero {
        padding: 15px;
        border-radius: var(--radius-lg);
    }

    .hero-title {
        font-size: 1.5rem;
    }

    .hero-stats-row {
        grid-template-columns: 1fr 1fr;
        gap: 15px;
        padding: 15px;
    }

    .route-visual {
        flex-direction: column;
        align-items: center;
        gap: 30px;
        padding: 20px 0;
    }

    .route-line {
        width: 2px;
        height: 100%;
        left: 50%;
        top: 0;
        transform: translateX(-50%);
        background: repeating-linear-gradient(to bottom, var(--border) 0, var(--border) 10px, transparent 10px, transparent 20px);
    }

    .route-line::after {
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%) rotate(90deg);
    }

    .owner-card-premium {
        position: static;
        margin-top: 20px;
        padding: 20px;
    }

    /* ===== NAV RIGHT CHANGES FOR MOBILE ===== */

    /* Hide + Post button on mobile */
    .nav-right #quickActionBlock {
        display: none !important;
    }

    /* Show Auth Block on mobile (for Bell) */
    .nav-right #authBlock {
        display: block !important;
    }

    /* But hide the "User Profile / Login" part inside Auth Block */
    .nav-right #authBlock .user-profile-header,
    .nav-right #authBlock .btn {
        display: none !important;
    }

    /* Ensure Notification Bell is visible */
    .nav-right #authBlock .notification-bell {
        display: flex !important;
        margin-right: 5px;
    }

    /* Adjust notification dropdown for mobile */
    #notif-dropdown {
        position: fixed !important;
        top: 60px !important;
        right: 10px !important;
        width: 300px !important;
        max-width: 90vw !important;
    }

    /* Ensure Bottom Nav is Visible */
    .mobile-bottom-nav {
        display: flex;
        z-index: 9999;
    }

    /* Adjust main content padding for bottom nav */
    main.main-content {
        padding-bottom: 70px;
    }

    /* ============ Admin Dashboard Mobile ============ */
    .admin-container {
        padding: 1rem;
    }

    .admin-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .admin-tabs {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 5px;
        margin-bottom: 1.5rem;
        -webkit-overflow-scrolling: touch;
    }

    .admin-tab {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    /* Make tables scrollable horizontally */
    .admin-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
    }

    .admin-table {
        min-width: 600px;
    }

    /* Adjust stats grid for very small screens */
    .stats-grid,
    .stats-grid-compact {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Chat & Modals */
    #messages-tab>div {
        flex-direction: column;
        height: calc(100vh - 200px);
    }

    #messages-tab>div>div:first-child {
        width: 100%;
        height: 150px;
        min-height: 150px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .modal-content {
        width: 95%;
        margin: 10px;
        padding: 1.5rem;
        max-height: 90vh;
        overflow-y: auto;
    }

    .auth-card {
        padding: 1.5rem;
    }
}

/* Extra small devices */
@media (max-width: 380px) {
    .hero-stats-row {
        grid-template-columns: 1fr;
    }
}

/* ============ PROFILE PAGE FIXES (Single Column Stack) ============ */
@media (max-width: 900px) {

    /* Force 1-column layout on Profile Page */
    .profile-page .container>div[style*="grid"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 24px !important;
        width: 100% !important;
    }

    .profile-page div[style*="sticky"] {
        position: static !important;
        width: 100% !important;
    }

    .profile-page .container {
        margin-top: 60px !important;
    }

    .profile-page #avatarInitial {
        font-size: 2rem !important;
    }
}