Advanced responsive Markdown table design enables sophisticated documentation systems that adapt seamlessly across all device types, screen sizes, and user contexts while maintaining data accessibility and visual clarity. By implementing comprehensive responsive design strategies, CSS Grid integration, and adaptive layout techniques, technical writers can create table-based documentation that delivers optimal user experiences regardless of viewport constraints, ensuring that complex data remains comprehensible and actionable across desktop, tablet, and mobile environments.

Why Master Responsive Markdown Table Design?

Professional responsive table design provides essential benefits for modern documentation:

  • Universal Accessibility: Ensure table data remains readable and functional across all devices and screen sizes
  • User Experience Optimization: Provide intuitive interaction patterns that adapt to touch and mouse interfaces
  • Data Integrity: Maintain information hierarchy and relationships even in constrained viewport environments
  • Performance Enhancement: Implement efficient rendering strategies that minimize load times and improve responsiveness
  • Future-Proof Design: Create table systems that adapt to emerging devices and interaction paradigms

Foundation Responsive Table Architecture

Basic Responsive Table Patterns

Understanding fundamental responsive design approaches for Markdown tables:

# Basic Responsive Table Implementation

## Standard Markdown Table

| Product | Price | Category | Availability | Rating | Description |
|---------|-------|----------|--------------|--------|-------------|
| MacBook Pro | $2,399 | Laptop | In Stock | 4.5/5 | High-performance laptop with M2 chip |
| iPad Air | $599 | Tablet | In Stock | 4.3/5 | Versatile tablet for productivity and creativity |
| AirPods Pro | $249 | Audio | Limited Stock | 4.4/5 | Premium wireless earbuds with noise cancellation |
| iPhone 14 | $799 | Phone | In Stock | 4.2/5 | Latest smartphone with advanced camera system |

## Responsive Enhancement with CSS Classes

<div class="responsive-table-container">
<div class="table-scroll-wrapper">

| Product | Price | Category | Availability | Rating | Description |
|---------|-------|----------|--------------|--------|-------------|
| MacBook Pro | $2,399 | Laptop | In Stock | 4.5/5 | High-performance laptop with M2 chip |
| iPad Air | $599 | Tablet | In Stock | 4.3/5 | Versatile tablet for productivity and creativity |
| AirPods Pro | $249 | Audio | Limited Stock | 4.4/5 | Premium wireless earbuds with noise cancellation |
| iPhone 14 | $799 | Phone | In Stock | 4.2/5 | Latest smartphone with advanced camera system |

</div>
</div>

## Mobile-Optimized Card Layout Alternative

<div class="table-cards-mobile">
<div class="table-card">
  <h3>MacBook Pro</h3>
  <p><strong>Price:</strong> $2,399</p>
  <p><strong>Category:</strong> Laptop</p>
  <p><strong>Availability:</strong> In Stock</p>
  <p><strong>Rating:</strong> 4.5/5</p>
  <p><strong>Description:</strong> High-performance laptop with M2 chip</p>
</div>
</div>

Comprehensive Responsive Table System

Creating a complete responsive table management system:

/* responsive-tables.css - Complete responsive table system */

/* Base table styles */
.responsive-table-container {
    width: 100%;
    margin: 1.5rem 0;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    background: #ffffff;
    position: relative;
}

.responsive-table-container table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
    line-height: 1.5;
}

.responsive-table-container th,
.responsive-table-container td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid #e5e5e5;
    vertical-align: top;
}

.responsive-table-container th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: #2c3e50;
    position: sticky;
    top: 0;
    z-index: 10;
}

.responsive-table-container tbody tr:hover {
    background-color: #f8f9fa;
}

.responsive-table-container tbody tr:last-child td {
    border-bottom: none;
}

/* Horizontal scroll wrapper for wide tables */
.table-scroll-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    width: 100%;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 #f7fafc;
}

.table-scroll-wrapper::-webkit-scrollbar {
    height: 8px;
}

.table-scroll-wrapper::-webkit-scrollbar-track {
    background: #f7fafc;
    border-radius: 4px;
}

.table-scroll-wrapper::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.table-scroll-wrapper::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Responsive breakpoints */
@media screen and (max-width: 1200px) {
    .responsive-table-container {
        font-size: 13px;
    }
    
    .responsive-table-container th,
    .responsive-table-container td {
        padding: 10px 12px;
    }
}

@media screen and (max-width: 768px) {
    /* Mobile-first responsive approach */
    .responsive-table-container.mobile-stack table,
    .responsive-table-container.mobile-stack thead,
    .responsive-table-container.mobile-stack tbody,
    .responsive-table-container.mobile-stack th,
    .responsive-table-container.mobile-stack td,
    .responsive-table-container.mobile-stack tr {
        display: block;
    }
    
    .responsive-table-container.mobile-stack thead {
        position: absolute;
        top: -9999px;
        left: -9999px;
        clip: rect(0 0 0 0);
        height: 1px;
        width: 1px;
        overflow: hidden;
    }
    
    .responsive-table-container.mobile-stack tbody tr {
        border: 1px solid #e5e5e5;
        border-radius: 8px;
        margin-bottom: 16px;
        padding: 16px;
        background: #ffffff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }
    
    .responsive-table-container.mobile-stack td {
        border: none;
        border-bottom: 1px solid #f0f0f0;
        position: relative;
        padding: 8px 0 8px 50%;
        margin: 0;
        min-height: 24px;
    }
    
    .responsive-table-container.mobile-stack td:before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: 600;
        color: #2c3e50;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .responsive-table-container.mobile-stack td:last-child {
        border-bottom: none;
    }
}

/* Alternative card-based mobile layout */
.table-cards-mobile {
    display: none;
}

@media screen and (max-width: 768px) {
    .responsive-table-container.mobile-cards {
        display: none;
    }
    
    .table-cards-mobile {
        display: grid;
        grid-template-columns: 1fr;
        gap: 16px;
        margin: 1.5rem 0;
    }
    
    .table-card {
        background: #ffffff;
        border: 1px solid #e5e5e5;
        border-radius: 12px;
        padding: 20px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        transition: box-shadow 0.2s ease;
    }
    
    .table-card:hover {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    }
    
    .table-card h3 {
        margin: 0 0 12px 0;
        font-size: 18px;
        font-weight: 600;
        color: #2c3e50;
    }
    
    .table-card p {
        margin: 8px 0;
        font-size: 14px;
        line-height: 1.4;
    }
    
    .table-card p strong {
        display: inline-block;
        width: 100px;
        font-weight: 600;
        color: #555;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
}

/* Advanced responsive patterns */

/* Horizontal scroll indicator */
.responsive-table-container:before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(to left, rgba(255,255,255,1), rgba(255,255,255,0));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 5;
}

.responsive-table-container.has-horizontal-scroll:before {
    opacity: 1;
}

/* Column priority system */
.col-priority-1 { display: table-cell; }
.col-priority-2 { display: table-cell; }
.col-priority-3 { display: table-cell; }

@media screen and (max-width: 1200px) {
    .col-priority-3 { display: none; }
}

@media screen and (max-width: 768px) {
    .col-priority-2 { display: none; }
}

@media screen and (max-width: 480px) {
    .col-priority-1 { 
        font-size: 12px;
        padding: 8px 6px;
    }
}

/* Grid-based responsive layout */
.responsive-table-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 1.5rem 0;
}

@media screen and (max-width: 768px) {
    .responsive-table-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* Accessible table enhancements */
.responsive-table-container[role="table"] {
    outline: none;
}

.responsive-table-container th {
    cursor: pointer;
    user-select: none;
    position: relative;
}

.responsive-table-container th:hover {
    background-color: #e9ecef;
}

.responsive-table-container th.sortable:after {
    content: "⇅";
    position: absolute;
    right: 8px;
    opacity: 0.3;
    font-size: 10px;
}

.responsive-table-container th.sort-asc:after {
    content: "↑";
    opacity: 1;
}

.responsive-table-container th.sort-desc:after {
    content: "↓";
    opacity: 1;
}

/* Loading and empty states */
.responsive-table-container.loading {
    position: relative;
}

.responsive-table-container.loading:after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

.table-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-style: italic;
}

/* Print styles */
@media print {
    .responsive-table-container {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .table-scroll-wrapper {
        overflow: visible;
    }
    
    .responsive-table-container th {
        background: #f0f0f0 !important;
        -webkit-print-color-adjust: exact;
        color-adjust: exact;
    }
    
    .table-cards-mobile {
        display: none;
    }
    
    .responsive-table-container.mobile-stack table,
    .responsive-table-container.mobile-stack thead,
    .responsive-table-container.mobile-stack tbody,
    .responsive-table-container.mobile-stack th,
    .responsive-table-container.mobile-stack td,
    .responsive-table-container.mobile-stack tr {
        display: table;
        display: table-header-group;
        display: table-row-group;
        display: table-cell;
        display: table-row;
    }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .responsive-table-container {
        background: #1a1a1a;
        color: #e0e0e0;
    }
    
    .responsive-table-container th {
        background-color: #2d2d2d;
        color: #ffffff;
    }
    
    .responsive-table-container th,
    .responsive-table-container td {
        border-bottom-color: #404040;
    }
    
    .responsive-table-container tbody tr:hover {
        background-color: #2d2d2d;
    }
    
    .table-card {
        background: #1a1a1a;
        border-color: #404040;
        color: #e0e0e0;
    }
    
    .table-card h3 {
        color: #ffffff;
    }
}

JavaScript Enhancement System

Advanced JavaScript functionality for responsive table behavior:

// responsive-table-manager.js - Comprehensive responsive table system
class ResponsiveTableManager {
    constructor(options = {}) {
        this.options = {
            breakpoints: {
                mobile: 768,
                tablet: 1024,
                desktop: 1200
            },
            enableSorting: true,
            enableFiltering: true,
            enableColumnToggle: true,
            enableExport: true,
            autoInitialize: true,
            ...options
        };
        
        this.tables = new Map();
        this.resizeObserver = null;
        this.currentBreakpoint = this.getCurrentBreakpoint();
        
        if (this.options.autoInitialize) {
            this.initialize();
        }
    }
    
    initialize() {
        console.log('Initializing responsive table manager...');
        
        // Find and enhance all tables
        this.discoverTables();
        
        // Set up responsive monitoring
        this.setupResponsiveMonitoring();
        
        // Set up event listeners
        this.setupEventListeners();
        
        console.log(`Enhanced ${this.tables.size} tables`);
    }
    
    discoverTables() {
        const tableContainers = document.querySelectorAll('.responsive-table-container');
        
        tableContainers.forEach((container, index) => {
            const table = container.querySelector('table');
            if (table) {
                const tableId = container.id || `responsive-table-${index}`;
                container.id = tableId;
                
                this.enhanceTable(tableId, container, table);
            }
        });
    }
    
    enhanceTable(tableId, container, table) {
        console.log(`Enhancing table: ${tableId}`);
        
        const tableData = {
            id: tableId,
            container,
            table,
            originalHTML: table.outerHTML,
            headers: this.extractHeaders(table),
            rows: this.extractRows(table),
            currentLayout: 'desktop',
            sortState: { column: null, direction: null },
            filters: new Map(),
            hiddenColumns: new Set()
        };
        
        // Add data attributes for mobile layout
        this.addDataLabels(table, tableData.headers);
        
        // Enhance table functionality
        if (this.options.enableSorting) {
            this.addSortingCapability(tableData);
        }
        
        if (this.options.enableFiltering) {
            this.addFilteringCapability(tableData);
        }
        
        if (this.options.enableColumnToggle) {
            this.addColumnToggleCapability(tableData);
        }
        
        if (this.options.enableExport) {
            this.addExportCapability(tableData);
        }
        
        // Set up responsive behavior
        this.setupResponsiveBehavior(tableData);
        
        this.tables.set(tableId, tableData);
        
        // Trigger initial layout
        this.updateTableLayout(tableData);
    }
    
    extractHeaders(table) {
        const headerRow = table.querySelector('thead tr, tr:first-child');
        if (!headerRow) return [];
        
        return Array.from(headerRow.children).map((cell, index) => ({
            index,
            text: cell.textContent.trim(),
            element: cell,
            sortable: !cell.classList.contains('no-sort'),
            priority: this.getColumnPriority(cell),
            type: this.detectColumnType(table, index)
        }));
    }
    
    extractRows(table) {
        const tbody = table.querySelector('tbody') || table;
        const rows = tbody.querySelectorAll('tr');
        
        // Skip header row if no tbody
        const startIndex = table.querySelector('tbody') ? 0 : 1;
        
        return Array.from(rows).slice(startIndex).map((row, index) => ({
            index: index + startIndex,
            element: row,
            cells: Array.from(row.children).map(cell => ({
                element: cell,
                value: cell.textContent.trim(),
                html: cell.innerHTML
            }))
        }));
    }
    
    addDataLabels(table, headers) {
        const rows = table.querySelectorAll('tbody tr, tr:not(:first-child)');
        
        rows.forEach(row => {
            const cells = row.children;
            Array.from(cells).forEach((cell, index) => {
                if (headers[index]) {
                    cell.setAttribute('data-label', headers[index].text);
                }
            });
        });
    }
    
    getColumnPriority(cell) {
        if (cell.classList.contains('col-priority-1')) return 1;
        if (cell.classList.contains('col-priority-2')) return 2;
        if (cell.classList.contains('col-priority-3')) return 3;
        return 2; // Default priority
    }
    
    detectColumnType(table, columnIndex) {
        const cells = table.querySelectorAll(`tbody td:nth-child(${columnIndex + 1}), tr:not(:first-child) td:nth-child(${columnIndex + 1})`);
        
        if (cells.length === 0) return 'string';
        
        let hasNumbers = 0;
        let hasDates = 0;
        
        Array.from(cells).slice(0, 5).forEach(cell => {
            const text = cell.textContent.trim();
            
            if (/^\d+(\.\d+)?$/.test(text) || /^\$[\d,]+(\.\d{2})?$/.test(text)) {
                hasNumbers++;
            } else if (Date.parse(text) && /\d{4}/.test(text)) {
                hasDates++;
            }
        });
        
        if (hasNumbers >= 3) return 'number';
        if (hasDates >= 3) return 'date';
        return 'string';
    }
    
    setupResponsiveMonitoring() {
        // Monitor viewport changes
        window.addEventListener('resize', this.debounce(() => {
            const newBreakpoint = this.getCurrentBreakpoint();
            if (newBreakpoint !== this.currentBreakpoint) {
                this.currentBreakpoint = newBreakpoint;
                this.handleBreakpointChange();
            }
        }, 250));
        
        // Monitor table container size changes
        if ('ResizeObserver' in window) {
            this.resizeObserver = new ResizeObserver(entries => {
                entries.forEach(entry => {
                    const container = entry.target;
                    const tableId = container.id;
                    const tableData = this.tables.get(tableId);
                    
                    if (tableData) {
                        this.updateScrollIndicators(tableData);
                    }
                });
            });
            
            this.tables.forEach(tableData => {
                this.resizeObserver.observe(tableData.container);
            });
        }
    }
    
    getCurrentBreakpoint() {
        const width = window.innerWidth;
        
        if (width <= this.options.breakpoints.mobile) return 'mobile';
        if (width <= this.options.breakpoints.tablet) return 'tablet';
        return 'desktop';
    }
    
    handleBreakpointChange() {
        console.log(`Breakpoint changed to: ${this.currentBreakpoint}`);
        
        this.tables.forEach(tableData => {
            this.updateTableLayout(tableData);
        });
    }
    
    updateTableLayout(tableData) {
        const { container, table } = tableData;
        const breakpoint = this.currentBreakpoint;
        
        // Remove existing responsive classes
        container.classList.remove('mobile-stack', 'mobile-cards', 'tablet-optimized');
        
        // Apply appropriate layout based on breakpoint
        switch (breakpoint) {
            case 'mobile':
                if (container.dataset.mobileLayout === 'cards') {
                    this.switchToCardLayout(tableData);
                } else {
                    container.classList.add('mobile-stack');
                    this.switchToStackLayout(tableData);
                }
                break;
                
            case 'tablet':
                container.classList.add('tablet-optimized');
                this.applyColumnPriorities(tableData);
                break;
                
            default:
                this.showAllColumns(tableData);
                break;
        }
        
        // Update scroll indicators
        this.updateScrollIndicators(tableData);
        
        // Update toolbar if exists
        this.updateToolbar(tableData);
        
        tableData.currentLayout = breakpoint;
    }
    
    switchToStackLayout(tableData) {
        const { table } = tableData;
        
        // Ensure data labels are present
        this.addDataLabels(table, tableData.headers);
        
        // Update table structure for stacking
        const rows = table.querySelectorAll('tbody tr, tr:not(:first-child)');
        rows.forEach(row => {
            row.classList.add('stacked-row');
        });
    }
    
    switchToCardLayout(tableData) {
        const { container, table } = tableData;
        
        // Create card container if it doesn't exist
        let cardContainer = container.querySelector('.table-cards-mobile');
        if (!cardContainer) {
            cardContainer = document.createElement('div');
            cardContainer.className = 'table-cards-mobile';
            container.appendChild(cardContainer);
        }
        
        // Clear existing cards
        cardContainer.innerHTML = '';
        
        // Generate cards from table data
        tableData.rows.forEach(row => {
            const card = this.createCardFromRow(row, tableData.headers);
            cardContainer.appendChild(card);
        });
        
        // Hide original table
        table.style.display = 'none';
    }
    
    createCardFromRow(row, headers) {
        const card = document.createElement('div');
        card.className = 'table-card';
        
        // Use first column as card title
        const titleCell = row.cells[0];
        if (titleCell) {
            const title = document.createElement('h3');
            title.textContent = titleCell.value;
            card.appendChild(title);
        }
        
        // Add other columns as key-value pairs
        row.cells.slice(1).forEach((cell, index) => {
            const headerIndex = index + 1;
            const header = headers[headerIndex];
            
            if (header && cell.value) {
                const field = document.createElement('p');
                field.innerHTML = `<strong>${header.text}:</strong> ${cell.html}`;
                card.appendChild(field);
            }
        });
        
        return card;
    }
    
    applyColumnPriorities(tableData) {
        const { table } = tableData;
        const breakpoint = this.currentBreakpoint;
        
        tableData.headers.forEach((header, index) => {
            const cells = table.querySelectorAll(`td:nth-child(${index + 1}), th:nth-child(${index + 1})`);
            
            // Hide low priority columns on smaller screens
            const shouldHide = (
                (breakpoint === 'tablet' && header.priority > 2) ||
                (breakpoint === 'mobile' && header.priority > 1)
            );
            
            cells.forEach(cell => {
                cell.style.display = shouldHide ? 'none' : '';
            });
            
            if (shouldHide) {
                tableData.hiddenColumns.add(index);
            } else {
                tableData.hiddenColumns.delete(index);
            }
        });
    }
    
    showAllColumns(tableData) {
        const { table } = tableData;
        
        // Show all columns
        const allCells = table.querySelectorAll('td, th');
        allCells.forEach(cell => {
            cell.style.display = '';
        });
        
        tableData.hiddenColumns.clear();
    }
    
    updateScrollIndicators(tableData) {
        const { container } = tableData;
        const scrollWrapper = container.querySelector('.table-scroll-wrapper');
        
        if (!scrollWrapper) return;
        
        const hasHorizontalScroll = scrollWrapper.scrollWidth > scrollWrapper.clientWidth;
        
        if (hasHorizontalScroll) {
            container.classList.add('has-horizontal-scroll');
        } else {
            container.classList.remove('has-horizontal-scroll');
        }
    }
    
    addSortingCapability(tableData) {
        const { table, headers } = tableData;
        
        headers.forEach((header, index) => {
            if (header.sortable) {
                header.element.classList.add('sortable');
                header.element.addEventListener('click', () => {
                    this.sortTable(tableData, index);
                });
            }
        });
    }
    
    sortTable(tableData, columnIndex) {
        const { table, headers, sortState } = tableData;
        const header = headers[columnIndex];
        
        // Determine sort direction
        let direction = 'asc';
        if (sortState.column === columnIndex) {
            direction = sortState.direction === 'asc' ? 'desc' : 'asc';
        }
        
        // Update sort state
        tableData.sortState = { column: columnIndex, direction };
        
        // Update header classes
        headers.forEach((h, i) => {
            h.element.classList.remove('sort-asc', 'sort-desc');
            if (i === columnIndex) {
                h.element.classList.add(`sort-${direction}`);
            }
        });
        
        // Sort table rows
        const tbody = table.querySelector('tbody') || table;
        const rows = Array.from(tbody.querySelectorAll('tr'));
        
        // Skip header row if no tbody
        const dataRows = table.querySelector('tbody') ? rows : rows.slice(1);
        
        dataRows.sort((a, b) => {
            const aCell = a.children[columnIndex];
            const bCell = b.children[columnIndex];
            
            if (!aCell || !bCell) return 0;
            
            let aValue = aCell.textContent.trim();
            let bValue = bCell.textContent.trim();
            
            // Type-specific comparison
            if (header.type === 'number') {
                aValue = parseFloat(aValue.replace(/[^\d.-]/g, '')) || 0;
                bValue = parseFloat(bValue.replace(/[^\d.-]/g, '')) || 0;
                return direction === 'asc' ? aValue - bValue : bValue - aValue;
            } else if (header.type === 'date') {
                aValue = new Date(aValue).getTime() || 0;
                bValue = new Date(bValue).getTime() || 0;
                return direction === 'asc' ? aValue - bValue : bValue - aValue;
            } else {
                // String comparison
                const result = aValue.localeCompare(bValue);
                return direction === 'asc' ? result : -result;
            }
        });
        
        // Reorder rows in DOM
        dataRows.forEach(row => tbody.appendChild(row));
        
        // Update row data
        this.updateRowData(tableData);
        
        // Dispatch custom event
        this.dispatchTableEvent(tableData, 'sort', {
            column: columnIndex,
            direction,
            header: header.text
        });
    }
    
    updateRowData(tableData) {
        tableData.rows = this.extractRows(tableData.table);
    }
    
    addFilteringCapability(tableData) {
        // Create filter toolbar
        const toolbar = this.createFilterToolbar(tableData);
        tableData.container.insertBefore(toolbar, tableData.table.parentElement);
    }
    
    createFilterToolbar(tableData) {
        const toolbar = document.createElement('div');
        toolbar.className = 'table-toolbar';
        
        // Search input
        const searchContainer = document.createElement('div');
        searchContainer.className = 'table-search';
        
        const searchInput = document.createElement('input');
        searchInput.type = 'search';
        searchInput.placeholder = 'Search table...';
        searchInput.className = 'table-search-input';
        
        searchInput.addEventListener('input', this.debounce(() => {
            this.filterTable(tableData, searchInput.value);
        }, 300));
        
        searchContainer.appendChild(searchInput);
        toolbar.appendChild(searchContainer);
        
        return toolbar;
    }
    
    filterTable(tableData, searchTerm) {
        const { table } = tableData;
        const rows = table.querySelectorAll('tbody tr, tr:not(:first-child)');
        
        const term = searchTerm.toLowerCase().trim();
        
        rows.forEach(row => {
            if (!term) {
                row.style.display = '';
                return;
            }
            
            const text = row.textContent.toLowerCase();
            const matches = text.includes(term);
            
            row.style.display = matches ? '' : 'none';
        });
        
        // Dispatch filter event
        this.dispatchTableEvent(tableData, 'filter', { searchTerm });
    }
    
    addColumnToggleCapability(tableData) {
        // Add column toggle controls to toolbar
        let toolbar = tableData.container.querySelector('.table-toolbar');
        if (!toolbar) {
            toolbar = document.createElement('div');
            toolbar.className = 'table-toolbar';
            tableData.container.insertBefore(toolbar, tableData.table.parentElement);
        }
        
        const columnToggle = this.createColumnToggle(tableData);
        toolbar.appendChild(columnToggle);
    }
    
    createColumnToggle(tableData) {
        const toggle = document.createElement('div');
        toggle.className = 'column-toggle';
        
        const button = document.createElement('button');
        button.textContent = 'Columns';
        button.className = 'column-toggle-button';
        
        const dropdown = document.createElement('div');
        dropdown.className = 'column-toggle-dropdown';
        
        tableData.headers.forEach((header, index) => {
            const label = document.createElement('label');
            label.className = 'column-toggle-item';
            
            const checkbox = document.createElement('input');
            checkbox.type = 'checkbox';
            checkbox.checked = !tableData.hiddenColumns.has(index);
            checkbox.addEventListener('change', () => {
                this.toggleColumn(tableData, index, checkbox.checked);
            });
            
            label.appendChild(checkbox);
            label.appendChild(document.createTextNode(header.text));
            dropdown.appendChild(label);
        });
        
        button.addEventListener('click', () => {
            dropdown.classList.toggle('active');
        });
        
        toggle.appendChild(button);
        toggle.appendChild(dropdown);
        
        return toggle;
    }
    
    toggleColumn(tableData, columnIndex, show) {
        const { table } = tableData;
        const cells = table.querySelectorAll(`td:nth-child(${columnIndex + 1}), th:nth-child(${columnIndex + 1})`);
        
        cells.forEach(cell => {
            cell.style.display = show ? '' : 'none';
        });
        
        if (show) {
            tableData.hiddenColumns.delete(columnIndex);
        } else {
            tableData.hiddenColumns.add(columnIndex);
        }
        
        // Update scroll indicators
        this.updateScrollIndicators(tableData);
    }
    
    addExportCapability(tableData) {
        let toolbar = tableData.container.querySelector('.table-toolbar');
        if (!toolbar) {
            toolbar = document.createElement('div');
            toolbar.className = 'table-toolbar';
            tableData.container.insertBefore(toolbar, tableData.table.parentElement);
        }
        
        const exportButton = document.createElement('button');
        exportButton.textContent = 'Export';
        exportButton.className = 'export-button';
        exportButton.addEventListener('click', () => {
            this.showExportOptions(tableData);
        });
        
        toolbar.appendChild(exportButton);
    }
    
    showExportOptions(tableData) {
        const options = [
            { label: 'CSV', action: () => this.exportCSV(tableData) },
            { label: 'JSON', action: () => this.exportJSON(tableData) },
            { label: 'Print', action: () => this.printTable(tableData) }
        ];
        
        // Simple modal for export options
        const modal = this.createModal('Export Options', options);
        document.body.appendChild(modal);
    }
    
    exportCSV(tableData) {
        const { headers, rows } = tableData;
        
        // Filter visible columns
        const visibleHeaders = headers.filter((_, index) => !tableData.hiddenColumns.has(index));
        const visibleColumnIndices = visibleHeaders.map(h => h.index);
        
        let csv = visibleHeaders.map(h => `"${h.text}"`).join(',') + '\n';
        
        rows.forEach(row => {
            const csvRow = visibleColumnIndices
                .map(index => `"${row.cells[index]?.value || ''}"`)
                .join(',');
            csv += csvRow + '\n';
        });
        
        this.downloadFile(csv, 'table-export.csv', 'text/csv');
    }
    
    exportJSON(tableData) {
        const { headers, rows } = tableData;
        
        const visibleHeaders = headers.filter((_, index) => !tableData.hiddenColumns.has(index));
        
        const jsonData = rows.map(row => {
            const rowData = {};
            visibleHeaders.forEach(header => {
                const cell = row.cells[header.index];
                rowData[header.text] = cell ? cell.value : '';
            });
            return rowData;
        });
        
        const json = JSON.stringify(jsonData, null, 2);
        this.downloadFile(json, 'table-export.json', 'application/json');
    }
    
    printTable(tableData) {
        const printWindow = window.open('', '_blank');
        const { table, headers } = tableData;
        
        const printHTML = `
            <!DOCTYPE html>
            <html>
            <head>
                <title>Table Export</title>
                <style>
                    body { font-family: Arial, sans-serif; margin: 20px; }
                    table { border-collapse: collapse; width: 100%; }
                    th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
                    th { background-color: #f2f2f2; font-weight: bold; }
                </style>
            </head>
            <body>
                <h1>Table Export</h1>
                ${table.outerHTML}
            </body>
            </html>
        `;
        
        printWindow.document.write(printHTML);
        printWindow.document.close();
        printWindow.print();
    }
    
    downloadFile(content, filename, mimeType) {
        const blob = new Blob([content], { type: mimeType });
        const url = URL.createObjectURL(blob);
        
        const link = document.createElement('a');
        link.href = url;
        link.download = filename;
        
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        
        URL.revokeObjectURL(url);
    }
    
    setupEventListeners() {
        // Handle clicks outside dropdowns
        document.addEventListener('click', (e) => {
            if (!e.target.closest('.column-toggle')) {
                document.querySelectorAll('.column-toggle-dropdown.active').forEach(dropdown => {
                    dropdown.classList.remove('active');
                });
            }
        });
    }
    
    updateToolbar(tableData) {
        const toolbar = tableData.container.querySelector('.table-toolbar');
        if (!toolbar) return;
        
        // Update toolbar visibility based on layout
        const breakpoint = this.currentBreakpoint;
        
        if (breakpoint === 'mobile') {
            toolbar.classList.add('mobile-layout');
        } else {
            toolbar.classList.remove('mobile-layout');
        }
    }
    
    createModal(title, options) {
        const overlay = document.createElement('div');
        overlay.className = 'modal-overlay';
        overlay.style.cssText = `
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.5); display: flex; align-items: center;
            justify-content: center; z-index: 10000;
        `;
        
        const modal = document.createElement('div');
        modal.className = 'modal';
        modal.style.cssText = `
            background: white; padding: 20px; border-radius: 8px;
            min-width: 200px; max-width: 400px;
        `;
        
        const titleElement = document.createElement('h3');
        titleElement.textContent = title;
        titleElement.style.marginTop = '0';
        modal.appendChild(titleElement);
        
        options.forEach(option => {
            const button = document.createElement('button');
            button.textContent = option.label;
            button.style.cssText = `
                display: block; width: 100%; padding: 10px;
                margin: 5px 0; border: 1px solid #ddd;
                background: white; cursor: pointer;
            `;
            button.addEventListener('click', () => {
                option.action();
                document.body.removeChild(overlay);
            });
            modal.appendChild(button);
        });
        
        const closeButton = document.createElement('button');
        closeButton.textContent = 'Cancel';
        closeButton.style.cssText = `
            display: block; width: 100%; padding: 10px;
            margin: 10px 0 0 0; border: 1px solid #ccc;
            background: #f8f9fa; cursor: pointer;
        `;
        closeButton.addEventListener('click', () => {
            document.body.removeChild(overlay);
        });
        modal.appendChild(closeButton);
        
        overlay.appendChild(modal);
        
        // Close on overlay click
        overlay.addEventListener('click', (e) => {
            if (e.target === overlay) {
                document.body.removeChild(overlay);
            }
        });
        
        return overlay;
    }
    
    dispatchTableEvent(tableData, eventType, detail) {
        const event = new CustomEvent(`table-${eventType}`, {
            detail: { tableId: tableData.id, ...detail }
        });
        
        tableData.container.dispatchEvent(event);
    }
    
    debounce(func, wait) {
        let timeout;
        return function executedFunction(...args) {
            const later = () => {
                clearTimeout(timeout);
                func(...args);
            };
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
        };
    }
    
    // Public API methods
    getTable(tableId) {
        return this.tables.get(tableId);
    }
    
    refreshTable(tableId) {
        const tableData = this.tables.get(tableId);
        if (tableData) {
            this.updateRowData(tableData);
            this.updateTableLayout(tableData);
        }
    }
    
    exportTable(tableId, format = 'csv') {
        const tableData = this.tables.get(tableId);
        if (!tableData) return;
        
        switch (format.toLowerCase()) {
            case 'csv':
                this.exportCSV(tableData);
                break;
            case 'json':
                this.exportJSON(tableData);
                break;
            default:
                console.warn(`Unsupported export format: ${format}`);
        }
    }
    
    destroy() {
        if (this.resizeObserver) {
            this.resizeObserver.disconnect();
        }
        
        this.tables.clear();
        console.log('Responsive table manager destroyed');
    }
}

// Auto-initialize on DOM ready
if (typeof window !== 'undefined') {
    document.addEventListener('DOMContentLoaded', () => {
        window.responsiveTableManager = new ResponsiveTableManager();
    });
}

module.exports = ResponsiveTableManager;

Advanced Mobile Optimization Techniques

Touch-Friendly Table Interactions

Optimizing table interactions for mobile and touch devices:

/* touch-optimized-tables.css - Touch-friendly table enhancements */

/* Touch target sizing */
.responsive-table-container th,
.responsive-table-container td {
    min-height: 44px; /* iOS minimum touch target */
    position: relative;
}

/* Touch-friendly sorting controls */
.responsive-table-container th.sortable {
    padding-right: 40px;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    tap-highlight-color: rgba(0, 0, 0, 0.1);
}

.responsive-table-container th.sortable:after {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Swipe gesture support */
.table-row-swipeable {
    position: relative;
    overflow: hidden;
}

.table-row-swipeable .swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    background: #e74c3c;
    color: white;
    display: flex;
    align-items: center;
    padding: 0 20px;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.table-row-swipeable.swiped .swipe-actions {
    transform: translateX(0);
}

/* Mobile-optimized table controls */
.table-controls-mobile {
    display: none;
    position: sticky;
    top: 0;
    background: white;
    z-index: 5;
    padding: 10px;
    border-bottom: 1px solid #e5e5e5;
}

@media screen and (max-width: 768px) {
    .table-controls-mobile {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .table-controls-mobile button {
        padding: 8px 16px;
        border: 1px solid #ddd;
        background: white;
        border-radius: 6px;
        font-size: 14px;
        cursor: pointer;
        touch-action: manipulation;
    }
    
    .table-controls-mobile button:active {
        background: #f0f0f0;
        transform: scale(0.98);
    }
}

/* Optimized mobile card interactions */
.table-card {
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.table-card:active {
    transform: scale(0.98);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Pull-to-refresh indicator */
.table-refresh-indicator {
    display: none;
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 14px;
}

.table-refreshing .table-refresh-indicator {
    display: block;
}

/* Loading states optimized for mobile */
@media screen and (max-width: 768px) {
    .responsive-table-container.loading:after {
        content: "Loading...";
        background: rgba(255, 255, 255, 0.95);
        color: #666;
        font-size: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
    }
    
    .responsive-table-container.loading:after:before {
        content: "";
        width: 30px;
        height: 30px;
        border: 3px solid #f3f3f3;
        border-top: 3px solid #3498db;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin-bottom: 10px;
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Accessibility enhancements for touch */
.responsive-table-container:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

.responsive-table-container th:focus,
.responsive-table-container td:focus {
    outline: 2px solid #3498db;
    outline-offset: -2px;
    background-color: rgba(52, 152, 219, 0.1);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .responsive-table-container {
        border: 2px solid;
    }
    
    .responsive-table-container th,
    .responsive-table-container td {
        border: 1px solid;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .responsive-table-container,
    .responsive-table-container * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

Progressive Enhancement Strategies

Implementing progressive enhancement for optimal performance:

// progressive-table-enhancement.js - Progressive enhancement system
class ProgressiveTableEnhancement {
    constructor() {
        this.features = {
            intersectionObserver: 'IntersectionObserver' in window,
            resizeObserver: 'ResizeObserver' in window,
            customElements: 'customElements' in window,
            cssGrid: this.supportsCSSGrid(),
            touchEvents: 'ontouchstart' in window,
            gestureEvents: 'GestureEvent' in window
        };
        
        this.loadStrategies = new Map();
        this.initialized = false;
    }
    
    supportsCSSGrid() {
        return typeof document !== 'undefined' && 
               CSS && CSS.supports && 
               CSS.supports('display', 'grid');
    }
    
    async initialize() {
        if (this.initialized) return;
        
        console.log('Initializing progressive table enhancement...');
        console.log('Supported features:', this.features);
        
        // Load core functionality first
        await this.loadCoreFeatures();
        
        // Load enhanced features based on capability
        await this.loadEnhancedFeatures();
        
        // Set up lazy loading for advanced features
        this.setupLazyLoading();
        
        this.initialized = true;
        console.log('Progressive enhancement complete');
    }
    
    async loadCoreFeatures() {
        // Always load basic responsive functionality
        this.enhanceBasicTables();
        
        // Add touch optimization if supported
        if (this.features.touchEvents) {
            this.addTouchOptimizations();
        }
    }
    
    async loadEnhancedFeatures() {
        // Load sorting if JavaScript is fully supported
        if (this.supportsAdvancedJS()) {
            await this.loadSortingModule();
        }
        
        // Load virtual scrolling for large datasets
        if (this.features.intersectionObserver && this.detectLargeTables()) {
            await this.loadVirtualScrolling();
        }
        
        // Load advanced responsive features
        if (this.features.resizeObserver) {
            await this.loadAdvancedResponsive();
        }
    }
    
    enhanceBasicTables() {
        const tables = document.querySelectorAll('table:not(.enhanced)');
        
        tables.forEach(table => {
            // Wrap tables for responsive behavior
            this.wrapTableForResponsive(table);
            
            // Add basic mobile optimizations
            this.addBasicMobileOptimizations(table);
            
            // Mark as enhanced
            table.classList.add('enhanced');
        });
    }
    
    wrapTableForResponsive(table) {
        if (table.closest('.responsive-table-container')) return;
        
        const container = document.createElement('div');
        container.className = 'responsive-table-container';
        
        const scrollWrapper = document.createElement('div');
        scrollWrapper.className = 'table-scroll-wrapper';
        
        // Move table into wrapper structure
        table.parentNode.insertBefore(container, table);
        container.appendChild(scrollWrapper);
        scrollWrapper.appendChild(table);
        
        // Add basic scroll detection
        this.addScrollDetection(container, scrollWrapper);
    }
    
    addScrollDetection(container, scrollWrapper) {
        let scrollTimeout;
        
        scrollWrapper.addEventListener('scroll', () => {
            container.classList.add('scrolling');
            
            clearTimeout(scrollTimeout);
            scrollTimeout = setTimeout(() => {
                container.classList.remove('scrolling');
            }, 150);
            
            // Update scroll indicators
            this.updateBasicScrollIndicators(container, scrollWrapper);
        });
    }
    
    updateBasicScrollIndicators(container, scrollWrapper) {
        const isScrolledToStart = scrollWrapper.scrollLeft <= 0;
        const isScrolledToEnd = 
            scrollWrapper.scrollLeft >= scrollWrapper.scrollWidth - scrollWrapper.clientWidth - 1;
        
        container.classList.toggle('scrolled-to-start', isScrolledToStart);
        container.classList.toggle('scrolled-to-end', isScrolledToEnd);
    }
    
    addBasicMobileOptimizations(table) {
        // Add data labels for mobile stacking
        const headers = table.querySelectorAll('th');
        const rows = table.querySelectorAll('tbody tr');
        
        rows.forEach(row => {
            const cells = row.querySelectorAll('td');
            cells.forEach((cell, index) => {
                const header = headers[index];
                if (header) {
                    cell.setAttribute('data-label', header.textContent.trim());
                }
            });
        });
        
        // Add mobile class detection
        this.addMobileClassDetection(table);
    }
    
    addMobileClassDetection(table) {
        const checkMobile = () => {
            const isMobile = window.innerWidth <= 768;
            const container = table.closest('.responsive-table-container');
            
            if (container) {
                container.classList.toggle('mobile-layout', isMobile);
            }
        };
        
        checkMobile();
        window.addEventListener('resize', this.debounce(checkMobile, 250));
    }
    
    addTouchOptimizations() {
        // Add touch-specific CSS class
        document.body.classList.add('touch-enabled');
        
        // Optimize touch targets
        this.optimizeTouchTargets();
        
        // Add touch gestures if supported
        if (this.features.gestureEvents) {
            this.addGestureSupport();
        }
    }
    
    optimizeTouchTargets() {
        const style = document.createElement('style');
        style.textContent = `
            .touch-enabled .responsive-table-container th,
            .touch-enabled .responsive-table-container td {
                min-height: 44px;
                padding: 12px 16px;
            }
            
            .touch-enabled .table-toolbar button {
                min-height: 44px;
                min-width: 44px;
                padding: 8px 16px;
            }
        `;
        document.head.appendChild(style);
    }
    
    addGestureSupport() {
        document.addEventListener('gesturestart', (e) => {
            e.preventDefault();
        });
        
        // Add swipe detection for mobile tables
        this.addSwipeDetection();
    }
    
    addSwipeDetection() {
        let startX, startY, currentX, currentY;
        
        document.addEventListener('touchstart', (e) => {
            const touch = e.touches[0];
            startX = touch.clientX;
            startY = touch.clientY;
        }, { passive: true });
        
        document.addEventListener('touchmove', (e) => {
            if (!startX || !startY) return;
            
            const touch = e.touches[0];
            currentX = touch.clientX;
            currentY = touch.clientY;
        }, { passive: true });
        
        document.addEventListener('touchend', (e) => {
            if (!startX || !startY || !currentX || !currentY) return;
            
            const diffX = startX - currentX;
            const diffY = startY - currentY;
            
            // Check if it's a horizontal swipe
            if (Math.abs(diffX) > Math.abs(diffY) && Math.abs(diffX) > 50) {
                const target = e.target.closest('.table-card, tbody tr');
                if (target) {
                    this.handleSwipeGesture(target, diffX > 0 ? 'left' : 'right');
                }
            }
            
            // Reset values
            startX = startY = currentX = currentY = null;
        }, { passive: true });
    }
    
    handleSwipeGesture(element, direction) {
        // Dispatch custom swipe event
        const swipeEvent = new CustomEvent('tableSwipe', {
            detail: { element, direction },
            bubbles: true
        });
        element.dispatchEvent(swipeEvent);
    }
    
    supportsAdvancedJS() {
        try {
            return (
                typeof Map !== 'undefined' &&
                typeof Set !== 'undefined' &&
                typeof Promise !== 'undefined' &&
                Array.prototype.includes &&
                Object.assign
            );
        } catch (e) {
            return false;
        }
    }
    
    detectLargeTables() {
        const tables = document.querySelectorAll('table');
        return Array.from(tables).some(table => {
            const rows = table.querySelectorAll('tr');
            return rows.length > 100;
        });
    }
    
    async loadSortingModule() {
        // Dynamically load sorting functionality
        if (!window.TableSorter) {
            try {
                const module = await import('./table-sorter.js');
                window.TableSorter = module.default;
            } catch (error) {
                console.warn('Failed to load sorting module:', error);
                return;
            }
        }
        
        // Initialize sorting on enhanced tables
        const tables = document.querySelectorAll('.enhanced table');
        tables.forEach(table => {
            new window.TableSorter(table);
        });
    }
    
    async loadVirtualScrolling() {
        if (!window.VirtualTableScroller) {
            try {
                const module = await import('./virtual-table-scroller.js');
                window.VirtualTableScroller = module.default;
                
                // Apply to large tables
                this.applyVirtualScrolling();
            } catch (error) {
                console.warn('Failed to load virtual scrolling:', error);
            }
        }
    }
    
    applyVirtualScrolling() {
        const largeTables = document.querySelectorAll('table');
        
        largeTables.forEach(table => {
            const rows = table.querySelectorAll('tbody tr');
            if (rows.length > 100) {
                new window.VirtualTableScroller(table, {
                    itemHeight: 44,
                    bufferSize: 10
                });
            }
        });
    }
    
    async loadAdvancedResponsive() {
        // Initialize advanced responsive features
        this.setupAdvancedBreakpointDetection();
        this.setupContainerQueries();
    }
    
    setupAdvancedBreakpointDetection() {
        if (!this.features.resizeObserver) return;
        
        const observer = new ResizeObserver(entries => {
            entries.forEach(entry => {
                const container = entry.target;
                const width = entry.contentRect.width;
                
                // Apply size-based classes
                container.classList.toggle('container-small', width < 400);
                container.classList.toggle('container-medium', width >= 400 && width < 800);
                container.classList.toggle('container-large', width >= 800);
                
                // Trigger custom resize event
                const resizeEvent = new CustomEvent('containerResize', {
                    detail: { width, height: entry.contentRect.height }
                });
                container.dispatchEvent(resizeEvent);
            });
        });
        
        // Observe all table containers
        document.querySelectorAll('.responsive-table-container').forEach(container => {
            observer.observe(container);
        });
    }
    
    setupContainerQueries() {
        // Polyfill container queries using ResizeObserver
        const style = document.createElement('style');
        style.textContent = `
            .container-small .responsive-table-container table {
                font-size: 12px;
            }
            
            .container-small .responsive-table-container th,
            .container-small .responsive-table-container td {
                padding: 6px 8px;
            }
            
            .container-medium .responsive-table-container {
                /* Medium container styles */
            }
            
            .container-large .responsive-table-container {
                /* Large container styles */
            }
        `;
        document.head.appendChild(style);
    }
    
    setupLazyLoading() {
        if (!this.features.intersectionObserver) return;
        
        // Set up lazy loading for tables that are not in viewport
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                if (entry.isIntersecting) {
                    const container = entry.target;
                    this.loadTableEnhancements(container);
                    observer.unobserve(container);
                }
            });
        }, {
            rootMargin: '50px'
        });
        
        // Observe tables that haven't been enhanced yet
        document.querySelectorAll('.responsive-table-container:not(.fully-enhanced)').forEach(container => {
            observer.observe(container);
        });
    }
    
    loadTableEnhancements(container) {
        // Load additional features for visible tables
        const table = container.querySelector('table');
        if (!table) return;
        
        // Add advanced sorting
        this.addAdvancedSorting(table);
        
        // Add filtering
        this.addFiltering(container);
        
        // Add export functionality
        this.addExport(container);
        
        // Mark as fully enhanced
        container.classList.add('fully-enhanced');
    }
    
    addAdvancedSorting(table) {
        // Implementation for advanced sorting features
        const headers = table.querySelectorAll('th');
        headers.forEach((header, index) => {
            if (!header.classList.contains('no-sort')) {
                header.classList.add('sortable');
                header.setAttribute('tabindex', '0');
                header.setAttribute('role', 'button');
                header.setAttribute('aria-label', `Sort by ${header.textContent}`);
            }
        });
    }
    
    addFiltering(container) {
        // Add search functionality
        const searchContainer = document.createElement('div');
        searchContainer.className = 'table-search-container';
        
        const searchInput = document.createElement('input');
        searchInput.type = 'search';
        searchInput.placeholder = 'Search table...';
        searchInput.className = 'table-search-input';
        
        searchContainer.appendChild(searchInput);
        container.insertBefore(searchContainer, container.firstChild);
        
        // Add search functionality
        this.setupTableSearch(searchInput, container);
    }
    
    setupTableSearch(searchInput, container) {
        const table = container.querySelector('table');
        const rows = Array.from(table.querySelectorAll('tbody tr'));
        
        searchInput.addEventListener('input', this.debounce((e) => {
            const term = e.target.value.toLowerCase().trim();
            
            rows.forEach(row => {
                const text = row.textContent.toLowerCase();
                const matches = !term || text.includes(term);
                row.style.display = matches ? '' : 'none';
            });
            
            // Update row count indicator
            this.updateRowCount(container, rows, term);
        }, 300));
    }
    
    updateRowCount(container, rows, searchTerm) {
        let indicator = container.querySelector('.row-count-indicator');
        if (!indicator) {
            indicator = document.createElement('div');
            indicator.className = 'row-count-indicator';
            container.appendChild(indicator);
        }
        
        if (searchTerm) {
            const visibleRows = rows.filter(row => row.style.display !== 'none');
            indicator.textContent = `Showing ${visibleRows.length} of ${rows.length} rows`;
            indicator.style.display = 'block';
        } else {
            indicator.style.display = 'none';
        }
    }
    
    addExport(container) {
        // Add export button
        const exportButton = document.createElement('button');
        exportButton.textContent = '↓ Export';
        exportButton.className = 'table-export-button';
        exportButton.addEventListener('click', () => {
            this.showExportModal(container);
        });
        
        let toolbar = container.querySelector('.table-search-container');
        if (!toolbar) {
            toolbar = document.createElement('div');
            toolbar.className = 'table-toolbar';
            container.insertBefore(toolbar, container.firstChild);
        }
        
        toolbar.appendChild(exportButton);
    }
    
    showExportModal(container) {
        // Simple export functionality
        const table = container.querySelector('table');
        const csv = this.tableToCSV(table);
        
        const blob = new Blob([csv], { type: 'text/csv' });
        const url = URL.createObjectURL(blob);
        
        const link = document.createElement('a');
        link.href = url;
        link.download = 'table-export.csv';
        link.click();
        
        URL.revokeObjectURL(url);
    }
    
    tableToCSV(table) {
        const rows = Array.from(table.querySelectorAll('tr'));
        
        return rows.map(row => {
            const cells = Array.from(row.querySelectorAll('th, td'));
            return cells.map(cell => {
                const text = cell.textContent.trim();
                // Escape commas and quotes
                return text.includes(',') || text.includes('"') 
                    ? `"${text.replace(/"/g, '""')}"` 
                    : text;
            }).join(',');
        }).join('\n');
    }
    
    debounce(func, wait) {
        let timeout;
        return function executedFunction(...args) {
            const later = () => {
                clearTimeout(timeout);
                func(...args);
            };
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
        };
    }
    
    // Public API
    enhanceTable(table) {
        if (table.classList.contains('enhanced')) return;
        
        this.wrapTableForResponsive(table);
        this.addBasicMobileOptimizations(table);
        table.classList.add('enhanced');
        
        // Load full enhancements if in viewport
        const container = table.closest('.responsive-table-container');
        if (this.isInViewport(container)) {
            this.loadTableEnhancements(container);
        }
    }
    
    isInViewport(element) {
        const rect = element.getBoundingClientRect();
        return (
            rect.top >= 0 &&
            rect.left >= 0 &&
            rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
            rect.right <= (window.innerWidth || document.documentElement.clientWidth)
        );
    }
}

// Initialize progressive enhancement
if (typeof window !== 'undefined') {
    const progressiveEnhancement = new ProgressiveTableEnhancement();
    
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', () => {
            progressiveEnhancement.initialize();
        });
    } else {
        progressiveEnhancement.initialize();
    }
    
    // Expose to global scope
    window.progressiveTableEnhancement = progressiveEnhancement;
}

Integration with Documentation Systems

Responsive table design integrates seamlessly with modern documentation workflows. When combined with automated content management systems and version control, responsive tables maintain their adaptive behavior across different deployment environments while ensuring that data presentations remain consistent and accessible throughout content lifecycle management processes.

For comprehensive table management, responsive design works effectively with advanced table styling and formatting systems to create cohesive data presentation architectures that adapt visual styling based on viewport constraints while preserving data hierarchy and maintaining professional appearance standards across all device categories and user contexts.

When building sophisticated documentation platforms, responsive tables complement interactive table features and user engagement systems by ensuring that sorting, filtering, and data manipulation capabilities remain functional and accessible across mobile and desktop environments, providing consistent user experiences regardless of device limitations or interaction paradigms.

Performance Optimization Strategies

Efficient Responsive Table Loading

// performance-optimized-tables.js - Performance optimization techniques
class PerformanceOptimizedTables {
    constructor() {
        this.loadStrategies = {
            eager: new Set(),
            lazy: new Set(),
            deferred: new Set()
        };
        
        this.performanceObserver = null;
        this.setupPerformanceMonitoring();
    }
    
    setupPerformanceMonitoring() {
        if ('PerformanceObserver' in window) {
            this.performanceObserver = new PerformanceObserver((list) => {
                const entries = list.getEntries();
                entries.forEach(entry => {
                    if (entry.entryType === 'measure' && entry.name.startsWith('table-')) {
                        console.log(`Table performance: ${entry.name} took ${entry.duration}ms`);
                    }
                });
            });
            
            this.performanceObserver.observe({ entryTypes: ['measure'] });
        }
    }
    
    optimizeTableLoading(table) {
        performance.mark('table-optimization-start');
        
        const rowCount = table.querySelectorAll('tr').length;
        const complexity = this.assessTableComplexity(table);
        
        // Determine loading strategy based on size and complexity
        if (rowCount > 100 || complexity.score > 0.7) {
            this.implementVirtualScrolling(table);
        } else if (rowCount > 50 || complexity.score > 0.5) {
            this.implementProgressiveLoading(table);
        } else {
            this.implementEagerLoading(table);
        }
        
        performance.mark('table-optimization-end');
        performance.measure('table-optimization', 'table-optimization-start', 'table-optimization-end');
    }
    
    assessTableComplexity(table) {
        const factors = {
            rowCount: table.querySelectorAll('tr').length,
            columnCount: table.querySelectorAll('th').length,
            hasImages: table.querySelectorAll('img').length > 0,
            hasComplexContent: table.innerHTML.length > 50000,
            hasInteractiveElements: table.querySelectorAll('button, input, select').length > 0
        };
        
        let score = 0;
        
        // Weight different complexity factors
        score += Math.min(factors.rowCount / 100, 0.4);  // Up to 40% for row count
        score += Math.min(factors.columnCount / 10, 0.2);  // Up to 20% for column count
        score += factors.hasImages ? 0.15 : 0;  // 15% if has images
        score += factors.hasComplexContent ? 0.15 : 0;  // 15% if complex content
        score += factors.hasInteractiveElements ? 0.1 : 0;  // 10% if interactive
        
        return { score, factors };
    }
    
    implementEagerLoading(table) {
        // For simple tables, load everything immediately with optimizations
        this.addCSSOptimizations(table);
        this.optimizeDOM(table);
    }
    
    implementProgressiveLoading(table) {
        // Load visible rows first, then remaining rows
        const visibleRows = this.getVisibleRows(table);
        const remainingRows = Array.from(table.querySelectorAll('tr')).slice(visibleRows.length);
        
        // Hide non-visible rows initially
        remainingRows.forEach(row => {
            row.style.display = 'none';
            row.classList.add('deferred-row');
        });
        
        // Load remaining rows progressively
        this.loadRowsProgressively(remainingRows);
    }
    
    implementVirtualScrolling(table) {
        // Implement virtual scrolling for very large tables
        const container = table.closest('.responsive-table-container');
        if (!container) return;
        
        const virtualScroller = new VirtualTableScroller(table, {
            itemHeight: 44,
            bufferSize: 10,
            renderItem: (row, index) => this.renderTableRow(row, index)
        });
        
        container.appendChild(virtualScroller.element);
    }
    
    getVisibleRows(table) {
        const containerHeight = window.innerHeight;
        const rowHeight = 44; // Estimated row height
        const visibleRowCount = Math.ceil(containerHeight / rowHeight) + 5; // Buffer
        
        return Array.from(table.querySelectorAll('tr')).slice(0, visibleRowCount);
    }
    
    loadRowsProgressively(rows) {
        let index = 0;
        const batchSize = 10;
        
        const loadBatch = () => {
            const batch = rows.slice(index, index + batchSize);
            
            batch.forEach(row => {
                row.style.display = '';
                row.classList.remove('deferred-row');
            });
            
            index += batchSize;
            
            if (index < rows.length) {
                // Use requestIdleCallback if available, otherwise setTimeout
                if ('requestIdleCallback' in window) {
                    requestIdleCallback(loadBatch, { timeout: 1000 });
                } else {
                    setTimeout(loadBatch, 16);
                }
            }
        };
        
        // Start loading after a short delay
        setTimeout(loadBatch, 100);
    }
    
    addCSSOptimizations(table) {
        // Add CSS optimizations for better performance
        const style = document.createElement('style');
        style.textContent = `
            /* Performance optimizations */
            .optimized-table {
                contain: layout style paint;
                will-change: transform;
            }
            
            .optimized-table tr {
                contain: layout style;
            }
            
            .optimized-table td,
            .optimized-table th {
                contain: layout;
            }
            
            /* GPU acceleration for smooth scrolling */
            .table-scroll-wrapper {
                transform: translateZ(0);
                -webkit-overflow-scrolling: touch;
            }
            
            /* Optimize repaints */
            .responsive-table-container.scrolling * {
                pointer-events: none;
            }
        `;
        document.head.appendChild(style);
        
        table.classList.add('optimized-table');
    }
    
    optimizeDOM(table) {
        // Remove unnecessary whitespace and optimize DOM structure
        const walker = document.createTreeWalker(
            table,
            NodeFilter.SHOW_TEXT,
            {
                acceptNode: (node) => {
                    // Remove empty text nodes
                    return node.textContent.trim() === '' 
                        ? NodeFilter.FILTER_REJECT 
                        : NodeFilter.FILTER_ACCEPT;
                }
            }
        );
        
        const emptyTextNodes = [];
        let node;
        
        while (node = walker.nextNode()) {
            if (node.textContent.trim() === '') {
                emptyTextNodes.push(node);
            }
        }
        
        emptyTextNodes.forEach(node => node.remove());
    }
    
    // Memory management for large tables
    setupMemoryManagement(table) {
        const observer = new IntersectionObserver((entries) => {
            entries.forEach(entry => {
                const row = entry.target;
                
                if (!entry.isIntersecting) {
                    // Row is out of view, can optimize
                    this.dehydrateRow(row);
                } else {
                    // Row is in view, ensure it's hydrated
                    this.hydrateRow(row);
                }
            });
        }, {
            rootMargin: '100px'  // Start loading 100px before visible
        });
        
        // Observe all table rows
        table.querySelectorAll('tr').forEach(row => {
            observer.observe(row);
        });
    }
    
    dehydrateRow(row) {
        // Store complex content and replace with placeholders
        if (row.dataset.hydrated === 'true') {
            const cells = row.querySelectorAll('td');
            cells.forEach(cell => {
                const images = cell.querySelectorAll('img');
                images.forEach(img => {
                    if (!img.dataset.dehydrated) {
                        img.dataset.originalSrc = img.src;
                        img.src = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9IiNjY2MiLz48L3N2Zz4=';
                        img.dataset.dehydrated = 'true';
                    }
                });
            });
            
            row.dataset.hydrated = 'false';
        }
    }
    
    hydrateRow(row) {
        // Restore complex content from placeholders
        if (row.dataset.hydrated !== 'true') {
            const cells = row.querySelectorAll('td');
            cells.forEach(cell => {
                const images = cell.querySelectorAll('img[data-dehydrated="true"]');
                images.forEach(img => {
                    if (img.dataset.originalSrc) {
                        img.src = img.dataset.originalSrc;
                        img.removeAttribute('data-dehydrated');
                        delete img.dataset.originalSrc;
                    }
                });
            });
            
            row.dataset.hydrated = 'true';
        }
    }
}

// Virtual scrolling implementation
class VirtualTableScroller {
    constructor(table, options = {}) {
        this.table = table;
        this.options = {
            itemHeight: 44,
            bufferSize: 10,
            ...options
        };
        
        this.rows = Array.from(table.querySelectorAll('tbody tr'));
        this.visibleStart = 0;
        this.visibleEnd = 0;
        
        this.setupVirtualScrolling();
    }
    
    setupVirtualScrolling() {
        // Create virtual scroll container
        this.container = document.createElement('div');
        this.container.className = 'virtual-table-scroller';
        this.container.style.cssText = `
            height: 400px;
            overflow-y: auto;
            position: relative;
        `;
        
        // Create spacer elements
        this.topSpacer = document.createElement('div');
        this.bottomSpacer = document.createElement('div');
        
        this.viewport = document.createElement('div');
        this.viewport.className = 'virtual-viewport';
        
        // Setup structure
        this.container.appendChild(this.topSpacer);
        this.container.appendChild(this.viewport);
        this.container.appendChild(this.bottomSpacer);
        
        // Move table into viewport
        this.viewport.appendChild(this.table);
        
        // Setup event listeners
        this.container.addEventListener('scroll', () => {
            this.updateVisibleRange();
        });
        
        // Initial render
        this.updateVisibleRange();
        
        this.element = this.container;
    }
    
    updateVisibleRange() {
        const scrollTop = this.container.scrollTop;
        const containerHeight = this.container.clientHeight;
        
        // Calculate visible range
        this.visibleStart = Math.max(0, 
            Math.floor(scrollTop / this.options.itemHeight) - this.options.bufferSize
        );
        this.visibleEnd = Math.min(this.rows.length,
            Math.ceil((scrollTop + containerHeight) / this.options.itemHeight) + this.options.bufferSize
        );
        
        // Update spacers
        this.topSpacer.style.height = `${this.visibleStart * this.options.itemHeight}px`;
        this.bottomSpacer.style.height = `${(this.rows.length - this.visibleEnd) * this.options.itemHeight}px`;
        
        // Update visible rows
        this.renderVisibleRows();
    }
    
    renderVisibleRows() {
        const tbody = this.table.querySelector('tbody');
        
        // Clear current rows
        while (tbody.firstChild) {
            tbody.removeChild(tbody.firstChild);
        }
        
        // Render visible rows
        for (let i = this.visibleStart; i < this.visibleEnd; i++) {
            if (this.rows[i]) {
                tbody.appendChild(this.rows[i].cloneNode(true));
            }
        }
    }
}

// Initialize performance optimizations
if (typeof window !== 'undefined') {
    document.addEventListener('DOMContentLoaded', () => {
        const optimizer = new PerformanceOptimizedTables();
        
        // Optimize all existing tables
        document.querySelectorAll('table').forEach(table => {
            optimizer.optimizeTableLoading(table);
        });
        
        window.performanceOptimizedTables = optimizer;
    });
}

Accessibility and Responsive Design

WCAG-Compliant Responsive Tables

/* accessible-responsive-tables.css - WCAG 2.1 AA compliant styles */

/* High contrast support */
@media (prefers-contrast: high) {
    .responsive-table-container {
        border: 2px solid CanvasText;
        background: Canvas;
        color: CanvasText;
    }
    
    .responsive-table-container th {
        background: ButtonFace;
        border: 1px solid ButtonText;
    }
    
    .responsive-table-container td {
        border: 1px solid ButtonText;
    }
    
    .responsive-table-container tbody tr:hover {
        background: Highlight;
        color: HighlightText;
    }
}

/* Forced colors mode (Windows High Contrast) */
@media (forced-colors: active) {
    .responsive-table-container {
        forced-color-adjust: none;
        border: 1px solid;
    }
    
    .responsive-table-container th,
    .responsive-table-container td {
        border: 1px solid;
    }
}

/* Focus management */
.responsive-table-container table:focus {
    outline: 3px solid Highlight;
    outline-offset: 2px;
}

.responsive-table-container th:focus,
.responsive-table-container td:focus {
    outline: 2px solid Highlight;
    outline-offset: -2px;
    position: relative;
    z-index: 1;
}

/* Screen reader improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Mobile accessibility enhancements */
@media screen and (max-width: 768px) {
    .responsive-table-container.mobile-stack table {
        caption-side: top;
    }
    
    .responsive-table-container.mobile-stack caption {
        font-weight: bold;
        font-size: 1.2em;
        margin-bottom: 16px;
        text-align: left;
    }
    
    .responsive-table-container.mobile-stack td:before {
        font-weight: 600;
        color: #2c3e50;
    }
    
    /* Ensure touch targets meet minimum size requirements */
    .responsive-table-container.mobile-stack td,
    .table-card {
        min-height: 44px;
    }
}

/* Print accessibility */
@media print {
    .responsive-table-container {
        break-inside: avoid;
    }
    
    .responsive-table-container th,
    .responsive-table-container td {
        break-inside: avoid;
    }
    
    /* Ensure data labels are visible in print */
    .responsive-table-container td:before {
        content: attr(data-label) ": ";
        font-weight: bold;
    }
}

/* Animation preferences */
@media (prefers-reduced-motion: reduce) {
    .responsive-table-container,
    .responsive-table-container *,
    .table-card {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Large text scaling support */
@media (min-resolution: 120dpi) {
    .responsive-table-container {
        font-size: 16px;
    }
    
    .responsive-table-container th,
    .responsive-table-container td {
        padding: 16px 20px;
        line-height: 1.6;
    }
}

/* Color blindness considerations */
.responsive-table-container .status-positive {
    background-color: #e8f5e8;
    color: #2d5a2d;
}

.responsive-table-container .status-negative {
    background-color: #ffe8e8;
    color: #5a2d2d;
}

.responsive-table-container .status-warning {
    background-color: #fff8e8;
    color: #5a4d2d;
}

/* Pattern indicators for color-blind users */
.responsive-table-container .status-positive:before {
    content: "✓ ";
}

.responsive-table-container .status-negative:before {
    content: "✗ ";
}

.responsive-table-container .status-warning:before {
    content: "⚠ ";
}

Conclusion

Advanced responsive Markdown table design represents a sophisticated approach to data presentation that ensures optimal user experiences across all device categories while maintaining accessibility standards and performance optimization. By implementing comprehensive responsive design strategies, progressive enhancement techniques, and accessibility compliance measures, technical documentation can deliver table-based content that adapts seamlessly to user needs and device capabilities without compromising data integrity or visual clarity.

The key to successful responsive table implementation lies in understanding user interaction patterns across different devices, implementing performance-optimized loading strategies, and maintaining consistent accessibility standards throughout the responsive design process. Whether you’re building technical documentation, data dashboards, or content management systems, the techniques covered in this guide provide the foundation for creating table systems that scale effectively while delivering exceptional user experiences.

Remember to test your responsive table implementations across various devices and screen sizes, validate accessibility compliance using automated testing tools and manual verification processes, and continuously monitor performance metrics to ensure optimal loading times and smooth user interactions. With proper implementation of advanced responsive design techniques, your Markdown tables can provide professional-grade data presentation capabilities that meet modern web standards while remaining maintainable and scalable for long-term content management needs.