@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        overflow-x: hidden;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.5);
    }

    .sidebar.open {
        transform: translateX(0) !important;
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1001; /* Higher than sidebar (1000)? No, needs to be below sidebar but above content */
        /* Sidebar is 1000. Overlay should be 999. */
        z-index: 999;
        display: none;
        backdrop-filter: blur(2px);
    }
    
    .sidebar-overlay.visible {
        display: block;
    }

    .main-content {
        padding: 15px;
        width: 100%;
        padding-top: 60px;
    }

    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 2000; /* Ensure it's on top */
        background: var(--bg-card);
        border: 1px solid var(--border);
        width: 40px;
        height: 40px;
        border-radius: 8px;
        color: white;
        cursor: pointer;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }
    
    #sync-timer-container {
        display: none !important;
    }

    .header {
        margin-bottom: 20px;
        text-align: center;
    }

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

    .command-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        padding: 15px;
    }
    
    .command-info {
        width: 100%;
    }
    
    .command-actions {
        width: 100%;
        display: flex;
        justify-content: flex-end;
        gap: 15px;
        border-top: 1px solid rgba(255,255,255,0.1);
        padding-top: 10px;
        margin-top: 5px;
    }
    
    .command-actions button {
        padding: 10px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 10px;
        display: flex;
        flex-direction: column;
    }
    
    .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .option-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        background: rgba(255,255,255,0.03);
        padding: 10px;
        border-radius: 6px;
    }
    
    .option-row-header {
        flex-wrap: wrap;
    }
    
    .option-row-details {
        flex-wrap: wrap;
    }
    
    .opt-input {
        width: 100%;
    }

    #flow-editor {
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 2000;
        background: var(--bg-dark);
        display: none;
    }
    
    #flow-editor.active {
        display: block;
    }

    .flow-editor-wrapper {
        flex-direction: column;
    }

    .flow-toolbox {
        width: 100%;
        height: auto;
        max-height: 160px; /* Increased height */
        flex-direction: row;
        overflow-x: auto;
        padding: 15px;
        gap: 12px;
        border-right: none;
        border-bottom: 1px solid #333;
        background: #111;
        /* Scroll snapping for better feel */
        scroll-snap-type: x mandatory;
    }

    .toolbox-header, .variables-list {
        display: none;
    }

    .toolbox-item {
        min-width: 110px;
        height: 90px; /* Fixed height for consistency */
        margin-bottom: 0;
        flex-direction: column; /* Stack icon and text */
        justify-content: center;
        flex-shrink: 0;
        font-size: 0.85rem;
        text-align: center;
        background: #222;
        border: 1px solid #333;
        border-radius: 8px;
        scroll-snap-align: start;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }
    
    .toolbox-item i {
        font-size: 1.5rem;
        margin-bottom: 8px;
        color: var(--primary);
    }
    
    /* Make node inputs touch-friendly */
    .flow-node-inputs input,
    .flow-node-inputs select,
    .flow-node-inputs textarea {
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 10px;
        border-radius: 6px;
        min-height: 40px;
        margin-bottom: 8px;
    }

    .flow-canvas-container {
        touch-action: none;
    }
    
    .flow-controls {
        top: auto;
        bottom: 30px;
        left: 50%;
        transform: translateX(-50%); /* Center horizontally */
        right: auto;
        width: 90%;
        max-width: 400px;
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: 10px;
        padding: 10px;
        background: rgba(20, 20, 20, 0.95);
        border-radius: 8px;
        border: 1px solid #333;
    }
    
    .flow-controls button {
        flex: 1;
        min-width: 40px;
        padding: 12px;
        justify-content: center;
    }
    
    #btn-back-dashboard {
        position: absolute;
        top: max(15px, env(safe-area-inset-top) + 15px);
        left: 15px;
        z-index: 100;
        background: var(--primary);
        color: white;
        border: none;
        padding: 12px 20px;
        border-radius: 25px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.4);
        font-weight: bold;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    input[type="text"], 
    input[type="password"], 
    select, 
    textarea {
        font-size: 16px;
        padding: 12px;
    }
    
    button {
        min-height: 44px;
    }
}

.mobile-menu-btn {
    display: none;
}
.sidebar-overlay {
    display: none;
}
